Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@0: A waveform viewer and audio annotation editor. Chris@2: Chris Cannam, Queen Mary University of London, 2005-2006 Chris@0: Chris@0: This is experimental software. Not for distribution. Chris@0: */ Chris@0: Chris@0: #include "FeatureExtractionPluginFactory.h" Chris@0: #include "PluginIdentifier.h" Chris@0: Chris@0: #include "plugins/BeatDetect.h" //!!! Chris@19: #include "plugins/ChromagramPlugin.h" //!!! Chris@0: #include "plugins/ZeroCrossing.h" //!!! Chris@47: #include "plugins/SpectralCentroid.h" //!!! Martin@37: #include "plugins/TonalChangeDetect.h" //!!! Chris@0: Chris@0: #include Chris@0: Chris@0: static FeatureExtractionPluginFactory *_nativeInstance = 0; Chris@0: Chris@0: FeatureExtractionPluginFactory * Chris@0: FeatureExtractionPluginFactory::instance(QString pluginType) Chris@0: { Chris@0: if (pluginType == "sv") { Chris@0: if (!_nativeInstance) { Chris@0: std::cerr << "FeatureExtractionPluginFactory::instance(" << pluginType.toStdString() Chris@0: << "): creating new FeatureExtractionPluginFactory" << std::endl; Chris@0: _nativeInstance = new FeatureExtractionPluginFactory(); Chris@0: } Chris@0: return _nativeInstance; Chris@0: } Chris@0: Chris@0: else return 0; Chris@0: } Chris@0: Chris@0: FeatureExtractionPluginFactory * Chris@0: FeatureExtractionPluginFactory::instanceFor(QString identifier) Chris@0: { Chris@0: QString type, soName, label; Chris@0: PluginIdentifier::parseIdentifier(identifier, type, soName, label); Chris@0: return instance(type); Chris@0: } Chris@0: Chris@0: std::vector Chris@0: FeatureExtractionPluginFactory::getAllPluginIdentifiers() Chris@0: { Chris@0: FeatureExtractionPluginFactory *factory; Chris@0: std::vector rv; Chris@0: Chris@0: factory = instance("sv"); Chris@0: if (factory) { Chris@0: std::vector tmp = factory->getPluginIdentifiers(); Chris@0: for (size_t i = 0; i < tmp.size(); ++i) { Chris@0: rv.push_back(tmp[i]); Chris@0: } Chris@0: } Chris@0: Chris@0: // Plugins can change the locale, revert it to default. Chris@0: setlocale(LC_ALL, "C"); Chris@0: return rv; Chris@0: } Chris@0: Chris@0: std::vector Chris@0: FeatureExtractionPluginFactory::getPluginIdentifiers() Chris@0: { Chris@0: std::vector rv; Chris@0: rv.push_back("sv:_builtin:beats"); //!!! Chris@19: rv.push_back("sv:_builtin:chromagram"); //!!! Chris@0: rv.push_back("sv:_builtin:zerocrossing"); //!!! Chris@47: rv.push_back("sv:_builtin:spectralcentroid"); //!!! Chris@47: rv.push_back("sv:_builtin:tonalchange"); //!!! Chris@0: return rv; Chris@0: } Chris@0: Chris@0: FeatureExtractionPlugin * Chris@0: FeatureExtractionPluginFactory::instantiatePlugin(QString identifier, Chris@0: float inputSampleRate) Chris@0: { Chris@0: QString type, soName, label; Chris@0: PluginIdentifier::parseIdentifier(identifier, type, soName, label); Chris@0: if (type != "sv") { Chris@0: std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type.toStdString() << std::endl; Chris@0: return 0; Chris@0: } Chris@0: Chris@0: //!!! Chris@0: if (soName != PluginIdentifier::BUILTIN_PLUGIN_SONAME) { Chris@0: std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Non-built-in plugins not yet supported (paradoxically enough)" << std::endl; Chris@0: return 0; Chris@0: } Chris@0: Chris@0: if (label == "beats") { Chris@0: return new BeatDetector(inputSampleRate); //!!! Chris@0: } Chris@0: Chris@19: if (label == "chromagram") { Chris@19: return new ChromagramPlugin(inputSampleRate); //!!! Chris@19: } Chris@19: Chris@0: if (label == "zerocrossing") { Chris@0: return new ZeroCrossing(inputSampleRate); //!!! Chris@0: } Chris@0: Chris@47: if (label == "spectralcentroid") { Chris@47: return new SpectralCentroid(inputSampleRate); //!!! Chris@47: } Chris@47: Martin@37: if (label == "tonalchange") { Martin@37: return new TonalChangeDetect(inputSampleRate); //!!! Martin@37: } Martin@37: Chris@0: std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Unknown plugin \"" << identifier.toStdString() << "\"" << std::endl; Chris@0: Chris@0: return 0; Chris@0: } Chris@0: