diff PyPlugScanner.cpp @ 24:7d28bed0864e

* Rearrange Python plugin construction. Formerly, the PyPluginAdapter has retained a single plugin instance pointer for each plugin found, and its createPlugin method has simply returned a new PyPlugin object wrapping the same instance pointer. This has a couple of negative consequences: - Because construction of the actual Python instance occurred before the wrapper was constructed, it was not possible to pass arguments (i.e. the sample rate) from the wrapper constructor to the Python plugin instance constructor -- they had to be passed later, to initialise, disadvantaging those plugins that would like to use the sample rate for parameter & step/block size calculations etc - Because there was only a single Python plugin instance, it was not possible to run more than one instance at once with any isolation This rework instead stores the Python class pointer (rather than instance pointer) in the PyPluginAdapter, and each PyPlugin wrapper instance creates its own Python plugin instance. What could possibly go wrong?
author cannam
date Mon, 17 Aug 2009 15:22:06 +0000
parents 3af6b5990ad8
children 7648f3f2fa14
line wrap: on
line diff
--- a/PyPlugScanner.cpp	Thu Jul 16 13:19:20 2009 +0000
+++ b/PyPlugScanner.cpp	Mon Aug 17 15:22:06 2009 +0000
@@ -62,7 +62,7 @@
 	
 	vector<string> pyPlugs;
 	string pluginKey;
-	PyObject *pyClassInstance;
+	PyObject *pyClass;
 	
     for (size_t i = 0; i < m_path.size(); ++i) {
         
@@ -74,13 +74,13 @@
 				if (!script.empty()) {					
 					string classname=script.substr(0,script.rfind('.'));
 					pluginKey=joinPath(m_path[i],script)+":"+classname;
-					pyClassInstance = getScriptInstance(m_path[i],classname);
-					if (pyClassInstance == NULL) 
+					pyClass = getScriptClass(m_path[i],classname);
+					if (pyClass == NULL) 
 					cerr << "Warning: Syntax error in VamPy plugin:  " 
-					<< classname << ". Avoiding plugin." << endl;
+					     << classname << ". Avoiding plugin." << endl;
 					else { 
 							pyPlugs.push_back(pluginKey);
-							m_pyInstances.push_back(pyClassInstance);
+							m_pyClasses.push_back(pyClass);
 						}
 					//pyPlugs.push_back(pluginKey);
 				}
@@ -92,11 +92,11 @@
 }
 
 
-//For now return one class instance found in each script
+//For now return one class object found in each script
 vector<PyObject*> 
-PyPlugScanner::getPyInstances()
+PyPlugScanner::getPyClasses()
 {
-return m_pyInstances;	
+return m_pyClasses;	
 
 }
 
@@ -104,7 +104,7 @@
 //Validate
 //This should not be called more than once!
 PyObject* 
-PyPlugScanner::getScriptInstance(string path, string classname)
+PyPlugScanner::getScriptClass(string path, string classname)
 {
 
 	//Add plugin path to active Python Path 
@@ -136,10 +136,7 @@
 	//Check if class is present and a callable method is implemented
 	if (pyClass && PyCallable_Check(pyClass)) {
 
-		//Create an instance
-		PyObject *pyInstance = PyObject_CallObject(pyClass, NULL);
-		//cerr << "__(getInstance) PyPlugin Class: " << m_class << " successfully created.__" << endl;
-		return pyInstance; 
+	    return pyClass;
 	}	
 	else {
 		cerr << "ERROR: callable plugin class could not be found in source: " << classname << endl