| 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 |
#include "lo/lo.h" |
| 29 |
|
| 30 |
static void error(int num, const char *msg, const char *path) |
| 31 |
{ |
| 32 |
PySys_WriteStdout("liblo server error %d in path %s: %s\n", num, path, msg); |
| 33 |
} |
| 34 |
|
| 35 |
/* main OSC receiver */ |
| 36 |
typedef struct |
| 37 |
{ |
| 38 |
pyo_audio_HEAD |
| 39 |
lo_server osc_server; |
| 40 |
int port; |
| 41 |
PyObject *dict; |
| 42 |
PyObject *address_path; |
| 43 |
} OscReceiver; |
| 44 |
|
| 45 |
/* lo_method_handler' (aka 'int (*)(const char *, const char *, lo_arg **, int, struct lo_message_ *, void *)') */ |
| 46 |
int OscReceiver_handler(const char *path, const char *types, lo_arg **argv, int argc, |
| 47 |
lo_message data, void *user_data) |
| 48 |
{ |
| 49 |
OscReceiver *self = user_data; |
| 50 |
PyObject *pathObj = PyUnicode_FromString(path); |
| 51 |
PyObject *valueObj = PyFloat_FromDouble(argv[0]->FLOAT_VALUE); |
| 52 |
PyDict_SetItem(self->dict, pathObj, valueObj); |
| 53 |
Py_DECREF(pathObj); |
| 54 |
Py_DECREF(valueObj); |
| 55 |
return 0; |
| 56 |
} |
| 57 |
|
| 58 |
MYFLT OscReceiver_getValue(OscReceiver *self, PyObject *path) |
| 59 |
{ |
| 60 |
return PyFloat_AsDouble(PyDict_GetItem(self->dict, path)); |
| 61 |
} |
| 62 |
|
| 63 |
static void |
| 64 |
OscReceiver_compute_next_data_frame(OscReceiver *self) |
| 65 |
{ |
| 66 |
while (lo_server_recv_noblock(self->osc_server, 0) != 0) {}; |
| 67 |
} |
| 68 |
|
| 69 |
static int |
| 70 |
OscReceiver_traverse(OscReceiver *self, visitproc visit, void *arg) |
| 71 |
{ |
| 72 |
pyo_VISIT |
| 73 |
Py_VISIT(self->dict); |
| 74 |
Py_VISIT(self->address_path); |
| 75 |
return 0; |
| 76 |
} |
| 77 |
|
| 78 |
static int |
| 79 |
OscReceiver_clear(OscReceiver *self) |
| 80 |
{ |
| 81 |
pyo_CLEAR |
| 82 |
Py_CLEAR(self->dict); |
| 83 |
Py_CLEAR(self->address_path); |
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
static void |
| 88 |
OscReceiver_dealloc(OscReceiver* self) |
| 89 |
{ |
| 90 |
lo_server_free(self->osc_server); |
| 91 |
pyo_DEALLOC |
| 92 |
OscReceiver_clear(self); |
| 93 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 94 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 95 |
} |
| 96 |
|
| 97 |
static PyObject * |
| 98 |
OscReceiver_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 99 |
{ |
| 100 |
int i; |
| 101 |
PyObject *pathtmp; |
| 102 |
OscReceiver *self; |
| 103 |
self = (OscReceiver *)type->tp_alloc(type, 0); |
| 104 |
|
| 105 |
INIT_OBJECT_COMMON |
| 106 |
Stream_setFunctionPtr(self->stream, OscReceiver_compute_next_data_frame); |
| 107 |
|
| 108 |
static char *kwlist[] = {"port", "address", NULL}; |
| 109 |
|
| 110 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "iO", kwlist, &self->port, &pathtmp)) |
| 111 |
Py_RETURN_NONE; |
| 112 |
|
| 113 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 114 |
|
| 115 |
self->dict = PyDict_New(); |
| 116 |
|
| 117 |
if (PyList_Check(pathtmp)) |
| 118 |
{ |
| 119 |
self->address_path = pathtmp; |
| 120 |
Py_INCREF(self->address_path); |
| 121 |
} |
| 122 |
else |
| 123 |
{ |
| 124 |
PyErr_SetString(PyExc_TypeError, "The OscReceiver_base 'address' attributes must be a list of strings and/or unicodes."); |
| 125 |
Py_RETURN_NONE; |
| 126 |
} |
| 127 |
|
| 128 |
int lsize = PyList_Size(self->address_path); |
| 129 |
|
| 130 |
PyObject *zero = PyFloat_FromDouble(0.); |
| 131 |
for (i = 0; i < lsize; i++) |
| 132 |
{ |
| 133 |
PyDict_SetItem(self->dict, PyList_GET_ITEM(self->address_path, i), zero); |
| 134 |
} |
| 135 |
Py_DECREF(zero); |
| 136 |
|
| 137 |
char buf[20]; |
| 138 |
sprintf(buf, "%i", self->port); |
| 139 |
self->osc_server = lo_server_new(buf, error); |
| 140 |
|
| 141 |
lo_server_add_method(self->osc_server, NULL, TYPE_F, OscReceiver_handler, self); |
| 142 |
|
| 143 |
return (PyObject *)self; |
| 144 |
} |
| 145 |
|
| 146 |
static PyObject * |
| 147 |
OscReceiver_addAddress(OscReceiver *self, PyObject *arg) |
| 148 |
{ |
| 149 |
int i; |
| 150 |
|
| 151 |
if (PyUnicode_Check(arg)) |
| 152 |
{ |
| 153 |
PyObject *zero = PyFloat_FromDouble(0.); |
| 154 |
PyDict_SetItem(self->dict, arg, zero); |
| 155 |
Py_DECREF(zero); |
| 156 |
} |
| 157 |
else if (PyList_Check(arg)) |
| 158 |
{ |
| 159 |
Py_ssize_t lsize = PyList_Size(arg); |
| 160 |
|
| 161 |
PyObject *zero = PyFloat_FromDouble(0.); |
| 162 |
for (i = 0; i < lsize; i++) |
| 163 |
{ |
| 164 |
PyDict_SetItem(self->dict, PyList_GET_ITEM(arg, i), zero); |
| 165 |
} |
| 166 |
Py_DECREF(zero); |
| 167 |
} |
| 168 |
|
| 169 |
Py_RETURN_NONE; |
| 170 |
} |
| 171 |
|
| 172 |
static PyObject * |
| 173 |
OscReceiver_delAddress(OscReceiver *self, PyObject *arg) |
| 174 |
{ |
| 175 |
int i; |
| 176 |
|
| 177 |
if (PyUnicode_Check(arg)) |
| 178 |
{ |
| 179 |
PyDict_DelItem(self->dict, arg); |
| 180 |
} |
| 181 |
else if (PyList_Check(arg)) |
| 182 |
{ |
| 183 |
Py_ssize_t lsize = PyList_Size(arg); |
| 184 |
|
| 185 |
for (i = 0; i < lsize; i++) |
| 186 |
{ |
| 187 |
PyDict_DelItem(self->dict, PyList_GET_ITEM(arg, i)); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
Py_RETURN_NONE; |
| 192 |
} |
| 193 |
|
| 194 |
static PyObject * |
| 195 |
OscReceiver_setValue(OscReceiver *self, PyObject *args, PyObject *kwds) |
| 196 |
{ |
| 197 |
PyObject *address, *value; |
| 198 |
|
| 199 |
static char *kwlist[] = {"address", "value", NULL}; |
| 200 |
|
| 201 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &address, &value)) |
| 202 |
Py_RETURN_NONE; |
| 203 |
|
| 204 |
PyDict_SetItem(self->dict, address, value); |
| 205 |
Py_RETURN_NONE; |
| 206 |
} |
| 207 |
|
| 208 |
static PyObject * OscReceiver_getServer(OscReceiver* self) { GET_SERVER }; |
| 209 |
static PyObject * OscReceiver_getStream(OscReceiver* self) { GET_STREAM }; |
| 210 |
|
| 211 |
static PyObject * OscReceiver_play(OscReceiver *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 212 |
static PyObject * OscReceiver_stop(OscReceiver *self, PyObject *args, PyObject *kwds) { STOP }; |
| 213 |
|
| 214 |
static PyMemberDef OscReceiver_members[] = |
| 215 |
{ |
| 216 |
{"server", T_OBJECT_EX, offsetof(OscReceiver, server), 0, "Pyo server."}, |
| 217 |
{"stream", T_OBJECT_EX, offsetof(OscReceiver, stream), 0, "Stream object."}, |
| 218 |
{NULL} /* Sentinel */ |
| 219 |
}; |
| 220 |
|
| 221 |
static PyMethodDef OscReceiver_methods[] = |
| 222 |
{ |
| 223 |
{"getServer", (PyCFunction)OscReceiver_getServer, METH_NOARGS, "Returns server object."}, |
| 224 |
{"_getStream", (PyCFunction)OscReceiver_getStream, METH_NOARGS, "Returns stream object."}, |
| 225 |
{"play", (PyCFunction)OscReceiver_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 226 |
{"stop", (PyCFunction)OscReceiver_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 227 |
{"addAddress", (PyCFunction)OscReceiver_addAddress, METH_O, "Add a new address to the dictionary."}, |
| 228 |
{"delAddress", (PyCFunction)OscReceiver_delAddress, METH_O, "Remove an address from the dictionary."}, |
| 229 |
{"setValue", (PyCFunction)OscReceiver_setValue, METH_VARARGS | METH_KEYWORDS, "Sets value for a specified address."}, |
| 230 |
{NULL} /* Sentinel */ |
| 231 |
}; |
| 232 |
|
| 233 |
PyTypeObject OscReceiverType = |
| 234 |
{ |
| 235 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 236 |
"_pyo.OscReceiver_base", /*tp_name*/ |
| 237 |
sizeof(OscReceiver), /*tp_basicsize*/ |
| 238 |
0, /*tp_itemsize*/ |
| 239 |
(destructor)OscReceiver_dealloc, /*tp_dealloc*/ |
| 240 |
0, /*tp_print*/ |
| 241 |
0, /*tp_getattr*/ |
| 242 |
0, /*tp_setattr*/ |
| 243 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 244 |
0, /*tp_repr*/ |
| 245 |
0, /*tp_as_number*/ |
| 246 |
0, /*tp_as_sequence*/ |
| 247 |
0, /*tp_as_mapping*/ |
| 248 |
0, /*tp_hash */ |
| 249 |
0, /*tp_call*/ |
| 250 |
0, /*tp_str*/ |
| 251 |
0, /*tp_getattro*/ |
| 252 |
0, /*tp_setattro*/ |
| 253 |
0, /*tp_as_buffer*/ |
| 254 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 255 |
"OscReceiver objects. Receive values via Open Sound Control protocol.", /* tp_doc */ |
| 256 |
(traverseproc)OscReceiver_traverse, /* tp_traverse */ |
| 257 |
(inquiry)OscReceiver_clear, /* tp_clear */ |
| 258 |
0, /* tp_richcompare */ |
| 259 |
0, /* tp_weaklistoffset */ |
| 260 |
0, /* tp_iter */ |
| 261 |
0, /* tp_iternext */ |
| 262 |
OscReceiver_methods, /* tp_methods */ |
| 263 |
OscReceiver_members, /* tp_members */ |
| 264 |
0, /* tp_getset */ |
| 265 |
0, /* tp_base */ |
| 266 |
0, /* tp_dict */ |
| 267 |
0, /* tp_descr_get */ |
| 268 |
0, /* tp_descr_set */ |
| 269 |
0, /* tp_dictoffset */ |
| 270 |
0, /* tp_init */ |
| 271 |
0, /* tp_alloc */ |
| 272 |
OscReceiver_new, /* tp_new */ |
| 273 |
}; |
| 274 |
|
| 275 |
/* OSC receiver stream object */ |
| 276 |
typedef struct |
| 277 |
{ |
| 278 |
pyo_audio_HEAD |
| 279 |
PyObject *input; |
| 280 |
PyObject *address_path; |
| 281 |
MYFLT value; |
| 282 |
MYFLT factor; |
| 283 |
int interpolation; |
| 284 |
int modebuffer[2]; |
| 285 |
} OscReceive; |
| 286 |
|
| 287 |
static void OscReceive_postprocessing_ii(OscReceive *self) { POST_PROCESSING_II }; |
| 288 |
static void OscReceive_postprocessing_ai(OscReceive *self) { POST_PROCESSING_AI }; |
| 289 |
static void OscReceive_postprocessing_ia(OscReceive *self) { POST_PROCESSING_IA }; |
| 290 |
static void OscReceive_postprocessing_aa(OscReceive *self) { POST_PROCESSING_AA }; |
| 291 |
static void OscReceive_postprocessing_ireva(OscReceive *self) { POST_PROCESSING_IREVA }; |
| 292 |
static void OscReceive_postprocessing_areva(OscReceive *self) { POST_PROCESSING_AREVA }; |
| 293 |
static void OscReceive_postprocessing_revai(OscReceive *self) { POST_PROCESSING_REVAI }; |
| 294 |
static void OscReceive_postprocessing_revaa(OscReceive *self) { POST_PROCESSING_REVAA }; |
| 295 |
static void OscReceive_postprocessing_revareva(OscReceive *self) { POST_PROCESSING_REVAREVA }; |
| 296 |
|
| 297 |
static void |
| 298 |
OscReceive_setProcMode(OscReceive *self) |
| 299 |
{ |
| 300 |
int muladdmode; |
| 301 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 302 |
|
| 303 |
switch (muladdmode) |
| 304 |
{ |
| 305 |
case 0: |
| 306 |
self->muladd_func_ptr = OscReceive_postprocessing_ii; |
| 307 |
break; |
| 308 |
|
| 309 |
case 1: |
| 310 |
self->muladd_func_ptr = OscReceive_postprocessing_ai; |
| 311 |
break; |
| 312 |
|
| 313 |
case 2: |
| 314 |
self->muladd_func_ptr = OscReceive_postprocessing_revai; |
| 315 |
break; |
| 316 |
|
| 317 |
case 10: |
| 318 |
self->muladd_func_ptr = OscReceive_postprocessing_ia; |
| 319 |
break; |
| 320 |
|
| 321 |
case 11: |
| 322 |
self->muladd_func_ptr = OscReceive_postprocessing_aa; |
| 323 |
break; |
| 324 |
|
| 325 |
case 12: |
| 326 |
self->muladd_func_ptr = OscReceive_postprocessing_revaa; |
| 327 |
break; |
| 328 |
|
| 329 |
case 20: |
| 330 |
self->muladd_func_ptr = OscReceive_postprocessing_ireva; |
| 331 |
break; |
| 332 |
|
| 333 |
case 21: |
| 334 |
self->muladd_func_ptr = OscReceive_postprocessing_areva; |
| 335 |
break; |
| 336 |
|
| 337 |
case 22: |
| 338 |
self->muladd_func_ptr = OscReceive_postprocessing_revareva; |
| 339 |
break; |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
static void |
| 344 |
OscReceive_compute_next_data_frame(OscReceive *self) |
| 345 |
{ |
| 346 |
int i; |
| 347 |
MYFLT val = OscReceiver_getValue((OscReceiver *)self->input, self->address_path); |
| 348 |
|
| 349 |
if (self->interpolation == 1) |
| 350 |
{ |
| 351 |
for (i = 0; i < self->bufsize; i++) |
| 352 |
{ |
| 353 |
self->data[i] = self->value = self->value + (val - self->value) * self->factor; |
| 354 |
} |
| 355 |
} |
| 356 |
else |
| 357 |
{ |
| 358 |
for (i = 0; i < self->bufsize; i++) |
| 359 |
{ |
| 360 |
self->data[i] = self->value = val; |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
(*self->muladd_func_ptr)(self); |
| 365 |
} |
| 366 |
|
| 367 |
static int |
| 368 |
OscReceive_traverse(OscReceive *self, visitproc visit, void *arg) |
| 369 |
{ |
| 370 |
pyo_VISIT |
| 371 |
Py_VISIT(self->input); |
| 372 |
Py_VISIT(self->address_path); |
| 373 |
return 0; |
| 374 |
} |
| 375 |
|
| 376 |
static int |
| 377 |
OscReceive_clear(OscReceive *self) |
| 378 |
{ |
| 379 |
pyo_CLEAR |
| 380 |
Py_CLEAR(self->input); |
| 381 |
Py_CLEAR(self->address_path); |
| 382 |
return 0; |
| 383 |
} |
| 384 |
|
| 385 |
static void |
| 386 |
OscReceive_dealloc(OscReceive* self) |
| 387 |
{ |
| 388 |
pyo_DEALLOC |
| 389 |
OscReceive_clear(self); |
| 390 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 391 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 392 |
} |
| 393 |
|
| 394 |
static PyObject * |
| 395 |
OscReceive_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 396 |
{ |
| 397 |
int i; |
| 398 |
PyObject *inputtmp = NULL, *pathtmp = NULL, *multmp = NULL, *addtmp = NULL;; |
| 399 |
OscReceive *self; |
| 400 |
self = (OscReceive *)type->tp_alloc(type, 0); |
| 401 |
|
| 402 |
self->value = 0.; |
| 403 |
self->interpolation = 1; |
| 404 |
self->modebuffer[0] = 0; |
| 405 |
self->modebuffer[1] = 0; |
| 406 |
|
| 407 |
INIT_OBJECT_COMMON |
| 408 |
|
| 409 |
self->factor = 1. / (0.01 * self->sr); |
| 410 |
|
| 411 |
Stream_setFunctionPtr(self->stream, OscReceive_compute_next_data_frame); |
| 412 |
self->mode_func_ptr = OscReceive_setProcMode; |
| 413 |
|
| 414 |
static char *kwlist[] = {"input", "address", "mul", "add", NULL}; |
| 415 |
|
| 416 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO", kwlist, &inputtmp, &pathtmp, &multmp, &addtmp)) |
| 417 |
Py_RETURN_NONE; |
| 418 |
|
| 419 |
self->input = inputtmp; |
| 420 |
Py_INCREF(self->input); |
| 421 |
|
| 422 |
if (multmp) |
| 423 |
{ |
| 424 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 425 |
} |
| 426 |
|
| 427 |
if (addtmp) |
| 428 |
{ |
| 429 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 430 |
} |
| 431 |
|
| 432 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 433 |
|
| 434 |
if (!PyUnicode_Check(pathtmp)) |
| 435 |
{ |
| 436 |
PyErr_SetString(PyExc_TypeError, "The address attributes must be a string or a unicode."); |
| 437 |
Py_RETURN_NONE; |
| 438 |
} |
| 439 |
|
| 440 |
self->address_path = pathtmp; |
| 441 |
Py_INCREF(self->address_path); |
| 442 |
|
| 443 |
(*self->mode_func_ptr)(self); |
| 444 |
|
| 445 |
return (PyObject *)self; |
| 446 |
} |
| 447 |
|
| 448 |
static PyObject * |
| 449 |
OscReceive_setInterpolation(OscReceive *self, PyObject *arg) |
| 450 |
{ |
| 451 |
ASSERT_ARG_NOT_NULL |
| 452 |
|
| 453 |
self->interpolation = PyLong_AsLong(arg); |
| 454 |
|
| 455 |
Py_RETURN_NONE; |
| 456 |
} |
| 457 |
|
| 458 |
static PyObject * OscReceive_getServer(OscReceive* self) { GET_SERVER }; |
| 459 |
static PyObject * OscReceive_getStream(OscReceive* self) { GET_STREAM }; |
| 460 |
static PyObject * OscReceive_setMul(OscReceive *self, PyObject *arg) { SET_MUL }; |
| 461 |
static PyObject * OscReceive_setAdd(OscReceive *self, PyObject *arg) { SET_ADD }; |
| 462 |
static PyObject * OscReceive_setSub(OscReceive *self, PyObject *arg) { SET_SUB }; |
| 463 |
static PyObject * OscReceive_setDiv(OscReceive *self, PyObject *arg) { SET_DIV }; |
| 464 |
|
| 465 |
static PyObject * OscReceive_play(OscReceive *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 466 |
static PyObject * OscReceive_stop(OscReceive *self, PyObject *args, PyObject *kwds) { STOP }; |
| 467 |
|
| 468 |
static PyObject * OscReceive_multiply(OscReceive *self, PyObject *arg) { MULTIPLY }; |
| 469 |
static PyObject * OscReceive_inplace_multiply(OscReceive *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 470 |
static PyObject * OscReceive_add(OscReceive *self, PyObject *arg) { ADD }; |
| 471 |
static PyObject * OscReceive_inplace_add(OscReceive *self, PyObject *arg) { INPLACE_ADD }; |
| 472 |
static PyObject * OscReceive_sub(OscReceive *self, PyObject *arg) { SUB }; |
| 473 |
static PyObject * OscReceive_inplace_sub(OscReceive *self, PyObject *arg) { INPLACE_SUB }; |
| 474 |
static PyObject * OscReceive_div(OscReceive *self, PyObject *arg) { DIV }; |
| 475 |
static PyObject * OscReceive_inplace_div(OscReceive *self, PyObject *arg) { INPLACE_DIV }; |
| 476 |
|
| 477 |
static PyMemberDef OscReceive_members[] = |
| 478 |
{ |
| 479 |
{"server", T_OBJECT_EX, offsetof(OscReceive, server), 0, "Pyo server."}, |
| 480 |
{"stream", T_OBJECT_EX, offsetof(OscReceive, stream), 0, "Stream object."}, |
| 481 |
{"mul", T_OBJECT_EX, offsetof(OscReceive, mul), 0, "Mul factor."}, |
| 482 |
{"add", T_OBJECT_EX, offsetof(OscReceive, add), 0, "Add factor."}, |
| 483 |
{NULL} /* Sentinel */ |
| 484 |
}; |
| 485 |
|
| 486 |
static PyMethodDef OscReceive_methods[] = |
| 487 |
{ |
| 488 |
{"getServer", (PyCFunction)OscReceive_getServer, METH_NOARGS, "Returns server object."}, |
| 489 |
{"_getStream", (PyCFunction)OscReceive_getStream, METH_NOARGS, "Returns stream object."}, |
| 490 |
{"play", (PyCFunction)OscReceive_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 491 |
{"stop", (PyCFunction)OscReceive_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 492 |
{"setInterpolation", (PyCFunction)OscReceive_setInterpolation, METH_O, "Sets interpolation on or off."}, |
| 493 |
{"setMul", (PyCFunction)OscReceive_setMul, METH_O, "Sets oscillator mul factor."}, |
| 494 |
{"setAdd", (PyCFunction)OscReceive_setAdd, METH_O, "Sets oscillator add factor."}, |
| 495 |
{"setSub", (PyCFunction)OscReceive_setSub, METH_O, "Sets inverse add factor."}, |
| 496 |
{"setDiv", (PyCFunction)OscReceive_setDiv, METH_O, "Sets inverse mul factor."}, |
| 497 |
{NULL} /* Sentinel */ |
| 498 |
}; |
| 499 |
|
| 500 |
static PyNumberMethods OscReceive_as_number = |
| 501 |
{ |
| 502 |
(binaryfunc)OscReceive_add, /*nb_add*/ |
| 503 |
(binaryfunc)OscReceive_sub, /*nb_subtract*/ |
| 504 |
(binaryfunc)OscReceive_multiply, /*nb_multiply*/ |
| 505 |
0, /*nb_remainder*/ |
| 506 |
0, /*nb_divmod*/ |
| 507 |
0, /*nb_power*/ |
| 508 |
0, /*nb_neg*/ |
| 509 |
0, /*nb_pos*/ |
| 510 |
0, /*(unaryfunc)array_abs,*/ |
| 511 |
0, /*nb_nonzero*/ |
| 512 |
0, /*nb_invert*/ |
| 513 |
0, /*nb_lshift*/ |
| 514 |
0, /*nb_rshift*/ |
| 515 |
0, /*nb_and*/ |
| 516 |
0, /*nb_xor*/ |
| 517 |
0, /*nb_or*/ |
| 518 |
0, /*nb_int*/ |
| 519 |
0, /*nb_long*/ |
| 520 |
0, /*nb_float*/ |
| 521 |
(binaryfunc)OscReceive_inplace_add, /*inplace_add*/ |
| 522 |
(binaryfunc)OscReceive_inplace_sub, /*inplace_subtract*/ |
| 523 |
(binaryfunc)OscReceive_inplace_multiply, /*inplace_multiply*/ |
| 524 |
0, /*inplace_remainder*/ |
| 525 |
0, /*inplace_power*/ |
| 526 |
0, /*inplace_lshift*/ |
| 527 |
0, /*inplace_rshift*/ |
| 528 |
0, /*inplace_and*/ |
| 529 |
0, /*inplace_xor*/ |
| 530 |
0, /*inplace_or*/ |
| 531 |
0, /*nb_floor_divide*/ |
| 532 |
(binaryfunc)OscReceive_div, /*nb_true_divide*/ |
| 533 |
0, /*nb_inplace_floor_divide*/ |
| 534 |
(binaryfunc)OscReceive_inplace_div, /*nb_inplace_true_divide*/ |
| 535 |
0, /* nb_index */ |
| 536 |
}; |
| 537 |
|
| 538 |
PyTypeObject OscReceiveType = |
| 539 |
{ |
| 540 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 541 |
"_pyo.OscReceive_base", /*tp_name*/ |
| 542 |
sizeof(OscReceive), /*tp_basicsize*/ |
| 543 |
0, /*tp_itemsize*/ |
| 544 |
(destructor)OscReceive_dealloc, /*tp_dealloc*/ |
| 545 |
0, /*tp_print*/ |
| 546 |
0, /*tp_getattr*/ |
| 547 |
0, /*tp_setattr*/ |
| 548 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 549 |
0, /*tp_repr*/ |
| 550 |
&OscReceive_as_number, /*tp_as_number*/ |
| 551 |
0, /*tp_as_sequence*/ |
| 552 |
0, /*tp_as_mapping*/ |
| 553 |
0, /*tp_hash */ |
| 554 |
0, /*tp_call*/ |
| 555 |
0, /*tp_str*/ |
| 556 |
0, /*tp_getattro*/ |
| 557 |
0, /*tp_setattro*/ |
| 558 |
0, /*tp_as_buffer*/ |
| 559 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 560 |
"OscReceive objects. Receive values via Open Sound Control protocol.", /* tp_doc */ |
| 561 |
(traverseproc)OscReceive_traverse, /* tp_traverse */ |
| 562 |
(inquiry)OscReceive_clear, /* tp_clear */ |
| 563 |
0, /* tp_richcompare */ |
| 564 |
0, /* tp_weaklistoffset */ |
| 565 |
0, /* tp_iter */ |
| 566 |
0, /* tp_iternext */ |
| 567 |
OscReceive_methods, /* tp_methods */ |
| 568 |
OscReceive_members, /* tp_members */ |
| 569 |
0, /* tp_getset */ |
| 570 |
0, /* tp_base */ |
| 571 |
0, /* tp_dict */ |
| 572 |
0, /* tp_descr_get */ |
| 573 |
0, /* tp_descr_set */ |
| 574 |
0, /* tp_dictoffset */ |
| 575 |
0, /* tp_init */ |
| 576 |
0, /* tp_alloc */ |
| 577 |
OscReceive_new, /* tp_new */ |
| 578 |
}; |
| 579 |
|
| 580 |
/* OSC send object */ |
| 581 |
typedef struct |
| 582 |
{ |
| 583 |
pyo_audio_HEAD |
| 584 |
PyObject *input; |
| 585 |
Stream *input_stream; |
| 586 |
PyObject *address_path; |
| 587 |
lo_address address; |
| 588 |
char *host; |
| 589 |
int port; |
| 590 |
int count; |
| 591 |
int bufrate; |
| 592 |
} OscSend; |
| 593 |
|
| 594 |
static void |
| 595 |
OscSend_compute_next_data_frame(OscSend *self) |
| 596 |
{ |
| 597 |
const char *path = NULL; |
| 598 |
self->count++; |
| 599 |
|
| 600 |
if (self->count >= self->bufrate) |
| 601 |
{ |
| 602 |
self->count = 0; |
| 603 |
MYFLT *in = Stream_getData((Stream *)self->input_stream); |
| 604 |
float value = (float)in[0]; |
| 605 |
|
| 606 |
if (PyBytes_Check(self->address_path)) |
| 607 |
path = PyBytes_AsString(self->address_path); |
| 608 |
else |
| 609 |
path = PyUnicode_AsUTF8(self->address_path); |
| 610 |
|
| 611 |
if (lo_send(self->address, path, "f", value) == -1) |
| 612 |
{ |
| 613 |
PySys_WriteStdout("OSC error %d: %s\n", |
| 614 |
lo_address_errno(self->address), |
| 615 |
lo_address_errstr(self->address)); |
| 616 |
} |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
static int |
| 621 |
OscSend_traverse(OscSend *self, visitproc visit, void *arg) |
| 622 |
{ |
| 623 |
pyo_VISIT |
| 624 |
Py_VISIT(self->address_path); |
| 625 |
Py_VISIT(self->input); |
| 626 |
return 0; |
| 627 |
} |
| 628 |
|
| 629 |
static int |
| 630 |
OscSend_clear(OscSend *self) |
| 631 |
{ |
| 632 |
pyo_CLEAR |
| 633 |
Py_CLEAR(self->address_path); |
| 634 |
Py_CLEAR(self->input); |
| 635 |
return 0; |
| 636 |
} |
| 637 |
|
| 638 |
static void |
| 639 |
OscSend_dealloc(OscSend* self) |
| 640 |
{ |
| 641 |
pyo_DEALLOC |
| 642 |
lo_address_free(self->address); |
| 643 |
OscSend_clear(self); |
| 644 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 645 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 646 |
} |
| 647 |
|
| 648 |
static PyObject * |
| 649 |
OscSend_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 650 |
{ |
| 651 |
int i; |
| 652 |
PyObject *inputtmp, *input_streamtmp, *pathtmp; |
| 653 |
OscSend *self; |
| 654 |
self = (OscSend *)type->tp_alloc(type, 0); |
| 655 |
|
| 656 |
self->host = NULL; |
| 657 |
self->count = 0; |
| 658 |
self->bufrate = 1; |
| 659 |
|
| 660 |
INIT_OBJECT_COMMON |
| 661 |
Stream_setFunctionPtr(self->stream, OscSend_compute_next_data_frame); |
| 662 |
|
| 663 |
static char *kwlist[] = {"input", "port", "address", "host", NULL}; |
| 664 |
|
| 665 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OiO|s", kwlist, &inputtmp, &self->port, &pathtmp, &self->host)) |
| 666 |
Py_RETURN_NONE; |
| 667 |
|
| 668 |
INIT_INPUT_STREAM |
| 669 |
|
| 670 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 671 |
|
| 672 |
if (!PyUnicode_Check(pathtmp)) |
| 673 |
{ |
| 674 |
PyErr_SetString(PyExc_TypeError, "The address attributes must be a string or a unicode (bytes or string in Python 3)."); |
| 675 |
Py_RETURN_NONE; |
| 676 |
} |
| 677 |
|
| 678 |
Py_INCREF(pathtmp); |
| 679 |
Py_XDECREF(self->address_path); |
| 680 |
self->address_path = pathtmp; |
| 681 |
|
| 682 |
char buf[20]; |
| 683 |
sprintf(buf, "%i", self->port); |
| 684 |
self->address = lo_address_new(self->host, buf); |
| 685 |
|
| 686 |
return (PyObject *)self; |
| 687 |
} |
| 688 |
|
| 689 |
static PyObject * |
| 690 |
OscSend_setBufferRate(OscSend *self, PyObject *arg) |
| 691 |
{ |
| 692 |
ASSERT_ARG_NOT_NULL |
| 693 |
|
| 694 |
self->bufrate = PyLong_AsLong(arg); |
| 695 |
|
| 696 |
if (self->bufrate < 1) |
| 697 |
self->bufrate = 1; |
| 698 |
|
| 699 |
Py_RETURN_NONE; |
| 700 |
} |
| 701 |
|
| 702 |
static PyObject * OscSend_getServer(OscSend* self) { GET_SERVER }; |
| 703 |
static PyObject * OscSend_getStream(OscSend* self) { GET_STREAM }; |
| 704 |
|
| 705 |
static PyObject * OscSend_play(OscSend *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 706 |
static PyObject * OscSend_stop(OscSend *self, PyObject *args, PyObject *kwds) { STOP }; |
| 707 |
|
| 708 |
static PyMemberDef OscSend_members[] = |
| 709 |
{ |
| 710 |
{"server", T_OBJECT_EX, offsetof(OscSend, server), 0, "Pyo server."}, |
| 711 |
{"stream", T_OBJECT_EX, offsetof(OscSend, stream), 0, "Stream object."}, |
| 712 |
{"input", T_OBJECT_EX, offsetof(OscSend, input), 0, "Input sound object."}, |
| 713 |
{NULL} /* Sentinel */ |
| 714 |
}; |
| 715 |
|
| 716 |
static PyMethodDef OscSend_methods[] = |
| 717 |
{ |
| 718 |
{"getServer", (PyCFunction)OscSend_getServer, METH_NOARGS, "Returns server object."}, |
| 719 |
{"_getStream", (PyCFunction)OscSend_getStream, METH_NOARGS, "Returns stream object."}, |
| 720 |
{"play", (PyCFunction)OscSend_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 721 |
{"stop", (PyCFunction)OscSend_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 722 |
{"setBufferRate", (PyCFunction)OscSend_setBufferRate, METH_O, "Set how many buffers to wait before sending a new value."}, |
| 723 |
{NULL} /* Sentinel */ |
| 724 |
}; |
| 725 |
|
| 726 |
PyTypeObject OscSendType = |
| 727 |
{ |
| 728 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 729 |
"_pyo.OscSend_base", /*tp_name*/ |
| 730 |
sizeof(OscSend), /*tp_basicsize*/ |
| 731 |
0, /*tp_itemsize*/ |
| 732 |
(destructor)OscSend_dealloc, /*tp_dealloc*/ |
| 733 |
0, /*tp_print*/ |
| 734 |
0, /*tp_getattr*/ |
| 735 |
0, /*tp_setattr*/ |
| 736 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 737 |
0, /*tp_repr*/ |
| 738 |
0, /*tp_as_number*/ |
| 739 |
0, /*tp_as_sequence*/ |
| 740 |
0, /*tp_as_mapping*/ |
| 741 |
0, /*tp_hash */ |
| 742 |
0, /*tp_call*/ |
| 743 |
0, /*tp_str*/ |
| 744 |
0, /*tp_getattro*/ |
| 745 |
0, /*tp_setattro*/ |
| 746 |
0, /*tp_as_buffer*/ |
| 747 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 748 |
"OscSend objects. Send values via Open Sound Control protocol.", /* tp_doc */ |
| 749 |
(traverseproc)OscSend_traverse, /* tp_traverse */ |
| 750 |
(inquiry)OscSend_clear, /* tp_clear */ |
| 751 |
0, /* tp_richcompare */ |
| 752 |
0, /* tp_weaklistoffset */ |
| 753 |
0, /* tp_iter */ |
| 754 |
0, /* tp_iternext */ |
| 755 |
OscSend_methods, /* tp_methods */ |
| 756 |
OscSend_members, /* tp_members */ |
| 757 |
0, /* tp_getset */ |
| 758 |
0, /* tp_base */ |
| 759 |
0, /* tp_dict */ |
| 760 |
0, /* tp_descr_get */ |
| 761 |
0, /* tp_descr_set */ |
| 762 |
0, /* tp_dictoffset */ |
| 763 |
0, /* tp_init */ |
| 764 |
0, /* tp_alloc */ |
| 765 |
OscSend_new, /* tp_new */ |
| 766 |
}; |
| 767 |
|
| 768 |
/* OscDataSend object */ |
| 769 |
typedef struct |
| 770 |
{ |
| 771 |
pyo_audio_HEAD |
| 772 |
PyObject *value; |
| 773 |
PyObject *address_path; |
| 774 |
lo_address address; |
| 775 |
char *host; |
| 776 |
char *types; |
| 777 |
int port; |
| 778 |
int something_to_send; |
| 779 |
int num_items; |
| 780 |
} OscDataSend; |
| 781 |
|
| 782 |
static void |
| 783 |
OscDataSend_compute_next_data_frame(OscDataSend *self) |
| 784 |
{ |
| 785 |
int i, j = 0; |
| 786 |
Py_ssize_t blobsize = 0; |
| 787 |
PyObject *inlist = NULL; |
| 788 |
PyObject *datalist = NULL; |
| 789 |
char *blobdata = NULL; |
| 790 |
uint8_t midi[4]; |
| 791 |
lo_blob blob = NULL; |
| 792 |
const char *path = NULL; |
| 793 |
lo_message msg; |
| 794 |
|
| 795 |
while (self->something_to_send) |
| 796 |
{ |
| 797 |
if (PyBytes_Check(self->address_path)) |
| 798 |
path = PyBytes_AsString(self->address_path); |
| 799 |
else |
| 800 |
path = PyUnicode_AsUTF8(self->address_path); |
| 801 |
|
| 802 |
msg = lo_message_new(); |
| 803 |
|
| 804 |
self->something_to_send--; |
| 805 |
inlist = PyList_GetItem(self->value, self->something_to_send); |
| 806 |
|
| 807 |
for (i = 0; i < self->num_items; i++) |
| 808 |
{ |
| 809 |
switch (self->types[i]) |
| 810 |
{ |
| 811 |
case LO_INT32: |
| 812 |
lo_message_add_int32(msg, PyLong_AsLong(PyList_GET_ITEM(inlist, i))); |
| 813 |
break; |
| 814 |
|
| 815 |
case LO_INT64: |
| 816 |
lo_message_add_int64(msg, (long)PyLong_AsLong(PyList_GET_ITEM(inlist, i))); |
| 817 |
break; |
| 818 |
|
| 819 |
case LO_FLOAT: |
| 820 |
lo_message_add_float(msg, (float)PyFloat_AsDouble(PyList_GET_ITEM(inlist, i))); |
| 821 |
break; |
| 822 |
|
| 823 |
case LO_DOUBLE: |
| 824 |
lo_message_add_double(msg, (double)PyFloat_AsDouble(PyList_GET_ITEM(inlist, i))); |
| 825 |
break; |
| 826 |
|
| 827 |
case LO_STRING: |
| 828 |
lo_message_add_string(msg, PyUnicode_AsUTF8(PyList_GET_ITEM(inlist, i))); |
| 829 |
break; |
| 830 |
|
| 831 |
case LO_CHAR: |
| 832 |
lo_message_add_char(msg, (char)PyUnicode_AsUTF8(PyList_GET_ITEM(inlist, i))[0]); |
| 833 |
break; |
| 834 |
|
| 835 |
case LO_BLOB: |
| 836 |
datalist = PyList_GET_ITEM(inlist, i); |
| 837 |
blobsize = PyList_Size(datalist); |
| 838 |
blobdata = (char *)PyMem_RawMalloc(blobsize * sizeof(char)); |
| 839 |
|
| 840 |
for (j = 0; j < blobsize; j++) |
| 841 |
{ |
| 842 |
blobdata[j] = (char)PyUnicode_AsUTF8(PyList_GET_ITEM(datalist, j))[0]; |
| 843 |
} |
| 844 |
|
| 845 |
blob = lo_blob_new(blobsize * sizeof(char), blobdata); |
| 846 |
lo_message_add_blob(msg, blob); |
| 847 |
break; |
| 848 |
|
| 849 |
case LO_MIDI: |
| 850 |
datalist = PyList_GET_ITEM(inlist, i); |
| 851 |
|
| 852 |
for (j = 0; j < 4; j++) |
| 853 |
{ |
| 854 |
midi[j] = (uint8_t)PyLong_AsLong(PyList_GET_ITEM(datalist, j)); |
| 855 |
} |
| 856 |
|
| 857 |
lo_message_add_midi(msg, midi); |
| 858 |
break; |
| 859 |
|
| 860 |
case LO_NIL: |
| 861 |
lo_message_add_nil(msg); |
| 862 |
break; |
| 863 |
|
| 864 |
case LO_TRUE: |
| 865 |
lo_message_add_true(msg); |
| 866 |
break; |
| 867 |
|
| 868 |
case LO_FALSE: |
| 869 |
lo_message_add_false(msg); |
| 870 |
break; |
| 871 |
|
| 872 |
default: |
| 873 |
break; |
| 874 |
} |
| 875 |
} |
| 876 |
|
| 877 |
if (lo_send_message(self->address, path, msg) == -1) |
| 878 |
{ |
| 879 |
PySys_WriteStdout("OSC error %d: %s\n", lo_address_errno(self->address), |
| 880 |
lo_address_errstr(self->address)); |
| 881 |
} |
| 882 |
|
| 883 |
Py_DECREF(inlist); |
| 884 |
PySequence_DelItem(self->value, self->something_to_send); |
| 885 |
lo_message_free(msg); |
| 886 |
|
| 887 |
if (blob != NULL) |
| 888 |
lo_blob_free(blob); |
| 889 |
|
| 890 |
if (blobdata != NULL) |
| 891 |
PyMem_RawFree(blobdata); |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
static int |
| 896 |
OscDataSend_traverse(OscDataSend *self, visitproc visit, void *arg) |
| 897 |
{ |
| 898 |
pyo_VISIT |
| 899 |
Py_VISIT(self->value); |
| 900 |
Py_VISIT(self->address_path); |
| 901 |
return 0; |
| 902 |
} |
| 903 |
|
| 904 |
static int |
| 905 |
OscDataSend_clear(OscDataSend *self) |
| 906 |
{ |
| 907 |
pyo_CLEAR |
| 908 |
Py_CLEAR(self->value); |
| 909 |
Py_CLEAR(self->address_path); |
| 910 |
return 0; |
| 911 |
} |
| 912 |
|
| 913 |
static void |
| 914 |
OscDataSend_dealloc(OscDataSend* self) |
| 915 |
{ |
| 916 |
pyo_DEALLOC |
| 917 |
lo_address_free(self->address); |
| 918 |
OscDataSend_clear(self); |
| 919 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 920 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 921 |
} |
| 922 |
|
| 923 |
static PyObject * |
| 924 |
OscDataSend_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 925 |
{ |
| 926 |
int i; |
| 927 |
PyObject *pathtmp; |
| 928 |
OscDataSend *self; |
| 929 |
self = (OscDataSend *)type->tp_alloc(type, 0); |
| 930 |
|
| 931 |
self->value = PyList_New(0); |
| 932 |
self->something_to_send = 0; |
| 933 |
self->host = NULL; |
| 934 |
|
| 935 |
INIT_OBJECT_COMMON |
| 936 |
Stream_setFunctionPtr(self->stream, OscDataSend_compute_next_data_frame); |
| 937 |
|
| 938 |
static char *kwlist[] = {"types", "port", "address", "host", NULL}; |
| 939 |
|
| 940 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "siO|s", kwlist, &self->types, &self->port, &pathtmp, &self->host)) |
| 941 |
Py_RETURN_NONE; |
| 942 |
|
| 943 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 944 |
|
| 945 |
if (!PyUnicode_Check(pathtmp)) |
| 946 |
{ |
| 947 |
PyErr_SetString(PyExc_TypeError, "The address attributes must be of type string or unicode (bytes or string in Python 3)."); |
| 948 |
Py_RETURN_NONE; |
| 949 |
} |
| 950 |
|
| 951 |
self->num_items = strlen(self->types); |
| 952 |
|
| 953 |
Py_INCREF(pathtmp); |
| 954 |
Py_XDECREF(self->address_path); |
| 955 |
self->address_path = pathtmp; |
| 956 |
|
| 957 |
char buf[20]; |
| 958 |
sprintf(buf, "%i", self->port); |
| 959 |
self->address = lo_address_new(self->host, buf); |
| 960 |
|
| 961 |
return (PyObject *)self; |
| 962 |
} |
| 963 |
|
| 964 |
static PyObject * OscDataSend_getServer(OscDataSend* self) { GET_SERVER }; |
| 965 |
static PyObject * OscDataSend_getStream(OscDataSend* self) { GET_STREAM }; |
| 966 |
|
| 967 |
static PyObject * OscDataSend_play(OscDataSend *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 968 |
static PyObject * OscDataSend_stop(OscDataSend *self, PyObject *args, PyObject *kwds) { STOP }; |
| 969 |
|
| 970 |
static PyObject * |
| 971 |
OscDataSend_send(OscDataSend *self, PyObject *arg) |
| 972 |
{ |
| 973 |
ASSERT_ARG_NOT_NULL |
| 974 |
|
| 975 |
if (PyList_Check(arg)) |
| 976 |
{ |
| 977 |
Py_INCREF(arg); |
| 978 |
PyList_Append(self->value, arg); |
| 979 |
self->something_to_send++; |
| 980 |
} |
| 981 |
else |
| 982 |
PySys_WriteStdout("OscDataSend: argument to send() method must be a list of values.\n"); |
| 983 |
|
| 984 |
Py_RETURN_NONE; |
| 985 |
} |
| 986 |
|
| 987 |
static PyMemberDef OscDataSend_members[] = |
| 988 |
{ |
| 989 |
{"server", T_OBJECT_EX, offsetof(OscDataSend, server), 0, "Pyo server."}, |
| 990 |
{"stream", T_OBJECT_EX, offsetof(OscDataSend, stream), 0, "Stream object."}, |
| 991 |
{NULL} /* Sentinel */ |
| 992 |
}; |
| 993 |
|
| 994 |
static PyMethodDef OscDataSend_methods[] = |
| 995 |
{ |
| 996 |
{"getServer", (PyCFunction)OscDataSend_getServer, METH_NOARGS, "Returns server object."}, |
| 997 |
{"_getStream", (PyCFunction)OscDataSend_getStream, METH_NOARGS, "Returns stream object."}, |
| 998 |
{"send", (PyCFunction)OscDataSend_send, METH_O, "Sets values to be sent."}, |
| 999 |
{"play", (PyCFunction)OscDataSend_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1000 |
{"stop", (PyCFunction)OscDataSend_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1001 |
{NULL} /* Sentinel */ |
| 1002 |
}; |
| 1003 |
|
| 1004 |
PyTypeObject OscDataSendType = |
| 1005 |
{ |
| 1006 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1007 |
"_pyo.OscDataSend_base", /*tp_name*/ |
| 1008 |
sizeof(OscDataSend), /*tp_basicsize*/ |
| 1009 |
0, /*tp_itemsize*/ |
| 1010 |
(destructor)OscDataSend_dealloc, /*tp_dealloc*/ |
| 1011 |
0, /*tp_print*/ |
| 1012 |
0, /*tp_getattr*/ |
| 1013 |
0, /*tp_setattr*/ |
| 1014 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1015 |
0, /*tp_repr*/ |
| 1016 |
0, /*tp_as_number*/ |
| 1017 |
0, /*tp_as_sequence*/ |
| 1018 |
0, /*tp_as_mapping*/ |
| 1019 |
0, /*tp_hash */ |
| 1020 |
0, /*tp_call*/ |
| 1021 |
0, /*tp_str*/ |
| 1022 |
0, /*tp_getattro*/ |
| 1023 |
0, /*tp_setattro*/ |
| 1024 |
0, /*tp_as_buffer*/ |
| 1025 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1026 |
"OscDataSend objects. Send data values via Open Sound Control protocol.", /* tp_doc */ |
| 1027 |
(traverseproc)OscDataSend_traverse, /* tp_traverse */ |
| 1028 |
(inquiry)OscDataSend_clear, /* tp_clear */ |
| 1029 |
0, /* tp_richcompare */ |
| 1030 |
0, /* tp_weaklistoffset */ |
| 1031 |
0, /* tp_iter */ |
| 1032 |
0, /* tp_iternext */ |
| 1033 |
OscDataSend_methods, /* tp_methods */ |
| 1034 |
OscDataSend_members, /* tp_members */ |
| 1035 |
0, /* tp_getset */ |
| 1036 |
0, /* tp_base */ |
| 1037 |
0, /* tp_dict */ |
| 1038 |
0, /* tp_descr_get */ |
| 1039 |
0, /* tp_descr_set */ |
| 1040 |
0, /* tp_dictoffset */ |
| 1041 |
0, /* tp_init */ |
| 1042 |
0, /* tp_alloc */ |
| 1043 |
OscDataSend_new, /* tp_new */ |
| 1044 |
}; |
| 1045 |
|
| 1046 |
/* main OscDataReceive */ |
| 1047 |
typedef struct |
| 1048 |
{ |
| 1049 |
pyo_audio_HEAD |
| 1050 |
lo_server osc_server; |
| 1051 |
PyObject *address_path; |
| 1052 |
PyObject *callable; |
| 1053 |
int port; |
| 1054 |
} OscDataReceive; |
| 1055 |
|
| 1056 |
/* lo_method_handler' (aka 'int (*)(const char *, const char *, lo_arg **, int, struct lo_message_ *, void *)') */ |
| 1057 |
int OscDataReceive_handler(const char *path, const char *types, lo_arg **argv, int argc, |
| 1058 |
lo_message data, void *user_data) |
| 1059 |
{ |
| 1060 |
OscDataReceive *self = user_data; |
| 1061 |
PyObject *tup, *result = NULL; |
| 1062 |
lo_blob blob = NULL; |
| 1063 |
char *blobdata = NULL; |
| 1064 |
uint32_t blobsize = 0; |
| 1065 |
PyObject *charlist = NULL; |
| 1066 |
tup = PyTuple_New(argc + 1); |
| 1067 |
int i, ok = 0; |
| 1068 |
uint32_t j = 0; |
| 1069 |
|
| 1070 |
Py_ssize_t lsize = PyList_Size(self->address_path); |
| 1071 |
|
| 1072 |
for (i = 0; i < lsize; i++) |
| 1073 |
{ |
| 1074 |
if (PyBytes_Check(PyList_GET_ITEM(self->address_path, i))) |
| 1075 |
{ |
| 1076 |
if (lo_pattern_match(path, PyBytes_AsString(PyList_GET_ITEM(self->address_path, i)))) |
| 1077 |
{ |
| 1078 |
ok = 1; |
| 1079 |
break; |
| 1080 |
} |
| 1081 |
} |
| 1082 |
else |
| 1083 |
{ |
| 1084 |
if (lo_pattern_match(path, PyUnicode_AsUTF8(PyList_GET_ITEM(self->address_path, i)))) |
| 1085 |
{ |
| 1086 |
ok = 1; |
| 1087 |
break; |
| 1088 |
} |
| 1089 |
} |
| 1090 |
} |
| 1091 |
|
| 1092 |
if (ok) |
| 1093 |
{ |
| 1094 |
PyTuple_SET_ITEM(tup, 0, PyUnicode_FromString(path)); |
| 1095 |
|
| 1096 |
for (i = 0; i < argc; i++) |
| 1097 |
{ |
| 1098 |
switch (types[i]) |
| 1099 |
{ |
| 1100 |
case LO_INT32: |
| 1101 |
PyTuple_SET_ITEM(tup, i + 1, PyLong_FromLong(argv[i]->i)); |
| 1102 |
break; |
| 1103 |
|
| 1104 |
case LO_INT64: |
| 1105 |
PyTuple_SET_ITEM(tup, i + 1, PyLong_FromLong(argv[i]->h)); |
| 1106 |
break; |
| 1107 |
|
| 1108 |
case LO_FLOAT: |
| 1109 |
PyTuple_SET_ITEM(tup, i + 1, PyFloat_FromDouble(argv[i]->f)); |
| 1110 |
break; |
| 1111 |
|
| 1112 |
case LO_DOUBLE: |
| 1113 |
PyTuple_SET_ITEM(tup, i + 1, PyFloat_FromDouble(argv[i]->d)); |
| 1114 |
break; |
| 1115 |
|
| 1116 |
case LO_STRING: |
| 1117 |
PyTuple_SET_ITEM(tup, i + 1, PyUnicode_FromString(&argv[i]->s)); |
| 1118 |
break; |
| 1119 |
|
| 1120 |
case LO_CHAR: |
| 1121 |
PyTuple_SET_ITEM(tup, i + 1, PyUnicode_FromFormat("%c", argv[i]->c)); |
| 1122 |
break; |
| 1123 |
|
| 1124 |
case LO_BLOB: |
| 1125 |
blob = (lo_blob)argv[i]; |
| 1126 |
blobsize = lo_blob_datasize(blob); |
| 1127 |
blobdata = lo_blob_dataptr(blob); |
| 1128 |
charlist = PyList_New(blobsize); |
| 1129 |
|
| 1130 |
for (j = 0; j < blobsize; j++) |
| 1131 |
{ |
| 1132 |
PyList_SET_ITEM(charlist, j, PyUnicode_FromFormat("%c", blobdata[j])); |
| 1133 |
} |
| 1134 |
|
| 1135 |
PyTuple_SET_ITEM(tup, i + 1, charlist); |
| 1136 |
break; |
| 1137 |
|
| 1138 |
case LO_MIDI: |
| 1139 |
charlist = PyList_New(4); |
| 1140 |
|
| 1141 |
for (j = 0; j < 4; j++) |
| 1142 |
{ |
| 1143 |
PyList_SET_ITEM(charlist, j, PyLong_FromLong(argv[i]->m[j])); |
| 1144 |
} |
| 1145 |
|
| 1146 |
PyTuple_SET_ITEM(tup, i + 1, charlist); |
| 1147 |
break; |
| 1148 |
|
| 1149 |
case LO_NIL: |
| 1150 |
Py_INCREF(Py_None); |
| 1151 |
PyTuple_SET_ITEM(tup, i + 1, Py_None); |
| 1152 |
break; |
| 1153 |
|
| 1154 |
case LO_TRUE: |
| 1155 |
Py_INCREF(Py_True); |
| 1156 |
PyTuple_SET_ITEM(tup, i + 1, Py_True); |
| 1157 |
break; |
| 1158 |
|
| 1159 |
case LO_FALSE: |
| 1160 |
Py_INCREF(Py_False); |
| 1161 |
PyTuple_SET_ITEM(tup, i + 1, Py_False); |
| 1162 |
break; |
| 1163 |
|
| 1164 |
default: |
| 1165 |
break; |
| 1166 |
} |
| 1167 |
} |
| 1168 |
|
| 1169 |
result = PyObject_Call(self->callable, tup, NULL); |
| 1170 |
|
| 1171 |
if (result == NULL) |
| 1172 |
PyErr_Print(); |
| 1173 |
} |
| 1174 |
|
| 1175 |
Py_XDECREF(tup); |
| 1176 |
Py_XDECREF(result); |
| 1177 |
Py_XDECREF(charlist); |
| 1178 |
return 0; |
| 1179 |
} |
| 1180 |
|
| 1181 |
static void |
| 1182 |
OscDataReceive_compute_next_data_frame(OscDataReceive *self) |
| 1183 |
{ |
| 1184 |
while (lo_server_recv_noblock(self->osc_server, 0) != 0) {}; |
| 1185 |
} |
| 1186 |
|
| 1187 |
static int |
| 1188 |
OscDataReceive_traverse(OscDataReceive *self, visitproc visit, void *arg) |
| 1189 |
{ |
| 1190 |
pyo_VISIT |
| 1191 |
Py_VISIT(self->address_path); |
| 1192 |
Py_VISIT(self->callable); |
| 1193 |
return 0; |
| 1194 |
} |
| 1195 |
|
| 1196 |
static int |
| 1197 |
OscDataReceive_clear(OscDataReceive *self) |
| 1198 |
{ |
| 1199 |
pyo_CLEAR |
| 1200 |
Py_CLEAR(self->address_path); |
| 1201 |
Py_CLEAR(self->callable); |
| 1202 |
return 0; |
| 1203 |
} |
| 1204 |
|
| 1205 |
static void |
| 1206 |
OscDataReceive_dealloc(OscDataReceive* self) |
| 1207 |
{ |
| 1208 |
lo_server_free(self->osc_server); |
| 1209 |
pyo_DEALLOC |
| 1210 |
OscDataReceive_clear(self); |
| 1211 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 1212 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1213 |
} |
| 1214 |
|
| 1215 |
static PyObject * |
| 1216 |
OscDataReceive_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1217 |
{ |
| 1218 |
int i; |
| 1219 |
PyObject *pathtmp, *calltmp; |
| 1220 |
OscDataReceive *self; |
| 1221 |
self = (OscDataReceive *)type->tp_alloc(type, 0); |
| 1222 |
|
| 1223 |
INIT_OBJECT_COMMON |
| 1224 |
Stream_setFunctionPtr(self->stream, OscDataReceive_compute_next_data_frame); |
| 1225 |
|
| 1226 |
static char *kwlist[] = {"port", "address", "callable", NULL}; |
| 1227 |
|
| 1228 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "iOO", kwlist, &self->port, &pathtmp, &calltmp)) |
| 1229 |
Py_RETURN_NONE; |
| 1230 |
|
| 1231 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 1232 |
|
| 1233 |
Py_XDECREF(self->callable); |
| 1234 |
self->callable = calltmp; |
| 1235 |
Py_INCREF(self->callable); |
| 1236 |
|
| 1237 |
if (PyList_Check(pathtmp)) |
| 1238 |
{ |
| 1239 |
Py_INCREF(pathtmp); |
| 1240 |
Py_XDECREF(self->address_path); |
| 1241 |
self->address_path = pathtmp; |
| 1242 |
} |
| 1243 |
else |
| 1244 |
{ |
| 1245 |
PyErr_SetString(PyExc_TypeError, "The address attributes must be a list of strings and/or unicodes."); |
| 1246 |
Py_RETURN_NONE; |
| 1247 |
} |
| 1248 |
|
| 1249 |
char buf[20]; |
| 1250 |
sprintf(buf, "%i", self->port); |
| 1251 |
self->osc_server = lo_server_new(buf, error); |
| 1252 |
|
| 1253 |
lo_server_add_method(self->osc_server, NULL, NULL, OscDataReceive_handler, self); |
| 1254 |
|
| 1255 |
return (PyObject *)self; |
| 1256 |
} |
| 1257 |
|
| 1258 |
static PyObject * OscDataReceive_getServer(OscDataReceive* self) { GET_SERVER }; |
| 1259 |
static PyObject * OscDataReceive_getStream(OscDataReceive* self) { GET_STREAM }; |
| 1260 |
static PyObject * OscDataReceive_play(OscDataReceive *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 1261 |
static PyObject * OscDataReceive_stop(OscDataReceive *self, PyObject *args, PyObject *kwds) { STOP }; |
| 1262 |
|
| 1263 |
static PyObject * |
| 1264 |
OscDataReceive_addAddress(OscDataReceive *self, PyObject *arg) |
| 1265 |
{ |
| 1266 |
int i; |
| 1267 |
|
| 1268 |
if (arg != NULL) |
| 1269 |
{ |
| 1270 |
if (PyUnicode_Check(arg)) |
| 1271 |
PyList_Append(self->address_path, arg); |
| 1272 |
else if (PyList_Check(arg)) |
| 1273 |
{ |
| 1274 |
Py_ssize_t len = PyList_Size(arg); |
| 1275 |
|
| 1276 |
for (i = 0; i < len; i++) |
| 1277 |
{ |
| 1278 |
PyList_Append(self->address_path, PyList_GET_ITEM(arg, i)); |
| 1279 |
} |
| 1280 |
} |
| 1281 |
} |
| 1282 |
|
| 1283 |
Py_RETURN_NONE; |
| 1284 |
} |
| 1285 |
|
| 1286 |
static PyObject * |
| 1287 |
OscDataReceive_delAddress(OscDataReceive *self, PyObject *arg) |
| 1288 |
{ |
| 1289 |
if (arg != NULL) |
| 1290 |
{ |
| 1291 |
if (PyLong_Check(arg)) |
| 1292 |
{ |
| 1293 |
PySequence_DelItem(self->address_path, PyLong_AsLong(arg)); |
| 1294 |
} |
| 1295 |
} |
| 1296 |
|
| 1297 |
Py_RETURN_NONE; |
| 1298 |
} |
| 1299 |
|
| 1300 |
static PyMemberDef OscDataReceive_members[] = |
| 1301 |
{ |
| 1302 |
{"server", T_OBJECT_EX, offsetof(OscDataReceive, server), 0, "Pyo server."}, |
| 1303 |
{"stream", T_OBJECT_EX, offsetof(OscDataReceive, stream), 0, "Stream object."}, |
| 1304 |
{NULL} /* Sentinel */ |
| 1305 |
}; |
| 1306 |
|
| 1307 |
static PyMethodDef OscDataReceive_methods[] = |
| 1308 |
{ |
| 1309 |
{"getServer", (PyCFunction)OscDataReceive_getServer, METH_NOARGS, "Returns server object."}, |
| 1310 |
{"_getStream", (PyCFunction)OscDataReceive_getStream, METH_NOARGS, "Returns stream object."}, |
| 1311 |
{"play", (PyCFunction)OscDataReceive_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1312 |
{"stop", (PyCFunction)OscDataReceive_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1313 |
{"addAddress", (PyCFunction)OscDataReceive_addAddress, METH_O, "Add new paths to the object."}, |
| 1314 |
{"delAddress", (PyCFunction)OscDataReceive_delAddress, METH_O, "Remove path from the object."}, |
| 1315 |
{NULL} /* Sentinel */ |
| 1316 |
}; |
| 1317 |
|
| 1318 |
PyTypeObject OscDataReceiveType = |
| 1319 |
{ |
| 1320 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1321 |
"_pyo.OscDataReceive_base", /*tp_name*/ |
| 1322 |
sizeof(OscDataReceive), /*tp_basicsize*/ |
| 1323 |
0, /*tp_itemsize*/ |
| 1324 |
(destructor)OscDataReceive_dealloc, /*tp_dealloc*/ |
| 1325 |
0, /*tp_print*/ |
| 1326 |
0, /*tp_getattr*/ |
| 1327 |
0, /*tp_setattr*/ |
| 1328 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1329 |
0, /*tp_repr*/ |
| 1330 |
0, /*tp_as_number*/ |
| 1331 |
0, /*tp_as_sequence*/ |
| 1332 |
0, /*tp_as_mapping*/ |
| 1333 |
0, /*tp_hash */ |
| 1334 |
0, /*tp_call*/ |
| 1335 |
0, /*tp_str*/ |
| 1336 |
0, /*tp_getattro*/ |
| 1337 |
0, /*tp_setattro*/ |
| 1338 |
0, /*tp_as_buffer*/ |
| 1339 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1340 |
"OscDataReceive objects. Receive values via Open Sound Control protocol.", /* tp_doc */ |
| 1341 |
(traverseproc)OscDataReceive_traverse, /* tp_traverse */ |
| 1342 |
(inquiry)OscDataReceive_clear, /* tp_clear */ |
| 1343 |
0, /* tp_richcompare */ |
| 1344 |
0, /* tp_weaklistoffset */ |
| 1345 |
0, /* tp_iter */ |
| 1346 |
0, /* tp_iternext */ |
| 1347 |
OscDataReceive_methods, /* tp_methods */ |
| 1348 |
OscDataReceive_members, /* tp_members */ |
| 1349 |
0, /* tp_getset */ |
| 1350 |
0, /* tp_base */ |
| 1351 |
0, /* tp_dict */ |
| 1352 |
0, /* tp_descr_get */ |
| 1353 |
0, /* tp_descr_set */ |
| 1354 |
0, /* tp_dictoffset */ |
| 1355 |
0, /* tp_init */ |
| 1356 |
0, /* tp_alloc */ |
| 1357 |
OscDataReceive_new, /* tp_new */ |
| 1358 |
}; |
| 1359 |
|
| 1360 |
/* main OSC list receiver */ |
| 1361 |
typedef struct |
| 1362 |
{ |
| 1363 |
pyo_audio_HEAD |
| 1364 |
lo_server osc_server; |
| 1365 |
PyObject *dict; |
| 1366 |
PyObject *address_path; |
| 1367 |
int port; |
| 1368 |
int num; |
| 1369 |
} OscListReceiver; |
| 1370 |
|
| 1371 |
/* lo_method_handler' (aka 'int (*)(const char *, const char *, lo_arg **, int, struct lo_message_ *, void *)') */ |
| 1372 |
int OscListReceiver_handler(const char *path, const char *types, lo_arg **argv, int argc, |
| 1373 |
lo_message data, void *user_data) |
| 1374 |
{ |
| 1375 |
OscListReceiver *self = user_data; |
| 1376 |
|
| 1377 |
int i; |
| 1378 |
PyObject *flist; |
| 1379 |
flist = PyList_New(self->num); |
| 1380 |
|
| 1381 |
for (i = 0; i < self->num; i++) |
| 1382 |
{ |
| 1383 |
PyObject *valueObj = PyFloat_FromDouble(argv[i]->FLOAT_VALUE); |
| 1384 |
PyList_SET_ITEM(flist, i, valueObj); |
| 1385 |
Py_DECREF(valueObj); |
| 1386 |
} |
| 1387 |
|
| 1388 |
PyObject *pathObj = PyUnicode_FromString(path); |
| 1389 |
PyDict_SetItem(self->dict, pathObj, flist); |
| 1390 |
Py_DECREF(pathObj); |
| 1391 |
Py_DECREF(flist); |
| 1392 |
return 0; |
| 1393 |
} |
| 1394 |
|
| 1395 |
PyObject * |
| 1396 |
OscListReceiver_getValue(OscListReceiver *self, PyObject *path) |
| 1397 |
{ |
| 1398 |
PyObject *value = PyDict_GetItem(self->dict, path); |
| 1399 |
Py_INCREF(value); |
| 1400 |
return value; |
| 1401 |
} |
| 1402 |
|
| 1403 |
static void |
| 1404 |
OscListReceiver_compute_next_data_frame(OscListReceiver *self) |
| 1405 |
{ |
| 1406 |
while (lo_server_recv_noblock(self->osc_server, 0) != 0) {}; |
| 1407 |
} |
| 1408 |
|
| 1409 |
static int |
| 1410 |
OscListReceiver_traverse(OscListReceiver *self, visitproc visit, void *arg) |
| 1411 |
{ |
| 1412 |
pyo_VISIT |
| 1413 |
Py_VISIT(self->dict); |
| 1414 |
Py_VISIT(self->address_path); |
| 1415 |
return 0; |
| 1416 |
} |
| 1417 |
|
| 1418 |
static int |
| 1419 |
OscListReceiver_clear(OscListReceiver *self) |
| 1420 |
{ |
| 1421 |
pyo_CLEAR |
| 1422 |
Py_CLEAR(self->dict); |
| 1423 |
Py_CLEAR(self->address_path); |
| 1424 |
return 0; |
| 1425 |
} |
| 1426 |
|
| 1427 |
static void |
| 1428 |
OscListReceiver_dealloc(OscListReceiver* self) |
| 1429 |
{ |
| 1430 |
lo_server_free(self->osc_server); |
| 1431 |
pyo_DEALLOC |
| 1432 |
OscListReceiver_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 |
OscListReceiver_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1439 |
{ |
| 1440 |
int i, j; |
| 1441 |
PyObject *pathtmp, *flist; |
| 1442 |
OscListReceiver *self; |
| 1443 |
self = (OscListReceiver *)type->tp_alloc(type, 0); |
| 1444 |
|
| 1445 |
self->num = 8; |
| 1446 |
|
| 1447 |
INIT_OBJECT_COMMON |
| 1448 |
Stream_setFunctionPtr(self->stream, OscListReceiver_compute_next_data_frame); |
| 1449 |
|
| 1450 |
static char *kwlist[] = {"port", "address", "num", NULL}; |
| 1451 |
|
| 1452 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "iO|i", kwlist, &self->port, &pathtmp, &self->num)) |
| 1453 |
Py_RETURN_NONE; |
| 1454 |
|
| 1455 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 1456 |
|
| 1457 |
Py_XDECREF(self->dict); |
| 1458 |
self->dict = PyDict_New(); |
| 1459 |
Py_INCREF(self->dict); |
| 1460 |
|
| 1461 |
if (PyList_Check(pathtmp)) |
| 1462 |
{ |
| 1463 |
Py_INCREF(pathtmp); |
| 1464 |
Py_XDECREF(self->address_path); |
| 1465 |
self->address_path = pathtmp; |
| 1466 |
} |
| 1467 |
else |
| 1468 |
{ |
| 1469 |
PyErr_SetString(PyExc_TypeError, "The address attributes must be a list of strings and/or unicodes."); |
| 1470 |
Py_RETURN_NONE; |
| 1471 |
} |
| 1472 |
|
| 1473 |
int lsize = PyList_Size(self->address_path); |
| 1474 |
|
| 1475 |
PyObject *zero = PyFloat_FromDouble(0.); |
| 1476 |
for (i = 0; i < lsize; i++) |
| 1477 |
{ |
| 1478 |
flist = PyList_New(self->num); |
| 1479 |
|
| 1480 |
for (j = 0; j < self->num; j++) |
| 1481 |
{ |
| 1482 |
PyList_SET_ITEM(flist, j, zero); |
| 1483 |
} |
| 1484 |
|
| 1485 |
PyDict_SetItem(self->dict, PyList_GET_ITEM(self->address_path, i), flist); |
| 1486 |
Py_DECREF(flist); |
| 1487 |
} |
| 1488 |
Py_DECREF(zero); |
| 1489 |
|
| 1490 |
char buf[20]; |
| 1491 |
sprintf(buf, "%i", self->port); |
| 1492 |
self->osc_server = lo_server_new(buf, error); |
| 1493 |
|
| 1494 |
lo_server_add_method(self->osc_server, NULL, NULL, OscListReceiver_handler, self); |
| 1495 |
|
| 1496 |
return (PyObject *)self; |
| 1497 |
} |
| 1498 |
|
| 1499 |
static PyObject * |
| 1500 |
OscListReceiver_addAddress(OscListReceiver *self, PyObject *arg) |
| 1501 |
{ |
| 1502 |
PyObject *flist; |
| 1503 |
int i, j; |
| 1504 |
|
| 1505 |
if (PyUnicode_Check(arg)) |
| 1506 |
{ |
| 1507 |
flist = PyList_New(self->num); |
| 1508 |
|
| 1509 |
PyObject *zero = PyFloat_FromDouble(0.); |
| 1510 |
for (j = 0; j < self->num; j++) |
| 1511 |
{ |
| 1512 |
PyList_SET_ITEM(flist, j, zero); |
| 1513 |
} |
| 1514 |
Py_DECREF(zero); |
| 1515 |
|
| 1516 |
PyDict_SetItem(self->dict, arg, flist); |
| 1517 |
} |
| 1518 |
else if (PyList_Check(arg)) |
| 1519 |
{ |
| 1520 |
Py_ssize_t lsize = PyList_Size(arg); |
| 1521 |
|
| 1522 |
PyObject *zero = PyFloat_FromDouble(0.); |
| 1523 |
for (i = 0; i < lsize; i++) |
| 1524 |
{ |
| 1525 |
flist = PyList_New(self->num); |
| 1526 |
|
| 1527 |
for (j = 0; j < self->num; j++) |
| 1528 |
{ |
| 1529 |
PyList_SET_ITEM(flist, j, zero); |
| 1530 |
} |
| 1531 |
|
| 1532 |
PyDict_SetItem(self->dict, PyList_GET_ITEM(arg, i), flist); |
| 1533 |
} |
| 1534 |
Py_DECREF(zero); |
| 1535 |
} |
| 1536 |
|
| 1537 |
Py_RETURN_NONE; |
| 1538 |
} |
| 1539 |
|
| 1540 |
static PyObject * |
| 1541 |
OscListReceiver_delAddress(OscListReceiver *self, PyObject *arg) |
| 1542 |
{ |
| 1543 |
int i; |
| 1544 |
|
| 1545 |
if (PyUnicode_Check(arg)) |
| 1546 |
{ |
| 1547 |
PyDict_DelItem(self->dict, arg); |
| 1548 |
} |
| 1549 |
else if (PyList_Check(arg)) |
| 1550 |
{ |
| 1551 |
Py_ssize_t lsize = PyList_Size(arg); |
| 1552 |
|
| 1553 |
for (i = 0; i < lsize; i++) |
| 1554 |
{ |
| 1555 |
if (PyDict_Contains(self->dict, PyList_GET_ITEM(arg, i))) |
| 1556 |
PyDict_DelItem(self->dict, PyList_GET_ITEM(arg, i)); |
| 1557 |
} |
| 1558 |
} |
| 1559 |
|
| 1560 |
Py_RETURN_NONE; |
| 1561 |
} |
| 1562 |
|
| 1563 |
static PyObject * |
| 1564 |
OscListReceiver_setValue(OscListReceiver *self, PyObject *args, PyObject *kwds) |
| 1565 |
{ |
| 1566 |
PyObject *address, *value; |
| 1567 |
|
| 1568 |
static char *kwlist[] = {"address", "value", NULL}; |
| 1569 |
|
| 1570 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &address, &value)) |
| 1571 |
Py_RETURN_NONE; |
| 1572 |
|
| 1573 |
PyDict_SetItem(self->dict, address, value); |
| 1574 |
Py_RETURN_NONE; |
| 1575 |
} |
| 1576 |
|
| 1577 |
static PyObject * OscListReceiver_getServer(OscListReceiver* self) { GET_SERVER }; |
| 1578 |
static PyObject * OscListReceiver_getStream(OscListReceiver* self) { GET_STREAM }; |
| 1579 |
|
| 1580 |
static PyObject * OscListReceiver_play(OscListReceiver *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 1581 |
static PyObject * OscListReceiver_stop(OscListReceiver *self, PyObject *args, PyObject *kwds) { STOP }; |
| 1582 |
|
| 1583 |
static PyMemberDef OscListReceiver_members[] = |
| 1584 |
{ |
| 1585 |
{"server", T_OBJECT_EX, offsetof(OscListReceiver, server), 0, "Pyo server."}, |
| 1586 |
{"stream", T_OBJECT_EX, offsetof(OscListReceiver, stream), 0, "Stream object."}, |
| 1587 |
{NULL} /* Sentinel */ |
| 1588 |
}; |
| 1589 |
|
| 1590 |
static PyMethodDef OscListReceiver_methods[] = |
| 1591 |
{ |
| 1592 |
{"getServer", (PyCFunction)OscListReceiver_getServer, METH_NOARGS, "Returns server object."}, |
| 1593 |
{"_getStream", (PyCFunction)OscListReceiver_getStream, METH_NOARGS, "Returns stream object."}, |
| 1594 |
{"play", (PyCFunction)OscListReceiver_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1595 |
{"stop", (PyCFunction)OscListReceiver_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1596 |
{"addAddress", (PyCFunction)OscListReceiver_addAddress, METH_O, "Add a new address to the dictionary."}, |
| 1597 |
{"delAddress", (PyCFunction)OscListReceiver_delAddress, METH_O, "Remove an address from the dictionary."}, |
| 1598 |
{"setValue", (PyCFunction)OscListReceiver_setValue, METH_VARARGS | METH_KEYWORDS, "Sets value for a specified address."}, |
| 1599 |
{NULL} /* Sentinel */ |
| 1600 |
}; |
| 1601 |
|
| 1602 |
PyTypeObject OscListReceiverType = |
| 1603 |
{ |
| 1604 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1605 |
"_pyo.OscListReceiver_base", /*tp_name*/ |
| 1606 |
sizeof(OscListReceiver), /*tp_basicsize*/ |
| 1607 |
0, /*tp_itemsize*/ |
| 1608 |
(destructor)OscListReceiver_dealloc, /*tp_dealloc*/ |
| 1609 |
0, /*tp_print*/ |
| 1610 |
0, /*tp_getattr*/ |
| 1611 |
0, /*tp_setattr*/ |
| 1612 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1613 |
0, /*tp_repr*/ |
| 1614 |
0, /*tp_as_number*/ |
| 1615 |
0, /*tp_as_sequence*/ |
| 1616 |
0, /*tp_as_mapping*/ |
| 1617 |
0, /*tp_hash */ |
| 1618 |
0, /*tp_call*/ |
| 1619 |
0, /*tp_str*/ |
| 1620 |
0, /*tp_getattro*/ |
| 1621 |
0, /*tp_setattro*/ |
| 1622 |
0, /*tp_as_buffer*/ |
| 1623 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1624 |
"OscListReceiver objects. Receive list of values via Open Sound Control protocol.", /* tp_doc */ |
| 1625 |
(traverseproc)OscListReceiver_traverse, /* tp_traverse */ |
| 1626 |
(inquiry)OscListReceiver_clear, /* tp_clear */ |
| 1627 |
0, /* tp_richcompare */ |
| 1628 |
0, /* tp_weaklistoffset */ |
| 1629 |
0, /* tp_iter */ |
| 1630 |
0, /* tp_iternext */ |
| 1631 |
OscListReceiver_methods, /* tp_methods */ |
| 1632 |
OscListReceiver_members, /* tp_members */ |
| 1633 |
0, /* tp_getset */ |
| 1634 |
0, /* tp_base */ |
| 1635 |
0, /* tp_dict */ |
| 1636 |
0, /* tp_descr_get */ |
| 1637 |
0, /* tp_descr_set */ |
| 1638 |
0, /* tp_dictoffset */ |
| 1639 |
0, /* tp_init */ |
| 1640 |
0, /* tp_alloc */ |
| 1641 |
OscListReceiver_new, /* tp_new */ |
| 1642 |
}; |
| 1643 |
|
| 1644 |
/* OSC list receiver stream object */ |
| 1645 |
typedef struct |
| 1646 |
{ |
| 1647 |
pyo_audio_HEAD |
| 1648 |
PyObject *input; |
| 1649 |
PyObject *address_path; |
| 1650 |
MYFLT value; |
| 1651 |
MYFLT factor; |
| 1652 |
int order; |
| 1653 |
int interpolation; |
| 1654 |
int modebuffer[2]; |
| 1655 |
} OscListReceive; |
| 1656 |
|
| 1657 |
static void OscListReceive_postprocessing_ii(OscListReceive *self) { POST_PROCESSING_II }; |
| 1658 |
static void OscListReceive_postprocessing_ai(OscListReceive *self) { POST_PROCESSING_AI }; |
| 1659 |
static void OscListReceive_postprocessing_ia(OscListReceive *self) { POST_PROCESSING_IA }; |
| 1660 |
static void OscListReceive_postprocessing_aa(OscListReceive *self) { POST_PROCESSING_AA }; |
| 1661 |
static void OscListReceive_postprocessing_ireva(OscListReceive *self) { POST_PROCESSING_IREVA }; |
| 1662 |
static void OscListReceive_postprocessing_areva(OscListReceive *self) { POST_PROCESSING_AREVA }; |
| 1663 |
static void OscListReceive_postprocessing_revai(OscListReceive *self) { POST_PROCESSING_REVAI }; |
| 1664 |
static void OscListReceive_postprocessing_revaa(OscListReceive *self) { POST_PROCESSING_REVAA }; |
| 1665 |
static void OscListReceive_postprocessing_revareva(OscListReceive *self) { POST_PROCESSING_REVAREVA }; |
| 1666 |
|
| 1667 |
static void |
| 1668 |
OscListReceive_setProcMode(OscListReceive *self) |
| 1669 |
{ |
| 1670 |
int muladdmode; |
| 1671 |
muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10; |
| 1672 |
|
| 1673 |
switch (muladdmode) |
| 1674 |
{ |
| 1675 |
case 0: |
| 1676 |
self->muladd_func_ptr = OscListReceive_postprocessing_ii; |
| 1677 |
break; |
| 1678 |
|
| 1679 |
case 1: |
| 1680 |
self->muladd_func_ptr = OscListReceive_postprocessing_ai; |
| 1681 |
break; |
| 1682 |
|
| 1683 |
case 2: |
| 1684 |
self->muladd_func_ptr = OscListReceive_postprocessing_revai; |
| 1685 |
break; |
| 1686 |
|
| 1687 |
case 10: |
| 1688 |
self->muladd_func_ptr = OscListReceive_postprocessing_ia; |
| 1689 |
break; |
| 1690 |
|
| 1691 |
case 11: |
| 1692 |
self->muladd_func_ptr = OscListReceive_postprocessing_aa; |
| 1693 |
break; |
| 1694 |
|
| 1695 |
case 12: |
| 1696 |
self->muladd_func_ptr = OscListReceive_postprocessing_revaa; |
| 1697 |
break; |
| 1698 |
|
| 1699 |
case 20: |
| 1700 |
self->muladd_func_ptr = OscListReceive_postprocessing_ireva; |
| 1701 |
break; |
| 1702 |
|
| 1703 |
case 21: |
| 1704 |
self->muladd_func_ptr = OscListReceive_postprocessing_areva; |
| 1705 |
break; |
| 1706 |
|
| 1707 |
case 22: |
| 1708 |
self->muladd_func_ptr = OscListReceive_postprocessing_revareva; |
| 1709 |
break; |
| 1710 |
} |
| 1711 |
} |
| 1712 |
|
| 1713 |
static void |
| 1714 |
OscListReceive_compute_next_data_frame(OscListReceive *self) |
| 1715 |
{ |
| 1716 |
int i; |
| 1717 |
PyObject *flist = OscListReceiver_getValue((OscListReceiver *)self->input, self->address_path); |
| 1718 |
MYFLT val = PyFloat_AsDouble(PyList_GET_ITEM(flist, self->order)); |
| 1719 |
|
| 1720 |
if (self->interpolation == 1) |
| 1721 |
{ |
| 1722 |
|
| 1723 |
for (i = 0; i < self->bufsize; i++) |
| 1724 |
{ |
| 1725 |
self->data[i] = self->value = self->value + (val - self->value) * self->factor; |
| 1726 |
} |
| 1727 |
} |
| 1728 |
else |
| 1729 |
{ |
| 1730 |
for (i = 0; i < self->bufsize; i++) |
| 1731 |
{ |
| 1732 |
self->data[i] = self->value = val; |
| 1733 |
} |
| 1734 |
} |
| 1735 |
|
| 1736 |
(*self->muladd_func_ptr)(self); |
| 1737 |
} |
| 1738 |
|
| 1739 |
static int |
| 1740 |
OscListReceive_traverse(OscListReceive *self, visitproc visit, void *arg) |
| 1741 |
{ |
| 1742 |
pyo_VISIT |
| 1743 |
Py_VISIT(self->input); |
| 1744 |
Py_VISIT(self->address_path); |
| 1745 |
return 0; |
| 1746 |
} |
| 1747 |
|
| 1748 |
static int |
| 1749 |
OscListReceive_clear(OscListReceive *self) |
| 1750 |
{ |
| 1751 |
pyo_CLEAR |
| 1752 |
Py_CLEAR(self->input); |
| 1753 |
Py_CLEAR(self->address_path); |
| 1754 |
return 0; |
| 1755 |
} |
| 1756 |
|
| 1757 |
static void |
| 1758 |
OscListReceive_dealloc(OscListReceive* self) |
| 1759 |
{ |
| 1760 |
pyo_DEALLOC |
| 1761 |
OscListReceive_clear(self); |
| 1762 |
Py_TYPE(self->stream)->tp_free((PyObject*)self->stream); |
| 1763 |
Py_TYPE(self)->tp_free((PyObject*)self); |
| 1764 |
} |
| 1765 |
|
| 1766 |
static PyObject * |
| 1767 |
OscListReceive_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 1768 |
{ |
| 1769 |
int i; |
| 1770 |
PyObject *inputtmp = NULL, *pathtmp = NULL, *multmp = NULL, *addtmp = NULL;; |
| 1771 |
OscListReceive *self; |
| 1772 |
self = (OscListReceive *)type->tp_alloc(type, 0); |
| 1773 |
|
| 1774 |
self->order = 0; |
| 1775 |
self->value = 0.; |
| 1776 |
self->interpolation = 1; |
| 1777 |
self->modebuffer[0] = 0; |
| 1778 |
self->modebuffer[1] = 0; |
| 1779 |
|
| 1780 |
INIT_OBJECT_COMMON |
| 1781 |
|
| 1782 |
self->factor = 1. / (0.01 * self->sr); |
| 1783 |
|
| 1784 |
Stream_setFunctionPtr(self->stream, OscListReceive_compute_next_data_frame); |
| 1785 |
self->mode_func_ptr = OscListReceive_setProcMode; |
| 1786 |
|
| 1787 |
static char *kwlist[] = {"input", "address", "order", "mul", "add", NULL}; |
| 1788 |
|
| 1789 |
if (! PyArg_ParseTupleAndKeywords(args, kwds, "OOi|OO", kwlist, &inputtmp, &pathtmp, &self->order, &multmp, &addtmp)) |
| 1790 |
Py_RETURN_NONE; |
| 1791 |
|
| 1792 |
self->input = inputtmp; |
| 1793 |
Py_INCREF(self->input); |
| 1794 |
|
| 1795 |
if (multmp) |
| 1796 |
{ |
| 1797 |
PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp); |
| 1798 |
} |
| 1799 |
|
| 1800 |
if (addtmp) |
| 1801 |
{ |
| 1802 |
PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp); |
| 1803 |
} |
| 1804 |
|
| 1805 |
PyObject_CallMethod(self->server, "addStream", "O", self->stream); |
| 1806 |
|
| 1807 |
if (!PyUnicode_Check(pathtmp)) |
| 1808 |
{ |
| 1809 |
PyErr_SetString(PyExc_TypeError, "OscListReceive: the address attributes must be a string or a unicode."); |
| 1810 |
Py_RETURN_NONE; |
| 1811 |
} |
| 1812 |
|
| 1813 |
self->address_path = pathtmp; |
| 1814 |
Py_INCREF(self->address_path); |
| 1815 |
|
| 1816 |
(*self->mode_func_ptr)(self); |
| 1817 |
|
| 1818 |
return (PyObject *)self; |
| 1819 |
} |
| 1820 |
|
| 1821 |
static PyObject * |
| 1822 |
OscListReceive_setInterpolation(OscListReceive *self, PyObject *arg) |
| 1823 |
{ |
| 1824 |
ASSERT_ARG_NOT_NULL |
| 1825 |
|
| 1826 |
self->interpolation = PyLong_AsLong(arg); |
| 1827 |
|
| 1828 |
Py_RETURN_NONE; |
| 1829 |
} |
| 1830 |
|
| 1831 |
static PyObject * OscListReceive_getServer(OscListReceive* self) { GET_SERVER }; |
| 1832 |
static PyObject * OscListReceive_getStream(OscListReceive* self) { GET_STREAM }; |
| 1833 |
static PyObject * OscListReceive_setMul(OscListReceive *self, PyObject *arg) { SET_MUL }; |
| 1834 |
static PyObject * OscListReceive_setAdd(OscListReceive *self, PyObject *arg) { SET_ADD }; |
| 1835 |
static PyObject * OscListReceive_setSub(OscListReceive *self, PyObject *arg) { SET_SUB }; |
| 1836 |
static PyObject * OscListReceive_setDiv(OscListReceive *self, PyObject *arg) { SET_DIV }; |
| 1837 |
|
| 1838 |
static PyObject * OscListReceive_play(OscListReceive *self, PyObject *args, PyObject *kwds) { PLAY }; |
| 1839 |
static PyObject * OscListReceive_stop(OscListReceive *self, PyObject *args, PyObject *kwds) { STOP }; |
| 1840 |
|
| 1841 |
static PyObject * OscListReceive_multiply(OscListReceive *self, PyObject *arg) { MULTIPLY }; |
| 1842 |
static PyObject * OscListReceive_inplace_multiply(OscListReceive *self, PyObject *arg) { INPLACE_MULTIPLY }; |
| 1843 |
static PyObject * OscListReceive_add(OscListReceive *self, PyObject *arg) { ADD }; |
| 1844 |
static PyObject * OscListReceive_inplace_add(OscListReceive *self, PyObject *arg) { INPLACE_ADD }; |
| 1845 |
static PyObject * OscListReceive_sub(OscListReceive *self, PyObject *arg) { SUB }; |
| 1846 |
static PyObject * OscListReceive_inplace_sub(OscListReceive *self, PyObject *arg) { INPLACE_SUB }; |
| 1847 |
static PyObject * OscListReceive_div(OscListReceive *self, PyObject *arg) { DIV }; |
| 1848 |
static PyObject * OscListReceive_inplace_div(OscListReceive *self, PyObject *arg) { INPLACE_DIV }; |
| 1849 |
|
| 1850 |
static PyMemberDef OscListReceive_members[] = |
| 1851 |
{ |
| 1852 |
{"server", T_OBJECT_EX, offsetof(OscListReceive, server), 0, "Pyo server."}, |
| 1853 |
{"stream", T_OBJECT_EX, offsetof(OscListReceive, stream), 0, "Stream object."}, |
| 1854 |
{"mul", T_OBJECT_EX, offsetof(OscListReceive, mul), 0, "Mul factor."}, |
| 1855 |
{"add", T_OBJECT_EX, offsetof(OscListReceive, add), 0, "Add factor."}, |
| 1856 |
{NULL} /* Sentinel */ |
| 1857 |
}; |
| 1858 |
|
| 1859 |
static PyMethodDef OscListReceive_methods[] = |
| 1860 |
{ |
| 1861 |
{"getServer", (PyCFunction)OscListReceive_getServer, METH_NOARGS, "Returns server object."}, |
| 1862 |
{"_getStream", (PyCFunction)OscListReceive_getStream, METH_NOARGS, "Returns stream object."}, |
| 1863 |
{"play", (PyCFunction)OscListReceive_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."}, |
| 1864 |
{"stop", (PyCFunction)OscListReceive_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."}, |
| 1865 |
{"setInterpolation", (PyCFunction)OscListReceive_setInterpolation, METH_O, "Sets interpolation on or off."}, |
| 1866 |
{"setMul", (PyCFunction)OscListReceive_setMul, METH_O, "Sets oscillator mul factor."}, |
| 1867 |
{"setAdd", (PyCFunction)OscListReceive_setAdd, METH_O, "Sets oscillator add factor."}, |
| 1868 |
{"setSub", (PyCFunction)OscListReceive_setSub, METH_O, "Sets inverse add factor."}, |
| 1869 |
{"setDiv", (PyCFunction)OscListReceive_setDiv, METH_O, "Sets inverse mul factor."}, |
| 1870 |
{NULL} /* Sentinel */ |
| 1871 |
}; |
| 1872 |
|
| 1873 |
static PyNumberMethods OscListReceive_as_number = |
| 1874 |
{ |
| 1875 |
(binaryfunc)OscListReceive_add, /*nb_add*/ |
| 1876 |
(binaryfunc)OscListReceive_sub, /*nb_subtract*/ |
| 1877 |
(binaryfunc)OscListReceive_multiply, /*nb_multiply*/ |
| 1878 |
0, /*nb_remainder*/ |
| 1879 |
0, /*nb_divmod*/ |
| 1880 |
0, /*nb_power*/ |
| 1881 |
0, /*nb_neg*/ |
| 1882 |
0, /*nb_pos*/ |
| 1883 |
0, /*(unaryfunc)array_abs,*/ |
| 1884 |
0, /*nb_nonzero*/ |
| 1885 |
0, /*nb_invert*/ |
| 1886 |
0, /*nb_lshift*/ |
| 1887 |
0, /*nb_rshift*/ |
| 1888 |
0, /*nb_and*/ |
| 1889 |
0, /*nb_xor*/ |
| 1890 |
0, /*nb_or*/ |
| 1891 |
0, /*nb_int*/ |
| 1892 |
0, /*nb_long*/ |
| 1893 |
0, /*nb_float*/ |
| 1894 |
(binaryfunc)OscListReceive_inplace_add, /*inplace_add*/ |
| 1895 |
(binaryfunc)OscListReceive_inplace_sub, /*inplace_subtract*/ |
| 1896 |
(binaryfunc)OscListReceive_inplace_multiply, /*inplace_multiply*/ |
| 1897 |
0, /*inplace_remainder*/ |
| 1898 |
0, /*inplace_power*/ |
| 1899 |
0, /*inplace_lshift*/ |
| 1900 |
0, /*inplace_rshift*/ |
| 1901 |
0, /*inplace_and*/ |
| 1902 |
0, /*inplace_xor*/ |
| 1903 |
0, /*inplace_or*/ |
| 1904 |
0, /*nb_floor_divide*/ |
| 1905 |
(binaryfunc)OscListReceive_div, /*nb_true_divide*/ |
| 1906 |
0, /*nb_inplace_floor_divide*/ |
| 1907 |
(binaryfunc)OscListReceive_inplace_div, /*nb_inplace_true_divide*/ |
| 1908 |
0, /* nb_index */ |
| 1909 |
}; |
| 1910 |
|
| 1911 |
PyTypeObject OscListReceiveType = |
| 1912 |
{ |
| 1913 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 1914 |
"_pyo.OscListReceive_base", /*tp_name*/ |
| 1915 |
sizeof(OscListReceive), /*tp_basicsize*/ |
| 1916 |
0, /*tp_itemsize*/ |
| 1917 |
(destructor)OscListReceive_dealloc, /*tp_dealloc*/ |
| 1918 |
0, /*tp_print*/ |
| 1919 |
0, /*tp_getattr*/ |
| 1920 |
0, /*tp_setattr*/ |
| 1921 |
0, /*tp_as_async (tp_compare in Python 2)*/ |
| 1922 |
0, /*tp_repr*/ |
| 1923 |
&OscListReceive_as_number, /*tp_as_number*/ |
| 1924 |
0, /*tp_as_sequence*/ |
| 1925 |
0, /*tp_as_mapping*/ |
| 1926 |
0, /*tp_hash */ |
| 1927 |
0, /*tp_call*/ |
| 1928 |
0, /*tp_str*/ |
| 1929 |
0, /*tp_getattro*/ |
| 1930 |
0, /*tp_setattro*/ |
| 1931 |
0, /*tp_as_buffer*/ |
| 1932 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
| 1933 |
"OscListReceive objects. Receive one value from a list of floats via Open Sound Control protocol.", /* tp_doc */ |
| 1934 |
(traverseproc)OscListReceive_traverse, /* tp_traverse */ |
| 1935 |
(inquiry)OscListReceive_clear, /* tp_clear */ |
| 1936 |
0, /* tp_richcompare */ |
| 1937 |
0, /* tp_weaklistoffset */ |
| 1938 |
0, /* tp_iter */ |
| 1939 |
0, /* tp_iternext */ |
| 1940 |
OscListReceive_methods, /* tp_methods */ |
| 1941 |
OscListReceive_members, /* tp_members */ |
| 1942 |
0, /* tp_getset */ |
| 1943 |
0, /* tp_base */ |
| 1944 |
0, /* tp_dict */ |
| 1945 |
0, /* tp_descr_get */ |
| 1946 |
0, /* tp_descr_set */ |
| 1947 |
0, /* tp_dictoffset */ |
| 1948 |
0, /* tp_init */ |
| 1949 |
0, /* tp_alloc */ |
| 1950 |
OscListReceive_new, /* tp_new */ |
| 1951 |
}; |