Debian Codegraph @

src/objects/fadermodule.c

raw
1 /**************************************************************************
2 * Copyright 2009-2015 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 typedef struct
29 {
30 pyo_audio_HEAD
31 int modebuffer[2];
32 int fademode;
33 int ended;
34 MYFLT topValue;
35 MYFLT attack;
36 MYFLT release;
37 MYFLT duration;
38 MYFLT exp;
39 MYFLT offset;
40 MYFLT currentVal;
41 double currentTime;
42 MYFLT sampleToSec;
43 MYFLT *trigsBuffer;
44 TriggerStream *trig_stream;
45 } Fader;
46
47 static void Fader_internal_stop(Fader *self)
48 {
49 int i;
50 Stream_setStreamActive(self->stream, 0);
51 Stream_setStreamChnl(self->stream, 0);
52 Stream_setStreamToDac(self->stream, 0);
53
54 for (i = 0; i < self->bufsize; i++)
55 {
56 self->data[i] = 0;
57 self->trigsBuffer[i] = 0.0;
58 }
59 }
60
61 static void
62 Fader_generate_auto(Fader *self)
63 {
64 MYFLT val, iatt, irel;
65 int i;
66
67 iatt = 1.0 / self->attack;
68 irel = 1.0 / self->release;
69
70 if (self->ended == 1)
71 {
72 Fader_internal_stop((Fader *)self);
73 return;
74 }
75
76 for (i = 0; i < self->bufsize; i++)
77 {
78 self->trigsBuffer[i] = 0.0;
79
80 if (self->currentTime <= self->attack)
81 val = self->currentTime * iatt * (1.0 - self->offset) + self->offset;
82 else if (self->currentTime > self->duration)
83 {
84 if (self->ended == 0)
85 {
86 self->trigsBuffer[i] = 1.0;
87 }
88
89 val = 0.;
90 self->ended = 1;
91 }
92 else if (self->currentTime >= (self->duration - self->release))
93 val = (self->duration - self->currentTime) * irel;
94 else
95 val = 1.;
96
97 self->data[i] = self->currentVal = val;
98 self->currentTime += self->sampleToSec;
99 }
100
101 if (self->exp != 1.0)
102 {
103 for (i = 0; i < self->bufsize; i++)
104 {
105 self->data[i] = MYPOW(self->data[i], self->exp);
106 }
107 }
108 }
109
110 static void
111 Fader_generate_wait(Fader *self)
112 {
113 MYFLT val, iatt, irel;
114 int i;
115
116 iatt = 1.0 / self->attack;
117 irel = 1.0 / self->release;
118
119 if (self->fademode == 1 && self->ended == 1)
120 {
121 Fader_internal_stop((Fader *)self);
122 return;
123 }
124
125 for (i = 0; i < self->bufsize; i++)
126 {
127 self->trigsBuffer[i] = 0.0;
128
129 if (self->fademode == 0)
130 {
131 if (self->currentTime <= self->attack)
132 val = self->currentTime * iatt * (1.0 - self->offset) + self->offset;
133 else
134 val = 1.;
135
136 self->topValue = val;
137 }
138 else
139 {
140 if (self->currentTime <= self->release)
141 val = (1. - self->currentTime * irel) * self->topValue;
142 else
143 {
144 if (self->ended == 0)
145 {
146 self->trigsBuffer[i] = 1.0;
147 }
148
149 val = 0.;
150 self->ended = 1;
151 }
152 }
153
154 self->data[i] = self->currentVal = val;
155 self->currentTime += self->sampleToSec;
156 }
157
158 if (self->exp != 1.0)
159 {
160 for (i = 0; i < self->bufsize; i++)
161 {
162 self->data[i] = MYPOW(self->data[i], self->exp);
163 }
164 }
165 }
166
167 static void Fader_postprocessing_ii(Fader *self) { POST_PROCESSING_II };
168 static void Fader_postprocessing_ai(Fader *self) { POST_PROCESSING_AI };
169 static void Fader_postprocessing_ia(Fader *self) { POST_PROCESSING_IA };
170 static void Fader_postprocessing_aa(Fader *self) { POST_PROCESSING_AA };
171 static void Fader_postprocessing_ireva(Fader *self) { POST_PROCESSING_IREVA };
172 static void Fader_postprocessing_areva(Fader *self) { POST_PROCESSING_AREVA };
173 static void Fader_postprocessing_revai(Fader *self) { POST_PROCESSING_REVAI };
174 static void Fader_postprocessing_revaa(Fader *self) { POST_PROCESSING_REVAA };
175 static void Fader_postprocessing_revareva(Fader *self) { POST_PROCESSING_REVAREVA };
176
177 static void
178 Fader_setProcMode(Fader *self)
179 {
180 int muladdmode;
181 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
182
183 if (self->duration == 0.0)
184 self->proc_func_ptr = Fader_generate_wait;
185 else
186 self->proc_func_ptr = Fader_generate_auto;
187
188 switch (muladdmode)
189 {
190 case 0:
191 self->muladd_func_ptr = Fader_postprocessing_ii;
192 break;
193
194 case 1:
195 self->muladd_func_ptr = Fader_postprocessing_ai;
196 break;
197
198 case 2:
199 self->muladd_func_ptr = Fader_postprocessing_revai;
200 break;
201
202 case 10:
203 self->muladd_func_ptr = Fader_postprocessing_ia;
204 break;
205
206 case 11:
207 self->muladd_func_ptr = Fader_postprocessing_aa;
208 break;
209
210 case 12:
211 self->muladd_func_ptr = Fader_postprocessing_revaa;
212 break;
213
214 case 20:
215 self->muladd_func_ptr = Fader_postprocessing_ireva;
216 break;
217
218 case 21:
219 self->muladd_func_ptr = Fader_postprocessing_areva;
220 break;
221
222 case 22:
223 self->muladd_func_ptr = Fader_postprocessing_revareva;
224 break;
225 }
226 }
227
228 static void
229 Fader_compute_next_data_frame(Fader *self)
230 {
231 (*self->proc_func_ptr)(self);
232 (*self->muladd_func_ptr)(self);
233 }
234
235 static int
236 Fader_traverse(Fader *self, visitproc visit, void *arg)
237 {
238 pyo_VISIT
239 return 0;
240 }
241
242 static int
243 Fader_clear(Fader *self)
244 {
245 pyo_CLEAR
246 return 0;
247 }
248
249 static void
250 Fader_dealloc(Fader* self)
251 {
252 pyo_DEALLOC
253 PyMem_RawFree(self->trigsBuffer);
254 Fader_clear(self);
255 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
256 Py_TYPE(self->trig_stream)->tp_free((PyObject*)self->trig_stream);
257 Py_TYPE(self)->tp_free((PyObject*)self);
258 }
259
260 static PyObject *
261 Fader_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
262 {
263 int i;
264 PyObject *multmp = NULL, *addtmp = NULL;
265 Fader *self;
266 self = (Fader *)type->tp_alloc(type, 0);
267
268 self->modebuffer[0] = 0;
269 self->modebuffer[1] = 0;
270 self->topValue = 0.0;
271 self->fademode = 0;
272 self->ended = 0;
273 self->attack = 0.01;
274 self->release = 0.1;
275 self->duration = 0.0;
276 self->exp = 1.0;
277 self->currentTime = 0.0;
278 self->offset = 0.0;
279 self->currentVal = 0.0;
280
281 INIT_OBJECT_COMMON
282 Stream_setFunctionPtr(self->stream, Fader_compute_next_data_frame);
283 self->mode_func_ptr = Fader_setProcMode;
284
285 self->sampleToSec = 1. / self->sr;
286
287 static char *kwlist[] = {"fadein", "fadeout", "dur", "mul", "add", NULL};
288
289 if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__FFFOO, kwlist, &self->attack, &self->release, &self->duration, &multmp, &addtmp))
290 Py_RETURN_NONE;
291
292 if (multmp)
293 {
294 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
295 }
296
297 if (addtmp)
298 {
299 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
300 }
301
302 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
303
304 self->trigsBuffer = (MYFLT *)PyMem_RawRealloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT));
305
306 for (i = 0; i < self->bufsize; i++)
307 {
308 self->trigsBuffer[i] = 0.0;
309 }
310
311 MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL);
312 TriggerStream_setData(self->trig_stream, self->trigsBuffer);
313
314 (*self->mode_func_ptr)(self);
315
316 return (PyObject *)self;
317 }
318
319 static PyObject * Fader_getServer(Fader* self) { GET_SERVER };
320 static PyObject * Fader_getStream(Fader* self) { GET_STREAM };
321 static PyObject * Fader_getTriggerStream(Fader* self) { GET_TRIGGER_STREAM };
322 static PyObject * Fader_setMul(Fader *self, PyObject *arg) { SET_MUL };
323 static PyObject * Fader_setAdd(Fader *self, PyObject *arg) { SET_ADD };
324 static PyObject * Fader_setSub(Fader *self, PyObject *arg) { SET_SUB };
325 static PyObject * Fader_setDiv(Fader *self, PyObject *arg) { SET_DIV };
326
327 static PyObject * Fader_play(Fader *self, PyObject *args, PyObject *kwds)
328 {
329 self->fademode = 0;
330 self->ended = 0;
331 self->currentTime = 0.0;
332 self->offset = self->currentVal;
333 (*self->mode_func_ptr)(self);
334 PLAY
335 };
336
337 static PyObject *
338 Fader_stop(Fader *self, PyObject *args, PyObject *kwds)
339 {
340 if (self->duration == 0.0)
341 {
342 self->fademode = 1;
343 self->currentTime = 0.0;
344 }
345 else
346 Fader_internal_stop((Fader *)self);
347
348 Py_RETURN_NONE;
349 }
350
351 static PyObject * Fader_multiply(Fader *self, PyObject *arg) { MULTIPLY };
352 static PyObject * Fader_inplace_multiply(Fader *self, PyObject *arg) { INPLACE_MULTIPLY };
353 static PyObject * Fader_add(Fader *self, PyObject *arg) { ADD };
354 static PyObject * Fader_inplace_add(Fader *self, PyObject *arg) { INPLACE_ADD };
355 static PyObject * Fader_sub(Fader *self, PyObject *arg) { SUB };
356 static PyObject * Fader_inplace_sub(Fader *self, PyObject *arg) { INPLACE_SUB };
357 static PyObject * Fader_div(Fader *self, PyObject *arg) { DIV };
358 static PyObject * Fader_inplace_div(Fader *self, PyObject *arg) { INPLACE_DIV };
359
360 static PyObject *
361 Fader_setFadein(Fader *self, PyObject *arg)
362 {
363 self->attack = PyFloat_AsDouble(arg);
364 Py_RETURN_NONE;
365 }
366
367 static PyObject *
368 Fader_setFadeout(Fader *self, PyObject *arg)
369 {
370 self->release = PyFloat_AsDouble(arg);
371 Py_RETURN_NONE;
372 }
373
374 static PyObject *
375 Fader_setDur(Fader *self, PyObject *arg)
376 {
377 self->duration = PyFloat_AsDouble(arg);
378 Py_RETURN_NONE;
379 }
380
381 static PyObject *
382 Fader_setExp(Fader *self, PyObject *arg)
383 {
384 MYFLT tmp = PyFloat_AsDouble(arg);
385
386 if (tmp > 0.0)
387 self->exp = tmp;
388
389 Py_RETURN_NONE;
390 }
391
392 static PyMemberDef Fader_members[] =
393 {
394 {"server", T_OBJECT_EX, offsetof(Fader, server), 0, "Pyo server."},
395 {"stream", T_OBJECT_EX, offsetof(Fader, stream), 0, "Stream object."},
396 {"trig_stream", T_OBJECT_EX, offsetof(Fader, trig_stream), 0, "Trigger Stream object."},
397 {"mul", T_OBJECT_EX, offsetof(Fader, mul), 0, "Mul factor."},
398 {"add", T_OBJECT_EX, offsetof(Fader, add), 0, "Add factor."},
399 {NULL} /* Sentinel */
400 };
401
402 static PyMethodDef Fader_methods[] =
403 {
404 {"getServer", (PyCFunction)Fader_getServer, METH_NOARGS, "Returns server object."},
405 {"_getStream", (PyCFunction)Fader_getStream, METH_NOARGS, "Returns stream object."},
406 {"_getTriggerStream", (PyCFunction)Fader_getTriggerStream, METH_NOARGS, "Returns trigger stream object."},
407 {"play", (PyCFunction)Fader_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
408 {"stop", (PyCFunction)Fader_stop, METH_VARARGS | METH_KEYWORDS, "Starts fadeout and stops computing."},
409 {"setMul", (PyCFunction)Fader_setMul, METH_O, "Sets Fader mul factor."},
410 {"setAdd", (PyCFunction)Fader_setAdd, METH_O, "Sets Fader add factor."},
411 {"setSub", (PyCFunction)Fader_setSub, METH_O, "Sets inverse add factor."},
412 {"setFadein", (PyCFunction)Fader_setFadein, METH_O, "Sets fadein time in seconds."},
413 {"setFadeout", (PyCFunction)Fader_setFadeout, METH_O, "Sets fadeout time in seconds."},
414 {"setDur", (PyCFunction)Fader_setDur, METH_O, "Sets duration in seconds (0 means wait for stop method to start fadeout)."},
415 {"setExp", (PyCFunction)Fader_setExp, METH_O, "Sets the exponent factor for exponential envelope."},
416 {"setDiv", (PyCFunction)Fader_setDiv, METH_O, "Sets inverse mul factor."},
417 {NULL} /* Sentinel */
418 };
419
420 static PyNumberMethods Fader_as_number =
421 {
422 (binaryfunc)Fader_add, /*nb_add*/
423 (binaryfunc)Fader_sub, /*nb_subtract*/
424 (binaryfunc)Fader_multiply, /*nb_multiply*/
425 0, /*nb_remainder*/
426 0, /*nb_divmod*/
427 0, /*nb_power*/
428 0, /*nb_neg*/
429 0, /*nb_pos*/
430 0, /*(unaryfunc)array_abs,*/
431 0, /*nb_nonzero*/
432 0, /*nb_invert*/
433 0, /*nb_lshift*/
434 0, /*nb_rshift*/
435 0, /*nb_and*/
436 0, /*nb_xor*/
437 0, /*nb_or*/
438 0, /*nb_int*/
439 0, /*nb_long*/
440 0, /*nb_float*/
441 (binaryfunc)Fader_inplace_add, /*inplace_add*/
442 (binaryfunc)Fader_inplace_sub, /*inplace_subtract*/
443 (binaryfunc)Fader_inplace_multiply, /*inplace_multiply*/
444 0, /*inplace_remainder*/
445 0, /*inplace_power*/
446 0, /*inplace_lshift*/
447 0, /*inplace_rshift*/
448 0, /*inplace_and*/
449 0, /*inplace_xor*/
450 0, /*inplace_or*/
451 0, /*nb_floor_divide*/
452 (binaryfunc)Fader_div, /*nb_true_divide*/
453 0, /*nb_inplace_floor_divide*/
454 (binaryfunc)Fader_inplace_div, /*nb_inplace_true_divide*/
455 0, /* nb_index */
456 };
457
458 PyTypeObject FaderType =
459 {
460 PyVarObject_HEAD_INIT(NULL, 0)
461 "_pyo.Fader_base", /*tp_name*/
462 sizeof(Fader), /*tp_basicsize*/
463 0, /*tp_itemsize*/
464 (destructor)Fader_dealloc, /*tp_dealloc*/
465 0, /*tp_print*/
466 0, /*tp_getattr*/
467 0, /*tp_setattr*/
468 0, /*tp_as_async (tp_compare in Python 2)*/
469 0, /*tp_repr*/
470 &Fader_as_number, /*tp_as_number*/
471 0, /*tp_as_sequence*/
472 0, /*tp_as_mapping*/
473 0, /*tp_hash */
474 0, /*tp_call*/
475 0, /*tp_str*/
476 0, /*tp_getattro*/
477 0, /*tp_setattro*/
478 0, /*tp_as_buffer*/
479 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
480 "Fader objects. Generates fadin and fadeout signal.", /* tp_doc */
481 (traverseproc)Fader_traverse, /* tp_traverse */
482 (inquiry)Fader_clear, /* tp_clear */
483 0, /* tp_richcompare */
484 0, /* tp_weaklistoffset */
485 0, /* tp_iter */
486 0, /* tp_iternext */
487 Fader_methods, /* tp_methods */
488 Fader_members, /* tp_members */
489 0, /* tp_getset */
490 0, /* tp_base */
491 0, /* tp_dict */
492 0, /* tp_descr_get */
493 0, /* tp_descr_set */
494 0, /* tp_dictoffset */
495 0, /* tp_init */
496 0, /* tp_alloc */
497 Fader_new, /* tp_new */
498 };
499
500 typedef struct
501 {
502 pyo_audio_HEAD
503 int modebuffer[2];
504 int fademode;
505 MYFLT topValue;
506 MYFLT attack;
507 MYFLT decay;
508 MYFLT sustain;
509 MYFLT release;
510 MYFLT duration;
511 MYFLT exp;
512 MYFLT offset;
513 MYFLT currentVal;
514 double currentTime;
515 MYFLT sampleToSec;
516 int ended;
517 MYFLT *trigsBuffer;
518 TriggerStream *trig_stream;
519 } Adsr;
520
521 static void Adsr_internal_stop(Adsr *self)
522 {
523 int i;
524 Stream_setStreamActive(self->stream, 0);
525 Stream_setStreamChnl(self->stream, 0);
526 Stream_setStreamToDac(self->stream, 0);
527
528 for (i = 0; i < self->bufsize; i++)
529 {
530 self->data[i] = 0;
531 self->trigsBuffer[i] = 0.0;
532 }
533 }
534
535 static void
536 Adsr_generate_auto(Adsr *self)
537 {
538 MYFLT val, invatt, invdec, invrel;
539 int i;
540
541 if (self->currentTime > self->duration)
542 Adsr_internal_stop((Adsr *)self);
543
544 invatt = 1.0 / self->attack;
545 invdec = 1.0 / self->decay;
546 invrel = 1.0 / self->release;
547
548 for (i = 0; i < self->bufsize; i++)
549 {
550 self->trigsBuffer[i] = 0.0;
551
552 if (self->currentTime <= self->attack)
553 val = self->currentTime * invatt * (1.0 - self->offset) + self->offset;
554 else if (self->currentTime <= (self->attack + self->decay))
555 val = (self->decay - (self->currentTime - self->attack)) * invdec * (1. - self->sustain) + self->sustain;
556 else if (self->currentTime > self->duration)
557 {
558 if (self->ended == 0)
559 {
560 self->trigsBuffer[i] = 1.0;
561 }
562
563 self->ended = 1;
564 val = 0.;
565 }
566 else if (self->currentTime >= (self->duration - self->release))
567 val = (self->duration - self->currentTime) * invrel * self->sustain;
568 else
569 val = self->sustain;
570
571 self->data[i] = self->currentVal = val;
572 self->currentTime += self->sampleToSec;
573 }
574
575 if (self->exp != 1.0)
576 {
577 for (i = 0; i < self->bufsize; i++)
578 {
579 self->data[i] = MYPOW(self->data[i], self->exp);
580 }
581 }
582 }
583
584 static void
585 Adsr_generate_wait(Adsr *self)
586 {
587 MYFLT val, invatt, invdec, invrel;
588 int i;
589
590 if (self->fademode == 1 && self->currentTime > self->release)
591 Adsr_internal_stop((Adsr *)self);
592
593 invatt = 1.0 / self->attack;
594 invdec = 1.0 / self->decay;
595 invrel = 1.0 / self->release;
596
597 for (i = 0; i < self->bufsize; i++)
598 {
599 self->trigsBuffer[i] = 0.0;
600
601 if (self->fademode == 0)
602 {
603 if (self->currentTime <= self->attack)
604 val = self->currentTime * invatt * (1.0 - self->offset) + self->offset;
605 else if (self->currentTime <= (self->attack + self->decay))
606 val = (self->decay - (self->currentTime - self->attack)) * invdec * (1. - self->sustain) + self->sustain;
607 else
608 val = self->sustain;
609
610 self->topValue = val;
611 }
612 else
613 {
614 if (self->currentTime <= self->release)
615 {
616 val = self->topValue * (1. - self->currentTime * invrel);
617 }
618 else
619 {
620 if (self->ended == 0)
621 {
622 self->trigsBuffer[i] = 1.0;
623 }
624
625 self->ended = 1;
626 val = 0.;
627 }
628 }
629
630 self->data[i] = self->currentVal = val;
631 self->currentTime += self->sampleToSec;
632 }
633
634 if (self->exp != 1.0)
635 {
636 for (i = 0; i < self->bufsize; i++)
637 {
638 self->data[i] = MYPOW(self->data[i], self->exp);
639 }
640 }
641 }
642
643 static void Adsr_postprocessing_ii(Adsr *self) { POST_PROCESSING_II };
644 static void Adsr_postprocessing_ai(Adsr *self) { POST_PROCESSING_AI };
645 static void Adsr_postprocessing_ia(Adsr *self) { POST_PROCESSING_IA };
646 static void Adsr_postprocessing_aa(Adsr *self) { POST_PROCESSING_AA };
647 static void Adsr_postprocessing_ireva(Adsr *self) { POST_PROCESSING_IREVA };
648 static void Adsr_postprocessing_areva(Adsr *self) { POST_PROCESSING_AREVA };
649 static void Adsr_postprocessing_revai(Adsr *self) { POST_PROCESSING_REVAI };
650 static void Adsr_postprocessing_revaa(Adsr *self) { POST_PROCESSING_REVAA };
651 static void Adsr_postprocessing_revareva(Adsr *self) { POST_PROCESSING_REVAREVA };
652
653 static void
654 Adsr_setProcMode(Adsr *self)
655 {
656 int muladdmode;
657 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
658
659 if (self->duration == 0.0)
660 self->proc_func_ptr = Adsr_generate_wait;
661 else
662 self->proc_func_ptr = Adsr_generate_auto;
663
664 switch (muladdmode)
665 {
666 case 0:
667 self->muladd_func_ptr = Adsr_postprocessing_ii;
668 break;
669
670 case 1:
671 self->muladd_func_ptr = Adsr_postprocessing_ai;
672 break;
673
674 case 2:
675 self->muladd_func_ptr = Adsr_postprocessing_revai;
676 break;
677
678 case 10:
679 self->muladd_func_ptr = Adsr_postprocessing_ia;
680 break;
681
682 case 11:
683 self->muladd_func_ptr = Adsr_postprocessing_aa;
684 break;
685
686 case 12:
687 self->muladd_func_ptr = Adsr_postprocessing_revaa;
688 break;
689
690 case 20:
691 self->muladd_func_ptr = Adsr_postprocessing_ireva;
692 break;
693
694 case 21:
695 self->muladd_func_ptr = Adsr_postprocessing_areva;
696 break;
697
698 case 22:
699 self->muladd_func_ptr = Adsr_postprocessing_revareva;
700 break;
701 }
702 }
703
704 static void
705 Adsr_compute_next_data_frame(Adsr *self)
706 {
707 (*self->proc_func_ptr)(self);
708 (*self->muladd_func_ptr)(self);
709 }
710
711 static int
712 Adsr_traverse(Adsr *self, visitproc visit, void *arg)
713 {
714 pyo_VISIT
715 return 0;
716 }
717
718 static int
719 Adsr_clear(Adsr *self)
720 {
721 pyo_CLEAR
722 return 0;
723 }
724
725 static void
726 Adsr_dealloc(Adsr* self)
727 {
728 pyo_DEALLOC
729 PyMem_RawFree(self->trigsBuffer);
730 Adsr_clear(self);
731 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
732 Py_TYPE(self->trig_stream)->tp_free((PyObject*)self->trig_stream);
733 Py_TYPE(self)->tp_free((PyObject*)self);
734 }
735
736 static PyObject *
737 Adsr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
738 {
739 int i;
740 PyObject *multmp = NULL, *addtmp = NULL;
741 Adsr *self;
742 self = (Adsr *)type->tp_alloc(type, 0);
743
744 self->modebuffer[0] = 0;
745 self->modebuffer[1] = 0;
746 self->topValue = 0.0;
747 self->fademode = 0;
748 self->attack = 0.01;
749 self->decay = 0.05;
750 self->sustain = 0.707;
751 self->release = 0.1;
752 self->duration = 0.0;
753 self->exp = 1.0;
754 self->currentTime = 0.0;
755 self->offset = 0.0;
756 self->currentVal = 0.0;
757 self->ended = 0;
758
759 INIT_OBJECT_COMMON
760 Stream_setFunctionPtr(self->stream, Adsr_compute_next_data_frame);
761 self->mode_func_ptr = Adsr_setProcMode;
762
763 self->sampleToSec = 1. / self->sr;
764
765 static char *kwlist[] = {"attack", "decay", "sustain", "release", "dur", "mul", "add", NULL};
766
767 if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__FFFFFOO, kwlist, &self->attack, &self->decay, &self->sustain, &self->release, &self->duration, &multmp, &addtmp))
768 Py_RETURN_NONE;
769
770 if (multmp)
771 {
772 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
773 }
774
775 if (addtmp)
776 {
777 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
778 }
779
780 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
781
782 if (self->attack < 0.000001)
783 self->attack = 0.000001;
784
785 if (self->decay < 0.000001)
786 self->decay = 0.000001;
787
788 if (self->release < 0.000001)
789 self->release = 0.000001;
790
791 if (self->sustain < 0.0)
792 self->sustain = 0.0;
793 else if (self->sustain > 1.0)
794 self->sustain = 1.0;
795
796 self->trigsBuffer = (MYFLT *)PyMem_RawRealloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT));
797
798 for (i = 0; i < self->bufsize; i++)
799 {
800 self->trigsBuffer[i] = 0.0;
801 }
802
803 MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL);
804 TriggerStream_setData(self->trig_stream, self->trigsBuffer);
805
806 (*self->mode_func_ptr)(self);
807
808 return (PyObject *)self;
809 }
810
811 static PyObject * Adsr_getServer(Adsr* self) { GET_SERVER };
812 static PyObject * Adsr_getStream(Adsr* self) { GET_STREAM };
813 static PyObject * Adsr_getTriggerStream(Adsr* self) { GET_TRIGGER_STREAM };
814 static PyObject * Adsr_setMul(Adsr *self, PyObject *arg) { SET_MUL };
815 static PyObject * Adsr_setAdd(Adsr *self, PyObject *arg) { SET_ADD };
816 static PyObject * Adsr_setSub(Adsr *self, PyObject *arg) { SET_SUB };
817 static PyObject * Adsr_setDiv(Adsr *self, PyObject *arg) { SET_DIV };
818
819 static PyObject * Adsr_play(Adsr *self, PyObject *args, PyObject *kwds)
820 {
821 self->ended = 0;
822 self->fademode = 0;
823 self->currentTime = 0.0;
824 self->offset = self->currentVal;
825 (*self->mode_func_ptr)(self);
826 PLAY
827 };
828
829 static PyObject *
830 Adsr_stop(Adsr *self, PyObject *args, PyObject *kwds)
831 {
832 if (self->duration == 0.0)
833 {
834 self->fademode = 1;
835 self->currentTime = 0.0;
836 }
837 else
838 Adsr_internal_stop((Adsr *)self);
839
840 Py_RETURN_NONE;
841 }
842
843 static PyObject * Adsr_multiply(Adsr *self, PyObject *arg) { MULTIPLY };
844 static PyObject * Adsr_inplace_multiply(Adsr *self, PyObject *arg) { INPLACE_MULTIPLY };
845 static PyObject * Adsr_add(Adsr *self, PyObject *arg) { ADD };
846 static PyObject * Adsr_inplace_add(Adsr *self, PyObject *arg) { INPLACE_ADD };
847 static PyObject * Adsr_sub(Adsr *self, PyObject *arg) { SUB };
848 static PyObject * Adsr_inplace_sub(Adsr *self, PyObject *arg) { INPLACE_SUB };
849 static PyObject * Adsr_div(Adsr *self, PyObject *arg) { DIV };
850 static PyObject * Adsr_inplace_div(Adsr *self, PyObject *arg) { INPLACE_DIV };
851
852 static PyObject *
853 Adsr_setAttack(Adsr *self, PyObject *arg)
854 {
855 if (PyNumber_Check(arg))
856 {
857 self->attack = PyFloat_AsDouble(arg);
858
859 if (self->attack < 0.000001)
860 self->attack = 0.000001;
861 }
862
863 Py_RETURN_NONE;
864 }
865
866 static PyObject *
867 Adsr_setDecay(Adsr *self, PyObject *arg)
868 {
869 if (PyNumber_Check(arg))
870 {
871 self->decay = PyFloat_AsDouble(arg);
872
873 if (self->decay < 0.000001)
874 self->decay = 0.000001;
875 }
876
877 Py_RETURN_NONE;
878 }
879
880 static PyObject *
881 Adsr_setSustain(Adsr *self, PyObject *arg)
882 {
883 if (PyNumber_Check(arg))
884 {
885 self->sustain = PyFloat_AsDouble(arg);
886
887 if (self->sustain < 0.0)
888 self->sustain = 0.0;
889 else if (self->sustain > 1.0)
890 self->sustain = 1.0;
891 }
892
893 Py_RETURN_NONE;
894 }
895
896 static PyObject *
897 Adsr_setRelease(Adsr *self, PyObject *arg)
898 {
899 if (PyNumber_Check(arg))
900 {
901 self->release = PyFloat_AsDouble(arg);
902
903 if (self->release < 0.000001)
904 self->release = 0.000001;
905 }
906
907 Py_RETURN_NONE;
908 }
909
910 static PyObject *
911 Adsr_setDur(Adsr *self, PyObject *arg)
912 {
913 if (PyNumber_Check(arg))
914 self->duration = PyFloat_AsDouble(arg);
915
916 Py_RETURN_NONE;
917 }
918
919 static PyObject *
920 Adsr_setExp(Adsr *self, PyObject *arg)
921 {
922 if (PyNumber_Check(arg))
923 {
924 MYFLT tmp = PyFloat_AsDouble(arg);
925
926 if (tmp > 0.0)
927 self->exp = tmp;
928 }
929
930 Py_RETURN_NONE;
931 }
932
933 static PyMemberDef Adsr_members[] =
934 {
935 {"server", T_OBJECT_EX, offsetof(Adsr, server), 0, "Pyo server."},
936 {"stream", T_OBJECT_EX, offsetof(Adsr, stream), 0, "Stream object."},
937 {"trig_stream", T_OBJECT_EX, offsetof(Adsr, trig_stream), 0, "Trigger Stream object."},
938 {"mul", T_OBJECT_EX, offsetof(Adsr, mul), 0, "Mul factor."},
939 {"add", T_OBJECT_EX, offsetof(Adsr, add), 0, "Add factor."},
940 {NULL} /* Sentinel */
941 };
942
943 static PyMethodDef Adsr_methods[] =
944 {
945 {"getServer", (PyCFunction)Adsr_getServer, METH_NOARGS, "Returns server object."},
946 {"_getStream", (PyCFunction)Adsr_getStream, METH_NOARGS, "Returns stream object."},
947 {"_getTriggerStream", (PyCFunction)Adsr_getTriggerStream, METH_NOARGS, "Returns trigger stream object."},
948 {"play", (PyCFunction)Adsr_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
949 {"stop", (PyCFunction)Adsr_stop, METH_VARARGS | METH_KEYWORDS, "Starts fadeout and stops computing."},
950 {"setMul", (PyCFunction)Adsr_setMul, METH_O, "Sets Adsr mul factor."},
951 {"setAdd", (PyCFunction)Adsr_setAdd, METH_O, "Sets Adsr add factor."},
952 {"setSub", (PyCFunction)Adsr_setSub, METH_O, "Sets inverse add factor."},
953 {"setAttack", (PyCFunction)Adsr_setAttack, METH_O, "Sets attack time in seconds."},
954 {"setDecay", (PyCFunction)Adsr_setDecay, METH_O, "Sets attack time in seconds."},
955 {"setSustain", (PyCFunction)Adsr_setSustain, METH_O, "Sets attack time in seconds."},
956 {"setRelease", (PyCFunction)Adsr_setRelease, METH_O, "Sets release time in seconds."},
957 {"setDur", (PyCFunction)Adsr_setDur, METH_O, "Sets duration in seconds (0 means wait for stop method to start fadeout)."},
958 {"setExp", (PyCFunction)Adsr_setExp, METH_O, "Sets the exponent factor for exponential envelope."},
959 {"setDiv", (PyCFunction)Adsr_setDiv, METH_O, "Sets inverse mul factor."},
960 {NULL} /* Sentinel */
961 };
962
963 static PyNumberMethods Adsr_as_number =
964 {
965 (binaryfunc)Adsr_add, /*nb_add*/
966 (binaryfunc)Adsr_sub, /*nb_subtract*/
967 (binaryfunc)Adsr_multiply, /*nb_multiply*/
968 0, /*nb_remainder*/
969 0, /*nb_divmod*/
970 0, /*nb_power*/
971 0, /*nb_neg*/
972 0, /*nb_pos*/
973 0, /*(unaryfunc)array_abs,*/
974 0, /*nb_nonzero*/
975 0, /*nb_invert*/
976 0, /*nb_lshift*/
977 0, /*nb_rshift*/
978 0, /*nb_and*/
979 0, /*nb_xor*/
980 0, /*nb_or*/
981 0, /*nb_int*/
982 0, /*nb_long*/
983 0, /*nb_float*/
984 (binaryfunc)Adsr_inplace_add, /*inplace_add*/
985 (binaryfunc)Adsr_inplace_sub, /*inplace_subtract*/
986 (binaryfunc)Adsr_inplace_multiply, /*inplace_multiply*/
987 0, /*inplace_remainder*/
988 0, /*inplace_power*/
989 0, /*inplace_lshift*/
990 0, /*inplace_rshift*/
991 0, /*inplace_and*/
992 0, /*inplace_xor*/
993 0, /*inplace_or*/
994 0, /*nb_floor_divide*/
995 (binaryfunc)Adsr_div, /*nb_true_divide*/
996 0, /*nb_inplace_floor_divide*/
997 (binaryfunc)Adsr_inplace_div, /*nb_inplace_true_divide*/
998 0, /* nb_index */
999 };
1000
1001 PyTypeObject AdsrType =
1002 {
1003 PyVarObject_HEAD_INIT(NULL, 0)
1004 "_pyo.Adsr_base", /*tp_name*/
1005 sizeof(Adsr), /*tp_basicsize*/
1006 0, /*tp_itemsize*/
1007 (destructor)Adsr_dealloc, /*tp_dealloc*/
1008 0, /*tp_print*/
1009 0, /*tp_getattr*/
1010 0, /*tp_setattr*/
1011 0, /*tp_as_async (tp_compare in Python 2)*/
1012 0, /*tp_repr*/
1013 &Adsr_as_number, /*tp_as_number*/
1014 0, /*tp_as_sequence*/
1015 0, /*tp_as_mapping*/
1016 0, /*tp_hash */
1017 0, /*tp_call*/
1018 0, /*tp_str*/
1019 0, /*tp_getattro*/
1020 0, /*tp_setattro*/
1021 0, /*tp_as_buffer*/
1022 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1023 "Adsr objects. Generates Adsr envelope signal.", /* tp_doc */
1024 (traverseproc)Adsr_traverse, /* tp_traverse */
1025 (inquiry)Adsr_clear, /* tp_clear */
1026 0, /* tp_richcompare */
1027 0, /* tp_weaklistoffset */
1028 0, /* tp_iter */
1029 0, /* tp_iternext */
1030 Adsr_methods, /* tp_methods */
1031 Adsr_members, /* tp_members */
1032 0, /* tp_getset */
1033 0, /* tp_base */
1034 0, /* tp_dict */
1035 0, /* tp_descr_get */
1036 0, /* tp_descr_set */
1037 0, /* tp_dictoffset */
1038 0, /* tp_init */
1039 0, /* tp_alloc */
1040 Adsr_new, /* tp_new */
1041 };
1042
1043 typedef struct
1044 {
1045 pyo_audio_HEAD
1046 PyObject *pointslist;
1047 int modebuffer[2];
1048 double currentTime;
1049 double currentValue;
1050 double sampleToSec;
1051 double increment;
1052 double *targets;
1053 double *times;
1054 int which;
1055 int flag;
1056 int newlist;
1057 int loop;
1058 int listsize;
1059 int okToPause;
1060 } Linseg;
1061
1062 static void
1063 Linseg_convert_pointslist(Linseg *self)
1064 {
1065 int i;
1066 PyObject *tup;
1067
1068 self->listsize = PyList_Size(self->pointslist);
1069 self->targets = (double *)PyMem_RawRealloc(self->targets, self->listsize * sizeof(double));
1070 self->times = (double *)PyMem_RawRealloc(self->times, self->listsize * sizeof(double));
1071
1072 for (i = 0; i < self->listsize; i++)
1073 {
1074 tup = PyList_GET_ITEM(self->pointslist, i);
1075 self->times[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 0));
1076 self->targets[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1));
1077 }
1078 }
1079
1080 static void
1081 Linseg_reinit(Linseg *self)
1082 {
1083 if (self->newlist == 1)
1084 {
1085 Linseg_convert_pointslist((Linseg *)self);
1086 self->newlist = 0;
1087 }
1088
1089 self->currentTime = 0.0;
1090 self->currentValue = self->targets[0];
1091 self->which = 0;
1092 self->flag = 1;
1093 self->okToPause = 1;
1094 }
1095
1096 static void
1097 Linseg_generate(Linseg *self)
1098 {
1099 int i;
1100
1101 for (i = 0; i < self->bufsize; i++)
1102 {
1103 if (self->flag == 1)
1104 {
1105 if (self->currentTime >= self->times[self->which])
1106 {
1107 self->which++;
1108
1109 if (self->which == self->listsize)
1110 {
1111 if (self->loop == 1)
1112 Linseg_reinit((Linseg *)self);
1113 else
1114 {
1115 self->flag = 0;
1116 self->okToPause = 0;
1117 self->currentValue = self->targets[self->which - 1];
1118 }
1119 }
1120 else
1121 {
1122 if ((self->times[self->which] - self->times[self->which - 1]) <= self->sampleToSec)
1123 {
1124 self->increment = self->targets[self->which] - self->currentValue;
1125 }
1126 else
1127 {
1128 double targetDiff = self->targets[self->which] - self->targets[self->which - 1];
1129 double timeDiff = self->times[self->which] - self->times[self->which - 1];
1130 self->increment = targetDiff / (timeDiff / self->sampleToSec);
1131 }
1132 self->currentValue = (MYFLT)self->targets[self->which - 1];
1133 self->currentTime += self->sampleToSec;
1134 }
1135
1136 self->data[i] = (MYFLT)self->currentValue;
1137 continue;
1138 }
1139
1140 if (self->currentTime <= self->times[self->listsize - 1])
1141 self->currentValue += self->increment;
1142
1143 self->data[i] = (MYFLT)self->currentValue;
1144 self->currentTime += self->sampleToSec;
1145 }
1146 else
1147 self->data[i] = (MYFLT)self->currentValue;
1148 }
1149 }
1150
1151 static void Linseg_postprocessing_ii(Linseg *self) { POST_PROCESSING_II };
1152 static void Linseg_postprocessing_ai(Linseg *self) { POST_PROCESSING_AI };
1153 static void Linseg_postprocessing_ia(Linseg *self) { POST_PROCESSING_IA };
1154 static void Linseg_postprocessing_aa(Linseg *self) { POST_PROCESSING_AA };
1155 static void Linseg_postprocessing_ireva(Linseg *self) { POST_PROCESSING_IREVA };
1156 static void Linseg_postprocessing_areva(Linseg *self) { POST_PROCESSING_AREVA };
1157 static void Linseg_postprocessing_revai(Linseg *self) { POST_PROCESSING_REVAI };
1158 static void Linseg_postprocessing_revaa(Linseg *self) { POST_PROCESSING_REVAA };
1159 static void Linseg_postprocessing_revareva(Linseg *self) { POST_PROCESSING_REVAREVA };
1160
1161 static void
1162 Linseg_setProcMode(Linseg *self)
1163 {
1164 int muladdmode;
1165 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1166
1167 self->proc_func_ptr = Linseg_generate;
1168
1169 switch (muladdmode)
1170 {
1171 case 0:
1172 self->muladd_func_ptr = Linseg_postprocessing_ii;
1173 break;
1174
1175 case 1:
1176 self->muladd_func_ptr = Linseg_postprocessing_ai;
1177 break;
1178
1179 case 2:
1180 self->muladd_func_ptr = Linseg_postprocessing_revai;
1181 break;
1182
1183 case 10:
1184 self->muladd_func_ptr = Linseg_postprocessing_ia;
1185 break;
1186
1187 case 11:
1188 self->muladd_func_ptr = Linseg_postprocessing_aa;
1189 break;
1190
1191 case 12:
1192 self->muladd_func_ptr = Linseg_postprocessing_revaa;
1193 break;
1194
1195 case 20:
1196 self->muladd_func_ptr = Linseg_postprocessing_ireva;
1197 break;
1198
1199 case 21:
1200 self->muladd_func_ptr = Linseg_postprocessing_areva;
1201 break;
1202
1203 case 22:
1204 self->muladd_func_ptr = Linseg_postprocessing_revareva;
1205 break;
1206 }
1207 }
1208
1209 static void
1210 Linseg_compute_next_data_frame(Linseg *self)
1211 {
1212 (*self->proc_func_ptr)(self);
1213 (*self->muladd_func_ptr)(self);
1214 }
1215
1216 static int
1217 Linseg_traverse(Linseg *self, visitproc visit, void *arg)
1218 {
1219 pyo_VISIT
1220 Py_VISIT(self->pointslist);
1221 return 0;
1222 }
1223
1224 static int
1225 Linseg_clear(Linseg *self)
1226 {
1227 pyo_CLEAR
1228 Py_CLEAR(self->pointslist);
1229 return 0;
1230 }
1231
1232 static void
1233 Linseg_dealloc(Linseg* self)
1234 {
1235 pyo_DEALLOC
1236 PyMem_RawFree(self->targets);
1237 PyMem_RawFree(self->times);
1238 Linseg_clear(self);
1239 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1240 Py_TYPE(self)->tp_free((PyObject*)self);
1241 }
1242
1243 static PyObject *
1244 Linseg_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1245 {
1246 int i, initToFirstVal = 0;
1247 PyObject *pointslist = NULL, *multmp = NULL, *addtmp = NULL;
1248 Linseg *self;
1249 self = (Linseg *)type->tp_alloc(type, 0);
1250
1251 self->loop = 0;
1252 self->newlist = 1;
1253 self->okToPause = 0;
1254 self->modebuffer[0] = 0;
1255 self->modebuffer[1] = 0;
1256
1257 INIT_OBJECT_COMMON
1258 Stream_setFunctionPtr(self->stream, Linseg_compute_next_data_frame);
1259 self->mode_func_ptr = Linseg_setProcMode;
1260
1261 self->sampleToSec = 1. / self->sr;
1262
1263 static char *kwlist[] = {"list", "loop", "initToFirstVal", "mul", "add", NULL};
1264
1265 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|iiOO", kwlist, &pointslist, &self->loop, &initToFirstVal, &multmp, &addtmp))
1266 Py_RETURN_NONE;
1267
1268 self->pointslist = pointslist;
1269 Py_INCREF(self->pointslist);
1270 Linseg_convert_pointslist((Linseg *)self);
1271
1272 if (multmp)
1273 {
1274 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1275 }
1276
1277 if (addtmp)
1278 {
1279 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1280 }
1281
1282 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1283
1284 if (initToFirstVal)
1285 {
1286 for (i = 0; i < self->bufsize; i++)
1287 {
1288 self->data[i] = self->targets[0];
1289 }
1290 }
1291
1292 (*self->mode_func_ptr)(self);
1293
1294 return (PyObject *)self;
1295 }
1296
1297 static PyObject * Linseg_getServer(Linseg* self) { GET_SERVER };
1298 static PyObject * Linseg_getStream(Linseg* self) { GET_STREAM };
1299 static PyObject * Linseg_setMul(Linseg *self, PyObject *arg) { SET_MUL };
1300 static PyObject * Linseg_setAdd(Linseg *self, PyObject *arg) { SET_ADD };
1301 static PyObject * Linseg_setSub(Linseg *self, PyObject *arg) { SET_SUB };
1302 static PyObject * Linseg_setDiv(Linseg *self, PyObject *arg) { SET_DIV };
1303
1304 static PyObject * Linseg_play(Linseg *self, PyObject *args, PyObject *kwds)
1305 {
1306 Linseg_reinit((Linseg *)self);
1307 PLAY
1308 };
1309
1310 static PyObject * Linseg_stop(Linseg *self, PyObject *args, PyObject *kwds)
1311 {
1312 self->okToPause = 0;
1313 STOP
1314 };
1315
1316 static PyObject * Linseg_pause(Linseg *self)
1317 {
1318 if (self->okToPause == 1)
1319 self->flag = 1 - self->flag;
1320
1321 Py_RETURN_NONE;
1322 };
1323
1324 static PyObject * Linseg_multiply(Linseg *self, PyObject *arg) { MULTIPLY };
1325 static PyObject * Linseg_inplace_multiply(Linseg *self, PyObject *arg) { INPLACE_MULTIPLY };
1326 static PyObject * Linseg_add(Linseg *self, PyObject *arg) { ADD };
1327 static PyObject * Linseg_inplace_add(Linseg *self, PyObject *arg) { INPLACE_ADD };
1328 static PyObject * Linseg_sub(Linseg *self, PyObject *arg) { SUB };
1329 static PyObject * Linseg_inplace_sub(Linseg *self, PyObject *arg) { INPLACE_SUB };
1330 static PyObject * Linseg_div(Linseg *self, PyObject *arg) { DIV };
1331 static PyObject * Linseg_inplace_div(Linseg *self, PyObject *arg) { INPLACE_DIV };
1332
1333 static PyObject *
1334 Linseg_setList(Linseg *self, PyObject *value)
1335 {
1336 if (value == NULL)
1337 {
1338 PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute.");
1339 return PyLong_FromLong(-1);
1340 }
1341
1342 if (! PyList_Check(value))
1343 {
1344 PyErr_SetString(PyExc_TypeError, "The points list attribute value must be a list of tuples.");
1345 return PyLong_FromLong(-1);
1346 }
1347
1348 Py_INCREF(value);
1349 Py_DECREF(self->pointslist);
1350 self->pointslist = value;
1351
1352 self->newlist = 1;
1353
1354 Py_RETURN_NONE;
1355 }
1356
1357 static PyObject *
1358 Linseg_setLoop(Linseg *self, PyObject *arg)
1359 {
1360 ASSERT_ARG_NOT_NULL
1361
1362 self->loop = PyLong_AsLong(arg);
1363
1364 Py_RETURN_NONE;
1365 }
1366
1367 static PyObject *
1368 Linseg_clear_data(Linseg *self)
1369 {
1370 int i;
1371 self->currentValue = 0.0;
1372
1373 for (i = 0; i < self->bufsize; i++)
1374 {
1375 self->data[i] = 0.0;
1376 }
1377
1378 Py_RETURN_NONE;
1379 }
1380
1381 static PyMemberDef Linseg_members[] =
1382 {
1383 {"server", T_OBJECT_EX, offsetof(Linseg, server), 0, "Pyo server."},
1384 {"stream", T_OBJECT_EX, offsetof(Linseg, stream), 0, "Stream object."},
1385 {"pointslist", T_OBJECT_EX, offsetof(Linseg, pointslist), 0, "List of target points."},
1386 {"mul", T_OBJECT_EX, offsetof(Linseg, mul), 0, "Mul factor."},
1387 {"add", T_OBJECT_EX, offsetof(Linseg, add), 0, "Add factor."},
1388 {NULL} /* Sentinel */
1389 };
1390
1391 static PyMethodDef Linseg_methods[] =
1392 {
1393 {"getServer", (PyCFunction)Linseg_getServer, METH_NOARGS, "Returns server object."},
1394 {"_getStream", (PyCFunction)Linseg_getStream, METH_NOARGS, "Returns stream object."},
1395 {"play", (PyCFunction)Linseg_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1396 {"stop", (PyCFunction)Linseg_stop, METH_VARARGS | METH_KEYWORDS, "Starts fadeout and stops computing."},
1397 {"clear", (PyCFunction)Linseg_clear_data, METH_NOARGS, "Resets the data buffer to 0."},
1398 {"pause", (PyCFunction)Linseg_pause, METH_NOARGS, "Toggles between play and stop without reset."},
1399 {"setList", (PyCFunction)Linseg_setList, METH_O, "Sets target points list."},
1400 {"setLoop", (PyCFunction)Linseg_setLoop, METH_O, "Sets looping mode."},
1401 {"setMul", (PyCFunction)Linseg_setMul, METH_O, "Sets Linseg mul factor."},
1402 {"setAdd", (PyCFunction)Linseg_setAdd, METH_O, "Sets Linseg add factor."},
1403 {"setSub", (PyCFunction)Linseg_setSub, METH_O, "Sets inverse add factor."},
1404 {"setDiv", (PyCFunction)Linseg_setDiv, METH_O, "Sets inverse mul factor."},
1405 {NULL} /* Sentinel */
1406 };
1407
1408 static PyNumberMethods Linseg_as_number =
1409 {
1410 (binaryfunc)Linseg_add, /*nb_add*/
1411 (binaryfunc)Linseg_sub, /*nb_subtract*/
1412 (binaryfunc)Linseg_multiply, /*nb_multiply*/
1413 0, /*nb_remainder*/
1414 0, /*nb_divmod*/
1415 0, /*nb_power*/
1416 0, /*nb_neg*/
1417 0, /*nb_pos*/
1418 0, /*(unaryfunc)array_abs,*/
1419 0, /*nb_nonzero*/
1420 0, /*nb_invert*/
1421 0, /*nb_lshift*/
1422 0, /*nb_rshift*/
1423 0, /*nb_and*/
1424 0, /*nb_xor*/
1425 0, /*nb_or*/
1426 0, /*nb_int*/
1427 0, /*nb_long*/
1428 0, /*nb_float*/
1429 (binaryfunc)Linseg_inplace_add, /*inplace_add*/
1430 (binaryfunc)Linseg_inplace_sub, /*inplace_subtract*/
1431 (binaryfunc)Linseg_inplace_multiply, /*inplace_multiply*/
1432 0, /*inplace_remainder*/
1433 0, /*inplace_power*/
1434 0, /*inplace_lshift*/
1435 0, /*inplace_rshift*/
1436 0, /*inplace_and*/
1437 0, /*inplace_xor*/
1438 0, /*inplace_or*/
1439 0, /*nb_floor_divide*/
1440 (binaryfunc)Linseg_div, /*nb_true_divide*/
1441 0, /*nb_inplace_floor_divide*/
1442 (binaryfunc)Linseg_inplace_div, /*nb_inplace_true_divide*/
1443 0, /* nb_index */
1444 };
1445
1446 PyTypeObject LinsegType =
1447 {
1448 PyVarObject_HEAD_INIT(NULL, 0)
1449 "_pyo.Linseg_base", /*tp_name*/
1450 sizeof(Linseg), /*tp_basicsize*/
1451 0, /*tp_itemsize*/
1452 (destructor)Linseg_dealloc, /*tp_dealloc*/
1453 0, /*tp_print*/
1454 0, /*tp_getattr*/
1455 0, /*tp_setattr*/
1456 0, /*tp_as_async (tp_compare in Python 2)*/
1457 0, /*tp_repr*/
1458 &Linseg_as_number, /*tp_as_number*/
1459 0, /*tp_as_sequence*/
1460 0, /*tp_as_mapping*/
1461 0, /*tp_hash */
1462 0, /*tp_call*/
1463 0, /*tp_str*/
1464 0, /*tp_getattro*/
1465 0, /*tp_setattro*/
1466 0, /*tp_as_buffer*/
1467 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1468 "Linseg objects. Generates a linear segments break-points line.", /* tp_doc */
1469 (traverseproc)Linseg_traverse, /* tp_traverse */
1470 (inquiry)Linseg_clear, /* tp_clear */
1471 0, /* tp_richcompare */
1472 0, /* tp_weaklistoffset */
1473 0, /* tp_iter */
1474 0, /* tp_iternext */
1475 Linseg_methods, /* tp_methods */
1476 Linseg_members, /* tp_members */
1477 0, /* tp_getset */
1478 0, /* tp_base */
1479 0, /* tp_dict */
1480 0, /* tp_descr_get */
1481 0, /* tp_descr_set */
1482 0, /* tp_dictoffset */
1483 0, /* tp_init */
1484 0, /* tp_alloc */
1485 Linseg_new, /* tp_new */
1486 };
1487
1488 typedef struct
1489 {
1490 pyo_audio_HEAD
1491 PyObject *pointslist;
1492 int modebuffer[2];
1493 double currentTime;
1494 double currentValue;
1495 double sampleToSec;
1496 double inc;
1497 double pointer;
1498 double range;
1499 double steps;
1500 double *targets;
1501 double *times;
1502 int which;
1503 int flag;
1504 int newlist;
1505 int loop;
1506 int listsize;
1507 double exp;
1508 double exp_tmp;
1509 int inverse;
1510 int inverse_tmp;
1511 int okToPause;
1512 } Expseg;
1513
1514 static void
1515 Expseg_convert_pointslist(Expseg *self)
1516 {
1517 int i;
1518 PyObject *tup;
1519
1520 self->listsize = PyList_Size(self->pointslist);
1521 self->targets = (double *)PyMem_RawRealloc(self->targets, self->listsize * sizeof(double));
1522 self->times = (double *)PyMem_RawRealloc(self->times, self->listsize * sizeof(double));
1523
1524 for (i = 0; i < self->listsize; i++)
1525 {
1526 tup = PyList_GET_ITEM(self->pointslist, i);
1527 self->times[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 0));
1528 self->targets[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1));
1529 }
1530 }
1531
1532 static void
1533 Expseg_reinit(Expseg *self)
1534 {
1535 if (self->newlist == 1)
1536 {
1537 Expseg_convert_pointslist((Expseg *)self);
1538 self->newlist = 0;
1539 }
1540
1541 self->currentTime = 0.0;
1542 self->currentValue = self->targets[0];
1543 self->which = 0;
1544 self->flag = 1;
1545 self->exp = self->exp_tmp;
1546 self->inverse = self->inverse_tmp;
1547 self->okToPause = 1;
1548 self->pointer = 0.0;
1549 }
1550
1551 static void
1552 Expseg_generate(Expseg *self)
1553 {
1554 int i;
1555 double scl;
1556
1557 for (i = 0; i < self->bufsize; i++)
1558 {
1559 if (self->flag == 1)
1560 {
1561 if (self->currentTime >= self->times[self->which])
1562 {
1563 self->which++;
1564
1565 if (self->which == self->listsize)
1566 {
1567 if (self->loop == 1)
1568 Expseg_reinit((Expseg *)self);
1569 else
1570 {
1571 self->flag = 0;
1572 self->currentValue = self->targets[self->which - 1];
1573 self->okToPause = 0;
1574 self->pointer = 0.0;
1575 }
1576 self->data[i] = (MYFLT)self->currentValue;
1577 continue;
1578 }
1579 else
1580 {
1581 self->range = self->targets[self->which] - self->targets[self->which - 1];
1582 self->steps = (self->times[self->which] - self->times[self->which - 1]) * self->sr;
1583
1584 if (self->steps <= 0)
1585 self->inc = 1.0;
1586 else
1587 self->inc = 1.0 / self->steps;
1588
1589 self->pointer = 0.0;
1590 }
1591 }
1592
1593 if (self->currentTime <= self->times[self->listsize - 1])
1594 {
1595 if (self->pointer >= 1.0)
1596 self->pointer = 1.0;
1597
1598 if (self->inverse == 1 && self->range < 0.0)
1599 scl = 1.0 - pow(1.0 - self->pointer, self->exp);
1600 else
1601 scl = pow(self->pointer, self->exp);
1602
1603 self->currentValue = scl * self->range + self->targets[self->which - 1];
1604 self->pointer += self->inc;
1605 }
1606
1607 self->data[i] = (MYFLT)self->currentValue;
1608 self->currentTime += self->sampleToSec;
1609 }
1610 else
1611 self->data[i] = (MYFLT)self->currentValue;
1612 }
1613 }
1614
1615 static void Expseg_postprocessing_ii(Expseg *self) { POST_PROCESSING_II };
1616 static void Expseg_postprocessing_ai(Expseg *self) { POST_PROCESSING_AI };
1617 static void Expseg_postprocessing_ia(Expseg *self) { POST_PROCESSING_IA };
1618 static void Expseg_postprocessing_aa(Expseg *self) { POST_PROCESSING_AA };
1619 static void Expseg_postprocessing_ireva(Expseg *self) { POST_PROCESSING_IREVA };
1620 static void Expseg_postprocessing_areva(Expseg *self) { POST_PROCESSING_AREVA };
1621 static void Expseg_postprocessing_revai(Expseg *self) { POST_PROCESSING_REVAI };
1622 static void Expseg_postprocessing_revaa(Expseg *self) { POST_PROCESSING_REVAA };
1623 static void Expseg_postprocessing_revareva(Expseg *self) { POST_PROCESSING_REVAREVA };
1624
1625 static void
1626 Expseg_setProcMode(Expseg *self)
1627 {
1628 int muladdmode;
1629 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1630
1631 self->proc_func_ptr = Expseg_generate;
1632
1633 switch (muladdmode)
1634 {
1635 case 0:
1636 self->muladd_func_ptr = Expseg_postprocessing_ii;
1637 break;
1638
1639 case 1:
1640 self->muladd_func_ptr = Expseg_postprocessing_ai;
1641 break;
1642
1643 case 2:
1644 self->muladd_func_ptr = Expseg_postprocessing_revai;
1645 break;
1646
1647 case 10:
1648 self->muladd_func_ptr = Expseg_postprocessing_ia;
1649 break;
1650
1651 case 11:
1652 self->muladd_func_ptr = Expseg_postprocessing_aa;
1653 break;
1654
1655 case 12:
1656 self->muladd_func_ptr = Expseg_postprocessing_revaa;
1657 break;
1658
1659 case 20:
1660 self->muladd_func_ptr = Expseg_postprocessing_ireva;
1661 break;
1662
1663 case 21:
1664 self->muladd_func_ptr = Expseg_postprocessing_areva;
1665 break;
1666
1667 case 22:
1668 self->muladd_func_ptr = Expseg_postprocessing_revareva;
1669 break;
1670 }
1671 }
1672
1673 static void
1674 Expseg_compute_next_data_frame(Expseg *self)
1675 {
1676 (*self->proc_func_ptr)(self);
1677 (*self->muladd_func_ptr)(self);
1678 }
1679
1680 static int
1681 Expseg_traverse(Expseg *self, visitproc visit, void *arg)
1682 {
1683 pyo_VISIT
1684 Py_VISIT(self->pointslist);
1685 return 0;
1686 }
1687
1688 static int
1689 Expseg_clear(Expseg *self)
1690 {
1691 pyo_CLEAR
1692 Py_CLEAR(self->pointslist);
1693 return 0;
1694 }
1695
1696 static void
1697 Expseg_dealloc(Expseg* self)
1698 {
1699 pyo_DEALLOC
1700 PyMem_RawFree(self->targets);
1701 PyMem_RawFree(self->times);
1702 Expseg_clear(self);
1703 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1704 Py_TYPE(self)->tp_free((PyObject*)self);
1705 }
1706
1707 static PyObject *
1708 Expseg_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1709 {
1710 int i, initToFirstVal = 0;
1711 PyObject *pointslist = NULL, *multmp = NULL, *addtmp = NULL;
1712 Expseg *self;
1713 self = (Expseg *)type->tp_alloc(type, 0);
1714
1715 self->loop = 0;
1716 self->newlist = 1;
1717 self->exp = self->exp_tmp = 10;
1718 self->inverse = self->inverse_tmp = 1;
1719 self->okToPause = 0;
1720 self->modebuffer[0] = 0;
1721 self->modebuffer[1] = 0;
1722
1723 INIT_OBJECT_COMMON
1724 Stream_setFunctionPtr(self->stream, Expseg_compute_next_data_frame);
1725 self->mode_func_ptr = Expseg_setProcMode;
1726
1727 self->sampleToSec = 1. / self->sr;
1728
1729 static char *kwlist[] = {"list", "loop", "exp", "inverse", "initToFirstVal", "mul", "add", NULL};
1730
1731 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|idiiOO", kwlist, &pointslist, &self->loop, &self->exp_tmp, &self->inverse_tmp, &initToFirstVal, &multmp, &addtmp))
1732 Py_RETURN_NONE;
1733
1734 self->pointslist = pointslist;
1735 Py_INCREF(self->pointslist);
1736 Expseg_convert_pointslist((Expseg *)self);
1737
1738 if (multmp)
1739 {
1740 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1741 }
1742
1743 if (addtmp)
1744 {
1745 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1746 }
1747
1748 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1749
1750 if (initToFirstVal)
1751 {
1752 for (i = 0; i < self->bufsize; i++)
1753 {
1754 self->data[i] = self->targets[0];
1755 }
1756 }
1757
1758 (*self->mode_func_ptr)(self);
1759
1760 return (PyObject *)self;
1761 }
1762
1763 static PyObject * Expseg_getServer(Expseg* self) { GET_SERVER };
1764 static PyObject * Expseg_getStream(Expseg* self) { GET_STREAM };
1765 static PyObject * Expseg_setMul(Expseg *self, PyObject *arg) { SET_MUL };
1766 static PyObject * Expseg_setAdd(Expseg *self, PyObject *arg) { SET_ADD };
1767 static PyObject * Expseg_setSub(Expseg *self, PyObject *arg) { SET_SUB };
1768 static PyObject * Expseg_setDiv(Expseg *self, PyObject *arg) { SET_DIV };
1769
1770 static PyObject * Expseg_play(Expseg *self, PyObject *args, PyObject *kwds)
1771 {
1772 Expseg_reinit((Expseg *)self);
1773 PLAY
1774 };
1775
1776 static PyObject * Expseg_stop(Expseg *self, PyObject *args, PyObject *kwds)
1777 {
1778 self->okToPause = 0;
1779 STOP
1780 };
1781
1782 static PyObject * Expseg_pause(Expseg *self)
1783 {
1784 if (self->okToPause == 1)
1785 self->flag = 1 - self->flag;
1786
1787 Py_RETURN_NONE;
1788 };
1789
1790 static PyObject * Expseg_multiply(Expseg *self, PyObject *arg) { MULTIPLY };
1791 static PyObject * Expseg_inplace_multiply(Expseg *self, PyObject *arg) { INPLACE_MULTIPLY };
1792 static PyObject * Expseg_add(Expseg *self, PyObject *arg) { ADD };
1793 static PyObject * Expseg_inplace_add(Expseg *self, PyObject *arg) { INPLACE_ADD };
1794 static PyObject * Expseg_sub(Expseg *self, PyObject *arg) { SUB };
1795 static PyObject * Expseg_inplace_sub(Expseg *self, PyObject *arg) { INPLACE_SUB };
1796 static PyObject * Expseg_div(Expseg *self, PyObject *arg) { DIV };
1797 static PyObject * Expseg_inplace_div(Expseg *self, PyObject *arg) { INPLACE_DIV };
1798
1799 static PyObject *
1800 Expseg_setList(Expseg *self, PyObject *value)
1801 {
1802 if (value == NULL)
1803 {
1804 PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute.");
1805 return PyLong_FromLong(-1);
1806 }
1807
1808 if (! PyList_Check(value))
1809 {
1810 PyErr_SetString(PyExc_TypeError, "The points list attribute value must be a list of tuples.");
1811 return PyLong_FromLong(-1);
1812 }
1813
1814 Py_INCREF(value);
1815 Py_DECREF(self->pointslist);
1816 self->pointslist = value;
1817
1818 self->newlist = 1;
1819
1820 Py_RETURN_NONE;
1821 }
1822
1823 static PyObject *
1824 Expseg_setLoop(Expseg *self, PyObject *arg)
1825 {
1826 ASSERT_ARG_NOT_NULL
1827
1828 self->loop = PyLong_AsLong(arg);
1829
1830 Py_RETURN_NONE;
1831 }
1832
1833 static PyObject *
1834 Expseg_setExp(Expseg *self, PyObject *arg)
1835 {
1836 ASSERT_ARG_NOT_NULL
1837
1838 if (PyNumber_Check(arg))
1839 self->exp_tmp = PyFloat_AsDouble(arg);
1840
1841 Py_RETURN_NONE;
1842 }
1843
1844 static PyObject *
1845 Expseg_setInverse(Expseg *self, PyObject *arg)
1846 {
1847 ASSERT_ARG_NOT_NULL
1848
1849 if (PyNumber_Check(arg))
1850 self->inverse_tmp = PyLong_AsLong(PyNumber_Long(arg));
1851
1852 Py_RETURN_NONE;
1853 }
1854
1855 static PyObject *
1856 Expseg_clear_data(Linseg *self)
1857 {
1858 int i;
1859 self->currentValue = 0.0;
1860
1861 for (i = 0; i < self->bufsize; i++)
1862 {
1863 self->data[i] = 0.0;
1864 }
1865
1866 Py_RETURN_NONE;
1867 }
1868
1869 static PyMemberDef Expseg_members[] =
1870 {
1871 {"server", T_OBJECT_EX, offsetof(Expseg, server), 0, "Pyo server."},
1872 {"stream", T_OBJECT_EX, offsetof(Expseg, stream), 0, "Stream object."},
1873 {"pointslist", T_OBJECT_EX, offsetof(Expseg, pointslist), 0, "List of target points."},
1874 {"mul", T_OBJECT_EX, offsetof(Expseg, mul), 0, "Mul factor."},
1875 {"add", T_OBJECT_EX, offsetof(Expseg, add), 0, "Add factor."},
1876 {NULL} /* Sentinel */
1877 };
1878
1879 static PyMethodDef Expseg_methods[] =
1880 {
1881 {"getServer", (PyCFunction)Expseg_getServer, METH_NOARGS, "Returns server object."},
1882 {"_getStream", (PyCFunction)Expseg_getStream, METH_NOARGS, "Returns stream object."},
1883 {"play", (PyCFunction)Expseg_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1884 {"stop", (PyCFunction)Expseg_stop, METH_VARARGS | METH_KEYWORDS, "Starts fadeout and stops computing."},
1885 {"pause", (PyCFunction)Expseg_pause, METH_NOARGS, "Toggles between play and stop without reset."},
1886 {"setList", (PyCFunction)Expseg_setList, METH_O, "Sets target points list."},
1887 {"setLoop", (PyCFunction)Expseg_setLoop, METH_O, "Sets looping mode."},
1888 {"setExp", (PyCFunction)Expseg_setExp, METH_O, "Sets exponent factor."},
1889 {"setInverse", (PyCFunction)Expseg_setInverse, METH_O, "Sets inverse factor."},
1890 {"clear", (PyCFunction)Expseg_clear_data, METH_NOARGS, "Resets the data buffer to 0."},
1891 {"setMul", (PyCFunction)Expseg_setMul, METH_O, "Sets Expseg mul factor."},
1892 {"setAdd", (PyCFunction)Expseg_setAdd, METH_O, "Sets Expseg add factor."},
1893 {"setSub", (PyCFunction)Expseg_setSub, METH_O, "Sets inverse add factor."},
1894 {"setDiv", (PyCFunction)Expseg_setDiv, METH_O, "Sets inverse mul factor."},
1895 {NULL} /* Sentinel */
1896 };
1897
1898 static PyNumberMethods Expseg_as_number =
1899 {
1900 (binaryfunc)Expseg_add, /*nb_add*/
1901 (binaryfunc)Expseg_sub, /*nb_subtract*/
1902 (binaryfunc)Expseg_multiply, /*nb_multiply*/
1903 0, /*nb_remainder*/
1904 0, /*nb_divmod*/
1905 0, /*nb_power*/
1906 0, /*nb_neg*/
1907 0, /*nb_pos*/
1908 0, /*(unaryfunc)array_abs,*/
1909 0, /*nb_nonzero*/
1910 0, /*nb_invert*/
1911 0, /*nb_lshift*/
1912 0, /*nb_rshift*/
1913 0, /*nb_and*/
1914 0, /*nb_xor*/
1915 0, /*nb_or*/
1916 0, /*nb_int*/
1917 0, /*nb_long*/
1918 0, /*nb_float*/
1919 (binaryfunc)Expseg_inplace_add, /*inplace_add*/
1920 (binaryfunc)Expseg_inplace_sub, /*inplace_subtract*/
1921 (binaryfunc)Expseg_inplace_multiply, /*inplace_multiply*/
1922 0, /*inplace_remainder*/
1923 0, /*inplace_power*/
1924 0, /*inplace_lshift*/
1925 0, /*inplace_rshift*/
1926 0, /*inplace_and*/
1927 0, /*inplace_xor*/
1928 0, /*inplace_or*/
1929 0, /*nb_floor_divide*/
1930 (binaryfunc)Expseg_div, /*nb_true_divide*/
1931 0, /*nb_inplace_floor_divide*/
1932 (binaryfunc)Expseg_inplace_div, /*nb_inplace_true_divide*/
1933 0, /* nb_index */
1934 };
1935
1936 PyTypeObject ExpsegType =
1937 {
1938 PyVarObject_HEAD_INIT(NULL, 0)
1939 "_pyo.Expseg_base", /*tp_name*/
1940 sizeof(Expseg), /*tp_basicsize*/
1941 0, /*tp_itemsize*/
1942 (destructor)Expseg_dealloc, /*tp_dealloc*/
1943 0, /*tp_print*/
1944 0, /*tp_getattr*/
1945 0, /*tp_setattr*/
1946 0, /*tp_as_async (tp_compare in Python 2)*/
1947 0, /*tp_repr*/
1948 &Expseg_as_number, /*tp_as_number*/
1949 0, /*tp_as_sequence*/
1950 0, /*tp_as_mapping*/
1951 0, /*tp_hash */
1952 0, /*tp_call*/
1953 0, /*tp_str*/
1954 0, /*tp_getattro*/
1955 0, /*tp_setattro*/
1956 0, /*tp_as_buffer*/
1957 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1958 "Expseg objects. Generates a linear segments break-points line.", /* tp_doc */
1959 (traverseproc)Expseg_traverse, /* tp_traverse */
1960 (inquiry)Expseg_clear, /* tp_clear */
1961 0, /* tp_richcompare */
1962 0, /* tp_weaklistoffset */
1963 0, /* tp_iter */
1964 0, /* tp_iternext */
1965 Expseg_methods, /* tp_methods */
1966 Expseg_members, /* tp_members */
1967 0, /* tp_getset */
1968 0, /* tp_base */
1969 0, /* tp_dict */
1970 0, /* tp_descr_get */
1971 0, /* tp_descr_set */
1972 0, /* tp_dictoffset */
1973 0, /* tp_init */
1974 0, /* tp_alloc */
1975 Expseg_new, /* tp_new */
1976 };