comparison plugin/FeatureExtractionPluginFactory.cpp @ 71:e32c6a6cb40f

* Remove dsp directory. This is now the qm-dsp library used by qm-vamp-plugins instead of being used in Sonic Visualiser directly. * Remove plugins that have now become part of qm-vamp-plugins. * Move time stretcher from dsp to audioio (this is the one DSP thing we do need in SV)
author Chris Cannam
date Thu, 06 Apr 2006 12:12:41 +0000
parents 7afcfe666910
children e9b8b51f6326
comparison
equal deleted inserted replaced
70:d26c85099215 71:e32c6a6cb40f
14 */ 14 */
15 15
16 #include "FeatureExtractionPluginFactory.h" 16 #include "FeatureExtractionPluginFactory.h"
17 #include "PluginIdentifier.h" 17 #include "PluginIdentifier.h"
18 18
19 #include "plugins/BeatDetect.h" //!!!
20 #include "plugins/ChromagramPlugin.h" //!!!
21 #include "plugins/ZeroCrossing.h" //!!!
22 #include "plugins/SpectralCentroid.h" //!!!
23 #include "plugins/TonalChangeDetect.h" //!!!
24
25 #include "vamp/vamp.h" 19 #include "vamp/vamp.h"
26 #include "vamp-sdk/PluginHostAdapter.h" 20 #include "vamp-sdk/PluginHostAdapter.h"
27 21
28 #include "base/System.h" 22 #include "base/System.h"
29 23
36 static FeatureExtractionPluginFactory *_nativeInstance = 0; 30 static FeatureExtractionPluginFactory *_nativeInstance = 0;
37 31
38 FeatureExtractionPluginFactory * 32 FeatureExtractionPluginFactory *
39 FeatureExtractionPluginFactory::instance(QString pluginType) 33 FeatureExtractionPluginFactory::instance(QString pluginType)
40 { 34 {
41 if (pluginType == "vamp" || pluginType == "sv") { //!!! 35 if (pluginType == "vamp") {
42 if (!_nativeInstance) { 36 if (!_nativeInstance) {
43 std::cerr << "FeatureExtractionPluginFactory::instance(" << pluginType.toStdString() 37 std::cerr << "FeatureExtractionPluginFactory::instance(" << pluginType.toStdString()
44 << "): creating new FeatureExtractionPluginFactory" << std::endl; 38 << "): creating new FeatureExtractionPluginFactory" << std::endl;
45 _nativeInstance = new FeatureExtractionPluginFactory(); 39 _nativeInstance = new FeatureExtractionPluginFactory();
46 } 40 }
110 104
111 std::vector<QString> 105 std::vector<QString>
112 FeatureExtractionPluginFactory::getPluginIdentifiers() 106 FeatureExtractionPluginFactory::getPluginIdentifiers()
113 { 107 {
114 std::vector<QString> rv; 108 std::vector<QString> rv;
115 rv.push_back("sv:_builtin:beats"); //!!!
116 rv.push_back("sv:_builtin:chromagram"); //!!!
117 rv.push_back("sv:_builtin:zerocrossing"); //!!!
118 rv.push_back("sv:_builtin:spectralcentroid"); //!!!
119 rv.push_back("sv:_builtin:tonalchange"); //!!!
120
121 std::vector<QString> path = getPluginPath(); 109 std::vector<QString> path = getPluginPath();
122 110
123 for (std::vector<QString>::iterator i = path.begin(); i != path.end(); ++i) { 111 for (std::vector<QString>::iterator i = path.begin(); i != path.end(); ++i) {
124 112
125 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: scanning directory " << i->toStdString() << std::endl; 113 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: scanning directory " << i->toStdString() << std::endl;
133 QString soname = pluginDir.filePath(pluginDir[j]); 121 QString soname = pluginDir.filePath(pluginDir[j]);
134 122
135 void *libraryHandle = DLOPEN(soname, RTLD_LAZY); 123 void *libraryHandle = DLOPEN(soname, RTLD_LAZY);
136 124
137 if (!libraryHandle) { 125 if (!libraryHandle) {
138 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname.toStdString() << std::endl; 126 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname.toStdString() << ": " << DLERROR() << std::endl;
139 continue; 127 continue;
140 } 128 }
141 129
142 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) 130 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction)
143 DLSYM(libraryHandle, "vampGetPluginDescriptor"); 131 DLSYM(libraryHandle, "vampGetPluginDescriptor");
227 const VampPluginDescriptor *descriptor = 0; 215 const VampPluginDescriptor *descriptor = 0;
228 int index = 0; 216 int index = 0;
229 217
230 QString type, soname, label; 218 QString type, soname, label;
231 PluginIdentifier::parseIdentifier(identifier, type, soname, label); 219 PluginIdentifier::parseIdentifier(identifier, type, soname, label);
232 if (type != "vamp" && type != "sv") { //!!! 220 if (type != "vamp") {
233 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type.toStdString() << std::endl; 221 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type.toStdString() << std::endl;
234 return 0; 222 return 0;
235 }
236
237 //!!!
238 if (type == "sv" && soname == PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
239
240 if (label == "beats") {
241 return new BeatDetector(inputSampleRate); //!!!
242 }
243
244 if (label == "chromagram") {
245 return new ChromagramPlugin(inputSampleRate); //!!!
246 }
247
248 if (label == "zerocrossing") {
249 return new ZeroCrossing(inputSampleRate); //!!!
250 }
251
252 if (label == "spectralcentroid") {
253 return new SpectralCentroid(inputSampleRate); //!!!
254 }
255
256 if (label == "tonalchange") {
257 return new TonalChangeDetect(inputSampleRate); //!!!
258 }
259
260 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Unknown plugin \"" << identifier.toStdString() << "\"" << std::endl;
261
262 return 0;
263 } 223 }
264 224
265 QString found = findPluginFile(soname); 225 QString found = findPluginFile(soname);
266 226
267 if (found == "") { 227 if (found == "") {
273 soname = found; 233 soname = found;
274 234
275 void *libraryHandle = DLOPEN(soname, RTLD_LAZY); 235 void *libraryHandle = DLOPEN(soname, RTLD_LAZY);
276 236
277 if (!libraryHandle) { 237 if (!libraryHandle) {
278 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to load library " << soname.toStdString() << std::endl; 238 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to load library " << soname.toStdString() << ": " << DLERROR() << std::endl;
279 return 0; 239 return 0;
280 } 240 }
281 241
282 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) 242 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction)
283 DLSYM(libraryHandle, "vampGetPluginDescriptor"); 243 DLSYM(libraryHandle, "vampGetPluginDescriptor");