diff plugin/FeatureExtractionPluginFactory.cpp @ 0:da6937383da8

initial import
author Chris Cannam
date Tue, 10 Jan 2006 16:33:16 +0000
parents
children d86891498eef
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/FeatureExtractionPluginFactory.cpp	Tue Jan 10 16:33:16 2006 +0000
@@ -0,0 +1,100 @@
+/* -*- c-basic-offset: 4 -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    A waveform viewer and audio annotation editor.
+    Chris Cannam, Queen Mary University of London, 2005
+    
+    This is experimental software.  Not for distribution.
+*/
+
+#include "FeatureExtractionPluginFactory.h"
+#include "PluginIdentifier.h"
+
+#include "plugins/BeatDetect.h" //!!!
+#include "plugins/ZeroCrossing.h" //!!!
+
+#include <iostream>
+
+static FeatureExtractionPluginFactory *_nativeInstance = 0;
+
+FeatureExtractionPluginFactory *
+FeatureExtractionPluginFactory::instance(QString pluginType)
+{
+    if (pluginType == "sv") {
+	if (!_nativeInstance) {
+	    std::cerr << "FeatureExtractionPluginFactory::instance(" << pluginType.toStdString()
+		      << "): creating new FeatureExtractionPluginFactory" << std::endl;
+	    _nativeInstance = new FeatureExtractionPluginFactory();
+	}
+	return _nativeInstance;
+    }
+
+    else return 0;
+}
+
+FeatureExtractionPluginFactory *
+FeatureExtractionPluginFactory::instanceFor(QString identifier)
+{
+    QString type, soName, label;
+    PluginIdentifier::parseIdentifier(identifier, type, soName, label);
+    return instance(type);
+}
+
+std::vector<QString>
+FeatureExtractionPluginFactory::getAllPluginIdentifiers()
+{
+    FeatureExtractionPluginFactory *factory;
+    std::vector<QString> rv;
+    
+    factory = instance("sv");
+    if (factory) {
+	std::vector<QString> tmp = factory->getPluginIdentifiers();
+	for (size_t i = 0; i < tmp.size(); ++i) {
+	    rv.push_back(tmp[i]);
+	}
+    }
+
+    // Plugins can change the locale, revert it to default.
+    setlocale(LC_ALL, "C");
+    return rv;
+}
+
+std::vector<QString>
+FeatureExtractionPluginFactory::getPluginIdentifiers()
+{
+    std::vector<QString> rv;
+    rv.push_back("sv:_builtin:beats"); //!!!
+    rv.push_back("sv:_builtin:zerocrossing"); //!!!
+    return rv;
+}
+
+FeatureExtractionPlugin *
+FeatureExtractionPluginFactory::instantiatePlugin(QString identifier,
+						  float inputSampleRate)
+{
+    QString type, soName, label;
+    PluginIdentifier::parseIdentifier(identifier, type, soName, label);
+    if (type != "sv") {
+	std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type.toStdString() << std::endl;
+	return 0;
+    }
+
+    //!!!
+    if (soName != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
+	std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Non-built-in plugins not yet supported (paradoxically enough)" << std::endl;
+	return 0;
+    }
+
+    if (label == "beats") {
+	return new BeatDetector(inputSampleRate); //!!!
+    }
+
+    if (label == "zerocrossing") {
+	return new ZeroCrossing(inputSampleRate); //!!!
+    }
+
+    std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Unknown plugin \"" << identifier.toStdString() << "\"" << std::endl;
+    
+    return 0;
+}
+