~ubuntu-branches/ubuntu/quantal/python-pyo/quantal

« back to all changes in this revision

Viewing changes to src/objects/recordmodule.c

  • Committer: Package Import Robot
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2012-07-03 23:45:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120703234541-jh5jg00lvljnwq8m
Tags: 0.6.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
static void
107
107
Record_dealloc(Record* self)
108
108
{
109
 
    free(self->data);
 
109
    if (Stream_getStreamActive(self->stream))
 
110
        PyObject_CallMethod((PyObject *)self, "stop", NULL);
 
111
    pyo_DEALLOC
110
112
    free(self->buffer);
111
113
    Record_clear(self);
112
114
    self->ob_type->tp_free((PyObject*)self);
113
115
}
114
116
 
115
 
static PyObject * Record_deleteStream(Record *self) { DELETE_STREAM };
116
 
 
117
117
static PyObject *
118
118
Record_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
119
119
{
120
 
    int i;
 
120
    int i, buflen;
 
121
    int fileformat = 0;
 
122
    int sampletype = 0;
 
123
    PyObject *input_listtmp;
121
124
    Record *self;
122
125
    self = (Record *)type->tp_alloc(type, 0);
123
126
    
128
131
    INIT_OBJECT_COMMON
129
132
    Stream_setFunctionPtr(self->stream, Record_compute_next_data_frame);
130
133
    self->mode_func_ptr = Record_setProcMode;
131
 
    return (PyObject *)self;
132
 
}
133
134
 
134
 
static int
135
 
Record_init(Record *self, PyObject *args, PyObject *kwds)
136
 
{
137
 
    int i, buflen;
138
 
    int fileformat = 0;
139
 
    int sampletype = 0;
140
 
    PyObject *input_listtmp;
141
 
    
142
135
    static char *kwlist[] = {"input", "filename", "chnls", "fileformat", "sampletype", "buffering", NULL};
143
136
    
144
137
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "Os|iiii", kwlist, &input_listtmp, &self->recpath, &self->chnls, &fileformat, &sampletype, &self->buffering))
145
 
        return -1; 
 
138
        Py_RETURN_NONE;
146
139
    
147
140
    Py_XDECREF(self->input_list);
148
141
    self->input_list = input_listtmp;
185
178
    /* Open the output file. */
186
179
    if (! (self->recfile = sf_open(self->recpath, SFM_WRITE, &self->recinfo))) {   
187
180
        printf ("Not able to open output file %s.\n", self->recpath);
 
181
        Py_RETURN_NONE;
188
182
    }   
189
183
 
190
184
    buflen = self->bufsize * self->chnls * self->buffering;
193
187
        self->buffer[i] = 0.;
194
188
    }    
195
189
    
196
 
    Py_INCREF(self->stream);
197
190
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
198
191
    
199
192
    (*self->mode_func_ptr)(self);
200
 
        
201
 
    Py_INCREF(self);
202
 
    return 0;
 
193
 
 
194
    return (PyObject *)self;
203
195
}
204
196
 
