comparison plugin/FeatureExtractionPluginFactory.cpp @ 0:da6937383da8

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