Debian Codegraph @

src/objects/mmlmodule.c

raw
1 /**************************************************************************
2 * Copyright 2009-2019 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 Lesser General Public License as *
9 * published by the Free Software Foundation, either version 3 of the *
10 * License, or (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 Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License 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 static MYFLT MML_DURATIONS[10] = {0.03125, 0.0625, 0.09375, 0.125, 0.1875, 0.25, 0.375, 0.5, 0.75, 1.0};
29 static MYFLT MML_VOLUMES[101] = {0.0, 1.0000000000000002e-06, 8.000000000000001e-06, 2.6999999999999996e-05, 6.400000000000001e-05, 0.00012500000000000003, 0.00021599999999999996, 0.0003430000000000001, 0.0005120000000000001, 0.0007289999999999999, 0.0010000000000000002, 0.001331, 0.0017279999999999997, 0.002197, 0.0027440000000000008, 0.0033749999999999995, 0.004096000000000001, 0.004913000000000001, 0.0058319999999999995, 0.0068590000000000005, 0.008000000000000002, 0.009260999999999998, 0.010648, 0.012167, 0.013823999999999998, 0.015625, 0.017576, 0.019683000000000003, 0.021952000000000006, 0.024388999999999994, 0.026999999999999996, 0.029790999999999998, 0.032768000000000005, 0.035937000000000004, 0.039304000000000006, 0.04287499999999999, 0.046655999999999996, 0.050653, 0.054872000000000004, 0.059319000000000004, 0.06400000000000002, 0.06892099999999998, 0.07408799999999999, 0.079507, 0.085184, 0.09112500000000001, 0.097336, 0.10382299999999998, 0.11059199999999998, 0.11764899999999999, 0.125, 0.13265100000000002, 0.140608, 0.148877, 0.15746400000000002, 0.16637500000000005, 0.17561600000000005, 0.18519299999999994, 0.19511199999999995, 0.20537899999999998, 0.21599999999999997, 0.226981, 0.23832799999999998, 0.250047, 0.26214400000000004, 0.274625, 0.28749600000000003, 0.30076300000000006, 0.31443200000000004, 0.32850899999999994, 0.3429999999999999, 0.3579109999999999, 0.37324799999999997, 0.38901699999999995, 0.405224, 0.421875, 0.43897600000000003, 0.456533, 0.47455200000000003, 0.49303900000000006, 0.5120000000000001, 0.531441, 0.5513679999999999, 0.5717869999999999, 0.5927039999999999, 0.6141249999999999, 0.636056, 0.658503, 0.681472, 0.7049690000000001, 0.7290000000000001, 0.7535710000000001, 0.778688, 0.8043570000000001, 0.8305839999999999, 0.8573749999999999, 0.8847359999999999, 0.912673, 0.9411919999999999, 0.970299, 1.0};
30
31 /****************/
32 /**** MMLMain *****/
33 /****************/
34 typedef struct
35 {
36 pyo_audio_HEAD
37 PyObject *sequence;
38 PyObject *pending;
39 PyObject *pitches;
40 int to_stop;
41 int loop;
42 int poly;
43 int updateAtEnd;
44 Py_ssize_t num_events;
45 Py_ssize_t count;
46 int voiceCount;
47 double sampleToSec;
48 double currentTime;
49 int currentDurationCode;
50 double currentDuration;
51 double defaultDuration;
52 int currentVolume;
53 double currentAmplitude;
54 double currentTempo;
55 MYFLT currentDivider;
56 MYFLT currentX;
57 MYFLT currentY;
58 MYFLT currentZ;
59 double durOfWhole;
60 MYFLT *buffer_streams;
61 MYFLT *fre_buffer_streams;
62 MYFLT *amp_buffer_streams;
63 MYFLT *dur_buffer_streams;
64 MYFLT *end_buffer_streams;
65 MYFLT *x_buffer_streams;
66 MYFLT *y_buffer_streams;
67 MYFLT *z_buffer_streams;
68 MYFLT *curFrequencies;
69 MYFLT *curAmplitudes;
70 MYFLT *curDurations;
71 MYFLT *curXs;
72 MYFLT *curYs;
73 MYFLT *curZs;
74 int octave;
75 Py_ssize_t loopStart[128];
76 Py_ssize_t loopCount[128];
77 Py_ssize_t currentLoop;
78 } MMLMain;
79
80 static void
81 MMLMain_consume(MMLMain *self, int i)
82 {
83 long pos = 0;
84 double duration = 0.0;
85
86 if (self->count == self->num_events)
87 {
88 self->count = 0;
89 self->end_buffer_streams[i + self->voiceCount * self->bufsize] = 1.0;
90
91 if (self->loop == 0)
92 {
93 self->buffer_streams[i + self->voiceCount * self->bufsize] = 0.0;
94 self->to_stop = 1;
95 return;
96 }
97
98 if (self->pending != NULL)
99 {
100 Py_XDECREF(self->sequence);
101 self->sequence = self->pending;
102 self->num_events = PyList_Size(self->sequence);
103 self->pending = NULL;
104 }
105 }
106
107 PyObject *event = PyList_GetItem(self->sequence, self->count);
108
109 self->count++;
110
111 Py_ssize_t mpos = 0;
112 Py_ssize_t pos1 = 0;
113 Py_ssize_t pos2 = 0;
114
115 // Handle random values from a set.
116 PyObject *randSetToken = PyUnicode_FromString("?[");
117 while (PyUnicode_Contains(event, randSetToken))
118 {
119 mpos = PyUnicode_Find(event, PyUnicode_FromString("?"), 0, PySequence_Size(event), 1);
120 pos1 = PyUnicode_Find(event, PyUnicode_FromString("["), 0, PySequence_Size(event), 1);
121 pos2 = PyUnicode_Find(event, PyUnicode_FromString("]"), 0, PySequence_Size(event), 1);
122 PyObject *choices = PyUnicode_Split(PySequence_GetSlice(event, pos1 + 1, pos2), PyUnicode_FromString(","), -1);
123 Py_ssize_t chsize = PyList_Size(choices);
124 PyObject *chosen = PyList_GetItem(choices, (Py_ssize_t)(RANDOM_UNIFORM * chsize));
125 PyObject *head = PySequence_GetSlice(event, 0, mpos);
126 PyObject *tail = PySequence_GetSlice(event, pos2 + 1, PySequence_Size(event));
127 event = PyUnicode_Concat(head, chosen);
128 event = PyUnicode_Concat(event, tail);
129 }
130 Py_DECREF(randSetToken);
131
132 // Handle random values from a range.
133 PyObject *randRangeToken = PyUnicode_FromString("?{");
134 while (PyUnicode_Contains(event, randRangeToken))
135 {
136 mpos = PyUnicode_Find(event, PyUnicode_FromString("?"), 0, PySequence_Size(event), 1);
137 pos1 = PyUnicode_Find(event, PyUnicode_FromString("{"), 0, PySequence_Size(event), 1);
138 pos2 = PyUnicode_Find(event, PyUnicode_FromString("}"), 0, PySequence_Size(event), 1);
139 PyObject *bounds = PyUnicode_Split(PySequence_GetSlice(event, pos1 + 1, pos2), PyUnicode_FromString(","), -1);
140 Py_ssize_t bsize = PyList_Size(bounds);
141 MYFLT value = 0.0, low = 0.0, high = 1.0;
142
143 if (bsize == 1)
144 {
145 if (PyUnicode_GET_LENGTH(PyList_GetItem(bounds, 0)) > 0)
146 {
147 high = (MYFLT)PyFloat_AsDouble(PyNumber_Float(PyList_GetItem(bounds, 0)));
148 value = RANDOM_UNIFORM * high;
149 }
150 else
151 {
152 value = RANDOM_UNIFORM;
153 }
154 }
155 else if (bsize >= 2)
156 {
157 low = PyFloat_AsDouble(PyNumber_Float(PyList_GetItem(bounds, 0)));
158 high = PyFloat_AsDouble(PyNumber_Float(PyList_GetItem(bounds, 1)));
159 value = RANDOM_UNIFORM * (high - low) + low;
160 }
161
162 char temp[128];
163 sprintf(temp, "%f", value);
164 PyObject *val = PyUnicode_FromString(temp);
165 PyObject *head = PySequence_GetSlice(event, 0, mpos);
166 PyObject *tail = PySequence_GetSlice(event, pos2 + 1, PySequence_Size(event));
167 event = PyUnicode_Concat(head, val);
168 event = PyUnicode_Concat(event, tail);
169 }
170 Py_DECREF(randRangeToken);
171
172 Py_ssize_t eventSize = PySequence_Size(event);
173
174 PyObject *first = PySequence_GetItem(event, 0);
175 PyObject *openBarToken = PyUnicode_FromString("|:");
176 PyObject *closeBarToken = PyUnicode_FromString(":|");
177 PyObject *plusToken = PyUnicode_FromString("+");
178 PyObject *minusToken = PyUnicode_FromString("-");
179
180 PyObject *second = NULL;
181 PyObject *eventTwoFirstChars = NULL;
182 if (eventSize >= 2)
183 {
184 second = PySequence_GetItem(event, 1);
185 eventTwoFirstChars = PySequence_GetSlice(event, 0, 2);
186 }
187
188 // Octave
189 if (PyUnicode_Compare(first, PyUnicode_FromString("o")) == 0)
190 {
191 if (PyUnicode_Compare(second, plusToken) == 0)
192 {
193 if (eventSize > 2)
194 {
195 self->octave += 12 * PyLong_AsLong(PyLong_FromUnicodeObject(PySequence_GetItem(event, 2), 10));
196 }
197 else
198 {
199 self->octave += 12;
200 }
201 }
202 else if (PyUnicode_Compare(second, minusToken) == 0)
203 {
204 if (eventSize > 2)
205 {
206 self->octave -= 12 * PyLong_AsLong(PyLong_FromUnicodeObject(PySequence_GetItem(event, 2), 10));
207 }
208 else
209 {
210 self->octave -= 12;
211 }
212 }
213 else
214 {
215 PyObject *octaveValue = PySequence_GetItem(event, 1);
216 PyObject *octaveValueAsLong = PyLong_FromUnicodeObject(octaveValue, 10);
217 self->octave = 12 * PyLong_AsLong(octaveValueAsLong);
218 Py_DECREF(octaveValue);
219 Py_DECREF(octaveValueAsLong);
220 }
221
222 MMLMain_consume(self, i);
223 }
224 // tempo
225 else if (PyUnicode_Compare(first, PyUnicode_FromString("t")) == 0)
226 {
227 if (PyUnicode_Compare(second, plusToken) == 0)
228 {
229 if (eventSize > 2)
230 {
231 PyObject *currentTempoValue = PySequence_GetSlice(event, 2, eventSize);
232 PyObject *currentTempoValueAsFloat = PyNumber_Float(currentTempoValue);
233 self->currentTempo += PyFloat_AsDouble(currentTempoValueAsFloat);
234 Py_DECREF(currentTempoValue);
235 Py_DECREF(currentTempoValueAsFloat);
236 }
237 else
238 {
239 self->currentTempo += 1.0;
240 }
241 }
242 else if (PyUnicode_Compare(second, minusToken) == 0)
243 {
244 if (eventSize > 2)
245 {
246 PyObject *currentTempoValue = PySequence_GetSlice(event, 2, eventSize);
247 PyObject *currentTempoValueAsFloat = PyNumber_Float(currentTempoValue);
248 self->currentTempo -= PyFloat_AsDouble(currentTempoValueAsFloat);
249 Py_DECREF(currentTempoValue);
250 Py_DECREF(currentTempoValueAsFloat);
251 }
252 else
253 {
254 self->currentTempo -= 1.0;
255 }
256 }
257 else
258 {
259 PyObject *tempoValue = PySequence_GetSlice(event, 1, eventSize);
260 PyObject *tempoValueAsFloat = PyNumber_Float(tempoValue);
261 self->currentTempo = PyFloat_AsDouble(tempoValueAsFloat);
262 Py_DECREF(tempoValue);
263 Py_DECREF(tempoValueAsFloat);
264 }
265
266 self->durOfWhole = 4 * 60.0 / self->currentTempo;
267 self->defaultDuration = self->durOfWhole * MML_DURATIONS[1] / self->currentDivider;
268 MMLMain_consume(self, i);
269 }
270 // volume
271 else if (PyUnicode_Compare(first, PyUnicode_FromString("v")) == 0)
272 {
273 if (PyUnicode_Compare(second, plusToken) == 0)
274 {
275 if (eventSize > 2)
276 {
277 PyObject *currentVolumeUpValue = PySequence_GetSlice(event, 2, eventSize);
278 PyObject *currentVolumeUpValueAsLong = PyLong_FromUnicodeObject(currentVolumeUpValue, 10);
279 self->currentVolume += PyLong_AsLong(currentVolumeUpValueAsLong);
280 Py_DECREF(currentVolumeUpValue);
281 Py_DECREF(currentVolumeUpValueAsLong);
282 }
283 else
284 {
285 self->currentVolume++;
286 }
287 }
288 else if (PyUnicode_Compare(second, minusToken) == 0)
289 {
290 if (eventSize > 2)
291 {
292 PyObject *currentVolumeDownValue = PySequence_GetSlice(event, 2, eventSize);
293 PyObject *currentVolumeDownValueAsLong = PyLong_FromUnicodeObject(currentVolumeDownValue, 10);
294 self->currentVolume -= PyLong_AsLong(currentVolumeDownValueAsLong);
295 Py_DECREF(currentVolumeDownValue);
296 Py_DECREF(currentVolumeDownValueAsLong);
297 }
298 else
299 {
300 self->currentVolume--;
301 }
302 }
303 else
304 {
305 PyObject *currentVolumeValue = PySequence_GetSlice(event, 1, eventSize);
306 PyObject *currentVolumeValueAsLong = PyLong_FromUnicodeObject(currentVolumeValue, 10);
307 self->currentVolume = PyLong_AsLong(currentVolumeValueAsLong);
308 Py_DECREF(currentVolumeValue);
309 Py_DECREF(currentVolumeValueAsLong);
310 }
311
312 self->currentVolume = self->currentVolume < 0 ? 0 : self->currentVolume > 100 ? 100 : self->currentVolume;
313 self->currentAmplitude = MML_VOLUMES[self->currentVolume];
314 MMLMain_consume(self, i);
315 }
316 // divider
317 else if (PyUnicode_Compare(first, PyUnicode_FromString("/")) == 0)
318 {
319 PyObject *currentDividerValue = PySequence_GetSlice(event, 1, eventSize);
320 PyObject *currentDividerValueAsLong = PyLong_FromUnicodeObject(currentDividerValue, 10);
321 self->currentDivider = (MYFLT)PyLong_AsLong(currentDividerValueAsLong);
322 Py_DECREF(currentDividerValue);
323 Py_DECREF(currentDividerValueAsLong);
324 MMLMain_consume(self, i);
325 }
326 // x
327 else if (PyUnicode_Compare(first, PyUnicode_FromString("x")) == 0)
328 {
329 if (PyUnicode_Compare(second, plusToken) == 0)
330 {
331 if (eventSize > 2)
332 {
333 PyObject *currentXUpValue = PySequence_GetSlice(event, 2, eventSize);
334 PyObject *currentXUpValueAsFloat = PyNumber_Float(currentXUpValue);
335 self->currentX += (MYFLT)PyFloat_AsDouble(currentXUpValueAsFloat);
336 Py_DECREF(currentXUpValue);
337 Py_DECREF(currentXUpValueAsFloat);
338 }
339 else
340 {
341 self->currentX += 0.01;
342 }
343 }
344 else if (PyUnicode_Compare(second, minusToken) == 0)
345 {
346 if (eventSize > 2)
347 {
348 PyObject *currentXDownValue = PySequence_GetSlice(event, 2, eventSize);
349 PyObject *currentXDownValueAsFloat = PyNumber_Float(currentXDownValue);
350 self->currentX -= (MYFLT)PyFloat_AsDouble(currentXDownValueAsFloat);
351 Py_DECREF(currentXDownValue);
352 Py_DECREF(currentXDownValueAsFloat);
353 }
354 else
355 {
356 self->currentX -= 0.01;
357 }
358 }
359 else
360 {
361 PyObject *currentXValue = PySequence_GetSlice(event, 1, eventSize);
362 PyObject *currentXValueAsFloat = PyNumber_Float(currentXValue);
363 self->currentX = (MYFLT)PyFloat_AsDouble(currentXValueAsFloat);
364 Py_DECREF(currentXValue);
365 Py_DECREF(currentXValueAsFloat);
366 }
367
368 MMLMain_consume(self, i);
369 }
370 // y
371 else if (PyUnicode_Compare(first, PyUnicode_FromString("y")) == 0)
372 {
373 if (PyUnicode_Compare(second, plusToken) == 0)
374 {
375 if (eventSize > 2)
376 {
377 PyObject *currentYUpValue = PySequence_GetSlice(event, 2, eventSize);
378 PyObject *currentYUpValueAsFloat = PyNumber_Float(currentYUpValue);
379 self->currentY += (MYFLT)PyFloat_AsDouble(currentYUpValueAsFloat);
380 Py_DECREF(currentYUpValue);
381 Py_DECREF(currentYUpValueAsFloat);
382 }
383 else
384 {
385 self->currentY += 0.01;
386 }
387 }
388 else if (PyUnicode_Compare(second, minusToken) == 0)
389 {
390 if (eventSize > 2)
391 {
392 PyObject *currentYDownValue = PySequence_GetSlice(event, 2, eventSize);
393 PyObject *currentYDownValueAsFloat = PyNumber_Float(currentYDownValue);
394 self->currentY -= (MYFLT)PyFloat_AsDouble(currentYDownValueAsFloat);
395 Py_DECREF(currentYDownValue);
396 Py_DECREF(currentYDownValueAsFloat);
397 }
398 else
399 {
400 self->currentY -= 0.01;
401 }
402 }
403 else
404 {
405 PyObject *currentYValue = PySequence_GetSlice(event, 1, eventSize);
406 PyObject *currentYValueAsFloat = PyNumber_Float(currentYValue);
407 self->currentY = (MYFLT)PyFloat_AsDouble(currentYValueAsFloat);
408 Py_DECREF(currentYValue);
409 Py_DECREF(currentYValueAsFloat);
410 }
411
412 MMLMain_consume(self, i);
413 }
414 // z
415 else if (PyUnicode_Compare(first, PyUnicode_FromString("z")) == 0)
416 {
417 if (PyUnicode_Compare(second, plusToken) == 0)
418 {
419 if (eventSize > 2)
420 {
421 PyObject *currentZUpValue = PySequence_GetSlice(event, 2, eventSize);
422 PyObject *currentZUpValueAsFloat = PyNumber_Float(currentZUpValue);
423 self->currentZ += (MYFLT)PyFloat_AsDouble(currentZUpValueAsFloat);
424 Py_DECREF(currentZUpValue);
425 Py_DECREF(currentZUpValueAsFloat);
426 }
427 else
428 {
429 self->currentZ += 0.01;
430 }
431 }
432 else if (PyUnicode_Compare(second, minusToken) == 0)
433 {
434 if (eventSize > 2)
435 {
436 PyObject *currentZDownValue = PySequence_GetSlice(event, 2, eventSize);
437 PyObject *currentZDownValueAsFloat = PyNumber_Float(currentZDownValue);
438 self->currentZ -= (MYFLT)PyFloat_AsDouble(currentZDownValueAsFloat);
439 Py_DECREF(currentZDownValue);
440 Py_DECREF(currentZDownValueAsFloat);
441 }
442 else
443 {
444 self->currentZ -= 0.01;
445 }
446 }
447 else
448 {
449 PyObject *currentZValue = PySequence_GetSlice(event, 1, eventSize);
450 PyObject *currentZValueAsFloat = PyNumber_Float(currentZValue);
451 self->currentZ = (MYFLT)PyFloat_AsDouble(currentZValueAsFloat);
452 Py_DECREF(currentZValue);
453 Py_DECREF(currentZValueAsFloat);
454 }
455
456 MMLMain_consume(self, i);
457 }
458 // Opening repeat bar
459 else if (PyUnicode_Compare(event, openBarToken) == 0)
460 {
461 self->currentLoop++;
462 self->loopStart[self->currentLoop] = self->count;
463 self->loopCount[self->currentLoop] = 0;
464 MMLMain_consume(self, i);
465 }
466 // Closing repeat bar
467 else if (eventSize >= 2 && PyUnicode_Compare(eventTwoFirstChars, closeBarToken) == 0)
468 {
469 int repeats;
470
471 if (eventSize == 2)
472 {
473 repeats = 2;
474 }
475 else
476 {
477 PyObject *repeatsValue = PySequence_GetSlice(event, 2, eventSize);
478 repeats = PyLong_AsLong(PyLong_FromUnicodeObject(repeatsValue, 10));
479 Py_DECREF(repeatsValue);
480 }
481
482 self->loopCount[self->currentLoop]++;
483
484 if (self->loopCount[self->currentLoop] < repeats)
485 {
486 self->count = self->loopStart[self->currentLoop];
487 }
488 else
489 {
490 self->currentLoop--;
491 }
492
493 MMLMain_consume(self, i);
494 }
495 // rest
496 else if (PyUnicode_Compare(first, PyUnicode_FromString("r")) == 0)
497 {
498 if (self->currentDuration == -1)
499 {
500 duration = self->defaultDuration;
501 }
502 else
503 {
504 duration = self->durOfWhole * MML_DURATIONS[self->currentDurationCode] / self->currentDivider;
505 }
506
507 if (eventSize > 1)
508 {
509 pos = PyLong_AsLong(PyLong_FromUnicodeObject(PySequence_GetItem(event, 1), 10));
510 pos = pos < 0 ? 0 : pos > 9 ? 9 : pos;
511 self->currentDurationCode = pos;
512 duration = self->durOfWhole * MML_DURATIONS[pos] / self->currentDivider;
513 }
514
515 self->currentDuration = duration;
516 self->curAmplitudes[self->voiceCount] = 0.0;
517 self->curDurations[self->voiceCount] = (MYFLT)duration;
518 self->curXs[self->voiceCount] = self->currentX;
519 self->curYs[self->voiceCount] = self->currentY;
520 self->curZs[self->voiceCount] = self->currentZ;
521 self->voiceCount++;
522
523 if (self->voiceCount >= self->poly)
524 {
525 self->voiceCount = 0;
526 }
527 }
528 // note event.
529 else if (PyDict_Contains(self->pitches, first))
530 {
531 if (self->currentDuration == -1)
532 {
533 duration = self->defaultDuration;
534 }
535 else
536 {
537 duration = self->durOfWhole * MML_DURATIONS[self->currentDurationCode] / self->currentDivider;
538 }
539
540 long pitch = PyLong_AsLong(PyDict_GetItem(self->pitches, first)) + self->octave;
541
542 if (eventSize > 2)
543 {
544 if (PyUnicode_Compare(second, plusToken) == 0)
545 {
546 pitch += 1;
547 }
548 else if (PyUnicode_Compare(second, minusToken) == 0)
549 {
550 pitch -= 1;
551 }
552
553 pos = PyLong_AsLong(PyLong_FromUnicodeObject(PySequence_GetItem(event, 2), 10));
554 pos = pos < 0 ? 0 : pos > 9 ? 9 : pos;
555 self->currentDurationCode = pos;
556 duration = self->durOfWhole * MML_DURATIONS[pos] / self->currentDivider;
557 }
558 else if (eventSize > 1)
559 {
560 if (PyUnicode_Compare(second, plusToken) == 0)
561 {
562 pitch += 1;
563 }
564 else if (PyUnicode_Compare(second, minusToken) == 0)
565 {
566 pitch -= 1;
567 }
568 else
569 {
570 PyObject *posValueAsLong = PyLong_FromUnicodeObject(second, 10);
571 pos = PyLong_AsLong(posValueAsLong);
572 Py_DECREF(posValueAsLong);
573 pos = pos < 0 ? 0 : pos > 9 ? 9 : pos;
574 self->currentDurationCode = pos;
575 duration = self->durOfWhole * MML_DURATIONS[pos] / self->currentDivider;
576 }
577 }
578
579 self->currentDuration = duration;
580 self->curFrequencies[self->voiceCount] = 440.0 * MYPOW(2.0, (pitch - 69) / 12.0);
581 self->curAmplitudes[self->voiceCount] = self->currentAmplitude;
582 self->curDurations[self->voiceCount] = (MYFLT)duration;
583 self->curXs[self->voiceCount] = self->currentX;
584 self->curYs[self->voiceCount] = self->currentY;
585 self->curZs[self->voiceCount] = self->currentZ;
586 self->voiceCount++;
587
588 if (self->voiceCount >= self->poly)
589 {
590 self->voiceCount = 0;
591 }
592 }
593
594 Py_DECREF(first);
595 Py_DECREF(openBarToken);
596 Py_DECREF(closeBarToken);
597 Py_DECREF(plusToken);
598 Py_DECREF(minusToken);
599 if (eventSize >= 2)
600 {
601 Py_DECREF(second);
602 Py_DECREF(eventTwoFirstChars);
603 }
604 }
605
606 static void
607 MMLMain_generate(MMLMain *self)
608 {
609 int i, j;
610
611 for (i = 0; i < (self->poly * self->bufsize); i++)
612 {
613 self->buffer_streams[i] = self->end_buffer_streams[i] = 0.0;
614 }
615
616 if (self->num_events == 0)
617 {
618 return;
619 }
620
621 if (self->to_stop)
622 {
623 PyObject_CallMethod((PyObject *)self, "stop", NULL);
624 self->to_stop = 0;
625 return;
626 }
627
628 if (self->currentDuration == -1.0)
629 {
630 self->buffer_streams[self->voiceCount * self->bufsize] = 1.0;
631 MMLMain_consume(self, 0);
632 }
633
634 for (i = 0; i < self->bufsize; i++)
635 {
636 if (self->currentTime >= self->currentDuration && self->to_stop == 0)
637 {
638 self->currentTime -= self->currentDuration;
639 self->buffer_streams[i + self->voiceCount * self->bufsize] = 1.0;
640 MMLMain_consume(self, i);
641 }
642
643 if (self->to_stop == 0)
644 {
645 for (j = 0; j < self->poly; j++)
646 {
647 self->fre_buffer_streams[i + j * self->bufsize] = self->curFrequencies[j];
648 self->dur_buffer_streams[i + j * self->bufsize] = self->curDurations[j];
649 self->amp_buffer_streams[i + j * self->bufsize] = self->curAmplitudes[j];
650 self->x_buffer_streams[i + j * self->bufsize] = self->curXs[j];
651 self->y_buffer_streams[i + j * self->bufsize] = self->curYs[j];
652 self->z_buffer_streams[i + j * self->bufsize] = self->curZs[j];
653 }
654 }
655
656 self->currentTime += self->sampleToSec;
657 }
658 }
659
660 MYFLT *
661 MMLMain_getSamplesBuffer(MMLMain *self)
662 {
663 return (MYFLT *)self->buffer_streams;
664 }
665
666 MYFLT *
667 MMLMain_getFreqBuffer(MMLMain *self)
668 {
669 return (MYFLT *)self->fre_buffer_streams;
670 }
671
672 MYFLT *
673 MMLMain_getAmpBuffer(MMLMain *self)
674 {
675 return (MYFLT *)self->amp_buffer_streams;
676 }
677
678 MYFLT *
679 MMLMain_getDurBuffer(MMLMain *self)
680 {
681 return (MYFLT *)self->dur_buffer_streams;
682 }
683
684 MYFLT *
685 MMLMain_getEndBuffer(MMLMain *self)
686 {
687 return (MYFLT *)self->end_buffer_streams;
688 }
689
690 MYFLT *
691 MMLMain_getXBuffer(MMLMain *self)
692 {
693 return (MYFLT *)self->x_buffer_streams;
694 }
695
696 MYFLT *
697 MMLMain_getYBuffer(MMLMain *self)
698 {
699 return (MYFLT *)self->y_buffer_streams;
700 }
701
702 MYFLT *
703 MMLMain_getZBuffer(MMLMain *self)
704 {
705 return (MYFLT *)self->z_buffer_streams;
706 }
707
708 static void
709 MMLMain_setProcMode(MMLMain *self)
710 {
711 self->proc_func_ptr = MMLMain_generate;
712 }
713
714 static void
715 MMLMain_compute_next_data_frame(MMLMain *self)
716 {
717 (*self->proc_func_ptr)(self);
718 }
719
720 static int
721 MMLMain_traverse(MMLMain *self, visitproc visit, void *arg)
722 {
723 pyo_VISIT
724 Py_VISIT(self->sequence);
725 Py_VISIT(self->pitches);
726
727 if (self->pending != NULL)
728 {
729 Py_VISIT(self->pending);
730 }
731
732 return 0;
733 }
734
735 static int
736 MMLMain_clear(MMLMain *self)
737 {
738 pyo_CLEAR
739 Py_CLEAR(self->sequence);
740 Py_CLEAR(self->pitches);
741
742 if (self->pending != NULL)
743 {
744 Py_CLEAR(self->pending);
745 }
746
747 return 0;
748 }
749
750 static void
751 MMLMain_dealloc(MMLMain* self)
752 {
753 pyo_DEALLOC
754 PyMem_RawFree(self->buffer_streams);
755 PyMem_RawFree(self->fre_buffer_streams);
756 PyMem_RawFree(self->amp_buffer_streams);
757 PyMem_RawFree(self->dur_buffer_streams);
758 PyMem_RawFree(self->end_buffer_streams);
759 PyMem_RawFree(self->x_buffer_streams);
760 PyMem_RawFree(self->y_buffer_streams);
761 PyMem_RawFree(self->z_buffer_streams);
762 PyMem_RawFree(self->curFrequencies);
763 PyMem_RawFree(self->curAmplitudes);
764 PyMem_RawFree(self->curDurations);
765 PyMem_RawFree(self->curXs);
766 PyMem_RawFree(self->curYs);
767 PyMem_RawFree(self->curZs);
768 MMLMain_clear(self);
769 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
770 Py_TYPE(self)->tp_free((PyObject*)self);
771 }
772
773 static PyObject *
774 MMLMain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
775 {
776 int i;
777 MMLMain *self;
778 self = (MMLMain *)type->tp_alloc(type, 0);
779
780 self->pitches = PyDict_New();
781 PyDict_SetItem(self->pitches, PyUnicode_FromString("c"), PyLong_FromLong(0));
782 PyDict_SetItem(self->pitches, PyUnicode_FromString("d"), PyLong_FromLong(2));
783 PyDict_SetItem(self->pitches, PyUnicode_FromString("e"), PyLong_FromLong(4));
784 PyDict_SetItem(self->pitches, PyUnicode_FromString("f"), PyLong_FromLong(5));
785 PyDict_SetItem(self->pitches, PyUnicode_FromString("g"), PyLong_FromLong(7));
786 PyDict_SetItem(self->pitches, PyUnicode_FromString("a"), PyLong_FromLong(9));
787 PyDict_SetItem(self->pitches, PyUnicode_FromString("b"), PyLong_FromLong(11));
788
789 INIT_OBJECT_COMMON
790 Stream_setFunctionPtr(self->stream, MMLMain_compute_next_data_frame);
791 self->mode_func_ptr = MMLMain_setProcMode;
792
793 Stream_setStreamActive(self->stream, 0);
794
795 self->pending = NULL;
796 self->to_stop = 0;
797 self->durOfWhole = 2.0;
798 self->voiceCount = 0;
799 self->octave = 60;
800 self->loop = 0;
801 self->updateAtEnd = 0;
802 self->num_events = 0;
803 self->count = 0;
804 self->sampleToSec = 1.0 / self->sr;
805 self->currentDuration = -1.0;
806 self->currentDurationCode = 1;
807 self->currentTime = 0.0;
808 self->currentTempo = 120.0;
809 self->currentVolume = 50;
810 self->currentAmplitude = 0.125;
811 self->currentDivider = 1.0;
812 self->durOfWhole = 4 * 60.0 / self->currentTempo;
813 self->defaultDuration = self->durOfWhole * MML_DURATIONS[self->currentDurationCode] / self->currentDivider;
814
815 static char *kwlist[] = {"loop", "poly", "updateAtEnd", NULL};
816
817 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|iii", kwlist, &self->loop, &self->poly, &self->updateAtEnd))
818 Py_RETURN_NONE;
819
820 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
821
822 (*self->mode_func_ptr)(self);
823
824 self->buffer_streams = (MYFLT *)PyMem_RawRealloc(self->buffer_streams, self->poly * self->bufsize * sizeof(MYFLT));
825 self->fre_buffer_streams = (MYFLT *)PyMem_RawRealloc(self->fre_buffer_streams, self->poly * self->bufsize * sizeof(MYFLT));
826 self->amp_buffer_streams = (MYFLT *)PyMem_RawRealloc(self->amp_buffer_streams, self->poly * self->bufsize * sizeof(MYFLT));
827 self->dur_buffer_streams = (MYFLT *)PyMem_RawRealloc(self->dur_buffer_streams, self->poly * self->bufsize * sizeof(MYFLT));
828 self->end_buffer_streams = (MYFLT *)PyMem_RawRealloc(self->end_buffer_streams, self->poly * self->bufsize * sizeof(MYFLT));
829 self->x_buffer_streams = (MYFLT *)PyMem_RawRealloc(self->x_buffer_streams, self->poly * self->bufsize * sizeof(MYFLT));
830 self->y_buffer_streams = (MYFLT *)PyMem_RawRealloc(self->y_buffer_streams, self->poly * self->bufsize * sizeof(MYFLT));
831 self->z_buffer_streams = (MYFLT *)PyMem_RawRealloc(self->z_buffer_streams, self->poly * self->bufsize * sizeof(MYFLT));
832
833 for (i = 0; i < (self->poly * self->bufsize); i++)
834 {
835 self->buffer_streams[i] = self->fre_buffer_streams[i] = self->amp_buffer_streams[i] = self->dur_buffer_streams[i] = self->end_buffer_streams[i] = 0.0;
836 self->x_buffer_streams[i] = self->y_buffer_streams[i] = self->z_buffer_streams[i] = 0.0;
837 }
838
839 self->curFrequencies = (MYFLT *)PyMem_RawRealloc(self->curFrequencies, self->poly * sizeof(MYFLT));
840 self->curAmplitudes = (MYFLT *)PyMem_RawRealloc(self->curAmplitudes, self->poly * sizeof(MYFLT));
841 self->curDurations = (MYFLT *)PyMem_RawRealloc(self->curDurations, self->poly * sizeof(MYFLT));
842 self->curXs = (MYFLT *)PyMem_RawRealloc(self->curXs, self->poly * sizeof(MYFLT));
843 self->curYs = (MYFLT *)PyMem_RawRealloc(self->curYs, self->poly * sizeof(MYFLT));
844 self->curZs = (MYFLT *)PyMem_RawRealloc(self->curZs, self->poly * sizeof(MYFLT));
845
846 for (i = 0; i < self->poly; i++)
847 {
848 self->curFrequencies[i] = self->curAmplitudes[i] = self->curDurations[i] = self->curXs[i] = self->curYs[i] = self->curZs[i] = 0.0;
849 }
850
851 self->currentLoop = 0;
852
853 for (i = 0; i < 128; i++)
854 {
855 self->loopStart[i] = self->loopCount[i] = 0;
856 }
857
858 return (PyObject *)self;
859 }
860
861 static PyObject * MMLMain_getServer(MMLMain* self) { GET_SERVER };
862 static PyObject * MMLMain_getStream(MMLMain* self) { GET_STREAM };
863
864 static PyObject * MMLMain_play(MMLMain *self, PyObject *args, PyObject *kwds)
865 {
866 self->voiceCount = 0;
867 PLAY
868 };
869 static PyObject * MMLMain_stop(MMLMain *self, PyObject *args, PyObject *kwds) { STOP };
870
871 static PyObject *
872 MMLMain_setSequence(MMLMain *self, PyObject *arg)
873 {
874 ASSERT_ARG_NOT_NULL
875
876 if (PyList_Check(arg))
877 {
878 Py_XDECREF(self->sequence);
879 self->sequence = arg;
880 Py_INCREF(self->sequence);
881 self->num_events = PyList_Size(self->sequence);
882 }
883
884 Py_RETURN_NONE;
885 }
886
887 static PyObject *
888 MMLMain_setPending(MMLMain *self, PyObject *arg)
889 {
890 ASSERT_ARG_NOT_NULL
891
892 if (PyList_Check(arg))
893 {
894 Py_XDECREF(self->pending);
895 self->pending = arg;
896 Py_INCREF(self->pending);
897 }
898
899 Py_RETURN_NONE;
900 }
901
902 static PyObject *
903 MMLMain_update(MMLMain *self, PyObject *arg)
904 {
905 ASSERT_ARG_NOT_NULL
906
907 if (PyList_Check(arg))
908 {
909 Py_INCREF(arg);
910
911 if (self->updateAtEnd && self->num_events != 0)
912 {
913 MMLMain_setPending(self, arg);
914 }
915 else
916 {
917 MMLMain_setSequence(self, arg);
918 self->count = 0;
919 self->currentDuration = -1.0;
920 }
921 }
922
923 Py_RETURN_NONE;
924 }
925
926 static PyMemberDef MMLMain_members[] =
927 {
928 {"server", T_OBJECT_EX, offsetof(MMLMain, server), 0, "Pyo server."},
929 {"stream", T_OBJECT_EX, offsetof(MMLMain, stream), 0, "Stream object."},
930 {"sequence", T_OBJECT_EX, offsetof(MMLMain, sequence), 0, "Sequence of events."},
931 {NULL} /* Sentinel */
932 };
933
934 static PyMethodDef MMLMain_methods[] =
935 {
936 {"getServer", (PyCFunction)MMLMain_getServer, METH_NOARGS, "Returns server object."},
937 {"_getStream", (PyCFunction)MMLMain_getStream, METH_NOARGS, "Returns stream object."},
938 {"play", (PyCFunction)MMLMain_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
939 {"stop", (PyCFunction)MMLMain_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
940 {"setPending", (PyCFunction)MMLMain_setPending, METH_O, "Sets a new sequence of events."},
941 {"setSequence", (PyCFunction)MMLMain_setSequence, METH_O, "Sets a new sequence of events."},
942 {"update", (PyCFunction)MMLMain_update, METH_O, "Sets a new sequence of events."},
943 {NULL} /* Sentinel */
944 };
945
946 PyTypeObject MMLMainType =
947 {
948 PyVarObject_HEAD_INIT(NULL, 0)
949 "_pyo.MMLMain_base", /*tp_name*/
950 sizeof(MMLMain), /*tp_basicsize*/
951 0, /*tp_itemsize*/
952 (destructor)MMLMain_dealloc, /*tp_dealloc*/
953 0, /*tp_print*/
954 0, /*tp_getattr*/
955 0, /*tp_setattr*/
956 0, /*tp_as_async (tp_compare in Python 2)*/
957 0, /*tp_repr*/
958 0, /*tp_as_number*/
959 0, /*tp_as_sequence*/
960 0, /*tp_as_mapping*/
961 0, /*tp_hash */
962 0, /*tp_call*/
963 0, /*tp_str*/
964 0, /*tp_getattro*/
965 0, /*tp_setattro*/
966 0, /*tp_as_buffer*/
967 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
968 "MMLMain objects. Read a MML sequence.", /* tp_doc */
969 (traverseproc)MMLMain_traverse, /* tp_traverse */
970 (inquiry)MMLMain_clear, /* tp_clear */
971 0, /* tp_richcompare */
972 0, /* tp_weaklistoffset */
973 0, /* tp_iter */
974 0, /* tp_iternext */
975 MMLMain_methods, /* tp_methods */
976 MMLMain_members, /* tp_members */
977 0, /* tp_getset */
978 0, /* tp_base */
979 0, /* tp_dict */
980 0, /* tp_descr_get */
981 0, /* tp_descr_set */
982 0, /* tp_dictoffset */
983 0, /* tp_init */
984 0, /* tp_alloc */
985 MMLMain_new, /* tp_new */
986 };
987
988 /************************************************************************************************/
989 /* MML streamer object per channel */
990 /************************************************************************************************/
991 typedef struct
992 {
993 pyo_audio_HEAD
994 MMLMain *mainPlayer;
995 int chnl;
996 int modebuffer[2];
997 } MML;
998
999 static void MML_postprocessing_ii(MML *self) { POST_PROCESSING_II };
1000 static void MML_postprocessing_ai(MML *self) { POST_PROCESSING_AI };
1001 static void MML_postprocessing_ia(MML *self) { POST_PROCESSING_IA };
1002 static void MML_postprocessing_aa(MML *self) { POST_PROCESSING_AA };
1003 static void MML_postprocessing_ireva(MML *self) { POST_PROCESSING_IREVA };
1004 static void MML_postprocessing_areva(MML *self) { POST_PROCESSING_AREVA };
1005 static void MML_postprocessing_revai(MML *self) { POST_PROCESSING_REVAI };
1006 static void MML_postprocessing_revaa(MML *self) { POST_PROCESSING_REVAA };
1007 static void MML_postprocessing_revareva(MML *self) { POST_PROCESSING_REVAREVA };
1008
1009 static void
1010 MML_setProcMode(MML *self)
1011 {
1012 int muladdmode;
1013 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1014
1015 switch (muladdmode)
1016 {
1017 case 0:
1018 self->muladd_func_ptr = MML_postprocessing_ii;
1019 break;
1020
1021 case 1:
1022 self->muladd_func_ptr = MML_postprocessing_ai;
1023 break;
1024
1025 case 2:
1026 self->muladd_func_ptr = MML_postprocessing_revai;
1027 break;
1028
1029 case 10:
1030 self->muladd_func_ptr = MML_postprocessing_ia;
1031 break;
1032
1033 case 11:
1034 self->muladd_func_ptr = MML_postprocessing_aa;
1035 break;
1036
1037 case 12:
1038 self->muladd_func_ptr = MML_postprocessing_revaa;
1039 break;
1040
1041 case 20:
1042 self->muladd_func_ptr = MML_postprocessing_ireva;
1043 break;
1044
1045 case 21:
1046 self->muladd_func_ptr = MML_postprocessing_areva;
1047 break;
1048
1049 case 22:
1050 self->muladd_func_ptr = MML_postprocessing_revareva;
1051 break;
1052 }
1053 }
1054
1055 static void
1056 MML_compute_next_data_frame(MML *self)
1057 {
1058 int i;
1059 MYFLT *tmp;
1060 int offset = self->chnl * self->bufsize;
1061 tmp = MMLMain_getSamplesBuffer((MMLMain *)self->mainPlayer);
1062
1063 for (i = 0; i < self->bufsize; i++)
1064 {
1065 self->data[i] = tmp[i + offset];
1066 }
1067
1068 (*self->muladd_func_ptr)(self);
1069 }
1070
1071 static int
1072 MML_traverse(MML *self, visitproc visit, void *arg)
1073 {
1074 pyo_VISIT
1075 Py_VISIT(self->mainPlayer);
1076 return 0;
1077 }
1078
1079 static int
1080 MML_clear(MML *self)
1081 {
1082 pyo_CLEAR
1083 Py_CLEAR(self->mainPlayer);
1084 return 0;
1085 }
1086
1087 static void
1088 MML_dealloc(MML* self)
1089 {
1090 pyo_DEALLOC
1091 MML_clear(self);
1092 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1093 Py_TYPE(self)->tp_free((PyObject*)self);
1094 }
1095
1096 static PyObject *
1097 MML_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1098 {
1099 int i;
1100 PyObject *maintmp = NULL;
1101 MML *self;
1102 self = (MML *)type->tp_alloc(type, 0);
1103
1104 self->chnl = 0;
1105 self->modebuffer[0] = 0;
1106 self->modebuffer[1] = 0;
1107
1108 INIT_OBJECT_COMMON
1109 Stream_setFunctionPtr(self->stream, MML_compute_next_data_frame);
1110 self->mode_func_ptr = MML_setProcMode;
1111
1112 static char *kwlist[] = {"mainPlayer", "chnl", NULL};
1113
1114 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &maintmp, &self->chnl))
1115 Py_RETURN_NONE;
1116
1117 self->mainPlayer = (MMLMain *)maintmp;
1118 Py_INCREF(self->mainPlayer);
1119
1120 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1121
1122 (*self->mode_func_ptr)(self);
1123
1124 return (PyObject *)self;
1125 }
1126
1127 static PyObject * MML_getServer(MML* self) { GET_SERVER };
1128 static PyObject * MML_getStream(MML* self) { GET_STREAM };
1129 static PyObject * MML_setMul(MML *self, PyObject *arg) { SET_MUL };
1130 static PyObject * MML_setAdd(MML *self, PyObject *arg) { SET_ADD };
1131 static PyObject * MML_setSub(MML *self, PyObject *arg) { SET_SUB };
1132 static PyObject * MML_setDiv(MML *self, PyObject *arg) { SET_DIV };
1133
1134 static PyObject * MML_play(MML *self, PyObject *args, PyObject *kwds) { PLAY };
1135 static PyObject * MML_out(MML *self, PyObject *args, PyObject *kwds) { OUT };
1136 static PyObject * MML_stop(MML *self, PyObject *args, PyObject *kwds) { STOP };
1137
1138 static PyObject * MML_multiply(MML *self, PyObject *arg) { MULTIPLY };
1139 static PyObject * MML_inplace_multiply(MML *self, PyObject *arg) { INPLACE_MULTIPLY };
1140 static PyObject * MML_add(MML *self, PyObject *arg) { ADD };
1141 static PyObject * MML_inplace_add(MML *self, PyObject *arg) { INPLACE_ADD };
1142 static PyObject * MML_sub(MML *self, PyObject *arg) { SUB };
1143 static PyObject * MML_inplace_sub(MML *self, PyObject *arg) { INPLACE_SUB };
1144 static PyObject * MML_div(MML *self, PyObject *arg) { DIV };
1145 static PyObject * MML_inplace_div(MML *self, PyObject *arg) { INPLACE_DIV };
1146
1147 static PyMemberDef MML_members[] =
1148 {
1149 {"server", T_OBJECT_EX, offsetof(MML, server), 0, "Pyo server."},
1150 {"stream", T_OBJECT_EX, offsetof(MML, stream), 0, "Stream object."},
1151 {"mul", T_OBJECT_EX, offsetof(MML, mul), 0, "Mul factor."},
1152 {"add", T_OBJECT_EX, offsetof(MML, add), 0, "Add factor."},
1153 {NULL} /* Sentinel */
1154 };
1155
1156 static PyMethodDef MML_methods[] =
1157 {
1158 {"getServer", (PyCFunction)MML_getServer, METH_NOARGS, "Returns server object."},
1159 {"_getStream", (PyCFunction)MML_getStream, METH_NOARGS, "Returns stream object."},
1160 {"play", (PyCFunction)MML_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1161 {"out", (PyCFunction)MML_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1162 {"stop", (PyCFunction)MML_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1163 {"setMul", (PyCFunction)MML_setMul, METH_O, "Sets oscillator mul factor."},
1164 {"setAdd", (PyCFunction)MML_setAdd, METH_O, "Sets oscillator add factor."},
1165 {"setSub", (PyCFunction)MML_setSub, METH_O, "Sets inverse add factor."},
1166 {"setDiv", (PyCFunction)MML_setDiv, METH_O, "Sets inverse mul factor."},
1167 {NULL} /* Sentinel */
1168 };
1169
1170 static PyNumberMethods MML_as_number =
1171 {
1172 (binaryfunc)MML_add, /*nb_add*/
1173 (binaryfunc)MML_sub, /*nb_subtract*/
1174 (binaryfunc)MML_multiply, /*nb_multiply*/
1175 0, /*nb_remainder*/
1176 0, /*nb_divmod*/
1177 0, /*nb_power*/
1178 0, /*nb_neg*/
1179 0, /*nb_pos*/
1180 0, /*(unaryfunc)array_abs,*/
1181 0, /*nb_nonzero*/
1182 0, /*nb_invert*/
1183 0, /*nb_lshift*/
1184 0, /*nb_rshift*/
1185 0, /*nb_and*/
1186 0, /*nb_xor*/
1187 0, /*nb_or*/
1188 0, /*nb_int*/
1189 0, /*nb_long*/
1190 0, /*nb_float*/
1191 (binaryfunc)MML_inplace_add, /*inplace_add*/
1192 (binaryfunc)MML_inplace_sub, /*inplace_subtract*/
1193 (binaryfunc)MML_inplace_multiply, /*inplace_multiply*/
1194 0, /*inplace_remainder*/
1195 0, /*inplace_power*/
1196 0, /*inplace_lshift*/
1197 0, /*inplace_rshift*/
1198 0, /*inplace_and*/
1199 0, /*inplace_xor*/
1200 0, /*inplace_or*/
1201 0, /*nb_floor_divide*/
1202 (binaryfunc)MML_div, /*nb_true_divide*/
1203 0, /*nb_inplace_floor_divide*/
1204 (binaryfunc)MML_inplace_div, /*nb_inplace_true_divide*/
1205 0, /* nb_index */
1206 };
1207
1208 PyTypeObject MMLType =
1209 {
1210 PyVarObject_HEAD_INIT(NULL, 0)
1211 "_pyo.MML_base", /*tp_name*/
1212 sizeof(MML), /*tp_basicsize*/
1213 0, /*tp_itemsize*/
1214 (destructor)MML_dealloc, /*tp_dealloc*/
1215 0, /*tp_print*/
1216 0, /*tp_getattr*/
1217 0, /*tp_setattr*/
1218 0, /*tp_as_async (tp_compare in Python 2)*/
1219 0, /*tp_repr*/
1220 &MML_as_number, /*tp_as_number*/
1221 0, /*tp_as_sequence*/
1222 0, /*tp_as_mapping*/
1223 0, /*tp_hash */
1224 0, /*tp_call*/
1225 0, /*tp_str*/
1226 0, /*tp_getattro*/
1227 0, /*tp_setattro*/
1228 0, /*tp_as_buffer*/
1229 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1230 "MML objects. Reads a channel from a MMLMain.", /* tp_doc */
1231 (traverseproc)MML_traverse, /* tp_traverse */
1232 (inquiry)MML_clear, /* tp_clear */
1233 0, /* tp_richcompare */
1234 0, /* tp_weaklistoffset */
1235 0, /* tp_iter */
1236 0, /* tp_iternext */
1237 MML_methods, /* tp_methods */
1238 MML_members, /* tp_members */
1239 0, /* tp_getset */
1240 0, /* tp_base */
1241 0, /* tp_dict */
1242 0, /* tp_descr_get */
1243 0, /* tp_descr_set */
1244 0, /* tp_dictoffset */
1245 0, /* tp_init */
1246 0, /* tp_alloc */
1247 MML_new, /* tp_new */
1248 };
1249
1250 /************************************************************************************************/
1251 /* MMLFreqStream object per channel */
1252 /************************************************************************************************/
1253 typedef struct
1254 {
1255 pyo_audio_HEAD
1256 MMLMain *mainPlayer;
1257 int chnl;
1258 int modebuffer[2];
1259 } MMLFreqStream;
1260
1261 static void MMLFreqStream_postprocessing_ii(MMLFreqStream *self) { POST_PROCESSING_II };
1262 static void MMLFreqStream_postprocessing_ai(MMLFreqStream *self) { POST_PROCESSING_AI };
1263 static void MMLFreqStream_postprocessing_ia(MMLFreqStream *self) { POST_PROCESSING_IA };
1264 static void MMLFreqStream_postprocessing_aa(MMLFreqStream *self) { POST_PROCESSING_AA };
1265 static void MMLFreqStream_postprocessing_ireva(MMLFreqStream *self) { POST_PROCESSING_IREVA };
1266 static void MMLFreqStream_postprocessing_areva(MMLFreqStream *self) { POST_PROCESSING_AREVA };
1267 static void MMLFreqStream_postprocessing_revai(MMLFreqStream *self) { POST_PROCESSING_REVAI };
1268 static void MMLFreqStream_postprocessing_revaa(MMLFreqStream *self) { POST_PROCESSING_REVAA };
1269 static void MMLFreqStream_postprocessing_revareva(MMLFreqStream *self) { POST_PROCESSING_REVAREVA };
1270
1271 static void
1272 MMLFreqStream_setProcMode(MMLFreqStream *self)
1273 {
1274 int muladdmode;
1275 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1276
1277 switch (muladdmode)
1278 {
1279 case 0:
1280 self->muladd_func_ptr = MMLFreqStream_postprocessing_ii;
1281 break;
1282
1283 case 1:
1284 self->muladd_func_ptr = MMLFreqStream_postprocessing_ai;
1285 break;
1286
1287 case 2:
1288 self->muladd_func_ptr = MMLFreqStream_postprocessing_revai;
1289 break;
1290
1291 case 10:
1292 self->muladd_func_ptr = MMLFreqStream_postprocessing_ia;
1293 break;
1294
1295 case 11:
1296 self->muladd_func_ptr = MMLFreqStream_postprocessing_aa;
1297 break;
1298
1299 case 12:
1300 self->muladd_func_ptr = MMLFreqStream_postprocessing_revaa;
1301 break;
1302
1303 case 20:
1304 self->muladd_func_ptr = MMLFreqStream_postprocessing_ireva;
1305 break;
1306
1307 case 21:
1308 self->muladd_func_ptr = MMLFreqStream_postprocessing_areva;
1309 break;
1310
1311 case 22:
1312 self->muladd_func_ptr = MMLFreqStream_postprocessing_revareva;
1313 break;
1314 }
1315 }
1316
1317 static void
1318 MMLFreqStream_compute_next_data_frame(MMLFreqStream *self)
1319 {
1320 int i;
1321 MYFLT *tmp;
1322 int offset = self->chnl * self->bufsize;
1323 tmp = MMLMain_getFreqBuffer((MMLMain *)self->mainPlayer);
1324
1325 for (i = 0; i < self->bufsize; i++)
1326 {
1327 self->data[i] = tmp[i + offset];
1328 }
1329
1330 (*self->muladd_func_ptr)(self);
1331 }
1332
1333 static int
1334 MMLFreqStream_traverse(MMLFreqStream *self, visitproc visit, void *arg)
1335 {
1336 pyo_VISIT
1337 Py_VISIT(self->mainPlayer);
1338 return 0;
1339 }
1340
1341 static int
1342 MMLFreqStream_clear(MMLFreqStream *self)
1343 {
1344 pyo_CLEAR
1345 Py_CLEAR(self->mainPlayer);
1346 return 0;
1347 }
1348
1349 static void
1350 MMLFreqStream_dealloc(MMLFreqStream* self)
1351 {
1352 pyo_DEALLOC
1353 MMLFreqStream_clear(self);
1354 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1355 Py_TYPE(self)->tp_free((PyObject*)self);
1356 }
1357
1358 static PyObject *
1359 MMLFreqStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1360 {
1361 int i;
1362 PyObject *maintmp = NULL;
1363 MMLFreqStream *self;
1364 self = (MMLFreqStream *)type->tp_alloc(type, 0);
1365
1366 self->chnl = 0;
1367 self->modebuffer[0] = 0;
1368 self->modebuffer[1] = 0;
1369
1370 INIT_OBJECT_COMMON
1371 Stream_setFunctionPtr(self->stream, MMLFreqStream_compute_next_data_frame);
1372 self->mode_func_ptr = MMLFreqStream_setProcMode;
1373
1374 static char *kwlist[] = {"mainPlayer", "chnl", NULL};
1375
1376 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &maintmp, &self->chnl))
1377 Py_RETURN_NONE;
1378
1379 self->mainPlayer = (MMLMain *)maintmp;
1380 Py_INCREF(self->mainPlayer);
1381
1382 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1383
1384 (*self->mode_func_ptr)(self);
1385
1386 return (PyObject *)self;
1387 }
1388
1389 static PyObject * MMLFreqStream_getServer(MMLFreqStream* self) { GET_SERVER };
1390 static PyObject * MMLFreqStream_getStream(MMLFreqStream* self) { GET_STREAM };
1391 static PyObject * MMLFreqStream_setMul(MMLFreqStream *self, PyObject *arg) { SET_MUL };
1392 static PyObject * MMLFreqStream_setAdd(MMLFreqStream *self, PyObject *arg) { SET_ADD };
1393 static PyObject * MMLFreqStream_setSub(MMLFreqStream *self, PyObject *arg) { SET_SUB };
1394 static PyObject * MMLFreqStream_setDiv(MMLFreqStream *self, PyObject *arg) { SET_DIV };
1395
1396 static PyObject * MMLFreqStream_play(MMLFreqStream *self, PyObject *args, PyObject *kwds) { PLAY };
1397 static PyObject * MMLFreqStream_out(MMLFreqStream *self, PyObject *args, PyObject *kwds) { OUT };
1398 static PyObject * MMLFreqStream_stop(MMLFreqStream *self, PyObject *args, PyObject *kwds) { STOP };
1399
1400 static PyObject * MMLFreqStream_multiply(MMLFreqStream *self, PyObject *arg) { MULTIPLY };
1401 static PyObject * MMLFreqStream_inplace_multiply(MMLFreqStream *self, PyObject *arg) { INPLACE_MULTIPLY };
1402 static PyObject * MMLFreqStream_add(MMLFreqStream *self, PyObject *arg) { ADD };
1403 static PyObject * MMLFreqStream_inplace_add(MMLFreqStream *self, PyObject *arg) { INPLACE_ADD };
1404 static PyObject * MMLFreqStream_sub(MMLFreqStream *self, PyObject *arg) { SUB };
1405 static PyObject * MMLFreqStream_inplace_sub(MMLFreqStream *self, PyObject *arg) { INPLACE_SUB };
1406 static PyObject * MMLFreqStream_div(MMLFreqStream *self, PyObject *arg) { DIV };
1407 static PyObject * MMLFreqStream_inplace_div(MMLFreqStream *self, PyObject *arg) { INPLACE_DIV };
1408
1409 static PyMemberDef MMLFreqStream_members[] =
1410 {
1411 {"server", T_OBJECT_EX, offsetof(MMLFreqStream, server), 0, "Pyo server."},
1412 {"stream", T_OBJECT_EX, offsetof(MMLFreqStream, stream), 0, "Stream object."},
1413 {"mul", T_OBJECT_EX, offsetof(MMLFreqStream, mul), 0, "Mul factor."},
1414 {"add", T_OBJECT_EX, offsetof(MMLFreqStream, add), 0, "Add factor."},
1415 {NULL} /* Sentinel */
1416 };
1417
1418 static PyMethodDef MMLFreqStream_methods[] =
1419 {
1420 {"getServer", (PyCFunction)MMLFreqStream_getServer, METH_NOARGS, "Returns server object."},
1421 {"_getStream", (PyCFunction)MMLFreqStream_getStream, METH_NOARGS, "Returns stream object."},
1422 {"play", (PyCFunction)MMLFreqStream_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1423 {"out", (PyCFunction)MMLFreqStream_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1424 {"stop", (PyCFunction)MMLFreqStream_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1425 {"setMul", (PyCFunction)MMLFreqStream_setMul, METH_O, "Sets oscillator mul factor."},
1426 {"setAdd", (PyCFunction)MMLFreqStream_setAdd, METH_O, "Sets oscillator add factor."},
1427 {"setSub", (PyCFunction)MMLFreqStream_setSub, METH_O, "Sets inverse add factor."},
1428 {"setDiv", (PyCFunction)MMLFreqStream_setDiv, METH_O, "Sets inverse mul factor."},
1429 {NULL} /* Sentinel */
1430 };
1431
1432 static PyNumberMethods MMLFreqStream_as_number =
1433 {
1434 (binaryfunc)MMLFreqStream_add, /*nb_add*/
1435 (binaryfunc)MMLFreqStream_sub, /*nb_subtract*/
1436 (binaryfunc)MMLFreqStream_multiply, /*nb_multiply*/
1437 0, /*nb_remainder*/
1438 0, /*nb_divmod*/
1439 0, /*nb_power*/
1440 0, /*nb_neg*/
1441 0, /*nb_pos*/
1442 0, /*(unaryfunc)array_abs,*/
1443 0, /*nb_nonzero*/
1444 0, /*nb_invert*/
1445 0, /*nb_lshift*/
1446 0, /*nb_rshift*/
1447 0, /*nb_and*/
1448 0, /*nb_xor*/
1449 0, /*nb_or*/
1450 0, /*nb_int*/
1451 0, /*nb_long*/
1452 0, /*nb_float*/
1453 (binaryfunc)MMLFreqStream_inplace_add, /*inplace_add*/
1454 (binaryfunc)MMLFreqStream_inplace_sub, /*inplace_subtract*/
1455 (binaryfunc)MMLFreqStream_inplace_multiply, /*inplace_multiply*/
1456 0, /*inplace_remainder*/
1457 0, /*inplace_power*/
1458 0, /*inplace_lshift*/
1459 0, /*inplace_rshift*/
1460 0, /*inplace_and*/
1461 0, /*inplace_xor*/
1462 0, /*inplace_or*/
1463 0, /*nb_floor_divide*/
1464 (binaryfunc)MMLFreqStream_div, /*nb_true_divide*/
1465 0, /*nb_inplace_floor_divide*/
1466 (binaryfunc)MMLFreqStream_inplace_div, /*nb_inplace_true_divide*/
1467 0, /* nb_index */
1468 };
1469
1470 PyTypeObject MMLFreqStreamType =
1471 {
1472 PyVarObject_HEAD_INIT(NULL, 0)
1473 "_pyo.MMLFreqStream_base", /*tp_name*/
1474 sizeof(MMLFreqStream), /*tp_basicsize*/
1475 0, /*tp_itemsize*/
1476 (destructor)MMLFreqStream_dealloc, /*tp_dealloc*/
1477 0, /*tp_print*/
1478 0, /*tp_getattr*/
1479 0, /*tp_setattr*/
1480 0, /*tp_as_async (tp_compare in Python 2)*/
1481 0, /*tp_repr*/
1482 &MMLFreqStream_as_number, /*tp_as_number*/
1483 0, /*tp_as_sequence*/
1484 0, /*tp_as_mapping*/
1485 0, /*tp_hash */
1486 0, /*tp_call*/
1487 0, /*tp_str*/
1488 0, /*tp_getattro*/
1489 0, /*tp_setattro*/
1490 0, /*tp_as_buffer*/
1491 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1492 "MMLFreqStream objects. Reads the current Freq from a MMLMain object.", /* tp_doc */
1493 (traverseproc)MMLFreqStream_traverse, /* tp_traverse */
1494 (inquiry)MMLFreqStream_clear, /* tp_clear */
1495 0, /* tp_richcompare */
1496 0, /* tp_weaklistoffset */
1497 0, /* tp_iter */
1498 0, /* tp_iternext */
1499 MMLFreqStream_methods, /* tp_methods */
1500 MMLFreqStream_members, /* tp_members */
1501 0, /* tp_getset */
1502 0, /* tp_base */
1503 0, /* tp_dict */
1504 0, /* tp_descr_get */
1505 0, /* tp_descr_set */
1506 0, /* tp_dictoffset */
1507 0, /* tp_init */
1508 0, /* tp_alloc */
1509 MMLFreqStream_new, /* tp_new */
1510 };
1511
1512 /************************************************************************************************/
1513 /* MMLAmpStream object per channel */
1514 /************************************************************************************************/
1515 typedef struct
1516 {
1517 pyo_audio_HEAD
1518 MMLMain *mainPlayer;
1519 int chnl;
1520 int modebuffer[2];
1521 } MMLAmpStream;
1522
1523 static void MMLAmpStream_postprocessing_ii(MMLAmpStream *self) { POST_PROCESSING_II };
1524 static void MMLAmpStream_postprocessing_ai(MMLAmpStream *self) { POST_PROCESSING_AI };
1525 static void MMLAmpStream_postprocessing_ia(MMLAmpStream *self) { POST_PROCESSING_IA };
1526 static void MMLAmpStream_postprocessing_aa(MMLAmpStream *self) { POST_PROCESSING_AA };
1527 static void MMLAmpStream_postprocessing_ireva(MMLAmpStream *self) { POST_PROCESSING_IREVA };
1528 static void MMLAmpStream_postprocessing_areva(MMLAmpStream *self) { POST_PROCESSING_AREVA };
1529 static void MMLAmpStream_postprocessing_revai(MMLAmpStream *self) { POST_PROCESSING_REVAI };
1530 static void MMLAmpStream_postprocessing_revaa(MMLAmpStream *self) { POST_PROCESSING_REVAA };
1531 static void MMLAmpStream_postprocessing_revareva(MMLAmpStream *self) { POST_PROCESSING_REVAREVA };
1532
1533 static void
1534 MMLAmpStream_setProcMode(MMLAmpStream *self)
1535 {
1536 int muladdmode;
1537 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1538
1539 switch (muladdmode)
1540 {
1541 case 0:
1542 self->muladd_func_ptr = MMLAmpStream_postprocessing_ii;
1543 break;
1544
1545 case 1:
1546 self->muladd_func_ptr = MMLAmpStream_postprocessing_ai;
1547 break;
1548
1549 case 2:
1550 self->muladd_func_ptr = MMLAmpStream_postprocessing_revai;
1551 break;
1552
1553 case 10:
1554 self->muladd_func_ptr = MMLAmpStream_postprocessing_ia;
1555 break;
1556
1557 case 11:
1558 self->muladd_func_ptr = MMLAmpStream_postprocessing_aa;
1559 break;
1560
1561 case 12:
1562 self->muladd_func_ptr = MMLAmpStream_postprocessing_revaa;
1563 break;
1564
1565 case 20:
1566 self->muladd_func_ptr = MMLAmpStream_postprocessing_ireva;
1567 break;
1568
1569 case 21:
1570 self->muladd_func_ptr = MMLAmpStream_postprocessing_areva;
1571 break;
1572
1573 case 22:
1574 self->muladd_func_ptr = MMLAmpStream_postprocessing_revareva;
1575 break;
1576 }
1577 }
1578
1579 static void
1580 MMLAmpStream_compute_next_data_frame(MMLAmpStream *self)
1581 {
1582 int i;
1583 MYFLT *tmp;
1584 int offset = self->chnl * self->bufsize;
1585 tmp = MMLMain_getAmpBuffer((MMLMain *)self->mainPlayer);
1586
1587 for (i = 0; i < self->bufsize; i++)
1588 {
1589 self->data[i] = tmp[i + offset];
1590 }
1591
1592 (*self->muladd_func_ptr)(self);
1593 }
1594
1595 static int
1596 MMLAmpStream_traverse(MMLAmpStream *self, visitproc visit, void *arg)
1597 {
1598 pyo_VISIT
1599 Py_VISIT(self->mainPlayer);
1600 return 0;
1601 }
1602
1603 static int
1604 MMLAmpStream_clear(MMLAmpStream *self)
1605 {
1606 pyo_CLEAR
1607 Py_CLEAR(self->mainPlayer);
1608 return 0;
1609 }
1610
1611 static void
1612 MMLAmpStream_dealloc(MMLAmpStream* self)
1613 {
1614 pyo_DEALLOC
1615 MMLAmpStream_clear(self);
1616 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1617 Py_TYPE(self)->tp_free((PyObject*)self);
1618 }
1619
1620 static PyObject *
1621 MMLAmpStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1622 {
1623 int i;
1624 PyObject *maintmp = NULL;
1625 MMLAmpStream *self;
1626 self = (MMLAmpStream *)type->tp_alloc(type, 0);
1627
1628 self->chnl = 0;
1629 self->modebuffer[0] = 0;
1630 self->modebuffer[1] = 0;
1631
1632 INIT_OBJECT_COMMON
1633 Stream_setFunctionPtr(self->stream, MMLAmpStream_compute_next_data_frame);
1634 self->mode_func_ptr = MMLAmpStream_setProcMode;
1635
1636 static char *kwlist[] = {"mainPlayer", "chnl", NULL};
1637
1638 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &maintmp, &self->chnl))
1639 Py_RETURN_NONE;
1640
1641 self->mainPlayer = (MMLMain *)maintmp;
1642 Py_INCREF(self->mainPlayer);
1643
1644 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1645
1646 (*self->mode_func_ptr)(self);
1647
1648 return (PyObject *)self;
1649 }
1650
1651 static PyObject * MMLAmpStream_getServer(MMLAmpStream* self) { GET_SERVER };
1652 static PyObject * MMLAmpStream_getStream(MMLAmpStream* self) { GET_STREAM };
1653 static PyObject * MMLAmpStream_setMul(MMLAmpStream *self, PyObject *arg) { SET_MUL };
1654 static PyObject * MMLAmpStream_setAdd(MMLAmpStream *self, PyObject *arg) { SET_ADD };
1655 static PyObject * MMLAmpStream_setSub(MMLAmpStream *self, PyObject *arg) { SET_SUB };
1656 static PyObject * MMLAmpStream_setDiv(MMLAmpStream *self, PyObject *arg) { SET_DIV };
1657
1658 static PyObject * MMLAmpStream_play(MMLAmpStream *self, PyObject *args, PyObject *kwds) { PLAY };
1659 static PyObject * MMLAmpStream_out(MMLAmpStream *self, PyObject *args, PyObject *kwds) { OUT };
1660 static PyObject * MMLAmpStream_stop(MMLAmpStream *self, PyObject *args, PyObject *kwds) { STOP };
1661
1662 static PyObject * MMLAmpStream_multiply(MMLAmpStream *self, PyObject *arg) { MULTIPLY };
1663 static PyObject * MMLAmpStream_inplace_multiply(MMLAmpStream *self, PyObject *arg) { INPLACE_MULTIPLY };
1664 static PyObject * MMLAmpStream_add(MMLAmpStream *self, PyObject *arg) { ADD };
1665 static PyObject * MMLAmpStream_inplace_add(MMLAmpStream *self, PyObject *arg) { INPLACE_ADD };
1666 static PyObject * MMLAmpStream_sub(MMLAmpStream *self, PyObject *arg) { SUB };
1667 static PyObject * MMLAmpStream_inplace_sub(MMLAmpStream *self, PyObject *arg) { INPLACE_SUB };
1668 static PyObject * MMLAmpStream_div(MMLAmpStream *self, PyObject *arg) { DIV };
1669 static PyObject * MMLAmpStream_inplace_div(MMLAmpStream *self, PyObject *arg) { INPLACE_DIV };
1670
1671 static PyMemberDef MMLAmpStream_members[] =
1672 {
1673 {"server", T_OBJECT_EX, offsetof(MMLAmpStream, server), 0, "Pyo server."},
1674 {"stream", T_OBJECT_EX, offsetof(MMLAmpStream, stream), 0, "Stream object."},
1675 {"mul", T_OBJECT_EX, offsetof(MMLAmpStream, mul), 0, "Mul factor."},
1676 {"add", T_OBJECT_EX, offsetof(MMLAmpStream, add), 0, "Add factor."},
1677 {NULL} /* Sentinel */
1678 };
1679
1680 static PyMethodDef MMLAmpStream_methods[] =
1681 {
1682 {"getServer", (PyCFunction)MMLAmpStream_getServer, METH_NOARGS, "Returns server object."},
1683 {"_getStream", (PyCFunction)MMLAmpStream_getStream, METH_NOARGS, "Returns stream object."},
1684 {"play", (PyCFunction)MMLAmpStream_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1685 {"out", (PyCFunction)MMLAmpStream_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1686 {"stop", (PyCFunction)MMLAmpStream_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1687 {"setMul", (PyCFunction)MMLAmpStream_setMul, METH_O, "Sets oscillator mul factor."},
1688 {"setAdd", (PyCFunction)MMLAmpStream_setAdd, METH_O, "Sets oscillator add factor."},
1689 {"setSub", (PyCFunction)MMLAmpStream_setSub, METH_O, "Sets inverse add factor."},
1690 {"setDiv", (PyCFunction)MMLAmpStream_setDiv, METH_O, "Sets inverse mul factor."},
1691 {NULL} /* Sentinel */
1692 };
1693
1694 static PyNumberMethods MMLAmpStream_as_number =
1695 {
1696 (binaryfunc)MMLAmpStream_add, /*nb_add*/
1697 (binaryfunc)MMLAmpStream_sub, /*nb_subtract*/
1698 (binaryfunc)MMLAmpStream_multiply, /*nb_multiply*/
1699 0, /*nb_remainder*/
1700 0, /*nb_divmod*/
1701 0, /*nb_power*/
1702 0, /*nb_neg*/
1703 0, /*nb_pos*/
1704 0, /*(unaryfunc)array_abs,*/
1705 0, /*nb_nonzero*/
1706 0, /*nb_invert*/
1707 0, /*nb_lshift*/
1708 0, /*nb_rshift*/
1709 0, /*nb_and*/
1710 0, /*nb_xor*/
1711 0, /*nb_or*/
1712 0, /*nb_int*/
1713 0, /*nb_long*/
1714 0, /*nb_float*/
1715 (binaryfunc)MMLAmpStream_inplace_add, /*inplace_add*/
1716 (binaryfunc)MMLAmpStream_inplace_sub, /*inplace_subtract*/
1717 (binaryfunc)MMLAmpStream_inplace_multiply, /*inplace_multiply*/
1718 0, /*inplace_remainder*/
1719 0, /*inplace_power*/
1720 0, /*inplace_lshift*/
1721 0, /*inplace_rshift*/
1722 0, /*inplace_and*/
1723 0, /*inplace_xor*/
1724 0, /*inplace_or*/
1725 0, /*nb_floor_divide*/
1726 (binaryfunc)MMLAmpStream_div, /*nb_true_divide*/
1727 0, /*nb_inplace_floor_divide*/
1728 (binaryfunc)MMLAmpStream_inplace_div, /*nb_inplace_true_divide*/
1729 0, /* nb_index */
1730 };
1731
1732 PyTypeObject MMLAmpStreamType =
1733 {
1734 PyVarObject_HEAD_INIT(NULL, 0)
1735 "_pyo.MMLAmpStream_base", /*tp_name*/
1736 sizeof(MMLAmpStream), /*tp_basicsize*/
1737 0, /*tp_itemsize*/
1738 (destructor)MMLAmpStream_dealloc, /*tp_dealloc*/
1739 0, /*tp_print*/
1740 0, /*tp_getattr*/
1741 0, /*tp_setattr*/
1742 0, /*tp_as_async (tp_compare in Python 2)*/
1743 0, /*tp_repr*/
1744 &MMLAmpStream_as_number, /*tp_as_number*/
1745 0, /*tp_as_sequence*/
1746 0, /*tp_as_mapping*/
1747 0, /*tp_hash */
1748 0, /*tp_call*/
1749 0, /*tp_str*/
1750 0, /*tp_getattro*/
1751 0, /*tp_setattro*/
1752 0, /*tp_as_buffer*/
1753 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1754 "MMLAmpStream objects. Reads a amplitude channel from a MMLMain object.", /* tp_doc */
1755 (traverseproc)MMLAmpStream_traverse, /* tp_traverse */
1756 (inquiry)MMLAmpStream_clear, /* tp_clear */
1757 0, /* tp_richcompare */
1758 0, /* tp_weaklistoffset */
1759 0, /* tp_iter */
1760 0, /* tp_iternext */
1761 MMLAmpStream_methods, /* tp_methods */
1762 MMLAmpStream_members, /* tp_members */
1763 0, /* tp_getset */
1764 0, /* tp_base */
1765 0, /* tp_dict */
1766 0, /* tp_descr_get */
1767 0, /* tp_descr_set */
1768 0, /* tp_dictoffset */
1769 0, /* tp_init */
1770 0, /* tp_alloc */
1771 MMLAmpStream_new, /* tp_new */
1772 };
1773
1774 /************************************************************************************************/
1775 /* MMLDurStream object per channel */
1776 /************************************************************************************************/
1777 typedef struct
1778 {
1779 pyo_audio_HEAD
1780 MMLMain *mainPlayer;
1781 int chnl;
1782 int modebuffer[2];
1783 } MMLDurStream;
1784
1785 static void MMLDurStream_postprocessing_ii(MMLDurStream *self) { POST_PROCESSING_II };
1786 static void MMLDurStream_postprocessing_ai(MMLDurStream *self) { POST_PROCESSING_AI };
1787 static void MMLDurStream_postprocessing_ia(MMLDurStream *self) { POST_PROCESSING_IA };
1788 static void MMLDurStream_postprocessing_aa(MMLDurStream *self) { POST_PROCESSING_AA };
1789 static void MMLDurStream_postprocessing_ireva(MMLDurStream *self) { POST_PROCESSING_IREVA };
1790 static void MMLDurStream_postprocessing_areva(MMLDurStream *self) { POST_PROCESSING_AREVA };
1791 static void MMLDurStream_postprocessing_revai(MMLDurStream *self) { POST_PROCESSING_REVAI };
1792 static void MMLDurStream_postprocessing_revaa(MMLDurStream *self) { POST_PROCESSING_REVAA };
1793 static void MMLDurStream_postprocessing_revareva(MMLDurStream *self) { POST_PROCESSING_REVAREVA };
1794
1795 static void
1796 MMLDurStream_setProcMode(MMLDurStream *self)
1797 {
1798 int muladdmode;
1799 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1800
1801 switch (muladdmode)
1802 {
1803 case 0:
1804 self->muladd_func_ptr = MMLDurStream_postprocessing_ii;
1805 break;
1806
1807 case 1:
1808 self->muladd_func_ptr = MMLDurStream_postprocessing_ai;
1809 break;
1810
1811 case 2:
1812 self->muladd_func_ptr = MMLDurStream_postprocessing_revai;
1813 break;
1814
1815 case 10:
1816 self->muladd_func_ptr = MMLDurStream_postprocessing_ia;
1817 break;
1818
1819 case 11:
1820 self->muladd_func_ptr = MMLDurStream_postprocessing_aa;
1821 break;
1822
1823 case 12:
1824 self->muladd_func_ptr = MMLDurStream_postprocessing_revaa;
1825 break;
1826
1827 case 20:
1828 self->muladd_func_ptr = MMLDurStream_postprocessing_ireva;
1829 break;
1830
1831 case 21:
1832 self->muladd_func_ptr = MMLDurStream_postprocessing_areva;
1833 break;
1834
1835 case 22:
1836 self->muladd_func_ptr = MMLDurStream_postprocessing_revareva;
1837 break;
1838 }
1839 }
1840
1841 static void
1842 MMLDurStream_compute_next_data_frame(MMLDurStream *self)
1843 {
1844 int i;
1845 MYFLT *tmp;
1846 int offset = self->chnl * self->bufsize;
1847 tmp = MMLMain_getDurBuffer((MMLMain *)self->mainPlayer);
1848
1849 for (i = 0; i < self->bufsize; i++)
1850 {
1851 self->data[i] = tmp[i + offset];
1852 }
1853
1854 (*self->muladd_func_ptr)(self);
1855 }
1856
1857 static int
1858 MMLDurStream_traverse(MMLDurStream *self, visitproc visit, void *arg)
1859 {
1860 pyo_VISIT
1861 Py_VISIT(self->mainPlayer);
1862 return 0;
1863 }
1864
1865 static int
1866 MMLDurStream_clear(MMLDurStream *self)
1867 {
1868 pyo_CLEAR
1869 Py_CLEAR(self->mainPlayer);
1870 return 0;
1871 }
1872
1873 static void
1874 MMLDurStream_dealloc(MMLDurStream* self)
1875 {
1876 pyo_DEALLOC
1877 MMLDurStream_clear(self);
1878 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1879 Py_TYPE(self)->tp_free((PyObject*)self);
1880 }
1881
1882 static PyObject *
1883 MMLDurStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1884 {
1885 int i;
1886 PyObject *maintmp = NULL;
1887 MMLDurStream *self;
1888 self = (MMLDurStream *)type->tp_alloc(type, 0);
1889
1890 self->chnl = 0;
1891 self->modebuffer[0] = 0;
1892 self->modebuffer[1] = 0;
1893
1894 INIT_OBJECT_COMMON
1895 Stream_setFunctionPtr(self->stream, MMLDurStream_compute_next_data_frame);
1896 self->mode_func_ptr = MMLDurStream_setProcMode;
1897
1898 static char *kwlist[] = {"mainPlayer", "chnl", NULL};
1899
1900 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &maintmp, &self->chnl))
1901 Py_RETURN_NONE;
1902
1903 self->mainPlayer = (MMLMain *)maintmp;
1904 Py_INCREF(self->mainPlayer);
1905
1906 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1907
1908 (*self->mode_func_ptr)(self);
1909
1910 return (PyObject *)self;
1911 }
1912
1913 static PyObject * MMLDurStream_getServer(MMLDurStream* self) { GET_SERVER };
1914 static PyObject * MMLDurStream_getStream(MMLDurStream* self) { GET_STREAM };
1915 static PyObject * MMLDurStream_setMul(MMLDurStream *self, PyObject *arg) { SET_MUL };
1916 static PyObject * MMLDurStream_setAdd(MMLDurStream *self, PyObject *arg) { SET_ADD };
1917 static PyObject * MMLDurStream_setSub(MMLDurStream *self, PyObject *arg) { SET_SUB };
1918 static PyObject * MMLDurStream_setDiv(MMLDurStream *self, PyObject *arg) { SET_DIV };
1919
1920 static PyObject * MMLDurStream_play(MMLDurStream *self, PyObject *args, PyObject *kwds) { PLAY };
1921 static PyObject * MMLDurStream_out(MMLDurStream *self, PyObject *args, PyObject *kwds) { OUT };
1922 static PyObject * MMLDurStream_stop(MMLDurStream *self, PyObject *args, PyObject *kwds) { STOP };
1923
1924 static PyObject * MMLDurStream_multiply(MMLDurStream *self, PyObject *arg) { MULTIPLY };
1925 static PyObject * MMLDurStream_inplace_multiply(MMLDurStream *self, PyObject *arg) { INPLACE_MULTIPLY };
1926 static PyObject * MMLDurStream_add(MMLDurStream *self, PyObject *arg) { ADD };
1927 static PyObject * MMLDurStream_inplace_add(MMLDurStream *self, PyObject *arg) { INPLACE_ADD };
1928 static PyObject * MMLDurStream_sub(MMLDurStream *self, PyObject *arg) { SUB };
1929 static PyObject * MMLDurStream_inplace_sub(MMLDurStream *self, PyObject *arg) { INPLACE_SUB };
1930 static PyObject * MMLDurStream_div(MMLDurStream *self, PyObject *arg) { DIV };
1931 static PyObject * MMLDurStream_inplace_div(MMLDurStream *self, PyObject *arg) { INPLACE_DIV };
1932
1933 static PyMemberDef MMLDurStream_members[] =
1934 {
1935 {"server", T_OBJECT_EX, offsetof(MMLDurStream, server), 0, "Pyo server."},
1936 {"stream", T_OBJECT_EX, offsetof(MMLDurStream, stream), 0, "Stream object."},
1937 {"mul", T_OBJECT_EX, offsetof(MMLDurStream, mul), 0, "Mul factor."},
1938 {"add", T_OBJECT_EX, offsetof(MMLDurStream, add), 0, "Add factor."},
1939 {NULL} /* Sentinel */
1940 };
1941
1942 static PyMethodDef MMLDurStream_methods[] =
1943 {
1944 {"getServer", (PyCFunction)MMLDurStream_getServer, METH_NOARGS, "Returns server object."},
1945 {"_getStream", (PyCFunction)MMLDurStream_getStream, METH_NOARGS, "Returns stream object."},
1946 {"play", (PyCFunction)MMLDurStream_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1947 {"out", (PyCFunction)MMLDurStream_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1948 {"stop", (PyCFunction)MMLDurStream_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1949 {"setMul", (PyCFunction)MMLDurStream_setMul, METH_O, "Sets oscillator mul factor."},
1950 {"setAdd", (PyCFunction)MMLDurStream_setAdd, METH_O, "Sets oscillator add factor."},
1951 {"setSub", (PyCFunction)MMLDurStream_setSub, METH_O, "Sets inverse add factor."},
1952 {"setDiv", (PyCFunction)MMLDurStream_setDiv, METH_O, "Sets inverse mul factor."},
1953 {NULL} /* Sentinel */
1954 };
1955
1956 static PyNumberMethods MMLDurStream_as_number =
1957 {
1958 (binaryfunc)MMLDurStream_add, /*nb_add*/
1959 (binaryfunc)MMLDurStream_sub, /*nb_subtract*/
1960 (binaryfunc)MMLDurStream_multiply, /*nb_multiply*/
1961 0, /*nb_remainder*/
1962 0, /*nb_divmod*/
1963 0, /*nb_power*/
1964 0, /*nb_neg*/
1965 0, /*nb_pos*/
1966 0, /*(unaryfunc)array_abs,*/
1967 0, /*nb_nonzero*/
1968 0, /*nb_invert*/
1969 0, /*nb_lshift*/
1970 0, /*nb_rshift*/
1971 0, /*nb_and*/
1972 0, /*nb_xor*/
1973 0, /*nb_or*/
1974 0, /*nb_int*/
1975 0, /*nb_long*/
1976 0, /*nb_float*/
1977 (binaryfunc)MMLDurStream_inplace_add, /*inplace_add*/
1978 (binaryfunc)MMLDurStream_inplace_sub, /*inplace_subtract*/
1979 (binaryfunc)MMLDurStream_inplace_multiply, /*inplace_multiply*/
1980 0, /*inplace_remainder*/
1981 0, /*inplace_power*/
1982 0, /*inplace_lshift*/
1983 0, /*inplace_rshift*/
1984 0, /*inplace_and*/
1985 0, /*inplace_xor*/
1986 0, /*inplace_or*/
1987 0, /*nb_floor_divide*/
1988 (binaryfunc)MMLDurStream_div, /*nb_true_divide*/
1989 0, /*nb_inplace_floor_divide*/
1990 (binaryfunc)MMLDurStream_inplace_div, /*nb_inplace_true_divide*/
1991 0, /* nb_index */
1992 };
1993
1994 PyTypeObject MMLDurStreamType =
1995 {
1996 PyVarObject_HEAD_INIT(NULL, 0)
1997 "_pyo.MMLDurStream_base", /*tp_name*/
1998 sizeof(MMLDurStream), /*tp_basicsize*/
1999 0, /*tp_itemsize*/
2000 (destructor)MMLDurStream_dealloc, /*tp_dealloc*/
2001 0, /*tp_print*/
2002 0, /*tp_getattr*/
2003 0, /*tp_setattr*/
2004 0, /*tp_as_async (tp_compare in Python 2)*/
2005 0, /*tp_repr*/
2006 &MMLDurStream_as_number, /*tp_as_number*/
2007 0, /*tp_as_sequence*/
2008 0, /*tp_as_mapping*/
2009 0, /*tp_hash */
2010 0, /*tp_call*/
2011 0, /*tp_str*/
2012 0, /*tp_getattro*/
2013 0, /*tp_setattro*/
2014 0, /*tp_as_buffer*/
2015 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2016 "MMLDurStream objects. Reads a duration channel from a MMLMain object.", /* tp_doc */
2017 (traverseproc)MMLDurStream_traverse, /* tp_traverse */
2018 (inquiry)MMLDurStream_clear, /* tp_clear */
2019 0, /* tp_richcompare */
2020 0, /* tp_weaklistoffset */
2021 0, /* tp_iter */
2022 0, /* tp_iternext */
2023 MMLDurStream_methods, /* tp_methods */
2024 MMLDurStream_members, /* tp_members */
2025 0, /* tp_getset */
2026 0, /* tp_base */
2027 0, /* tp_dict */
2028 0, /* tp_descr_get */
2029 0, /* tp_descr_set */
2030 0, /* tp_dictoffset */
2031 0, /* tp_init */
2032 0, /* tp_alloc */
2033 MMLDurStream_new, /* tp_new */
2034 };
2035
2036 /************************************************************************************************/
2037 /* MMLEndStream object per channel */
2038 /************************************************************************************************/
2039 typedef struct
2040 {
2041 pyo_audio_HEAD
2042 MMLMain *mainPlayer;
2043 int chnl;
2044 int modebuffer[2];
2045 } MMLEndStream;
2046
2047 static void MMLEndStream_postprocessing_ii(MMLEndStream *self) { POST_PROCESSING_II };
2048 static void MMLEndStream_postprocessing_ai(MMLEndStream *self) { POST_PROCESSING_AI };
2049 static void MMLEndStream_postprocessing_ia(MMLEndStream *self) { POST_PROCESSING_IA };
2050 static void MMLEndStream_postprocessing_aa(MMLEndStream *self) { POST_PROCESSING_AA };
2051 static void MMLEndStream_postprocessing_ireva(MMLEndStream *self) { POST_PROCESSING_IREVA };
2052 static void MMLEndStream_postprocessing_areva(MMLEndStream *self) { POST_PROCESSING_AREVA };
2053 static void MMLEndStream_postprocessing_revai(MMLEndStream *self) { POST_PROCESSING_REVAI };
2054 static void MMLEndStream_postprocessing_revaa(MMLEndStream *self) { POST_PROCESSING_REVAA };
2055 static void MMLEndStream_postprocessing_revareva(MMLEndStream *self) { POST_PROCESSING_REVAREVA };
2056
2057 static void
2058 MMLEndStream_setProcMode(MMLEndStream *self)
2059 {
2060 int muladdmode;
2061 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2062
2063 switch (muladdmode)
2064 {
2065 case 0:
2066 self->muladd_func_ptr = MMLEndStream_postprocessing_ii;
2067 break;
2068
2069 case 1:
2070 self->muladd_func_ptr = MMLEndStream_postprocessing_ai;
2071 break;
2072
2073 case 2:
2074 self->muladd_func_ptr = MMLEndStream_postprocessing_revai;
2075 break;
2076
2077 case 10:
2078 self->muladd_func_ptr = MMLEndStream_postprocessing_ia;
2079 break;
2080
2081 case 11:
2082 self->muladd_func_ptr = MMLEndStream_postprocessing_aa;
2083 break;
2084
2085 case 12:
2086 self->muladd_func_ptr = MMLEndStream_postprocessing_revaa;
2087 break;
2088
2089 case 20:
2090 self->muladd_func_ptr = MMLEndStream_postprocessing_ireva;
2091 break;
2092
2093 case 21:
2094 self->muladd_func_ptr = MMLEndStream_postprocessing_areva;
2095 break;
2096
2097 case 22:
2098 self->muladd_func_ptr = MMLEndStream_postprocessing_revareva;
2099 break;
2100 }
2101 }
2102
2103 static void
2104 MMLEndStream_compute_next_data_frame(MMLEndStream *self)
2105 {
2106 int i;
2107 MYFLT *tmp;
2108 int offset = self->chnl * self->bufsize;
2109 tmp = MMLMain_getEndBuffer((MMLMain *)self->mainPlayer);
2110
2111 for (i = 0; i < self->bufsize; i++)
2112 {
2113 self->data[i] = tmp[i + offset];
2114 }
2115
2116 (*self->muladd_func_ptr)(self);
2117 }
2118
2119 static int
2120 MMLEndStream_traverse(MMLEndStream *self, visitproc visit, void *arg)
2121 {
2122 pyo_VISIT
2123 Py_VISIT(self->mainPlayer);
2124 return 0;
2125 }
2126
2127 static int
2128 MMLEndStream_clear(MMLEndStream *self)
2129 {
2130 pyo_CLEAR
2131 Py_CLEAR(self->mainPlayer);
2132 return 0;
2133 }
2134
2135 static void
2136 MMLEndStream_dealloc(MMLEndStream* self)
2137 {
2138 pyo_DEALLOC
2139 MMLEndStream_clear(self);
2140 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2141 Py_TYPE(self)->tp_free((PyObject*)self);
2142 }
2143
2144 static PyObject *
2145 MMLEndStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2146 {
2147 int i;
2148 PyObject *maintmp = NULL;
2149 MMLEndStream *self;
2150 self = (MMLEndStream *)type->tp_alloc(type, 0);
2151
2152 self->chnl = 0;
2153 self->modebuffer[0] = 0;
2154 self->modebuffer[1] = 0;
2155
2156 INIT_OBJECT_COMMON
2157 Stream_setFunctionPtr(self->stream, MMLEndStream_compute_next_data_frame);
2158 self->mode_func_ptr = MMLEndStream_setProcMode;
2159
2160 static char *kwlist[] = {"mainPlayer", "chnl", NULL};
2161
2162 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &maintmp, &self->chnl))
2163 Py_RETURN_NONE;
2164
2165 self->mainPlayer = (MMLMain *)maintmp;
2166 Py_INCREF(self->mainPlayer);
2167
2168 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2169
2170 (*self->mode_func_ptr)(self);
2171
2172 return (PyObject *)self;
2173 }
2174
2175 static PyObject * MMLEndStream_getServer(MMLEndStream* self) { GET_SERVER };
2176 static PyObject * MMLEndStream_getStream(MMLEndStream* self) { GET_STREAM };
2177 static PyObject * MMLEndStream_setMul(MMLEndStream *self, PyObject *arg) { SET_MUL };
2178 static PyObject * MMLEndStream_setAdd(MMLEndStream *self, PyObject *arg) { SET_ADD };
2179 static PyObject * MMLEndStream_setSub(MMLEndStream *self, PyObject *arg) { SET_SUB };
2180 static PyObject * MMLEndStream_setDiv(MMLEndStream *self, PyObject *arg) { SET_DIV };
2181
2182 static PyObject * MMLEndStream_play(MMLEndStream *self, PyObject *args, PyObject *kwds) { PLAY };
2183 static PyObject * MMLEndStream_out(MMLEndStream *self, PyObject *args, PyObject *kwds) { OUT };
2184 static PyObject * MMLEndStream_stop(MMLEndStream *self, PyObject *args, PyObject *kwds) { STOP };
2185
2186 static PyObject * MMLEndStream_multiply(MMLEndStream *self, PyObject *arg) { MULTIPLY };
2187 static PyObject * MMLEndStream_inplace_multiply(MMLEndStream *self, PyObject *arg) { INPLACE_MULTIPLY };
2188 static PyObject * MMLEndStream_add(MMLEndStream *self, PyObject *arg) { ADD };
2189 static PyObject * MMLEndStream_inplace_add(MMLEndStream *self, PyObject *arg) { INPLACE_ADD };
2190 static PyObject * MMLEndStream_sub(MMLEndStream *self, PyObject *arg) { SUB };
2191 static PyObject * MMLEndStream_inplace_sub(MMLEndStream *self, PyObject *arg) { INPLACE_SUB };
2192 static PyObject * MMLEndStream_div(MMLEndStream *self, PyObject *arg) { DIV };
2193 static PyObject * MMLEndStream_inplace_div(MMLEndStream *self, PyObject *arg) { INPLACE_DIV };
2194
2195 static PyMemberDef MMLEndStream_members[] =
2196 {
2197 {"server", T_OBJECT_EX, offsetof(MMLEndStream, server), 0, "Pyo server."},
2198 {"stream", T_OBJECT_EX, offsetof(MMLEndStream, stream), 0, "Stream object."},
2199 {"mul", T_OBJECT_EX, offsetof(MMLEndStream, mul), 0, "Mul factor."},
2200 {"add", T_OBJECT_EX, offsetof(MMLEndStream, add), 0, "Add factor."},
2201 {NULL} /* Sentinel */
2202 };
2203
2204 static PyMethodDef MMLEndStream_methods[] =
2205 {
2206 {"getServer", (PyCFunction)MMLEndStream_getServer, METH_NOARGS, "Returns server object."},
2207 {"_getStream", (PyCFunction)MMLEndStream_getStream, METH_NOARGS, "Returns stream object."},
2208 {"play", (PyCFunction)MMLEndStream_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2209 {"out", (PyCFunction)MMLEndStream_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2210 {"stop", (PyCFunction)MMLEndStream_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2211 {"setMul", (PyCFunction)MMLEndStream_setMul, METH_O, "Sets oscillator mul factor."},
2212 {"setAdd", (PyCFunction)MMLEndStream_setAdd, METH_O, "Sets oscillator add factor."},
2213 {"setSub", (PyCFunction)MMLEndStream_setSub, METH_O, "Sets inverse add factor."},
2214 {"setDiv", (PyCFunction)MMLEndStream_setDiv, METH_O, "Sets inverse mul factor."},
2215 {NULL} /* Sentinel */
2216 };
2217
2218 static PyNumberMethods MMLEndStream_as_number =
2219 {
2220 (binaryfunc)MMLEndStream_add, /*nb_add*/
2221 (binaryfunc)MMLEndStream_sub, /*nb_subtract*/
2222 (binaryfunc)MMLEndStream_multiply, /*nb_multiply*/
2223 0, /*nb_remainder*/
2224 0, /*nb_divmod*/
2225 0, /*nb_power*/
2226 0, /*nb_neg*/
2227 0, /*nb_pos*/
2228 0, /*(unaryfunc)array_abs,*/
2229 0, /*nb_nonzero*/
2230 0, /*nb_invert*/
2231 0, /*nb_lshift*/
2232 0, /*nb_rshift*/
2233 0, /*nb_and*/
2234 0, /*nb_xor*/
2235 0, /*nb_or*/
2236 0, /*nb_int*/
2237 0, /*nb_long*/
2238 0, /*nb_float*/
2239 (binaryfunc)MMLEndStream_inplace_add, /*inplace_add*/
2240 (binaryfunc)MMLEndStream_inplace_sub, /*inplace_subtract*/
2241 (binaryfunc)MMLEndStream_inplace_multiply, /*inplace_multiply*/
2242 0, /*inplace_remainder*/
2243 0, /*inplace_power*/
2244 0, /*inplace_lshift*/
2245 0, /*inplace_rshift*/
2246 0, /*inplace_and*/
2247 0, /*inplace_xor*/
2248 0, /*inplace_or*/
2249 0, /*nb_floor_divide*/
2250 (binaryfunc)MMLEndStream_div, /*nb_true_divide*/
2251 0, /*nb_inplace_floor_divide*/
2252 (binaryfunc)MMLEndStream_inplace_div, /*nb_inplace_true_divide*/
2253 0, /* nb_index */
2254 };
2255
2256 PyTypeObject MMLEndStreamType =
2257 {
2258 PyVarObject_HEAD_INIT(NULL, 0)
2259 "_pyo.MMLEndStream_base", /*tp_name*/
2260 sizeof(MMLEndStream), /*tp_basicsize*/
2261 0, /*tp_itemsize*/
2262 (destructor)MMLEndStream_dealloc, /*tp_dealloc*/
2263 0, /*tp_print*/
2264 0, /*tp_getattr*/
2265 0, /*tp_setattr*/
2266 0, /*tp_as_async (tp_compare in Python 2)*/
2267 0, /*tp_repr*/
2268 &MMLEndStream_as_number, /*tp_as_number*/
2269 0, /*tp_as_sequence*/
2270 0, /*tp_as_mapping*/
2271 0, /*tp_hash */
2272 0, /*tp_call*/
2273 0, /*tp_str*/
2274 0, /*tp_getattro*/
2275 0, /*tp_setattro*/
2276 0, /*tp_as_buffer*/
2277 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2278 "MMLEndStream objects. Reads a duration channel from a MMLMain object.", /* tp_doc */
2279 (traverseproc)MMLEndStream_traverse, /* tp_traverse */
2280 (inquiry)MMLEndStream_clear, /* tp_clear */
2281 0, /* tp_richcompare */
2282 0, /* tp_weaklistoffset */
2283 0, /* tp_iter */
2284 0, /* tp_iternext */
2285 MMLEndStream_methods, /* tp_methods */
2286 MMLEndStream_members, /* tp_members */
2287 0, /* tp_getset */
2288 0, /* tp_base */
2289 0, /* tp_dict */
2290 0, /* tp_descr_get */
2291 0, /* tp_descr_set */
2292 0, /* tp_dictoffset */
2293 0, /* tp_init */
2294 0, /* tp_alloc */
2295 MMLEndStream_new, /* tp_new */
2296 };
2297
2298 /************************************************************************************************/
2299 /* MMLXStream object per channel */
2300 /************************************************************************************************/
2301 typedef struct
2302 {
2303 pyo_audio_HEAD
2304 MMLMain *mainPlayer;
2305 int chnl;
2306 int modebuffer[2];
2307 } MMLXStream;
2308
2309 static void MMLXStream_postprocessing_ii(MMLXStream *self) { POST_PROCESSING_II };
2310 static void MMLXStream_postprocessing_ai(MMLXStream *self) { POST_PROCESSING_AI };
2311 static void MMLXStream_postprocessing_ia(MMLXStream *self) { POST_PROCESSING_IA };
2312 static void MMLXStream_postprocessing_aa(MMLXStream *self) { POST_PROCESSING_AA };
2313 static void MMLXStream_postprocessing_ireva(MMLXStream *self) { POST_PROCESSING_IREVA };
2314 static void MMLXStream_postprocessing_areva(MMLXStream *self) { POST_PROCESSING_AREVA };
2315 static void MMLXStream_postprocessing_revai(MMLXStream *self) { POST_PROCESSING_REVAI };
2316 static void MMLXStream_postprocessing_revaa(MMLXStream *self) { POST_PROCESSING_REVAA };
2317 static void MMLXStream_postprocessing_revareva(MMLXStream *self) { POST_PROCESSING_REVAREVA };
2318
2319 static void
2320 MMLXStream_setProcMode(MMLXStream *self)
2321 {
2322 int muladdmode;
2323 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2324
2325 switch (muladdmode)
2326 {
2327 case 0:
2328 self->muladd_func_ptr = MMLXStream_postprocessing_ii;
2329 break;
2330
2331 case 1:
2332 self->muladd_func_ptr = MMLXStream_postprocessing_ai;
2333 break;
2334
2335 case 2:
2336 self->muladd_func_ptr = MMLXStream_postprocessing_revai;
2337 break;
2338
2339 case 10:
2340 self->muladd_func_ptr = MMLXStream_postprocessing_ia;
2341 break;
2342
2343 case 11:
2344 self->muladd_func_ptr = MMLXStream_postprocessing_aa;
2345 break;
2346
2347 case 12:
2348 self->muladd_func_ptr = MMLXStream_postprocessing_revaa;
2349 break;
2350
2351 case 20:
2352 self->muladd_func_ptr = MMLXStream_postprocessing_ireva;
2353 break;
2354
2355 case 21:
2356 self->muladd_func_ptr = MMLXStream_postprocessing_areva;
2357 break;
2358
2359 case 22:
2360 self->muladd_func_ptr = MMLXStream_postprocessing_revareva;
2361 break;
2362 }
2363 }
2364
2365 static void
2366 MMLXStream_compute_next_data_frame(MMLXStream *self)
2367 {
2368 int i;
2369 MYFLT *tmp;
2370 int offset = self->chnl * self->bufsize;
2371 tmp = MMLMain_getXBuffer((MMLMain *)self->mainPlayer);
2372
2373 for (i = 0; i < self->bufsize; i++)
2374 {
2375 self->data[i] = tmp[i + offset];
2376 }
2377
2378 (*self->muladd_func_ptr)(self);
2379 }
2380
2381 static int
2382 MMLXStream_traverse(MMLXStream *self, visitproc visit, void *arg)
2383 {
2384 pyo_VISIT
2385 Py_VISIT(self->mainPlayer);
2386 return 0;
2387 }
2388
2389 static int
2390 MMLXStream_clear(MMLXStream *self)
2391 {
2392 pyo_CLEAR
2393 Py_CLEAR(self->mainPlayer);
2394 return 0;
2395 }
2396
2397 static void
2398 MMLXStream_dealloc(MMLXStream* self)
2399 {
2400 pyo_DEALLOC
2401 MMLXStream_clear(self);
2402 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2403 Py_TYPE(self)->tp_free((PyObject*)self);
2404 }
2405
2406 static PyObject *
2407 MMLXStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2408 {
2409 int i;
2410 PyObject *maintmp = NULL;
2411 MMLXStream *self;
2412 self = (MMLXStream *)type->tp_alloc(type, 0);
2413
2414 self->chnl = 0;
2415 self->modebuffer[0] = 0;
2416 self->modebuffer[1] = 0;
2417
2418 INIT_OBJECT_COMMON
2419 Stream_setFunctionPtr(self->stream, MMLXStream_compute_next_data_frame);
2420 self->mode_func_ptr = MMLXStream_setProcMode;
2421
2422 static char *kwlist[] = {"mainPlayer", "chnl", NULL};
2423
2424 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &maintmp, &self->chnl))
2425 Py_RETURN_NONE;
2426
2427 self->mainPlayer = (MMLMain *)maintmp;
2428 Py_INCREF(self->mainPlayer);
2429
2430 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2431
2432 (*self->mode_func_ptr)(self);
2433
2434 return (PyObject *)self;
2435 }
2436
2437 static PyObject * MMLXStream_getServer(MMLXStream* self) { GET_SERVER };
2438 static PyObject * MMLXStream_getStream(MMLXStream* self) { GET_STREAM };
2439 static PyObject * MMLXStream_setMul(MMLXStream *self, PyObject *arg) { SET_MUL };
2440 static PyObject * MMLXStream_setAdd(MMLXStream *self, PyObject *arg) { SET_ADD };
2441 static PyObject * MMLXStream_setSub(MMLXStream *self, PyObject *arg) { SET_SUB };
2442 static PyObject * MMLXStream_setDiv(MMLXStream *self, PyObject *arg) { SET_DIV };
2443
2444 static PyObject * MMLXStream_play(MMLXStream *self, PyObject *args, PyObject *kwds) { PLAY };
2445 static PyObject * MMLXStream_out(MMLXStream *self, PyObject *args, PyObject *kwds) { OUT };
2446 static PyObject * MMLXStream_stop(MMLXStream *self, PyObject *args, PyObject *kwds) { STOP };
2447
2448 static PyObject * MMLXStream_multiply(MMLXStream *self, PyObject *arg) { MULTIPLY };
2449 static PyObject * MMLXStream_inplace_multiply(MMLXStream *self, PyObject *arg) { INPLACE_MULTIPLY };
2450 static PyObject * MMLXStream_add(MMLXStream *self, PyObject *arg) { ADD };
2451 static PyObject * MMLXStream_inplace_add(MMLXStream *self, PyObject *arg) { INPLACE_ADD };
2452 static PyObject * MMLXStream_sub(MMLXStream *self, PyObject *arg) { SUB };
2453 static PyObject * MMLXStream_inplace_sub(MMLXStream *self, PyObject *arg) { INPLACE_SUB };
2454 static PyObject * MMLXStream_div(MMLXStream *self, PyObject *arg) { DIV };
2455 static PyObject * MMLXStream_inplace_div(MMLXStream *self, PyObject *arg) { INPLACE_DIV };
2456
2457 static PyMemberDef MMLXStream_members[] =
2458 {
2459 {"server", T_OBJECT_EX, offsetof(MMLXStream, server), 0, "Pyo server."},
2460 {"stream", T_OBJECT_EX, offsetof(MMLXStream, stream), 0, "Stream object."},
2461 {"mul", T_OBJECT_EX, offsetof(MMLXStream, mul), 0, "Mul factor."},
2462 {"add", T_OBJECT_EX, offsetof(MMLXStream, add), 0, "Add factor."},
2463 {NULL} /* Sentinel */
2464 };
2465
2466 static PyMethodDef MMLXStream_methods[] =
2467 {
2468 {"getServer", (PyCFunction)MMLXStream_getServer, METH_NOARGS, "Returns server object."},
2469 {"_getStream", (PyCFunction)MMLXStream_getStream, METH_NOARGS, "Returns stream object."},
2470 {"play", (PyCFunction)MMLXStream_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2471 {"out", (PyCFunction)MMLXStream_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2472 {"stop", (PyCFunction)MMLXStream_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2473 {"setMul", (PyCFunction)MMLXStream_setMul, METH_O, "Sets oscillator mul factor."},
2474 {"setAdd", (PyCFunction)MMLXStream_setAdd, METH_O, "Sets oscillator add factor."},
2475 {"setSub", (PyCFunction)MMLXStream_setSub, METH_O, "Sets inverse add factor."},
2476 {"setDiv", (PyCFunction)MMLXStream_setDiv, METH_O, "Sets inverse mul factor."},
2477 {NULL} /* Sentinel */
2478 };
2479
2480 static PyNumberMethods MMLXStream_as_number =
2481 {
2482 (binaryfunc)MMLXStream_add, /*nb_add*/
2483 (binaryfunc)MMLXStream_sub, /*nb_subtract*/
2484 (binaryfunc)MMLXStream_multiply, /*nb_multiply*/
2485 0, /*nb_remainder*/
2486 0, /*nb_divmod*/
2487 0, /*nb_power*/
2488 0, /*nb_neg*/
2489 0, /*nb_pos*/
2490 0, /*(unaryfunc)array_abs,*/
2491 0, /*nb_nonzero*/
2492 0, /*nb_invert*/
2493 0, /*nb_lshift*/
2494 0, /*nb_rshift*/
2495 0, /*nb_and*/
2496 0, /*nb_xor*/
2497 0, /*nb_or*/
2498 0, /*nb_int*/
2499 0, /*nb_long*/
2500 0, /*nb_float*/
2501 (binaryfunc)MMLXStream_inplace_add, /*inplace_add*/
2502 (binaryfunc)MMLXStream_inplace_sub, /*inplace_subtract*/
2503 (binaryfunc)MMLXStream_inplace_multiply, /*inplace_multiply*/
2504 0, /*inplace_remainder*/
2505 0, /*inplace_power*/
2506 0, /*inplace_lshift*/
2507 0, /*inplace_rshift*/
2508 0, /*inplace_and*/
2509 0, /*inplace_xor*/
2510 0, /*inplace_or*/
2511 0, /*nb_floor_divide*/
2512 (binaryfunc)MMLXStream_div, /*nb_true_divide*/
2513 0, /*nb_inplace_floor_divide*/
2514 (binaryfunc)MMLXStream_inplace_div, /*nb_inplace_true_divide*/
2515 0, /* nb_index */
2516 };
2517
2518 PyTypeObject MMLXStreamType =
2519 {
2520 PyVarObject_HEAD_INIT(NULL, 0)
2521 "_pyo.MMLXStream_base", /*tp_name*/
2522 sizeof(MMLXStream), /*tp_basicsize*/
2523 0, /*tp_itemsize*/
2524 (destructor)MMLXStream_dealloc, /*tp_dealloc*/
2525 0, /*tp_print*/
2526 0, /*tp_getattr*/
2527 0, /*tp_setattr*/
2528 0, /*tp_as_async (tp_compare in Python 2)*/
2529 0, /*tp_repr*/
2530 &MMLXStream_as_number, /*tp_as_number*/
2531 0, /*tp_as_sequence*/
2532 0, /*tp_as_mapping*/
2533 0, /*tp_hash */
2534 0, /*tp_call*/
2535 0, /*tp_str*/
2536 0, /*tp_getattro*/
2537 0, /*tp_setattro*/
2538 0, /*tp_as_buffer*/
2539 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2540 "MMLXStream objects. Reads a Xation channel from a MMLMain object.", /* tp_doc */
2541 (traverseproc)MMLXStream_traverse, /* tp_traverse */
2542 (inquiry)MMLXStream_clear, /* tp_clear */
2543 0, /* tp_richcompare */
2544 0, /* tp_weaklistoffset */
2545 0, /* tp_iter */
2546 0, /* tp_iternext */
2547 MMLXStream_methods, /* tp_methods */
2548 MMLXStream_members, /* tp_members */
2549 0, /* tp_getset */
2550 0, /* tp_base */
2551 0, /* tp_dict */
2552 0, /* tp_descr_get */
2553 0, /* tp_descr_set */
2554 0, /* tp_dictoffset */
2555 0, /* tp_init */
2556 0, /* tp_alloc */
2557 MMLXStream_new, /* tp_new */
2558 };
2559
2560 /************************************************************************************************/
2561 /* MMLYStream object per channel */
2562 /************************************************************************************************/
2563 typedef struct
2564 {
2565 pyo_audio_HEAD
2566 MMLMain *mainPlayer;
2567 int chnl;
2568 int modebuffer[2];
2569 } MMLYStream;
2570
2571 static void MMLYStream_postprocessing_ii(MMLYStream *self) { POST_PROCESSING_II };
2572 static void MMLYStream_postprocessing_ai(MMLYStream *self) { POST_PROCESSING_AI };
2573 static void MMLYStream_postprocessing_ia(MMLYStream *self) { POST_PROCESSING_IA };
2574 static void MMLYStream_postprocessing_aa(MMLYStream *self) { POST_PROCESSING_AA };
2575 static void MMLYStream_postprocessing_ireva(MMLYStream *self) { POST_PROCESSING_IREVA };
2576 static void MMLYStream_postprocessing_areva(MMLYStream *self) { POST_PROCESSING_AREVA };
2577 static void MMLYStream_postprocessing_revai(MMLYStream *self) { POST_PROCESSING_REVAI };
2578 static void MMLYStream_postprocessing_revaa(MMLYStream *self) { POST_PROCESSING_REVAA };
2579 static void MMLYStream_postprocessing_revareva(MMLYStream *self) { POST_PROCESSING_REVAREVA };
2580
2581 static void
2582 MMLYStream_setProcMode(MMLYStream *self)
2583 {
2584 int muladdmode;
2585 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2586
2587 switch (muladdmode)
2588 {
2589 case 0:
2590 self->muladd_func_ptr = MMLYStream_postprocessing_ii;
2591 break;
2592
2593 case 1:
2594 self->muladd_func_ptr = MMLYStream_postprocessing_ai;
2595 break;
2596
2597 case 2:
2598 self->muladd_func_ptr = MMLYStream_postprocessing_revai;
2599 break;
2600
2601 case 10:
2602 self->muladd_func_ptr = MMLYStream_postprocessing_ia;
2603 break;
2604
2605 case 11:
2606 self->muladd_func_ptr = MMLYStream_postprocessing_aa;
2607 break;
2608
2609 case 12:
2610 self->muladd_func_ptr = MMLYStream_postprocessing_revaa;
2611 break;
2612
2613 case 20:
2614 self->muladd_func_ptr = MMLYStream_postprocessing_ireva;
2615 break;
2616
2617 case 21:
2618 self->muladd_func_ptr = MMLYStream_postprocessing_areva;
2619 break;
2620
2621 case 22:
2622 self->muladd_func_ptr = MMLYStream_postprocessing_revareva;
2623 break;
2624 }
2625 }
2626
2627 static void
2628 MMLYStream_compute_next_data_frame(MMLYStream *self)
2629 {
2630 int i;
2631 MYFLT *tmp;
2632 int offset = self->chnl * self->bufsize;
2633 tmp = MMLMain_getYBuffer((MMLMain *)self->mainPlayer);
2634
2635 for (i = 0; i < self->bufsize; i++)
2636 {
2637 self->data[i] = tmp[i + offset];
2638 }
2639
2640 (*self->muladd_func_ptr)(self);
2641 }
2642
2643 static int
2644 MMLYStream_traverse(MMLYStream *self, visitproc visit, void *arg)
2645 {
2646 pyo_VISIT
2647 Py_VISIT(self->mainPlayer);
2648 return 0;
2649 }
2650
2651 static int
2652 MMLYStream_clear(MMLYStream *self)
2653 {
2654 pyo_CLEAR
2655 Py_CLEAR(self->mainPlayer);
2656 return 0;
2657 }
2658
2659 static void
2660 MMLYStream_dealloc(MMLYStream* self)
2661 {
2662 pyo_DEALLOC
2663 MMLYStream_clear(self);
2664 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2665 Py_TYPE(self)->tp_free((PyObject*)self);
2666 }
2667
2668 static PyObject *
2669 MMLYStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2670 {
2671 int i;
2672 PyObject *maintmp = NULL;
2673 MMLYStream *self;
2674 self = (MMLYStream *)type->tp_alloc(type, 0);
2675
2676 self->chnl = 0;
2677 self->modebuffer[0] = 0;
2678 self->modebuffer[1] = 0;
2679
2680 INIT_OBJECT_COMMON
2681 Stream_setFunctionPtr(self->stream, MMLYStream_compute_next_data_frame);
2682 self->mode_func_ptr = MMLYStream_setProcMode;
2683
2684 static char *kwlist[] = {"mainPlayer", "chnl", NULL};
2685
2686 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &maintmp, &self->chnl))
2687 Py_RETURN_NONE;
2688
2689 self->mainPlayer = (MMLMain *)maintmp;
2690 Py_INCREF(self->mainPlayer);
2691
2692 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2693
2694 (*self->mode_func_ptr)(self);
2695
2696 return (PyObject *)self;
2697 }
2698
2699 static PyObject * MMLYStream_getServer(MMLYStream* self) { GET_SERVER };
2700 static PyObject * MMLYStream_getStream(MMLYStream* self) { GET_STREAM };
2701 static PyObject * MMLYStream_setMul(MMLYStream *self, PyObject *arg) { SET_MUL };
2702 static PyObject * MMLYStream_setAdd(MMLYStream *self, PyObject *arg) { SET_ADD };
2703 static PyObject * MMLYStream_setSub(MMLYStream *self, PyObject *arg) { SET_SUB };
2704 static PyObject * MMLYStream_setDiv(MMLYStream *self, PyObject *arg) { SET_DIV };
2705
2706 static PyObject * MMLYStream_play(MMLYStream *self, PyObject *args, PyObject *kwds) { PLAY };
2707 static PyObject * MMLYStream_out(MMLYStream *self, PyObject *args, PyObject *kwds) { OUT };
2708 static PyObject * MMLYStream_stop(MMLYStream *self, PyObject *args, PyObject *kwds) { STOP };
2709
2710 static PyObject * MMLYStream_multiply(MMLYStream *self, PyObject *arg) { MULTIPLY };
2711 static PyObject * MMLYStream_inplace_multiply(MMLYStream *self, PyObject *arg) { INPLACE_MULTIPLY };
2712 static PyObject * MMLYStream_add(MMLYStream *self, PyObject *arg) { ADD };
2713 static PyObject * MMLYStream_inplace_add(MMLYStream *self, PyObject *arg) { INPLACE_ADD };
2714 static PyObject * MMLYStream_sub(MMLYStream *self, PyObject *arg) { SUB };
2715 static PyObject * MMLYStream_inplace_sub(MMLYStream *self, PyObject *arg) { INPLACE_SUB };
2716 static PyObject * MMLYStream_div(MMLYStream *self, PyObject *arg) { DIV };
2717 static PyObject * MMLYStream_inplace_div(MMLYStream *self, PyObject *arg) { INPLACE_DIV };
2718
2719 static PyMemberDef MMLYStream_members[] =
2720 {
2721 {"server", T_OBJECT_EX, offsetof(MMLYStream, server), 0, "Pyo server."},
2722 {"stream", T_OBJECT_EX, offsetof(MMLYStream, stream), 0, "Stream object."},
2723 {"mul", T_OBJECT_EX, offsetof(MMLYStream, mul), 0, "Mul factor."},
2724 {"add", T_OBJECT_EX, offsetof(MMLYStream, add), 0, "Add factor."},
2725 {NULL} /* Sentinel */
2726 };
2727
2728 static PyMethodDef MMLYStream_methods[] =
2729 {
2730 {"getServer", (PyCFunction)MMLYStream_getServer, METH_NOARGS, "Returns server object."},
2731 {"_getStream", (PyCFunction)MMLYStream_getStream, METH_NOARGS, "Returns stream object."},
2732 {"play", (PyCFunction)MMLYStream_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2733 {"out", (PyCFunction)MMLYStream_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2734 {"stop", (PyCFunction)MMLYStream_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2735 {"setMul", (PyCFunction)MMLYStream_setMul, METH_O, "Sets oscillator mul factor."},
2736 {"setAdd", (PyCFunction)MMLYStream_setAdd, METH_O, "Sets oscillator add factor."},
2737 {"setSub", (PyCFunction)MMLYStream_setSub, METH_O, "Sets inverse add factor."},
2738 {"setDiv", (PyCFunction)MMLYStream_setDiv, METH_O, "Sets inverse mul factor."},
2739 {NULL} /* Sentinel */
2740 };
2741
2742 static PyNumberMethods MMLYStream_as_number =
2743 {
2744 (binaryfunc)MMLYStream_add, /*nb_add*/
2745 (binaryfunc)MMLYStream_sub, /*nb_subtract*/
2746 (binaryfunc)MMLYStream_multiply, /*nb_multiply*/
2747 0, /*nb_remainder*/
2748 0, /*nb_divmod*/
2749 0, /*nb_power*/
2750 0, /*nb_neg*/
2751 0, /*nb_pos*/
2752 0, /*(unaryfunc)array_abs,*/
2753 0, /*nb_nonzero*/
2754 0, /*nb_invert*/
2755 0, /*nb_lshift*/
2756 0, /*nb_rshift*/
2757 0, /*nb_and*/
2758 0, /*nb_xor*/
2759 0, /*nb_or*/
2760 0, /*nb_int*/
2761 0, /*nb_long*/
2762 0, /*nb_float*/
2763 (binaryfunc)MMLYStream_inplace_add, /*inplace_add*/
2764 (binaryfunc)MMLYStream_inplace_sub, /*inplace_subtract*/
2765 (binaryfunc)MMLYStream_inplace_multiply, /*inplace_multiply*/
2766 0, /*inplace_remainder*/
2767 0, /*inplace_power*/
2768 0, /*inplace_lshift*/
2769 0, /*inplace_rshift*/
2770 0, /*inplace_and*/
2771 0, /*inplace_xor*/
2772 0, /*inplace_or*/
2773 0, /*nb_floor_divide*/
2774 (binaryfunc)MMLYStream_div, /*nb_true_divide*/
2775 0, /*nb_inplace_floor_divide*/
2776 (binaryfunc)MMLYStream_inplace_div, /*nb_inplace_true_divide*/
2777 0, /* nb_index */
2778 };
2779
2780 PyTypeObject MMLYStreamType =
2781 {
2782 PyVarObject_HEAD_INIT(NULL, 0)
2783 "_pyo.MMLYStream_base", /*tp_name*/
2784 sizeof(MMLYStream), /*tp_basicsize*/
2785 0, /*tp_itemsize*/
2786 (destructor)MMLYStream_dealloc, /*tp_dealloc*/
2787 0, /*tp_print*/
2788 0, /*tp_getattr*/
2789 0, /*tp_setattr*/
2790 0, /*tp_as_async (tp_compare in Python 2)*/
2791 0, /*tp_repr*/
2792 &MMLYStream_as_number, /*tp_as_number*/
2793 0, /*tp_as_sequence*/
2794 0, /*tp_as_mapping*/
2795 0, /*tp_hash */
2796 0, /*tp_call*/
2797 0, /*tp_str*/
2798 0, /*tp_getattro*/
2799 0, /*tp_setattro*/
2800 0, /*tp_as_buffer*/
2801 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2802 "MMLYStream objects. Reads a Yation channel from a MMLMain object.", /* tp_doc */
2803 (traverseproc)MMLYStream_traverse, /* tp_traverse */
2804 (inquiry)MMLYStream_clear, /* tp_clear */
2805 0, /* tp_richcompare */
2806 0, /* tp_weaklistoffset */
2807 0, /* tp_iter */
2808 0, /* tp_iternext */
2809 MMLYStream_methods, /* tp_methods */
2810 MMLYStream_members, /* tp_members */
2811 0, /* tp_getset */
2812 0, /* tp_base */
2813 0, /* tp_dict */
2814 0, /* tp_descr_get */
2815 0, /* tp_descr_set */
2816 0, /* tp_dictoffset */
2817 0, /* tp_init */
2818 0, /* tp_alloc */
2819 MMLYStream_new, /* tp_new */
2820 };
2821
2822 /************************************************************************************************/
2823 /* MMLZStream object per channel */
2824 /************************************************************************************************/
2825 typedef struct
2826 {
2827 pyo_audio_HEAD
2828 MMLMain *mainPlayer;
2829 int chnl;
2830 int modebuffer[2];
2831 } MMLZStream;
2832
2833 static void MMLZStream_postprocessing_ii(MMLZStream *self) { POST_PROCESSING_II };
2834 static void MMLZStream_postprocessing_ai(MMLZStream *self) { POST_PROCESSING_AI };
2835 static void MMLZStream_postprocessing_ia(MMLZStream *self) { POST_PROCESSING_IA };
2836 static void MMLZStream_postprocessing_aa(MMLZStream *self) { POST_PROCESSING_AA };
2837 static void MMLZStream_postprocessing_ireva(MMLZStream *self) { POST_PROCESSING_IREVA };
2838 static void MMLZStream_postprocessing_areva(MMLZStream *self) { POST_PROCESSING_AREVA };
2839 static void MMLZStream_postprocessing_revai(MMLZStream *self) { POST_PROCESSING_REVAI };
2840 static void MMLZStream_postprocessing_revaa(MMLZStream *self) { POST_PROCESSING_REVAA };
2841 static void MMLZStream_postprocessing_revareva(MMLZStream *self) { POST_PROCESSING_REVAREVA };
2842
2843 static void
2844 MMLZStream_setProcMode(MMLZStream *self)
2845 {
2846 int muladdmode;
2847 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2848
2849 switch (muladdmode)
2850 {
2851 case 0:
2852 self->muladd_func_ptr = MMLZStream_postprocessing_ii;
2853 break;
2854
2855 case 1:
2856 self->muladd_func_ptr = MMLZStream_postprocessing_ai;
2857 break;
2858
2859 case 2:
2860 self->muladd_func_ptr = MMLZStream_postprocessing_revai;
2861 break;
2862
2863 case 10:
2864 self->muladd_func_ptr = MMLZStream_postprocessing_ia;
2865 break;
2866
2867 case 11:
2868 self->muladd_func_ptr = MMLZStream_postprocessing_aa;
2869 break;
2870
2871 case 12:
2872 self->muladd_func_ptr = MMLZStream_postprocessing_revaa;
2873 break;
2874
2875 case 20:
2876 self->muladd_func_ptr = MMLZStream_postprocessing_ireva;
2877 break;
2878
2879 case 21:
2880 self->muladd_func_ptr = MMLZStream_postprocessing_areva;
2881 break;
2882
2883 case 22:
2884 self->muladd_func_ptr = MMLZStream_postprocessing_revareva;
2885 break;
2886 }
2887 }
2888
2889 static void
2890 MMLZStream_compute_next_data_frame(MMLZStream *self)
2891 {
2892 int i;
2893 MYFLT *tmp;
2894 int offset = self->chnl * self->bufsize;
2895 tmp = MMLMain_getZBuffer((MMLMain *)self->mainPlayer);
2896
2897 for (i = 0; i < self->bufsize; i++)
2898 {
2899 self->data[i] = tmp[i + offset];
2900 }
2901
2902 (*self->muladd_func_ptr)(self);
2903 }
2904
2905 static int
2906 MMLZStream_traverse(MMLZStream *self, visitproc visit, void *arg)
2907 {
2908 pyo_VISIT
2909 Py_VISIT(self->mainPlayer);
2910 return 0;
2911 }
2912
2913 static int
2914 MMLZStream_clear(MMLZStream *self)
2915 {
2916 pyo_CLEAR
2917 Py_CLEAR(self->mainPlayer);
2918 return 0;
2919 }
2920
2921 static void
2922 MMLZStream_dealloc(MMLZStream* self)
2923 {
2924 pyo_DEALLOC
2925 MMLZStream_clear(self);
2926 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2927 Py_TYPE(self)->tp_free((PyObject*)self);
2928 }
2929
2930 static PyObject *
2931 MMLZStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2932 {
2933 int i;
2934 PyObject *maintmp = NULL;
2935 MMLZStream *self;
2936 self = (MMLZStream *)type->tp_alloc(type, 0);
2937
2938 self->chnl = 0;
2939 self->modebuffer[0] = 0;
2940 self->modebuffer[1] = 0;
2941
2942 INIT_OBJECT_COMMON
2943 Stream_setFunctionPtr(self->stream, MMLZStream_compute_next_data_frame);
2944 self->mode_func_ptr = MMLZStream_setProcMode;
2945
2946 static char *kwlist[] = {"mainPlayer", "chnl", NULL};
2947
2948 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &maintmp, &self->chnl))
2949 Py_RETURN_NONE;
2950
2951 self->mainPlayer = (MMLMain *)maintmp;
2952 Py_INCREF(self->mainPlayer);
2953
2954 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2955
2956 (*self->mode_func_ptr)(self);
2957
2958 return (PyObject *)self;
2959 }
2960
2961 static PyObject * MMLZStream_getServer(MMLZStream* self) { GET_SERVER };
2962 static PyObject * MMLZStream_getStream(MMLZStream* self) { GET_STREAM };
2963 static PyObject * MMLZStream_setMul(MMLZStream *self, PyObject *arg) { SET_MUL };
2964 static PyObject * MMLZStream_setAdd(MMLZStream *self, PyObject *arg) { SET_ADD };
2965 static PyObject * MMLZStream_setSub(MMLZStream *self, PyObject *arg) { SET_SUB };
2966 static PyObject * MMLZStream_setDiv(MMLZStream *self, PyObject *arg) { SET_DIV };
2967
2968 static PyObject * MMLZStream_play(MMLZStream *self, PyObject *args, PyObject *kwds) { PLAY };
2969 static PyObject * MMLZStream_out(MMLZStream *self, PyObject *args, PyObject *kwds) { OUT };
2970 static PyObject * MMLZStream_stop(MMLZStream *self, PyObject *args, PyObject *kwds) { STOP };
2971
2972 static PyObject * MMLZStream_multiply(MMLZStream *self, PyObject *arg) { MULTIPLY };
2973 static PyObject * MMLZStream_inplace_multiply(MMLZStream *self, PyObject *arg) { INPLACE_MULTIPLY };
2974 static PyObject * MMLZStream_add(MMLZStream *self, PyObject *arg) { ADD };
2975 static PyObject * MMLZStream_inplace_add(MMLZStream *self, PyObject *arg) { INPLACE_ADD };
2976 static PyObject * MMLZStream_sub(MMLZStream *self, PyObject *arg) { SUB };
2977 static PyObject * MMLZStream_inplace_sub(MMLZStream *self, PyObject *arg) { INPLACE_SUB };
2978 static PyObject * MMLZStream_div(MMLZStream *self, PyObject *arg) { DIV };
2979 static PyObject * MMLZStream_inplace_div(MMLZStream *self, PyObject *arg) { INPLACE_DIV };
2980
2981 static PyMemberDef MMLZStream_members[] =
2982 {
2983 {"server", T_OBJECT_EX, offsetof(MMLZStream, server), 0, "Pyo server."},
2984 {"stream", T_OBJECT_EX, offsetof(MMLZStream, stream), 0, "Stream object."},
2985 {"mul", T_OBJECT_EX, offsetof(MMLZStream, mul), 0, "Mul factor."},
2986 {"add", T_OBJECT_EX, offsetof(MMLZStream, add), 0, "Add factor."},
2987 {NULL} /* Sentinel */
2988 };
2989
2990 static PyMethodDef MMLZStream_methods[] =
2991 {
2992 {"getServer", (PyCFunction)MMLZStream_getServer, METH_NOARGS, "Returns server object."},
2993 {"_getStream", (PyCFunction)MMLZStream_getStream, METH_NOARGS, "Returns stream object."},
2994 {"play", (PyCFunction)MMLZStream_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2995 {"out", (PyCFunction)MMLZStream_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2996 {"stop", (PyCFunction)MMLZStream_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2997 {"setMul", (PyCFunction)MMLZStream_setMul, METH_O, "Sets oscillator mul factor."},
2998 {"setAdd", (PyCFunction)MMLZStream_setAdd, METH_O, "Sets oscillator add factor."},
2999 {"setSub", (PyCFunction)MMLZStream_setSub, METH_O, "Sets inverse add factor."},
3000 {"setDiv", (PyCFunction)MMLZStream_setDiv, METH_O, "Sets inverse mul factor."},
3001 {NULL} /* Sentinel */
3002 };
3003
3004 static PyNumberMethods MMLZStream_as_number =
3005 {
3006 (binaryfunc)MMLZStream_add, /*nb_add*/
3007 (binaryfunc)MMLZStream_sub, /*nb_subtract*/
3008 (binaryfunc)MMLZStream_multiply, /*nb_multiply*/
3009 0, /*nb_remainder*/
3010 0, /*nb_divmod*/
3011 0, /*nb_power*/
3012 0, /*nb_neg*/
3013 0, /*nb_pos*/
3014 0, /*(unaryfunc)array_abs,*/
3015 0, /*nb_nonzero*/
3016 0, /*nb_invert*/
3017 0, /*nb_lshift*/
3018 0, /*nb_rshift*/
3019 0, /*nb_and*/
3020 0, /*nb_xor*/
3021 0, /*nb_or*/
3022 0, /*nb_int*/
3023 0, /*nb_long*/
3024 0, /*nb_float*/
3025 (binaryfunc)MMLZStream_inplace_add, /*inplace_add*/
3026 (binaryfunc)MMLZStream_inplace_sub, /*inplace_subtract*/
3027 (binaryfunc)MMLZStream_inplace_multiply, /*inplace_multiply*/
3028 0, /*inplace_remainder*/
3029 0, /*inplace_power*/
3030 0, /*inplace_lshift*/
3031 0, /*inplace_rshift*/
3032 0, /*inplace_and*/
3033 0, /*inplace_xor*/
3034 0, /*inplace_or*/
3035 0, /*nb_floor_divide*/
3036 (binaryfunc)MMLZStream_div, /*nb_true_divide*/
3037 0, /*nb_inplace_floor_divide*/
3038 (binaryfunc)MMLZStream_inplace_div, /*nb_inplace_true_divide*/
3039 0, /* nb_index */
3040 };
3041
3042 PyTypeObject MMLZStreamType =
3043 {
3044 PyVarObject_HEAD_INIT(NULL, 0)
3045 "_pyo.MMLZStream_base", /*tp_name*/
3046 sizeof(MMLZStream), /*tp_basicsize*/
3047 0, /*tp_itemsize*/
3048 (destructor)MMLZStream_dealloc, /*tp_dealloc*/
3049 0, /*tp_print*/
3050 0, /*tp_getattr*/
3051 0, /*tp_setattr*/
3052 0, /*tp_as_async (tp_compare in Python 2)*/
3053 0, /*tp_repr*/
3054 &MMLZStream_as_number, /*tp_as_number*/
3055 0, /*tp_as_sequence*/
3056 0, /*tp_as_mapping*/
3057 0, /*tp_hash */
3058 0, /*tp_call*/
3059 0, /*tp_str*/
3060 0, /*tp_getattro*/
3061 0, /*tp_setattro*/
3062 0, /*tp_as_buffer*/
3063 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3064 "MMLZStream objects. Reads a Zation channel from a MMLMain object.", /* tp_doc */
3065 (traverseproc)MMLZStream_traverse, /* tp_traverse */
3066 (inquiry)MMLZStream_clear, /* tp_clear */
3067 0, /* tp_richcompare */
3068 0, /* tp_weaklistoffset */
3069 0, /* tp_iter */
3070 0, /* tp_iternext */
3071 MMLZStream_methods, /* tp_methods */
3072 MMLZStream_members, /* tp_members */
3073 0, /* tp_getset */
3074 0, /* tp_base */
3075 0, /* tp_dict */
3076 0, /* tp_descr_get */
3077 0, /* tp_descr_set */
3078 0, /* tp_dictoffset */
3079 0, /* tp_init */
3080 0, /* tp_alloc */
3081 MMLZStream_new, /* tp_new */
3082 };