Mercurial > hg > vampy
changeset 27:046ba4183373
Some further mods to vampy construction
author | fazekasgy |
---|---|
date | Tue, 25 Aug 2009 08:46:15 +0000 |
parents | ba3686eb697c |
children | 5139bf30f208 |
files | PyPlugin.cpp |
diffstat | 1 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/PyPlugin.cpp Wed Aug 19 15:21:17 2009 +0000 +++ b/PyPlugin.cpp Tue Aug 25 08:46:15 2009 +0000 @@ -89,25 +89,31 @@ m_inputDomain(TimeDomain) { // Create an instance + MutexLocker locker(&m_pythonInterpreterMutex); + Py_INCREF(m_pyClass); PyObject *pyInputSampleRate = PyFloat_FromDouble(inputSampleRate); PyObject *args = PyTuple_Pack(1, pyInputSampleRate); - - m_pyInstance = PyObject_CallObject(m_pyClass, args); - - if (!m_pyInstance) { + m_pyInstance = PyObject_Call(m_pyClass, args, NULL); + + if (!m_pyInstance || PyErr_Occurred()) { + if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } + Py_CLEAR(args); + Py_CLEAR(pyInputSampleRate); cerr << "PyPlugin::PyPlugin: Failed to create Python plugin instance for key \"" << pluginKey << "\" (is the 1-arg class constructor from sample rate correctly provided?)" << endl; throw std::string("Constructor failed"); } - + Py_INCREF(m_pyInstance); Py_DECREF(args); Py_DECREF(pyInputSampleRate); + } PyPlugin::~PyPlugin() { if (m_pyInstance) Py_DECREF(m_pyInstance); + if (m_pyClass) Py_DECREF(m_pyClass); + if (m_pyProcess) Py_CLEAR(m_pyProcess); - Py_CLEAR(m_pyProcess); #ifdef _DEBUG cerr << "PyPlugin::PyPlugin:" << m_class << " Instance deleted." << endl; @@ -615,6 +621,8 @@ ParameterDescriptor pd; char method[]="getParameterDescriptors"; cerr << "[call] " << method << endl; + + if (!m_pyInstance) {cerr << "Error: pyInstance is NULL" << endl; return list;} //Check if the method is implemented in Python if ( ! PyObject_HasAttrString(m_pyInstance,method) ) return list; @@ -678,7 +686,8 @@ break; case p::isQuantized: pd.isQuantized = (bool) PyInt_AS_LONG(pyValue); - break; case p::quantizeStep: + break; + case p::quantizeStep: pd.quantizeStep = (float) PyFloat_AS_DOUBLE(pyValue); break; default :