changeset 18:e9cf443b18f5

* Add duration support (Vamp 2.0)
author cannam
date Fri, 10 Jul 2009 15:14:24 +0000
parents 5b8167619b76
children a54850da8229
files Makefile.cc-linux PyPlugin.cpp PyPlugin.h pyvamp-main.cpp
diffstat 4 files changed, 111 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.cc-linux	Thu Jun 25 16:23:30 2009 +0000
+++ b/Makefile.cc-linux	Fri Jul 10 15:14:24 2009 +0000
@@ -1,8 +1,8 @@
 
-CXXFLAGS	:= -I../vamp-plugin-sdk -O2 -Wall -I/usr/include/python2.5
+CXXFLAGS	:= -I../vamp-plugin-sdk -O2 -Wall -I/usr/include/python2.6 -fPIC
 
 vampy.so:	PyPlugin.o PyPlugScanner.o pyvamp-main.o Mutex.o
-	g++ -shared $^ -o $@ -L../vamp-plugin-sdk/vamp-sdk -Wl,-Bstatic -lvamp-sdk -Wl,-Bdynamic -lpython2.5 -lpthread -Wl,--version-script=vamp-plugin.map
+	g++ -shared $^ -o $@ -L../vamp-plugin-sdk/vamp-sdk -Wl,-Bstatic -lvamp-sdk -Wl,-Bdynamic -lpython2.6 -lpthread -Wl,--version-script=vamp-plugin.map
 
 clean:	
 	rm *.o
