Mercurial > hg > vampy
comparison PyPlugin.h @ 51:c1e4f706ca9a
Fix numpy version incompatibility issues and updated some example plugins.
author | fazekasgy |
---|---|
date | Thu, 08 Oct 2009 08:47:28 +0000 |
parents | 8b2eddf686da |
children | 5664fe298af2 |
comparison
equal
deleted
inserted
replaced
50:3868da185d73 | 51:c1e4f706ca9a |
---|---|
71 }; | 71 }; |
72 | 72 |
73 class PyPlugin : public Vamp::Plugin | 73 class PyPlugin : public Vamp::Plugin |
74 { | 74 { |
75 public: | 75 public: |
76 PyPlugin(std::string plugin,float inputSampleRate, PyObject *pyClass, int &instcount); | 76 PyPlugin(std::string plugin,float inputSampleRate, PyObject *pyClass, int &instcount, bool &numpyInstalled); |
77 virtual ~PyPlugin(); | 77 virtual ~PyPlugin(); |
78 | 78 |
79 bool initialise(size_t channels, size_t stepSize, size_t blockSize); | 79 bool initialise(size_t channels, size_t stepSize, size_t blockSize); |
80 void reset(); | 80 void reset(); |
81 | 81 |
120 PyTypeInterface m_ti; | 120 PyTypeInterface m_ti; |
121 int m_vampyFlags; | 121 int m_vampyFlags; |
122 bool m_quitOnErrorFlag; | 122 bool m_quitOnErrorFlag; |
123 bool m_debugFlag; | 123 bool m_debugFlag; |
124 bool m_useRealTimeFlag; | 124 bool m_useRealTimeFlag; |
125 bool m_numpyInstalled; | |
126 mutable bool m_processFailure; | |
125 | 127 |
126 void setProcessType(); | 128 void setProcessType(); |
127 | 129 |
128 FeatureSet processMethodCall(const float *const *inputBuffers,Vamp::RealTime timestamp); | 130 FeatureSet processMethodCall(const float *const *inputBuffers,Vamp::RealTime timestamp); |
129 | 131 |
130 bool getBooleanFlag(char flagName[],bool) const; | 132 bool getBooleanFlag(char flagName[],bool) const; |
131 int getBinaryFlags(char flagName[], eVampyFlags) const; | 133 int getBinaryFlags(char flagName[], eVampyFlags) const; |
132 void typeErrorHandler(char *method) const; | 134 void typeErrorHandler(char *method, bool process = false) const; |
133 | 135 |
134 /// simple 'void return' call with no args | 136 /// simple 'void return' call with no args |
135 void genericMethodCall(char *method) const | 137 void genericMethodCall(char *method) const |
136 { | 138 { |
137 if (m_debugFlag) cerr << DEBUG_NAME << endl; | 139 if (m_debugFlag) cerr << DEBUG_NAME << endl; |
395 | 397 |
396 /// optimised process call | 398 /// optimised process call |
397 inline PyPlugin::FeatureSet | 399 inline PyPlugin::FeatureSet |
398 PyPlugin::processMethodCall(const float *const *inputBuffers,Vamp::RealTime timestamp) | 400 PyPlugin::processMethodCall(const float *const *inputBuffers,Vamp::RealTime timestamp) |
399 { | 401 { |
400 | 402 |
401 /// Optimizations: 1) we avoid ...ObjArg functions since we know | 403 /// Optimizations: 1) we avoid ...ObjArg functions since we know |
402 /// the number of arguments, and we don't like va_list parsing | 404 /// the number of arguments, and we don't like va_list parsing |
403 /// in the process. 2) Also: we're supposed to incref args, | 405 /// in the process. 2) Also: we're supposed to incref args, |
404 /// but instead, we let the arguments tuple steal the references | 406 /// but instead, we let the arguments tuple steal the references |
405 /// and decref them when it is deallocated. | 407 /// and decref them when it is deallocated. |
408 | 410 |
409 FeatureSet rFeatureSet; | 411 FeatureSet rFeatureSet; |
410 PyObject *pyChannelList = NULL; | 412 PyObject *pyChannelList = NULL; |
411 | 413 |
412 if (m_processType == numpy_bufferProcess) { | 414 if (m_processType == numpy_bufferProcess) { |
413 pyChannelList = m_ti.InputBuffers_As_SharedMemoryList(inputBuffers,m_channels,m_blockSize,m_inputDomain); | 415 pyChannelList = m_ti.InputBuffers_As_SharedMemoryList( |
416 inputBuffers,m_channels,m_blockSize,m_inputDomain); | |
414 } | 417 } |
415 | 418 |
416 if (m_processType == legacyProcess) { | 419 if (m_processType == legacyProcess) { |
417 pyChannelList = m_ti.InputBuffers_As_PythonLists(inputBuffers,m_channels,m_blockSize,m_inputDomain); | 420 pyChannelList = m_ti.InputBuffers_As_PythonLists( |
421 inputBuffers,m_channels,m_blockSize,m_inputDomain); | |
418 } | 422 } |
419 | 423 |
420 #ifdef HAVE_NUMPY | 424 #ifdef HAVE_NUMPY |
421 if (m_processType == numpy_arrayProcess) { | 425 if (m_processType == numpy_arrayProcess) { |
422 pyChannelList = m_ti.InputBuffers_As_NumpyArray(inputBuffers,m_channels,m_blockSize,m_inputDomain); | 426 pyChannelList = m_ti.InputBuffers_As_NumpyArray( |
427 inputBuffers,m_channels,m_blockSize,m_inputDomain); | |
423 } | 428 } |
424 #endif | 429 #endif |
425 | 430 |
426 /// we don't expect these to fail unless out of memory (which is very unlikely on modern systems) | 431 /// we don't expect these to fail unless out of memory (which is very unlikely on modern systems) |
427 #ifdef _DEBUG | 432 #ifdef _DEBUG |
479 rFeatureSet = m_ti.PyValue_To_FeatureSet(pyValue); | 484 rFeatureSet = m_ti.PyValue_To_FeatureSet(pyValue); |
480 if (!m_ti.error) { | 485 if (!m_ti.error) { |
481 Py_DECREF(pyValue); | 486 Py_DECREF(pyValue); |
482 Py_DECREF(pyArgs); | 487 Py_DECREF(pyArgs); |
483 } else { | 488 } else { |
484 typeErrorHandler(PyString_AsString(m_pyProcess)); | 489 typeErrorHandler(PyString_AsString(m_pyProcess),true); |
485 Py_CLEAR(pyValue); | 490 Py_CLEAR(pyValue); |
486 Py_CLEAR(pyArgs); | 491 Py_CLEAR(pyArgs); |
487 } | 492 } |
488 return rFeatureSet; | 493 return rFeatureSet; |
489 } | 494 } |