annotate plugin/FeatureExtractionPluginFactory.cpp @ 54:709d63d90028

fixed some bugs in tonal change detection function, removed ChromaMatrix (no longer used), added TCSgram
author Martin Gasser
date Tue, 21 Mar 2006 18:05:28 +0000
parents d397ea0a79f5
children 7afcfe666910
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "FeatureExtractionPluginFactory.h"
Chris@0 17 #include "PluginIdentifier.h"
Chris@0 18
Chris@0 19 #include "plugins/BeatDetect.h" //!!!
Chris@19 20 #include "plugins/ChromagramPlugin.h" //!!!
Chris@0 21 #include "plugins/ZeroCrossing.h" //!!!
Chris@47 22 #include "plugins/SpectralCentroid.h" //!!!
Martin@37 23 #include "plugins/TonalChangeDetect.h" //!!!
Chris@0 24
Chris@0 25 #include <iostream>
Chris@0 26
Chris@0 27 static FeatureExtractionPluginFactory *_nativeInstance = 0;
Chris@0 28
Chris@0 29 FeatureExtractionPluginFactory *
Chris@0 30 FeatureExtractionPluginFactory::instance(QString pluginType)
Chris@0 31 {
Chris@0 32 if (pluginType == "sv") {
Chris@0 33 if (!_nativeInstance) {
Chris@0 34 std::cerr << "FeatureExtractionPluginFactory::instance(" << pluginType.toStdString()
Chris@0 35 << "): creating new FeatureExtractionPluginFactory" << std::endl;
Chris@0 36 _nativeInstance = new FeatureExtractionPluginFactory();
Chris@0 37 }
Chris@0 38 return _nativeInstance;
Chris@0 39 }
Chris@0 40
Chris@0 41 else return 0;
Chris@0 42 }
Chris@0 43
Chris@0 44 FeatureExtractionPluginFactory *
Chris@0 45 FeatureExtractionPluginFactory::instanceFor(QString identifier)
Chris@0 46 {
Chris@0 47 QString type, soName, label;
Chris@0 48 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
Chris@0 49 return instance(type);
Chris@0 50 }
Chris@0 51
Chris@0 52 std::vector<QString>
Chris@0 53 FeatureExtractionPluginFactory::getAllPluginIdentifiers()
Chris@0 54 {
Chris@0 55 FeatureExtractionPluginFactory *factory;
Chris@0 56 std::vector<QString> rv;
Chris@0 57
Chris@0 58 factory = instance("sv");
Chris@0 59 if (factory) {
Chris@0 60 std::vector<QString> tmp = factory->getPluginIdentifiers();
Chris@0 61 for (size_t i = 0; i < tmp.size(); ++i) {
Chris@0 62 rv.push_back(tmp[i]);
Chris@0 63 }
Chris@0 64 }
Chris@0 65
Chris@0 66 // Plugins can change the locale, revert it to default.
Chris@0 67 setlocale(LC_ALL, "C");
Chris@0 68 return rv;
Chris@0 69 }
Chris@0 70
Chris@0 71 std::vector<QString>
Chris@0 72 FeatureExtractionPluginFactory::getPluginIdentifiers()
Chris@0 73 {
Chris@0 74 std::vector<QString> rv;
Chris@0 75 rv.push_back("sv:_builtin:beats"); //!!!
Chris@19 76 rv.push_back("sv:_builtin:chromagram"); //!!!
Chris@0 77 rv.push_back("sv:_builtin:zerocrossing"); //!!!
Chris@47 78 rv.push_back("sv:_builtin:spectralcentroid"); //!!!
Chris@47 79 rv.push_back("sv:_builtin:tonalchange"); //!!!
Chris@0 80 return rv;
Chris@0 81 }
Chris@0 82
Chris@0 83 FeatureExtractionPlugin *
Chris@0 84 FeatureExtractionPluginFactory::instantiatePlugin(QString identifier,
Chris@0 85 float inputSampleRate)
Chris@0 86 {
Chris@0 87 QString type, soName, label;
Chris@0 88 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
Chris@0 89 if (type != "sv") {
Chris@0 90 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type.toStdString() << std::endl;
Chris@0 91 return 0;
Chris@0 92 }
Chris@0 93
Chris@0 94 //!!!
Chris@0 95 if (soName != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
Chris@0 96 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Non-built-in plugins not yet supported (paradoxically enough)" << std::endl;
Chris@0 97 return 0;
Chris@0 98 }
Chris@0 99
Chris@0 100 if (label == "beats") {
Chris@0 101 return new BeatDetector(inputSampleRate); //!!!
Chris@0 102 }
Chris@0 103
Chris@19 104 if (label == "chromagram") {
Chris@19 105 return new ChromagramPlugin(inputSampleRate); //!!!
Chris@19 106 }
Chris@19 107
Chris@0 108 if (label == "zerocrossing") {
Chris@0 109 return new ZeroCrossing(inputSampleRate); //!!!
Chris@0 110 }
Chris@0 111
Chris@47 112 if (label == "spectralcentroid") {
Chris@47 113 return new SpectralCentroid(inputSampleRate); //!!!
Chris@47 114 }
Chris@47 115
Martin@37 116 if (label == "tonalchange") {
Martin@37 117 return new TonalChangeDetect(inputSampleRate); //!!!
Martin@37 118 }
Martin@37 119
Chris@0 120 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Unknown plugin \"" << identifier.toStdString() << "\"" << std::endl;
Chris@0 121
Chris@0 122 return 0;
Chris@0 123 }
Chris@0 124