205
197
static PyObject * Record_getServer(Record* self) { GET_SERVER };
222
214
static PyMethodDef Record_methods[] = {
223
215
{"getServer", (PyCFunction)Record_getServer, METH_NOARGS, "Returns server object."},
224
216
{"_getStream", (PyCFunction)Record_getStream, METH_NOARGS, "Returns stream object."},
225
 
{"deleteStream", (PyCFunction)Record_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
226
217
{"play", (PyCFunction)Record_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
227
218
{"stop", (PyCFunction)Record_stop, METH_NOARGS, "Stops computing."},
228
219
{NULL}  /* Sentinel */
265
256
0,                                              /* tp_descr_get */
266
257
0,                                              /* tp_descr_set */
267
258
0,                                              /* tp_dictoffset */
268
 
(initproc)Record_init,                          /* tp_init */
 
259
0,                          /* tp_init */
269
260
0,                                              /* tp_alloc */
270
261
Record_new,                                     /* tp_new */
271
262
};
349
340
static void
350
341
ControlRec_dealloc(ControlRec* self)
351
342
{
352
 
    free(self->data);
 
343
    pyo_DEALLOC
353
344
    if (self->buffer != NULL)
354
345
        free(self->buffer);
355
346
    ControlRec_clear(self);
356
347
    self->ob_type->tp_free((PyObject*)self);
357
348
}
358
349
 
359
 
static PyObject * ControlRec_deleteStream(ControlRec *self) { DELETE_STREAM };
360
 
 
361
350
static PyObject *
362
351
ControlRec_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
363
352
{
364
353
    int i;
 
354
    long j;
 
355
    PyObject *inputtmp, *input_streamtmp;
365
356
    ControlRec *self;
366
357
    self = (ControlRec *)type->tp_alloc(type, 0);
367
358
    
373
364
    Stream_setFunctionPtr(self->stream, ControlRec_compute_next_data_frame);
374
365
    self->mode_func_ptr = ControlRec_setProcMode;
375
366
 
376
 
    return (PyObject *)self;
377
 
}
378
 
 
379
 
static int
380
 
ControlRec_init(ControlRec *self, PyObject *args, PyObject *kwds)
381
 
{
382
 
    long i;
383
 
    PyObject *inputtmp, *input_streamtmp;
384
 
    
385
367
    static char *kwlist[] = {"input", "rate", "dur", NULL};
386
368
    
387
369
    if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_IF, kwlist, &inputtmp, &self->rate, &self->dur))
388
 
        return -1; 
 
370
        Py_RETURN_NONE;
389
371
    
390
372
    INIT_INPUT_STREAM
391
373
 
392
 
    Py_INCREF(self->stream);
393
374
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
394
375
    
395
376
    if (self->dur > 0.0) {
396
377
        self->size = (long)(self->dur * self->rate + 1);
397
378
        self->buffer = (MYFLT *)realloc(self->buffer, self->size * sizeof(MYFLT));
398
 
        for (i=0; i<self->size; i++) {
399
 
            self->buffer[i] = 0.0;
 
379
        for (j=0; j<self->size; j++) {
 
380
            self->buffer[j] = 0.0;
400
381
        }        
401
382
    }    
402
383
    self->modulo = (int)(self->sr / self->rate);
403
384
    
404
385
    (*self->mode_func_ptr)(self);
405
 
    
406
 
    Py_INCREF(self);
407
 
    return 0;
 
386
 
 
387
    return (PyObject *)self;
408
388
}
409
389
 
410
390
static PyObject * ControlRec_getServer(ControlRec* self) { GET_SERVER };
457
437
static PyMethodDef ControlRec_methods[] = {
458
438
    {"getServer", (PyCFunction)ControlRec_getServer, METH_NOARGS, "Returns server object."},
459
439
    {"_getStream", (PyCFunction)ControlRec_getStream, METH_NOARGS, "Returns stream object."},
460
 
    {"deleteStream", (PyCFunction)ControlRec_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
461
440
    {"play", (PyCFunction)ControlRec_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
462
441
    {"stop", (PyCFunction)ControlRec_stop, METH_NOARGS, "Stops computing."},
463
442
    {"getData", (PyCFunction)ControlRec_getData, METH_NOARGS, "Returns list of sampled points."},
501
480
    0,                                              /* tp_descr_get */
502
481
    0,                                              /* tp_descr_set */
503
482
    0,                                              /* tp_dictoffset */
504
 
    (initproc)ControlRec_init,                          /* tp_init */
 
483
    0,                          /* tp_init */
505
484
    0,                                              /* tp_alloc */
506
485
    ControlRec_new,                                     /* tp_new */
507
486
};
636
615
static void
637
616
ControlRead_dealloc(ControlRead* self)
638
617
{
639
 
    free(self->data);
 
618
    pyo_DEALLOC
640
619
    free(self->values);
641
620
    free(self->trigsBuffer);
642
621
    ControlRead_clear(self);
643
622
    self->ob_type->tp_free((PyObject*)self);
644
623
}
645
624
 
646
 
static PyObject * ControlRead_deleteStream(ControlRead *self) { DELETE_STREAM };
647
 
 
648
625
static PyObject *
649
626
ControlRead_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
650
627
{
651
628
    int i;
 
629
    PyObject *valuestmp, *multmp=NULL, *addtmp=NULL;
652
630
    ControlRead *self;
653
631
    self = (ControlRead *)type->tp_alloc(type, 0);
654
632
    
662
640
    INIT_OBJECT_COMMON
663
641
    Stream_setFunctionPtr(self->stream, ControlRead_compute_next_data_frame);
664
642
    self->mode_func_ptr = ControlRead_setProcMode;
665
 
    
666
 
    return (PyObject *)self;
667
 
}
668
643
 
669
 
static int
670
 
ControlRead_init(ControlRead *self, PyObject *args, PyObject *kwds)
671
 
{
672
 
    int i;
673
 
    PyObject *valuestmp, *multmp=NULL, *addtmp=NULL;
674
 
    
675
644
    static char *kwlist[] = {"values", "rate", "loop", "interp", "mul", "add", NULL};
676
645
    
677
646
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|iiiOO", kwlist, &valuestmp, &self->rate, &self->loop, &self->interp, &multmp, &addtmp))
678
 
        return -1; 
 
647
        Py_RETURN_NONE;
679
648
 
680
649
    if (valuestmp) {
681
650
        PyObject_CallMethod((PyObject *)self, "setValues", "O", valuestmp);
689
658
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
690
659
    }
691
660
    
692
 
    Py_INCREF(self->stream);
693
661
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
694
662
        
695
663
    self->trigsBuffer = (MYFLT *)realloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT));
706
674
    (*self->mode_func_ptr)(self);
707
675
    
708
676
    SET_INTERP_POINTER
709
 
 
710
 
    Py_INCREF(self);
711
 
    return 0;
 
677
    
 
678
    return (PyObject *)self;
712
679
}
713
680
 
714
681
static PyObject * ControlRead_getServer(ControlRead* self) { GET_SERVER };
823
790
    {"getServer", (PyCFunction)ControlRead_getServer, METH_NOARGS, "Returns server object."},
824
791
    {"_getStream", (PyCFunction)ControlRead_getStream, METH_NOARGS, "Returns stream object."},
825
792
    {"_getTriggerStream", (PyCFunction)ControlRead_getTriggerStream, METH_NOARGS, "Returns trigger stream object."},
826
 
    {"deleteStream", (PyCFunction)ControlRead_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
827
793
    {"play", (PyCFunction)ControlRead_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
828
794
    {"stop", (PyCFunction)ControlRead_stop, METH_NOARGS, "Stops computing."},
829
795
    {"setValues", (PyCFunction)ControlRead_setValues, METH_O, "Fill buffer with values in input."},
916
882
    0,                         /* tp_descr_get */
917
883
    0,                         /* tp_descr_set */
918
884
    0,                         /* tp_dictoffset */
919
 
    (initproc)ControlRead_init,      /* tp_init */
 
885
    0,      /* tp_init */
920
886
    0,                         /* tp_alloc */
921
887
    ControlRead_new,                 /* tp_new */
922
888
};
1003
969
static void
1004
970
NoteinRec_dealloc(NoteinRec* self)
1005
971
{
1006
 
    free(self->data);
 
972
    pyo_DEALLOC
1007
973
    NoteinRec_clear(self);
1008
974
    self->ob_type->tp_free((PyObject*)self);
1009
975
}
1010
976
 
1011
 
static PyObject * NoteinRec_deleteStream(NoteinRec *self) { DELETE_STREAM };
1012
 
 
1013
977
static PyObject *
1014
978
NoteinRec_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1015
979
{
1016
980
    int i;
 
981
    PyObject *inputptmp, *inputp_streamtmp, *inputvtmp, *inputv_streamtmp;
1017
982
    NoteinRec *self;
1018
983
    self = (NoteinRec *)type->tp_alloc(type, 0);
1019
984
    
1025
990
    INIT_OBJECT_COMMON
1026
991
    Stream_setFunctionPtr(self->stream, NoteinRec_compute_next_data_frame);
1027
992
    self->mode_func_ptr = NoteinRec_setProcMode;
1028
 
    
1029
 
    return (PyObject *)self;
1030
 
}
1031
993
 
1032
 
static int
1033
 
NoteinRec_init(NoteinRec *self, PyObject *args, PyObject *kwds)
1034
 
{
1035
 
    PyObject *inputptmp, *inputp_streamtmp, *inputvtmp, *inputv_streamtmp;
1036
 
    
1037
994
    static char *kwlist[] = {"inputp", "inputv", NULL};
1038
995
    
1039
996
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &inputptmp, &inputvtmp))
1040
 
        return -1; 
 
997
        Py_RETURN_NONE;
1041
998
    
1042
999
    Py_XDECREF(self->inputp);
1043
1000
    self->inputp = inputptmp;
1053
1010
    Py_XDECREF(self->inputv_stream);
1054
1011
    self->inputv_stream = (Stream *)inputv_streamtmp;
1055
1012
    
1056
 
    Py_INCREF(self->stream);
1057
1013
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1058
1014
 
1059
1015
    (*self->mode_func_ptr)(self);
1060
1016
    
1061
 
    Py_INCREF(self);
1062
 
    return 0;
 
1017
    return (PyObject *)self;
1063
1018
}
1064
1019
 
