annotate plugin/FeatureExtractionPluginFactory.cpp @ 0:da6937383da8

initial import
author Chris Cannam
date Tue, 10 Jan 2006 16:33:16 +0000
parents
children d86891498eef
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 A waveform viewer and audio annotation editor.
Chris@0 5 Chris Cannam, Queen Mary University of London, 2005
Chris@0 6
Chris@0 7 This is experimental software. Not for distribution.
Chris@0 8 */
Chris@0 9
Chris@0 10 #include "FeatureExtractionPluginFactory.h"
Chris@0 11 #include "PluginIdentifier.h"
Chris@0 12
Chris@0 13 #include "plugins/BeatDetect.h" //!!!
Chris@0 14 #include "plugins/ZeroCrossing.h" //!!!
Chris@0 15
Chris@0 16 #include <iostream>
Chris@0 17
Chris@0 18 static FeatureExtractionPluginFactory *_nativeInstance = 0;
Chris@0 19
Chris@0 20 FeatureExtractionPluginFactory *
Chris@0 21 FeatureExtractionPluginFactory::instance(QString pluginType)
Chris@0 22 {
Chris@0 23 if (pluginType == "sv") {
Chris@0 24 if (!_nativeInstance) {
Chris@0 25 std::cerr << "FeatureExtractionPluginFactory::instance(" << pluginType.toStdString()
Chris@0 26 << "): creating new FeatureExtractionPluginFactory" << std::endl;
Chris@0 27 _nativeInstance = new FeatureExtractionPluginFactory();
Chris@0 28 }
Chris@0 29 return _nativeInstance;
Chris@0 30 }
Chris@0 31
Chris@0 32 else return 0;
Chris@0 33 }
Chris@0 34
Chris@0 35 FeatureExtractionPluginFactory *
Chris@0 36 FeatureExtractionPluginFactory::instanceFor(QString identifier)
Chris@0 37 {
Chris@0 38 QString type, soName, label;
Chris@0 39 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
Chris@0 40 return instance(type);
Chris@0 41 }
Chris@0 42
Chris@0 43 std::vector<QString>
Chris@0 44 FeatureExtractionPluginFactory::getAllPluginIdentifiers()
Chris@0 45 {
Chris@0 46 FeatureExtractionPluginFactory *factory;
Chris@0 47 std::vector<QString> rv;
Chris@0 48
Chris@0 49 factory = instance("sv");
Chris@0 50 if (factory) {
Chris@0 51 std::vector<QString> tmp = factory->getPluginIdentifiers();
Chris@0 52 for (size_t i = 0; i < tmp.size(); ++i) {
Chris@0 53 rv.push_back(tmp[i]);
Chris@0 54 }
Chris@0 55 }
Chris@0 56
Chris@0 57 // Plugins can change the locale, revert it to default.
Chris@0 58 setlocale(LC_ALL, "C");
Chris@0 59 return rv;
Chris@0 60 }
Chris@0 61
Chris@0 62 std::vector<QString>
Chris@0 63 FeatureExtractionPluginFactory::getPluginIdentifiers()
Chris@0 64 {
Chris@0 65 std::vector<QString> rv;
Chris@0 66 rv.push_back("sv:_builtin:beats"); //!!!
Chris@0 67 rv.push_back("sv:_builtin:zerocrossing"); //!!!
Chris@0 68 return rv;
Chris@0 69 }
Chris@0 70
Chris@0 71 FeatureExtractionPlugin *
Chris@0 72 FeatureExtractionPluginFactory::instantiatePlugin(QString identifier,
Chris@0 73 float inputSampleRate)
Chris@0 74 {
Chris@0 75 QString type, soName, label;
Chris@0 76 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
Chris@0 77 if (type != "sv") {
Chris@0 78 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type.toStdString() << std::endl;
Chris@0 79 return 0;
Chris@0 80 }
Chris@0 81
Chris@0 82 //!!!
Chris@0 83 if (soName != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
Chris@0 84 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Non-built-in plugins not yet supported (paradoxically enough)" << std::endl;
Chris@0 85 return 0;
Chris@0 86 }
Chris@0 87
Chris@0 88 if (label == "beats") {
Chris@0 89 return new BeatDetector(inputSampleRate); //!!!
Chris@0 90 }
Chris@0 91
Chris@0 92 if (label == "zerocrossing") {
Chris@0 93 return new ZeroCrossing(inputSampleRate); //!!!
Chris@0 94 }
Chris@0 95
Chris@0 96 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Unknown plugin \"" << identifier.toStdString() << "\"" << std::endl;
Chris@0 97
Chris@0 98 return 0;
Chris@0 99 }
Chris@0 100