Mercurial > hg > vampy
comparison PyPlugin.cpp @ 27:046ba4183373
Some further mods to vampy construction
| author | fazekasgy |
|---|---|
| date | Tue, 25 Aug 2009 08:46:15 +0000 |
| parents | 7d28bed0864e |
| children | 5139bf30f208 |
comparison
equal
deleted
inserted
replaced
| 26:ba3686eb697c | 27:046ba4183373 |
|---|---|
| 87 m_processType(0), | 87 m_processType(0), |
| 88 m_pyProcess(NULL), | 88 m_pyProcess(NULL), |
| 89 m_inputDomain(TimeDomain) | 89 m_inputDomain(TimeDomain) |
| 90 { | 90 { |
| 91 // Create an instance | 91 // Create an instance |
| 92 MutexLocker locker(&m_pythonInterpreterMutex); | |
| 93 Py_INCREF(m_pyClass); | |
| 92 PyObject *pyInputSampleRate = PyFloat_FromDouble(inputSampleRate); | 94 PyObject *pyInputSampleRate = PyFloat_FromDouble(inputSampleRate); |
| 93 PyObject *args = PyTuple_Pack(1, pyInputSampleRate); | 95 PyObject *args = PyTuple_Pack(1, pyInputSampleRate); |
| 94 | 96 m_pyInstance = PyObject_Call(m_pyClass, args, NULL); |
| 95 m_pyInstance = PyObject_CallObject(m_pyClass, args); | 97 |
| 96 | 98 if (!m_pyInstance || PyErr_Occurred()) { |
| 97 if (!m_pyInstance) { | 99 if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } |
| 100 Py_CLEAR(args); | |
| 101 Py_CLEAR(pyInputSampleRate); | |
| 98 cerr << "PyPlugin::PyPlugin: Failed to create Python plugin instance for key \"" << pluginKey << "\" (is the 1-arg class constructor from sample rate correctly provided?)" << endl; | 102 cerr << "PyPlugin::PyPlugin: Failed to create Python plugin instance for key \"" << pluginKey << "\" (is the 1-arg class constructor from sample rate correctly provided?)" << endl; |
| 99 throw std::string("Constructor failed"); | 103 throw std::string("Constructor failed"); |
| 100 } | 104 } |
| 101 | 105 Py_INCREF(m_pyInstance); |
| 102 Py_DECREF(args); | 106 Py_DECREF(args); |
| 103 Py_DECREF(pyInputSampleRate); | 107 Py_DECREF(pyInputSampleRate); |
| 108 | |
| 104 } | 109 } |
| 105 | 110 |
| 106 PyPlugin::~PyPlugin() | 111 PyPlugin::~PyPlugin() |
| 107 { | 112 { |
| 108 if (m_pyInstance) Py_DECREF(m_pyInstance); | 113 if (m_pyInstance) Py_DECREF(m_pyInstance); |
| 109 | 114 if (m_pyClass) Py_DECREF(m_pyClass); |
| 110 Py_CLEAR(m_pyProcess); | 115 if (m_pyProcess) Py_CLEAR(m_pyProcess); |
| 116 | |
| 111 #ifdef _DEBUG | 117 #ifdef _DEBUG |
| 112 cerr << "PyPlugin::PyPlugin:" << m_class | 118 cerr << "PyPlugin::PyPlugin:" << m_class |
| 113 << " Instance deleted." << endl; | 119 << " Instance deleted." << endl; |
| 114 #endif | 120 #endif |
| 115 } | 121 } |
| 613 | 619 |
| 614 ParameterList list; | 620 ParameterList list; |
| 615 ParameterDescriptor pd; | 621 ParameterDescriptor pd; |
| 616 char method[]="getParameterDescriptors"; | 622 char method[]="getParameterDescriptors"; |
| 617 cerr << "[call] " << method << endl; | 623 cerr << "[call] " << method << endl; |
| 624 | |
| 625 if (!m_pyInstance) {cerr << "Error: pyInstance is NULL" << endl; return list;} | |
| 618 | 626 |
| 619 //Check if the method is implemented in Python | 627 //Check if the method is implemented in Python |
| 620 if ( ! PyObject_HasAttrString(m_pyInstance,method) ) return list; | 628 if ( ! PyObject_HasAttrString(m_pyInstance,method) ) return list; |
| 621 | 629 |
| 622 //Call the method: must return list object (new reference) | 630 //Call the method: must return list object (new reference) |
| 676 case p::defaultValue: | 684 case p::defaultValue: |
| 677 pd.defaultValue = (float) PyFloat_AS_DOUBLE(pyValue); | 685 pd.defaultValue = (float) PyFloat_AS_DOUBLE(pyValue); |
| 678 break; | 686 break; |
| 679 case p::isQuantized: | 687 case p::isQuantized: |
| 680 pd.isQuantized = (bool) PyInt_AS_LONG(pyValue); | 688 pd.isQuantized = (bool) PyInt_AS_LONG(pyValue); |
| 681 break; case p::quantizeStep: | 689 break; |
| 690 case p::quantizeStep: | |
| 682 pd.quantizeStep = (float) PyFloat_AS_DOUBLE(pyValue); | 691 pd.quantizeStep = (float) PyFloat_AS_DOUBLE(pyValue); |
| 683 break; | 692 break; |
| 684 default : | 693 default : |
| 685 cerr << "Invalid key in Vamp OutputDescriptor: " << PyString_AsString(pyKey) << endl; | 694 cerr << "Invalid key in Vamp OutputDescriptor: " << PyString_AsString(pyKey) << endl; |
| 686 } | 695 } |
