1
/*************************************************************************
2
* Copyright 2010 Olivier Belanger *
4
* This file is part of pyo, a python module to help digital signal *
5
* processing script creation. *
7
* pyo is free software: you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation, either version 3 of the License, or *
10
* (at your option) any later version. *
12
* pyo is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with pyo. If not, see <http://www.gnu.org/licenses/>. *
19
*************************************************************************/
22
#include "structmember.h"
23
#include "pyomodule.h"
24
#include "streammodule.h"
25
#include "servermodule.h"
26
#include "dummymodule.h"
27
#include "matrixmodule.h"
30
/* MatrixPointer object */
43
MatrixPointer_readframes(MatrixPointer *self) {
46
MYFLT *x = Stream_getData((Stream *)self->x_stream);
47
MYFLT *y = Stream_getData((Stream *)self->y_stream);
49
for (i=0; i<self->bufsize; i++) {
50
self->data[i] = MatrixStream_getInterpPointFromPos(self->matrix, x[i], y[i]);
54
static void MatrixPointer_postprocessing_ii(MatrixPointer *self) { POST_PROCESSING_II };
55
static void MatrixPointer_postprocessing_ai(MatrixPointer *self) { POST_PROCESSING_AI };
56
static void MatrixPointer_postprocessing_ia(MatrixPointer *self) { POST_PROCESSING_IA };
57
static void MatrixPointer_postprocessing_aa(MatrixPointer *self) { POST_PROCESSING_AA };
58
static void MatrixPointer_postprocessing_ireva(MatrixPointer *self) { POST_PROCESSING_IREVA };
59
static void MatrixPointer_postprocessing_areva(MatrixPointer *self) { POST_PROCESSING_AREVA };
60
static void MatrixPointer_postprocessing_revai(MatrixPointer *self) { POST_PROCESSING_REVAI };
61
static void MatrixPointer_postprocessing_revaa(MatrixPointer *self) { POST_PROCESSING_REVAA };
62
static void MatrixPointer_postprocessing_revareva(MatrixPointer *self) { POST_PROCESSING_REVAREVA };
65
MatrixPointer_setProcMode(MatrixPointer *self)
68
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
70
self->proc_func_ptr = MatrixPointer_readframes;
74
self->muladd_func_ptr = MatrixPointer_postprocessing_ii;
77
self->muladd_func_ptr = MatrixPointer_postprocessing_ai;
80
self->muladd_func_ptr = MatrixPointer_postprocessing_revai;
83
self->muladd_func_ptr = MatrixPointer_postprocessing_ia;
86
self->muladd_func_ptr = MatrixPointer_postprocessing_aa;
89
self->muladd_func_ptr = MatrixPointer_postprocessing_revaa;
92
self->muladd_func_ptr = MatrixPointer_postprocessing_ireva;
95
self->muladd_func_ptr = MatrixPointer_postprocessing_areva;
98
self->muladd_func_ptr = MatrixPointer_postprocessing_revareva;
104
MatrixPointer_compute_next_data_frame(MatrixPointer *self)
106
(*self->proc_func_ptr)(self);
107
(*self->muladd_func_ptr)(self);
111
MatrixPointer_traverse(MatrixPointer *self, visitproc visit, void *arg)
114
Py_VISIT(self->matrix);
116
Py_VISIT(self->x_stream);
118
Py_VISIT(self->y_stream);
123
MatrixPointer_clear(MatrixPointer *self)
126
Py_CLEAR(self->matrix);
128
Py_CLEAR(self->x_stream);
130
Py_CLEAR(self->y_stream);
135
MatrixPointer_dealloc(MatrixPointer* self)
138
MatrixPointer_clear(self);
139
self->ob_type->tp_free((PyObject*)self);
142
static PyObject * MatrixPointer_deleteStream(MatrixPointer *self) { DELETE_STREAM };
145
MatrixPointer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
149
self = (MatrixPointer *)type->tp_alloc(type, 0);
151
self->modebuffer[0] = 0;
152
self->modebuffer[1] = 0;
155
Stream_setFunctionPtr(self->stream, MatrixPointer_compute_next_data_frame);
156
self->mode_func_ptr = MatrixPointer_setProcMode;
158
return (PyObject *)self;
162
MatrixPointer_init(MatrixPointer *self, PyObject *args, PyObject *kwds)
164
PyObject *matrixtmp, *xtmp, *ytmp, *multmp=NULL, *addtmp=NULL;
166
static char *kwlist[] = {"matrix", "x", "y", "mul", "add", NULL};
168
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OOO|OO", kwlist, &matrixtmp, &xtmp, &ytmp, &multmp, &addtmp))
171
Py_XDECREF(self->matrix);
172
self->matrix = PyObject_CallMethod((PyObject *)matrixtmp, "getMatrixStream", "");
175
PyObject_CallMethod((PyObject *)self, "setX", "O", xtmp);
179
PyObject_CallMethod((PyObject *)self, "setY", "O", ytmp);
183
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
187
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
190
Py_INCREF(self->stream);
191
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
193
(*self->mode_func_ptr)(self);
199
static PyObject * MatrixPointer_getServer(MatrixPointer* self) { GET_SERVER };
200
static PyObject * MatrixPointer_getStream(MatrixPointer* self) { GET_STREAM };
201
static PyObject * MatrixPointer_setMul(MatrixPointer *self, PyObject *arg) { SET_MUL };
202
static PyObject * MatrixPointer_setAdd(MatrixPointer *self, PyObject *arg) { SET_ADD };
203
static PyObject * MatrixPointer_setSub(MatrixPointer *self, PyObject *arg) { SET_SUB };
204
static PyObject * MatrixPointer_setDiv(MatrixPointer *self, PyObject *arg) { SET_DIV };
206
static PyObject * MatrixPointer_play(MatrixPointer *self, PyObject *args, PyObject *kwds) { PLAY };
207
static PyObject * MatrixPointer_out(MatrixPointer *self, PyObject *args, PyObject *kwds) { OUT };
208
static PyObject * MatrixPointer_stop(MatrixPointer *self) { STOP };
210
static PyObject * MatrixPointer_multiply(MatrixPointer *self, PyObject *arg) { MULTIPLY };
211
static PyObject * MatrixPointer_inplace_multiply(MatrixPointer *self, PyObject *arg) { INPLACE_MULTIPLY };
212
static PyObject * MatrixPointer_add(MatrixPointer *self, PyObject *arg) { ADD };
213
static PyObject * MatrixPointer_inplace_add(MatrixPointer *self, PyObject *arg) { INPLACE_ADD };
214
static PyObject * MatrixPointer_sub(MatrixPointer *self, PyObject *arg) { SUB };
215
static PyObject * MatrixPointer_inplace_sub(MatrixPointer *self, PyObject *arg) { INPLACE_SUB };
216
static PyObject * MatrixPointer_div(MatrixPointer *self, PyObject *arg) { DIV };
217
static PyObject * MatrixPointer_inplace_div(MatrixPointer *self, PyObject *arg) { INPLACE_DIV };
220
MatrixPointer_getMatrix(MatrixPointer* self)
222
Py_INCREF(self->matrix);
227
MatrixPointer_setMatrix(MatrixPointer *self, PyObject *arg)
237
Py_DECREF(self->matrix);
238
self->matrix = PyObject_CallMethod((PyObject *)tmp, "getMatrixStream", "");
245
MatrixPointer_setX(MatrixPointer *self, PyObject *arg)
247
PyObject *tmp, *streamtmp;
254
int isNumber = PyNumber_Check(arg);
256
printf("MatrixPointer x attributes must be a PyoObject.\n");
266
streamtmp = PyObject_CallMethod((PyObject *)self->x, "_getStream", NULL);
267
Py_INCREF(streamtmp);
268
Py_XDECREF(self->x_stream);
269
self->x_stream = (Stream *)streamtmp;
276
MatrixPointer_setY(MatrixPointer *self, PyObject *arg)
278
PyObject *tmp, *streamtmp;
285
int isNumber = PyNumber_Check(arg);
287
printf("MatrixPointer y attributes must be a PyoObject.\n");
297
streamtmp = PyObject_CallMethod((PyObject *)self->y, "_getStream", NULL);
298
Py_INCREF(streamtmp);
299
Py_XDECREF(self->y_stream);
300
self->y_stream = (Stream *)streamtmp;
306
static PyMemberDef MatrixPointer_members[] = {
307
{"server", T_OBJECT_EX, offsetof(MatrixPointer, server), 0, "Pyo server."},
308
{"stream", T_OBJECT_EX, offsetof(MatrixPointer, stream), 0, "Stream object."},
309
{"matrix", T_OBJECT_EX, offsetof(MatrixPointer, matrix), 0, "Waveform matrix."},
310
{"x", T_OBJECT_EX, offsetof(MatrixPointer, x), 0, "Reader x."},
311
{"y", T_OBJECT_EX, offsetof(MatrixPointer, y), 0, "Reader y."},
312
{"mul", T_OBJECT_EX, offsetof(MatrixPointer, mul), 0, "Mul factor."},
313
{"add", T_OBJECT_EX, offsetof(MatrixPointer, add), 0, "Add factor."},
314
{NULL} /* Sentinel */
317
static PyMethodDef MatrixPointer_methods[] = {
318
{"getMatrix", (PyCFunction)MatrixPointer_getMatrix, METH_NOARGS, "Returns waveform matrix object."},
319
{"getServer", (PyCFunction)MatrixPointer_getServer, METH_NOARGS, "Returns server object."},
320
{"_getStream", (PyCFunction)MatrixPointer_getStream, METH_NOARGS, "Returns stream object."},
321
{"deleteStream", (PyCFunction)MatrixPointer_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
322
{"play", (PyCFunction)MatrixPointer_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
323
{"out", (PyCFunction)MatrixPointer_out, METH_VARARGS|METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
324
{"stop", (PyCFunction)MatrixPointer_stop, METH_NOARGS, "Stops computing."},
325
{"setMatrix", (PyCFunction)MatrixPointer_setMatrix, METH_O, "Sets oscillator matrix."},
326
{"setX", (PyCFunction)MatrixPointer_setX, METH_O, "Sets reader x."},
327
{"setY", (PyCFunction)MatrixPointer_setY, METH_O, "Sets reader y."},
328
{"setMul", (PyCFunction)MatrixPointer_setMul, METH_O, "Sets oscillator mul factor."},
329
{"setAdd", (PyCFunction)MatrixPointer_setAdd, METH_O, "Sets oscillator add factor."},
330
{"setSub", (PyCFunction)MatrixPointer_setSub, METH_O, "Sets oscillator inverse add factor."},
331
{"setDiv", (PyCFunction)MatrixPointer_setDiv, METH_O, "Sets inverse mul factor."},
332
{NULL} /* Sentinel */
335
static PyNumberMethods MatrixPointer_as_number = {
336
(binaryfunc)MatrixPointer_add, /*nb_add*/
337
(binaryfunc)MatrixPointer_sub, /*nb_subtract*/
338
(binaryfunc)MatrixPointer_multiply, /*nb_multiply*/
339
(binaryfunc)MatrixPointer_div, /*nb_divide*/
345
0, /*(unaryfunc)array_abs,*/
359
(binaryfunc)MatrixPointer_inplace_add, /*inplace_add*/
360
(binaryfunc)MatrixPointer_inplace_sub, /*inplace_subtract*/
361
(binaryfunc)MatrixPointer_inplace_multiply, /*inplace_multiply*/
362
(binaryfunc)MatrixPointer_inplace_div, /*inplace_divide*/
363
0, /*inplace_remainder*/
365
0, /*inplace_lshift*/
366
0, /*inplace_rshift*/
370
0, /*nb_floor_divide*/
371
0, /*nb_true_divide*/
372
0, /*nb_inplace_floor_divide*/
373
0, /*nb_inplace_true_divide*/
377
PyTypeObject MatrixPointerType = {
378
PyObject_HEAD_INIT(NULL)
380
"_pyo.MatrixPointer_base", /*tp_name*/
381
sizeof(MatrixPointer), /*tp_basicsize*/
383
(destructor)MatrixPointer_dealloc, /*tp_dealloc*/
389
&MatrixPointer_as_number, /*tp_as_number*/
390
0, /*tp_as_sequence*/
398
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
399
"MatrixPointer objects. Read a waveform matrix with a pointer x.", /* tp_doc */
400
(traverseproc)MatrixPointer_traverse, /* tp_traverse */
401
(inquiry)MatrixPointer_clear, /* tp_clear */
402
0, /* tp_richcompare */
403
0, /* tp_weaklistoffset */
406
MatrixPointer_methods, /* tp_methods */
407
MatrixPointer_members, /* tp_members */
411
0, /* tp_descr_get */
412
0, /* tp_descr_set */
413
0, /* tp_dictoffset */
414
(initproc)MatrixPointer_init, /* tp_init */
416
MatrixPointer_new, /* tp_new */