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

« back to all changes in this revision

Viewing changes to src/engine/streammodule.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:
28
28
 
29
29
int stream_id = 1;
30
30
 
31
 
/* Stream object */
32
31
int 
33
32
Stream_getNewStreamId() 
34
33
{
35
34
    return stream_id++;
36
35
}
37
36
 
 
37
static int
 
38
Stream_traverse(Stream *self, visitproc visit, void *arg)
 
39
{
 
40
    Py_VISIT(self->streamobject);    
 
41
    return 0;
 
42
}
 
43
 
 
44
static int 
 
45
Stream_clear(Stream *self)
 
46
{
 
47
    Py_CLEAR(self->streamobject);    
 
48
    return 0;
 
49
}
 
50
 
38
51
static void
39
52
Stream_dealloc(Stream* self)
40
53
{
41
 
    free(self->data);
42
 
    Py_XDECREF(self->streamobject);
 
54
    self->data = NULL;
 
55
    Stream_clear(self);
43
56
    self->ob_type->tp_free((PyObject*)self);
44
57
}
45
58
 
46
 
static PyObject *
47
 
Stream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
48
 
{
49
 
    Stream *self;
50
 
    MAKE_NEW_STREAM(self, type, NULL);
51
 
    return (PyObject *)self;
52
 
}
53
 
 
54
 
static int
55
 
Stream_init(Stream *self, PyObject *args, PyObject *kwds)
56
 
{
57
 
    PyObject *object=NULL, *tmp;
58
 
     
59
 
    static char *kwlist[] = {"streamobject", NULL};
60
 
 
61
 
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &object)){
62
 
        return -1;
63
 
    }
64
 
 
65
 
    if (object) {
66
 
        tmp = self->streamobject;
67
 
        Py_INCREF(object);
68
 
        self->streamobject = object;
69
 
        self->active = 0;
70
 
        self->chnl = 0;
71
 
        self->todac = 0;
72
 
        self->duration = 0;
73
 
        self->bufferCountWait = 0;
74
 
        self->bufferCount = 0;
75
 
        Py_DECREF(tmp);
76
 
    }
77
 
 
78
 
    return 0;
79
 
}
80
 
 
81
 
PyObject *
82
 
Stream_getStreamObject(Stream *self)
83
 
{
84
 
    Py_INCREF(self->streamobject);
85
 
    return self->streamobject;
86
 
}
87
 
 
88
59
int
89
60
Stream_getStreamId(Stream *self)
90
61
{
171
142
    return Py_BuildValue("i", self->sid);
172
143
}
173
144
 
 
145
PyObject *
 
146
Stream_getStreamObject(Stream *self)
 
147
{
 
148
    Py_INCREF(self->streamobject);
 
149
    return self->streamobject;
 
150
}
 
151
 
 
152
PyObject *
 
153
Stream_isPlaying(Stream *self)
 
154
{
 
155
    if (self->active || self->todac)
 
156
        Py_RETURN_TRUE;
 
157
    else 
 
158
        Py_RETURN_FALSE;
 
159
}
 
160
 
 
161
PyObject *
 
162
Stream_isOutputting(Stream *self)
 
163
{
 
164
    if (self->todac)
 
165
        Py_RETURN_TRUE;
 
166
    else 
 
167
        Py_RETURN_FALSE;
 
168
}
 
169
 
174
170
static PyMethodDef Stream_methods[] = {
175
171
{"getValue", (PyCFunction)Stream_getValue, METH_NOARGS, "Returns the first sample of the current buffer."},
176
172
{"getId", (PyCFunction)Stream_getId, METH_NOARGS, "Returns the ID of assigned to this stream."},
 
173
{"getStreamObject", (PyCFunction)Stream_getStreamObject, METH_NOARGS, "Returns the object associated with this stream."},
 
174
{"isPlaying", (PyCFunction)Stream_isPlaying, METH_NOARGS, "Returns True if the stream is playing, otherwise, returns False."},
 
175
{"isOutputting", (PyCFunction)Stream_isOutputting, METH_NOARGS, "Returns True if the stream outputs to dac, otherwise, returns False."},
177
176
{NULL}  /* Sentinel */
178
177
};
179
178
 
217
216
The second stream contains the samples from the 500Hz waveform, and so on.\n\n\
218
217
User can call a specific stream of an object by giving the position of the stream\n\
219
218
between brackets, beginning at 0. To retrieve only the third stream of our object:\n\n\
220
 
    a[2].out()\n\
 
219
    a[2].out()\n\n\
 
220
The method getStreamObject() can be called on a Stream object to retrieve the \n\
 
221
XXX_base object associated with this Stream. This method can be used by developers who\n\
 
222
are debugging their programs!\n\n\
221
223
", /* tp_doc */
222
224
    0, /* tp_traverse */
223
225
    0, /* tp_clear */
233
235
    0, /* tp_descr_get */
234
236
    0, /* tp_descr_set */
235
237
    0, /* tp_dictoffset */
236
 
    (initproc)Stream_init, /* tp_init */
 
238
    0, /* tp_init */
237
239
    0, /* tp_alloc */
238
 
    Stream_new, /* tp_new */
 
240
    0, /* tp_new */
239
241
};
240
242
 
 
243
/************************/
241
244
/* TriggerStream object */
 
245
/************************/
242
246
static void
243
247
TriggerStream_dealloc(TriggerStream* self)
244
248
{
245
 
    free(self->data);
 
249
    self->data = NULL;
246
250
    self->ob_type->tp_free((PyObject*)self);
247
251
}
248
252
 
249
 
static PyObject *
250
 
TriggerStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
251
 
{
252
 
    TriggerStream *self;
253
 
    MAKE_NEW_TRIGGER_STREAM(self, type, NULL);
254
 
    return (PyObject *)self;
255
 
}
256
 
 
257
 
static int
258
 
TriggerStream_init(TriggerStream *self)
259
 
{
260
 
    return 0;
261
 
}
262
 
 
263
253
MYFLT *
264
254
TriggerStream_getData(TriggerStream *self)
265
255
{
297
287
    "\n\
298
288
    Trigger stream object. For internal use only. \n\n\
299
289
    ", /* tp_doc */
300
 
    0, /* tp_traverse */
301
 
    0, /* tp_clear */
 
290
    (traverseproc)Stream_traverse, /* tp_traverse */
 
291
    (inquiry)Stream_clear, /* tp_clear */
302
292
    0, /* tp_richcompare */
303
293
    0, /* tp_weaklistoffset */
304
294
    0, /* tp_iter */
311
301
    0, /* tp_descr_get */
312
302
    0, /* tp_descr_set */
313
303
    0, /* tp_dictoffset */
314
 
    (initproc)TriggerStream_init, /* tp_init */
 
304
    0, /* tp_init */
315
305
    0, /* tp_alloc */
316
 
    TriggerStream_new, /* tp_new */
 
306
    0, /* tp_new */
317
307
};