1065
1020
static PyObject * NoteinRec_getServer(NoteinRec* self) { GET_SERVER };
1101
1056
static PyMethodDef NoteinRec_methods[] = {
1102
1057
    {"getServer", (PyCFunction)NoteinRec_getServer, METH_NOARGS, "Returns server object."},
1103
1058
    {"_getStream", (PyCFunction)NoteinRec_getStream, METH_NOARGS, "Returns stream object."},
1104
 
    {"deleteStream", (PyCFunction)NoteinRec_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
1105
1059
    {"play", (PyCFunction)NoteinRec_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1106
1060
    {"stop", (PyCFunction)NoteinRec_stop, METH_NOARGS, "Stops computing."},
1107
1061
    {"getData", (PyCFunction)NoteinRec_getData, METH_NOARGS, "Returns list of sampled points."},
1145
1099
    0,                                              /* tp_descr_get */
1146
1100
    0,                                              /* tp_descr_set */
1147
1101
    0,                                              /* tp_dictoffset */
1148
 
    (initproc)NoteinRec_init,                          /* tp_init */
 
1102
    0,                          /* tp_init */
1149
1103
    0,                                              /* tp_alloc */
1150
1104
    NoteinRec_new,                                     /* tp_new */
1151
1105
};
1275
1229
static void
1276
1230
NoteinRead_dealloc(NoteinRead* self)
1277
1231
{
1278
 
    free(self->data);
 
1232
    pyo_DEALLOC
1279
1233
    free(self->values);
1280
1234
    free(self->timestamps);
1281
1235
    free(self->trigsBuffer);
1283
1237
    self->ob_type->tp_free((PyObject*)self);
1284
1238
}
1285
1239
 
1286
 
static PyObject * NoteinRead_deleteStream(NoteinRead *self) { DELETE_STREAM };
1287
 
 
1288
1240
static PyObject *
1289
1241
NoteinRead_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1290
1242
{
1291
1243
    int i;
 
1244
    PyObject *valuestmp, *timestampstmp, *multmp=NULL, *addtmp=NULL;
1292
1245
    NoteinRead *self;
1293
1246
    self = (NoteinRead *)type->tp_alloc(type, 0);
1294
1247
    
1301
1254
    INIT_OBJECT_COMMON
1302
1255
    Stream_setFunctionPtr(self->stream, NoteinRead_compute_next_data_frame);
1303
1256
    self->mode_func_ptr = NoteinRead_setProcMode;
1304
 
    
1305
 
    return (PyObject *)self;
1306
 
}
1307
1257
 
1308
 
static int
1309
 
NoteinRead_init(NoteinRead *self, PyObject *args, PyObject *kwds)
1310
 
{
1311
 
    int i;
1312
 
    PyObject *valuestmp, *timestampstmp, *multmp=NULL, *addtmp=NULL;
1313
 
    
1314
1258
    static char *kwlist[] = {"values", "timestamps", "loop", "mul", "add", NULL};
1315
1259
    
1316
1260
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|iOO", kwlist, &valuestmp, &timestampstmp, &self->loop, &multmp, &addtmp))
1317
 
        return -1; 
 
1261
        Py_RETURN_NONE;
1318
1262
 
1319
1263
    if (valuestmp) {
1320
1264
        PyObject_CallMethod((PyObject *)self, "setValues", "O", valuestmp);
1332
1276
        PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1333
1277
    }
1334
1278
    
1335
 
    Py_INCREF(self->stream);
1336
1279
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1337
1280
        
1338
1281
    self->trigsBuffer = (MYFLT *)realloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT));
1346
1289
    
1347
1290
    (*self->mode_func_ptr)(self);
1348
1291
    
1349
 
    Py_INCREF(self);
1350
 
    return 0;
 
1292
    return (PyObject *)self;
1351
1293
}
1352
1294
 
