annotate plugin/FeatureExtractionPluginFactory.cpp @ 35:0164c8d3023b

* Rejig project file a bit to do pkg-config detection &c and change some HAVE_* symbol names accordingly * Add selection move/resize/delete * First stubs for add layer / pane commands
author Chris Cannam
date Wed, 01 Mar 2006 18:13:01 +0000
parents a7ed14263fe4
children 838652cc31e6
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@2 5 Chris Cannam, Queen Mary University of London, 2005-2006
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@19 14 #include "plugins/ChromagramPlugin.h" //!!!
Chris@0 15 #include "plugins/ZeroCrossing.h" //!!!
Chris@0 16
Chris@0 17 #include <iostream>
Chris@0 18
Chris@0 19 static FeatureExtractionPluginFactory *_nativeInstance = 0;
Chris@0 20
Chris@0 21 FeatureExtractionPluginFactory *
Chris@0 22 FeatureExtractionPluginFactory::instance(QString pluginType)
Chris@0 23 {
Chris@0 24 if (pluginType == "sv") {
Chris@0 25 if (!_nativeInstance) {
Chris@0 26 std::cerr << "FeatureExtractionPluginFactory::instance(" << pluginType.toStdString()
Chris@0 27 << "): creating new FeatureExtractionPluginFactory" << std::endl;
Chris@0 28 _nativeInstance = new FeatureExtractionPluginFactory();
Chris@0 29 }
Chris@0 30 return _nativeInstance;
Chris@0 31 }
Chris@0 32
Chris@0 33 else return 0;
Chris@0 34 }
Chris@0 35
Chris@0 36 FeatureExtractionPluginFactory *
Chris@0 37 FeatureExtractionPluginFactory::instanceFor(QString identifier)
Chris@0 38 {
Chris@0 39 QString type, soName, label;
Chris@0 40 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
Chris@0 41 return instance(type);
Chris@0 42 }
Chris@0 43
Chris@0 44 std::vector<QString>
Chris@0 45 FeatureExtractionPluginFactory::getAllPluginIdentifiers()
Chris@0 46 {
Chris@0 47 FeatureExtractionPluginFactory *factory;
Chris@0 48 std::vector<QString> rv;
Chris@0 49
Chris@0 50 factory = instance("sv");
Chris@0 51 if (factory) {
Chris@0 52 std::vector<QString> tmp = factory->getPluginIdentifiers();
Chris@0 53 for (size_t i = 0; i < tmp.size(); ++i) {
Chris@0 54 rv.push_back(tmp[i]);
Chris@0 55 }
Chris@0 56 }
Chris@0 57
Chris@0 58 // Plugins can change the locale, revert it to default.
Chris@0 59 setlocale(LC_ALL, "C");
Chris@0 60 return rv;
Chris@0 61 }
Chris@0 62
Chris@0 63 std::vector<QString>
Chris@0 64 FeatureExtractionPluginFactory::getPluginIdentifiers()
Chris@0 65 {
Chris@0 66 std::vector<QString> rv;
Chris@0 67 rv.push_back("sv:_builtin:beats"); //!!!
Chris@19 68 rv.push_back("sv:_builtin:chromagram"); //!!!
Chris@0 69 rv.push_back("sv:_builtin:zerocrossing"); //!!!
Chris@0 70 return rv;
Chris@0 71 }
Chris@0 72
Chris@0 73 FeatureExtractionPlugin *
Chris@0 74 FeatureExtractionPluginFactory::instantiatePlugin(QString identifier,
Chris@0 75 float inputSampleRate)
Chris@0 76 {
Chris@0 77 QString type, soName, label;
Chris@0 78 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
Chris@0 79 if (type != "sv") {
Chris@0 80 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type.toStdString() << std::endl;
Chris@0 81 return 0;
Chris@0 82 }
Chris@0 83
Chris@0 84 //!!!
Chris@0 85 if (soName != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
Chris@0 86 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Non-built-in plugins not yet supported (paradoxically enough)" << std::endl;
Chris@0 87 return 0;
Chris@0 88 }
Chris@0 89
Chris@0 90 if (label == "beats") {
Chris@0 91 return new BeatDetector(inputSampleRate); //!!!
Chris@0 92 }
Chris@0 93
Chris@19 94 if (label == "chromagram") {
Chris@19 95 return new ChromagramPlugin(inputSampleRate); //!!!
Chris@19 96 }
Chris@19 97
Chris@0 98 if (label == "zerocrossing") {
Chris@0 99 return new ZeroCrossing(inputSampleRate); //!!!
Chris@0 100 }
Chris@0 101
Chris@0 102 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Unknown plugin \"" << identifier.toStdString() << "\"" << std::endl;
Chris@0 103
Chris@0 104 return 0;
Chris@0 105 }
Chris@0 106