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" //!!!
|
Martin@37
|
16 // NOTE: added by Martin Gasser
|
Martin@37
|
17 #include "plugins/TonalChangeDetect.h" //!!!
|
Chris@0
|
18
|
Chris@0
|
19 #include <iostream>
|
Chris@0
|
20
|
Chris@0
|
21 static FeatureExtractionPluginFactory *_nativeInstance = 0;
|
Chris@0
|
22
|
Chris@0
|
23 FeatureExtractionPluginFactory *
|
Chris@0
|
24 FeatureExtractionPluginFactory::instance(QString pluginType)
|
Chris@0
|
25 {
|
Chris@0
|
26 if (pluginType == "sv") {
|
Chris@0
|
27 if (!_nativeInstance) {
|
Chris@0
|
28 std::cerr << "FeatureExtractionPluginFactory::instance(" << pluginType.toStdString()
|
Chris@0
|
29 << "): creating new FeatureExtractionPluginFactory" << std::endl;
|
Chris@0
|
30 _nativeInstance = new FeatureExtractionPluginFactory();
|
Chris@0
|
31 }
|
Chris@0
|
32 return _nativeInstance;
|
Chris@0
|
33 }
|
Chris@0
|
34
|
Chris@0
|
35 else return 0;
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 FeatureExtractionPluginFactory *
|
Chris@0
|
39 FeatureExtractionPluginFactory::instanceFor(QString identifier)
|
Chris@0
|
40 {
|
Chris@0
|
41 QString type, soName, label;
|
Chris@0
|
42 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
|
Chris@0
|
43 return instance(type);
|
Chris@0
|
44 }
|
Chris@0
|
45
|
Chris@0
|
46 std::vector<QString>
|
Chris@0
|
47 FeatureExtractionPluginFactory::getAllPluginIdentifiers()
|
Chris@0
|
48 {
|
Chris@0
|
49 FeatureExtractionPluginFactory *factory;
|
Chris@0
|
50 std::vector<QString> rv;
|
Chris@0
|
51
|
Chris@0
|
52 factory = instance("sv");
|
Chris@0
|
53 if (factory) {
|
Chris@0
|
54 std::vector<QString> tmp = factory->getPluginIdentifiers();
|
Chris@0
|
55 for (size_t i = 0; i < tmp.size(); ++i) {
|
Chris@0
|
56 rv.push_back(tmp[i]);
|
Chris@0
|
57 }
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 // Plugins can change the locale, revert it to default.
|
Chris@0
|
61 setlocale(LC_ALL, "C");
|
Chris@0
|
62 return rv;
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@0
|
65 std::vector<QString>
|
Chris@0
|
66 FeatureExtractionPluginFactory::getPluginIdentifiers()
|
Chris@0
|
67 {
|
Chris@0
|
68 std::vector<QString> rv;
|
Chris@0
|
69 rv.push_back("sv:_builtin:beats"); //!!!
|
Chris@19
|
70 rv.push_back("sv:_builtin:chromagram"); //!!!
|
Chris@0
|
71 rv.push_back("sv:_builtin:zerocrossing"); //!!!
|
Martin@37
|
72 // NOTE: added by Martin Gasser
|
Martin@37
|
73 rv.push_back("sv:_builtin:tonalchange"); //!!!
|
Chris@0
|
74 return rv;
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 FeatureExtractionPlugin *
|
Chris@0
|
78 FeatureExtractionPluginFactory::instantiatePlugin(QString identifier,
|
Chris@0
|
79 float inputSampleRate)
|
Chris@0
|
80 {
|
Chris@0
|
81 QString type, soName, label;
|
Chris@0
|
82 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
|
Chris@0
|
83 if (type != "sv") {
|
Chris@0
|
84 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type.toStdString() << std::endl;
|
Chris@0
|
85 return 0;
|
Chris@0
|
86 }
|
Chris@0
|
87
|
Chris@0
|
88 //!!!
|
Chris@0
|
89 if (soName != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
|
Chris@0
|
90 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Non-built-in plugins not yet supported (paradoxically enough)" << std::endl;
|
Chris@0
|
91 return 0;
|
Chris@0
|
92 }
|
Chris@0
|
93
|
Chris@0
|
94 if (label == "beats") {
|
Chris@0
|
95 return new BeatDetector(inputSampleRate); //!!!
|
Chris@0
|
96 }
|
Chris@0
|
97
|
Chris@19
|
98 if (label == "chromagram") {
|
Chris@19
|
99 return new ChromagramPlugin(inputSampleRate); //!!!
|
Chris@19
|
100 }
|
Chris@19
|
101
|
Chris@0
|
102 if (label == "zerocrossing") {
|
Chris@0
|
103 return new ZeroCrossing(inputSampleRate); //!!!
|
Chris@0
|
104 }
|
Chris@0
|
105
|
Martin@37
|
106 // NOTE: added by Martin Gasser
|
Martin@37
|
107 if (label == "tonalchange") {
|
Martin@37
|
108 return new TonalChangeDetect(inputSampleRate); //!!!
|
Martin@37
|
109 }
|
Martin@37
|
110
|
Chris@0
|
111 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Unknown plugin \"" << identifier.toStdString() << "\"" << std::endl;
|
Chris@0
|
112
|
Chris@0
|
113 return 0;
|
Chris@0
|
114 }
|
Chris@0
|
115
|