1353
1295
static PyObject * NoteinRead_getServer(NoteinRead* self) { GET_SERVER };
1447
1389
    {"getServer", (PyCFunction)NoteinRead_getServer, METH_NOARGS, "Returns server object."},
1448
1390
    {"_getStream", (PyCFunction)NoteinRead_getStream, METH_NOARGS, "Returns stream object."},
1449
1391
    {"_getTriggerStream", (PyCFunction)NoteinRead_getTriggerStream, METH_NOARGS, "Returns trigger stream object."},
1450
 
    {"deleteStream", (PyCFunction)NoteinRead_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
1451
1392
    {"play", (PyCFunction)NoteinRead_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1452
1393
    {"stop", (PyCFunction)NoteinRead_stop, METH_NOARGS, "Stops computing."},
1453
1394
    {"setValues", (PyCFunction)NoteinRead_setValues, METH_O, "Fill buffer with values in input."},
1539
1480
    0,                         /* tp_descr_get */
1540
1481
    0,                         /* tp_descr_set */
1541
1482
    0,                         /* tp_dictoffset */
1542
 
    (initproc)NoteinRead_init,      /* tp_init */
 
1483
    0,      /* tp_init */
1543
1484
    0,                         /* tp_alloc */
1544
1485
    NoteinRead_new,                 /* tp_new */
1545
1486
};