~ubuntu-branches/debian/sid/python-pyo/sid

« back to all changes in this revision

Viewing changes to src/objects/patternmodule.c

  • Committer: Package Import Robot
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2012-06-08 20:35:45 UTC
  • Revision ID: package-import@ubuntu.com-20120608203545-4z7kcf2lgvpsk18y
Tags: upstream-0.6.1
ImportĀ upstreamĀ versionĀ 0.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************
 
2
 * Copyright 2010 Olivier Belanger                                        *                  
 
3
 *                                                                        * 
 
4
 * This file is part of pyo, a python module to help digital signal       *
 
5
 * processing script creation.                                            *  
 
6
 *                                                                        * 
 
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.                                    * 
 
11
 *                                                                        *
 
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.                           *
 
16
 *                                                                        *
 
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
 *************************************************************************/
 
20
 
 
21
#include <Python.h>
 
22
#include "structmember.h"
 
23
#include "pyomodule.h"
 
24
#include "streammodule.h"
 
25
#include "servermodule.h"
 
26
#include "dummymodule.h"
 
27
 
 
28
typedef struct {
 
29
    pyo_audio_HEAD
 
30
    PyObject *callable;
 
31
    PyObject *time;
 
32
    Stream *time_stream;
 
33
    int modebuffer[1];
 
34
    MYFLT sampleToSec;
 
35
    double currentTime;
 
36
    int init;
 
37
} Pattern;
 
38
 
 
39
static void
 
40
Pattern_generate_i(Pattern *self) {
 
41
    MYFLT tm;
 
42
    int i, flag;
 
43
    PyObject *result;
 
44
    
 
45
    flag = 0;
 
46
    tm = PyFloat_AS_DOUBLE(self->time);
 
47
 
 
48
    for (i=0; i<self->bufsize; i++) {
 
49
        if (self->currentTime >= tm) {
 
50
            flag = 1;
 
51
            self->currentTime = 0.;
 
52
        }    
 
53
 
 
54
        self->currentTime += self->sampleToSec;
 
55
    }
 
56
    if (flag == 1 || self->init == 1) {
 
57
        self->init = 0;
 
58
        result = PyObject_Call((PyObject *)self->callable, PyTuple_New(0), NULL);
 
59
        if (result == NULL)
 
60
            PyErr_Print();
 
61
    }
 
62
}
 
63
 
 
64
static void
 
65
Pattern_generate_a(Pattern *self) {
 
66
    int i, flag;
 
67
    PyObject *result;
 
68
    
 
69
    MYFLT *tm = Stream_getData((Stream *)self->time_stream);
 
70
    
 
71
    flag = 0;
 
72
    for (i=0; i<self->bufsize; i++) {
 
73
        if (self->currentTime >= tm[i]) {
 
74
            flag = 1;
 
75
            self->currentTime = 0.;
 
76
        }    
 
77
        
 
78
        self->currentTime += self->sampleToSec;
 
79
    }
 
80
    if (flag == 1 || self->init == 1) {
 
81
        self->init = 0;
 
82
        result = PyObject_Call((PyObject *)self->callable, PyTuple_New(0), NULL);
 
83
        if (result == NULL)
 
84
            PyErr_Print();
 
85
    }    
 
86
}
 
87
 
 
88
 
 
89
static void
 
90
Pattern_setProcMode(Pattern *self)
 
91
{
 
92
    int procmode = self->modebuffer[0];
 
93
    switch (procmode) {
 
94
        case 0:        
 
95
            self->proc_func_ptr = Pattern_generate_i;
 
96
            break;
 
97
        case 1:    
 
98
            self->proc_func_ptr = Pattern_generate_a;
 
99
            break;
 
100
    }
 
101
}
 
102
 
 
103
static void
 
104
Pattern_compute_next_data_frame(Pattern *self)
 
105
{
 
106
    (*self->proc_func_ptr)(self);     
 
107
}
 
108
 
 
109
static int
 
