diff transform/TransformFactory.cpp @ 56:2157fa46c1e7

* Add plugin parameter dialog, and use it to set up parameters for feature extraction plugins via a semi-opaque (translucent?) configurationXml string which is associated with a given transform instance. This is not yet saved to and restored from the SV file properly. * Remove no-longer-relevant BeatDetect and BeatDetectionFunction transforms (replaced a long time ago with the beat detector plugin).
author Chris Cannam
date Wed, 22 Mar 2006 17:38:29 +0000
parents d397ea0a79f5
children 7439f1696314
line wrap: on
line diff
--- a/transform/TransformFactory.cpp	Wed Mar 22 13:23:50 2006 +0000
+++ b/transform/TransformFactory.cpp	Wed Mar 22 17:38:29 2006 +0000
@@ -15,12 +15,12 @@
 
 #include "TransformFactory.h"
 
-#include "BeatDetectTransform.h"
-#include "BeatDetectionFunctionTransform.h"
 #include "FeatureExtractionPluginTransform.h"
 
 #include "plugin/FeatureExtractionPluginFactory.h"
 
+#include "widgets/PluginParameterDialog.h"
+
 #include <iostream>
 
 TransformFactory *
@@ -42,9 +42,9 @@
     if (m_transforms.empty()) populateTransforms();
 
     TransformList list;
-    for (TransformMap::const_iterator i = m_transforms.begin();
+    for (TransformDescriptionMap::const_iterator i = m_transforms.begin();
 	 i != m_transforms.end(); ++i) {
-	list.push_back(TransformDesc(i->first, i->second));
+	list.push_back(i->second);
     }
 
     return list;
@@ -97,7 +97,13 @@
 		    .arg(outputs[j].description.c_str());
 	    }
 
-	    m_transforms[transformName] = userDescription;
+            bool configurable = (!plugin->getPrograms().empty() ||
+                                 !plugin->getParameterDescriptors().empty());
+
+	    m_transforms[transformName] = 
+                TransformDesc(transformName,
+                              userDescription,
+                              configurable);
 	    
 	    makers[transformName] = plugin->getMaker().c_str();
 	}
@@ -107,22 +113,23 @@
 
     std::map<QString, int> descriptions;
 
-    for (TransformMap::iterator i = m_transforms.begin(); i != m_transforms.end();
-	 ++i) {
+    for (TransformDescriptionMap::iterator i = m_transforms.begin();
+         i != m_transforms.end(); ++i) {
 
-	QString name = i->first, description = i->second;
+        TransformDesc desc = i->second;
 
-	++descriptions[description];
-	++descriptions[QString("%1 [%2]").arg(description).arg(makers[name])];
+	++descriptions[desc.description];
+	++descriptions[QString("%1 [%2]").arg(desc.description).arg(makers[desc.name])];
     }
 
     std::map<QString, int> counts;
-    TransformMap newMap;
+    TransformDescriptionMap newMap;
 
-    for (TransformMap::iterator i = m_transforms.begin(); i != m_transforms.end();
-	 ++i) {
+    for (TransformDescriptionMap::iterator i = m_transforms.begin();
+         i != m_transforms.end(); ++i) {
 
-	QString name = i->first, description = i->second;
+        TransformDesc desc = i->second;
+	QString name = desc.name, description = desc.description;
 
 	if (descriptions[description] > 1) {
 	    description = QString("%1 [%2]").arg(description).arg(makers[name]);
@@ -132,7 +139,8 @@
 	    }
 	}
 
-	newMap[name] = description;
+        desc.description = description;
+	newMap[name] = desc;
     }	    
 	    
     m_transforms = newMap;
@@ -142,7 +150,7 @@
 TransformFactory::getTransformDescription(TransformName name)
 {
     if (m_transforms.find(name) != m_transforms.end()) {
-	return m_transforms[name];
+	return m_transforms[name].description;
     } else return "";
 }
 
@@ -159,32 +167,63 @@
     }
 }
 
-Transform *
-TransformFactory::createTransform(TransformName name, Model *inputModel)
+bool
+TransformFactory::getConfigurationForTransform(TransformName name,
+                                               Model *inputModel,
+                                               QString &configurationXml)
 {
-    return createTransform(name, inputModel, true);
+    QString id = name.section(':', 0, 2);
+    QString output = name.section(':', 3);
+    
+    bool ok = false;
+    configurationXml = m_lastConfigurations[name];
+
+    std::cerr << "last configuration: " << configurationXml.toStdString() << std::endl;
+
+    if (FeatureExtractionPluginFactory::instanceFor(id)) {
+        FeatureExtractionPlugin *plugin =
+            FeatureExtractionPluginFactory::instanceFor(id)->instantiatePlugin
+            (id, inputModel->getSampleRate());
+        if (plugin) {
+            if (configurationXml != "") {
+                plugin->setParametersFromXml(configurationXml);
+            }
+            PluginParameterDialog *dialog = new PluginParameterDialog(plugin);
+            if (dialog->exec() == QDialog::Accepted) {
+                ok = true;
+            }
+            configurationXml = plugin->toXmlString();
+            delete plugin;
+        }
+    }
+
+    if (ok) m_lastConfigurations[name] = configurationXml;
+
+    return ok;
 }
 
 Transform *
 TransformFactory::createTransform(TransformName name, Model *inputModel,
-				  bool start)
+				  QString configurationXml, bool start)
 {
     Transform *transform = 0;
 
-    if (name == BeatDetectTransform::getName()) {
-	transform = new BeatDetectTransform(inputModel);
-    } else if (name == BeatDetectionFunctionTransform::getName()) {
-	transform = new BeatDetectionFunctionTransform(inputModel);
+    // The only transform type we support at the moment is the
+    // FeatureExtractionPluginTransform.  In future we may wish to
+    // support e.g. RealTimePluginTransform for audio->audio or
+    // audio->midi transforms using standard effects plugins.
+
+    QString id = name.section(':', 0, 2);
+    QString output = name.section(':', 3);
+
+    if (FeatureExtractionPluginFactory::instanceFor(id)) {
+        transform = new FeatureExtractionPluginTransform(inputModel,
+                                                         id,
+                                                         configurationXml,
+                                                         output);
     } else {
-	QString id = name.section(':', 0, 2);
-	QString output = name.section(':', 3);
-	if (FeatureExtractionPluginFactory::instanceFor(id)) {
-	    transform = new FeatureExtractionPluginTransform(inputModel,
-							     id, output);
-	} else {
-	    std::cerr << "TransformFactory::createTransform: Unknown transform "
-		      << name.toStdString() << std::endl;
-	}
+        std::cerr << "TransformFactory::createTransform: Unknown transform "
+                  << name.toStdString() << std::endl;
     }
 
     if (start && transform) transform->start();
@@ -193,9 +232,10 @@
 }
 
 Model *
-TransformFactory::transform(TransformName name, Model *inputModel)
+TransformFactory::transform(TransformName name, Model *inputModel,
+                            QString configurationXml)
 {
-    Transform *t = createTransform(name, inputModel, false);
+    Transform *t = createTransform(name, inputModel, configurationXml, false);
 
     if (!t) return 0;