237
237
self->x_pointer = self->y_pointer = 0;
239
239
MAKE_NEW_MATRIXSTREAM(self->matrixstream, &MatrixStreamType, NULL);
241
return (PyObject *)self;
245
NewMatrix_init(NewMatrix *self, PyObject *args, PyObject *kwds)
248
PyObject *inittmp=NULL;
249
241
static char *kwlist[] = {"width", "height", "init", NULL};
251
243
if (! PyArg_ParseTupleAndKeywords(args, kwds, "ii|O", kwlist, &self->width, &self->height, &inittmp))
254
246
self->data = (MYFLT **)realloc(self->data, (self->height + 1) * sizeof(MYFLT));
256
248
for (i=0; i<(self->height+1); i++) {
257
249
self->data[i] = (MYFLT *)malloc((self->width + 1) * sizeof(MYFLT));
260
252
for(i=0; i<(self->height+1); i++) {
261
253
for (j=0; j<(self->width+1); j++) {
262
254
self->data[i][j] = 0.0;
266
258
MatrixStream_setWidth(self->matrixstream, self->width);
267
259
MatrixStream_setHeight(self->matrixstream, self->height);
270
262
PyObject_CallMethod((PyObject *)self, "setMatrix", "O", inittmp);
273
265
MatrixStream_setData(self->matrixstream, self->data);
267
return (PyObject *)self;
279
270
static PyObject * NewMatrix_getServer(NewMatrix* self) { GET_SERVER };
598
588
Stream_setFunctionPtr(self->stream, MatrixRec_compute_next_data_frame);
599
589
Stream_setStreamActive(self->stream, 0);
601
return (PyObject *)self;
605
MatrixRec_init(MatrixRec *self, PyObject *args, PyObject *kwds)
608
PyObject *inputtmp, *input_streamtmp, *matrixtmp;
610
591
static char *kwlist[] = {"input", "matrix", "fadetime", "delay", NULL};
612
593
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_OO_FI, kwlist, &inputtmp, &matrixtmp, &self->fadetime, &self->delay))
615
Py_XDECREF(self->input);
616
self->input = inputtmp;
617
input_streamtmp = PyObject_CallMethod((PyObject *)self->input, "_getStream", NULL);
618
Py_INCREF(input_streamtmp);
619
Py_XDECREF(self->input_stream);
620
self->input_stream = (Stream *)input_streamtmp;
622
598
Py_XDECREF(self->matrix);
623
599
self->matrix = (NewMatrix *)matrixtmp;
625
Py_INCREF(self->stream);
626
601
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
628
603
self->trigsBuffer = (MYFLT *)realloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT));
735
708
0, /* tp_descr_get */
736
709
0, /* tp_descr_set */
737
710
0, /* tp_dictoffset */
738
(initproc)MatrixRec_init, /* tp_init */
739
712
0, /* tp_alloc */
740
713
MatrixRec_new, /* tp_new */
743
716
/******************************/
717
/* MatrixRecLoop object definition */
718
/******************************/
722
Stream *input_stream;
726
TriggerStream *trig_stream;
730
MatrixRecLoop_compute_next_data_frame(MatrixRecLoop *self)
733
int width = NewMatrix_getWidth((NewMatrix *)self->matrix);
734
int height = NewMatrix_getHeight((NewMatrix *)self->matrix);
735
int size = width * height;
737
MYFLT buffer[self->bufsize];
738
memset(&buffer, 0, sizeof(buffer));
739
MYFLT *in = Stream_getData((Stream *)self->input_stream);
741
for (i=0; i<self->bufsize; i++) {
742
self->trigsBuffer[i] = 0.0;
744
if (self->pointer++ >= size) {
746
self->trigsBuffer[i] = 1.0;
749
NewMatrix_recordChunkAllRow((NewMatrix *)self->matrix, buffer, self->bufsize);
753
MatrixRecLoop_traverse(MatrixRecLoop *self, visitproc visit, void *arg)
756
Py_VISIT(self->input);
757
Py_VISIT(self->input_stream);
758
Py_VISIT(self->matrix);
759
Py_VISIT(self->trig_stream);
764
MatrixRecLoop_clear(MatrixRecLoop *self)
767
Py_CLEAR(self->input);
768
Py_CLEAR(self->input_stream);
769
Py_CLEAR(self->matrix);
770
Py_CLEAR(self->trig_stream);
775
MatrixRecLoop_dealloc(MatrixRecLoop* self)
778
free(self->trigsBuffer);
779
MatrixRecLoop_clear(self);
780
self->ob_type->tp_free((PyObject*)self);
784
MatrixRecLoop_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
787
PyObject *inputtmp, *input_streamtmp, *matrixtmp;
789
self = (MatrixRecLoop *)type->tp_alloc(type, 0);
795
Stream_setFunctionPtr(self->stream, MatrixRecLoop_compute_next_data_frame);
797
static char *kwlist[] = {"input", "matrix", NULL};
799
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &inputtmp, &matrixtmp))
804
Py_XDECREF(self->matrix);
805
self->matrix = (NewMatrix *)matrixtmp;
807
PyObject_CallMethod(self->server, "addStream", "O", self->stream);
809
self->trigsBuffer = (MYFLT *)realloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT));
811
for (i=0; i<self->bufsize; i++) {
812
self->trigsBuffer[i] = 0.0;
815
MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL);
816
TriggerStream_setData(self->trig_stream, self->trigsBuffer);
818
return (PyObject *)self;
821
static PyObject * MatrixRecLoop_getServer(MatrixRecLoop* self) { GET_SERVER };
822
static PyObject * MatrixRecLoop_getStream(MatrixRecLoop* self) { GET_STREAM };
823
static PyObject * MatrixRecLoop_getTriggerStream(MatrixRecLoop* self) { GET_TRIGGER_STREAM };
825
static PyObject * MatrixRecLoop_play(MatrixRecLoop *self, PyObject *args, PyObject *kwds) { PLAY };
826
static PyObject * MatrixRecLoop_stop(MatrixRecLoop *self) { STOP };
829
MatrixRecLoop_setMatrix(MatrixRecLoop *self, PyObject *arg)
840
Py_DECREF(self->matrix);
841
self->matrix = (NewMatrix *)tmp;
847
static PyMemberDef MatrixRecLoop_members[] = {
848
{"server", T_OBJECT_EX, offsetof(MatrixRecLoop, server), 0, "Pyo server."},
849
{"stream", T_OBJECT_EX, offsetof(MatrixRecLoop, stream), 0, "Stream object."},
850
{"trig_stream", T_OBJECT_EX, offsetof(MatrixRecLoop, trig_stream), 0, "Trigger Stream object."},
851
{"input", T_OBJECT_EX, offsetof(MatrixRecLoop, input), 0, "Input sound object."},
852
{"matrix", T_OBJECT_EX, offsetof(MatrixRecLoop, matrix), 0, "matrix to record in."},
853
{NULL} /* Sentinel */
856
static PyMethodDef MatrixRecLoop_methods[] = {
857
{"getServer", (PyCFunction)MatrixRecLoop_getServer, METH_NOARGS, "Returns server object."},
858
{"_getStream", (PyCFunction)MatrixRecLoop_getStream, METH_NOARGS, "Returns stream object."},
859
{"_getTriggerStream", (PyCFunction)MatrixRecLoop_getTriggerStream, METH_NOARGS, "Returns trigger stream object."},
860
{"setMatrix", (PyCFunction)MatrixRecLoop_setMatrix, METH_O, "Sets a new Matrix."},
861
{"play", (PyCFunction)MatrixRecLoop_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
862
{"stop", (PyCFunction)MatrixRecLoop_stop, METH_NOARGS, "Stops computing."},
863
{NULL} /* Sentinel */
866
PyTypeObject MatrixRecLoopType = {
867
PyObject_HEAD_INIT(NULL)
869
"_pyo.MatrixRecLoop_base", /*tp_name*/
870
sizeof(MatrixRecLoop), /*tp_basicsize*/
872
(destructor)MatrixRecLoop_dealloc, /*tp_dealloc*/
879
0, /*tp_as_sequence*/
887
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
888
"MatrixRecLoop objects. Record circular audio input in a Matrix object.", /* tp_doc */
889
(traverseproc)MatrixRecLoop_traverse, /* tp_traverse */
890
(inquiry)MatrixRecLoop_clear, /* tp_clear */
891
0, /* tp_richcompare */
892
0, /* tp_weaklistoffset */
895
MatrixRecLoop_methods, /* tp_methods */
896
MatrixRecLoop_members, /* tp_members */
900
0, /* tp_descr_get */
901
0, /* tp_descr_set */
902
0, /* tp_dictoffset */
905
MatrixRecLoop_new, /* tp_new */
908
/******************************/
744
909
/* MatrixMorph object definition */
745
910
/******************************/
823
988
MatrixMorph_dealloc(MatrixMorph* self)
826
991
free(self->buffer);
827
992
MatrixMorph_clear(self);
828
993
self->ob_type->tp_free((PyObject*)self);
831
static PyObject * MatrixMorph_deleteStream(MatrixMorph *self) { DELETE_STREAM };
833
996
static PyObject *
834
997
MatrixMorph_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1000
long width, height, numsamps;
1001
PyObject *inputtmp, *input_streamtmp, *matrixtmp, *sourcestmp;
837
1002
MatrixMorph *self;
838
1003
self = (MatrixMorph *)type->tp_alloc(type, 0);
840
1005
INIT_OBJECT_COMMON
842
1007
Stream_setFunctionPtr(self->stream, MatrixMorph_compute_next_data_frame);
844
return (PyObject *)self;
848
MatrixMorph_init(MatrixMorph *self, PyObject *args, PyObject *kwds)
850
long width, height, numsamps;
851
PyObject *inputtmp, *input_streamtmp, *matrixtmp, *sourcestmp;
853
1009
static char *kwlist[] = {"input", "matrix", "sources", NULL};
855
1011
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OOO", kwlist, &inputtmp, &matrixtmp, &sourcestmp))
858
Py_XDECREF(self->input);
859
self->input = inputtmp;
860
input_streamtmp = PyObject_CallMethod((PyObject *)self->input, "_getStream", NULL);
861
Py_INCREF(input_streamtmp);
862
Py_XDECREF(self->input_stream);
863
self->input_stream = (Stream *)input_streamtmp;
865
1016
Py_XDECREF(self->matrix);
866
1017
self->matrix = (PyObject *)matrixtmp;