110
Pattern_traverse(Pattern *self, visitproc visit, void *arg)
 
111
{
 
112
    pyo_VISIT
 
113
    Py_VISIT(self->callable);
 
114
    Py_VISIT(self->time);    
 
115
    Py_VISIT(self->time_stream);    
 
116
    return 0;
 
117
}
 
118
 
 
119
static int 
 
120
Pattern_clear(Pattern *self)
 
121
{
 
122
    pyo_CLEAR
 
123
    Py_CLEAR(self->callable);
 
124
    Py_CLEAR(self->time);    
 
125
    Py_CLEAR(self->time_stream);
 
126
    return 0;
 
127
}
 
128
 
 
129
static void
 
130
Pattern_dealloc(Pattern* self)
 
131
{
 
132
    free(self->data);
 
133
    Pattern_clear(self);
 
134
    self->ob_type->tp_free((PyObject*)self);
 
135
}
 
136
 
 
137
static PyObject * Pattern_deleteStream(Pattern *self) { DELETE_STREAM };
 
138
 
 
139
static PyObject *
 
140
Pattern_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
141
{
 
142
    int i;
 
143
    Pattern *self;
 
144
    self = (Pattern *)type->tp_alloc(type, 0);
 
145
    
 
146
    self->time = PyFloat_FromDouble(1.);
 
147
        self->modebuffer[0] = 0;
 
148
    self->init = 1;
 
149
 
 
150
    INIT_OBJECT_COMMON
 
151
    Stream_setFunctionPtr(self->stream, Pattern_compute_next_data_frame);
 
152
    self->mode_func_ptr = Pattern_setProcMode;
 
153
 
 
154
    Stream_setStreamActive(self->stream, 0);
 
155
    
 
156
    self->sampleToSec = 1. / self->sr;
 
157
    self->currentTime = 0.;
 
158
    
 
159
    return (PyObject *)self;
 
160
}
 
161
 
 
162
static int
 
163
Pattern_init(Pattern *self, PyObject *args, PyObject *kwds)
 
164
{
 
165
    PyObject *timetmp=NULL, *calltmp=NULL;
 
166
    
 
167
    static char *kwlist[] = {"callable", "time", NULL};
 
168
    
 
169
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, &calltmp, &timetmp))
 
170
        return -1; 
 
171
   
 
172
    if (calltmp) {
 
173
        PyObject_CallMethod((PyObject *)self, "setFunction", "O", calltmp);
 
174
    }
 
175
    
 
176
    if (timetmp) {
 
177
        PyObject_CallMethod((PyObject *)self, "setTime", "O", timetmp);
 
178
    }
 
179
    
 
180
    Py_INCREF(self->stream);
 
181
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
182
 
 
183
    (*self->mode_func_ptr)(self);
 
184
        
 
185
    Py_INCREF(self);
 
186
    return 0;
 
187
}
 
188
 
 
189
static PyObject * Pattern_getServer(Pattern* self) { GET_SERVER };
 
190
static PyObject * Pattern_getStream(Pattern* self) { GET_STREAM };
 
191
 
 
192
static PyObject * 
 
193
Pattern_play(Pattern *self, PyObject *args, PyObject *kwds) 
 
194
 
195
    self->init = 1;
 
196
    PLAY 
 
197
};
 
198
 
 
199
static PyObject * Pattern_stop(Pattern *self) { STOP };
 
200
 
 
201
static PyObject *
 
202
Pattern_setFunction(Pattern *self, PyObject *arg)
 
203
{
 
204
        PyObject *tmp;
 
205
        
 
206
        if (! PyCallable_Check(arg)) {
 
207
        PyErr_SetString(PyExc_TypeError, "The callable attribute must be a valid Python function.");
 
208
                Py_INCREF(Py_None);
 
209
                return Py_None;
 
210
        }
 
211
    
 
212
    tmp = arg;
 
213
    Py_XDECREF(self->callable);
 
214
    Py_INCREF(tmp);
 
215
    self->callable = tmp;
 
216
    
 
217
        Py_INCREF(Py_None);
 
218
        return Py_None;
 
219
}       
 