--- a/PyPlugin.cpp	Thu Jun 25 16:23:30 2009 +0000
+++ b/PyPlugin.cpp	Fri Jul 10 15:14:24 2009 +0000
@@ -1,3 +1,4 @@
+/* -*- c-basic-offset: 8 indent-tabs-mode: t -*- */
 /*
     Vamp
 
@@ -66,7 +67,7 @@
 using std::map;
 
 // Maps to associate strings with enum values
-static std::map<std::string, eOutDescriptors> outKeys;
+static std::map<std::string, o::eOutDescriptors> outKeys;
 static std::map<std::string, eSampleTypes> sampleKeys;
 static std::map<std::string, eFeatureFields> ffKeys;
 static std::map<std::string, p::eParmDescriptors> parmKeys;
@@ -280,15 +281,15 @@
 	char legacyMethod[]="process";
 	char numpyMethod[]="processN";
 
-	if (PyObject_HasAttrString(m_pyInstance,legacyMethod) &
-		m_processType == 0) 
+	if (PyObject_HasAttrString(m_pyInstance,legacyMethod) &&
+	    m_processType == 0) 
 	{ 
 		m_processType = legacyProcess;
 		m_pyProcess = PyString_FromString(legacyMethod);
 	}
 
-	if (PyObject_HasAttrString(m_pyInstance,numpyMethod) & 
-		m_processType == 0)
+	if (PyObject_HasAttrString(m_pyInstance,numpyMethod) &&
+	    m_processType == 0)
 	{
 		m_processType = numpyProcess;
 		m_pyProcess = PyString_FromString(numpyMethod);
@@ -516,7 +517,7 @@
 		//Parse Output List
 		for (Py_ssize_t i = 0; i < PyList_GET_SIZE(pyList); ++i) {
 	
-			//Get i-th VAMP output descriptor (Borrowed Reference)
+			//Get i-th Vamp output descriptor (Borrowed Reference)
 			pyDict = PyList_GET_ITEM(pyList,i);
 			
 			//We only care about dictionaries holding output descriptors
@@ -530,55 +531,58 @@
 			{		
 				switch (outKeys[PyString_AsString(pyKey)]) 
 				{
-					case not_found : 	
-						cerr << "Unknown key in VAMP OutputDescriptor: " << PyString_AsString(pyKey) << endl; 
+					case o::not_found : 	
+						cerr << "Unknown key in Vamp OutputDescriptor: " << PyString_AsString(pyKey) << endl; 
 						break;
-					case identifier: 	
+					case o::identifier: 	
 						od.identifier = PyString_AsString(pyValue); 
 						break;				
-					case name: 			
+					case o::name: 			
 						od.name = PyString_AsString(pyValue); 
 						break;
-					case description: 	
+					case o::description: 	
 						od.description = PyString_AsString(pyValue); 
 						break; 								
-					case unit: 			
+					case o::unit: 			
 						od.unit = PyString_AsString(pyValue); 
 						break; 													
-					case hasFixedBinCount:
+					case o::hasFixedBinCount:
 						od.hasFixedBinCount = (bool) PyInt_AS_LONG(pyValue); 
 						break;
-					case binCount:
+					case o::binCount:
 						od.binCount = (size_t) PyInt_AS_LONG(pyValue);
 						break;
-					case binNames:
+					case o::binNames:
 						od.binNames = PyList_To_StringVector(pyValue);
 						break;
-					case hasKnownExtents:
+					case o::hasKnownExtents:
 						od.hasKnownExtents = (bool) PyInt_AS_LONG(pyValue); 
 						break;					
-					case minValue:
+					case o::minValue:
 						od.minValue = (float) PyFloat_AS_DOUBLE(pyValue);
 						break;
-					case maxValue:
+					case o::maxValue:
 						od.maxValue = (float) PyFloat_AS_DOUBLE(pyValue);
 						break;
-					case isQuantized:
+					case o::isQuantized:
 						od.isQuantized = (bool) PyInt_AS_LONG(pyValue); 
 						break;					
-					case quantizeStep:
+					case o::quantizeStep:
 						od.quantizeStep = (float) PyFloat_AS_DOUBLE(pyValue);
 						break;
-					case sampleType: 				
+					case o::sampleType: 				
 						od.sampleType = (OutputDescriptor::SampleType) sampleKeys[PyString_AsString(pyValue)];
 						break;
-					case sampleRate:
+					case o::sampleRate:
 						od.sampleRate = (float) PyFloat_AS_DOUBLE(pyValue);
 //						od.sampleRate = m_inputSampleRate / m_stepSize;
 						cerr << od.sampleRate << endl;
 						break;					
+					case o::hasDuration:
+						od.hasDuration = (bool)PyInt_AS_LONG(pyValue);
+						break;
 					default : 	
-						cerr << "Invalid key in VAMP OutputDescriptor: " << PyString_AsString(pyKey) << endl; 
+						cerr << "Invalid key in Vamp OutputDescriptor: " << PyString_AsString(pyKey) << endl; 
 				} 					
 			} // while dict
 			list.push_back(od);
@@ -619,7 +623,7 @@
 		//Parse Output List
 		for (Py_ssize_t i = 0; i < PyList_GET_SIZE(pyList); ++i) {
 	
-			//Get i-th VAMP output descriptor (Borrowed Reference)
+			//Get i-th Vamp output descriptor (Borrowed Reference)
 			pyDict = PyList_GET_ITEM(pyList,i);
 			
 			//We only care about dictionaries holding output descriptors
@@ -633,8 +637,8 @@
 			{		
 				switch (parmKeys[PyString_AsString(pyKey)]) 
 				{
-					case not_found : 	
-						cerr << "Unknown key in VAMP OutputDescriptor: " << PyString_AsString(pyKey) << endl; 
+					case p::not_found : 	
+						cerr << "Unknown key in Vamp OutputDescriptor: " << PyString_AsString(pyKey) << endl; 
 						break;
 					case p::identifier: 	
 						pd.identifier = PyString_AsString(pyValue); 
@@ -661,7 +665,7 @@
 						pd.isQuantized = (bool) PyInt_AS_LONG(pyValue); 
 						break;					
 					default : 	
-						cerr << "Invalid key in VAMP OutputDescriptor: " << PyString_AsString(pyKey) << endl; 
+						cerr << "Invalid key in Vamp OutputDescriptor: " << PyString_AsString(pyKey) << endl; 
 				} 				
 			} // while dict
 			list.push_back(pd);
@@ -892,8 +896,8 @@
 					emptyFeature = false;
 					switch (ffKeys[PyString_AsString(pyKey)]) 
 					{
-						case not_found : 	
-							cerr << "Unknown key in VAMP FeatureSet: " 
+						case unknown: 	
+							cerr << "Unknown key in Vamp FeatureSet: " 
 							<< PyString_AsString(pyKey) << endl; 
 							break;
 						case hasTimestamp: 	
@@ -910,6 +914,20 @@
 							<< feature.timestamp.toString() << endl;
 #endif
 							break;
+						case hasDuration: 	
+							feature.hasDuration = (bool) PyInt_AS_LONG(pyValue); 
+							break;				
+						case duration: 			
+							feature.duration =  
+							Vamp::RealTime::frame2RealTime(
+							PyLong_AsLong(pyValue), 
+							(unsigned int) m_inputSampleRate );
+#ifdef _DEBUG
+							cerr << "Duration: " 
+							<< (long)PyLong_AsLong(pyValue) << ", ->" 
+							<< feature.duration.toString() << endl;
+#endif
+							break;
 						case values: 	
 							feature.values = PyList_As_FloatVector(pyValue); 
 							break; 								
@@ -917,7 +935,7 @@
 							feature.label = PyString_AsString(pyValue); 
 							break; 													
 						default : 	
-							cerr << "Invalid key in VAMP FeatureSet: " 
+							cerr << "Invalid key in Vamp FeatureSet: " 
 							<< PyString_AsString(pyKey) << endl; 
 					} // switch					
 
@@ -994,8 +1012,8 @@
 					emptyFeature = false;
 					switch (ffKeys[PyString_AsString(pyKey)]) 
 					{
-						case not_found : 	
-							cerr << "Unknown key in VAMP FeatureSet: " 
+						case unknown : 	
+							cerr << "Unknown key in Vamp FeatureSet: " 
 							<< PyString_AsString(pyKey) << endl; 
 							break;
 						case hasTimestamp: 	
@@ -1012,6 +1030,20 @@
 							<< feature.timestamp.toString() << endl;
 #endif
 							break;
+						case hasDuration: 	
+							feature.hasDuration = (bool) PyInt_AS_LONG(pyValue); 
+							break;				
+						case duration:
+							feature.duration =  
+							Vamp::RealTime::frame2RealTime(
+							PyLong_AsLong(pyValue), 
+							(unsigned int) m_inputSampleRate );
+#ifdef _DEBUG
+							cerr << "Duration: " 
+							<< (long)PyLong_AsLong(pyValue) << ", ->" 
+							<< feature.duration.toString() << endl;
+#endif
+							break;
 						case values: 	
 							feature.values = PyList_As_FloatVector(pyValue); 
 							break; 								
@@ -1034,20 +1066,21 @@
 
 	if (isMapInitialised) return true;
 
-	outKeys["identifier"] = identifier;
-	outKeys["name"] = name;
-	outKeys["description"] = description;
-	outKeys["unit"] = unit;
-	outKeys["hasFixedBinCount"] = hasFixedBinCount; 
-	outKeys["binCount"] = binCount;
-	outKeys["binNames"] = binNames;
-	outKeys["hasKnownExtents"] = hasKnownExtents;
-	outKeys["minValue"] = minValue;
-	outKeys["maxValue"] = maxValue;
-	outKeys["isQuantized"] = isQuantized;
-	outKeys["quantizeStep"] = quantizeStep;
-	outKeys["sampleType"] = sampleType;
-	outKeys["sampleRate"] = sampleRate;
+	outKeys["identifier"] = o::identifier;
+	outKeys["name"] = o::name;
+	outKeys["description"] = o::description;
+	outKeys["unit"] = o::unit;
+	outKeys["hasFixedBinCount"] = o::hasFixedBinCount; 
+	outKeys["binCount"] = o::binCount;
+	outKeys["binNames"] = o::binNames;
+	outKeys["hasKnownExtents"] = o::hasKnownExtents;
+	outKeys["minValue"] = o::minValue;
+	outKeys["maxValue"] = o::maxValue;
+	outKeys["isQuantized"] = o::isQuantized;
+	outKeys["quantizeStep"] = o::quantizeStep;
+	outKeys["sampleType"] = o::sampleType;
+	outKeys["sampleRate"] = o::sampleRate;
+	outKeys["hasDuration"] = o::hasDuration;
 
 	sampleKeys["OneSamplePerStep"] = OneSamplePerStep;
 	sampleKeys["FixedSampleRate"] = FixedSampleRate;
@@ -1055,6 +1088,8 @@
 
 	ffKeys["hasTimestamp"] = hasTimestamp;
 	ffKeys["timeStamp"] = timeStamp;
+	ffKeys["hasDuration"] = hasDuration;
+	ffKeys["duration"] = duration;
 	ffKeys["values"] = values;
 	ffKeys["label"] = label;
 
--- a/PyPlugin.h	Thu Jun 25 16:23:30 2009 +0000
+++ b/PyPlugin.h	Fri Jul 10 15:14:24 2009 +0000
@@ -1,3 +1,4 @@
+/* -*- c-basic-offset: 8 indent-tabs-mode: t -*- */
 /*
     Vamp
 
@@ -45,6 +46,7 @@
 #include "Mutex.h"
 
 //fields in OutputDescriptor
+namespace o {
 enum eOutDescriptors {
 	not_found,
 	identifier,
@@ -61,8 +63,10 @@
 	quantizeStep,
 	sampleType,	
 	sampleRate,
+	hasDuration,
 	endNode
 	}; 
+}
 
 namespace p {
 enum eParmDescriptors {
@@ -88,6 +92,8 @@
 	unknown,
 	hasTimestamp,
 	timeStamp,
+	hasDuration,
+	duration,
 	values,
 	label
 	};
@@ -101,11 +107,11 @@
 class PyPlugin : public Vamp::Plugin
 {
 public:
-    PyPlugin(std::string plugin,float inputSampleRate, PyObject *pyInstance);
-    virtual ~PyPlugin();
+	PyPlugin(std::string plugin,float inputSampleRate, PyObject *pyInstance);
+	virtual ~PyPlugin();
 
-    bool initialise(size_t channels, size_t stepSize, size_t blockSize);
-    void reset();
+	bool initialise(size_t channels, size_t stepSize, size_t blockSize);
+	void reset();
 
 	InputDomain getInputDomain() const;
 	size_t getPreferredBlockSize() const;
@@ -113,28 +119,28 @@
 	size_t getMinChannelCount() const; 
 	size_t getMaxChannelCount() const;
 
-    std::string getIdentifier() const;
-    std::string getName() const;
-    std::string getDescription() const;
-    std::string getMaker() const;
-    int getPluginVersion() const;
-    std::string getCopyright() const;
- 
-    OutputList getOutputDescriptors() const;
-    ParameterList getParameterDescriptors() const;
+	std::string getIdentifier() const;
+	std::string getName() const;
+	std::string getDescription() const;
+	std::string getMaker() const;
+	int getPluginVersion() const;
+	std::string getCopyright() const;
+	
+	OutputList getOutputDescriptors() const;
+	ParameterList getParameterDescriptors() const;
 	float getParameter(std::string paramid) const;
 	void setParameter(std::string paramid, float newval);
     
-FeatureSet process(const float *const *inputBuffers,
-                       Vamp::RealTime timestamp);
+	FeatureSet process(const float *const *inputBuffers,
+			   Vamp::RealTime timestamp);
 
-    FeatureSet getRemainingFeatures();
+	FeatureSet getRemainingFeatures();
 
 protected:
 	PyObject *m_pyInstance;
-    size_t m_stepSize;
-    size_t m_blockSize;
-    size_t m_channels;
+	size_t m_stepSize;
+	size_t m_blockSize;
+	size_t m_channels;
 	std::string m_plugin;
 	std::string m_class;
 	std::string m_path;
--- a/pyvamp-main.cpp	Thu Jun 25 16:23:30 2009 +0000
+++ b/pyvamp-main.cpp	Fri Jul 10 15:14:24 2009 +0000
@@ -128,7 +128,7 @@
     string pyver = Py_GetVersion();
     int dots = 2;
     string shortver;
-    for (int i = 0; i < pyver.length(); ++i) {
+    for (size_t i = 0; i < pyver.length(); ++i) {
         if (pyver[i] == '.') {
             if (--dots == 0) {
                 shortver = pyver.substr(0, i);
@@ -148,7 +148,7 @@
 
     // hahaha! grossness is like a brother to us
 #ifdef __APPLE__
-    for (int pfxidx = 0; pfxidx < pfxs.size(); ++pfxidx) {
+    for (size_t pfxidx = 0; pfxidx < pfxs.size(); ++pfxidx) {
         for (int minor = 8; minor >= 0; --minor) {
             sprintf(buffer, "%d", minor);
             if (tryPreload(pfxs[pfxidx] + string("libpython") + shortver + ".dylib." + buffer)) return true;
@@ -157,7 +157,7 @@
         if (tryPreload(pfxs[pfxidx] + string("libpython.dylib"))) return true;
     }
 #else
-    for (int pfxidx = 0; pfxidx < pfxs.size(); ++pfxidx) {
+    for (size_t pfxidx = 0; pfxidx < pfxs.size(); ++pfxidx) {
         for (int minor = 8; minor >= 0; --minor) {
             sprintf(buffer, "%d", minor);
             if (tryPreload(pfxs[pfxidx] + string("libpython") + shortver + ".so." + buffer)) return true;