comparison vampyhost.cpp @ 18:4b9adb4b532f

Return values from process
author Chris Cannam
date Tue, 25 Nov 2014 09:58:25 +0000
parents 3893b76daf80
children 8e5cefa70c99
comparison
equal deleted inserted replaced
17:3893b76daf80 18:4b9adb4b532f
300 300
301 return Py_True; 301 return Py_True;
302 } 302 }
303 303
304 static PyObject * 304 static PyObject *
305 vampyhost_reset(PyObject *self, PyObject *args)
306 {
307 PyObject *pyPluginHandle;
308
309 if (!PyArg_ParseTuple (args, "O", &pyPluginHandle))
310 {
311 PyErr_SetString(PyExc_TypeError,
312 "initialise() takes plugin handle (object) argument");
313 return 0;
314 }
315
316 PyPluginData *pd = getPluginData(pyPluginHandle);
317 if (!pd) return 0;
318
319 if (!pd->isInitialised) {
320 PyErr_SetString(PyExc_StandardError,
321 "Plugin has not been initialised");
322 return 0;
323 }
324
325 pd->plugin->reset();
326 return Py_True;
327 }
328
329 static PyObject *
305 vampyhost_process(PyObject *self, PyObject *args) 330 vampyhost_process(PyObject *self, PyObject *args)
306 { 331 {
307 PyObject *pyPluginHandle; 332 PyObject *pyPluginHandle;
308 PyObject *pyBuffer; 333 PyObject *pyBuffer;
309 PyObject *pyRealTime; 334 PyObject *pyRealTime;
366 391
367 cerr << "no, here!" << endl; 392 cerr << "no, here!" << endl;
368 393
369 RealTime timeStamp = *PyRealTime_AsRealTime(pyRealTime); 394 RealTime timeStamp = *PyRealTime_AsRealTime(pyRealTime);
370 395
371 // Call process and store the output 396 cerr << "no no, here!" << endl;
372 (void) pd->plugin->process(inbuf, timeStamp); //!!! return the output! 397
373 398 Plugin::FeatureSet fs = pd->plugin->process(inbuf, timeStamp);
374 /* TODO: DO SOMETHONG WITH THE FEATURE SET HERE */
375 /// convert to appropriate python objects, reuse types and conversion utilities from Vampy ...
376 399
377 delete[] inbuf; 400 delete[] inbuf;
378 401
379 return 0; //!!! Need to return actual features! 402 cerr << "no no no, here!" << endl;
380 403
404 PyTypeConversions conv;
405 conv.setNumpyInstalled(true);
406
407 PyObject *pyFs = PyDict_New();
408
409 for (Plugin::FeatureSet::const_iterator fsi = fs.begin();
410 fsi != fs.end(); ++fsi) {
411
412 int fno = fsi->first;
413 const Plugin::FeatureList &fl = fsi->second;
414
415 if (!fl.empty()) {
416
417 PyObject *pyFl = PyList_New(fl.size());
418
419 for (int fli = 0; fli < (int)fl.size(); ++fli) {
420
421 const Plugin::Feature &f = fl[fli];
422 PyObject *pyF = PyDict_New();
423
424 if (f.hasTimestamp) {
425 PyDict_SetItemString
426 (pyF, "timestamp", PyRealTime_FromRealTime(f.timestamp));
427 }
428 if (f.hasDuration) {
429 PyDict_SetItemString
430 (pyF, "duration", PyRealTime_FromRealTime(f.duration));
431 }
432
433 PyDict_SetItemString
434 (pyF, "label", PyString_FromString(f.label.c_str()));
435
436 if (!f.values.empty()) {
437 PyDict_SetItemString
438 (pyF, "values", conv.FloatVector_To_PyArray(f.values));
439 }
440
441 PyList_SET_ITEM(pyFl, fli, pyF);
442 }
443
444 PyObject *pyN = PyInt_FromLong(fno);
445 PyDict_SetItem(pyFs, pyN, pyFl);
446 }
447 }
448
449 cerr << "no you fool, here!" << endl;
450
451 return pyFs;
381 } 452 }
382 453
383 #ifdef NOPE 454 #ifdef NOPE
384 static PyObject * 455 static PyObject *
385 vampyhost_getOutput(PyObject *self, PyObject *args) { 456 vampyhost_getOutput(PyObject *self, PyObject *args) {
452 523
453 } 524 }
454 #endif 525 #endif
455 526
456 527
457 528 // module methods table
458 /* List of functions defined in this module */
459 //module methods table
460 static PyMethodDef vampyhost_methods[] = { 529 static PyMethodDef vampyhost_methods[] = {
461 530
462 {"enumeratePlugins", vampyhost_enumeratePlugins, METH_NOARGS, 531 {"listPlugins", vampyhost_enumeratePlugins, METH_NOARGS,
463 xx_foo_doc}, 532 xx_foo_doc},
464 533
465 {"getPluginPath", vampyhost_getPluginPath, METH_NOARGS, 534 {"getPluginPath", vampyhost_getPluginPath, METH_NOARGS,
466 xx_foo_doc}, 535 xx_foo_doc},
467 536
468 {"getLibraryForPlugin", vampyhost_getLibraryFor, METH_VARARGS, 537 {"getCategoryOf", vampyhost_getPluginCategory, METH_VARARGS,
469 xx_foo_doc}, 538 xx_foo_doc},
470 539
471 {"getPluginCategory", vampyhost_getPluginCategory, METH_VARARGS, 540 {"getLibraryFor", vampyhost_getLibraryFor, METH_VARARGS,
472 xx_foo_doc}, 541 xx_foo_doc},
473 542
474 {"getOutputList", vampyhost_getOutputList, METH_VARARGS, 543 {"getOutputsOf", vampyhost_getOutputList, METH_VARARGS,
475 xx_foo_doc}, 544 xx_foo_doc},
476 545
477 {"loadPlugin", vampyhost_loadPlugin, METH_VARARGS, 546 {"loadPlugin", vampyhost_loadPlugin, METH_VARARGS,
478 xx_foo_doc}, 547 xx_foo_doc},
479 548
549 {"initialise", vampyhost_initialise, METH_VARARGS,
550 xx_foo_doc},
551
552 {"reset", vampyhost_reset, METH_VARARGS,
553 xx_foo_doc},
554
480 {"process", vampyhost_process, METH_VARARGS, 555 {"process", vampyhost_process, METH_VARARGS,
481 xx_foo_doc}, 556 xx_foo_doc},
482 557
483 {"unloadPlugin", vampyhost_unloadPlugin, METH_VARARGS, 558 {"unloadPlugin", vampyhost_unloadPlugin, METH_VARARGS,
484 xx_foo_doc}, 559 xx_foo_doc},
485 560
486 {"initialise", vampyhost_initialise, METH_VARARGS,
487 xx_foo_doc},
488
489 // {"getOutput", vampyhost_getOutput, METH_VARARGS,
490 // xx_foo_doc},
491
492 /* Add RealTime Module Methods */
493 /*
494 {"frame2RealTime", (PyCFunction)RealTime_frame2RealTime, METH_VARARGS,
495 PyDoc_STR("frame2RealTime((int64)frame, (uint32)sampleRate ) -> returns new RealTime object from frame.")},
496
497 {"realtime", (PyCFunction)RealTime_new, METH_VARARGS,
498 PyDoc_STR("realtime() -> returns new RealTime object")},
499 */
500 {0, 0} /* sentinel */ 561 {0, 0} /* sentinel */
501 }; 562 };
502 563
503 //Documentation for our new module 564 //Documentation for our new module
504 PyDoc_STRVAR(module_doc, "This is a template module just for instruction."); 565 PyDoc_STRVAR(module_doc, "This is a template module just for instruction.");