220
 
 
221
static PyObject *
 
222
Pattern_setTime(Pattern *self, PyObject *arg)
 
223
{
 
224
        PyObject *tmp, *streamtmp;
 
225
        
 
226
        if (arg == NULL) {
 
227
                Py_INCREF(Py_None);
 
228
                return Py_None;
 
229
        }
 
230
    
 
231
        int isNumber = PyNumber_Check(arg);
 
232
        
 
233
        tmp = arg;
 
234
        Py_INCREF(tmp);
 
235
        Py_DECREF(self->time);
 
236
        if (isNumber == 1) {
 
237
                self->time = PyNumber_Float(tmp);
 
238
        self->modebuffer[0] = 0;
 
239
        }
 
240
        else {
 
241
                self->time = tmp;
 
242
        streamtmp = PyObject_CallMethod((PyObject *)self->time, "_getStream", NULL);
 
243
        Py_INCREF(streamtmp);
 
244
        Py_XDECREF(self->time_stream);
 
245
        self->time_stream = (Stream *)streamtmp;
 
246
                self->modebuffer[0] = 1;
 
247
        }
 
248
    
 
249
    (*self->mode_func_ptr)(self);
 
250
    
 
251
        Py_INCREF(Py_None);
 
252
        return Py_None;
 
253
}       
 
254
 
 
255
static PyMemberDef Pattern_members[] = {
 
256
{"server", T_OBJECT_EX, offsetof(Pattern, server), 0, "Pyo server."},
 
257
{"stream", T_OBJECT_EX, offsetof(Pattern, stream), 0, "Stream object."},
 
258
{"time", T_OBJECT_EX, offsetof(Pattern, time), 0, "Pattern time factor."},
 
259
{NULL}  /* Sentinel */
 
260
};
 
