| 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 <math.h> |
| 24 |
#include "pyomodule.h" |
| 25 |
#include "streammodule.h" |
| 26 |
#include "servermodule.h" |
| 27 |
#include "dummymodule.h" |
| 28 |
|
| 29 |
typedef struct |
| 30 |
{ |
| 31 |
pyo_audio_HEAD |
| 32 |
PyObject *callable; |
| 33 |
int ctlnumber; |
| 34 |
int toprint; |
| 35 |
} CtlScan; |
| 36 |
|
| 37 |
static void |
| 38 |
CtlScan_setProcMode(CtlScan *self) {} |
| 39 |
|
| 40 |
static void |
| 41 |
CtlScan_compute_next_data_frame(CtlScan *self) |
| 42 |
{ |
| 43 |
PyoMidiEvent *buffer; |
| 44 |
int i, count; |
| 45 |
|
| 46 |
buffer = Server_getMidiEventBuffer((Server *)self->server); |
| 47 |
count = Server_getMidiEventCount((Server *)self->server); |
| 48 |
|
| 49 |
if (count > 0) |
| 50 |
{ |
| 51 |
PyObject *tup; |
| 52 |
|
| 53 |
for (i = 0; i < count; i++) |
| 54 |
{ |
| 55 |
int status = PyoMidi_MessageStatus(buffer[i].message); // Temp note event holders |
| 56 |
int number = PyoMidi_MessageData1(buffer[i].message); |
| 57 |
int value = PyoMidi_MessageData2(buffer[i].message); |
| 58 |
|
| 59 |
if ((status & 0xF0) == 0xB0) |
| 60 |
{ |
| 61 |
if (number != self->ctlnumber) |
| 62 |
{ |
| 63 |
self->ctlnumber = number; |
| 64 |
tup = PyTuple_New(1); |
| 65 |
PyTuple_SetItem(tup, 0, PyLong_FromLong(self->ctlnumber)); |
| 66 |
PyObject_Call((PyObject *)self->callable, tup, NULL); |
| 67 |
} |
| 68 |
|
| 69 |
if (self->toprint == 1) |
| 70 |
PySys_WriteStdout("ctl number : %i, ctl value : %i, midi channel : %i\n", self->ctlnumber, value, status - 0xB0 + 1); |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
static int |
| 77 |
CtlScan_traverse(CtlScan *self, visitproc visit, void *arg) |
| 78 |
{ |
| 79 |
pyo_VISIT |
| 80 |
Py_VISIT(self->callable); |
| 81 |
return 0; |
| 82 |
} |
| 83 |
|
| 84 |
static int |
| 85 |
CtlScan_clear(CtlScan *self) |
| 86 |
{ |
| 87 |
pyo_CLEAR |
| 88 |
Py_CLEAR(self->callable); |
| 89 |
return 0; |
| 90 |
} |
| 91 |
|
| 92 |
static void |
| 93 |
CtlScan_dealloc(CtlScan* self) |
| 94 |
{ |
| 95 |
pyo_DEALLOC |
| 96 |
CtlScan_clear(self); |
| 97 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 98 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 99 |
} |
| 100 |
|
| 101 |
static PyObject * |
| 102 |
CtlScan_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 103 |
{ |
| 104 |
int i; |
| 105 |
PyObject *calltmp = NULL; |
| 106 |
CtlScan *self; |
| 107 |
self = (CtlScan *)type->tp_alloc(type, 0); |
| 108 |
|
| 109 |
self->ctlnumber = -1; |
| 110 |
self->toprint = 1; |
| 111 |
|
| 112 |
INIT_OBJECT_COMMON |
| 113 |
Stream_setFunctionPtr(self->stream, CtlScan_compute_next_data_frame); |
| 114 |
self->mode_func_ptr = CtlScan_setProcMode; |
| 115 |
|
| 116 |
static char *kwlist[] = {"callable", "toprint", NULL}; |
| 117 |
|
| 118 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &calltmp, &self->toprint)) |
| 119 |
Py_RETURN_NONE; |
| 120 |
|
| 121 |
if (calltmp) |
| 122 |
{ |
| 123 |
PyObject_CallMethod((PyObject *)self, "setFunction", "O", calltmp); |
| 124 |
} |
| 125 |
|
| 126 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 127 |
|
| 128 |
return (PyObject *)self; |
| 129 |
} |
| 130 |
|
| 131 |
static PyObject * CtlScan_getServer(CtlScan* self) { GET_SERVER }; |
| 132 |
static PyObject * CtlScan_getStream(CtlScan* self) { GET_STREAM }; |
| 133 |
|
| 134 |
static PyObject * CtlScan_play(CtlScan *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 135 |
static PyObject * CtlScan_stop(CtlScan *self, PyObject *args, PyObject *kwds) { STOP }; |
| 136 |
|
| 137 |
static PyObject * |
| 138 |
CtlScan_reset(CtlScan *self) |
| 139 |
{ |
| 140 |
self->ctlnumber = -1; |
| 141 |
Py_RETURN_NONE; |
| 142 |
}; |
| 143 |
|
| 144 |
static PyObject * |
| 145 |
CtlScan_setFunction(CtlScan *self, PyObject *arg) |
| 146 |
{ |
| 147 |
if (! PyCallable_Check(arg)) |
| 148 |
{ |
| 149 |
PyErr_SetString(PyExc_TypeError, "The callable attribute must be a valid Python function."); |
| 150 |
Py_RETURN_NONE; |
| 151 |
} |
| 152 |
|
| 153 |
Py_XDECREF(self->callable); |
| 154 |
self->callable = arg; |
| 155 |
Py_INCREF(self->callable); |
| 156 |
|
| 157 |
Py_RETURN_NONE; |
| 158 |
} |
| 159 |
|
| 160 |
static PyObject * |
| 161 |
CtlScan_setToprint(CtlScan *self, PyObject *arg) |
| 162 |
{ |
| 163 |
if (PyLong_Check(arg)) |
| 164 |
{ |
| 165 |
self->toprint = PyLong_AsLong(arg); |
| 166 |
} |
| 167 |
|
| 168 |
Py_RETURN_NONE; |
| 169 |
} |
| 170 |
static PyMemberDef CtlScan_members[] = |
| 171 |
{ |
| 172 |
{"server", T_OBJECT_EX, offsetof(CtlScan, server), 0, "Pyo server."}, |
| 173 |
{"stream", T_OBJECT_EX, offsetof(CtlScan, stream), 0, "Stream object."}, |
| 174 |
{NULL} /* Sentinel */ |
| 175 |
}; |
| 176 |
|
| 177 |
static PyMethodDef CtlScan_methods[] = |
| 178 |
{ |
| 179 |
{"getServer", (PyCFunction)CtlScan_getServer, METH_NOARGS, "Returns server object."}, |
| 180 |
{"_getStream", (PyCFunction)CtlScan_getStream, METH_NOARGS, "Returns stream object."}, |
| 181 |
{"play", (PyCFunction)CtlScan_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 182 |
{"stop", (PyCFunction)CtlScan_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 183 |
{"reset", (PyCFunction)CtlScan_reset, METH_NOARGS, "Resets the scanned number."}, |
| 184 |
{"setFunction", (PyCFunction)CtlScan_setFunction, METH_O, "Sets the function to be called."}, |
| 185 |
{"setToprint", (PyCFunction)CtlScan_setToprint, METH_O, "If True, print values to the console."}, |
| 186 |
{NULL} /* Sentinel */ |
| 187 |
}; |
| 188 |
|
| 189 |
PyTypeObject CtlScanType = |
| 190 |
{ |
| 191 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 192 |
"_pyo.CtlScan_base", /*tp_name*/ |
| 193 |
sizeof(CtlScan), /*tp_basicsize*/ |
| 194 |
0, /*tp_itemsize*/ |
| 195 |
(destructor)CtlScan_dealloc, /*tp_dealloc*/ |
| 196 |
0, /*tp_print*/ |
| 197 |
0, /*tp_getattr*/ |
| 198 |
0, /*tp_setattr*/ |
| 199 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 200 |
0, /*tp_repr*/ |
| 201 |
0, /*tp_as_number*/ |
| 202 |
0, /*tp_as_sequence*/ |
| 203 |
0, /*tp_as_mapping*/ |
| 204 |
0, /*tp_hash */ |
| 205 |
0, /*tp_call*/ |
| 206 |
0, /*tp_str*/ |
| 207 |
0, /*tp_getattro*/ |
| 208 |
0, /*tp_setattro*/ |
| 209 |
0, /*tp_as_buffer*/ |
| 210 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 211 |
"CtlScan objects. Retreive controller numbers from a Midi input.", /* tp_doc */ |
| 212 |
(traverseproc)CtlScan_traverse, /* tp_traverse */ |
| 213 |
(inquiry)CtlScan_clear, /* tp_clear */ |
| 214 |
0, /* tp_richcompare */ |
| 215 |
0, /* tp_weaklistoffset */ |
| 216 |
0, /* tp_iter */ |
| 217 |
0, /* tp_iternext */ |
| 218 |
CtlScan_methods, /* tp_methods */ |
| 219 |
CtlScan_members, /* tp_members */ |
| 220 |
0, /* tp_getset */ |
| 221 |
0, /* tp_base */ |
| 222 |
0, /* tp_dict */ |
| 223 |
0, /* tp_descr_get */ |
| 224 |
0, /* tp_descr_set */ |
| 225 |
0, /* tp_dictoffset */ |
| 226 |
0, /* tp_init */ |
| 227 |
0, /* tp_alloc */ |
| 228 |
CtlScan_new, /* tp_new */ |
| 229 |
}; |
| 230 |
|
| 231 |
typedef struct |
| 232 |
{ |
| 233 |
pyo_audio_HEAD |
| 234 |
PyObject *callable; |
| 235 |
int ctlnumber; |
| 236 |
int midichnl; |
| 237 |
int toprint; |
| 238 |
} CtlScan2; |
| 239 |
|
| 240 |
static void |
| 241 |
CtlScan2_setProcMode(CtlScan2 *self) {} |
| 242 |
|
| 243 |
static void |
| 244 |
CtlScan2_compute_next_data_frame(CtlScan2 *self) |
| 245 |
{ |
| 246 |
PyoMidiEvent *buffer; |
| 247 |
int i, count, midichnl; |
| 248 |
|
| 249 |
buffer = Server_getMidiEventBuffer((Server *)self->server); |
| 250 |
count = Server_getMidiEventCount((Server *)self->server); |
| 251 |
|
| 252 |
if (count > 0) |
| 253 |
{ |
| 254 |
PyObject *tup; |
| 255 |
|
| 256 |
for (i = 0; i < count; i++) |
| 257 |
{ |
| 258 |
int status = PyoMidi_MessageStatus(buffer[i].message); // Temp note event holders |
| 259 |
int number = PyoMidi_MessageData1(buffer[i].message); |
| 260 |
int value = PyoMidi_MessageData2(buffer[i].message); |
| 261 |
|
| 262 |
if ((status & 0xF0) == 0xB0) |
| 263 |
{ |
| 264 |
midichnl = status - 0xB0 + 1; |
| 265 |
|
| 266 |
if (number != self->ctlnumber || midichnl != self->midichnl) |
| 267 |
{ |
| 268 |
self->ctlnumber = number; |
| 269 |
self->midichnl = midichnl; |
| 270 |
tup = PyTuple_New(2); |
| 271 |
PyTuple_SetItem(tup, 0, PyLong_FromLong(self->ctlnumber)); |
| 272 |
PyTuple_SetItem(tup, 1, PyLong_FromLong(self->midichnl)); |
| 273 |
PyObject_Call((PyObject *)self->callable, tup, NULL); |
| 274 |
} |
| 275 |
|
| 276 |
if (self->toprint == 1) |
| 277 |
PySys_WriteStdout("ctl number : %i, ctl value : %i, midi channel : %i\n", self->ctlnumber, value, midichnl); |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
static int |
| 284 |
CtlScan2_traverse(CtlScan2 *self, visitproc visit, void *arg) |
| 285 |
{ |
| 286 |
pyo_VISIT |
| 287 |
Py_VISIT(self->callable); |
| 288 |
return 0; |
| 289 |
} |
| 290 |
|
| 291 |
static int |
| 292 |
CtlScan2_clear(CtlScan2 *self) |
| 293 |
{ |
| 294 |
pyo_CLEAR |
| 295 |
Py_CLEAR(self->callable); |
| 296 |
return 0; |
| 297 |
} |
| 298 |
|
| 299 |
static void |
| 300 |
CtlScan2_dealloc(CtlScan2* self) |
| 301 |
{ |
| 302 |
pyo_DEALLOC |
| 303 |
CtlScan2_clear(self); |
| 304 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 305 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 306 |
} |
| 307 |
|
| 308 |
static PyObject * |
| 309 |
CtlScan2_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 310 |
{ |
| 311 |
int i; |
| 312 |
PyObject *calltmp = NULL; |
| 313 |
CtlScan2 *self; |
| 314 |
self = (CtlScan2 *)type->tp_alloc(type, 0); |
| 315 |
|
| 316 |
self->ctlnumber = self->midichnl = -1; |
| 317 |
self->toprint = 1; |
| 318 |
|
| 319 |
INIT_OBJECT_COMMON |
| 320 |
Stream_setFunctionPtr(self->stream, CtlScan2_compute_next_data_frame); |
| 321 |
self->mode_func_ptr = CtlScan2_setProcMode; |
| 322 |
|
| 323 |
static char *kwlist[] = {"callable", "toprint", NULL}; |
| 324 |
|
| 325 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &calltmp, &self->toprint)) |
| 326 |
Py_RETURN_NONE; |
| 327 |
|
| 328 |
if (calltmp) |
| 329 |
{ |
| 330 |
PyObject_CallMethod((PyObject *)self, "setFunction", "O", calltmp); |
| 331 |
} |
| 332 |
|
| 333 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 334 |
|
| 335 |
return (PyObject *)self; |
| 336 |
} |
| 337 |
|
| 338 |
static PyObject * CtlScan2_getServer(CtlScan2* self) { GET_SERVER }; |
| 339 |
static PyObject * CtlScan2_getStream(CtlScan2* self) { GET_STREAM }; |
| 340 |
|
| 341 |
static PyObject * CtlScan2_play(CtlScan2 *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 342 |
static PyObject * CtlScan2_stop(CtlScan2 *self, PyObject *args, PyObject *kwds) { STOP }; |
| 343 |
|
| 344 |
static PyObject * |
| 345 |
CtlScan2_reset(CtlScan2 *self) |
| 346 |
{ |
| 347 |
self->ctlnumber = self->midichnl = -1; |
| 348 |
Py_RETURN_NONE; |
| 349 |
}; |
| 350 |
|
| 351 |
static PyObject * |
| 352 |
CtlScan2_setFunction(CtlScan2 *self, PyObject *arg) |
| 353 |
{ |
| 354 |
if (! PyCallable_Check(arg)) |
| 355 |
{ |
| 356 |
PyErr_SetString(PyExc_TypeError, "The callable attribute must be a valid Python function."); |
| 357 |
Py_RETURN_NONE; |
| 358 |
} |
| 359 |
|
| 360 |
Py_XDECREF(self->callable); |
| 361 |
self->callable = arg; |
| 362 |
Py_INCREF(self->callable); |
| 363 |
|
| 364 |
Py_RETURN_NONE; |
| 365 |
} |
| 366 |
|
| 367 |
static PyObject * |
| 368 |
CtlScan2_setToprint(CtlScan2 *self, PyObject *arg) |
| 369 |
{ |
| 370 |
if (PyLong_Check(arg)) |
| 371 |
{ |
| 372 |
self->toprint = PyLong_AsLong(arg); |
| 373 |
} |
| 374 |
|
| 375 |
Py_RETURN_NONE; |
| 376 |
} |
| 377 |
static PyMemberDef CtlScan2_members[] = |
| 378 |
{ |
| 379 |
{"server", T_OBJECT_EX, offsetof(CtlScan2, server), 0, "Pyo server."}, |
| 380 |
{"stream", T_OBJECT_EX, offsetof(CtlScan2, stream), 0, "Stream object."}, |
| 381 |
{NULL} /* Sentinel */ |
| 382 |
}; |
| 383 |
|
| 384 |
static PyMethodDef CtlScan2_methods[] = |
| 385 |
{ |
| 386 |
{"getServer", (PyCFunction)CtlScan2_getServer, METH_NOARGS, "Returns server object."}, |
| 387 |
{"_getStream", (PyCFunction)CtlScan2_getStream, METH_NOARGS, "Returns stream object."}, |
| 388 |
{"play", (PyCFunction)CtlScan2_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 389 |
{"stop", (PyCFunction)CtlScan2_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 390 |
{"reset", (PyCFunction)CtlScan2_reset, METH_NOARGS, "Reset scanned numbers."}, |
| 391 |
{"setFunction", (PyCFunction)CtlScan2_setFunction, METH_O, "Sets the function to be called."}, |
| 392 |
{"setToprint", (PyCFunction)CtlScan2_setToprint, METH_O, "If True, print values to the console."}, |
| 393 |
{NULL} /* Sentinel */ |
| 394 |
}; |
| 395 |
|
| 396 |
PyTypeObject CtlScan2Type = |
| 397 |
{ |
| 398 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 399 |
"_pyo.CtlScan2_base", /*tp_name*/ |
| 400 |
sizeof(CtlScan2), /*tp_basicsize*/ |
| 401 |
0, /*tp_itemsize*/ |
| 402 |
(destructor)CtlScan2_dealloc, /*tp_dealloc*/ |
| 403 |
0, /*tp_print*/ |
| 404 |
0, /*tp_getattr*/ |
| 405 |
0, /*tp_setattr*/ |
| 406 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 407 |
0, /*tp_repr*/ |
| 408 |
0, /*tp_as_number*/ |
| 409 |
0, /*tp_as_sequence*/ |
| 410 |
0, /*tp_as_mapping*/ |
| 411 |
0, /*tp_hash */ |
| 412 |
0, /*tp_call*/ |
| 413 |
0, /*tp_str*/ |
| 414 |
0, /*tp_getattro*/ |
| 415 |
0, /*tp_setattro*/ |
| 416 |
0, /*tp_as_buffer*/ |
| 417 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 418 |
"CtlScan2 objects. Retreive midi channel and controller numbers from a midi input.", /* tp_doc */ |
| 419 |
(traverseproc)CtlScan2_traverse, /* tp_traverse */ |
| 420 |
(inquiry)CtlScan2_clear, /* tp_clear */ |
| 421 |
0, /* tp_richcompare */ |
| 422 |
0, /* tp_weaklistoffset */ |
| 423 |
0, /* tp_iter */ |
| 424 |
0, /* tp_iternext */ |
| 425 |
CtlScan2_methods, /* tp_methods */ |
| 426 |
CtlScan2_members, /* tp_members */ |
| 427 |
0, /* tp_getset */ |
| 428 |
0, /* tp_base */ |
| 429 |
0, /* tp_dict */ |
| 430 |
0, /* tp_descr_get */ |
| 431 |
0, /* tp_descr_set */ |
| 432 |
0, /* tp_dictoffset */ |
| 433 |
0, /* tp_init */ |
| 434 |
0, /* tp_alloc */ |
| 435 |
CtlScan2_new, /* tp_new */ |
| 436 |
}; |
| 437 |
|
| 438 |
int |
| 439 |
getPosToWrite(long timestamp, Server *server, double sr, int bufsize) |
| 440 |
{ |
| 441 |
/* With JackMidi, the timestamp is already a sample offset inside the buffer size. */ |
| 442 |
if (server->withJackMidi) |
| 443 |
{ |
| 444 |
return (int)timestamp; |
| 445 |
} |
| 446 |
else |
| 447 |
{ |
| 448 |
int offset = 0; |
| 449 |
long realtimestamp, elapsed, ms; |
| 450 |
realtimestamp = timestamp - Server_getMidiTimeOffset(server); |
| 451 |
|
| 452 |
if (realtimestamp < 0) |
| 453 |
return 0; |
| 454 |
|
| 455 |
elapsed = (long)(Server_getElapsedTime(server) / sr * 1000); |
| 456 |
ms = realtimestamp - (elapsed - (long)(bufsize / sr * 1000)); |
| 457 |
offset = (int)(ms * 0.001 * sr); |
| 458 |
|
| 459 |
if (offset < 0) |
| 460 |
offset = 0; |
| 461 |
else if (offset >= bufsize) |
| 462 |
offset = bufsize - 1; |
| 463 |
|
| 464 |
return offset; |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
typedef struct |
| 469 |
{ |
| 470 |
pyo_audio_HEAD |
| 471 |
int ctlnumber; |
| 472 |
int channel; |
| 473 |
MYFLT minscale; |
| 474 |
MYFLT maxscale; |
| 475 |
MYFLT value; |
| 476 |
int modebuffer[2]; |
| 477 |
} Midictl; |
| 478 |
|
| 479 |
static void Midictl_postprocessing_ii(Midictl *self) { POST_PROCESSING_II }; |
| 480 |
static void Midictl_postprocessing_ai(Midictl *self) { POST_PROCESSING_AI }; |
| 481 |
static void Midictl_postprocessing_ia(Midictl *self) { POST_PROCESSING_IA }; |
| 482 |
static void Midictl_postprocessing_aa(Midictl *self) { POST_PROCESSING_AA }; |
| 483 |
static void Midictl_postprocessing_ireva(Midictl *self) { POST_PROCESSING_IREVA }; |
| 484 |
static void Midictl_postprocessing_areva(Midictl *self) { POST_PROCESSING_AREVA }; |
| 485 |
static void Midictl_postprocessing_revai(Midictl *self) { POST_PROCESSING_REVAI }; |
| 486 |
static void Midictl_postprocessing_revaa(Midictl *self) { POST_PROCESSING_REVAA }; |
| 487 |
static void Midictl_postprocessing_revareva(Midictl *self) { POST_PROCESSING_REVAREVA }; |
| 488 |
|
| 489 |
static void |
| 490 |
Midictl_setProcMode(Midictl *self) |
| 491 |
{ |
| 492 |
int muladdmode; |
| 493 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 494 |
|
| 495 |
switch (muladdmode) |
| 496 |
{ |
| 497 |
case 0: |
| 498 |
self->muladd_func_ptr = Midictl_postprocessing_ii; |
| 499 |
break; |
| 500 |
|
| 501 |
case 1: |
| 502 |
self->muladd_func_ptr = Midictl_postprocessing_ai; |
| 503 |
break; |
| 504 |
|
| 505 |
case 2: |
| 506 |
self->muladd_func_ptr = Midictl_postprocessing_revai; |
| 507 |
break; |
| 508 |
|
| 509 |
case 10: |
| 510 |
self->muladd_func_ptr = Midictl_postprocessing_ia; |
| 511 |
break; |
| 512 |
|
| 513 |
case 11: |
| 514 |
self->muladd_func_ptr = Midictl_postprocessing_aa; |
| 515 |
break; |
| 516 |
|
| 517 |
case 12: |
| 518 |
self->muladd_func_ptr = Midictl_postprocessing_revaa; |
| 519 |
break; |
| 520 |
|
| 521 |
case 20: |
| 522 |
self->muladd_func_ptr = Midictl_postprocessing_ireva; |
| 523 |
break; |
| 524 |
|
| 525 |
case 21: |
| 526 |
self->muladd_func_ptr = Midictl_postprocessing_areva; |
| 527 |
break; |
| 528 |
|
| 529 |
case 22: |
| 530 |
self->muladd_func_ptr = Midictl_postprocessing_revareva; |
| 531 |
break; |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
int |
| 536 |
Midictl_translateMidi(Midictl *self, PyoMidiEvent *buffer, int j) |
| 537 |
{ |
| 538 |
int ok, posto = -1; |
| 539 |
int status = PyoMidi_MessageStatus(buffer[j].message); // Temp note event holders |
| 540 |
int number = PyoMidi_MessageData1(buffer[j].message); |
| 541 |
int value = PyoMidi_MessageData2(buffer[j].message); |
| 542 |
|
| 543 |
if (self->channel == 0) |
| 544 |
{ |
| 545 |
if ((status & 0xF0) == 0xB0) |
| 546 |
ok = 1; |
| 547 |
else |
| 548 |
ok = 0; |
| 549 |
} |
| 550 |
else |
| 551 |
{ |
| 552 |
if (status == (0xB0 | (self->channel - 1))) |
| 553 |
ok = 1; |
| 554 |
else |
| 555 |
ok = 0; |
| 556 |
} |
| 557 |
|
| 558 |
if (ok == 1 && number == self->ctlnumber) |
| 559 |
{ |
| 560 |
self->value = (value / 127.) * (self->maxscale - self->minscale) + self->minscale; |
| 561 |
posto = getPosToWrite(buffer[j].timestamp, (Server *)self->server, self->sr, self->bufsize); |
| 562 |
} |
| 563 |
|
| 564 |
return posto; |
| 565 |
} |
| 566 |
|
| 567 |
static void |
| 568 |
Midictl_compute_next_data_frame(Midictl *self) |
| 569 |
{ |
| 570 |
PyoMidiEvent *tmp; |
| 571 |
int i, j, count, posto, oldpos = 0; |
| 572 |
MYFLT oldval = 0.0; |
| 573 |
|
| 574 |
tmp = Server_getMidiEventBuffer((Server *)self->server); |
| 575 |
count = Server_getMidiEventCount((Server *)self->server); |
| 576 |
|
| 577 |
if (count == 0) |
| 578 |
{ |
| 579 |
for (i = 0; i < self->bufsize; i++) |
| 580 |
{ |
| 581 |
self->data[i] = self->value; |
| 582 |
} |
| 583 |
} |
| 584 |
else |
| 585 |
{ |
| 586 |
for (j = 0; j < count; j++) |
| 587 |
{ |
| 588 |
oldval = self->value; |
| 589 |
posto = Midictl_translateMidi((Midictl *)self, tmp, j); |
| 590 |
|
| 591 |
if (posto == -1) |
| 592 |
continue; |
| 593 |
|
| 594 |
for (i = oldpos; i < posto; i++) |
| 595 |
{ |
| 596 |
self->data[i] = oldval; |
| 597 |
} |
| 598 |
|
| 599 |
oldpos = posto; |
| 600 |
} |
| 601 |
|
| 602 |
for (i = oldpos; i < self->bufsize; i++) |
| 603 |
{ |
| 604 |
self->data[i] = self->value; |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
(*self->muladd_func_ptr)(self); |
| 609 |
} |
| 610 |
|
| 611 |
static int |
| 612 |
Midictl_traverse(Midictl *self, visitproc visit, void *arg) |
| 613 |
{ |
| 614 |
pyo_VISIT |
| 615 |
return 0; |
| 616 |
} |
| 617 |
|
| 618 |
static int |
| 619 |
Midictl_clear(Midictl *self) |
| 620 |
{ |
| 621 |
pyo_CLEAR |
| 622 |
return 0; |
| 623 |
} |
| 624 |
|
| 625 |
static void |
| 626 |
Midictl_dealloc(Midictl* self) |
| 627 |
{ |
| 628 |
pyo_DEALLOC |
| 629 |
Midictl_clear(self); |
| 630 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 631 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 632 |
} |
| 633 |
|
| 634 |
static PyObject * |
| 635 |
Midictl_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 636 |
{ |
| 637 |
int i; |
| 638 |
PyObject *multmp = NULL, *addtmp = NULL; |
| 639 |
Midictl *self; |
| 640 |
self = (Midictl *)type->tp_alloc(type, 0); |
| 641 |
|
| 642 |
self->channel = 0; |
| 643 |
self->value = 0.; |
| 644 |
self->minscale = 0.; |
| 645 |
self->maxscale = 1.; |
| 646 |
self->modebuffer[0] = 0; |
| 647 |
self->modebuffer[1] = 0; |
| 648 |
|
| 649 |
INIT_OBJECT_COMMON |
| 650 |
Stream_setFunctionPtr(self->stream, Midictl_compute_next_data_frame); |
| 651 |
self->mode_func_ptr = Midictl_setProcMode; |
| 652 |
|
| 653 |
static char *kwlist[] = {"ctlnumber", "minscale", "maxscale", "init", "channel", "mul", "add", NULL}; |
| 654 |
|
| 655 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_I_FFFIOO, kwlist, &self->ctlnumber, &self->minscale, &self->maxscale, &self->value, &self->channel, &multmp, &addtmp)) |
| 656 |
Py_RETURN_NONE; |
| 657 |
|
| 658 |
if (multmp) |
| 659 |
{ |
| 660 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 661 |
} |
| 662 |
|
| 663 |
if (addtmp) |
| 664 |
{ |
| 665 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 666 |
} |
| 667 |
|
| 668 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 669 |
|
| 670 |
(*self->mode_func_ptr)(self); |
| 671 |
|
| 672 |
return (PyObject *)self; |
| 673 |
} |
| 674 |
|
| 675 |
static PyObject * Midictl_getServer(Midictl* self) { GET_SERVER }; |
| 676 |
static PyObject * Midictl_getStream(Midictl* self) { GET_STREAM }; |
| 677 |
static PyObject * Midictl_setMul(Midictl *self, PyObject *arg) { SET_MUL }; |
| 678 |
static PyObject * Midictl_setAdd(Midictl *self, PyObject *arg) { SET_ADD }; |
| 679 |
static PyObject * Midictl_setSub(Midictl *self, PyObject *arg) { SET_SUB }; |
| 680 |
static PyObject * Midictl_setDiv(Midictl *self, PyObject *arg) { SET_DIV }; |
| 681 |
|
| 682 |
static PyObject * Midictl_play(Midictl *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 683 |
static PyObject * Midictl_stop(Midictl *self, PyObject *args, PyObject *kwds) { STOP }; |
| 684 |
|
| 685 |
static PyObject * Midictl_multiply(Midictl *self, PyObject *arg) { MULTIPLY }; |
| 686 |
static PyObject * Midictl_inplace_multiply(Midictl *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 687 |
static PyObject * Midictl_add(Midictl *self, PyObject *arg) { ADD }; |
| 688 |
static PyObject * Midictl_inplace_add(Midictl *self, PyObject *arg) { INPLACE_ADD }; |
| 689 |
static PyObject * Midictl_sub(Midictl *self, PyObject *arg) { SUB }; |
| 690 |
static PyObject * Midictl_inplace_sub(Midictl *self, PyObject *arg) { INPLACE_SUB }; |
| 691 |
static PyObject * Midictl_div(Midictl *self, PyObject *arg) { DIV }; |
| 692 |
static PyObject * Midictl_inplace_div(Midictl *self, PyObject *arg) { INPLACE_DIV }; |
| 693 |
|
| 694 |
static PyObject * |
| 695 |
Midictl_setValue(Midictl *self, PyObject *arg) |
| 696 |
{ |
| 697 |
ASSERT_ARG_NOT_NULL |
| 698 |
|
| 699 |
if (PyNumber_Check(arg)) |
| 700 |
{ |
| 701 |
self->value = PyFloat_AsDouble(arg); |
| 702 |
} |
| 703 |
|
| 704 |
Py_RETURN_NONE; |
| 705 |
} |
| 706 |
|
| 707 |
static PyObject * |
| 708 |
Midictl_setMinScale(Midictl *self, PyObject *arg) |
| 709 |
{ |
| 710 |
ASSERT_ARG_NOT_NULL |
| 711 |
|
| 712 |
if (PyNumber_Check(arg)) |
| 713 |
{ |
| 714 |
self->minscale = PyFloat_AsDouble(arg); |
| 715 |
} |
| 716 |
|
| 717 |
Py_RETURN_NONE; |
| 718 |
} |
| 719 |
|
| 720 |
static PyObject * |
| 721 |
Midictl_setMaxScale(Midictl *self, PyObject *arg) |
| 722 |
{ |
| 723 |
ASSERT_ARG_NOT_NULL |
| 724 |
|
| 725 |
if (PyNumber_Check(arg)) |
| 726 |
{ |
| 727 |
self->maxscale = PyFloat_AsDouble(arg); |
| 728 |
} |
| 729 |
|
| 730 |
Py_RETURN_NONE; |
| 731 |
} |
| 732 |
|
| 733 |
static PyObject * |
| 734 |
Midictl_setCtlNumber(Midictl *self, PyObject *arg) |
| 735 |
{ |
| 736 |
int tmp; |
| 737 |
|
| 738 |
ASSERT_ARG_NOT_NULL |
| 739 |
|
| 740 |
if (PyLong_Check(arg)) |
| 741 |
{ |
| 742 |
tmp = PyLong_AsLong(arg); |
| 743 |
|
| 744 |
if (tmp >= 0 && tmp < 128) |
| 745 |
self->ctlnumber = tmp; |
| 746 |
} |
| 747 |
|
| 748 |
Py_RETURN_NONE; |
| 749 |
} |
| 750 |
|
| 751 |
static PyObject * |
| 752 |
Midictl_setChannel(Midictl *self, PyObject *arg) |
| 753 |
{ |
| 754 |
int tmp; |
| 755 |
|
| 756 |
ASSERT_ARG_NOT_NULL |
| 757 |
|
| 758 |
if (PyLong_Check(arg)) |
| 759 |
{ |
| 760 |
tmp = PyLong_AsLong(arg); |
| 761 |
|
| 762 |
if (tmp >= 0 && tmp < 128) |
| 763 |
self->channel = tmp; |
| 764 |
} |
| 765 |
|
| 766 |
Py_RETURN_NONE; |
| 767 |
} |
| 768 |
|
| 769 |
static PyMemberDef Midictl_members[] = |
| 770 |
{ |
| 771 |
{"server", T_OBJECT_EX, offsetof(Midictl, server), 0, "Pyo server."}, |
| 772 |
{"stream", T_OBJECT_EX, offsetof(Midictl, stream), 0, "Stream object."}, |
| 773 |
{"mul", T_OBJECT_EX, offsetof(Midictl, mul), 0, "Mul factor."}, |
| 774 |
{"add", T_OBJECT_EX, offsetof(Midictl, add), 0, "Add factor."}, |
| 775 |
{NULL} /* Sentinel */ |
| 776 |
}; |
| 777 |
|
| 778 |
static PyMethodDef Midictl_methods[] = |
| 779 |
{ |
| 780 |
{"getServer", (PyCFunction)Midictl_getServer, METH_NOARGS, "Returns server object."}, |
| 781 |
{"_getStream", (PyCFunction)Midictl_getStream, METH_NOARGS, "Returns stream object."}, |
| 782 |
{"play", (PyCFunction)Midictl_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 783 |
{"stop", (PyCFunction)Midictl_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 784 |
{"setValue", (PyCFunction)Midictl_setValue, METH_O, "Resets audio stream to value in argument."}, |
| 785 |
{"setMinScale", (PyCFunction)Midictl_setMinScale, METH_O, "Sets the minimum value of scaling."}, |
| 786 |
{"setMaxScale", (PyCFunction)Midictl_setMaxScale, METH_O, "Sets the maximum value of scaling."}, |
| 787 |
{"setCtlNumber", (PyCFunction)Midictl_setCtlNumber, METH_O, "Sets the controller number."}, |
| 788 |
{"setChannel", (PyCFunction)Midictl_setChannel, METH_O, "Sets the midi channel."}, |
| 789 |
{"setMul", (PyCFunction)Midictl_setMul, METH_O, "Sets oscillator mul factor."}, |
| 790 |
{"setAdd", (PyCFunction)Midictl_setAdd, METH_O, "Sets oscillator add factor."}, |
| 791 |
{"setSub", (PyCFunction)Midictl_setSub, METH_O, "Sets inverse add factor."}, |
| 792 |
{"setDiv", (PyCFunction)Midictl_setDiv, METH_O, "Sets inverse mul factor."}, |
| 793 |
{NULL} /* Sentinel */ |
| 794 |
}; |
| 795 |
|
| 796 |
static PyNumberMethods Midictl_as_number = |
| 797 |
{ |
| 798 |
(binaryfunc)Midictl_add, /*nb_add*/ |
| 799 |
(binaryfunc)Midictl_sub, /*nb_subtract*/ |
| 800 |
(binaryfunc)Midictl_multiply, /*nb_multiply*/ |
| 801 |
0, /*nb_remainder*/ |
| 802 |
0, /*nb_divmod*/ |
| 803 |
0, /*nb_power*/ |
| 804 |
0, /*nb_neg*/ |
| 805 |
0, /*nb_pos*/ |
| 806 |
0, /*(unaryfunc)array_abs,*/ |
| 807 |
0, /*nb_nonzero*/ |
| 808 |
0, /*nb_invert*/ |
| 809 |
0, /*nb_lshift*/ |
| 810 |
0, /*nb_rshift*/ |
| 811 |
0, /*nb_and*/ |
| 812 |
0, /*nb_xor*/ |
| 813 |
0, /*nb_or*/ |
| 814 |
0, /*nb_int*/ |
| 815 |
0, /*nb_long*/ |
| 816 |
0, /*nb_float*/ |
| 817 |
(binaryfunc)Midictl_inplace_add, /*inplace_add*/ |
| 818 |
(binaryfunc)Midictl_inplace_sub, /*inplace_subtract*/ |
| 819 |
(binaryfunc)Midictl_inplace_multiply, /*inplace_multiply*/ |
| 820 |
0, /*inplace_remainder*/ |
| 821 |
0, /*inplace_power*/ |
| 822 |
0, /*inplace_lshift*/ |
| 823 |
0, /*inplace_rshift*/ |
| 824 |
0, /*inplace_and*/ |
| 825 |
0, /*inplace_xor*/ |
| 826 |
0, /*inplace_or*/ |
| 827 |
0, /*nb_floor_divide*/ |
| 828 |
(binaryfunc)Midictl_div, /*nb_true_divide*/ |
| 829 |
0, /*nb_inplace_floor_divide*/ |
| 830 |
(binaryfunc)Midictl_inplace_div, /*nb_inplace_true_divide*/ |
| 831 |
0, /* nb_index */ |
| 832 |
}; |
| 833 |
|
| 834 |
PyTypeObject MidictlType = |
| 835 |
{ |
| 836 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 837 |
"_pyo.Midictl_base", /*tp_name*/ |
| 838 |
sizeof(Midictl), /*tp_basicsize*/ |
| 839 |
0, /*tp_itemsize*/ |
| 840 |
(destructor)Midictl_dealloc, /*tp_dealloc*/ |
| 841 |
0, /*tp_print*/ |
| 842 |
0, /*tp_getattr*/ |
| 843 |
0, /*tp_setattr*/ |
| 844 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 845 |
0, /*tp_repr*/ |
| 846 |
&Midictl_as_number, /*tp_as_number*/ |
| 847 |
0, /*tp_as_sequence*/ |
| 848 |
0, /*tp_as_mapping*/ |
| 849 |
0, /*tp_hash */ |
| 850 |
0, /*tp_call*/ |
| 851 |
0, /*tp_str*/ |
| 852 |
0, /*tp_getattro*/ |
| 853 |
0, /*tp_setattro*/ |
| 854 |
0, /*tp_as_buffer*/ |
| 855 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 856 |
"Midictl objects. Retreive audio from an input channel.", /* tp_doc */ |
| 857 |
(traverseproc)Midictl_traverse, /* tp_traverse */ |
| 858 |
(inquiry)Midictl_clear, /* tp_clear */ |
| 859 |
0, /* tp_richcompare */ |
| 860 |
0, /* tp_weaklistoffset */ |
| 861 |
0, /* tp_iter */ |
| 862 |
0, /* tp_iternext */ |
| 863 |
Midictl_methods, /* tp_methods */ |
| 864 |
Midictl_members, /* tp_members */ |
| 865 |
0, /* tp_getset */ |
| 866 |
0, /* tp_base */ |
| 867 |
0, /* tp_dict */ |
| 868 |
0, /* tp_descr_get */ |
| 869 |
0, /* tp_descr_set */ |
| 870 |
0, /* tp_dictoffset */ |
| 871 |
0, /* tp_init */ |
| 872 |
0, /* tp_alloc */ |
| 873 |
Midictl_new, /* tp_new */ |
| 874 |
}; |
| 875 |
|
| 876 |
typedef struct |
| 877 |
{ |
| 878 |
pyo_audio_HEAD |
| 879 |
int channel; |
| 880 |
int scale; /* 0 = midi, 1 = transpo */ |
| 881 |
MYFLT range; |
| 882 |
MYFLT value; |
| 883 |
int modebuffer[2]; |
| 884 |
} Bendin; |
| 885 |
|
| 886 |
static void Bendin_postprocessing_ii(Bendin *self) { POST_PROCESSING_II }; |
| 887 |
static void Bendin_postprocessing_ai(Bendin *self) { POST_PROCESSING_AI }; |
| 888 |
static void Bendin_postprocessing_ia(Bendin *self) { POST_PROCESSING_IA }; |
| 889 |
static void Bendin_postprocessing_aa(Bendin *self) { POST_PROCESSING_AA }; |
| 890 |
static void Bendin_postprocessing_ireva(Bendin *self) { POST_PROCESSING_IREVA }; |
| 891 |
static void Bendin_postprocessing_areva(Bendin *self) { POST_PROCESSING_AREVA }; |
| 892 |
static void Bendin_postprocessing_revai(Bendin *self) { POST_PROCESSING_REVAI }; |
| 893 |
static void Bendin_postprocessing_revaa(Bendin *self) { POST_PROCESSING_REVAA }; |
| 894 |
static void Bendin_postprocessing_revareva(Bendin *self) { POST_PROCESSING_REVAREVA }; |
| 895 |
|
| 896 |
static void |
| 897 |
Bendin_setProcMode(Bendin *self) |
| 898 |
{ |
| 899 |
int muladdmode; |
| 900 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 901 |
|
| 902 |
switch (muladdmode) |
| 903 |
{ |
| 904 |
case 0: |
| 905 |
self->muladd_func_ptr = Bendin_postprocessing_ii; |
| 906 |
break; |
| 907 |
|
| 908 |
case 1: |
| 909 |
self->muladd_func_ptr = Bendin_postprocessing_ai; |
| 910 |
break; |
| 911 |
|
| 912 |
case 2: |
| 913 |
self->muladd_func_ptr = Bendin_postprocessing_revai; |
| 914 |
break; |
| 915 |
|
| 916 |
case 10: |
| 917 |
self->muladd_func_ptr = Bendin_postprocessing_ia; |
| 918 |
break; |
| 919 |
|
| 920 |
case 11: |
| 921 |
self->muladd_func_ptr = Bendin_postprocessing_aa; |
| 922 |
break; |
| 923 |
|
| 924 |
case 12: |
| 925 |
self->muladd_func_ptr = Bendin_postprocessing_revaa; |
| 926 |
break; |
| 927 |
|
| 928 |
case 20: |
| 929 |
self->muladd_func_ptr = Bendin_postprocessing_ireva; |
| 930 |
break; |
| 931 |
|
| 932 |
case 21: |
| 933 |
self->muladd_func_ptr = Bendin_postprocessing_areva; |
| 934 |
break; |
| 935 |
|
| 936 |
case 22: |
| 937 |
self->muladd_func_ptr = Bendin_postprocessing_revareva; |
| 938 |
break; |
| 939 |
} |
| 940 |
} |
| 941 |
|
| 942 |
int |
| 943 |
Bendin_translateMidi(Bendin *self, PyoMidiEvent *buffer, int j) |
| 944 |
{ |
| 945 |
int ok, posto = -1; |
| 946 |
MYFLT val; |
| 947 |
|
| 948 |
int status = PyoMidi_MessageStatus(buffer[j].message); // Temp note event holders |
| 949 |
int number = PyoMidi_MessageData1(buffer[j].message); |
| 950 |
int value = PyoMidi_MessageData2(buffer[j].message); |
| 951 |
|
| 952 |
if (self->channel == 0) |
| 953 |
{ |
| 954 |
if ((status & 0xF0) == 0xe0) |
| 955 |
ok = 1; |
| 956 |
else |
| 957 |
ok = 0; |
| 958 |
} |
| 959 |
else |
| 960 |
{ |
| 961 |
if (status == (0xe0 | (self->channel - 1))) |
| 962 |
ok = 1; |
| 963 |
else |
| 964 |
ok = 0; |
| 965 |
} |
| 966 |
|
| 967 |
if (ok == 1) |
| 968 |
{ |
| 969 |
val = (number + (value << 7) - 8192) / 8192.0 * self->range; |
| 970 |
|
| 971 |
if (self->scale == 0) |
| 972 |
self->value = val; |
| 973 |
else |
| 974 |
self->value = MYPOW(1.0594630943593, val); |
| 975 |
|
| 976 |
posto = getPosToWrite(buffer[j].timestamp, (Server *)self->server, self->sr, self->bufsize); |
| 977 |
} |
| 978 |
|
| 979 |
return posto; |
| 980 |
} |
| 981 |
|
| 982 |
static void |
| 983 |
Bendin_compute_next_data_frame(Bendin *self) |
| 984 |
{ |
| 985 |
PyoMidiEvent *tmp; |
| 986 |
int i, j, count, posto, oldpos = 0; |
| 987 |
MYFLT oldval = 0.0; |
| 988 |
|
| 989 |
tmp = Server_getMidiEventBuffer((Server *)self->server); |
| 990 |
count = Server_getMidiEventCount((Server *)self->server); |
| 991 |
|
| 992 |
if (count == 0) |
| 993 |
{ |
| 994 |
for (i = 0; i < self->bufsize; i++) |
| 995 |
{ |
| 996 |
self->data[i] = self->value; |
| 997 |
} |
| 998 |
} |
| 999 |
else |
| 1000 |
{ |
| 1001 |
for (j = 0; j < count; j++) |
| 1002 |
{ |
| 1003 |
oldval = self->value; |
| 1004 |
posto = Bendin_translateMidi((Bendin *)self, tmp, j); |
| 1005 |
|
| 1006 |
if (posto == -1) |
| 1007 |
continue; |
| 1008 |
|
| 1009 |
for (i = oldpos; i < posto; i++) |
| 1010 |
{ |
| 1011 |
self->data[i] = oldval; |
| 1012 |
} |
| 1013 |
|
| 1014 |
oldpos = posto; |
| 1015 |
} |
| 1016 |
|
| 1017 |
for (i = oldpos; i < self->bufsize; i++) |
| 1018 |
{ |
| 1019 |
self->data[i] = self->value; |
| 1020 |
} |
| 1021 |
} |
| 1022 |
|
| 1023 |
(*self->muladd_func_ptr)(self); |
| 1024 |
} |
| 1025 |
|
| 1026 |
static int |
| 1027 |
Bendin_traverse(Bendin *self, visitproc visit, void *arg) |
| 1028 |
{ |
| 1029 |
pyo_VISIT |
| 1030 |
return 0; |
| 1031 |
} |
| 1032 |
|
| 1033 |
static int |
| 1034 |
Bendin_clear(Bendin *self) |
| 1035 |
{ |
| 1036 |
pyo_CLEAR |
| 1037 |
return 0; |
| 1038 |
} |
| 1039 |
|
| 1040 |
static void |
| 1041 |
Bendin_dealloc(Bendin* self) |
| 1042 |
{ |
| 1043 |
pyo_DEALLOC |
| 1044 |
Bendin_clear(self); |
| 1045 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 1046 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1047 |
} |
| 1048 |
|
| 1049 |
static PyObject * |
| 1050 |
Bendin_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1051 |
{ |
| 1052 |
int i; |
| 1053 |
PyObject *multmp = NULL, *addtmp = NULL; |
| 1054 |
Bendin *self; |
| 1055 |
self = (Bendin *)type->tp_alloc(type, 0); |
| 1056 |
|
| 1057 |
self->channel = 0; |
| 1058 |
self->scale = 0; |
| 1059 |
self->value = 0.; |
| 1060 |
self->range = 2.; |
| 1061 |
self->modebuffer[0] = 0; |
| 1062 |
self->modebuffer[1] = 0; |
| 1063 |
|
| 1064 |
INIT_OBJECT_COMMON |
| 1065 |
Stream_setFunctionPtr(self->stream, Bendin_compute_next_data_frame); |
| 1066 |
self->mode_func_ptr = Bendin_setProcMode; |
| 1067 |
|
| 1068 |
static char *kwlist[] = {"brange", "scale", "channel", "mul", "add", NULL}; |
| 1069 |
|
| 1070 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__FIIOO, kwlist, &self->range, &self->scale, &self->channel, &multmp, &addtmp)) |
| 1071 |
Py_RETURN_NONE; |
| 1072 |
|
| 1073 |
if (multmp) |
| 1074 |
{ |
| 1075 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 1076 |
} |
| 1077 |
|
| 1078 |
if (addtmp) |
| 1079 |
{ |
| 1080 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 1081 |
} |
| 1082 |
|
| 1083 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 1084 |
|
| 1085 |
if (self->scale == 1) |
| 1086 |
self->value = 1.0; |
| 1087 |
|
| 1088 |
(*self->mode_func_ptr)(self); |
| 1089 |
|
| 1090 |
return (PyObject *)self; |
| 1091 |
} |
| 1092 |
|
| 1093 |
static PyObject * Bendin_getServer(Bendin* self) { GET_SERVER }; |
| 1094 |
static PyObject * Bendin_getStream(Bendin* self) { GET_STREAM }; |
| 1095 |
static PyObject * Bendin_setMul(Bendin *self, PyObject *arg) { SET_MUL }; |
| 1096 |
static PyObject * Bendin_setAdd(Bendin *self, PyObject *arg) { SET_ADD }; |
| 1097 |
static PyObject * Bendin_setSub(Bendin *self, PyObject *arg) { SET_SUB }; |
| 1098 |
static PyObject * Bendin_setDiv(Bendin *self, PyObject *arg) { SET_DIV }; |
| 1099 |
|
| 1100 |
static PyObject * Bendin_play(Bendin *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 1101 |
static PyObject * Bendin_stop(Bendin *self, PyObject *args, PyObject *kwds) { STOP }; |
| 1102 |
|
| 1103 |
static PyObject * Bendin_multiply(Bendin *self, PyObject *arg) { MULTIPLY }; |
| 1104 |
static PyObject * Bendin_inplace_multiply(Bendin *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 1105 |
static PyObject * Bendin_add(Bendin *self, PyObject *arg) { ADD }; |
| 1106 |
static PyObject * Bendin_inplace_add(Bendin *self, PyObject *arg) { INPLACE_ADD }; |
| 1107 |
static PyObject * Bendin_sub(Bendin *self, PyObject *arg) { SUB }; |
| 1108 |
static PyObject * Bendin_inplace_sub(Bendin *self, PyObject *arg) { INPLACE_SUB }; |
| 1109 |
static PyObject * Bendin_div(Bendin *self, PyObject *arg) { DIV }; |
| 1110 |
static PyObject * Bendin_inplace_div(Bendin *self, PyObject *arg) { INPLACE_DIV }; |
| 1111 |
|
| 1112 |
static PyObject * |
| 1113 |
Bendin_setBrange(Bendin *self, PyObject *arg) |
| 1114 |
{ |
| 1115 |
MYFLT tmp; |
| 1116 |
|
| 1117 |
ASSERT_ARG_NOT_NULL |
| 1118 |
|
| 1119 |
if (PyNumber_Check(arg)) |
| 1120 |
{ |
| 1121 |
tmp = PyFloat_AsDouble(arg); |
| 1122 |
|
| 1123 |
if (tmp >= 0.0 && tmp < 128.0) |
| 1124 |
self->range = tmp; |
| 1125 |
} |
| 1126 |
|
| 1127 |
Py_RETURN_NONE; |
| 1128 |
} |
| 1129 |
|
| 1130 |
static PyObject * |
| 1131 |
Bendin_setChannel(Bendin *self, PyObject *arg) |
| 1132 |
{ |
| 1133 |
int tmp; |
| 1134 |
|
| 1135 |
ASSERT_ARG_NOT_NULL |
| 1136 |
|
| 1137 |
if (PyLong_Check(arg)) |
| 1138 |
{ |
| 1139 |
tmp = PyLong_AsLong(arg); |
| 1140 |
|
| 1141 |
if (tmp >= 0 && tmp < 128) |
| 1142 |
self->channel = tmp; |
| 1143 |
} |
| 1144 |
|
| 1145 |
Py_RETURN_NONE; |
| 1146 |
} |
| 1147 |
|
| 1148 |
static PyObject * |
| 1149 |
Bendin_setScale(Bendin *self, PyObject *arg) |
| 1150 |
{ |
| 1151 |
int tmp; |
| 1152 |
|
| 1153 |
ASSERT_ARG_NOT_NULL |
| 1154 |
|
| 1155 |
if (PyLong_Check(arg)) |
| 1156 |
{ |
| 1157 |
tmp = PyLong_AsLong(arg); |
| 1158 |
|
| 1159 |
if (tmp == 0) |
| 1160 |
self->scale = 0; |
| 1161 |
else if (tmp == 1) |
| 1162 |
self->scale = 1; |
| 1163 |
} |
| 1164 |
|
| 1165 |
Py_RETURN_NONE; |
| 1166 |
} |
| 1167 |
|
| 1168 |
static PyMemberDef Bendin_members[] = |
| 1169 |
{ |
| 1170 |
{"server", T_OBJECT_EX, offsetof(Bendin, server), 0, "Pyo server."}, |
| 1171 |
{"stream", T_OBJECT_EX, offsetof(Bendin, stream), 0, "Stream object."}, |
| 1172 |
{"mul", T_OBJECT_EX, offsetof(Bendin, mul), 0, "Mul factor."}, |
| 1173 |
{"add", T_OBJECT_EX, offsetof(Bendin, add), 0, "Add factor."}, |
| 1174 |
{NULL} /* Sentinel */ |
| 1175 |
}; |
| 1176 |
|
| 1177 |
static PyMethodDef Bendin_methods[] = |
| 1178 |
{ |
| 1179 |
{"getServer", (PyCFunction)Bendin_getServer, METH_NOARGS, "Returns server object."}, |
| 1180 |
{"_getStream", (PyCFunction)Bendin_getStream, METH_NOARGS, "Returns stream object."}, |
| 1181 |
{"play", (PyCFunction)Bendin_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1182 |
{"stop", (PyCFunction)Bendin_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1183 |
{"setBrange", (PyCFunction)Bendin_setBrange, METH_O, "Sets the bending bipolar range."}, |
| 1184 |
{"setScale", (PyCFunction)Bendin_setScale, METH_O, "Sets the output type, midi vs transpo."}, |
| 1185 |
{"setChannel", (PyCFunction)Bendin_setChannel, METH_O, "Sets the midi channel."}, |
| 1186 |
{"setMul", (PyCFunction)Bendin_setMul, METH_O, "Sets oscillator mul factor."}, |
| 1187 |
{"setAdd", (PyCFunction)Bendin_setAdd, METH_O, "Sets oscillator add factor."}, |
| 1188 |
{"setSub", (PyCFunction)Bendin_setSub, METH_O, "Sets inverse add factor."}, |
| 1189 |
{"setDiv", (PyCFunction)Bendin_setDiv, METH_O, "Sets inverse mul factor."}, |
| 1190 |
{NULL} /* Sentinel */ |
| 1191 |
}; |
| 1192 |
|
| 1193 |
static PyNumberMethods Bendin_as_number = |
| 1194 |
{ |
| 1195 |
(binaryfunc)Bendin_add, /*nb_add*/ |
| 1196 |
(binaryfunc)Bendin_sub, /*nb_subtract*/ |
| 1197 |
(binaryfunc)Bendin_multiply, /*nb_multiply*/ |
| 1198 |
0, /*nb_remainder*/ |
| 1199 |
0, /*nb_divmod*/ |
| 1200 |
0, /*nb_power*/ |
| 1201 |
0, /*nb_neg*/ |
| 1202 |
0, /*nb_pos*/ |
| 1203 |
0, /*(unaryfunc)array_abs,*/ |
| 1204 |
0, /*nb_nonzero*/ |
| 1205 |
0, /*nb_invert*/ |
| 1206 |
0, /*nb_lshift*/ |
| 1207 |
0, /*nb_rshift*/ |
| 1208 |
0, /*nb_and*/ |
| 1209 |
0, /*nb_xor*/ |
| 1210 |
0, /*nb_or*/ |
| 1211 |
0, /*nb_int*/ |
| 1212 |
0, /*nb_long*/ |
| 1213 |
0, /*nb_float*/ |
| 1214 |
(binaryfunc)Bendin_inplace_add, /*inplace_add*/ |
| 1215 |
(binaryfunc)Bendin_inplace_sub, /*inplace_subtract*/ |
| 1216 |
(binaryfunc)Bendin_inplace_multiply, /*inplace_multiply*/ |
| 1217 |
0, /*inplace_remainder*/ |
| 1218 |
0, /*inplace_power*/ |
| 1219 |
0, /*inplace_lshift*/ |
| 1220 |
0, /*inplace_rshift*/ |
| 1221 |
0, /*inplace_and*/ |
| 1222 |
0, /*inplace_xor*/ |
| 1223 |
0, /*inplace_or*/ |
| 1224 |
0, /*nb_floor_divide*/ |
| 1225 |
(binaryfunc)Bendin_div, /*nb_true_divide*/ |
| 1226 |
0, /*nb_inplace_floor_divide*/ |
| 1227 |
(binaryfunc)Bendin_inplace_div, /*nb_inplace_true_divide*/ |
| 1228 |
0, /* nb_index */ |
| 1229 |
}; |
| 1230 |
|
| 1231 |
PyTypeObject BendinType = |
| 1232 |
{ |
| 1233 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1234 |
"_pyo.Bendin_base", /*tp_name*/ |
| 1235 |
sizeof(Bendin), /*tp_basicsize*/ |
| 1236 |
0, /*tp_itemsize*/ |
| 1237 |
(destructor)Bendin_dealloc, /*tp_dealloc*/ |
| 1238 |
0, /*tp_print*/ |
| 1239 |
0, /*tp_getattr*/ |
| 1240 |
0, /*tp_setattr*/ |
| 1241 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1242 |
0, /*tp_repr*/ |
| 1243 |
&Bendin_as_number, /*tp_as_number*/ |
| 1244 |
0, /*tp_as_sequence*/ |
| 1245 |
0, /*tp_as_mapping*/ |
| 1246 |
0, /*tp_hash */ |
| 1247 |
0, /*tp_call*/ |
| 1248 |
0, /*tp_str*/ |
| 1249 |
0, /*tp_getattro*/ |
| 1250 |
0, /*tp_setattro*/ |
| 1251 |
0, /*tp_as_buffer*/ |
| 1252 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1253 |
"Bendin objects. Retreive audio from an input channel.", /* tp_doc */ |
| 1254 |
(traverseproc)Bendin_traverse, /* tp_traverse */ |
| 1255 |
(inquiry)Bendin_clear, /* tp_clear */ |
| 1256 |
0, /* tp_richcompare */ |
| 1257 |
0, /* tp_weaklistoffset */ |
| 1258 |
0, /* tp_iter */ |
| 1259 |
0, /* tp_iternext */ |
| 1260 |
Bendin_methods, /* tp_methods */ |
| 1261 |
Bendin_members, /* tp_members */ |
| 1262 |
0, /* tp_getset */ |
| 1263 |
0, /* tp_base */ |
| 1264 |
0, /* tp_dict */ |
| 1265 |
0, /* tp_descr_get */ |
| 1266 |
0, /* tp_descr_set */ |
| 1267 |
0, /* tp_dictoffset */ |
| 1268 |
0, /* tp_init */ |
| 1269 |
0, /* tp_alloc */ |
| 1270 |
Bendin_new, /* tp_new */ |
| 1271 |
}; |
| 1272 |
|
| 1273 |
typedef struct |
| 1274 |
{ |
| 1275 |
pyo_audio_HEAD |
| 1276 |
int channel; |
| 1277 |
MYFLT minscale; |
| 1278 |
MYFLT maxscale; |
| 1279 |
MYFLT value; |
| 1280 |
int modebuffer[2]; |
| 1281 |
} Touchin; |
| 1282 |
|
| 1283 |
static void Touchin_postprocessing_ii(Touchin *self) { POST_PROCESSING_II }; |
| 1284 |
static void Touchin_postprocessing_ai(Touchin *self) { POST_PROCESSING_AI }; |
| 1285 |
static void Touchin_postprocessing_ia(Touchin *self) { POST_PROCESSING_IA }; |
| 1286 |
static void Touchin_postprocessing_aa(Touchin *self) { POST_PROCESSING_AA }; |
| 1287 |
static void Touchin_postprocessing_ireva(Touchin *self) { POST_PROCESSING_IREVA }; |
| 1288 |
static void Touchin_postprocessing_areva(Touchin *self) { POST_PROCESSING_AREVA }; |
| 1289 |
static void Touchin_postprocessing_revai(Touchin *self) { POST_PROCESSING_REVAI }; |
| 1290 |
static void Touchin_postprocessing_revaa(Touchin *self) { POST_PROCESSING_REVAA }; |
| 1291 |
static void Touchin_postprocessing_revareva(Touchin *self) { POST_PROCESSING_REVAREVA }; |
| 1292 |
|
| 1293 |
static void |
| 1294 |
Touchin_setProcMode(Touchin *self) |
| 1295 |
{ |
| 1296 |
int muladdmode; |
| 1297 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 1298 |
|
| 1299 |
switch (muladdmode) |
| 1300 |
{ |
| 1301 |
case 0: |
| 1302 |
self->muladd_func_ptr = Touchin_postprocessing_ii; |
| 1303 |
break; |
| 1304 |
|
| 1305 |
case 1: |
| 1306 |
self->muladd_func_ptr = Touchin_postprocessing_ai; |
| 1307 |
break; |
| 1308 |
|
| 1309 |
case 2: |
| 1310 |
self->muladd_func_ptr = Touchin_postprocessing_revai; |
| 1311 |
break; |
| 1312 |
|
| 1313 |
case 10: |
| 1314 |
self->muladd_func_ptr = Touchin_postprocessing_ia; |
| 1315 |
break; |
| 1316 |
|
| 1317 |
case 11: |
| 1318 |
self->muladd_func_ptr = Touchin_postprocessing_aa; |
| 1319 |
break; |
| 1320 |
|
| 1321 |
case 12: |
| 1322 |
self->muladd_func_ptr = Touchin_postprocessing_revaa; |
| 1323 |
break; |
| 1324 |
|
| 1325 |
case 20: |
| 1326 |
self->muladd_func_ptr = Touchin_postprocessing_ireva; |
| 1327 |
break; |
| 1328 |
|
| 1329 |
case 21: |
| 1330 |
self->muladd_func_ptr = Touchin_postprocessing_areva; |
| 1331 |
break; |
| 1332 |
|
| 1333 |
case 22: |
| 1334 |
self->muladd_func_ptr = Touchin_postprocessing_revareva; |
| 1335 |
break; |
| 1336 |
} |
| 1337 |
} |
| 1338 |
|
| 1339 |
int |
| 1340 |
Touchin_translateMidi(Touchin *self, PyoMidiEvent *buffer, int j) |
| 1341 |
{ |
| 1342 |
int ok, posto = -1; |
| 1343 |
int status = PyoMidi_MessageStatus(buffer[j].message); // Temp note event holders |
| 1344 |
int number = PyoMidi_MessageData1(buffer[j].message); |
| 1345 |
|
| 1346 |
if (self->channel == 0) |
| 1347 |
{ |
| 1348 |
if ((status & 0xF0) == 0xd0) |
| 1349 |
ok = 1; |
| 1350 |
else |
| 1351 |
ok = 0; |
| 1352 |
} |
| 1353 |
else |
| 1354 |
{ |
| 1355 |
if (status == (0xd0 | (self->channel - 1))) |
| 1356 |
ok = 1; |
| 1357 |
else |
| 1358 |
ok = 0; |
| 1359 |
} |
| 1360 |
|
| 1361 |
if (ok == 1) |
| 1362 |
{ |
| 1363 |
self->value = (number / 127.) * (self->maxscale - self->minscale) + self->minscale; |
| 1364 |
posto = getPosToWrite(buffer[j].timestamp, (Server *)self->server, self->sr, self->bufsize); |
| 1365 |
} |
| 1366 |
|
| 1367 |
return posto; |
| 1368 |
} |
| 1369 |
|
| 1370 |
static void |
| 1371 |
Touchin_compute_next_data_frame(Touchin *self) |
| 1372 |
{ |
| 1373 |
PyoMidiEvent *tmp; |
| 1374 |
int i, j, count, posto, oldpos = 0; |
| 1375 |
MYFLT oldval = 0.0; |
| 1376 |
|
| 1377 |
tmp = Server_getMidiEventBuffer((Server *)self->server); |
| 1378 |
count = Server_getMidiEventCount((Server *)self->server); |
| 1379 |
|
| 1380 |
if (count == 0) |
| 1381 |
{ |
| 1382 |
for (i = 0; i < self->bufsize; i++) |
| 1383 |
{ |
| 1384 |
self->data[i] = self->value; |
| 1385 |
} |
| 1386 |
} |
| 1387 |
else |
| 1388 |
{ |
| 1389 |
for (j = 0; j < count; j++) |
| 1390 |
{ |
| 1391 |
oldval = self->value; |
| 1392 |
posto = Touchin_translateMidi((Touchin *)self, tmp, j); |
| 1393 |
|
| 1394 |
if (posto == -1) |
| 1395 |
continue; |
| 1396 |
|
| 1397 |
for (i = oldpos; i < posto; i++) |
| 1398 |
{ |
| 1399 |
self->data[i] = oldval; |
| 1400 |
} |
| 1401 |
|
| 1402 |
oldpos = posto; |
| 1403 |
} |
| 1404 |
|
| 1405 |
for (i = oldpos; i < self->bufsize; i++) |
| 1406 |
{ |
| 1407 |
self->data[i] = self->value; |
| 1408 |
} |
| 1409 |
} |
| 1410 |
|
| 1411 |
(*self->muladd_func_ptr)(self); |
| 1412 |
} |
| 1413 |
|
| 1414 |
static int |
| 1415 |
Touchin_traverse(Touchin *self, visitproc visit, void *arg) |
| 1416 |
{ |
| 1417 |
pyo_VISIT |
| 1418 |
return 0; |
| 1419 |
} |
| 1420 |
|
| 1421 |
static int |
| 1422 |
Touchin_clear(Touchin *self) |
| 1423 |
{ |
| 1424 |
pyo_CLEAR |
| 1425 |
return 0; |
| 1426 |
} |
| 1427 |
|
| 1428 |
static void |
| 1429 |
Touchin_dealloc(Touchin* self) |
| 1430 |
{ |
| 1431 |
pyo_DEALLOC |
| 1432 |
Touchin_clear(self); |
| 1433 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 1434 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1435 |
} |
| 1436 |
|
| 1437 |
static PyObject * |
| 1438 |
Touchin_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1439 |
{ |
| 1440 |
int i; |
| 1441 |
PyObject *multmp = NULL, *addtmp = NULL; |
| 1442 |
Touchin *self; |
| 1443 |
self = (Touchin *)type->tp_alloc(type, 0); |
| 1444 |
|
| 1445 |
self->channel = 0; |
| 1446 |
self->value = 0.; |
| 1447 |
self->minscale = 0.; |
| 1448 |
self->maxscale = 1.; |
| 1449 |
self->modebuffer[0] = 0; |
| 1450 |
self->modebuffer[1] = 0; |
| 1451 |
|
| 1452 |
INIT_OBJECT_COMMON |
| 1453 |
Stream_setFunctionPtr(self->stream, Touchin_compute_next_data_frame); |
| 1454 |
self->mode_func_ptr = Touchin_setProcMode; |
| 1455 |
|
| 1456 |
static char *kwlist[] = {"minscale", "maxscale", "init", "channel", "mul", "add", NULL}; |
| 1457 |
|
| 1458 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__FFFIOO, kwlist, &self->minscale, &self->maxscale, &self->value, &self->channel, &multmp, &addtmp)) |
| 1459 |
Py_RETURN_NONE; |
| 1460 |
|
| 1461 |
if (multmp) |
| 1462 |
{ |
| 1463 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 1464 |
} |
| 1465 |
|
| 1466 |
if (addtmp) |
| 1467 |
{ |
| 1468 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 1469 |
} |
| 1470 |
|
| 1471 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 1472 |
|
| 1473 |
(*self->mode_func_ptr)(self); |
| 1474 |
|
| 1475 |
return (PyObject *)self; |
| 1476 |
} |
| 1477 |
|
| 1478 |
static PyObject * Touchin_getServer(Touchin* self) { GET_SERVER }; |
| 1479 |
static PyObject * Touchin_getStream(Touchin* self) { GET_STREAM }; |
| 1480 |
static PyObject * Touchin_setMul(Touchin *self, PyObject *arg) { SET_MUL }; |
| 1481 |
static PyObject * Touchin_setAdd(Touchin *self, PyObject *arg) { SET_ADD }; |
| 1482 |
static PyObject * Touchin_setSub(Touchin *self, PyObject *arg) { SET_SUB }; |
| 1483 |
static PyObject * Touchin_setDiv(Touchin *self, PyObject *arg) { SET_DIV }; |
| 1484 |
|
| 1485 |
static PyObject * Touchin_play(Touchin *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 1486 |
static PyObject * Touchin_stop(Touchin *self, PyObject *args, PyObject *kwds) { STOP }; |
| 1487 |
|
| 1488 |
static PyObject * Touchin_multiply(Touchin *self, PyObject *arg) { MULTIPLY }; |
| 1489 |
static PyObject * Touchin_inplace_multiply(Touchin *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 1490 |
static PyObject * Touchin_add(Touchin *self, PyObject *arg) { ADD }; |
| 1491 |
static PyObject * Touchin_inplace_add(Touchin *self, PyObject *arg) { INPLACE_ADD }; |
| 1492 |
static PyObject * Touchin_sub(Touchin *self, PyObject *arg) { SUB }; |
| 1493 |
static PyObject * Touchin_inplace_sub(Touchin *self, PyObject *arg) { INPLACE_SUB }; |
| 1494 |
static PyObject * Touchin_div(Touchin *self, PyObject *arg) { DIV }; |
| 1495 |
static PyObject * Touchin_inplace_div(Touchin *self, PyObject *arg) { INPLACE_DIV }; |
| 1496 |
|
| 1497 |
static PyObject * |
| 1498 |
Touchin_setMinScale(Touchin *self, PyObject *arg) |
| 1499 |
{ |
| 1500 |
ASSERT_ARG_NOT_NULL |
| 1501 |
|
| 1502 |
if (PyNumber_Check(arg) == 1) |
| 1503 |
{ |
| 1504 |
self->minscale = PyFloat_AsDouble(arg); |
| 1505 |
} |
| 1506 |
|
| 1507 |
Py_RETURN_NONE; |
| 1508 |
} |
| 1509 |
|
| 1510 |
static PyObject * |
| 1511 |
Touchin_setMaxScale(Touchin *self, PyObject *arg) |
| 1512 |
{ |
| 1513 |
ASSERT_ARG_NOT_NULL |
| 1514 |
|
| 1515 |
if (PyNumber_Check(arg) == 1) |
| 1516 |
{ |
| 1517 |
self->maxscale = PyFloat_AsDouble(arg); |
| 1518 |
} |
| 1519 |
|
| 1520 |
Py_RETURN_NONE; |
| 1521 |
} |
| 1522 |
|
| 1523 |
static PyObject * |
| 1524 |
Touchin_setChannel(Touchin *self, PyObject *arg) |
| 1525 |
{ |
| 1526 |
int tmp; |
| 1527 |
|
| 1528 |
ASSERT_ARG_NOT_NULL |
| 1529 |
|
| 1530 |
if (PyLong_Check(arg) == 1) |
| 1531 |
{ |
| 1532 |
tmp = PyLong_AsLong(arg); |
| 1533 |
|
| 1534 |
if (tmp >= 0 && tmp < 128) |
| 1535 |
self->channel = tmp; |
| 1536 |
} |
| 1537 |
|
| 1538 |
Py_RETURN_NONE; |
| 1539 |
} |
| 1540 |
|
| 1541 |
static PyMemberDef Touchin_members[] = |
| 1542 |
{ |
| 1543 |
{"server", T_OBJECT_EX, offsetof(Touchin, server), 0, "Pyo server."}, |
| 1544 |
{"stream", T_OBJECT_EX, offsetof(Touchin, stream), 0, "Stream object."}, |
| 1545 |
{"mul", T_OBJECT_EX, offsetof(Touchin, mul), 0, "Mul factor."}, |
| 1546 |
{"add", T_OBJECT_EX, offsetof(Touchin, add), 0, "Add factor."}, |
| 1547 |
{NULL} /* Sentinel */ |
| 1548 |
}; |
| 1549 |
|
| 1550 |
static PyMethodDef Touchin_methods[] = |
| 1551 |
{ |
| 1552 |
{"getServer", (PyCFunction)Touchin_getServer, METH_NOARGS, "Returns server object."}, |
| 1553 |
{"_getStream", (PyCFunction)Touchin_getStream, METH_NOARGS, "Returns stream object."}, |
| 1554 |
{"play", (PyCFunction)Touchin_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1555 |
{"stop", (PyCFunction)Touchin_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1556 |
{"setMinScale", (PyCFunction)Touchin_setMinScale, METH_O, "Sets the minimum value of scaling."}, |
| 1557 |
{"setMaxScale", (PyCFunction)Touchin_setMaxScale, METH_O, "Sets the maximum value of scaling."}, |
| 1558 |
{"setChannel", (PyCFunction)Touchin_setChannel, METH_O, "Sets the midi channel."}, |
| 1559 |
{"setMul", (PyCFunction)Touchin_setMul, METH_O, "Sets oscillator mul factor."}, |
| 1560 |
{"setAdd", (PyCFunction)Touchin_setAdd, METH_O, "Sets oscillator add factor."}, |
| 1561 |
{"setSub", (PyCFunction)Touchin_setSub, METH_O, "Sets inverse add factor."}, |
| 1562 |
{"setDiv", (PyCFunction)Touchin_setDiv, METH_O, "Sets inverse mul factor."}, |
| 1563 |
{NULL} /* Sentinel */ |
| 1564 |
}; |
| 1565 |
|
| 1566 |
static PyNumberMethods Touchin_as_number = |
| 1567 |
{ |
| 1568 |
(binaryfunc)Touchin_add, /*nb_add*/ |
| 1569 |
(binaryfunc)Touchin_sub, /*nb_subtract*/ |
| 1570 |
(binaryfunc)Touchin_multiply, /*nb_multiply*/ |
| 1571 |
0, /*nb_remainder*/ |
| 1572 |
0, /*nb_divmod*/ |
| 1573 |
0, /*nb_power*/ |
| 1574 |
0, /*nb_neg*/ |
| 1575 |
0, /*nb_pos*/ |
| 1576 |
0, /*(unaryfunc)array_abs,*/ |
| 1577 |
0, /*nb_nonzero*/ |
| 1578 |
0, /*nb_invert*/ |
| 1579 |
0, /*nb_lshift*/ |
| 1580 |
0, /*nb_rshift*/ |
| 1581 |
0, /*nb_and*/ |
| 1582 |
0, /*nb_xor*/ |
| 1583 |
0, /*nb_or*/ |
| 1584 |
0, /*nb_int*/ |
| 1585 |
0, /*nb_long*/ |
| 1586 |
0, /*nb_float*/ |
| 1587 |
(binaryfunc)Touchin_inplace_add, /*inplace_add*/ |
| 1588 |
(binaryfunc)Touchin_inplace_sub, /*inplace_subtract*/ |
| 1589 |
(binaryfunc)Touchin_inplace_multiply, /*inplace_multiply*/ |
| 1590 |
0, /*inplace_remainder*/ |
| 1591 |
0, /*inplace_power*/ |
| 1592 |
0, /*inplace_lshift*/ |
| 1593 |
0, /*inplace_rshift*/ |
| 1594 |
0, /*inplace_and*/ |
| 1595 |
0, /*inplace_xor*/ |
| 1596 |
0, /*inplace_or*/ |
| 1597 |
0, /*nb_floor_divide*/ |
| 1598 |
(binaryfunc)Touchin_div, /*nb_true_divide*/ |
| 1599 |
0, /*nb_inplace_floor_divide*/ |
| 1600 |
(binaryfunc)Touchin_inplace_div, /*nb_inplace_true_divide*/ |
| 1601 |
0, /* nb_index */ |
| 1602 |
}; |
| 1603 |
|
| 1604 |
PyTypeObject TouchinType = |
| 1605 |
{ |
| 1606 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1607 |
"_pyo.Touchin_base", /*tp_name*/ |
| 1608 |
sizeof(Touchin), /*tp_basicsize*/ |
| 1609 |
0, /*tp_itemsize*/ |
| 1610 |
(destructor)Touchin_dealloc, /*tp_dealloc*/ |
| 1611 |
0, /*tp_print*/ |
| 1612 |
0, /*tp_getattr*/ |
| 1613 |
0, /*tp_setattr*/ |
| 1614 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1615 |
0, /*tp_repr*/ |
| 1616 |
&Touchin_as_number, /*tp_as_number*/ |
| 1617 |
0, /*tp_as_sequence*/ |
| 1618 |
0, /*tp_as_mapping*/ |
| 1619 |
0, /*tp_hash */ |
| 1620 |
0, /*tp_call*/ |
| 1621 |
0, /*tp_str*/ |
| 1622 |
0, /*tp_getattro*/ |
| 1623 |
0, /*tp_setattro*/ |
| 1624 |
0, /*tp_as_buffer*/ |
| 1625 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1626 |
"Touchin objects. Retrieve the signal of an aftertouch midi controller.", /* tp_doc */ |
| 1627 |
(traverseproc)Touchin_traverse, /* tp_traverse */ |
| 1628 |
(inquiry)Touchin_clear, /* tp_clear */ |
| 1629 |
0, /* tp_richcompare */ |
| 1630 |
0, /* tp_weaklistoffset */ |
| 1631 |
0, /* tp_iter */ |
| 1632 |
0, /* tp_iternext */ |
| 1633 |
Touchin_methods, /* tp_methods */ |
| 1634 |
Touchin_members, /* tp_members */ |
| 1635 |
0, /* tp_getset */ |
| 1636 |
0, /* tp_base */ |
| 1637 |
0, /* tp_dict */ |
| 1638 |
0, /* tp_descr_get */ |
| 1639 |
0, /* tp_descr_set */ |
| 1640 |
0, /* tp_dictoffset */ |
| 1641 |
0, /* tp_init */ |
| 1642 |
0, /* tp_alloc */ |
| 1643 |
Touchin_new, /* tp_new */ |
| 1644 |
}; |
| 1645 |
|
| 1646 |
typedef struct |
| 1647 |
{ |
| 1648 |
pyo_audio_HEAD |
| 1649 |
int channel; |
| 1650 |
MYFLT value; |
| 1651 |
int modebuffer[2]; |
| 1652 |
} Programin; |
| 1653 |
|
| 1654 |
static void Programin_postprocessing_ii(Programin *self) { POST_PROCESSING_II }; |
| 1655 |
static void Programin_postprocessing_ai(Programin *self) { POST_PROCESSING_AI }; |
| 1656 |
static void Programin_postprocessing_ia(Programin *self) { POST_PROCESSING_IA }; |
| 1657 |
static void Programin_postprocessing_aa(Programin *self) { POST_PROCESSING_AA }; |
| 1658 |
static void Programin_postprocessing_ireva(Programin *self) { POST_PROCESSING_IREVA }; |
| 1659 |
static void Programin_postprocessing_areva(Programin *self) { POST_PROCESSING_AREVA }; |
| 1660 |
static void Programin_postprocessing_revai(Programin *self) { POST_PROCESSING_REVAI }; |
| 1661 |
static void Programin_postprocessing_revaa(Programin *self) { POST_PROCESSING_REVAA }; |
| 1662 |
static void Programin_postprocessing_revareva(Programin *self) { POST_PROCESSING_REVAREVA }; |
| 1663 |
|
| 1664 |
static void |
| 1665 |
Programin_setProcMode(Programin *self) |
| 1666 |
{ |
| 1667 |
int muladdmode; |
| 1668 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 1669 |
|
| 1670 |
switch (muladdmode) |
| 1671 |
{ |
| 1672 |
case 0: |
| 1673 |
self->muladd_func_ptr = Programin_postprocessing_ii; |
| 1674 |
break; |
| 1675 |
|
| 1676 |
case 1: |
| 1677 |
self->muladd_func_ptr = Programin_postprocessing_ai; |
| 1678 |
break; |
| 1679 |
|
| 1680 |
case 2: |
| 1681 |
self->muladd_func_ptr = Programin_postprocessing_revai; |
| 1682 |
break; |
| 1683 |
|
| 1684 |
case 10: |
| 1685 |
self->muladd_func_ptr = Programin_postprocessing_ia; |
| 1686 |
break; |
| 1687 |
|
| 1688 |
case 11: |
| 1689 |
self->muladd_func_ptr = Programin_postprocessing_aa; |
| 1690 |
break; |
| 1691 |
|
| 1692 |
case 12: |
| 1693 |
self->muladd_func_ptr = Programin_postprocessing_revaa; |
| 1694 |
break; |
| 1695 |
|
| 1696 |
case 20: |
| 1697 |
self->muladd_func_ptr = Programin_postprocessing_ireva; |
| 1698 |
break; |
| 1699 |
|
| 1700 |
case 21: |
| 1701 |
self->muladd_func_ptr = Programin_postprocessing_areva; |
| 1702 |
break; |
| 1703 |
|
| 1704 |
case 22: |
| 1705 |
self->muladd_func_ptr = Programin_postprocessing_revareva; |
| 1706 |
break; |
| 1707 |
} |
| 1708 |
} |
| 1709 |
|
| 1710 |
// Take MIDI events and translate them... |
| 1711 |
void Programin_translateMidi(Programin *self, PyoMidiEvent *buffer, int count) |
| 1712 |
{ |
| 1713 |
int i, ok; |
| 1714 |
|
| 1715 |
for (i = 0; i < count; i++) |
| 1716 |
{ |
| 1717 |
int status = PyoMidi_MessageStatus(buffer[i].message); // Temp note event holders |
| 1718 |
int number = PyoMidi_MessageData1(buffer[i].message); |
| 1719 |
|
| 1720 |
if (self->channel == 0) |
| 1721 |
{ |
| 1722 |
if ((status & 0xF0) == 0xc0) |
| 1723 |
ok = 1; |
| 1724 |
else |
| 1725 |
ok = 0; |
| 1726 |
} |
| 1727 |
else |
| 1728 |
{ |
| 1729 |
if (status == (0xc0 | (self->channel - 1))) |
| 1730 |
ok = 1; |
| 1731 |
else |
| 1732 |
ok = 0; |
| 1733 |
} |
| 1734 |
|
| 1735 |
if (ok == 1) |
| 1736 |
{ |
| 1737 |
self->value = (MYFLT)number; |
| 1738 |
break; |
| 1739 |
} |
| 1740 |
} |
| 1741 |
} |
| 1742 |
|
| 1743 |
static void |
| 1744 |
Programin_compute_next_data_frame(Programin *self) |
| 1745 |
{ |
| 1746 |
PyoMidiEvent *tmp; |
| 1747 |
int i, count; |
| 1748 |
|
| 1749 |
tmp = Server_getMidiEventBuffer((Server *)self->server); |
| 1750 |
count = Server_getMidiEventCount((Server *)self->server); |
| 1751 |
|
| 1752 |
if (count > 0) |
| 1753 |
Programin_translateMidi((Programin *)self, tmp, count); |
| 1754 |
|
| 1755 |
for (i = 0; i < self->bufsize; i++) |
| 1756 |
{ |
| 1757 |
self->data[i] = self->value; |
| 1758 |
} |
| 1759 |
|
| 1760 |
(*self->muladd_func_ptr)(self); |
| 1761 |
} |
| 1762 |
|
| 1763 |
static int |
| 1764 |
Programin_traverse(Programin *self, visitproc visit, void *arg) |
| 1765 |
{ |
| 1766 |
pyo_VISIT |
| 1767 |
return 0; |
| 1768 |
} |
| 1769 |
|
| 1770 |
static int |
| 1771 |
Programin_clear(Programin *self) |
| 1772 |
{ |
| 1773 |
pyo_CLEAR |
| 1774 |
return 0; |
| 1775 |
} |
| 1776 |
|
| 1777 |
static void |
| 1778 |
Programin_dealloc(Programin* self) |
| 1779 |
{ |
| 1780 |
pyo_DEALLOC |
| 1781 |
Programin_clear(self); |
| 1782 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 1783 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1784 |
} |
| 1785 |
|
| 1786 |
static PyObject * |
| 1787 |
Programin_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1788 |
{ |
| 1789 |
int i; |
| 1790 |
PyObject *multmp = NULL, *addtmp = NULL; |
| 1791 |
Programin *self; |
| 1792 |
self = (Programin *)type->tp_alloc(type, 0); |
| 1793 |
|
| 1794 |
self->channel = 0; |
| 1795 |
self->value = 0.; |
| 1796 |
self->modebuffer[0] = 0; |
| 1797 |
self->modebuffer[1] = 0; |
| 1798 |
|
| 1799 |
INIT_OBJECT_COMMON |
| 1800 |
Stream_setFunctionPtr(self->stream, Programin_compute_next_data_frame); |
| 1801 |
self->mode_func_ptr = Programin_setProcMode; |
| 1802 |
|
| 1803 |
static char *kwlist[] = {"channel", "mul", "add", NULL}; |
| 1804 |
|
| 1805 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "iOO", kwlist, &self->channel, &multmp, &addtmp)) |
| 1806 |
Py_RETURN_NONE; |
| 1807 |
|
| 1808 |
if (multmp) |
| 1809 |
{ |
| 1810 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 1811 |
} |
| 1812 |
|
| 1813 |
if (addtmp) |
| 1814 |
{ |
| 1815 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 1816 |
} |
| 1817 |
|
| 1818 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 1819 |
|
| 1820 |
(*self->mode_func_ptr)(self); |
| 1821 |
|
| 1822 |
return (PyObject *)self; |
| 1823 |
} |
| 1824 |
|
| 1825 |
static PyObject * Programin_getServer(Programin* self) { GET_SERVER }; |
| 1826 |
static PyObject * Programin_getStream(Programin* self) { GET_STREAM }; |
| 1827 |
static PyObject * Programin_setMul(Programin *self, PyObject *arg) { SET_MUL }; |
| 1828 |
static PyObject * Programin_setAdd(Programin *self, PyObject *arg) { SET_ADD }; |
| 1829 |
static PyObject * Programin_setSub(Programin *self, PyObject *arg) { SET_SUB }; |
| 1830 |
static PyObject * Programin_setDiv(Programin *self, PyObject *arg) { SET_DIV }; |
| 1831 |
|
| 1832 |
static PyObject * Programin_play(Programin *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 1833 |
static PyObject * Programin_stop(Programin *self, PyObject *args, PyObject *kwds) { STOP }; |
| 1834 |
|
| 1835 |
static PyObject * Programin_multiply(Programin *self, PyObject *arg) { MULTIPLY }; |
| 1836 |
static PyObject * Programin_inplace_multiply(Programin *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 1837 |
static PyObject * Programin_add(Programin *self, PyObject *arg) { ADD }; |
| 1838 |
static PyObject * Programin_inplace_add(Programin *self, PyObject *arg) { INPLACE_ADD }; |
| 1839 |
static PyObject * Programin_sub(Programin *self, PyObject *arg) { SUB }; |
| 1840 |
static PyObject * Programin_inplace_sub(Programin *self, PyObject *arg) { INPLACE_SUB }; |
| 1841 |
static PyObject * Programin_div(Programin *self, PyObject *arg) { DIV }; |
| 1842 |
static PyObject * Programin_inplace_div(Programin *self, PyObject *arg) { INPLACE_DIV }; |
| 1843 |
|
| 1844 |
static PyObject * |
| 1845 |
Programin_setChannel(Programin *self, PyObject *arg) |
| 1846 |
{ |
| 1847 |
int tmp; |
| 1848 |
|
| 1849 |
ASSERT_ARG_NOT_NULL |
| 1850 |
|
| 1851 |
if (PyLong_Check(arg)) |
| 1852 |
{ |
| 1853 |
tmp = PyLong_AsLong(arg); |
| 1854 |
|
| 1855 |
if (tmp >= 0 && tmp < 128) |
| 1856 |
self->channel = tmp; |
| 1857 |
} |
| 1858 |
|
| 1859 |
Py_RETURN_NONE; |
| 1860 |
} |
| 1861 |
|
| 1862 |
static PyMemberDef Programin_members[] = |
| 1863 |
{ |
| 1864 |
{"server", T_OBJECT_EX, offsetof(Programin, server), 0, "Pyo server."}, |
| 1865 |
{"stream", T_OBJECT_EX, offsetof(Programin, stream), 0, "Stream object."}, |
| 1866 |
{"mul", T_OBJECT_EX, offsetof(Programin, mul), 0, "Mul factor."}, |
| 1867 |
{"add", T_OBJECT_EX, offsetof(Programin, add), 0, "Add factor."}, |
| 1868 |
{NULL} /* Sentinel */ |
| 1869 |
}; |
| 1870 |
|
| 1871 |
static PyMethodDef Programin_methods[] = |
| 1872 |
{ |
| 1873 |
{"getServer", (PyCFunction)Programin_getServer, METH_NOARGS, "Returns server object."}, |
| 1874 |
{"_getStream", (PyCFunction)Programin_getStream, METH_NOARGS, "Returns stream object."}, |
| 1875 |
{"play", (PyCFunction)Programin_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1876 |
{"stop", (PyCFunction)Programin_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1877 |
{"setChannel", (PyCFunction)Programin_setChannel, METH_O, "Sets the midi channel."}, |
| 1878 |
{"setMul", (PyCFunction)Programin_setMul, METH_O, "Sets oscillator mul factor."}, |
| 1879 |
{"setAdd", (PyCFunction)Programin_setAdd, METH_O, "Sets oscillator add factor."}, |
| 1880 |
{"setSub", (PyCFunction)Programin_setSub, METH_O, "Sets inverse add factor."}, |
| 1881 |
{"setDiv", (PyCFunction)Programin_setDiv, METH_O, "Sets inverse mul factor."}, |
| 1882 |
{NULL} /* Sentinel */ |
| 1883 |
}; |
| 1884 |
|
| 1885 |
static PyNumberMethods Programin_as_number = |
| 1886 |
{ |
| 1887 |
(binaryfunc)Programin_add, /*nb_add*/ |
| 1888 |
(binaryfunc)Programin_sub, /*nb_subtract*/ |
| 1889 |
(binaryfunc)Programin_multiply, /*nb_multiply*/ |
| 1890 |
0, /*nb_remainder*/ |
| 1891 |
0, /*nb_divmod*/ |
| 1892 |
0, /*nb_power*/ |
| 1893 |
0, /*nb_neg*/ |
| 1894 |
0, /*nb_pos*/ |
| 1895 |
0, /*(unaryfunc)array_abs,*/ |
| 1896 |
0, /*nb_nonzero*/ |
| 1897 |
0, /*nb_invert*/ |
| 1898 |
0, /*nb_lshift*/ |
| 1899 |
0, /*nb_rshift*/ |
| 1900 |
0, /*nb_and*/ |
| 1901 |
0, /*nb_xor*/ |
| 1902 |
0, /*nb_or*/ |
| 1903 |
0, /*nb_int*/ |
| 1904 |
0, /*nb_long*/ |
| 1905 |
0, /*nb_float*/ |
| 1906 |
(binaryfunc)Programin_inplace_add, /*inplace_add*/ |
| 1907 |
(binaryfunc)Programin_inplace_sub, /*inplace_subtract*/ |
| 1908 |
(binaryfunc)Programin_inplace_multiply, /*inplace_multiply*/ |
| 1909 |
0, /*inplace_remainder*/ |
| 1910 |
0, /*inplace_power*/ |
| 1911 |
0, /*inplace_lshift*/ |
| 1912 |
0, /*inplace_rshift*/ |
| 1913 |
0, /*inplace_and*/ |
| 1914 |
0, /*inplace_xor*/ |
| 1915 |
0, /*inplace_or*/ |
| 1916 |
0, /*nb_floor_divide*/ |
| 1917 |
(binaryfunc)Programin_div, /*nb_true_divide*/ |
| 1918 |
0, /*nb_inplace_floor_divide*/ |
| 1919 |
(binaryfunc)Programin_inplace_div, /*nb_inplace_true_divide*/ |
| 1920 |
0, /* nb_index */ |
| 1921 |
}; |
| 1922 |
|
| 1923 |
PyTypeObject PrograminType = |
| 1924 |
{ |
| 1925 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1926 |
"_pyo.Programin_base", /*tp_name*/ |
| 1927 |
sizeof(Programin), /*tp_basicsize*/ |
| 1928 |
0, /*tp_itemsize*/ |
| 1929 |
(destructor)Programin_dealloc, /*tp_dealloc*/ |
| 1930 |
0, /*tp_print*/ |
| 1931 |
0, /*tp_getattr*/ |
| 1932 |
0, /*tp_setattr*/ |
| 1933 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1934 |
0, /*tp_repr*/ |
| 1935 |
&Programin_as_number, /*tp_as_number*/ |
| 1936 |
0, /*tp_as_sequence*/ |
| 1937 |
0, /*tp_as_mapping*/ |
| 1938 |
0, /*tp_hash */ |
| 1939 |
0, /*tp_call*/ |
| 1940 |
0, /*tp_str*/ |
| 1941 |
0, /*tp_getattro*/ |
| 1942 |
0, /*tp_setattro*/ |
| 1943 |
0, /*tp_as_buffer*/ |
| 1944 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1945 |
"Programin objects. Retrieve the signal of a program change midi controller.", /* tp_doc */ |
| 1946 |
(traverseproc)Programin_traverse, /* tp_traverse */ |
| 1947 |
(inquiry)Programin_clear, /* tp_clear */ |
| 1948 |
0, /* tp_richcompare */ |
| 1949 |
0, /* tp_weaklistoffset */ |
| 1950 |
0, /* tp_iter */ |
| 1951 |
0, /* tp_iternext */ |
| 1952 |
Programin_methods, /* tp_methods */ |
| 1953 |
Programin_members, /* tp_members */ |
| 1954 |
0, /* tp_getset */ |
| 1955 |
0, /* tp_base */ |
| 1956 |
0, /* tp_dict */ |
| 1957 |
0, /* tp_descr_get */ |
| 1958 |
0, /* tp_descr_set */ |
| 1959 |
0, /* tp_dictoffset */ |
| 1960 |
0, /* tp_init */ |
| 1961 |
0, /* tp_alloc */ |
| 1962 |
Programin_new, /* tp_new */ |
| 1963 |
}; |
| 1964 |
|
| 1965 |
typedef struct |
| 1966 |
{ |
| 1967 |
pyo_audio_HEAD |
| 1968 |
int *notebuf; /* pitch, velocity, posToWrite */ |
| 1969 |
int voices; |
| 1970 |
int vcount; |
| 1971 |
int scale; /* 0 = midi, 1 = hertz, 2 = transpo */ |
| 1972 |
int first; |
| 1973 |
int last; |
| 1974 |
int centralkey; |
| 1975 |
int channel; |
| 1976 |
int stealing; |
| 1977 |
int holdmode; |
| 1978 |
int firstvelocity; |
| 1979 |
int lastvelocity; |
| 1980 |
PyoMidiEvent midiEvents[64]; |
| 1981 |
int eventcount; |
| 1982 |
MYFLT *trigger_streams; |
| 1983 |
} MidiNote; |
| 1984 |
|
| 1985 |
static void |
| 1986 |
MidiNote_setProcMode(MidiNote *self) {}; |
| 1987 |
|
| 1988 |
int |
| 1989 |
pitchIsIn(int *buf, int pitch, int len) |
| 1990 |
{ |
| 1991 |
int i; |
| 1992 |
int isIn = 0; |
| 1993 |
|
| 1994 |
for (i = 0; i < len; i++) |
| 1995 |
{ |
| 1996 |
if (buf[i * 3] == pitch) |
| 1997 |
{ |
| 1998 |
isIn = 1; |
| 1999 |
break; |
| 2000 |
} |
| 2001 |
} |
| 2002 |
|
| 2003 |
return isIn; |
| 2004 |
} |
| 2005 |
|
| 2006 |
/* no more used */ |
| 2007 |
int firstEmpty(int *buf, int len) |
| 2008 |
{ |
| 2009 |
int i; |
| 2010 |
int voice = -1; |
| 2011 |
|
| 2012 |
for (i = 0; i < len; i++) |
| 2013 |
{ |
| 2014 |
if (buf[i * 3 + 1] == 0) |
| 2015 |
{ |
| 2016 |
voice = i; |
| 2017 |
break; |
| 2018 |
} |
| 2019 |
} |
| 2020 |
|
| 2021 |
return voice; |
| 2022 |
} |
| 2023 |
|
| 2024 |
int nextEmptyVoice(int *buf, int voice, int len) |
| 2025 |
{ |
| 2026 |
int i, tmp; |
| 2027 |
int next = -1; |
| 2028 |
|
| 2029 |
for (i = 1; i <= len; i++) |
| 2030 |
{ |
| 2031 |
tmp = (i + voice) % len; |
| 2032 |
|
| 2033 |
if (buf[tmp * 3 + 1] == 0) |
| 2034 |
{ |
| 2035 |
next = tmp; |
| 2036 |
break; |
| 2037 |
} |
| 2038 |
} |
| 2039 |
|
| 2040 |
return next; |
| 2041 |
} |
| 2042 |
|
| 2043 |
int whichVoice(int *buf, int pitch, int len) |
| 2044 |
{ |
| 2045 |
int i; |
| 2046 |
int voice = 0; |
| 2047 |
|
| 2048 |
for (i = 0; i < len; i++) |
| 2049 |
{ |
| 2050 |
if (buf[i * 3] == pitch) |
| 2051 |
{ |
| 2052 |
voice = i; |
| 2053 |
break; |
| 2054 |
} |
| 2055 |
} |
| 2056 |
|
| 2057 |
return voice; |
| 2058 |
} |
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
// Sends a noteoff MIDI event for all pitches in MidiEventBuffer |
| 2063 |
// but not for current_pitch if current_pitch > -1 |
| 2064 |
void allNotesOff(MidiNote *self, int current_pitch) |
| 2065 |
{ |
| 2066 |
int i, pitch, samp; |
| 2067 |
PyoMidiEvent *buf = Server_getMidiEventBuffer((Server *)self->server); |
| 2068 |
|
| 2069 |
for (i = 0; i < self->voices; i++) |
| 2070 |
{ |
| 2071 |
pitch = self->notebuf[i * 3]; |
| 2072 |
if (pitch != -1 && (pitch != current_pitch || current_pitch == -1)) |
| 2073 |
{ |
| 2074 |
samp = getPosToWrite(buf[i].timestamp, (Server *)self->server, self->sr, self->bufsize); |
| 2075 |
self->notebuf[i * 3] = -1; |
| 2076 |
self->notebuf[i * 3 + 1] = 0; |
| 2077 |
self->notebuf[i * 3 + 2] = samp; |
| 2078 |
self->trigger_streams[self->bufsize * (i * 2 + 1) + samp] = 1.0; |
| 2079 |
} |
| 2080 |
} |
| 2081 |
|
| 2082 |
} |
| 2083 |
|
| 2084 |
// Take MIDI events and keep track of notes |
| 2085 |
void grabMidiNotes(MidiNote *self, PyoMidiEvent *buffer, int count) |
| 2086 |
{ |
| 2087 |
int i, ok, voice, kind, samp, pitchIsInBuffer = 0; |
| 2088 |
|
| 2089 |
for (i = 0; i < count; i++) |
| 2090 |
{ |
| 2091 |
int status = PyoMidi_MessageStatus(buffer[i].message); // Temp note event holders |
| 2092 |
int pitch = PyoMidi_MessageData1(buffer[i].message); |
| 2093 |
int velocity = PyoMidi_MessageData2(buffer[i].message); |
| 2094 |
|
| 2095 |
if (self->channel == 0) |
| 2096 |
{ |
| 2097 |
if (((status & 0xF0) == 0x90 || (status & 0xF0) == 0x80) |
| 2098 |
&& pitch >= self->first && pitch <= self->last |
| 2099 |
&& (velocity == 0 || (velocity >= self->firstvelocity && velocity <= self->lastvelocity))) |
| 2100 |
ok = 1; |
| 2101 |
else |
| 2102 |
ok = 0; |
| 2103 |
} |
| 2104 |
else |
| 2105 |
{ |
| 2106 |
if ((status == (0x90 | (self->channel - 1)) || status == (0x80 | (self->channel - 1))) |
| 2107 |
&& pitch >= self->first && pitch <= self->last |
| 2108 |
&& (velocity == 0 || (velocity >= self->firstvelocity && velocity <= self->lastvelocity))) |
| 2109 |
ok = 1; |
| 2110 |
else |
| 2111 |
ok = 0; |
| 2112 |
} |
| 2113 |
|
| 2114 |
if (ok == 1) |
| 2115 |
{ |
| 2116 |
samp = getPosToWrite(buffer[i].timestamp, (Server *)self->server, self->sr, self->bufsize); |
| 2117 |
|
| 2118 |
if ((status & 0xF0) == 0x80) |
| 2119 |
kind = 0; |
| 2120 |
else if ((status & 0xF0) == 0x90 && velocity == 0) |
| 2121 |
kind = 0; |
| 2122 |
else |
| 2123 |
{ |
| 2124 |
kind = 1; |
| 2125 |
if (self->holdmode > 2) |
| 2126 |
allNotesOff((MidiNote *)self, pitch); |
| 2127 |
} |
| 2128 |
|
| 2129 |
pitchIsInBuffer = pitchIsIn(self->notebuf, pitch, self->voices); |
| 2130 |
|
| 2131 |
if (pitchIsInBuffer == 0 && kind == 1) |
| 2132 |
{ |
| 2133 |
|
| 2134 |
if (self->holdmode == 2 || self->holdmode == 4) |
| 2135 |
velocity = 127; |
| 2136 |
|
| 2137 |
//PySys_WriteStdout("%i, %i, %i\n", status, pitch, velocity); |
| 2138 |
if (!self->stealing) |
| 2139 |
{ |
| 2140 |
voice = nextEmptyVoice(self->notebuf, self->vcount, self->voices); |
| 2141 |
|
| 2142 |
if (voice != -1) |
| 2143 |
{ |
| 2144 |
self->vcount = voice; |
| 2145 |
self->notebuf[voice * 3] = pitch; |
| 2146 |
self->notebuf[voice * 3 + 1] = velocity; |
| 2147 |
self->notebuf[voice * 3 + 2] = samp; |
| 2148 |
self->trigger_streams[self->bufsize * (self->vcount * 2) + samp] = 1.0; |
| 2149 |
} |
| 2150 |
} |
| 2151 |
else |
| 2152 |
{ |
| 2153 |
self->vcount = (self->vcount + 1) % self->voices; |
| 2154 |
self->notebuf[self->vcount * 3] = pitch; |
| 2155 |
self->notebuf[self->vcount * 3 + 1] = velocity; |
| 2156 |
self->notebuf[self->vcount * 3 + 2] = samp; |
| 2157 |
self->trigger_streams[self->bufsize * (self->vcount * 2) + samp] = 1.0; |
| 2158 |
} |
| 2159 |
} |
| 2160 |
else if (pitchIsInBuffer == 1 && ((kind == 0 && self->holdmode == 0) || (kind == 1 && self->holdmode > 0))) |
| 2161 |
{ |
| 2162 |
//PySys_WriteStdout("%i, %i, %i\n", status, pitch, velocity); |
| 2163 |
voice = whichVoice(self->notebuf, pitch, self->voices); |
| 2164 |
self->notebuf[voice * 3] = -1; |
| 2165 |
self->notebuf[voice * 3 + 1] = 0; |
| 2166 |
self->notebuf[voice * 3 + 2] = samp; |
| 2167 |
self->trigger_streams[self->bufsize * (voice * 2 + 1) + samp] = 1.0; |
| 2168 |
} |
| 2169 |
} |
| 2170 |
} |
| 2171 |
} |
| 2172 |
|
| 2173 |
static void |
| 2174 |
MidiNote_compute_next_data_frame(MidiNote *self) |
| 2175 |
{ |
| 2176 |
PyoMidiEvent *tmp; |
| 2177 |
int i, count; |
| 2178 |
|
| 2179 |
for (i = 0; i < self->bufsize * self->voices * 2; i++) |
| 2180 |
{ |
| 2181 |
self->trigger_streams[i] = 0.0; |
| 2182 |
} |
| 2183 |
|
| 2184 |
if (self->eventcount > 0) |
| 2185 |
{ |
| 2186 |
grabMidiNotes((MidiNote *)self, self->midiEvents, self->eventcount); |
| 2187 |
} |
| 2188 |
|
| 2189 |
self->eventcount = 0; |
| 2190 |
|
| 2191 |
tmp = Server_getMidiEventBuffer((Server *)self->server); |
| 2192 |
count = Server_getMidiEventCount((Server *)self->server); |
| 2193 |
|
| 2194 |
if (count > 0) |
| 2195 |
grabMidiNotes((MidiNote *)self, tmp, count); |
| 2196 |
} |
| 2197 |
|
| 2198 |
static int |
| 2199 |
MidiNote_traverse(MidiNote *self, visitproc visit, void *arg) |
| 2200 |
{ |
| 2201 |
pyo_VISIT |
| 2202 |
return 0; |
| 2203 |
} |
| 2204 |
|
| 2205 |
static int |
| 2206 |
MidiNote_clear(MidiNote *self) |
| 2207 |
{ |
| 2208 |
pyo_CLEAR |
| 2209 |
return 0; |
| 2210 |
} |
| 2211 |
|
| 2212 |
static void |
| 2213 |
MidiNote_dealloc(MidiNote* self) |
| 2214 |
{ |
| 2215 |
pyo_DEALLOC |
| 2216 |
PyMem_RawFree(self->notebuf); |
| 2217 |
PyMem_RawFree(self->trigger_streams); |
| 2218 |
MidiNote_clear(self); |
| 2219 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 2220 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 2221 |
} |
| 2222 |
|
| 2223 |
static MYFLT * |
| 2224 |
MidiNote_get_trigger_buffer(MidiNote *self) |
| 2225 |
{ |
| 2226 |
return self->trigger_streams; |
| 2227 |
} |
| 2228 |
|
| 2229 |
static PyObject * |
| 2230 |
MidiNote_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 2231 |
{ |
| 2232 |
int i; |
| 2233 |
|
| 2234 |
MidiNote *self; |
| 2235 |
self = (MidiNote *)type->tp_alloc(type, 0); |
| 2236 |
|
| 2237 |
self->voices = 10; |
| 2238 |
self->vcount = 0; |
| 2239 |
self->scale = 0; |
| 2240 |
self->first = 0; |
| 2241 |
self->last = 127; |
| 2242 |
self->channel = 0; |
| 2243 |
self->stealing = 0; |
| 2244 |
self->holdmode = 0; |
| 2245 |
self->firstvelocity = 1; |
| 2246 |
self->lastvelocity = 127; |
| 2247 |
self->eventcount = 0; |
| 2248 |
|
| 2249 |
INIT_OBJECT_COMMON |
| 2250 |
Stream_setFunctionPtr(self->stream, MidiNote_compute_next_data_frame); |
| 2251 |
self->mode_func_ptr = MidiNote_setProcMode; |
| 2252 |
|
| 2253 |
static char *kwlist[] = {"voices", "scale", "first", "last", "channel", NULL}; |
| 2254 |
|
| 2255 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|iiiii", kwlist, &self->voices, &self->scale, &self->first, &self->last, &self->channel)) |
| 2256 |
Py_RETURN_NONE; |
| 2257 |
|
| 2258 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 2259 |
|
| 2260 |
self->notebuf = (int *)PyMem_RawRealloc(self->notebuf, self->voices * 3 * sizeof(int)); |
| 2261 |
self->trigger_streams = (MYFLT *)PyMem_RawRealloc(self->trigger_streams, self->bufsize * self->voices * 2 * sizeof(MYFLT)); |
| 2262 |
|
| 2263 |
for (i = 0; i < self->bufsize * self->voices * 2; i++) |
| 2264 |
{ |
| 2265 |
self->trigger_streams[i] = 0.0; |
| 2266 |
} |
| 2267 |
|
| 2268 |
for (i = 0; i < self->voices; i++) |
| 2269 |
{ |
| 2270 |
self->notebuf[i * 3] = -1; |
| 2271 |
self->notebuf[i * 3 + 1] = 0; |
| 2272 |
self->notebuf[i * 3 + 2] = 0; |
| 2273 |
} |
| 2274 |
|
| 2275 |
self->centralkey = (self->first + self->last) / 2; |
| 2276 |
|
| 2277 |
(*self->mode_func_ptr)(self); |
| 2278 |
|
| 2279 |
return (PyObject *)self; |
| 2280 |
} |
| 2281 |
|
| 2282 |
MYFLT |
| 2283 |
MidiNote_getValue(MidiNote *self, int voice, int which, int *posto) |
| 2284 |
{ |
| 2285 |
MYFLT val = -1.0; |
| 2286 |
int midival = self->notebuf[voice * 3 + which]; |
| 2287 |
|
| 2288 |
if (which == 0 && midival != -1) |
| 2289 |
{ |
| 2290 |
if (self->scale == 0) |
| 2291 |
val = midival; |
| 2292 |
else if (self->scale == 1) |
| 2293 |
val = 8.1757989156437 * MYPOW(1.0594630943593, midival); |
| 2294 |
else if (self->scale == 2) |
| 2295 |
val = MYPOW(1.0594630943593, midival - self->centralkey); |
| 2296 |
} |
| 2297 |
else if (which == 0) |
| 2298 |
val = (MYFLT)midival; |
| 2299 |
else if (which == 1) |
| 2300 |
val = (MYFLT)midival / 127.; |
| 2301 |
|
| 2302 |
*posto = self->notebuf[voice * 3 + 2]; |
| 2303 |
|
| 2304 |
return val; |
| 2305 |
} |
| 2306 |
|
| 2307 |
static PyObject * |
| 2308 |
MidiNote_sendAllNotesOff(MidiNote *self) |
| 2309 |
{ |
| 2310 |
allNotesOff((MidiNote *)self, -1); |
| 2311 |
Py_RETURN_NONE; |
| 2312 |
} |
| 2313 |
|
| 2314 |
static PyObject * |
| 2315 |
MidiNote_addMidiEvent(MidiNote *self, PyObject *args) |
| 2316 |
{ |
| 2317 |
int status, data1, data2; |
| 2318 |
PyoMidiEvent buffer; |
| 2319 |
|
| 2320 |
if (! PyArg_ParseTuple(args, "ii", &data1, &data2)) |
| 2321 |
return PyLong_FromLong(-1); |
| 2322 |
|
| 2323 |
if (self->channel == 0) |
| 2324 |
{ |
| 2325 |
status = 0x90; |
| 2326 |
} |
| 2327 |
else |
| 2328 |
{ |
| 2329 |
status = 0x90 | (self->channel - 1); |
| 2330 |
} |
| 2331 |
|
| 2332 |
buffer.timestamp = 0; |
| 2333 |
buffer.message = PyoMidi_Message(status, data1, data2); |
| 2334 |
self->midiEvents[self->eventcount++] = buffer; |
| 2335 |
|
| 2336 |
if (self->eventcount == 64) |
| 2337 |
{ |
| 2338 |
self->eventcount = 0; |
| 2339 |
} |
| 2340 |
|
| 2341 |
Py_RETURN_NONE; |
| 2342 |
} |
| 2343 |
|
| 2344 |
static PyObject * MidiNote_getServer(MidiNote* self) { GET_SERVER }; |
| 2345 |
static PyObject * MidiNote_getStream(MidiNote* self) { GET_STREAM }; |
| 2346 |
|
| 2347 |
static PyObject * MidiNote_play(MidiNote *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 2348 |
static PyObject * MidiNote_stop(MidiNote *self, PyObject *args, PyObject *kwds) { STOP }; |
| 2349 |
|
| 2350 |
static PyObject * |
| 2351 |
MidiNote_setScale(MidiNote *self, PyObject *arg) |
| 2352 |
{ |
| 2353 |
ASSERT_ARG_NOT_NULL |
| 2354 |
|
| 2355 |
if (PyLong_Check(arg) == 1) |
| 2356 |
{ |
| 2357 |
int tmp = PyLong_AsLong(arg); |
| 2358 |
|
| 2359 |
if (tmp >= 0 && tmp < 3) |
| 2360 |
self->scale = tmp; |
| 2361 |
} |
| 2362 |
|
| 2363 |
Py_RETURN_NONE; |
| 2364 |
} |
| 2365 |
|
| 2366 |
static PyObject * |
| 2367 |
MidiNote_setFirst(MidiNote *self, PyObject *arg) |
| 2368 |
{ |
| 2369 |
ASSERT_ARG_NOT_NULL |
| 2370 |
|
| 2371 |
if (PyLong_Check(arg) == 1) |
| 2372 |
{ |
| 2373 |
int tmp = PyLong_AsLong(arg); |
| 2374 |
|
| 2375 |
if (tmp >= 0 && tmp < 128) |
| 2376 |
self->first = tmp; |
| 2377 |
} |
| 2378 |
|
| 2379 |
Py_RETURN_NONE; |
| 2380 |
} |
| 2381 |
|
| 2382 |
static PyObject * |
| 2383 |
MidiNote_setLast(MidiNote *self, PyObject *arg) |
| 2384 |
{ |
| 2385 |
ASSERT_ARG_NOT_NULL |
| 2386 |
|
| 2387 |
if (PyLong_Check(arg) == 1) |
| 2388 |
{ |
| 2389 |
int tmp = PyLong_AsLong(arg); |
| 2390 |
|
| 2391 |
if (tmp >= 0 && tmp < 128) |
| 2392 |
self->last = tmp; |
| 2393 |
} |
| 2394 |
|
| 2395 |
Py_RETURN_NONE; |
| 2396 |
} |
| 2397 |
|
| 2398 |
static PyObject * |
| 2399 |
MidiNote_setChannel(MidiNote *self, PyObject *arg) |
| 2400 |
{ |
| 2401 |
ASSERT_ARG_NOT_NULL |
| 2402 |
|
| 2403 |
if (PyLong_Check(arg) == 1) |
| 2404 |
{ |
| 2405 |
int tmp = PyLong_AsLong(arg); |
| 2406 |
|
| 2407 |
if (tmp >= 0 && tmp < 128) |
| 2408 |
self->channel = tmp; |
| 2409 |
} |
| 2410 |
|
| 2411 |
Py_RETURN_NONE; |
| 2412 |
} |
| 2413 |
|
| 2414 |
static PyObject * |
| 2415 |
MidiNote_setCentralKey(MidiNote *self, PyObject *arg) |
| 2416 |
{ |
| 2417 |
int tmp; |
| 2418 |
|
| 2419 |
ASSERT_ARG_NOT_NULL |
| 2420 |
|
| 2421 |
if (PyLong_Check(arg)) |
| 2422 |
{ |
| 2423 |
tmp = PyLong_AsLong(arg); |
| 2424 |
|
| 2425 |
if (tmp >= self->first && tmp <= self->last) |
| 2426 |
self->centralkey = tmp; |
| 2427 |
} |
| 2428 |
|
| 2429 |
Py_RETURN_NONE; |
| 2430 |
} |
| 2431 |
|
| 2432 |
static PyObject * |
| 2433 |
MidiNote_setStealing(MidiNote *self, PyObject *arg) |
| 2434 |
{ |
| 2435 |
ASSERT_ARG_NOT_NULL |
| 2436 |
|
| 2437 |
if (PyLong_Check(arg)) |
| 2438 |
self->stealing = PyLong_AsLong(arg); |
| 2439 |
|
| 2440 |
Py_RETURN_NONE; |
| 2441 |
} |
| 2442 |
|
| 2443 |
static PyObject * |
| 2444 |
MidiNote_setHoldmode(MidiNote *self, PyObject *arg) |
| 2445 |
{ |
| 2446 |
int tmp; |
| 2447 |
|
| 2448 |
ASSERT_ARG_NOT_NULL |
| 2449 |
|
| 2450 |
if (PyLong_Check(arg)) |
| 2451 |
{ |
| 2452 |
tmp = PyLong_AsLong(arg); |
| 2453 |
|
| 2454 |
if (tmp >= 0 && tmp < 5) |
| 2455 |
self->holdmode = tmp; |
| 2456 |
} |
| 2457 |
|
| 2458 |
Py_RETURN_NONE; |
| 2459 |
} |
| 2460 |
|
| 2461 |
static PyObject * |
| 2462 |
MidiNote_setFirstVelocity(MidiNote *self, PyObject *arg) |
| 2463 |
{ |
| 2464 |
int tmp; |
| 2465 |
|
| 2466 |
ASSERT_ARG_NOT_NULL |
| 2467 |
|
| 2468 |
if (PyLong_Check(arg)) |
| 2469 |
{ |
| 2470 |
tmp = PyLong_AsLong(arg); |
| 2471 |
|
| 2472 |
if (tmp > 0 && tmp < 128) |
| 2473 |
{ |
| 2474 |
self->firstvelocity = tmp; |
| 2475 |
if (self->firstvelocity > self->lastvelocity) |
| 2476 |
{ |
| 2477 |
tmp = self->lastvelocity; |
| 2478 |
self->lastvelocity = self->firstvelocity; |
| 2479 |
self->firstvelocity = tmp; |
| 2480 |
} |
| 2481 |
} |
| 2482 |
} |
| 2483 |
|
| 2484 |
Py_RETURN_NONE; |
| 2485 |
} |
| 2486 |
|
| 2487 |
static PyObject * |
| 2488 |
MidiNote_setLastVelocity(MidiNote *self, PyObject *arg) |
| 2489 |
{ |
| 2490 |
int tmp; |
| 2491 |
|
| 2492 |
ASSERT_ARG_NOT_NULL |
| 2493 |
|
| 2494 |
if (PyLong_Check(arg)) |
| 2495 |
{ |
| 2496 |
tmp = PyLong_AsLong(arg); |
| 2497 |
|
| 2498 |
if (tmp > 0 && tmp < 128) |
| 2499 |
{ |
| 2500 |
self->lastvelocity = tmp; |
| 2501 |
if (self->firstvelocity > self->lastvelocity) |
| 2502 |
{ |
| 2503 |
tmp = self->lastvelocity; |
| 2504 |
self->lastvelocity = self->firstvelocity; |
| 2505 |
self->firstvelocity = tmp; |
| 2506 |
} |
| 2507 |
} |
| 2508 |
} |
| 2509 |
|
| 2510 |
Py_RETURN_NONE; |
| 2511 |
} |
| 2512 |
|
| 2513 |
static PyMemberDef MidiNote_members[] = |
| 2514 |
{ |
| 2515 |
{"server", T_OBJECT_EX, offsetof(MidiNote, server), 0, "Pyo server."}, |
| 2516 |
{"stream", T_OBJECT_EX, offsetof(MidiNote, stream), 0, "Stream object."}, |
| 2517 |
{NULL} /* Sentinel */ |
| 2518 |
}; |
| 2519 |
|
| 2520 |
static PyMethodDef MidiNote_methods[] = |
| 2521 |
{ |
| 2522 |
{"getServer", (PyCFunction)MidiNote_getServer, METH_NOARGS, "Returns server object."}, |
| 2523 |
{"_getStream", (PyCFunction)MidiNote_getStream, METH_NOARGS, "Returns stream object."}, |
| 2524 |
{"play", (PyCFunction)MidiNote_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 2525 |
{"stop", (PyCFunction)MidiNote_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 2526 |
{"setScale", (PyCFunction)MidiNote_setScale, METH_O, "Sets the scale factor."}, |
| 2527 |
{"setFirst", (PyCFunction)MidiNote_setFirst, METH_O, "Sets the lowest midi note."}, |
| 2528 |
{"setLast", (PyCFunction)MidiNote_setLast, METH_O, "Sets the highest midi note."}, |
| 2529 |
{"setChannel", (PyCFunction)MidiNote_setChannel, METH_O, "Sets the midi channel."}, |
| 2530 |
{"setCentralKey", (PyCFunction)MidiNote_setCentralKey, METH_O, "Sets the midi key where there is no transposition."}, |
| 2531 |
{"setStealing", (PyCFunction)MidiNote_setStealing, METH_O, "Sets the stealing mode."}, |
| 2532 |
{"setHoldmode", (PyCFunction)MidiNote_setHoldmode, METH_O, "Sets the key hold mode."}, |
| 2533 |
{"setFirstVelocity", (PyCFunction)MidiNote_setFirstVelocity, METH_O, "Sets the lowest midi velocity."}, |
| 2534 |
{"setLastVelocity", (PyCFunction)MidiNote_setLastVelocity, METH_O, "Sets the highest midi velocity."}, |
| 2535 |
{"sendAllNotesOff", (PyCFunction)MidiNote_sendAllNotesOff, METH_NOARGS, "Sends all notes off event."}, |
| 2536 |
{"addMidiEvent", (PyCFunction)MidiNote_addMidiEvent, METH_VARARGS | METH_KEYWORDS, "Add a new midi event in the internal queue."}, |
| 2537 |
{NULL} /* Sentinel */ |
| 2538 |
}; |
| 2539 |
|
| 2540 |
PyTypeObject MidiNoteType = |
| 2541 |
{ |
| 2542 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 2543 |
"_pyo.MidiNote_base", /*tp_name*/ |
| 2544 |
sizeof(MidiNote), /*tp_basicsize*/ |
| 2545 |
0, /*tp_itemsize*/ |
| 2546 |
(destructor)MidiNote_dealloc, /*tp_dealloc*/ |
| 2547 |
0, /*tp_print*/ |
| 2548 |
0, /*tp_getattr*/ |
| 2549 |
0, /*tp_setattr*/ |
| 2550 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 2551 |
0, /*tp_repr*/ |
| 2552 |
0, /*tp_as_number*/ |
| 2553 |
0, /*tp_as_sequence*/ |
| 2554 |
0, /*tp_as_mapping*/ |
| 2555 |
0, /*tp_hash */ |
| 2556 |
0, /*tp_call*/ |
| 2557 |
0, /*tp_str*/ |
| 2558 |
0, /*tp_getattro*/ |
| 2559 |
0, /*tp_setattro*/ |
| 2560 |
0, /*tp_as_buffer*/ |
| 2561 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 2562 |
"MidiNote objects. Retreive midi note from a midi input.", /* tp_doc */ |
| 2563 |
(traverseproc)MidiNote_traverse, /* tp_traverse */ |
| 2564 |
(inquiry)MidiNote_clear, /* tp_clear */ |
| 2565 |
0, /* tp_richcompare */ |
| 2566 |
0, /* tp_weaklistoffset */ |
| 2567 |
0, /* tp_iter */ |
| 2568 |
0, /* tp_iternext */ |
| 2569 |
MidiNote_methods, /* tp_methods */ |
| 2570 |
MidiNote_members, /* tp_members */ |
| 2571 |
0, /* tp_getset */ |
| 2572 |
0, /* tp_base */ |
| 2573 |
0, /* tp_dict */ |
| 2574 |
0, /* tp_descr_get */ |
| 2575 |
0, /* tp_descr_set */ |
| 2576 |
0, /* tp_dictoffset */ |
| 2577 |
0, /* tp_init */ |
| 2578 |
0, /* tp_alloc */ |
| 2579 |
MidiNote_new, /* tp_new */ |
| 2580 |
}; |
| 2581 |
|
| 2582 |
|
| 2583 |
/* Notein streamer */ |
| 2584 |
typedef struct |
| 2585 |
{ |
| 2586 |
pyo_audio_HEAD |
| 2587 |
MidiNote *handler; |
| 2588 |
int modebuffer[2]; |
| 2589 |
int voice; |
| 2590 |
int mode; /* 0 = pitch, 1 = velocity */ |
| 2591 |
MYFLT lastval; |
| 2592 |
MYFLT lastpitch; |
| 2593 |
} Notein; |
| 2594 |
|
| 2595 |
static void Notein_postprocessing_ii(Notein *self) { POST_PROCESSING_II }; |
| 2596 |
static void Notein_postprocessing_ai(Notein *self) { POST_PROCESSING_AI }; |
| 2597 |
static void Notein_postprocessing_ia(Notein *self) { POST_PROCESSING_IA }; |
| 2598 |
static void Notein_postprocessing_aa(Notein *self) { POST_PROCESSING_AA }; |
| 2599 |
static void Notein_postprocessing_ireva(Notein *self) { POST_PROCESSING_IREVA }; |
| 2600 |
static void Notein_postprocessing_areva(Notein *self) { POST_PROCESSING_AREVA }; |
| 2601 |
static void Notein_postprocessing_revai(Notein *self) { POST_PROCESSING_REVAI }; |
| 2602 |
static void Notein_postprocessing_revaa(Notein *self) { POST_PROCESSING_REVAA }; |
| 2603 |
static void Notein_postprocessing_revareva(Notein *self) { POST_PROCESSING_REVAREVA }; |
| 2604 |
|
| 2605 |
static void |
| 2606 |
Notein_setProcMode(Notein *self) |
| 2607 |
{ |
| 2608 |
int muladdmode; |
| 2609 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 2610 |
|
| 2611 |
switch (muladdmode) |
| 2612 |
{ |
| 2613 |
case 0: |
| 2614 |
self->muladd_func_ptr = Notein_postprocessing_ii; |
| 2615 |
break; |
| 2616 |
|
| 2617 |
case 1: |
| 2618 |
self->muladd_func_ptr = Notein_postprocessing_ai; |
| 2619 |
break; |
| 2620 |
|
| 2621 |
case 2: |
| 2622 |
self->muladd_func_ptr = Notein_postprocessing_revai; |
| 2623 |
break; |
| 2624 |
|
| 2625 |
case 10: |
| 2626 |
self->muladd_func_ptr = Notein_postprocessing_ia; |
| 2627 |
break; |
| 2628 |
|
| 2629 |
case 11: |
| 2630 |
self->muladd_func_ptr = Notein_postprocessing_aa; |
| 2631 |
break; |
| 2632 |
|
| 2633 |
case 12: |
| 2634 |
self->muladd_func_ptr = Notein_postprocessing_revaa; |
| 2635 |
break; |
| 2636 |
|
| 2637 |
case 20: |
| 2638 |
self->muladd_func_ptr = Notein_postprocessing_ireva; |
| 2639 |
break; |
| 2640 |
|
| 2641 |
case 21: |
| 2642 |
self->muladd_func_ptr = Notein_postprocessing_areva; |
| 2643 |
break; |
| 2644 |
|
| 2645 |
case 22: |
| 2646 |
self->muladd_func_ptr = Notein_postprocessing_revareva; |
| 2647 |
break; |
| 2648 |
} |
| 2649 |
} |
| 2650 |
|
| 2651 |
static void |
| 2652 |
Notein_compute_next_data_frame(Notein *self) |
| 2653 |
{ |
| 2654 |
int i, posto; |
| 2655 |
MYFLT tmp = MidiNote_getValue(self->handler, self->voice, self->mode, &posto); |
| 2656 |
|
| 2657 |
if (self->lastval == tmp) |
| 2658 |
{ |
| 2659 |
if (self->mode == 0 && tmp != -1) |
| 2660 |
{ |
| 2661 |
for (i = 0; i < self->bufsize; i++) |
| 2662 |
{ |
| 2663 |
self->data[i] = tmp; |
| 2664 |
} |
| 2665 |
} |
| 2666 |
else if (self->mode == 1) |
| 2667 |
{ |
| 2668 |
for (i = 0; i < self->bufsize; i++) |
| 2669 |
{ |
| 2670 |
self->data[i] = tmp; |
| 2671 |
} |
| 2672 |
|
| 2673 |
(*self->muladd_func_ptr)(self); |
| 2674 |
} |
| 2675 |
} |
| 2676 |
else /* There is a new note to compute. */ |
| 2677 |
{ |
| 2678 |
if (self->mode == 0 && tmp != -1) |
| 2679 |
{ |
| 2680 |
for (i = 0; i < self->bufsize; i++) |
| 2681 |
{ |
| 2682 |
if (i < posto) |
| 2683 |
self->data[i] = self->lastpitch; |
| 2684 |
else |
| 2685 |
self->data[i] = tmp; |
| 2686 |
} |
| 2687 |
} |
| 2688 |
else if (self->mode == 1) |
| 2689 |
{ |
| 2690 |
for (i = 0; i < self->bufsize; i++) |
| 2691 |
{ |
| 2692 |
if (i < posto) |
| 2693 |
self->data[i] = self->lastval; |
| 2694 |
else |
| 2695 |
self->data[i] = tmp; |
| 2696 |
} |
| 2697 |
|
| 2698 |
(*self->muladd_func_ptr)(self); |
| 2699 |
} |
| 2700 |
|
| 2701 |
self->lastval = tmp; |
| 2702 |
|
| 2703 |
if (tmp != -1) |
| 2704 |
self->lastpitch = tmp; |
| 2705 |
} |
| 2706 |
} |
| 2707 |
|
| 2708 |
static int |
| 2709 |
Notein_traverse(Notein *self, visitproc visit, void *arg) |
| 2710 |
{ |
| 2711 |
pyo_VISIT |
| 2712 |
Py_VISIT(self->handler); |
| 2713 |
return 0; |
| 2714 |
} |
| 2715 |
|
| 2716 |
static int |
| 2717 |
Notein_clear(Notein *self) |
| 2718 |
{ |
| 2719 |
pyo_CLEAR |
| 2720 |
Py_CLEAR(self->handler); |
| 2721 |
return 0; |
| 2722 |
} |
| 2723 |
|
| 2724 |
static void |
| 2725 |
Notein_dealloc(Notein* self) |
| 2726 |
{ |
| 2727 |
pyo_DEALLOC |
| 2728 |
Notein_clear(self); |
| 2729 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 2730 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 2731 |
} |
| 2732 |
|
| 2733 |
static PyObject * |
| 2734 |
Notein_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 2735 |
{ |
| 2736 |
int i; |
| 2737 |
PyObject *handlertmp = NULL, *multmp = NULL, *addtmp = NULL; |
| 2738 |
Notein *self; |
| 2739 |
self = (Notein *)type->tp_alloc(type, 0); |
| 2740 |
|
| 2741 |
self->voice = 0; |
| 2742 |
self->mode = 0; |
| 2743 |
self->lastval = -1.0; |
| 2744 |
self->lastpitch = 0.0; |
| 2745 |
self->modebuffer[0] = 0; |
| 2746 |
self->modebuffer[1] = 0; |
| 2747 |
|
| 2748 |
INIT_OBJECT_COMMON |
| 2749 |
Stream_setFunctionPtr(self->stream, Notein_compute_next_data_frame); |
| 2750 |
self->mode_func_ptr = Notein_setProcMode; |
| 2751 |
|
| 2752 |
static char *kwlist[] = {"handler", "voice", "mode", "mul", "add", NULL}; |
| 2753 |
|
| 2754 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|iiOO", kwlist, &handlertmp, &self->voice, &self->mode, &multmp, &addtmp)) |
| 2755 |
Py_RETURN_NONE; |
| 2756 |
|
| 2757 |
Py_XDECREF(self->handler); |
| 2758 |
Py_INCREF(handlertmp); |
| 2759 |
self->handler = (MidiNote *)handlertmp; |
| 2760 |
|
| 2761 |
if (multmp) |
| 2762 |
{ |
| 2763 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 2764 |
} |
| 2765 |
|
| 2766 |
if (addtmp) |
| 2767 |
{ |
| 2768 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 2769 |
} |
| 2770 |
|
| 2771 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 2772 |
|
| 2773 |
(*self->mode_func_ptr)(self); |
| 2774 |
|
| 2775 |
return (PyObject *)self; |
| 2776 |
} |
| 2777 |
|
| 2778 |
static PyObject * Notein_getServer(Notein* self) { GET_SERVER }; |
| 2779 |
static PyObject * Notein_getStream(Notein* self) { GET_STREAM }; |
| 2780 |
static PyObject * Notein_setMul(Notein *self, PyObject *arg) { SET_MUL }; |
| 2781 |
static PyObject * Notein_setAdd(Notein *self, PyObject *arg) { SET_ADD }; |
| 2782 |
static PyObject * Notein_setSub(Notein *self, PyObject *arg) { SET_SUB }; |
| 2783 |
static PyObject * Notein_setDiv(Notein *self, PyObject *arg) { SET_DIV }; |
| 2784 |
|
| 2785 |
static PyObject * Notein_play(Notein *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 2786 |
static PyObject * Notein_stop(Notein *self, PyObject *args, PyObject *kwds) { STOP }; |
| 2787 |
|
| 2788 |
static PyObject * Notein_multiply(Notein *self, PyObject *arg) { MULTIPLY }; |
| 2789 |
static PyObject * Notein_inplace_multiply(Notein *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 2790 |
static PyObject * Notein_add(Notein *self, PyObject *arg) { ADD }; |
| 2791 |
static PyObject * Notein_inplace_add(Notein *self, PyObject *arg) { INPLACE_ADD }; |
| 2792 |
static PyObject * Notein_sub(Notein *self, PyObject *arg) { SUB }; |
| 2793 |
static PyObject * Notein_inplace_sub(Notein *self, PyObject *arg) { INPLACE_SUB }; |
| 2794 |
static PyObject * Notein_div(Notein *self, PyObject *arg) { DIV }; |
| 2795 |
static PyObject * Notein_inplace_div(Notein *self, PyObject *arg) { INPLACE_DIV }; |
| 2796 |
|
| 2797 |
static PyMemberDef Notein_members[] = |
| 2798 |
{ |
| 2799 |
{"server", T_OBJECT_EX, offsetof(Notein, server), 0, "Pyo server."}, |
| 2800 |
{"stream", T_OBJECT_EX, offsetof(Notein, stream), 0, "Stream object."}, |
| 2801 |
{"mul", T_OBJECT_EX, offsetof(Notein, mul), 0, "Mul factor."}, |
| 2802 |
{"add", T_OBJECT_EX, offsetof(Notein, add), 0, "Add factor."}, |
| 2803 |
{NULL} /* Sentinel */ |
| 2804 |
}; |
| 2805 |
|
| 2806 |
static PyMethodDef Notein_methods[] = |
| 2807 |
{ |
| 2808 |
{"getServer", (PyCFunction)Notein_getServer, METH_NOARGS, "Returns server object."}, |
| 2809 |
{"_getStream", (PyCFunction)Notein_getStream, METH_NOARGS, "Returns stream object."}, |
| 2810 |
{"play", (PyCFunction)Notein_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 2811 |
{"stop", (PyCFunction)Notein_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 2812 |
{"setMul", (PyCFunction)Notein_setMul, METH_O, "Sets Notein mul factor."}, |
| 2813 |
{"setAdd", (PyCFunction)Notein_setAdd, METH_O, "Sets Notein add factor."}, |
| 2814 |
{"setSub", (PyCFunction)Notein_setSub, METH_O, "Sets inverse add factor."}, |
| 2815 |
{"setDiv", (PyCFunction)Notein_setDiv, METH_O, "Sets inverse mul factor."}, |
| 2816 |
{NULL} /* Sentinel */ |
| 2817 |
}; |
| 2818 |
|
| 2819 |
static PyNumberMethods Notein_as_number = |
| 2820 |
{ |
| 2821 |
(binaryfunc)Notein_add, /*nb_add*/ |
| 2822 |
(binaryfunc)Notein_sub, /*nb_subtract*/ |
| 2823 |
(binaryfunc)Notein_multiply, /*nb_multiply*/ |
| 2824 |
0, /*nb_remainder*/ |
| 2825 |
0, /*nb_divmod*/ |
| 2826 |
0, /*nb_power*/ |
| 2827 |
0, /*nb_neg*/ |
| 2828 |
0, /*nb_pos*/ |
| 2829 |
0, /*(unaryfunc)array_abs,*/ |
| 2830 |
0, /*nb_nonzero*/ |
| 2831 |
0, /*nb_invert*/ |
| 2832 |
0, /*nb_lshift*/ |
| 2833 |
0, /*nb_rshift*/ |
| 2834 |
0, /*nb_and*/ |
| 2835 |
0, /*nb_xor*/ |
| 2836 |
0, /*nb_or*/ |
| 2837 |
0, /*nb_int*/ |
| 2838 |
0, /*nb_long*/ |
| 2839 |
0, /*nb_float*/ |
| 2840 |
(binaryfunc)Notein_inplace_add, /*inplace_add*/ |
| 2841 |
(binaryfunc)Notein_inplace_sub, /*inplace_subtract*/ |
| 2842 |
(binaryfunc)Notein_inplace_multiply, /*inplace_multiply*/ |
| 2843 |
0, /*inplace_remainder*/ |
| 2844 |
0, /*inplace_power*/ |
| 2845 |
0, /*inplace_lshift*/ |
| 2846 |
0, /*inplace_rshift*/ |
| 2847 |
0, /*inplace_and*/ |
| 2848 |
0, /*inplace_xor*/ |
| 2849 |
0, /*inplace_or*/ |
| 2850 |
0, /*nb_floor_divide*/ |
| 2851 |
(binaryfunc)Notein_div, /*nb_true_divide*/ |
| 2852 |
0, /*nb_inplace_floor_divide*/ |
| 2853 |
(binaryfunc)Notein_inplace_div, /*nb_inplace_true_divide*/ |
| 2854 |
0, /* nb_index */ |
| 2855 |
}; |
| 2856 |
|
| 2857 |
PyTypeObject NoteinType = |
| 2858 |
{ |
| 2859 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 2860 |
"_pyo.Notein_base", /*tp_name*/ |
| 2861 |
sizeof(Notein), /*tp_basicsize*/ |
| 2862 |
0, /*tp_itemsize*/ |
| 2863 |
(destructor)Notein_dealloc, /*tp_dealloc*/ |
| 2864 |
0, /*tp_print*/ |
| 2865 |
0, /*tp_getattr*/ |
| 2866 |
0, /*tp_setattr*/ |
| 2867 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 2868 |
0, /*tp_repr*/ |
| 2869 |
&Notein_as_number, /*tp_as_number*/ |
| 2870 |
0, /*tp_as_sequence*/ |
| 2871 |
0, /*tp_as_mapping*/ |
| 2872 |
0, /*tp_hash */ |
| 2873 |
0, /*tp_call*/ |
| 2874 |
0, /*tp_str*/ |
| 2875 |
0, /*tp_getattro*/ |
| 2876 |
0, /*tp_setattro*/ |
| 2877 |
0, /*tp_as_buffer*/ |
| 2878 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 2879 |
"Notein objects. Stream pitch or velocity from a Notein voice.", /* tp_doc */ |
| 2880 |
(traverseproc)Notein_traverse, /* tp_traverse */ |
| 2881 |
(inquiry)Notein_clear, /* tp_clear */ |
| 2882 |
0, /* tp_richcompare */ |
| 2883 |
0, /* tp_weaklistoffset */ |
| 2884 |
0, /* tp_iter */ |
| 2885 |
0, /* tp_iternext */ |
| 2886 |
Notein_methods, /* tp_methods */ |
| 2887 |
Notein_members, /* tp_members */ |
| 2888 |
0, /* tp_getset */ |
| 2889 |
0, /* tp_base */ |
| 2890 |
0, /* tp_dict */ |
| 2891 |
0, /* tp_descr_get */ |
| 2892 |
0, /* tp_descr_set */ |
| 2893 |
0, /* tp_dictoffset */ |
| 2894 |
0, /* tp_init */ |
| 2895 |
0, /* tp_alloc */ |
| 2896 |
Notein_new, /* tp_new */ |
| 2897 |
}; |
| 2898 |
|
| 2899 |
/* NoteinTrig trig streamer */ |
| 2900 |
typedef struct |
| 2901 |
{ |
| 2902 |
pyo_audio_HEAD |
| 2903 |
MidiNote *handler; |
| 2904 |
int modebuffer[2]; |
| 2905 |
int voice; |
| 2906 |
int mode; /* 0 = noteon, 1 = noteoff */ |
| 2907 |
} NoteinTrig; |
| 2908 |
|
| 2909 |
static void NoteinTrig_postprocessing_ii(NoteinTrig *self) { POST_PROCESSING_II }; |
| 2910 |
static void NoteinTrig_postprocessing_ai(NoteinTrig *self) { POST_PROCESSING_AI }; |
| 2911 |
static void NoteinTrig_postprocessing_ia(NoteinTrig *self) { POST_PROCESSING_IA }; |
| 2912 |
static void NoteinTrig_postprocessing_aa(NoteinTrig *self) { POST_PROCESSING_AA }; |
| 2913 |
static void NoteinTrig_postprocessing_ireva(NoteinTrig *self) { POST_PROCESSING_IREVA }; |
| 2914 |
static void NoteinTrig_postprocessing_areva(NoteinTrig *self) { POST_PROCESSING_AREVA }; |
| 2915 |
static void NoteinTrig_postprocessing_revai(NoteinTrig *self) { POST_PROCESSING_REVAI }; |
| 2916 |
static void NoteinTrig_postprocessing_revaa(NoteinTrig *self) { POST_PROCESSING_REVAA }; |
| 2917 |
static void NoteinTrig_postprocessing_revareva(NoteinTrig *self) { POST_PROCESSING_REVAREVA }; |
| 2918 |
|
| 2919 |
static void |
| 2920 |
NoteinTrig_setProcMode(NoteinTrig *self) |
| 2921 |
{ |
| 2922 |
int muladdmode; |
| 2923 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 2924 |
|
| 2925 |
switch (muladdmode) |
| 2926 |
{ |
| 2927 |
case 0: |
| 2928 |
self->muladd_func_ptr = NoteinTrig_postprocessing_ii; |
| 2929 |
break; |
| 2930 |
|
| 2931 |
case 1: |
| 2932 |
self->muladd_func_ptr = NoteinTrig_postprocessing_ai; |
| 2933 |
break; |
| 2934 |
|
| 2935 |
case 2: |
| 2936 |
self->muladd_func_ptr = NoteinTrig_postprocessing_revai; |
| 2937 |
break; |
| 2938 |
|
| 2939 |
case 10: |
| 2940 |
self->muladd_func_ptr = NoteinTrig_postprocessing_ia; |
| 2941 |
break; |
| 2942 |
|
| 2943 |
case 11: |
| 2944 |
self->muladd_func_ptr = NoteinTrig_postprocessing_aa; |
| 2945 |
break; |
| 2946 |
|
| 2947 |
case 12: |
| 2948 |
self->muladd_func_ptr = NoteinTrig_postprocessing_revaa; |
| 2949 |
break; |
| 2950 |
|
| 2951 |
case 20: |
| 2952 |
self->muladd_func_ptr = NoteinTrig_postprocessing_ireva; |
| 2953 |
break; |
| 2954 |
|
| 2955 |
case 21: |
| 2956 |
self->muladd_func_ptr = NoteinTrig_postprocessing_areva; |
| 2957 |
break; |
| 2958 |
|
| 2959 |
case 22: |
| 2960 |
self->muladd_func_ptr = NoteinTrig_postprocessing_revareva; |
| 2961 |
break; |
| 2962 |
} |
| 2963 |
} |
| 2964 |
|
| 2965 |
static void |
| 2966 |
NoteinTrig_compute_next_data_frame(NoteinTrig *self) |
| 2967 |
{ |
| 2968 |
int i; |
| 2969 |
MYFLT *tmp = MidiNote_get_trigger_buffer(self->handler); |
| 2970 |
|
| 2971 |
for (i = 0; i < self->bufsize; i++) |
| 2972 |
{ |
| 2973 |
self->data[i] = tmp[self->bufsize * (self->voice * 2 + self->mode) + i]; |
| 2974 |
} |
| 2975 |
|
| 2976 |
(*self->muladd_func_ptr)(self); |
| 2977 |
} |
| 2978 |
|
| 2979 |
static int |
| 2980 |
NoteinTrig_traverse(NoteinTrig *self, visitproc visit, void *arg) |
| 2981 |
{ |
| 2982 |
pyo_VISIT |
| 2983 |
Py_VISIT(self->handler); |
| 2984 |
return 0; |
| 2985 |
} |
| 2986 |
|
| 2987 |
static int |
| 2988 |
NoteinTrig_clear(NoteinTrig *self) |
| 2989 |
{ |
| 2990 |
pyo_CLEAR |
| 2991 |
Py_CLEAR(self->handler); |
| 2992 |
return 0; |
| 2993 |
} |
| 2994 |
|
| 2995 |
static void |
| 2996 |
NoteinTrig_dealloc(NoteinTrig* self) |
| 2997 |
{ |
| 2998 |
pyo_DEALLOC |
| 2999 |
NoteinTrig_clear(self); |
| 3000 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 3001 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 3002 |
} |
| 3003 |
|
| 3004 |
static PyObject * |
| 3005 |
NoteinTrig_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 3006 |
{ |
| 3007 |
int i; |
| 3008 |
PyObject *handlertmp = NULL, *multmp = NULL, *addtmp = NULL; |
| 3009 |
NoteinTrig *self; |
| 3010 |
self = (NoteinTrig *)type->tp_alloc(type, 0); |
| 3011 |
|
| 3012 |
self->voice = 0; |
| 3013 |
self->mode = 0; |
| 3014 |
self->modebuffer[0] = 0; |
| 3015 |
self->modebuffer[1] = 0; |
| 3016 |
|
| 3017 |
INIT_OBJECT_COMMON |
| 3018 |
Stream_setFunctionPtr(self->stream, NoteinTrig_compute_next_data_frame); |
| 3019 |
self->mode_func_ptr = NoteinTrig_setProcMode; |
| 3020 |
|
| 3021 |
static char *kwlist[] = {"handler", "voice", "mode", "mul", "add", NULL}; |
| 3022 |
|
| 3023 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|iiOO", kwlist, &handlertmp, &self->voice, &self->mode, &multmp, &addtmp)) |
| 3024 |
Py_RETURN_NONE; |
| 3025 |
|
| 3026 |
Py_XDECREF(self->handler); |
| 3027 |
Py_INCREF(handlertmp); |
| 3028 |
self->handler = (MidiNote *)handlertmp; |
| 3029 |
|
| 3030 |
if (multmp) |
| 3031 |
{ |
| 3032 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 3033 |
} |
| 3034 |
|
| 3035 |
if (addtmp) |
| 3036 |
{ |
| 3037 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 3038 |
} |
| 3039 |
|
| 3040 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 3041 |
|
| 3042 |
(*self->mode_func_ptr)(self); |
| 3043 |
|
| 3044 |
return (PyObject *)self; |
| 3045 |
} |
| 3046 |
|
| 3047 |
static PyObject * NoteinTrig_getServer(NoteinTrig* self) { GET_SERVER }; |
| 3048 |
static PyObject * NoteinTrig_getStream(NoteinTrig* self) { GET_STREAM }; |
| 3049 |
static PyObject * NoteinTrig_setMul(NoteinTrig *self, PyObject *arg) { SET_MUL }; |
| 3050 |
static PyObject * NoteinTrig_setAdd(NoteinTrig *self, PyObject *arg) { SET_ADD }; |
| 3051 |
static PyObject * NoteinTrig_setSub(NoteinTrig *self, PyObject *arg) { SET_SUB }; |
| 3052 |
static PyObject * NoteinTrig_setDiv(NoteinTrig *self, PyObject *arg) { SET_DIV }; |
| 3053 |
|
| 3054 |
static PyObject * NoteinTrig_play(NoteinTrig *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 3055 |
static PyObject * NoteinTrig_stop(NoteinTrig *self, PyObject *args, PyObject *kwds) { STOP }; |
| 3056 |
|
| 3057 |
static PyObject * NoteinTrig_multiply(NoteinTrig *self, PyObject *arg) { MULTIPLY }; |
| 3058 |
static PyObject * NoteinTrig_inplace_multiply(NoteinTrig *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 3059 |
static PyObject * NoteinTrig_add(NoteinTrig *self, PyObject *arg) { ADD }; |
| 3060 |
static PyObject * NoteinTrig_inplace_add(NoteinTrig *self, PyObject *arg) { INPLACE_ADD }; |
| 3061 |
static PyObject * NoteinTrig_sub(NoteinTrig *self, PyObject *arg) { SUB }; |
| 3062 |
static PyObject * NoteinTrig_inplace_sub(NoteinTrig *self, PyObject *arg) { INPLACE_SUB }; |
| 3063 |
static PyObject * NoteinTrig_div(NoteinTrig *self, PyObject *arg) { DIV }; |
| 3064 |
static PyObject * NoteinTrig_inplace_div(NoteinTrig *self, PyObject *arg) { INPLACE_DIV }; |
| 3065 |
|
| 3066 |
static PyMemberDef NoteinTrig_members[] = |
| 3067 |
{ |
| 3068 |
{"server", T_OBJECT_EX, offsetof(NoteinTrig, server), 0, "Pyo server."}, |
| 3069 |
{"stream", T_OBJECT_EX, offsetof(NoteinTrig, stream), 0, "Stream object."}, |
| 3070 |
{"mul", T_OBJECT_EX, offsetof(NoteinTrig, mul), 0, "Mul factor."}, |
| 3071 |
{"add", T_OBJECT_EX, offsetof(NoteinTrig, add), 0, "Add factor."}, |
| 3072 |
{NULL} /* Sentinel */ |
| 3073 |
}; |
| 3074 |
|
| 3075 |
static PyMethodDef NoteinTrig_methods[] = |
| 3076 |
{ |
| 3077 |
{"getServer", (PyCFunction)NoteinTrig_getServer, METH_NOARGS, "Returns server object."}, |
| 3078 |
{"_getStream", (PyCFunction)NoteinTrig_getStream, METH_NOARGS, "Returns stream object."}, |
| 3079 |
{"play", (PyCFunction)NoteinTrig_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 3080 |
{"stop", (PyCFunction)NoteinTrig_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 3081 |
{"setMul", (PyCFunction)NoteinTrig_setMul, METH_O, "Sets NoteinTrig mul factor."}, |
| 3082 |
{"setAdd", (PyCFunction)NoteinTrig_setAdd, METH_O, "Sets NoteinTrig add factor."}, |
| 3083 |
{"setSub", (PyCFunction)NoteinTrig_setSub, METH_O, "Sets inverse add factor."}, |
| 3084 |
{"setDiv", (PyCFunction)NoteinTrig_setDiv, METH_O, "Sets inverse mul factor."}, |
| 3085 |
{NULL} /* Sentinel */ |
| 3086 |
}; |
| 3087 |
|
| 3088 |
static PyNumberMethods NoteinTrig_as_number = |
| 3089 |
{ |
| 3090 |
(binaryfunc)NoteinTrig_add, /*nb_add*/ |
| 3091 |
(binaryfunc)NoteinTrig_sub, /*nb_subtract*/ |
| 3092 |
(binaryfunc)NoteinTrig_multiply, /*nb_multiply*/ |
| 3093 |
0, /*nb_remainder*/ |
| 3094 |
0, /*nb_divmod*/ |
| 3095 |
0, /*nb_power*/ |
| 3096 |
0, /*nb_neg*/ |
| 3097 |
0, /*nb_pos*/ |
| 3098 |
0, /*(unaryfunc)array_abs,*/ |
| 3099 |
0, /*nb_nonzero*/ |
| 3100 |
0, /*nb_invert*/ |
| 3101 |
0, /*nb_lshift*/ |
| 3102 |
0, /*nb_rshift*/ |
| 3103 |
0, /*nb_and*/ |
| 3104 |
0, /*nb_xor*/ |
| 3105 |
0, /*nb_or*/ |
| 3106 |
0, /*nb_int*/ |
| 3107 |
0, /*nb_long*/ |
| 3108 |
0, /*nb_float*/ |
| 3109 |
(binaryfunc)NoteinTrig_inplace_add, /*inplace_add*/ |
| 3110 |
(binaryfunc)NoteinTrig_inplace_sub, /*inplace_subtract*/ |
| 3111 |
(binaryfunc)NoteinTrig_inplace_multiply, /*inplace_multiply*/ |
| 3112 |
0, /*inplace_remainder*/ |
| 3113 |
0, /*inplace_power*/ |
| 3114 |
0, /*inplace_lshift*/ |
| 3115 |
0, /*inplace_rshift*/ |
| 3116 |
0, /*inplace_and*/ |
| 3117 |
0, /*inplace_xor*/ |
| 3118 |
0, /*inplace_or*/ |
| 3119 |
0, /*nb_floor_divide*/ |
| 3120 |
(binaryfunc)NoteinTrig_div, /*nb_true_divide*/ |
| 3121 |
0, /*nb_inplace_floor_divide*/ |
| 3122 |
(binaryfunc)NoteinTrig_inplace_div, /*nb_inplace_true_divide*/ |
| 3123 |
0, /* nb_index */ |
| 3124 |
}; |
| 3125 |
|
| 3126 |
PyTypeObject NoteinTrigType = |
| 3127 |
{ |
| 3128 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 3129 |
"_pyo.NoteinTrig_base", /*tp_name*/ |
| 3130 |
sizeof(NoteinTrig), /*tp_basicsize*/ |
| 3131 |
0, /*tp_itemsize*/ |
| 3132 |
(destructor)NoteinTrig_dealloc, /*tp_dealloc*/ |
| 3133 |
0, /*tp_print*/ |
| 3134 |
0, /*tp_getattr*/ |
| 3135 |
0, /*tp_setattr*/ |
| 3136 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 3137 |
0, /*tp_repr*/ |
| 3138 |
&NoteinTrig_as_number, /*tp_as_number*/ |
| 3139 |
0, /*tp_as_sequence*/ |
| 3140 |
0, /*tp_as_mapping*/ |
| 3141 |
0, /*tp_hash */ |
| 3142 |
0, /*tp_call*/ |
| 3143 |
0, /*tp_str*/ |
| 3144 |
0, /*tp_getattro*/ |
| 3145 |
0, /*tp_setattro*/ |
| 3146 |
0, /*tp_as_buffer*/ |
| 3147 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 3148 |
"NoteinTrig objects. Stream noteon or noteoff trigger from a Notein voice.", /* tp_doc */ |
| 3149 |
(traverseproc)NoteinTrig_traverse, /* tp_traverse */ |
| 3150 |
(inquiry)NoteinTrig_clear, /* tp_clear */ |
| 3151 |
0, /* tp_richcompare */ |
| 3152 |
0, /* tp_weaklistoffset */ |
| 3153 |
0, /* tp_iter */ |
| 3154 |
0, /* tp_iternext */ |
| 3155 |
NoteinTrig_methods, /* tp_methods */ |
| 3156 |
NoteinTrig_members, /* tp_members */ |
| 3157 |
0, /* tp_getset */ |
| 3158 |
0, /* tp_base */ |
| 3159 |
0, /* tp_dict */ |
| 3160 |
0, /* tp_descr_get */ |
| 3161 |
0, /* tp_descr_set */ |
| 3162 |
0, /* tp_dictoffset */ |
| 3163 |
0, /* tp_init */ |
| 3164 |
0, /* tp_alloc */ |
| 3165 |
NoteinTrig_new, /* tp_new */ |
| 3166 |
}; |
| 3167 |
|
| 3168 |
typedef struct |
| 3169 |
{ |
| 3170 |
pyo_audio_HEAD |
| 3171 |
PyObject *input; |
| 3172 |
Stream *input_stream; |
| 3173 |
int modebuffer[2]; |
| 3174 |
int fademode; |
| 3175 |
int changed; |
| 3176 |
MYFLT topValue; |
| 3177 |
MYFLT offsetAmp; |
| 3178 |
MYFLT initAmp; |
| 3179 |
MYFLT sustainAmp; |
| 3180 |
MYFLT attack; |
| 3181 |
MYFLT decay; |
| 3182 |
MYFLT sustain; |
| 3183 |
MYFLT release; |
| 3184 |
MYFLT exp; |
| 3185 |
MYFLT expscl; |
| 3186 |
MYFLT invAttack; |
| 3187 |
MYFLT initAmpMinusOffsetAmp; |
| 3188 |
MYFLT attackPlusDecay; |
| 3189 |
MYFLT invDecay; |
| 3190 |
MYFLT initAmpMinusSustainAmp; |
| 3191 |
MYFLT invRelease; |
| 3192 |
double currentTime; |
| 3193 |
MYFLT sampleToSec; |
| 3194 |
MYFLT *buf; |
| 3195 |
} MidiAdsr; |
| 3196 |
|
| 3197 |
static void |
| 3198 |
MidiAdsr_generates(MidiAdsr *self) |
| 3199 |
{ |
| 3200 |
MYFLT val; |
| 3201 |
int i; |
| 3202 |
|
| 3203 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 3204 |
|
| 3205 |
for (i = 0; i < self->bufsize; i++) |
| 3206 |
{ |
| 3207 |
if (self->fademode == 0 && in[i] > 0.0) |
| 3208 |
{ |
| 3209 |
self->fademode = 1; |
| 3210 |
self->initAmp = in[i]; |
| 3211 |
self->expscl = MYPOW(self->initAmp, 1.0 / self->exp) / self->initAmp; |
| 3212 |
self->offsetAmp = self->buf[i]; |
| 3213 |
self->sustainAmp = self->initAmp * self->sustain; |
| 3214 |
self->currentTime = 0.0; |
| 3215 |
self->invAttack = 1.0 / self->attack; |
| 3216 |
self->invDecay = 1.0 / self->decay; |
| 3217 |
self->attackPlusDecay = self->attack + self->decay; |
| 3218 |
self->initAmpMinusOffsetAmp = self->initAmp - self->offsetAmp; |
| 3219 |
self->initAmpMinusSustainAmp = self->initAmp - self->sustainAmp; |
| 3220 |
} |
| 3221 |
else if (self->fademode == 1 && in[i] == 0.0) |
| 3222 |
{ |
| 3223 |
self->fademode = 0; |
| 3224 |
self->currentTime = 0.0; |
| 3225 |
self->invRelease = 1.0 / self->release; |
| 3226 |
} |
| 3227 |
|
| 3228 |
if (self->fademode == 1) |
| 3229 |
{ |
| 3230 |
if (self->currentTime <= self->attack) |
| 3231 |
val = self->currentTime * self->invAttack * self->initAmpMinusOffsetAmp + self->offsetAmp; |
| 3232 |
else if (self->currentTime <= self->attackPlusDecay) |
| 3233 |
val = (self->decay - (self->currentTime - self->attack)) * self->invDecay * self->initAmpMinusSustainAmp + self->sustainAmp; |
| 3234 |
else |
| 3235 |
val = self->sustainAmp; |
| 3236 |
|
| 3237 |
self->topValue = val; |
| 3238 |
} |
| 3239 |
else |
| 3240 |
{ |
| 3241 |
if (self->currentTime <= self->release) |
| 3242 |
val = self->topValue * (1. - self->currentTime * self->invRelease); |
| 3243 |
else |
| 3244 |
val = 0.; |
| 3245 |
} |
| 3246 |
|
| 3247 |
self->buf[i] = val; |
| 3248 |
self->currentTime += self->sampleToSec; |
| 3249 |
} |
| 3250 |
|
| 3251 |
if (self->exp != 1.0) |
| 3252 |
{ |
| 3253 |
for (i = 0; i < self->bufsize; i++) |
| 3254 |
{ |
| 3255 |
self->data[i] = MYPOW(self->buf[i] * self->expscl, self->exp); |
| 3256 |
} |
| 3257 |
} |
| 3258 |
else |
| 3259 |
{ |
| 3260 |
for (i = 0; i < self->bufsize; i++) |
| 3261 |
{ |
| 3262 |
self->data[i] = self->buf[i]; |
| 3263 |
} |
| 3264 |
} |
| 3265 |
} |
| 3266 |
|
| 3267 |
static void MidiAdsr_postprocessing_ii(MidiAdsr *self) { POST_PROCESSING_II }; |
| 3268 |
static void MidiAdsr_postprocessing_ai(MidiAdsr *self) { POST_PROCESSING_AI }; |
| 3269 |
static void MidiAdsr_postprocessing_ia(MidiAdsr *self) { POST_PROCESSING_IA }; |
| 3270 |
static void MidiAdsr_postprocessing_aa(MidiAdsr *self) { POST_PROCESSING_AA }; |
| 3271 |
static void MidiAdsr_postprocessing_ireva(MidiAdsr *self) { POST_PROCESSING_IREVA }; |
| 3272 |
static void MidiAdsr_postprocessing_areva(MidiAdsr *self) { POST_PROCESSING_AREVA }; |
| 3273 |
static void MidiAdsr_postprocessing_revai(MidiAdsr *self) { POST_PROCESSING_REVAI }; |
| 3274 |
static void MidiAdsr_postprocessing_revaa(MidiAdsr *self) { POST_PROCESSING_REVAA }; |
| 3275 |
static void MidiAdsr_postprocessing_revareva(MidiAdsr *self) { POST_PROCESSING_REVAREVA }; |
| 3276 |
|
| 3277 |
static void |
| 3278 |
MidiAdsr_setProcMode(MidiAdsr *self) |
| 3279 |
{ |
| 3280 |
int muladdmode; |
| 3281 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 3282 |
|
| 3283 |
self->proc_func_ptr = MidiAdsr_generates; |
| 3284 |
|
| 3285 |
switch (muladdmode) |
| 3286 |
{ |
| 3287 |
case 0: |
| 3288 |
self->muladd_func_ptr = MidiAdsr_postprocessing_ii; |
| 3289 |
break; |
| 3290 |
|
| 3291 |
case 1: |
| 3292 |
self->muladd_func_ptr = MidiAdsr_postprocessing_ai; |
| 3293 |
break; |
| 3294 |
|
| 3295 |
case 2: |
| 3296 |
self->muladd_func_ptr = MidiAdsr_postprocessing_revai; |
| 3297 |
break; |
| 3298 |
|
| 3299 |
case 10: |
| 3300 |
self->muladd_func_ptr = MidiAdsr_postprocessing_ia; |
| 3301 |
break; |
| 3302 |
|
| 3303 |
case 11: |
| 3304 |
self->muladd_func_ptr = MidiAdsr_postprocessing_aa; |
| 3305 |
break; |
| 3306 |
|
| 3307 |
case 12: |
| 3308 |
self->muladd_func_ptr = MidiAdsr_postprocessing_revaa; |
| 3309 |
break; |
| 3310 |
|
| 3311 |
case 20: |
| 3312 |
self->muladd_func_ptr = MidiAdsr_postprocessing_ireva; |
| 3313 |
break; |
| 3314 |
|
| 3315 |
case 21: |
| 3316 |
self->muladd_func_ptr = MidiAdsr_postprocessing_areva; |
| 3317 |
break; |
| 3318 |
|
| 3319 |
case 22: |
| 3320 |
self->muladd_func_ptr = MidiAdsr_postprocessing_revareva; |
| 3321 |
break; |
| 3322 |
} |
| 3323 |
} |
| 3324 |
|
| 3325 |
static void |
| 3326 |
MidiAdsr_compute_next_data_frame(MidiAdsr *self) |
| 3327 |
{ |
| 3328 |
(*self->proc_func_ptr)(self); |
| 3329 |
(*self->muladd_func_ptr)(self); |
| 3330 |
} |
| 3331 |
|
| 3332 |
static int |
| 3333 |
MidiAdsr_traverse(MidiAdsr *self, visitproc visit, void *arg) |
| 3334 |
{ |
| 3335 |
pyo_VISIT |
| 3336 |
Py_VISIT(self->input); |
| 3337 |
return 0; |
| 3338 |
} |
| 3339 |
|
| 3340 |
static int |
| 3341 |
MidiAdsr_clear(MidiAdsr *self) |
| 3342 |
{ |
| 3343 |
pyo_CLEAR |
| 3344 |
Py_CLEAR(self->input); |
| 3345 |
return 0; |
| 3346 |
} |
| 3347 |
|
| 3348 |
static void |
| 3349 |
MidiAdsr_dealloc(MidiAdsr* self) |
| 3350 |
{ |
| 3351 |
pyo_DEALLOC |
| 3352 |
PyMem_RawFree(self->buf); |
| 3353 |
MidiAdsr_clear(self); |
| 3354 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 3355 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 3356 |
} |
| 3357 |
|
| 3358 |
static PyObject * |
| 3359 |
MidiAdsr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 3360 |
{ |
| 3361 |
int i; |
| 3362 |
PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL; |
| 3363 |
MidiAdsr *self; |
| 3364 |
self = (MidiAdsr *)type->tp_alloc(type, 0); |
| 3365 |
|
| 3366 |
self->modebuffer[0] = 0; |
| 3367 |
self->modebuffer[1] = 0; |
| 3368 |
self->topValue = 0.0; |
| 3369 |
self->fademode = 0; |
| 3370 |
self->changed = 0; |
| 3371 |
self->attack = 0.01; |
| 3372 |
self->decay = 0.05; |
| 3373 |
self->sustain = 0.707; |
| 3374 |
self->release = 0.1; |
| 3375 |
self->currentTime = 0.0; |
| 3376 |
self->exp = self->expscl = 1.0; |
| 3377 |
|
| 3378 |
INIT_OBJECT_COMMON |
| 3379 |
Stream_setFunctionPtr(self->stream, MidiAdsr_compute_next_data_frame); |
| 3380 |
self->mode_func_ptr = MidiAdsr_setProcMode; |
| 3381 |
|
| 3382 |
self->sampleToSec = 1. / self->sr; |
| 3383 |
|
| 3384 |
static char *kwlist[] = {"input", "attack", "decay", "sustain", "release", "mul", "add", NULL}; |
| 3385 |
|
| 3386 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_FFFFOO, kwlist, &inputtmp, &self->attack, &self->decay, &self->sustain, &self->release, &multmp, &addtmp)) |
| 3387 |
Py_RETURN_NONE; |
| 3388 |
|
| 3389 |
INIT_INPUT_STREAM |
| 3390 |
|
| 3391 |
if (multmp) |
| 3392 |
{ |
| 3393 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 3394 |
} |
| 3395 |
|
| 3396 |
if (addtmp) |
| 3397 |
{ |
| 3398 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 3399 |
} |
| 3400 |
|
| 3401 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 3402 |
|
| 3403 |
self->buf = (MYFLT *)PyMem_RawRealloc(self->buf, self->bufsize * sizeof(MYFLT)); |
| 3404 |
|
| 3405 |
for (i = 0; i < self->bufsize; i++) |
| 3406 |
{ |
| 3407 |
self->buf[i] = 0.0; |
| 3408 |
} |
| 3409 |
|
| 3410 |
if (self->attack < 0.000001) |
| 3411 |
self->attack = 0.000001; |
| 3412 |
|
| 3413 |
if (self->decay < 0.000001) |
| 3414 |
self->decay = 0.000001; |
| 3415 |
|
| 3416 |
if (self->release < 0.000001) |
| 3417 |
self->release = 0.000001; |
| 3418 |
|
| 3419 |
if (self->sustain < 0.0) |
| 3420 |
self->sustain = 0.0; |
| 3421 |
else if (self->sustain > 1.0) |
| 3422 |
self->sustain = 1.0; |
| 3423 |
|
| 3424 |
(*self->mode_func_ptr)(self); |
| 3425 |
|
| 3426 |
return (PyObject *)self; |
| 3427 |
} |
| 3428 |
|
| 3429 |
static PyObject * MidiAdsr_getServer(MidiAdsr* self) { GET_SERVER }; |
| 3430 |
static PyObject * MidiAdsr_getStream(MidiAdsr* self) { GET_STREAM }; |
| 3431 |
static PyObject * MidiAdsr_setMul(MidiAdsr *self, PyObject *arg) { SET_MUL }; |
| 3432 |
static PyObject * MidiAdsr_setAdd(MidiAdsr *self, PyObject *arg) { SET_ADD }; |
| 3433 |
static PyObject * MidiAdsr_setSub(MidiAdsr *self, PyObject *arg) { SET_SUB }; |
| 3434 |
static PyObject * MidiAdsr_setDiv(MidiAdsr *self, PyObject *arg) { SET_DIV }; |
| 3435 |
|
| 3436 |
static PyObject * MidiAdsr_play(MidiAdsr *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 3437 |
static PyObject * MidiAdsr_stop(MidiAdsr *self, PyObject *args, PyObject *kwds) { STOP } |
| 3438 |
|
| 3439 |
static PyObject * MidiAdsr_multiply(MidiAdsr *self, PyObject *arg) { MULTIPLY }; |
| 3440 |
static PyObject * MidiAdsr_inplace_multiply(MidiAdsr *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 3441 |
static PyObject * MidiAdsr_add(MidiAdsr *self, PyObject *arg) { ADD }; |
| 3442 |
static PyObject * MidiAdsr_inplace_add(MidiAdsr *self, PyObject *arg) { INPLACE_ADD }; |
| 3443 |
static PyObject * MidiAdsr_sub(MidiAdsr *self, PyObject *arg) { SUB }; |
| 3444 |
static PyObject * MidiAdsr_inplace_sub(MidiAdsr *self, PyObject *arg) { INPLACE_SUB }; |
| 3445 |
static PyObject * MidiAdsr_div(MidiAdsr *self, PyObject *arg) { DIV }; |
| 3446 |
static PyObject * MidiAdsr_inplace_div(MidiAdsr *self, PyObject *arg) { INPLACE_DIV }; |
| 3447 |
|
| 3448 |
static PyObject * |
| 3449 |
MidiAdsr_setAttack(MidiAdsr *self, PyObject *arg) |
| 3450 |
{ |
| 3451 |
if (PyNumber_Check(arg)) |
| 3452 |
{ |
| 3453 |
self->attack = PyFloat_AsDouble(arg); |
| 3454 |
|
| 3455 |
if (self->attack < 0.000001) |
| 3456 |
self->attack = 0.000001; |
| 3457 |
|
| 3458 |
self->invAttack = 1.0 / self->attack; |
| 3459 |
self->attackPlusDecay = self->attack + self->decay; |
| 3460 |
} |
| 3461 |
|
| 3462 |
Py_RETURN_NONE; |
| 3463 |
} |
| 3464 |
|
| 3465 |
static PyObject * |
| 3466 |
MidiAdsr_setDecay(MidiAdsr *self, PyObject *arg) |
| 3467 |
{ |
| 3468 |
if (PyNumber_Check(arg)) |
| 3469 |
{ |
| 3470 |
self->decay = PyFloat_AsDouble(arg); |
| 3471 |
|
| 3472 |
if (self->decay < 0.000001) |
| 3473 |
self->decay = 0.000001; |
| 3474 |
|
| 3475 |
self->invDecay = 1.0 / self->decay; |
| 3476 |
self->attackPlusDecay = self->attack + self->decay; |
| 3477 |
} |
| 3478 |
|
| 3479 |
Py_RETURN_NONE; |
| 3480 |
} |
| 3481 |
|
| 3482 |
static PyObject * |
| 3483 |
MidiAdsr_setSustain(MidiAdsr *self, PyObject *arg) |
| 3484 |
{ |
| 3485 |
if (PyNumber_Check(arg)) |
| 3486 |
{ |
| 3487 |
self->sustain = PyFloat_AsDouble(arg); |
| 3488 |
|
| 3489 |
if (self->sustain < 0.0) |
| 3490 |
self->sustain = 0.0; |
| 3491 |
else if (self->sustain > 1.0) |
| 3492 |
self->sustain = 1.0; |
| 3493 |
} |
| 3494 |
|
| 3495 |
Py_RETURN_NONE; |
| 3496 |
} |
| 3497 |
|
| 3498 |
static PyObject * |
| 3499 |
MidiAdsr_setRelease(MidiAdsr *self, PyObject *arg) |
| 3500 |
{ |
| 3501 |
if (PyNumber_Check(arg)) |
| 3502 |
{ |
| 3503 |
self->release = PyFloat_AsDouble(arg); |
| 3504 |
|
| 3505 |
if (self->release < 0.000001) |
| 3506 |
self->release = 0.000001; |
| 3507 |
|
| 3508 |
self->invRelease = 1.0 / self->release; |
| 3509 |
} |
| 3510 |
|
| 3511 |
Py_RETURN_NONE; |
| 3512 |
} |
| 3513 |
|
| 3514 |
static PyObject * |
| 3515 |
MidiAdsr_setExp(MidiAdsr *self, PyObject *arg) |
| 3516 |
{ |
| 3517 |
if (PyNumber_Check(arg)) |
| 3518 |
{ |
| 3519 |
MYFLT tmp = PyFloat_AsDouble(arg); |
| 3520 |
|
| 3521 |
if (tmp > 0.0) |
| 3522 |
self->exp = tmp; |
| 3523 |
} |
| 3524 |
|
| 3525 |
Py_RETURN_NONE; |
| 3526 |
} |
| 3527 |
|
| 3528 |
static PyMemberDef MidiAdsr_members[] = |
| 3529 |
{ |
| 3530 |
{"server", T_OBJECT_EX, offsetof(MidiAdsr, server), 0, "Pyo server."}, |
| 3531 |
{"stream", T_OBJECT_EX, offsetof(MidiAdsr, stream), 0, "Stream object."}, |
| 3532 |
{"input", T_OBJECT_EX, offsetof(MidiAdsr, input), 0, "Input sound object."}, |
| 3533 |
{"mul", T_OBJECT_EX, offsetof(MidiAdsr, mul), 0, "Mul factor."}, |
| 3534 |
{"add", T_OBJECT_EX, offsetof(MidiAdsr, add), 0, "Add factor."}, |
| 3535 |
{NULL} /* Sentinel */ |
| 3536 |
}; |
| 3537 |
|
| 3538 |
static PyMethodDef MidiAdsr_methods[] = |
| 3539 |
{ |
| 3540 |
{"getServer", (PyCFunction)MidiAdsr_getServer, METH_NOARGS, "Returns server object."}, |
| 3541 |
{"_getStream", (PyCFunction)MidiAdsr_getStream, METH_NOARGS, "Returns stream object."}, |
| 3542 |
{"play", (PyCFunction)MidiAdsr_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 3543 |
{"stop", (PyCFunction)MidiAdsr_stop, METH_VARARGS | METH_KEYWORDS, "Starts fadeout and stops computing."}, |
| 3544 |
{"setMul", (PyCFunction)MidiAdsr_setMul, METH_O, "Sets MidiAdsr mul factor."}, |
| 3545 |
{"setAdd", (PyCFunction)MidiAdsr_setAdd, METH_O, "Sets MidiAdsr add factor."}, |
| 3546 |
{"setSub", (PyCFunction)MidiAdsr_setSub, METH_O, "Sets inverse add factor."}, |
| 3547 |
{"setAttack", (PyCFunction)MidiAdsr_setAttack, METH_O, "Sets attack time in seconds."}, |
| 3548 |
{"setDecay", (PyCFunction)MidiAdsr_setDecay, METH_O, "Sets decay time in seconds."}, |
| 3549 |
{"setSustain", (PyCFunction)MidiAdsr_setSustain, METH_O, "Sets sustain level in percent of note amplitude."}, |
| 3550 |
{"setRelease", (PyCFunction)MidiAdsr_setRelease, METH_O, "Sets release time in seconds."}, |
| 3551 |
{"setExp", (PyCFunction)MidiAdsr_setExp, METH_O, "Sets the exponent factor for exponential envelope."}, |
| 3552 |
{"setDiv", (PyCFunction)MidiAdsr_setDiv, METH_O, "Sets inverse mul factor."}, |
| 3553 |
{NULL} /* Sentinel */ |
| 3554 |
}; |
| 3555 |
|
| 3556 |
static PyNumberMethods MidiAdsr_as_number = |
| 3557 |
{ |
| 3558 |
(binaryfunc)MidiAdsr_add, /*nb_add*/ |
| 3559 |
(binaryfunc)MidiAdsr_sub, /*nb_subtract*/ |
| 3560 |
(binaryfunc)MidiAdsr_multiply, /*nb_multiply*/ |
| 3561 |
0, /*nb_remainder*/ |
| 3562 |
0, /*nb_divmod*/ |
| 3563 |
0, /*nb_power*/ |
| 3564 |
0, /*nb_neg*/ |
| 3565 |
0, /*nb_pos*/ |
| 3566 |
0, /*(unaryfunc)array_abs,*/ |
| 3567 |
0, /*nb_nonzero*/ |
| 3568 |
0, /*nb_invert*/ |
| 3569 |
0, /*nb_lshift*/ |
| 3570 |
0, /*nb_rshift*/ |
| 3571 |
0, /*nb_and*/ |
| 3572 |
0, /*nb_xor*/ |
| 3573 |
0, /*nb_or*/ |
| 3574 |
0, /*nb_int*/ |
| 3575 |
0, /*nb_long*/ |
| 3576 |
0, /*nb_float*/ |
| 3577 |
(binaryfunc)MidiAdsr_inplace_add, /*inplace_add*/ |
| 3578 |
(binaryfunc)MidiAdsr_inplace_sub, /*inplace_subtract*/ |
| 3579 |
(binaryfunc)MidiAdsr_inplace_multiply, /*inplace_multiply*/ |
| 3580 |
0, /*inplace_remainder*/ |
| 3581 |
0, /*inplace_power*/ |
| 3582 |
0, /*inplace_lshift*/ |
| 3583 |
0, /*inplace_rshift*/ |
| 3584 |
0, /*inplace_and*/ |
| 3585 |
0, /*inplace_xor*/ |
| 3586 |
0, /*inplace_or*/ |
| 3587 |
0, /*nb_floor_divide*/ |
| 3588 |
(binaryfunc)MidiAdsr_div, /*nb_true_divide*/ |
| 3589 |
0, /*nb_inplace_floor_divide*/ |
| 3590 |
(binaryfunc)MidiAdsr_inplace_div, /*nb_inplace_true_divide*/ |
| 3591 |
0, /* nb_index */ |
| 3592 |
}; |
| 3593 |
|
| 3594 |
PyTypeObject MidiAdsrType = |
| 3595 |
{ |
| 3596 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 3597 |
"_pyo.MidiAdsr_base", /*tp_name*/ |
| 3598 |
sizeof(MidiAdsr), /*tp_basicsize*/ |
| 3599 |
0, /*tp_itemsize*/ |
| 3600 |
(destructor)MidiAdsr_dealloc, /*tp_dealloc*/ |
| 3601 |
0, /*tp_print*/ |
| 3602 |
0, /*tp_getattr*/ |
| 3603 |
0, /*tp_setattr*/ |
| 3604 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 3605 |
0, /*tp_repr*/ |
| 3606 |
&MidiAdsr_as_number, /*tp_as_number*/ |
| 3607 |
0, /*tp_as_sequence*/ |
| 3608 |
0, /*tp_as_mapping*/ |
| 3609 |
0, /*tp_hash */ |
| 3610 |
0, /*tp_call*/ |
| 3611 |
0, /*tp_str*/ |
| 3612 |
0, /*tp_getattro*/ |
| 3613 |
0, /*tp_setattro*/ |
| 3614 |
0, /*tp_as_buffer*/ |
| 3615 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 3616 |
"MidiAdsr objects. Generates MidiAdsr envelope signal.", /* tp_doc */ |
| 3617 |
(traverseproc)MidiAdsr_traverse, /* tp_traverse */ |
| 3618 |
(inquiry)MidiAdsr_clear, /* tp_clear */ |
| 3619 |
0, /* tp_richcompare */ |
| 3620 |
0, /* tp_weaklistoffset */ |
| 3621 |
0, /* tp_iter */ |
| 3622 |
0, /* tp_iternext */ |
| 3623 |
MidiAdsr_methods, /* tp_methods */ |
| 3624 |
MidiAdsr_members, /* tp_members */ |
| 3625 |
0, /* tp_getset */ |
| 3626 |
0, /* tp_base */ |
| 3627 |
0, /* tp_dict */ |
| 3628 |
0, /* tp_descr_get */ |
| 3629 |
0, /* tp_descr_set */ |
| 3630 |
0, /* tp_dictoffset */ |
| 3631 |
0, /* tp_init */ |
| 3632 |
0, /* tp_alloc */ |
| 3633 |
MidiAdsr_new, /* tp_new */ |
| 3634 |
}; |
| 3635 |
|
| 3636 |
typedef struct |
| 3637 |
{ |
| 3638 |
pyo_audio_HEAD |
| 3639 |
PyObject *input; |
| 3640 |
Stream *input_stream; |
| 3641 |
int modebuffer[2]; |
| 3642 |
int fademode; |
| 3643 |
int changed; |
| 3644 |
MYFLT topValue; |
| 3645 |
MYFLT offsetAmp; |
| 3646 |
MYFLT initAmp; |
| 3647 |
MYFLT sustainAmp; |
| 3648 |
MYFLT delay; |
| 3649 |
MYFLT attack; |
| 3650 |
MYFLT decay; |
| 3651 |
MYFLT sustain; |
| 3652 |
MYFLT release; |
| 3653 |
MYFLT exp; |
| 3654 |
MYFLT expscl; |
| 3655 |
MYFLT invAttack; |
| 3656 |
MYFLT initAmpMinusOffsetAmp; |
| 3657 |
MYFLT invDecay; |
| 3658 |
MYFLT delayPlusAttack; |
| 3659 |
MYFLT delayPlusAttackPlusDecay; |
| 3660 |
MYFLT initAmpMinusSustainAmp; |
| 3661 |
MYFLT invRelease; |
| 3662 |
double currentTime; |
| 3663 |
MYFLT sampleToSec; |
| 3664 |
MYFLT *buf; |
| 3665 |
} MidiDelAdsr; |
| 3666 |
|
| 3667 |
static void |
| 3668 |
MidiDelAdsr_generates(MidiDelAdsr *self) |
| 3669 |
{ |
| 3670 |
MYFLT val; |
| 3671 |
int i; |
| 3672 |
|
| 3673 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 3674 |
|
| 3675 |
for (i = 0; i < self->bufsize; i++) |
| 3676 |
{ |
| 3677 |
if (self->fademode == 0 && in[i] > 0.0) |
| 3678 |
{ |
| 3679 |
self->fademode = 1; |
| 3680 |
self->initAmp = in[i]; |
| 3681 |
self->expscl = MYPOW(self->initAmp, 1.0 / self->exp) / self->initAmp; |
| 3682 |
self->offsetAmp = self->buf[i]; |
| 3683 |
self->sustainAmp = self->initAmp * self->sustain; |
| 3684 |
self->currentTime = 0.0; |
| 3685 |
self->invAttack = 1.0 / self->attack; |
| 3686 |
self->invDecay = 1.0 / self->decay; |
| 3687 |
self->delayPlusAttack = self->delay + self->attack; |
| 3688 |
self->delayPlusAttackPlusDecay = self->delay + self->attack + self->decay; |
| 3689 |
self->initAmpMinusOffsetAmp = self->initAmp - self->offsetAmp; |
| 3690 |
self->initAmpMinusSustainAmp = self->initAmp - self->sustainAmp; |
| 3691 |
} |
| 3692 |
else if (self->fademode == 1 && in[i] == 0.0) |
| 3693 |
{ |
| 3694 |
self->fademode = 0; |
| 3695 |
self->currentTime = 0.0; |
| 3696 |
self->invRelease = 1.0 / self->release; |
| 3697 |
} |
| 3698 |
|
| 3699 |
if (self->fademode == 1) |
| 3700 |
{ |
| 3701 |
if (self->currentTime < self->delay) |
| 3702 |
val = 0.0; |
| 3703 |
else if (self->currentTime <= self->delayPlusAttack) |
| 3704 |
val = (self->currentTime - self->delay) * self->invAttack * self->initAmpMinusOffsetAmp + self->offsetAmp; |
| 3705 |
else if (self->currentTime <= self->delayPlusAttackPlusDecay) |
| 3706 |
val = (self->decay - (self->currentTime - self->delay - self->attack)) * self->invDecay * self->initAmpMinusSustainAmp + self->sustainAmp; |
| 3707 |
else |
| 3708 |
val = self->sustainAmp; |
| 3709 |
|
| 3710 |
self->topValue = val; |
| 3711 |
} |
| 3712 |
else |
| 3713 |
{ |
| 3714 |
if (self->currentTime <= self->release) |
| 3715 |
val = self->topValue * (1. - self->currentTime * self->invRelease); |
| 3716 |
else |
| 3717 |
val = 0.; |
| 3718 |
} |
| 3719 |
|
| 3720 |
self->buf[i] = val; |
| 3721 |
self->currentTime += self->sampleToSec; |
| 3722 |
} |
| 3723 |
|
| 3724 |
if (self->exp != 1.0) |
| 3725 |
{ |
| 3726 |
for (i = 0; i < self->bufsize; i++) |
| 3727 |
{ |
| 3728 |
self->data[i] = MYPOW(self->buf[i] * self->expscl, self->exp); |
| 3729 |
} |
| 3730 |
} |
| 3731 |
else |
| 3732 |
{ |
| 3733 |
for (i = 0; i < self->bufsize; i++) |
| 3734 |
{ |
| 3735 |
self->data[i] = self->buf[i]; |
| 3736 |
} |
| 3737 |
} |
| 3738 |
} |
| 3739 |
|
| 3740 |
static void MidiDelAdsr_postprocessing_ii(MidiDelAdsr *self) { POST_PROCESSING_II }; |
| 3741 |
static void MidiDelAdsr_postprocessing_ai(MidiDelAdsr *self) { POST_PROCESSING_AI }; |
| 3742 |
static void MidiDelAdsr_postprocessing_ia(MidiDelAdsr *self) { POST_PROCESSING_IA }; |
| 3743 |
static void MidiDelAdsr_postprocessing_aa(MidiDelAdsr *self) { POST_PROCESSING_AA }; |
| 3744 |
static void MidiDelAdsr_postprocessing_ireva(MidiDelAdsr *self) { POST_PROCESSING_IREVA }; |
| 3745 |
static void MidiDelAdsr_postprocessing_areva(MidiDelAdsr *self) { POST_PROCESSING_AREVA }; |
| 3746 |
static void MidiDelAdsr_postprocessing_revai(MidiDelAdsr *self) { POST_PROCESSING_REVAI }; |
| 3747 |
static void MidiDelAdsr_postprocessing_revaa(MidiDelAdsr *self) { POST_PROCESSING_REVAA }; |
| 3748 |
static void MidiDelAdsr_postprocessing_revareva(MidiDelAdsr *self) { POST_PROCESSING_REVAREVA }; |
| 3749 |
|
| 3750 |
static void |
| 3751 |
MidiDelAdsr_setProcMode(MidiDelAdsr *self) |
| 3752 |
{ |
| 3753 |
int muladdmode; |
| 3754 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 3755 |
|
| 3756 |
self->proc_func_ptr = MidiDelAdsr_generates; |
| 3757 |
|
| 3758 |
switch (muladdmode) |
| 3759 |
{ |
| 3760 |
case 0: |
| 3761 |
self->muladd_func_ptr = MidiDelAdsr_postprocessing_ii; |
| 3762 |
break; |
| 3763 |
|
| 3764 |
case 1: |
| 3765 |
self->muladd_func_ptr = MidiDelAdsr_postprocessing_ai; |
| 3766 |
break; |
| 3767 |
|
| 3768 |
case 2: |
| 3769 |
self->muladd_func_ptr = MidiDelAdsr_postprocessing_revai; |
| 3770 |
break; |
| 3771 |
|
| 3772 |
case 10: |
| 3773 |
self->muladd_func_ptr = MidiDelAdsr_postprocessing_ia; |
| 3774 |
break; |
| 3775 |
|
| 3776 |
case 11: |
| 3777 |
self->muladd_func_ptr = MidiDelAdsr_postprocessing_aa; |
| 3778 |
break; |
| 3779 |
|
| 3780 |
case 12: |
| 3781 |
self->muladd_func_ptr = MidiDelAdsr_postprocessing_revaa; |
| 3782 |
break; |
| 3783 |
|
| 3784 |
case 20: |
| 3785 |
self->muladd_func_ptr = MidiDelAdsr_postprocessing_ireva; |
| 3786 |
break; |
| 3787 |
|
| 3788 |
case 21: |
| 3789 |
self->muladd_func_ptr = MidiDelAdsr_postprocessing_areva; |
| 3790 |
break; |
| 3791 |
|
| 3792 |
case 22: |
| 3793 |
self->muladd_func_ptr = MidiDelAdsr_postprocessing_revareva; |
| 3794 |
break; |
| 3795 |
} |
| 3796 |
} |
| 3797 |
|
| 3798 |
static void |
| 3799 |
MidiDelAdsr_compute_next_data_frame(MidiDelAdsr *self) |
| 3800 |
{ |
| 3801 |
(*self->proc_func_ptr)(self); |
| 3802 |
(*self->muladd_func_ptr)(self); |
| 3803 |
} |
| 3804 |
|
| 3805 |
static int |
| 3806 |
MidiDelAdsr_traverse(MidiDelAdsr *self, visitproc visit, void *arg) |
| 3807 |
{ |
| 3808 |
pyo_VISIT |
| 3809 |
Py_VISIT(self->input); |
| 3810 |
return 0; |
| 3811 |
} |
| 3812 |
|
| 3813 |
static int |
| 3814 |
MidiDelAdsr_clear(MidiDelAdsr *self) |
| 3815 |
{ |
| 3816 |
pyo_CLEAR |
| 3817 |
Py_CLEAR(self->input); |
| 3818 |
return 0; |
| 3819 |
} |
| 3820 |
|
| 3821 |
static void |
| 3822 |
MidiDelAdsr_dealloc(MidiDelAdsr* self) |
| 3823 |
{ |
| 3824 |
pyo_DEALLOC |
| 3825 |
PyMem_RawFree(self->buf); |
| 3826 |
MidiDelAdsr_clear(self); |
| 3827 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 3828 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 3829 |
} |
| 3830 |
|
| 3831 |
static PyObject * |
| 3832 |
MidiDelAdsr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 3833 |
{ |
| 3834 |
int i; |
| 3835 |
PyObject *inputtmp, *input_streamtmp, *multmp = NULL, *addtmp = NULL; |
| 3836 |
MidiDelAdsr *self; |
| 3837 |
self = (MidiDelAdsr *)type->tp_alloc(type, 0); |
| 3838 |
|
| 3839 |
self->modebuffer[0] = 0; |
| 3840 |
self->modebuffer[1] = 0; |
| 3841 |
self->topValue = 0.0; |
| 3842 |
self->fademode = 0; |
| 3843 |
self->changed = 0; |
| 3844 |
self->delay = 0.; |
| 3845 |
self->attack = 0.01; |
| 3846 |
self->decay = 0.05; |
| 3847 |
self->sustain = 0.707; |
| 3848 |
self->release = 0.1; |
| 3849 |
self->currentTime = 0.0; |
| 3850 |
self->exp = self->expscl = 1.0; |
| 3851 |
|
| 3852 |
INIT_OBJECT_COMMON |
| 3853 |
Stream_setFunctionPtr(self->stream, MidiDelAdsr_compute_next_data_frame); |
| 3854 |
self->mode_func_ptr = MidiDelAdsr_setProcMode; |
| 3855 |
|
| 3856 |
self->sampleToSec = 1. / self->sr; |
| 3857 |
|
| 3858 |
static char *kwlist[] = {"input", "delay", "attack", "decay", "sustain", "release", "mul", "add", NULL}; |
| 3859 |
|
| 3860 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE_O_FFFFFOO, kwlist, &inputtmp, &self->delay, &self->attack, &self->decay, &self->sustain, &self->release, &multmp, &addtmp)) |
| 3861 |
Py_RETURN_NONE; |
| 3862 |
|
| 3863 |
INIT_INPUT_STREAM |
| 3864 |
|
| 3865 |
if (multmp) |
| 3866 |
{ |
| 3867 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 3868 |
} |
| 3869 |
|
| 3870 |
if (addtmp) |
| 3871 |
{ |
| 3872 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 3873 |
} |
| 3874 |
|
| 3875 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 3876 |
|
| 3877 |
self->buf = (MYFLT *)PyMem_RawRealloc(self->buf, self->bufsize * sizeof(MYFLT)); |
| 3878 |
|
| 3879 |
for (i = 0; i < self->bufsize; i++) |
| 3880 |
{ |
| 3881 |
self->buf[i] = 0.0; |
| 3882 |
} |
| 3883 |
|
| 3884 |
if (self->attack < 0.000001) |
| 3885 |
self->attack = 0.000001; |
| 3886 |
|
| 3887 |
if (self->decay < 0.000001) |
| 3888 |
self->decay = 0.000001; |
| 3889 |
|
| 3890 |
if (self->release < 0.000001) |
| 3891 |
self->release = 0.000001; |
| 3892 |
|
| 3893 |
if (self->sustain < 0.0) |
| 3894 |
self->sustain = 0.0; |
| 3895 |
else if (self->sustain > 1.0) |
| 3896 |
self->sustain = 1.0; |
| 3897 |
|
| 3898 |
(*self->mode_func_ptr)(self); |
| 3899 |
|
| 3900 |
return (PyObject *)self; |
| 3901 |
} |
| 3902 |
|
| 3903 |
static PyObject * MidiDelAdsr_getServer(MidiDelAdsr* self) { GET_SERVER }; |
| 3904 |
static PyObject * MidiDelAdsr_getStream(MidiDelAdsr* self) { GET_STREAM }; |
| 3905 |
static PyObject * MidiDelAdsr_setMul(MidiDelAdsr *self, PyObject *arg) { SET_MUL }; |
| 3906 |
static PyObject * MidiDelAdsr_setAdd(MidiDelAdsr *self, PyObject *arg) { SET_ADD }; |
| 3907 |
static PyObject * MidiDelAdsr_setSub(MidiDelAdsr *self, PyObject *arg) { SET_SUB }; |
| 3908 |
static PyObject * MidiDelAdsr_setDiv(MidiDelAdsr *self, PyObject *arg) { SET_DIV }; |
| 3909 |
|
| 3910 |
static PyObject * MidiDelAdsr_play(MidiDelAdsr *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 3911 |
static PyObject * MidiDelAdsr_stop(MidiDelAdsr *self, PyObject *args, PyObject *kwds) { STOP } |
| 3912 |
|
| 3913 |
static PyObject * MidiDelAdsr_multiply(MidiDelAdsr *self, PyObject *arg) { MULTIPLY }; |
| 3914 |
static PyObject * MidiDelAdsr_inplace_multiply(MidiDelAdsr *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 3915 |
static PyObject * MidiDelAdsr_add(MidiDelAdsr *self, PyObject *arg) { ADD }; |
| 3916 |
static PyObject * MidiDelAdsr_inplace_add(MidiDelAdsr *self, PyObject *arg) { INPLACE_ADD }; |
| 3917 |
static PyObject * MidiDelAdsr_sub(MidiDelAdsr *self, PyObject *arg) { SUB }; |
| 3918 |
static PyObject * MidiDelAdsr_inplace_sub(MidiDelAdsr *self, PyObject *arg) { INPLACE_SUB }; |
| 3919 |
static PyObject * MidiDelAdsr_div(MidiDelAdsr *self, PyObject *arg) { DIV }; |
| 3920 |
static PyObject * MidiDelAdsr_inplace_div(MidiDelAdsr *self, PyObject *arg) { INPLACE_DIV }; |
| 3921 |
|
| 3922 |
static PyObject * |
| 3923 |
MidiDelAdsr_setDelay(MidiDelAdsr *self, PyObject *arg) |
| 3924 |
{ |
| 3925 |
if (PyNumber_Check(arg)) |
| 3926 |
{ |
| 3927 |
self->delay = PyFloat_AsDouble(arg); |
| 3928 |
self->delayPlusAttack = self->delay + self->attack; |
| 3929 |
self->delayPlusAttackPlusDecay = self->delay + self->attack + self->decay; |
| 3930 |
} |
| 3931 |
|
| 3932 |
Py_RETURN_NONE; |
| 3933 |
} |
| 3934 |
|
| 3935 |
static PyObject * |
| 3936 |
MidiDelAdsr_setAttack(MidiDelAdsr *self, PyObject *arg) |
| 3937 |
{ |
| 3938 |
if (PyNumber_Check(arg)) |
| 3939 |
{ |
| 3940 |
self->attack = PyFloat_AsDouble(arg); |
| 3941 |
|
| 3942 |
if (self->attack < 0.000001) |
| 3943 |
self->attack = 0.000001; |
| 3944 |
|
| 3945 |
self->invAttack = 1.0 / self->attack; |
| 3946 |
self->delayPlusAttack = self->delay + self->attack; |
| 3947 |
self->delayPlusAttackPlusDecay = self->delay + self->attack + self->decay; |
| 3948 |
} |
| 3949 |
|
| 3950 |
Py_RETURN_NONE; |
| 3951 |
} |
| 3952 |
|
| 3953 |
static PyObject * |
| 3954 |
MidiDelAdsr_setDecay(MidiDelAdsr *self, PyObject *arg) |
| 3955 |
{ |
| 3956 |
if (PyNumber_Check(arg)) |
| 3957 |
{ |
| 3958 |
self->decay = PyFloat_AsDouble(arg); |
| 3959 |
|
| 3960 |
if (self->decay < 0.000001) |
| 3961 |
self->decay = 0.000001; |
| 3962 |
|
| 3963 |
self->invDecay = 1.0 / self->decay; |
| 3964 |
self->delayPlusAttackPlusDecay = self->delay + self->attack + self->decay; |
| 3965 |
} |
| 3966 |
|
| 3967 |
Py_RETURN_NONE; |
| 3968 |
} |
| 3969 |
|
| 3970 |
static PyObject * |
| 3971 |
MidiDelAdsr_setSustain(MidiDelAdsr *self, PyObject *arg) |
| 3972 |
{ |
| 3973 |
if (PyNumber_Check(arg)) |
| 3974 |
{ |
| 3975 |
self->sustain = PyFloat_AsDouble(arg); |
| 3976 |
|
| 3977 |
if (self->sustain < 0.0) |
| 3978 |
self->sustain = 0.0; |
| 3979 |
else if (self->sustain > 1.0) |
| 3980 |
self->sustain = 1.0; |
| 3981 |
} |
| 3982 |
|
| 3983 |
Py_RETURN_NONE; |
| 3984 |
} |
| 3985 |
|
| 3986 |
static PyObject * |
| 3987 |
MidiDelAdsr_setRelease(MidiDelAdsr *self, PyObject *arg) |
| 3988 |
{ |
| 3989 |
if (PyNumber_Check(arg)) |
| 3990 |
{ |
| 3991 |
self->release = PyFloat_AsDouble(arg); |
| 3992 |
|
| 3993 |
if (self->release < 0.000001) |
| 3994 |
self->release = 0.000001; |
| 3995 |
|
| 3996 |
self->invRelease = 1.0 / self->release; |
| 3997 |
} |
| 3998 |
|
| 3999 |
Py_RETURN_NONE; |
| 4000 |
} |
| 4001 |
|
| 4002 |
static PyObject * |
| 4003 |
MidiDelAdsr_setExp(MidiDelAdsr *self, PyObject *arg) |
| 4004 |
{ |
| 4005 |
if (PyNumber_Check(arg)) |
| 4006 |
{ |
| 4007 |
MYFLT tmp = PyFloat_AsDouble(arg); |
| 4008 |
|
| 4009 |
if (tmp > 0.0) |
| 4010 |
self->exp = tmp; |
| 4011 |
} |
| 4012 |
|
| 4013 |
Py_RETURN_NONE; |
| 4014 |
} |
| 4015 |
|
| 4016 |
static PyMemberDef MidiDelAdsr_members[] = |
| 4017 |
{ |
| 4018 |
{"server", T_OBJECT_EX, offsetof(MidiDelAdsr, server), 0, "Pyo server."}, |
| 4019 |
{"stream", T_OBJECT_EX, offsetof(MidiDelAdsr, stream), 0, "Stream object."}, |
| 4020 |
{"input", T_OBJECT_EX, offsetof(MidiDelAdsr, input), 0, "Input sound object."}, |
| 4021 |
{"mul", T_OBJECT_EX, offsetof(MidiDelAdsr, mul), 0, "Mul factor."}, |
| 4022 |
{"add", T_OBJECT_EX, offsetof(MidiDelAdsr, add), 0, "Add factor."}, |
| 4023 |
{NULL} /* Sentinel */ |
| 4024 |
}; |
| 4025 |
|
| 4026 |
static PyMethodDef MidiDelAdsr_methods[] = |
| 4027 |
{ |
| 4028 |
{"getServer", (PyCFunction)MidiDelAdsr_getServer, METH_NOARGS, "Returns server object."}, |
| 4029 |
{"_getStream", (PyCFunction)MidiDelAdsr_getStream, METH_NOARGS, "Returns stream object."}, |
| 4030 |
{"play", (PyCFunction)MidiDelAdsr_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 4031 |
{"stop", (PyCFunction)MidiDelAdsr_stop, METH_VARARGS | METH_KEYWORDS, "Starts fadeout and stops computing."}, |
| 4032 |
{"setMul", (PyCFunction)MidiDelAdsr_setMul, METH_O, "Sets MidiDelAdsr mul factor."}, |
| 4033 |
{"setAdd", (PyCFunction)MidiDelAdsr_setAdd, METH_O, "Sets MidiDelAdsr add factor."}, |
| 4034 |
{"setSub", (PyCFunction)MidiDelAdsr_setSub, METH_O, "Sets inverse add factor."}, |
| 4035 |
{"setDelay", (PyCFunction)MidiDelAdsr_setDelay, METH_O, "Sets delay time in seconds."}, |
| 4036 |
{"setAttack", (PyCFunction)MidiDelAdsr_setAttack, METH_O, "Sets attack time in seconds."}, |
| 4037 |
{"setDecay", (PyCFunction)MidiDelAdsr_setDecay, METH_O, "Sets decay time in seconds."}, |
| 4038 |
{"setSustain", (PyCFunction)MidiDelAdsr_setSustain, METH_O, "Sets sustain level in percent of note amplitude."}, |
| 4039 |
{"setRelease", (PyCFunction)MidiDelAdsr_setRelease, METH_O, "Sets release time in seconds."}, |
| 4040 |
{"setExp", (PyCFunction)MidiDelAdsr_setExp, METH_O, "Sets the exponent factor for exponential envelope."}, |
| 4041 |
{"setDiv", (PyCFunction)MidiDelAdsr_setDiv, METH_O, "Sets inverse mul factor."}, |
| 4042 |
{NULL} /* Sentinel */ |
| 4043 |
}; |
| 4044 |
|
| 4045 |
static PyNumberMethods MidiDelAdsr_as_number = |
| 4046 |
{ |
| 4047 |
(binaryfunc)MidiDelAdsr_add, /*nb_add*/ |
| 4048 |
(binaryfunc)MidiDelAdsr_sub, /*nb_subtract*/ |
| 4049 |
(binaryfunc)MidiDelAdsr_multiply, /*nb_multiply*/ |
| 4050 |
0, /*nb_remainder*/ |
| 4051 |
0, /*nb_divmod*/ |
| 4052 |
0, /*nb_power*/ |
| 4053 |
0, /*nb_neg*/ |
| 4054 |
0, /*nb_pos*/ |
| 4055 |
0, /*(unaryfunc)array_abs,*/ |
| 4056 |
0, /*nb_nonzero*/ |
| 4057 |
0, /*nb_invert*/ |
| 4058 |
0, /*nb_lshift*/ |
| 4059 |
0, /*nb_rshift*/ |
| 4060 |
0, /*nb_and*/ |
| 4061 |
0, /*nb_xor*/ |
| 4062 |
0, /*nb_or*/ |
| 4063 |
0, /*nb_int*/ |
| 4064 |
0, /*nb_long*/ |
| 4065 |
0, /*nb_float*/ |
| 4066 |
(binaryfunc)MidiDelAdsr_inplace_add, /*inplace_add*/ |
| 4067 |
(binaryfunc)MidiDelAdsr_inplace_sub, /*inplace_subtract*/ |
| 4068 |
(binaryfunc)MidiDelAdsr_inplace_multiply, /*inplace_multiply*/ |
| 4069 |
0, /*inplace_remainder*/ |
| 4070 |
0, /*inplace_power*/ |
| 4071 |
0, /*inplace_lshift*/ |
| 4072 |
0, /*inplace_rshift*/ |
| 4073 |
0, /*inplace_and*/ |
| 4074 |
0, /*inplace_xor*/ |
| 4075 |
0, /*inplace_or*/ |
| 4076 |
0, /*nb_floor_divide*/ |
| 4077 |
(binaryfunc)MidiDelAdsr_div, /*nb_true_divide*/ |
| 4078 |
0, /*nb_inplace_floor_divide*/ |
| 4079 |
(binaryfunc)MidiDelAdsr_inplace_div, /*nb_inplace_true_divide*/ |
| 4080 |
0, /* nb_index */ |
| 4081 |
}; |
| 4082 |
|
| 4083 |
PyTypeObject MidiDelAdsrType = |
| 4084 |
{ |
| 4085 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 4086 |
"_pyo.MidiDelAdsr_base", /*tp_name*/ |
| 4087 |
sizeof(MidiDelAdsr), /*tp_basicsize*/ |
| 4088 |
0, /*tp_itemsize*/ |
| 4089 |
(destructor)MidiDelAdsr_dealloc, /*tp_dealloc*/ |
| 4090 |
0, /*tp_print*/ |
| 4091 |
0, /*tp_getattr*/ |
| 4092 |
0, /*tp_setattr*/ |
| 4093 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 4094 |
0, /*tp_repr*/ |
| 4095 |
&MidiDelAdsr_as_number, /*tp_as_number*/ |
| 4096 |
0, /*tp_as_sequence*/ |
| 4097 |
0, /*tp_as_mapping*/ |
| 4098 |
0, /*tp_hash */ |
| 4099 |
0, /*tp_call*/ |
| 4100 |
0, /*tp_str*/ |
| 4101 |
0, /*tp_getattro*/ |
| 4102 |
0, /*tp_setattro*/ |
| 4103 |
0, /*tp_as_buffer*/ |
| 4104 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 4105 |
"MidiDelAdsr objects. Generates MidiDelAdsr envelope signal.", /* tp_doc */ |
| 4106 |
(traverseproc)MidiDelAdsr_traverse, /* tp_traverse */ |
| 4107 |
(inquiry)MidiDelAdsr_clear, /* tp_clear */ |
| 4108 |
0, /* tp_richcompare */ |
| 4109 |
0, /* tp_weaklistoffset */ |
| 4110 |
0, /* tp_iter */ |
| 4111 |
0, /* tp_iternext */ |
| 4112 |
MidiDelAdsr_methods, /* tp_methods */ |
| 4113 |
MidiDelAdsr_members, /* tp_members */ |
| 4114 |
0, /* tp_getset */ |
| 4115 |
0, /* tp_base */ |
| 4116 |
0, /* tp_dict */ |
| 4117 |
0, /* tp_descr_get */ |
| 4118 |
0, /* tp_descr_set */ |
| 4119 |
0, /* tp_dictoffset */ |
| 4120 |
0, /* tp_init */ |
| 4121 |
0, /* tp_alloc */ |
| 4122 |
MidiDelAdsr_new, /* tp_new */ |
| 4123 |
}; |
| 4124 |
|
| 4125 |
typedef struct |
| 4126 |
{ |
| 4127 |
pyo_audio_HEAD |
| 4128 |
PyObject *callable; |
| 4129 |
} RawMidi; |
| 4130 |
|
| 4131 |
static void |
| 4132 |
RawMidi_setProcMode(RawMidi *self) {} |
| 4133 |
|
| 4134 |
static void |
| 4135 |
RawMidi_compute_next_data_frame(RawMidi *self) |
| 4136 |
{ |
| 4137 |
PyoMidiEvent *buffer; |
| 4138 |
int i, count, status, data1, data2; |
| 4139 |
|
| 4140 |
buffer = Server_getMidiEventBuffer((Server *)self->server); |
| 4141 |
count = Server_getMidiEventCount((Server *)self->server); |
| 4142 |
|
| 4143 |
if (count > 0) |
| 4144 |
{ |
| 4145 |
PyObject *tup; |
| 4146 |
|
| 4147 |
for (i = 0; i < count; i++) |
| 4148 |
{ |
| 4149 |
status = PyoMidi_MessageStatus(buffer[i].message); // Temp note event holders |
| 4150 |
data1 = PyoMidi_MessageData1(buffer[i].message); |
| 4151 |
data2 = PyoMidi_MessageData2(buffer[i].message); |
| 4152 |
tup = PyTuple_New(3); |
| 4153 |
PyTuple_SetItem(tup, 0, PyLong_FromLong(status)); |
| 4154 |
PyTuple_SetItem(tup, 1, PyLong_FromLong(data1)); |
| 4155 |
PyTuple_SetItem(tup, 2, PyLong_FromLong(data2)); |
| 4156 |
PyObject_Call((PyObject *)self->callable, tup, NULL); |
| 4157 |
} |
| 4158 |
} |
| 4159 |
} |
| 4160 |
|
| 4161 |
static int |
| 4162 |
RawMidi_traverse(RawMidi *self, visitproc visit, void *arg) |
| 4163 |
{ |
| 4164 |
pyo_VISIT |
| 4165 |
Py_VISIT(self->callable); |
| 4166 |
return 0; |
| 4167 |
} |
| 4168 |
|
| 4169 |
static int |
| 4170 |
RawMidi_clear(RawMidi *self) |
| 4171 |
{ |
| 4172 |
pyo_CLEAR |
| 4173 |
Py_CLEAR(self->callable); |
| 4174 |
return 0; |
| 4175 |
} |
| 4176 |
|
| 4177 |
static void |
| 4178 |
RawMidi_dealloc(RawMidi* self) |
| 4179 |
{ |
| 4180 |
pyo_DEALLOC |
| 4181 |
RawMidi_clear(self); |
| 4182 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 4183 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 4184 |
} |
| 4185 |
|
| 4186 |
static PyObject * |
| 4187 |
RawMidi_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 4188 |
{ |
| 4189 |
int i; |
| 4190 |
PyObject *calltmp = NULL; |
| 4191 |
RawMidi *self; |
| 4192 |
self = (RawMidi *)type->tp_alloc(type, 0); |
| 4193 |
|
| 4194 |
INIT_OBJECT_COMMON |
| 4195 |
Stream_setFunctionPtr(self->stream, RawMidi_compute_next_data_frame); |
| 4196 |
self->mode_func_ptr = RawMidi_setProcMode; |
| 4197 |
|
| 4198 |
static char *kwlist[] = {"callable", NULL}; |
| 4199 |
|
| 4200 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &calltmp)) |
| 4201 |
Py_RETURN_NONE; |
| 4202 |
|
| 4203 |
if (calltmp) |
| 4204 |
{ |
| 4205 |
PyObject_CallMethod((PyObject *)self, "setFunction", "O", calltmp); |
| 4206 |
} |
| 4207 |
|
| 4208 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 4209 |
|
| 4210 |
return (PyObject *)self; |
| 4211 |
} |
| 4212 |
|
| 4213 |
static PyObject * RawMidi_getServer(RawMidi* self) { GET_SERVER }; |
| 4214 |
static PyObject * RawMidi_getStream(RawMidi* self) { GET_STREAM }; |
| 4215 |
|
| 4216 |
static PyObject * RawMidi_play(RawMidi *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 4217 |
static PyObject * RawMidi_stop(RawMidi *self, PyObject *args, PyObject *kwds) { STOP }; |
| 4218 |
|
| 4219 |
static PyObject * |
| 4220 |
RawMidi_setFunction(RawMidi *self, PyObject *arg) |
| 4221 |
{ |
| 4222 |
if (! PyCallable_Check(arg)) |
| 4223 |
{ |
| 4224 |
PyErr_SetString(PyExc_TypeError, "The callable attribute must be a valid Python function."); |
| 4225 |
Py_RETURN_NONE; |
| 4226 |
} |
| 4227 |
|
| 4228 |
Py_XDECREF(self->callable); |
| 4229 |
self->callable = arg; |
| 4230 |
Py_INCREF(self->callable); |
| 4231 |
|
| 4232 |
Py_RETURN_NONE; |
| 4233 |
} |
| 4234 |
|
| 4235 |
static PyMemberDef RawMidi_members[] = |
| 4236 |
{ |
| 4237 |
{"server", T_OBJECT_EX, offsetof(RawMidi, server), 0, "Pyo server."}, |
| 4238 |
{"stream", T_OBJECT_EX, offsetof(RawMidi, stream), 0, "Stream object."}, |
| 4239 |
{NULL} /* Sentinel */ |
| 4240 |
}; |
| 4241 |
|
| 4242 |
static PyMethodDef RawMidi_methods[] = |
| 4243 |
{ |
| 4244 |
{"getServer", (PyCFunction)RawMidi_getServer, METH_NOARGS, "Returns server object."}, |
| 4245 |
{"_getStream", (PyCFunction)RawMidi_getStream, METH_NOARGS, "Returns stream object."}, |
| 4246 |
{"play", (PyCFunction)RawMidi_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 4247 |
{"stop", (PyCFunction)RawMidi_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 4248 |
{"setFunction", (PyCFunction)RawMidi_setFunction, METH_O, "Sets the function to be called."}, |
| 4249 |
{NULL} /* Sentinel */ |
| 4250 |
}; |
| 4251 |
|
| 4252 |
PyTypeObject RawMidiType = |
| 4253 |
{ |
| 4254 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 4255 |
"_pyo.RawMidi_base", /*tp_name*/ |
| 4256 |
sizeof(RawMidi), /*tp_basicsize*/ |
| 4257 |
0, /*tp_itemsize*/ |
| 4258 |
(destructor)RawMidi_dealloc, /*tp_dealloc*/ |
| 4259 |
0, /*tp_print*/ |
| 4260 |
0, /*tp_getattr*/ |
| 4261 |
0, /*tp_setattr*/ |
| 4262 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 4263 |
0, /*tp_repr*/ |
| 4264 |
0, /*tp_as_number*/ |
| 4265 |
0, /*tp_as_sequence*/ |
| 4266 |
0, /*tp_as_mapping*/ |
| 4267 |
0, /*tp_hash */ |
| 4268 |
0, /*tp_call*/ |
| 4269 |
0, /*tp_str*/ |
| 4270 |
0, /*tp_getattro*/ |
| 4271 |
0, /*tp_setattro*/ |
| 4272 |
0, /*tp_as_buffer*/ |
| 4273 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 4274 |
"RawMidi objects. Calls a function with midi data as arguments.", /* tp_doc */ |
| 4275 |
(traverseproc)RawMidi_traverse, /* tp_traverse */ |
| 4276 |
(inquiry)RawMidi_clear, /* tp_clear */ |
| 4277 |
0, /* tp_richcompare */ |
| 4278 |
0, /* tp_weaklistoffset */ |
| 4279 |
0, /* tp_iter */ |
| 4280 |
0, /* tp_iternext */ |
| 4281 |
RawMidi_methods, /* tp_methods */ |
| 4282 |
RawMidi_members, /* tp_members */ |
| 4283 |
0, /* tp_getset */ |
| 4284 |
0, /* tp_base */ |
| 4285 |
0, /* tp_dict */ |
| 4286 |
0, /* tp_descr_get */ |
| 4287 |
0, /* tp_descr_set */ |
| 4288 |
0, /* tp_dictoffset */ |
| 4289 |
0, /* tp_init */ |
| 4290 |
0, /* tp_alloc */ |
| 4291 |
RawMidi_new, /* tp_new */ |
| 4292 |
}; |
| 4293 |
|
| 4294 |
/*********************************************************************************************/ |
| 4295 |
/* MidiLinseg *********************************************************************************/ |
| 4296 |
/*********************************************************************************************/ |
| 4297 |
typedef struct |
| 4298 |
{ |
| 4299 |
pyo_audio_HEAD |
| 4300 |
PyObject *pointslist; |
| 4301 |
PyObject *input; |
| 4302 |
Stream *input_stream; |
| 4303 |
int modebuffer[2]; |
| 4304 |
double currentTime; |
| 4305 |
double currentValue; |
| 4306 |
MYFLT sampleToSec; |
| 4307 |
double increment; |
| 4308 |
MYFLT *targets; |
| 4309 |
MYFLT *times; |
| 4310 |
MYFLT ampscaling; |
| 4311 |
int which; |
| 4312 |
int flag; |
| 4313 |
int noteon; |
| 4314 |
int hold; |
| 4315 |
int tmphold; |
| 4316 |
int waiting; |
| 4317 |
int newlist; |
| 4318 |
int listsize; |
| 4319 |
int startFromLast; |
| 4320 |
MYFLT *trigsBuffer; |
| 4321 |
TriggerStream *trig_stream; |
| 4322 |
} MidiLinseg; |
| 4323 |
|
| 4324 |
static void |
| 4325 |
MidiLinseg_convert_pointslist(MidiLinseg *self) |
| 4326 |
{ |
| 4327 |
int i; |
| 4328 |
PyObject *tup; |
| 4329 |
|
| 4330 |
self->listsize = PyList_Size(self->pointslist); |
| 4331 |
self->targets = (MYFLT *)PyMem_RawRealloc(self->targets, self->listsize * sizeof(MYFLT)); |
| 4332 |
self->times = (MYFLT *)PyMem_RawRealloc(self->times, self->listsize * sizeof(MYFLT)); |
| 4333 |
|
| 4334 |
for (i = 0; i < self->listsize; i++) |
| 4335 |
{ |
| 4336 |
tup = PyList_GET_ITEM(self->pointslist, i); |
| 4337 |
self->times[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 0)); |
| 4338 |
self->targets[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1)); |
| 4339 |
} |
| 4340 |
} |
| 4341 |
|
| 4342 |
static void |
| 4343 |
MidiLinseg_reinit(MidiLinseg *self) |
| 4344 |
{ |
| 4345 |
if (self->newlist == 1) |
| 4346 |
{ |
| 4347 |
MidiLinseg_convert_pointslist((MidiLinseg *)self); |
| 4348 |
self->newlist = 0; |
| 4349 |
} |
| 4350 |
|
| 4351 |
if (self->tmphold != self->hold) |
| 4352 |
{ |
| 4353 |
self->hold = self->tmphold; |
| 4354 |
} |
| 4355 |
|
| 4356 |
if (self->hold < 1 || self->hold >= self->listsize) |
| 4357 |
{ |
| 4358 |
self->hold = self->listsize / 2; |
| 4359 |
} |
| 4360 |
|
| 4361 |
self->currentTime = 0.0; |
| 4362 |
|
| 4363 |
if (self->currentValue == 0.0) |
| 4364 |
{ |
| 4365 |
self->currentValue = self->targets[0]; |
| 4366 |
self->startFromLast = 0; |
| 4367 |
} |
| 4368 |
else |
| 4369 |
{ |
| 4370 |
self->startFromLast = 1; |
| 4371 |
} |
| 4372 |
|
| 4373 |
self->which = 0; |
| 4374 |
self->flag = 1; |
| 4375 |
self->noteon = 1; |
| 4376 |
self->waiting = 0; |
| 4377 |
} |
| 4378 |
|
| 4379 |
static void |
| 4380 |
MidiLinseg_generate(MidiLinseg *self) |
| 4381 |
{ |
| 4382 |
int i; |
| 4383 |
MYFLT timefactor = 1.0; |
| 4384 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 4385 |
|
| 4386 |
for (i = 0; i < self->bufsize; i++) |
| 4387 |
{ |
| 4388 |
self->trigsBuffer[i] = 0.0; |
| 4389 |
|
| 4390 |
if (in[i] > 0.0 && self->noteon == 0) |
| 4391 |
{ |
| 4392 |
MidiLinseg_reinit((MidiLinseg *)self); |
| 4393 |
self->ampscaling = in[i]; |
| 4394 |
} |
| 4395 |
else if (in[i] == 0.0 && self->noteon == 1) |
| 4396 |
{ |
| 4397 |
self->noteon = 0; |
| 4398 |
self->waiting = 0; |
| 4399 |
} |
| 4400 |
|
| 4401 |
if (self->flag == 1) |
| 4402 |
{ |
| 4403 |
if (self->currentTime >= self->times[self->which]) |
| 4404 |
{ |
| 4405 |
self->which++; |
| 4406 |
|
| 4407 |
if (self->which == self->listsize) |
| 4408 |
{ |
| 4409 |
self->trigsBuffer[i] = 1.0; |
| 4410 |
self->flag = 0; |
| 4411 |
self->currentValue = self->targets[self->which - 1] * self->ampscaling; |
| 4412 |
} |
| 4413 |
else |
| 4414 |
{ |
| 4415 |
if ((self->which - 1) == self->hold && self->noteon) |
| 4416 |
{ |
| 4417 |
self->currentValue = self->targets[self->which - 1] * self->ampscaling; |
| 4418 |
self->waiting = 1; |
| 4419 |
} |
| 4420 |
|
| 4421 |
if ((self->times[self->which] - self->times[self->which - 1]) <= 0) |
| 4422 |
{ |
| 4423 |
self->increment = self->targets[self->which] * self->ampscaling - self->currentValue; |
| 4424 |
} |
| 4425 |
else |
| 4426 |
{ |
| 4427 |
timefactor = (self->times[self->which] - self->times[self->which - 1]) / self->sampleToSec; |
| 4428 |
|
| 4429 |
if (self->startFromLast) |
| 4430 |
{ |
| 4431 |
self->increment = (self->targets[self->which] * self->ampscaling - self->currentValue) / timefactor; |
| 4432 |
self->startFromLast = 0; |
| 4433 |
} |
| 4434 |
else |
| 4435 |
{ |
| 4436 |
self->increment = (self->targets[self->which] - self->targets[self->which - 1]) * self->ampscaling / timefactor; |
| 4437 |
} |
| 4438 |
} |
| 4439 |
} |
| 4440 |
} |
| 4441 |
|
| 4442 |
if (self->waiting == 0 && self->currentTime <= self->times[self->listsize - 1]) |
| 4443 |
{ |
| 4444 |
self->currentValue += self->increment; |
| 4445 |
} |
| 4446 |
|
| 4447 |
self->data[i] = (MYFLT)self->currentValue; |
| 4448 |
|
| 4449 |
if (self->waiting == 0) |
| 4450 |
{ |
| 4451 |
self->currentTime += self->sampleToSec; |
| 4452 |
} |
| 4453 |
} |
| 4454 |
else |
| 4455 |
self->data[i] = (MYFLT)self->currentValue; |
| 4456 |
} |
| 4457 |
} |
| 4458 |
|
| 4459 |
static void MidiLinseg_postprocessing_ii(MidiLinseg *self) { POST_PROCESSING_II }; |
| 4460 |
static void MidiLinseg_postprocessing_ai(MidiLinseg *self) { POST_PROCESSING_AI }; |
| 4461 |
static void MidiLinseg_postprocessing_ia(MidiLinseg *self) { POST_PROCESSING_IA }; |
| 4462 |
static void MidiLinseg_postprocessing_aa(MidiLinseg *self) { POST_PROCESSING_AA }; |
| 4463 |
static void MidiLinseg_postprocessing_ireva(MidiLinseg *self) { POST_PROCESSING_IREVA }; |
| 4464 |
static void MidiLinseg_postprocessing_areva(MidiLinseg *self) { POST_PROCESSING_AREVA }; |
| 4465 |
static void MidiLinseg_postprocessing_revai(MidiLinseg *self) { POST_PROCESSING_REVAI }; |
| 4466 |
static void MidiLinseg_postprocessing_revaa(MidiLinseg *self) { POST_PROCESSING_REVAA }; |
| 4467 |
static void MidiLinseg_postprocessing_revareva(MidiLinseg *self) { POST_PROCESSING_REVAREVA }; |
| 4468 |
|
| 4469 |
static void |
| 4470 |
MidiLinseg_setProcMode(MidiLinseg *self) |
| 4471 |
{ |
| 4472 |
int muladdmode; |
| 4473 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 4474 |
|
| 4475 |
self->proc_func_ptr = MidiLinseg_generate; |
| 4476 |
|
| 4477 |
switch (muladdmode) |
| 4478 |
{ |
| 4479 |
case 0: |
| 4480 |
self->muladd_func_ptr = MidiLinseg_postprocessing_ii; |
| 4481 |
break; |
| 4482 |
|
| 4483 |
case 1: |
| 4484 |
self->muladd_func_ptr = MidiLinseg_postprocessing_ai; |
| 4485 |
break; |
| 4486 |
|
| 4487 |
case 2: |
| 4488 |
self->muladd_func_ptr = MidiLinseg_postprocessing_revai; |
| 4489 |
break; |
| 4490 |
|
| 4491 |
case 10: |
| 4492 |
self->muladd_func_ptr = MidiLinseg_postprocessing_ia; |
| 4493 |
break; |
| 4494 |
|
| 4495 |
case 11: |
| 4496 |
self->muladd_func_ptr = MidiLinseg_postprocessing_aa; |
| 4497 |
break; |
| 4498 |
|
| 4499 |
case 12: |
| 4500 |
self->muladd_func_ptr = MidiLinseg_postprocessing_revaa; |
| 4501 |
break; |
| 4502 |
|
| 4503 |
case 20: |
| 4504 |
self->muladd_func_ptr = MidiLinseg_postprocessing_ireva; |
| 4505 |
break; |
| 4506 |
|
| 4507 |
case 21: |
| 4508 |
self->muladd_func_ptr = MidiLinseg_postprocessing_areva; |
| 4509 |
break; |
| 4510 |
|
| 4511 |
case 22: |
| 4512 |
self->muladd_func_ptr = MidiLinseg_postprocessing_revareva; |
| 4513 |
break; |
| 4514 |
} |
| 4515 |
} |
| 4516 |
|
| 4517 |
static void |
| 4518 |
MidiLinseg_compute_next_data_frame(MidiLinseg *self) |
| 4519 |
{ |
| 4520 |
(*self->proc_func_ptr)(self); |
| 4521 |
(*self->muladd_func_ptr)(self); |
| 4522 |
} |
| 4523 |
|
| 4524 |
static int |
| 4525 |
MidiLinseg_traverse(MidiLinseg *self, visitproc visit, void *arg) |
| 4526 |
{ |
| 4527 |
pyo_VISIT |
| 4528 |
Py_VISIT(self->pointslist); |
| 4529 |
Py_VISIT(self->input); |
| 4530 |
return 0; |
| 4531 |
} |
| 4532 |
|
| 4533 |
static int |
| 4534 |
MidiLinseg_clear(MidiLinseg *self) |
| 4535 |
{ |
| 4536 |
pyo_CLEAR |
| 4537 |
Py_CLEAR(self->pointslist); |
| 4538 |
Py_CLEAR(self->input); |
| 4539 |
return 0; |
| 4540 |
} |
| 4541 |
|
| 4542 |
static void |
| 4543 |
MidiLinseg_dealloc(MidiLinseg* self) |
| 4544 |
{ |
| 4545 |
pyo_DEALLOC |
| 4546 |
PyMem_RawFree(self->targets); |
| 4547 |
PyMem_RawFree(self->times); |
| 4548 |
PyMem_RawFree(self->trigsBuffer); |
| 4549 |
MidiLinseg_clear(self); |
| 4550 |
Py_TYPE(self->trig_stream)->tp_free((PyObject*)self->trig_stream); |
| 4551 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 4552 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 4553 |
} |
| 4554 |
|
| 4555 |
static PyObject * |
| 4556 |
MidiLinseg_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 4557 |
{ |
| 4558 |
int i; |
| 4559 |
PyObject *inputtmp, *input_streamtmp, *pointslist = NULL, *multmp = NULL, *addtmp = NULL; |
| 4560 |
MidiLinseg *self; |
| 4561 |
self = (MidiLinseg *)type->tp_alloc(type, 0); |
| 4562 |
|
| 4563 |
self->noteon = 0; |
| 4564 |
self->newlist = 1; |
| 4565 |
self->waiting = 0; |
| 4566 |
self->ampscaling = 1.0; |
| 4567 |
self->modebuffer[0] = 0; |
| 4568 |
self->modebuffer[1] = 0; |
| 4569 |
|
| 4570 |
INIT_OBJECT_COMMON |
| 4571 |
Stream_setFunctionPtr(self->stream, MidiLinseg_compute_next_data_frame); |
| 4572 |
self->mode_func_ptr = MidiLinseg_setProcMode; |
| 4573 |
|
| 4574 |
self->sampleToSec = 1. / self->sr; |
| 4575 |
|
| 4576 |
static char *kwlist[] = {"input", "list", "hold", "mul", "add", NULL}; |
| 4577 |
|
| 4578 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|iOO", kwlist, &inputtmp, &pointslist, &self->hold, &multmp, &addtmp)) |
| 4579 |
Py_RETURN_NONE; |
| 4580 |
|
| 4581 |
INIT_INPUT_STREAM |
| 4582 |
|
| 4583 |
self->pointslist = pointslist; |
| 4584 |
Py_INCREF(self->pointslist); |
| 4585 |
MidiLinseg_convert_pointslist((MidiLinseg *)self); |
| 4586 |
|
| 4587 |
self->tmphold = self->hold; |
| 4588 |
|
| 4589 |
if (multmp) |
| 4590 |
{ |
| 4591 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 4592 |
} |
| 4593 |
|
| 4594 |
if (addtmp) |
| 4595 |
{ |
| 4596 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 4597 |
} |
| 4598 |
|
| 4599 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 4600 |
|
| 4601 |
self->trigsBuffer = (MYFLT *)PyMem_RawRealloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT)); |
| 4602 |
|
| 4603 |
for (i = 0; i < self->bufsize; i++) |
| 4604 |
{ |
| 4605 |
self->trigsBuffer[i] = 0.0; |
| 4606 |
} |
| 4607 |
|
| 4608 |
MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL); |
| 4609 |
TriggerStream_setData(self->trig_stream, self->trigsBuffer); |
| 4610 |
|
| 4611 |
(*self->mode_func_ptr)(self); |
| 4612 |
|
| 4613 |
return (PyObject *)self; |
| 4614 |
} |
| 4615 |
|
| 4616 |
static PyObject * MidiLinseg_getServer(MidiLinseg* self) { GET_SERVER }; |
| 4617 |
static PyObject * MidiLinseg_getStream(MidiLinseg* self) { GET_STREAM }; |
| 4618 |
static PyObject * MidiLinseg_getTriggerStream(MidiLinseg* self) { GET_TRIGGER_STREAM }; |
| 4619 |
static PyObject * MidiLinseg_setMul(MidiLinseg *self, PyObject *arg) { SET_MUL }; |
| 4620 |
static PyObject * MidiLinseg_setAdd(MidiLinseg *self, PyObject *arg) { SET_ADD }; |
| 4621 |
static PyObject * MidiLinseg_setSub(MidiLinseg *self, PyObject *arg) { SET_SUB }; |
| 4622 |
static PyObject * MidiLinseg_setDiv(MidiLinseg *self, PyObject *arg) { SET_DIV }; |
| 4623 |
|
| 4624 |
static PyObject * MidiLinseg_play(MidiLinseg *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 4625 |
static PyObject * MidiLinseg_stop(MidiLinseg *self, PyObject *args, PyObject *kwds) { STOP }; |
| 4626 |
|
| 4627 |
static PyObject * MidiLinseg_multiply(MidiLinseg *self, PyObject *arg) { MULTIPLY }; |
| 4628 |
static PyObject * MidiLinseg_inplace_multiply(MidiLinseg *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 4629 |
static PyObject * MidiLinseg_add(MidiLinseg *self, PyObject *arg) { ADD }; |
| 4630 |
static PyObject * MidiLinseg_inplace_add(MidiLinseg *self, PyObject *arg) { INPLACE_ADD }; |
| 4631 |
static PyObject * MidiLinseg_sub(MidiLinseg *self, PyObject *arg) { SUB }; |
| 4632 |
static PyObject * MidiLinseg_inplace_sub(MidiLinseg *self, PyObject *arg) { INPLACE_SUB }; |
| 4633 |
static PyObject * MidiLinseg_div(MidiLinseg *self, PyObject *arg) { DIV }; |
| 4634 |
static PyObject * MidiLinseg_inplace_div(MidiLinseg *self, PyObject *arg) { INPLACE_DIV }; |
| 4635 |
|
| 4636 |
static PyObject * |
| 4637 |
MidiLinseg_setList(MidiLinseg *self, PyObject *value) |
| 4638 |
{ |
| 4639 |
if (value == NULL) |
| 4640 |
{ |
| 4641 |
PyErr_SetString(PyExc_TypeError, "Cannot delete the list attribute."); |
| 4642 |
return PyLong_FromLong(-1); |
| 4643 |
} |
| 4644 |
|
| 4645 |
if (! PyList_Check(value)) |
| 4646 |
{ |
| 4647 |
PyErr_SetString(PyExc_TypeError, "The points list attribute value must be a list of tuples."); |
| 4648 |
return PyLong_FromLong(-1); |
| 4649 |
} |
| 4650 |
|
| 4651 |
Py_INCREF(value); |
| 4652 |
Py_DECREF(self->pointslist); |
| 4653 |
self->pointslist = value; |
| 4654 |
|
| 4655 |
self->newlist = 1; |
| 4656 |
|
| 4657 |
Py_RETURN_NONE; |
| 4658 |
} |
| 4659 |
|
| 4660 |
static PyObject * |
| 4661 |
MidiLinseg_setHold(MidiLinseg *self, PyObject *arg) |
| 4662 |
{ |
| 4663 |
if (PyLong_Check(arg)) |
| 4664 |
{ |
| 4665 |
self->tmphold = PyLong_AsLong(arg); |
| 4666 |
} |
| 4667 |
|
| 4668 |
Py_RETURN_NONE; |
| 4669 |
} |
| 4670 |
|
| 4671 |
static PyMemberDef MidiLinseg_members[] = |
| 4672 |
{ |
| 4673 |
{"server", T_OBJECT_EX, offsetof(MidiLinseg, server), 0, "Pyo server."}, |
| 4674 |
{"stream", T_OBJECT_EX, offsetof(MidiLinseg, stream), 0, "Stream object."}, |
| 4675 |
{"trig_stream", T_OBJECT_EX, offsetof(MidiLinseg, trig_stream), 0, "Trigger Stream object."}, |
| 4676 |
{"pointslist", T_OBJECT_EX, offsetof(MidiLinseg, pointslist), 0, "List of target points."}, |
| 4677 |
{"mul", T_OBJECT_EX, offsetof(MidiLinseg, mul), 0, "Mul factor."}, |
| 4678 |
{"add", T_OBJECT_EX, offsetof(MidiLinseg, add), 0, "Add factor."}, |
| 4679 |
{NULL} /* Sentinel */ |
| 4680 |
}; |
| 4681 |
|
| 4682 |
static PyMethodDef MidiLinseg_methods[] = |
| 4683 |
{ |
| 4684 |
{"getServer", (PyCFunction)MidiLinseg_getServer, METH_NOARGS, "Returns server object."}, |
| 4685 |
{"_getStream", (PyCFunction)MidiLinseg_getStream, METH_NOARGS, "Returns stream object."}, |
| 4686 |
{"_getTriggerStream", (PyCFunction)MidiLinseg_getTriggerStream, METH_NOARGS, "Returns trigger stream object."}, |
| 4687 |
{"play", (PyCFunction)MidiLinseg_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 4688 |
{"stop", (PyCFunction)MidiLinseg_stop, METH_VARARGS | METH_KEYWORDS, "Starts fadeout and stops computing."}, |
| 4689 |
{"setList", (PyCFunction)MidiLinseg_setList, METH_O, "Sets target points list."}, |
| 4690 |
{"setHold", (PyCFunction)MidiLinseg_setHold, METH_O, "Sets hold point."}, |
| 4691 |
{"setMul", (PyCFunction)MidiLinseg_setMul, METH_O, "Sets MidiLinseg mul factor."}, |
| 4692 |
{"setAdd", (PyCFunction)MidiLinseg_setAdd, METH_O, "Sets MidiLinseg add factor."}, |
| 4693 |
{"setSub", (PyCFunction)MidiLinseg_setSub, METH_O, "Sets inverse add factor."}, |
| 4694 |
{"setDiv", (PyCFunction)MidiLinseg_setDiv, METH_O, "Sets inverse mul factor."}, |
| 4695 |
{NULL} /* Sentinel */ |
| 4696 |
}; |
| 4697 |
|
| 4698 |
static PyNumberMethods MidiLinseg_as_number = |
| 4699 |
{ |
| 4700 |
(binaryfunc)MidiLinseg_add, /*nb_add*/ |
| 4701 |
(binaryfunc)MidiLinseg_sub, /*nb_subtract*/ |
| 4702 |
(binaryfunc)MidiLinseg_multiply, /*nb_multiply*/ |
| 4703 |
0, /*nb_remainder*/ |
| 4704 |
0, /*nb_divmod*/ |
| 4705 |
0, /*nb_power*/ |
| 4706 |
0, /*nb_neg*/ |
| 4707 |
0, /*nb_pos*/ |
| 4708 |
0, /*(unaryfunc)array_abs,*/ |
| 4709 |
0, /*nb_nonzero*/ |
| 4710 |
0, /*nb_invert*/ |
| 4711 |
0, /*nb_lshift*/ |
| 4712 |
0, /*nb_rshift*/ |
| 4713 |
0, /*nb_and*/ |
| 4714 |
0, /*nb_xor*/ |
| 4715 |
0, /*nb_or*/ |
| 4716 |
0, /*nb_int*/ |
| 4717 |
0, /*nb_long*/ |
| 4718 |
0, /*nb_float*/ |
| 4719 |
(binaryfunc)MidiLinseg_inplace_add, /*inplace_add*/ |
| 4720 |
(binaryfunc)MidiLinseg_inplace_sub, /*inplace_subtract*/ |
| 4721 |
(binaryfunc)MidiLinseg_inplace_multiply, /*inplace_multiply*/ |
| 4722 |
0, /*inplace_remainder*/ |
| 4723 |
0, /*inplace_power*/ |
| 4724 |
0, /*inplace_lshift*/ |
| 4725 |
0, /*inplace_rshift*/ |
| 4726 |
0, /*inplace_and*/ |
| 4727 |
0, /*inplace_xor*/ |
| 4728 |
0, /*inplace_or*/ |
| 4729 |
0, /*nb_floor_divide*/ |
| 4730 |
(binaryfunc)MidiLinseg_div, /*nb_true_divide*/ |
| 4731 |
0, /*nb_inplace_floor_divide*/ |
| 4732 |
(binaryfunc)MidiLinseg_inplace_div, /*nb_inplace_true_divide*/ |
| 4733 |
0, /* nb_index */ |
| 4734 |
}; |
| 4735 |
|
| 4736 |
PyTypeObject MidiLinsegType = |
| 4737 |
{ |
| 4738 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 4739 |
"_pyo.MidiLinseg_base", /*tp_name*/ |
| 4740 |
sizeof(MidiLinseg), /*tp_basicsize*/ |
| 4741 |
0, /*tp_itemsize*/ |
| 4742 |
(destructor)MidiLinseg_dealloc, /*tp_dealloc*/ |
| 4743 |
0, /*tp_print*/ |
| 4744 |
0, /*tp_getattr*/ |
| 4745 |
0, /*tp_setattr*/ |
| 4746 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 4747 |
0, /*tp_repr*/ |
| 4748 |
&MidiLinseg_as_number, /*tp_as_number*/ |
| 4749 |
0, /*tp_as_sequence*/ |
| 4750 |
0, /*tp_as_mapping*/ |
| 4751 |
0, /*tp_hash */ |
| 4752 |
0, /*tp_call*/ |
| 4753 |
0, /*tp_str*/ |
| 4754 |
0, /*tp_getattro*/ |
| 4755 |
0, /*tp_setattro*/ |
| 4756 |
0, /*tp_as_buffer*/ |
| 4757 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 4758 |
"MidiLinseg objects. Generates a linear segments break-points line.", /* tp_doc */ |
| 4759 |
(traverseproc)MidiLinseg_traverse, /* tp_traverse */ |
| 4760 |
(inquiry)MidiLinseg_clear, /* tp_clear */ |
| 4761 |
0, /* tp_richcompare */ |
| 4762 |
0, /* tp_weaklistoffset */ |
| 4763 |
0, /* tp_iter */ |
| 4764 |
0, /* tp_iternext */ |
| 4765 |
MidiLinseg_methods, /* tp_methods */ |
| 4766 |
MidiLinseg_members, /* tp_members */ |
| 4767 |
0, /* tp_getset */ |
| 4768 |
0, /* tp_base */ |
| 4769 |
0, /* tp_dict */ |
| 4770 |
0, /* tp_descr_get */ |
| 4771 |
0, /* tp_descr_set */ |
| 4772 |
0, /* tp_dictoffset */ |
| 4773 |
0, /* tp_init */ |
| 4774 |
0, /* tp_alloc */ |
| 4775 |
MidiLinseg_new, /* tp_new */ |
| 4776 |
}; |