Mercurial > hg > vampy-host
comparison vampyhost.cpp @ 7:d29c25695f5e
On the plugin initialisation is now convertiing the 3 Python integers to C Py_ssize_t.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Tue, 12 Mar 2013 18:20:06 +0000 |
parents | aacfd14a0ae2 |
children | db72f98403b4 d0d91312e5a2 |
comparison
equal
deleted
inserted
replaced
6:aacfd14a0ae2 | 7:d29c25695f5e |
---|---|
44 | 44 |
45 /* MODULE HELPER FUNCTIONS */ | 45 /* MODULE HELPER FUNCTIONS */ |
46 PyDoc_STRVAR(xx_foo_doc, "Some description"); //!!! | 46 PyDoc_STRVAR(xx_foo_doc, "Some description"); //!!! |
47 | 47 |
48 /*obtain C plugin handle and key from pyCobject */ | 48 /*obtain C plugin handle and key from pyCobject */ |
49 bool getPluginHandle | 49 bool getPluginHandle |
50 (PyObject *pyPluginHandle, Plugin **plugin, string **pKey=NULL) { | 50 (PyObject *pyPluginHandle, Plugin **plugin, string **pKey=NULL) { |
51 | 51 |
52 //char errormsg[]="Wrong input argument: Plugin Handle required."; | 52 //char errormsg[]="Wrong input argument: Plugin Handle required."; |
53 | 53 |
54 *plugin = NULL; | 54 *plugin = NULL; |
55 if (!PyCObject_Check(pyPluginHandle)) return false; | 55 if (!PyCObject_Check(pyPluginHandle)) return false; |
56 | 56 |
57 //try to convert to Plugin pointer | 57 //try to convert to Plugin pointer |
58 Plugin *p = (Plugin*) PyCObject_AsVoidPtr(pyPluginHandle); | 58 Plugin *p = (Plugin*) PyCObject_AsVoidPtr(pyPluginHandle); |
59 if (!p) return false; | 59 if (!p) return false; |
60 | 60 |
61 string pId; | 61 string pId; |
62 | 62 |
63 if (pKey) { | 63 if (pKey) { |
64 *pKey = (string*) PyCObject_GetDesc(pyPluginHandle); | 64 *pKey = (string*) PyCObject_GetDesc(pyPluginHandle); |
69 | 69 |
70 void *pKey = PyCObject_GetDesc(pyPluginHandle); | 70 void *pKey = PyCObject_GetDesc(pyPluginHandle); |
71 if (!pKey) return false; | 71 if (!pKey) return false; |
72 pId = *(string*) pKey; | 72 pId = *(string*) pKey; |
73 } | 73 } |
74 | 74 |
75 string::size_type pos = pId.find(':'); | 75 string::size_type pos = pId.find(':'); |
76 if (pos == string::npos) return false; | 76 if (pos == string::npos) return false; |
77 | 77 |
78 pId = pId.substr(pId.rfind(':')+1); | 78 pId = pId.substr(pId.rfind(':')+1); |
79 string identifier = p->getIdentifier(); | 79 string identifier = p->getIdentifier(); |
80 | 80 |
81 if (pId.compare(identifier)) return false; | 81 if (pId.compare(identifier)) return false; |
82 | 82 |
83 *plugin = p; | 83 *plugin = p; |
84 return true; | 84 return true; |
85 } | 85 } |
89 */ | 89 */ |
90 | 90 |
91 | 91 |
92 | 92 |
93 /* | 93 /* |
94 VAMPYHOST MAIN | 94 VAMPYHOST MAIN |
95 --------------------------------------------------------------------- | 95 --------------------------------------------------------------------- |
96 */ | 96 */ |
97 | 97 |
98 /* ENUMERATE PLUGINS*/ | 98 /* ENUMERATE PLUGINS*/ |
99 | 99 |
100 static PyObject * | 100 static PyObject * |
101 vampyhost_enumeratePlugins(PyObject *self, PyObject *args) | 101 vampyhost_enumeratePlugins(PyObject *self, PyObject *args) |
102 { | 102 { |
103 string retType; | 103 string retType; |
104 | 104 |
105 if (!PyArg_ParseTuple(args, "|s:enumeratePlugins", &retType)) | 105 if (!PyArg_ParseTuple(args, "|s:enumeratePlugins", &retType)) |
106 return NULL; | 106 return NULL; |
107 | 107 |
108 //list available plugins | 108 //list available plugins |
109 PluginLoader *loader = PluginLoader::getInstance(); | 109 PluginLoader *loader = PluginLoader::getInstance(); |
120 string path = loader->getLibraryPathForPlugin(plugins[i]); | 120 string path = loader->getLibraryPathForPlugin(plugins[i]); |
121 libraryMap.insert(LibraryMap::value_type(path, plugins[i])); | 121 libraryMap.insert(LibraryMap::value_type(path, plugins[i])); |
122 | 122 |
123 PyObject *pyPluginKey = PyString_FromString(plugins[i].c_str()); | 123 PyObject *pyPluginKey = PyString_FromString(plugins[i].c_str()); |
124 PyList_SET_ITEM(pyList,i,pyPluginKey); | 124 PyList_SET_ITEM(pyList,i,pyPluginKey); |
125 | 125 |
126 } | 126 } |
127 | 127 |
128 PyList_Sort(pyList); | 128 PyList_Sort(pyList); |
129 return pyList; | 129 return pyList; |
130 } | 130 } |
147 | 147 |
148 //check pluginKey Validity | 148 //check pluginKey Validity |
149 string::size_type ki = pluginKey.find(':'); | 149 string::size_type ki = pluginKey.find(':'); |
150 if (ki == string::npos) { | 150 if (ki == string::npos) { |
151 PyErr_SetString(PyExc_TypeError, | 151 PyErr_SetString(PyExc_TypeError, |
152 "String input argument required: pluginLibrary:Identifier"); | 152 "String input argument required: pluginLibrary:Identifier"); |
153 return NULL; | 153 return NULL; |
154 } | 154 } |
155 | 155 |
156 PluginLoader *loader = PluginLoader::getInstance(); | 156 PluginLoader *loader = PluginLoader::getInstance(); |
157 string path = loader->getLibraryPathForPlugin(pluginKey); | 157 string path = loader->getLibraryPathForPlugin(pluginKey); |
177 | 177 |
178 //check pluginKey Validity | 178 //check pluginKey Validity |
179 string::size_type ki = pluginKey.find(':'); | 179 string::size_type ki = pluginKey.find(':'); |
180 if (ki == string::npos) { | 180 if (ki == string::npos) { |
181 PyErr_SetString(PyExc_TypeError, | 181 PyErr_SetString(PyExc_TypeError, |
182 "String input argument required: pluginLibrary:Identifier"); | 182 "String input argument required: pluginLibrary:Identifier"); |
183 return NULL; | 183 return NULL; |
184 } | 184 } |
185 | 185 |
186 PluginLoader *loader = PluginLoader::getInstance(); | 186 PluginLoader *loader = PluginLoader::getInstance(); |
187 PluginLoader::PluginCategoryHierarchy | 187 PluginLoader::PluginCategoryHierarchy |
188 category = loader->getPluginCategory(pluginKey); | 188 category = loader->getPluginCategory(pluginKey); |
189 string catstring; | 189 string catstring; |
190 | 190 |
191 if (!category.empty()) { | 191 if (!category.empty()) { |
192 catstring = ""; | 192 catstring = ""; |
212 string pluginKey; | 212 string pluginKey; |
213 | 213 |
214 if (!PyArg_ParseTuple(args, "O", &pyPluginHandle)) { | 214 if (!PyArg_ParseTuple(args, "O", &pyPluginHandle)) { |
215 PyErr_SetString(PyExc_TypeError, | 215 PyErr_SetString(PyExc_TypeError, |
216 "Invalid argument: plugin handle or plugin key required."); | 216 "Invalid argument: plugin handle or plugin key required."); |
217 return NULL; | 217 return NULL; |
218 } | 218 } |
219 | 219 |
220 //check if we have a plugin key string or a handle object | 220 //check if we have a plugin key string or a handle object |
221 if (PyString_Check(pyPluginHandle) ) { | 221 if (PyString_Check(pyPluginHandle) ) { |
222 | 222 |
223 pluginKey.assign(PyString_AS_STRING(pyPluginHandle)); | 223 pluginKey.assign(PyString_AS_STRING(pyPluginHandle)); |
224 //check pluginKey Validity | 224 //check pluginKey Validity |
225 string::size_type ki = pluginKey.find(':'); | 225 string::size_type ki = pluginKey.find(':'); |
226 if (ki == string::npos) { | 226 if (ki == string::npos) { |
227 PyErr_SetString(PyExc_TypeError, | 227 PyErr_SetString(PyExc_TypeError, |
228 "String input argument required: pluginLibrary:Identifier"); | 228 "String input argument required: pluginLibrary:Identifier"); |
229 return NULL; | 229 return NULL; |
230 } | 230 } |
231 | 231 |
232 } else { | 232 } else { |
233 | 233 |
234 string *key; | 234 string *key; |
235 Plugin *plugin; | 235 Plugin *plugin; |
236 | 236 |
237 if ( !getPluginHandle(pyPluginHandle, &plugin, &key) ) { | 237 if ( !getPluginHandle(pyPluginHandle, &plugin, &key) ) { |
238 PyErr_SetString(PyExc_TypeError, | 238 PyErr_SetString(PyExc_TypeError, |
239 "Invalid or deleted plugin handle."); | 239 "Invalid or deleted plugin handle."); |
240 return NULL; } | 240 return NULL; } |
241 pluginKey.assign(*key); | 241 pluginKey.assign(*key); |
242 } | 242 } |
243 | 243 |
244 //This code creates new instance of the plugin anyway | 244 //This code creates new instance of the plugin anyway |
245 PluginLoader *loader = PluginLoader::getInstance(); | 245 PluginLoader *loader = PluginLoader::getInstance(); |
246 | 246 |
247 //load plugin | 247 //load plugin |
248 Plugin *plugin = loader->loadPlugin | 248 Plugin *plugin = loader->loadPlugin |
249 (pluginKey, 48000, PluginLoader::ADAPT_ALL_SAFE); | 249 (pluginKey, 48000, PluginLoader::ADAPT_ALL_SAFE); |
250 if (!plugin) { | 250 if (!plugin) { |
251 string pyerr("Failed to load plugin: "); pyerr += pluginKey; | 251 string pyerr("Failed to load plugin: "); pyerr += pluginKey; |
252 PyErr_SetString(PyExc_TypeError,pyerr.c_str()); | 252 PyErr_SetString(PyExc_TypeError,pyerr.c_str()); |
253 return NULL; | 253 return NULL; |
254 } | 254 } |
255 | 255 |
256 Plugin::OutputList outputs = plugin->getOutputDescriptors(); | 256 Plugin::OutputList outputs = plugin->getOutputDescriptors(); |
257 //Plugin::OutputDescriptor od; | 257 //Plugin::OutputDescriptor od; |
258 | 258 |
259 if (outputs.size()<1) { | 259 if (outputs.size()<1) { |
260 string pyerr("Plugin has no output: "); pyerr += pluginKey; | 260 string pyerr("Plugin has no output: "); pyerr += pluginKey; |
261 PyErr_SetString(PyExc_TypeError,pyerr.c_str()); | 261 PyErr_SetString(PyExc_TypeError,pyerr.c_str()); |
262 return NULL; | 262 return NULL; |
263 } | 263 } |
264 | 264 |
265 //New list object | 265 //New list object |
266 PyObject *pyList = PyList_New(outputs.size()); | 266 PyObject *pyList = PyList_New(outputs.size()); |
267 | 267 |
268 for (size_t i = 0; i < outputs.size(); ++i) { | 268 for (size_t i = 0; i < outputs.size(); ++i) { |
269 PyObject *pyOutputId = | 269 PyObject *pyOutputId = |
270 PyString_FromString(outputs[i].identifier.c_str()); | 270 PyString_FromString(outputs[i].identifier.c_str()); |
271 PyList_SET_ITEM(pyList,i,pyOutputId); | 271 PyList_SET_ITEM(pyList,i,pyOutputId); |
272 } | 272 } |
273 | 273 |
274 delete plugin; | 274 delete plugin; |
275 return pyList; | 275 return pyList; |
276 } | 276 } |
283 vampyhost_loadPlugin(PyObject *self, PyObject *args) | 283 vampyhost_loadPlugin(PyObject *self, PyObject *args) |
284 { | 284 { |
285 PyObject *pyPluginKey; | 285 PyObject *pyPluginKey; |
286 float inputSampleRate; | 286 float inputSampleRate; |
287 | 287 |
288 if (!PyArg_ParseTuple(args, "Sf", | 288 if (!PyArg_ParseTuple(args, "Sf", |
289 &pyPluginKey, | 289 &pyPluginKey, |
290 &inputSampleRate)) { | 290 &inputSampleRate)) { |
291 PyErr_SetString(PyExc_TypeError, | 291 PyErr_SetString(PyExc_TypeError, |
292 "String input argument required: pluginKey"); | 292 "String input argument required: pluginKey"); |
293 return NULL; } | 293 return NULL; } |
297 | 297 |
298 //check pluginKey Validity | 298 //check pluginKey Validity |
299 string::size_type ki = pluginKey.find(':'); | 299 string::size_type ki = pluginKey.find(':'); |
300 if (ki == string::npos) { | 300 if (ki == string::npos) { |
301 PyErr_SetString(PyExc_TypeError, | 301 PyErr_SetString(PyExc_TypeError, |
302 "String input argument required: pluginLibrary:Identifier"); | 302 "String input argument required: pluginLibrary:Identifier"); |
303 return NULL; | 303 return NULL; |
304 } | 304 } |
305 | 305 |
306 PluginLoader *loader = PluginLoader::getInstance(); | 306 PluginLoader *loader = PluginLoader::getInstance(); |
307 | 307 |
308 //load plugin | 308 //load plugin |
309 Plugin *plugin = loader->loadPlugin (pluginKey, inputSampleRate, | 309 Plugin *plugin = loader->loadPlugin (pluginKey, inputSampleRate, |
310 PluginLoader::ADAPT_ALL_SAFE); | 310 PluginLoader::ADAPT_ALL_SAFE); |
311 if (!plugin) { | 311 if (!plugin) { |
312 string pyerr("Failed to load plugin: "); pyerr += pluginKey; | 312 string pyerr("Failed to load plugin: "); pyerr += pluginKey; |
313 PyErr_SetString(PyExc_TypeError,pyerr.c_str()); | 313 PyErr_SetString(PyExc_TypeError,pyerr.c_str()); |
314 return NULL; | 314 return NULL; |
315 } | 315 } |
316 //void *identifier = (void*) new string(pluginKey); | 316 //void *identifier = (void*) new string(pluginKey); |
317 PyPluginDescriptor *pd = new PyPluginDescriptor; | 317 PyPluginDescriptor *pd = new PyPluginDescriptor; |
318 | 318 |
319 pd->key = pluginKey; | 319 pd->key = pluginKey; |
320 pd->isInitialised = false; | 320 pd->isInitialised = false; |
321 pd->inputSampleRate = inputSampleRate; | 321 pd->inputSampleRate = inputSampleRate; |
322 | 322 |
323 //New PyCObject | 323 //New PyCObject |
324 //PyObject *pyPluginHandle = PyCObject_FromVoidPtrAndDesc( | 324 //PyObject *pyPluginHandle = PyCObject_FromVoidPtrAndDesc( |
325 //(void*) plugin, identifier, NULL); | 325 //(void*) plugin, identifier, NULL); |
326 | 326 |
327 PyObject *pyPluginHandle = PyCObject_FromVoidPtrAndDesc( | 327 PyObject *pyPluginHandle = PyCObject_FromVoidPtrAndDesc( |
328 (void*) plugin, (void*) pd, NULL); | 328 (void*) plugin, (void*) pd, NULL); |
329 | 329 |
330 return pyPluginHandle; | 330 return pyPluginHandle; |
331 } | 331 } |
332 | 332 |
333 | 333 |
334 | 334 |
342 if (!PyArg_ParseTuple(args, "O", &pyPluginHandle)) { | 342 if (!PyArg_ParseTuple(args, "O", &pyPluginHandle)) { |
343 PyErr_SetString(PyExc_TypeError, | 343 PyErr_SetString(PyExc_TypeError, |
344 "Wrong input argument: Plugin Handle required."); | 344 "Wrong input argument: Plugin Handle required."); |
345 return NULL; } | 345 return NULL; } |
346 | 346 |
347 string *key; | 347 string *key; |
348 Plugin *plugin; | 348 Plugin *plugin; |
349 | 349 |
350 if ( !getPluginHandle(pyPluginHandle, &plugin, &key) ) { | 350 if ( !getPluginHandle(pyPluginHandle, &plugin, &key) ) { |
351 PyErr_SetString(PyExc_TypeError, | 351 PyErr_SetString(PyExc_TypeError, |
352 "Invalid or already deleted plugin handle."); | 352 "Invalid or already deleted plugin handle."); |
353 return NULL; } | 353 return NULL; } |
354 | 354 |
355 /* Prevent repeated calls from causing segfault | 355 /* Prevent repeated calls from causing segfault |
356 sice it will fail type checking the 2nd time: */ | 356 sice it will fail type checking the 2nd time: */ |
357 PyCObject_SetVoidPtr(pyPluginHandle,NULL); | 357 PyCObject_SetVoidPtr(pyPluginHandle,NULL); |
358 | 358 |
359 PyPluginDescriptor *pd = (PyPluginDescriptor*) key; | 359 PyPluginDescriptor *pd = (PyPluginDescriptor*) key; |
360 | 360 |
361 delete plugin; | 361 delete plugin; |
362 delete pd; | 362 delete pd; |
363 return pyPluginHandle; | 363 return pyPluginHandle; |
364 | 364 |
365 } | 365 } |
369 | 369 |
370 static PyObject * | 370 static PyObject * |
371 vampyhost_initialise(PyObject *self, PyObject *args) | 371 vampyhost_initialise(PyObject *self, PyObject *args) |
372 { | 372 { |
373 PyObject *pyPluginHandle; | 373 PyObject *pyPluginHandle; |
374 size_t channels,blockSize,stepSize; | 374 size_t channels, blockSize, stepSize; |
375 | 375 |
376 if (!PyArg_ParseTuple (args, "Oiii", &pyPluginHandle, | 376 if (!PyArg_ParseTuple (args, "Onnn", &pyPluginHandle, |
377 (size_t) &channels, | 377 (size_t) &channels, |
378 (size_t) &stepSize, | 378 (size_t) &stepSize, |
379 (size_t) &blockSize)) | 379 (size_t) &blockSize)) |
380 { | 380 { |
381 PyErr_SetString(PyExc_TypeError, | 381 PyErr_SetString(PyExc_TypeError, |
382 "Wrong input arguments: requires a valid plugin handle,channels,stepSize,blockSize."); | 382 "Wrong input arguments: requires a valid plugin handle,channels,stepSize,blockSize."); |
383 return NULL; | 383 return NULL; |
384 } | 384 } |
385 | 385 |
386 Plugin *plugin; | 386 Plugin *plugin; |
387 string *key; | 387 string *key; |
388 | 388 |
389 if ( !getPluginHandle(pyPluginHandle, &plugin, &key) ) { | 389 if ( !getPluginHandle(pyPluginHandle, &plugin, &key) ) { |
390 PyErr_SetString(PyExc_TypeError, | 390 PyErr_SetString(PyExc_TypeError, |
391 "Invalid plugin handle."); | 391 "Invalid plugin handle."); |
392 return NULL; } | 392 return NULL; } |
393 | 393 |
394 // here we cast the void pointer as PyPluginDescriptor instead of string | 394 // here we cast the void pointer as PyPluginDescriptor instead of string |
395 PyPluginDescriptor *plugDesc = (PyPluginDescriptor*) key; | 395 PyPluginDescriptor *plugDesc = (PyPluginDescriptor*) key; |
396 | 396 |
397 plugDesc->channels = channels; | 397 plugDesc->channels = channels; |
398 plugDesc->stepSize = stepSize; | 398 plugDesc->stepSize = stepSize; |
399 plugDesc->blockSize = blockSize; | 399 plugDesc->blockSize = blockSize; |
400 | 400 |
403 PyErr_SetString(PyExc_TypeError, | 403 PyErr_SetString(PyExc_TypeError, |
404 "Plugin initialization failed."); | 404 "Plugin initialization failed."); |
405 return NULL; | 405 return NULL; |
406 } | 406 } |
407 | 407 |
408 plugDesc->identifier = | 408 plugDesc->identifier = |
409 plugDesc->key.substr(plugDesc->key.rfind(':')+1); | 409 plugDesc->key.substr(plugDesc->key.rfind(':')+1); |
410 plugDesc->isInitialised = true; | 410 plugDesc->isInitialised = true; |
411 | 411 |
412 return Py_True; | 412 return Py_True; |
413 } | 413 } |
414 | 414 |
415 // These conversion functions are borrowed from PyTypeInterface in VamPy | 415 // These conversion functions are borrowed from PyTypeInterface in VamPy |
416 | 416 |
417 template<typename RET, typename DTYPE> | 417 template<typename RET, typename DTYPE> |
418 static | 418 static |
419 RET *pyArrayConvert(char* raw_data_ptr, long length, size_t strides) | 419 RET *pyArrayConvert(char* raw_data_ptr, long length, size_t strides) |
420 { | 420 { |
421 RET *rValue = new RET[length]; | 421 RET *rValue = new RET[length]; |
422 | 422 |
423 /// check if the array is continuous, if not use strides info | 423 /// check if the array is continuous, if not use strides info |
424 if (sizeof(DTYPE)!=strides) { | 424 if (sizeof(DTYPE)!=strides) { |
425 char* data = (char*) raw_data_ptr; | 425 char* data = (char*) raw_data_ptr; |
426 for (long i = 0; i<length; ++i){ | 426 for (long i = 0; i<length; ++i){ |
427 rValue[i] = (RET)(*((DTYPE*)data)); | 427 rValue[i] = (RET)(*((DTYPE*)data)); |
432 | 432 |
433 DTYPE* data = (DTYPE*) raw_data_ptr; | 433 DTYPE* data = (DTYPE*) raw_data_ptr; |
434 for (long i = 0; i<length; ++i){ | 434 for (long i = 0; i<length; ++i){ |
435 rValue[i] = (RET)data[i]; | 435 rValue[i] = (RET)data[i]; |
436 } | 436 } |
437 | 437 |
438 return rValue; | 438 return rValue; |
439 } | 439 } |
440 | 440 |
441 static float * | 441 static float * |
442 pyArrayToFloatArray(PyObject *pyValue) | 442 pyArrayToFloatArray(PyObject *pyValue) |
443 { | 443 { |
444 if (!PyArray_Check(pyValue)) { | 444 if (!PyArray_Check(pyValue)) { |
445 cerr << "pyArrayToFloatArray: Failed, object has no array interface" << endl; | 445 cerr << "pyArrayToFloatArray: Failed, object has no array interface" << endl; |
446 return 0; | 446 return 0; |
447 } | 447 } |
448 | 448 |
449 PyArrayObject* pyArray = (PyArrayObject*) pyValue; | 449 PyArrayObject* pyArray = (PyArrayObject*) pyValue; |
450 PyArray_Descr* descr = pyArray->descr; | 450 PyArray_Descr* descr = pyArray->descr; |
451 | 451 |
452 /// check raw data and descriptor pointers | 452 /// check raw data and descriptor pointers |
453 if (pyArray->data == 0 || descr == 0) { | 453 if (pyArray->data == 0 || descr == 0) { |
454 cerr << "pyArrayToFloatArray: Failed, NumPy array has NULL data or descriptor" << endl; | 454 cerr << "pyArrayToFloatArray: Failed, NumPy array has NULL data or descriptor" << endl; |
455 return 0; | 455 return 0; |
456 } | 456 } |
461 return 0; | 461 return 0; |
462 } | 462 } |
463 | 463 |
464 /// check strides (useful if array is not continuous) | 464 /// check strides (useful if array is not continuous) |
465 size_t strides = *((size_t*) pyArray->strides); | 465 size_t strides = *((size_t*) pyArray->strides); |
466 | 466 |
467 /// convert the array | 467 /// convert the array |
468 switch (descr->type_num) { | 468 switch (descr->type_num) { |
469 case NPY_FLOAT : // dtype='float32' | 469 case NPY_FLOAT : // dtype='float32' |
470 return pyArrayConvert<float,float>(pyArray->data,pyArray->dimensions[0],strides); | 470 return pyArrayConvert<float,float>(pyArray->data,pyArray->dimensions[0],strides); |
471 case NPY_DOUBLE : // dtype='float64' | 471 case NPY_DOUBLE : // dtype='float64' |
484 { | 484 { |
485 PyObject *pyPluginHandle; | 485 PyObject *pyPluginHandle; |
486 PyObject *pyBuffer; | 486 PyObject *pyBuffer; |
487 PyObject *pyRealTime; | 487 PyObject *pyRealTime; |
488 | 488 |
489 if (!PyArg_ParseTuple(args, "OOO", | 489 if (!PyArg_ParseTuple(args, "OOO", |
490 &pyPluginHandle, // C object holding a pointer to a plugin and its descriptor | 490 &pyPluginHandle, // C object holding a pointer to a plugin and its descriptor |
491 &pyBuffer, // Audio data | 491 &pyBuffer, // Audio data |
492 &pyRealTime)) { // TimeStamp | 492 &pyRealTime)) { // TimeStamp |
493 PyErr_SetString(PyExc_TypeError, | 493 PyErr_SetString(PyExc_TypeError, |
494 "Required: plugin handle, buffer, timestmap."); | 494 "Required: plugin handle, buffer, timestmap."); |
497 if (!PyRealTime_Check(pyRealTime)) { | 497 if (!PyRealTime_Check(pyRealTime)) { |
498 PyErr_SetString(PyExc_TypeError,"Valid timestamp required."); | 498 PyErr_SetString(PyExc_TypeError,"Valid timestamp required."); |
499 return NULL; } | 499 return NULL; } |
500 | 500 |
501 string *key; | 501 string *key; |
502 Plugin *plugin; | 502 Plugin *plugin; |
503 | 503 |
504 if (!getPluginHandle(pyPluginHandle, &plugin, &key)) { | 504 if (!getPluginHandle(pyPluginHandle, &plugin, &key)) { |
505 PyErr_SetString(PyExc_AttributeError, | 505 PyErr_SetString(PyExc_AttributeError, |
506 "Invalid or already deleted plugin handle."); | 506 "Invalid or already deleted plugin handle."); |
507 return NULL; | 507 return NULL; |
512 if (!pd->isInitialised) { | 512 if (!pd->isInitialised) { |
513 PyErr_SetString(PyExc_StandardError, | 513 PyErr_SetString(PyExc_StandardError, |
514 "Plugin has not been initialised."); | 514 "Plugin has not been initialised."); |
515 return NULL; } | 515 return NULL; } |
516 | 516 |
517 size_t channels = pd->channels; | 517 size_t channels = pd->channels; |
518 size_t blockSize = pd->blockSize; | 518 size_t blockSize = pd->blockSize; |
519 | 519 |
520 if (!PyList_Check(pyBuffer)) { | 520 if (!PyList_Check(pyBuffer)) { |
521 PyErr_SetString(PyExc_TypeError, "List of NumPy Array required for process input."); | 521 PyErr_SetString(PyExc_TypeError, "List of NumPy Array required for process input."); |
522 return NULL; | 522 return NULL; |
566 PyObject *pyPluginHandle; | 566 PyObject *pyPluginHandle; |
567 // PyObject *pyBuffer; | 567 // PyObject *pyBuffer; |
568 // PyObject *pyRealTime; | 568 // PyObject *pyRealTime; |
569 PyObject *pyOutput; | 569 PyObject *pyOutput; |
570 | 570 |
571 if (!PyArg_ParseTuple(args, "OO", | 571 if (!PyArg_ParseTuple(args, "OO", |
572 &pyPluginHandle, // C object holding a pointer to a plugin and its descriptor | 572 &pyPluginHandle, // C object holding a pointer to a plugin and its descriptor |
573 &pyOutput)) { // Output reference | 573 &pyOutput)) { // Output reference |
574 PyErr_SetString(PyExc_TypeError, | 574 PyErr_SetString(PyExc_TypeError, |
575 "Required: plugin handle, buffer, timestmap."); | 575 "Required: plugin handle, buffer, timestmap."); |
576 return NULL; } | 576 return NULL; } |
577 | 577 |
578 string *key; | 578 string *key; |
579 Plugin *plugin; | 579 Plugin *plugin; |
580 | 580 |
581 if ( !getPluginHandle(pyPluginHandle, &plugin, &key) ) { | 581 if ( !getPluginHandle(pyPluginHandle, &plugin, &key) ) { |
582 PyErr_SetString(PyExc_AttributeError, | 582 PyErr_SetString(PyExc_AttributeError, |
583 "Invalid or already deleted plugin handle."); | 583 "Invalid or already deleted plugin handle."); |
584 return NULL; } | 584 return NULL; } |
596 PyObject *pyFeatureList = PyList_New(outLength); | 596 PyObject *pyFeatureList = PyList_New(outLength); |
597 | 597 |
598 for (size_t i = 0; i < outLength; ++i) { | 598 for (size_t i = 0; i < outLength; ++i) { |
599 // Test: | 599 // Test: |
600 /* | 600 /* |
601 XxoObject *pyFeature = PyObject_New(XxoObject, &Xxo_Type); | 601 XxoObject *pyFeature = PyObject_New(XxoObject, &Xxo_Type); |
602 if (pyFeature == NULL) break; //return NULL; | 602 if (pyFeature == NULL) break; //return NULL; |
603 | 603 |
604 pyFeature->x_attr = NULL; | 604 pyFeature->x_attr = NULL; |
605 pyFeature->feature = &pd->output[outputNo][i]; | 605 pyFeature->feature = &pd->output[outputNo][i]; |
606 | 606 |
607 PyList_SET_ITEM(pyFeatureList,i,(PyObject*)pyFeature); | 607 PyList_SET_ITEM(pyFeatureList,i,(PyObject*)pyFeature); |
608 */ | 608 */ |
609 } | 609 } |
610 | 610 |
611 Py_INCREF(pyFeatureList); | 611 Py_INCREF(pyFeatureList); |
612 return pyFeatureList; | 612 return pyFeatureList; |
613 | 613 |
614 // EXPLAIN WHAT WE NEED TO DO HERE: | 614 // EXPLAIN WHAT WE NEED TO DO HERE: |
615 // We have the block output in pd->output | 615 // We have the block output in pd->output |
616 // FeatureSet[output] -> [Feature[x]] -> Feature.hasTimestamp = v | 616 // FeatureSet[output] -> [Feature[x]] -> Feature.hasTimestamp = v |
617 // Vamp::Plugin::FeatureSet output; = pd->output | 617 // Vamp::Plugin::FeatureSet output; = pd->output |
618 // typedef std::vector<Feature> FeatureList; | 618 // typedef std::vector<Feature> FeatureList; |
619 // typedef std::map<int, FeatureList> FeatureSet; // key is output no | 619 // typedef std::map<int, FeatureList> FeatureSet; // key is output no |
620 | 620 |
621 // THIS IS FOR OUTPUT id LOOKUP LATER | 621 // THIS IS FOR OUTPUT id LOOKUP LATER |
622 // Plugin::OutputList outputs = plugin->getOutputDescriptors(); | 622 // Plugin::OutputList outputs = plugin->getOutputDescriptors(); |
623 // | 623 // |
624 // if (outputs.size()<1) { | 624 // if (outputs.size()<1) { |
625 // string pyerr("Plugin has no output: "); pyerr += pluginKey; | 625 // string pyerr("Plugin has no output: "); pyerr += pluginKey; |
626 // PyErr_SetString(PyExc_TypeError,pyerr.c_str()); | 626 // PyErr_SetString(PyExc_TypeError,pyerr.c_str()); |
627 // return NULL; | 627 // return NULL; |
628 // } | 628 // } |
629 // | 629 // |
630 // //New list object | 630 // //New list object |
631 // PyObject *pyList = PyList_New(outputs.size()); | 631 // PyObject *pyList = PyList_New(outputs.size()); |
632 // | 632 // |
633 // for (size_t i = 0; i < outputs.size(); ++i) { | 633 // for (size_t i = 0; i < outputs.size(); ++i) { |
634 // PyObject *pyOutputId = | 634 // PyObject *pyOutputId = |
635 // PyString_FromString(outputs[i].identifier.c_str()); | 635 // PyString_FromString(outputs[i].identifier.c_str()); |
636 // PyList_SET_ITEM(pyList,i,pyOutputId); | 636 // PyList_SET_ITEM(pyList,i,pyOutputId); |
637 // } | 637 // } |
638 | 638 |
639 } | 639 } |
640 | 640 |
641 | 641 |
642 | 642 |
643 | 643 |
677 {"frame2RealTime", (PyCFunction)RealTime_frame2RealTime, METH_VARARGS, | 677 {"frame2RealTime", (PyCFunction)RealTime_frame2RealTime, METH_VARARGS, |
678 PyDoc_STR("frame2RealTime((int64)frame, (uint32)sampleRate ) -> returns new RealTime object from frame.")}, | 678 PyDoc_STR("frame2RealTime((int64)frame, (uint32)sampleRate ) -> returns new RealTime object from frame.")}, |
679 | 679 |
680 {"realtime", (PyCFunction)RealTime_new, METH_VARARGS, | 680 {"realtime", (PyCFunction)RealTime_new, METH_VARARGS, |
681 PyDoc_STR("realtime() -> returns new RealTime object")}, | 681 PyDoc_STR("realtime() -> returns new RealTime object")}, |
682 | 682 |
683 {NULL, NULL} /* sentinel */ | 683 {NULL, NULL} /* sentinel */ |
684 }; | 684 }; |
685 | 685 |
686 //Documentation for our new module | 686 //Documentation for our new module |
687 PyDoc_STRVAR(module_doc, "This is a template module just for instruction."); | 687 PyDoc_STRVAR(module_doc, "This is a template module just for instruction."); |
693 initvampyhost(void) | 693 initvampyhost(void) |
694 { | 694 { |
695 PyObject *m; | 695 PyObject *m; |
696 | 696 |
697 /* Finalize the type object including setting type of the new type | 697 /* Finalize the type object including setting type of the new type |
698 * object; doing it here is required for portability to Windows | 698 * object; doing it here is required for portability to Windows |
699 * without requiring C++. */ | 699 * without requiring C++. */ |
700 | 700 |
701 if (PyType_Ready(&RealTime_Type) < 0) | 701 if (PyType_Ready(&RealTime_Type) < 0) |
702 return; | 702 return; |
703 // PyModule_AddObject(m, "Real_Time", (PyObject *)&RealTime_Type); | 703 // PyModule_AddObject(m, "Real_Time", (PyObject *)&RealTime_Type); |