261
 
 
262
static PyMethodDef Pattern_methods[] = {
 
263
{"getServer", (PyCFunction)Pattern_getServer, METH_NOARGS, "Returns server object."},
 
264
{"_getStream", (PyCFunction)Pattern_getStream, METH_NOARGS, "Returns stream object."},
 
265
{"deleteStream", (PyCFunction)Pattern_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
 
266
{"play", (PyCFunction)Pattern_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
 
267
{"stop", (PyCFunction)Pattern_stop, METH_NOARGS, "Stops computing."},
 
268
{"setTime", (PyCFunction)Pattern_setTime, METH_O, "Sets time factor."},
 
269
{"setFunction", (PyCFunction)Pattern_setFunction, METH_O, "Sets the function to be called."},
 
270
{NULL}  /* Sentinel */
 
271
};
 
272
 
 
273
PyTypeObject PatternType = {
 
274
PyObject_HEAD_INIT(NULL)
 
275
0,                         /*ob_size*/
 
276
"_pyo.Pattern_base",         /*tp_name*/
 
277
sizeof(Pattern),         /*tp_basicsize*/
 
278
0,                         /*tp_itemsize*/
 
279
(destructor)Pattern_dealloc, /*tp_dealloc*/
 
280
0,                         /*tp_print*/
 
281
0,                         /*tp_getattr*/
 
282
0,                         /*tp_setattr*/
 
283
0,                         /*tp_compare*/
 
284
0,                         /*tp_repr*/
 
285
0,             /*tp_as_number*/
 
286
0,                         /*tp_as_sequence*/
 
287
0,                         /*tp_as_mapping*/
 
288
0,                         /*tp_hash */
 
289
0,                         /*tp_call*/
 
290
0,                         /*tp_str*/
 
291
0,                         /*tp_getattro*/
 
292
0,                         /*tp_setattro*/
 
293
0,                         /*tp_as_buffer*/
 
294
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
 
295
"Pattern objects. Create a metronome.",           /* tp_doc */
 
296
(traverseproc)Pattern_traverse,   /* tp_traverse */
 
297
(inquiry)Pattern_clear,           /* tp_clear */
 
298
0,                             /* tp_richcompare */
 
299
0,                             /* tp_weaklistoffset */
 
300
0,                             /* tp_iter */
 
301
0,                             /* tp_iternext */
 
302
Pattern_methods,             /* tp_methods */
 
303
Pattern_members,             /* tp_members */
 
304
0,                      /* tp_getset */
 
305
0,                         /* tp_base */
 
306
0,                         /* tp_dict */
 
307
0,                         /* tp_descr_get */
 
308
0,                         /* tp_descr_set */
 
309
0,                         /* tp_dictoffset */
 
310
(initproc)Pattern_init,      /* tp_init */
 
311
0,                         /* tp_alloc */
 
312
Pattern_new,                 /* tp_new */
 
313
};
 
314
 
 
315
/***************/
 
316
/**** Score ****/
 
317
/***************/
 
318
typedef struct {
 
319
    pyo_audio_HEAD
 
320
    PyObject *input;
 
321
    Stream *input_stream;
 
322
    char *fname;
 
323
    char curfname[100];
 
324
    int last_value;
 
325
} Score;
 
326
 
 
327
static void
 
328
Score_selector(Score *self) {
 
329
    int i, inval, state, res;
 
330
    
 
331
    MYFLT *in = Stream_getData((Stream *)self->input_stream);
 
332
    
 
333
    for (i=0; i<self->bufsize; i++) {
 
334
        inval = (int)in[i];
 
335
        if (inval != self->last_value) {
 
336
            res = sprintf(self->curfname, "%s%i()\n", self->fname, inval);
 
337
            state = PyRun_SimpleString(self->curfname);
 
338
            self->last_value = inval;
 
339
        }    
 
340
    }
 
341
}
 
342
 
 
343
static void
 
344
Score_setProcMode(Score *self)
 
345
{
 
346
    self->proc_func_ptr = Score_selector;
 
347
}
 
348
 
 
349
static void
 
350
Score_compute_next_data_frame(Score *self)
 
351
{
 
352
    (*self->proc_func_ptr)(self);    
 
353
}
 
354
 
 
355
static int
 
356
Score_traverse(Score *self, visitproc visit, void *arg)
 
357
{
 
358
    pyo_VISIT
 
359
    Py_VISIT(self->input);    
 
360
    Py_VISIT(self->input_stream);    
 
361
    return 0;
 
362
}
 
363
 
 
364
static int 
 
365
Score_clear(Score *self)
 
366
{
 
367
    pyo_CLEAR
 
368
    Py_CLEAR(self->input);    
 
369
    Py_CLEAR(self->input_stream);
 
370
    return 0;
 
371
}
 
372
 
 
373
static void
 
374
Score_dealloc(Score* self)
 
375
{
 
376
    free(self->data);
 
377
        free(self->curfname);
 
378
    Score_clear(self);
 
379
    self->ob_type->tp_free((PyObject*)self);
 
380
}
 
381
 
 
382
static PyObject * Score_deleteStream(Score *self) { DELETE_STREAM };
 
383
 
 
384
static PyObject *
 
385
Score_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
386
{
 
387
    int i;
 
388
    Score *self;
 
389
    self = (Score *)type->tp_alloc(type, 0);
 
390
    
 
391
    self->last_value = -99;
 
392
    
 
393
    INIT_OBJECT_COMMON
 
394
    Stream_setFunctionPtr(self->stream, Score_compute_next_data_frame);
 
395
    self->mode_func_ptr = Score_setProcMode;
 
396
    
 
397
    return (PyObject *)self;
 
398
}
 
399
 
 
400
static int
 
401
Score_init(Score *self, PyObject *args, PyObject *kwds)
 
402
{
 
403
    PyObject *inputtmp, *input_streamtmp;
 
404
    
 
405
    static char *kwlist[] = {"input", "fname", NULL};
 
406
    
 
407
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|s", kwlist, &inputtmp, &self->fname))
 
408
        return -1; 
 
409
    
 
410
    INIT_INPUT_STREAM
 
411
    
 
412
    Py_INCREF(self->stream);
 
413
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
414
        
 
415
    (*self->mode_func_ptr)(self);
 
416
    
 
417
    Py_INCREF(self);
 
418
    return 0;
 
419
}
 
420
 
 
421
static PyObject * Score_getServer(Score* self) { GET_SERVER };
 
422
static PyObject * Score_getStream(Score* self) { GET_STREAM };
 
423
 
 
424
static PyObject * Score_play(Score *self, PyObject *args, PyObject *kwds) { PLAY };
 
425
static PyObject * Score_stop(Score *self) { STOP };
 
426
 
 
427
static PyMemberDef Score_members[] = {
 
428
{"server", T_OBJECT_EX, offsetof(Score, server), 0, "Pyo server."},
 
429
{"stream", T_OBJECT_EX, offsetof(Score, stream), 0, "Stream object."},
 
430
{NULL}  /* Sentinel */
 
431
};
 
432
 
 
433
static PyMethodDef Score_methods[] = {
 
434
{"getServer", (PyCFunction)Score_getServer, METH_NOARGS, "Returns server object."},
 
435
{"_getStream", (PyCFunction)Score_getStream, METH_NOARGS, "Returns stream object."},
 
436
{"deleteStream", (PyCFunction)Score_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
 
437
{"play", (PyCFunction)Score_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
 
438
{"stop", (PyCFunction)Score_stop, METH_NOARGS, "Stops computing."},
 
439
{NULL}  /* Sentinel */
 
440
};
 
441
 
 
442
PyTypeObject ScoreType = {
 
443
PyObject_HEAD_INIT(NULL)
 
444
0,                         /*ob_size*/
 
445
"_pyo.Score_base",         /*tp_name*/
 
446
sizeof(Score),         /*tp_basicsize*/
 
447
0,                         /*tp_itemsize*/
 
448
(destructor)Score_dealloc, /*tp_dealloc*/
 
449
0,                         /*tp_print*/
 
450
0,                         /*tp_getattr*/
 
451
0,                         /*tp_setattr*/
 
452
0,                         /*tp_compare*/
 
453
0,                         /*tp_repr*/
 
454
0,             /*tp_as_number*/
 
455
0,                         /*tp_as_sequence*/
 
456
0,                         /*tp_as_mapping*/
 
457
0,                         /*tp_hash */
 
458
0,                         /*tp_call*/
 
459
0,                         /*tp_str*/
 
460
0,                         /*tp_getattro*/
 
461
0,                         /*tp_setattro*/
 
462
0,                         /*tp_as_buffer*/
 
463
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
 
464
"Score objects. Calls numbered function from an integer count.",           /* tp_doc */
 
465
(traverseproc)Score_traverse,   /* tp_traverse */
 
466
(inquiry)Score_clear,           /* tp_clear */
 
467
0,                             /* tp_richcompare */
 
468
0,                             /* tp_weaklistoffset */
 
469
0,                             /* tp_iter */
 
470
0,                             /* tp_iternext */
 
471
Score_methods,             /* tp_methods */
 
472
Score_members,             /* tp_members */
 
473
0,                      /* tp_getset */
 
474
0,                         /* tp_base */
 
475
0,                         /* tp_dict */
 
476
0,                         /* tp_descr_get */
 
477
0,                         /* tp_descr_set */
 
478
0,                         /* tp_dictoffset */
 
479
(initproc)Score_init,      /* tp_init */
 
480
0,                         /* tp_alloc */
 
481
Score_new,                 /* tp_new */
 
482
};
 
483
 
 
484
/*****************/
 
485
/*** CallAfter ***/
 
486
/*****************/
 
487
typedef struct {
 
488
    pyo_audio_HEAD
 
489
    PyObject *callable;
 
490
    PyObject *arg;
 
491
    MYFLT time;
 
492
    MYFLT sampleToSec;
 
493
    double currentTime;
 
494
} CallAfter;
 
495
 
 
496
static void
 
497
CallAfter_generate(CallAfter *self) {
 
498
    int i;
 
499
    PyObject *tuple, *result;
 
500
 
 
501
    for (i=0; i<self->bufsize; i++) {
 
502
        if (self->currentTime >= self->time) {
 
503
            if (self->arg == Py_None)
 
504
                tuple = PyTuple_New(0);
 
505
            else {
 
506
                tuple = PyTuple_New(1);
 
507
                PyTuple_SET_ITEM(tuple, 0, self->arg);
 
508
            }
 
509
            result = PyObject_Call(self->callable, tuple, NULL);                
 
510
            if (result == NULL)
 
511
                PyErr_Print();
 
512
            PyObject_CallMethod((PyObject *)self, "stop", NULL);
 
513
            break;
 
514
        }
 
515
        self->currentTime += self->sampleToSec;
 
516
    }
 
517
}
 
518
 
 
519
static void
 
520
CallAfter_setProcMode(CallAfter *self)
 
521
{        
 
522
    self->proc_func_ptr = CallAfter_generate;
 
523
}
 
524
 
 
525
static void
 
526
CallAfter_compute_next_data_frame(CallAfter *self)
 
527
{
 
528
    (*self->proc_func_ptr)(self);     
 
529
}
 
530
 
 
531
static int
 
532
CallAfter_traverse(CallAfter *self, visitproc visit, void *arg)
 
533
{
 
534
    pyo_VISIT
 
535
    Py_VISIT(self->callable);
 
536
    Py_VISIT(self->arg);
 
537
    return 0;
 
538
}
 
539
 
 
540
static int 
 
541
CallAfter_clear(CallAfter *self)
 
542
{
 
543
    pyo_CLEAR
 
544
    Py_CLEAR(self->callable);
 
545
    Py_CLEAR(self->arg);
 
546
    return 0;
 
547
}
 
548
 
 
549
static void
 
550
CallAfter_dealloc(CallAfter* self)
 
551
{
 
552
    free(self->data);
 
553
    CallAfter_clear(self);
 
554
    self->ob_type->tp_free((PyObject*)self);
 
555
}
 
556
 
 
557
static PyObject * CallAfter_deleteStream(CallAfter *self) { DELETE_STREAM };
 
558
 
 
559
static PyObject *
 
560
CallAfter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
561
{
 
562
    int i;
 
563
    CallAfter *self;
 
564
    self = (CallAfter *)type->tp_alloc(type, 0);
 
565
    
 
566
    self->time = 1.;
 
567
    self->arg = Py_None;
 
568
    
 
569
    INIT_OBJECT_COMMON
 
570
    Stream_setFunctionPtr(self->stream, CallAfter_compute_next_data_frame);
 
571
    self->mode_func_ptr = CallAfter_setProcMode;
 
572
 
 
573
    self->sampleToSec = 1. / self->sr;
 
574
    self->currentTime = 0.;
 
575
    
 
576
    return (PyObject *)self;
 
577
}
 
578
 
 
579
static int
 
580
CallAfter_init(CallAfter *self, PyObject *args, PyObject *kwds)
 
581
{
 
582
    PyObject *calltmp=NULL, *argtmp=NULL;
 
583
    
 
584
    static char *kwlist[] = {"callable", "time", "arg", NULL};
 
585
    
 
586
    if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_FO, kwlist, &calltmp, &self->time, &argtmp))
 
587
        return -1; 
 
588
    
 
589
    if (! PyCallable_Check(calltmp))
 
590
        return -1;
 
591
 
 
592
    if (argtmp) {
 
593
        Py_DECREF(self->arg);
 
594
        Py_INCREF(argtmp);
 
595
        self->arg = argtmp;
 
596
    }
 
597
    
 
598
    Py_XDECREF(self->callable);
 
599
    self->callable = calltmp;
 
600
 
 
601
    Py_INCREF(self->stream);
 
602
    PyObject_CallMethod(self->server, "addStream", "O", self->stream);
 
603
    
 
604
    (*self->mode_func_ptr)(self);
 
605
        
 
606
    Py_INCREF(self);
 
607
    return 0;
 
608
}
 
609
 
 
610
static PyObject * CallAfter_getServer(CallAfter* self) { GET_SERVER };
 
611
static PyObject * CallAfter_getStream(CallAfter* self) { GET_STREAM };
 
612
 
 
613
static PyObject * CallAfter_play(CallAfter *self, PyObject *args, PyObject *kwds) { PLAY };
 
614
static PyObject * CallAfter_stop(CallAfter *self) { STOP };
 
615
 
 
616
static PyMemberDef CallAfter_members[] = {
 
617
{"server", T_OBJECT_EX, offsetof(CallAfter, server), 0, "Pyo server."},
 
618
{"stream", T_OBJECT_EX, offsetof(CallAfter, stream), 0, "Stream object."},
 
619
{NULL}  /* Sentinel */
 
620
};
 
621
 
 
622
static PyMethodDef CallAfter_methods[] = {
 
623
{"getServer", (PyCFunction)CallAfter_getServer, METH_NOARGS, "Returns server object."},
 
624
{"_getStream", (PyCFunction)CallAfter_getStream, METH_NOARGS, "Returns stream object."},
 
625
{"deleteStream", (PyCFunction)CallAfter_deleteStream, METH_NOARGS, "Remove stream from server and delete the object."},
 
626
{"play", (PyCFunction)CallAfter_play, METH_VARARGS|METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
 
627
{"stop", (PyCFunction)CallAfter_stop, METH_NOARGS, "Stops computing."},
 
628
{NULL}  /* Sentinel */
 
629
};
 
630
 
 
631
PyTypeObject CallAfterType = {
 
632
PyObject_HEAD_INIT(NULL)
 
633
0,                         /*ob_size*/
 
634
"_pyo.CallAfter_base",         /*tp_name*/
 
635
sizeof(CallAfter),         /*tp_basicsize*/
 
636
0,                         /*tp_itemsize*/
 
637
(destructor)CallAfter_dealloc, /*tp_dealloc*/
 
638
0,                         /*tp_print*/
 
639
0,                         /*tp_getattr*/
 
640
0,                         /*tp_setattr*/
 
641
0,                         /*tp_compare*/
 
642
0,                         /*tp_repr*/
 
643
0,             /*tp_as_number*/
 
644
0,                         /*tp_as_sequence*/
 
645
0,                         /*tp_as_mapping*/
 
646
0,                         /*tp_hash */
 
647
0,                         /*tp_call*/
 
648
0,                         /*tp_str*/
 
649
0,                         /*tp_getattro*/
 
650
0,                         /*tp_setattro*/
 
651
0,                         /*tp_as_buffer*/
 
652
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
 
653
"CallAfter objects. Create a metronome.",           /* tp_doc */
 
654
(traverseproc)CallAfter_traverse,   /* tp_traverse */
 
655
(inquiry)CallAfter_clear,           /* tp_clear */
 
656
0,                             /* tp_richcompare */
 
657
0,                             /* tp_weaklistoffset */
 
658
0,                             /* tp_iter */
 
659
0,                             /* tp_iternext */
 
660
CallAfter_methods,             /* tp_methods */
 
661
CallAfter_members,             /* tp_members */
 
662
0,                      /* tp_getset */
 
663
0,                         /* tp_base */
 
664
0,                         /* tp_dict */
 
665
0,                         /* tp_descr_get */
 
666
0,                         /* tp_descr_set */
 
667
0,                         /* tp_dictoffset */
 
668
(initproc)CallAfter_init,      /* tp_init */
 
669
0,                         /* tp_alloc */
 
670
CallAfter_new,                 /* tp_new */
 
671
};