diff plugin/PluginInstance.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 6befca60ab4e
children 7439f1696314
line wrap: on
line diff
--- a/plugin/PluginInstance.cpp	Wed Mar 22 13:23:50 2006 +0000
+++ b/plugin/PluginInstance.cpp	Wed Mar 22 17:38:29 2006 +0000
@@ -18,6 +18,11 @@
 #include <QRegExp>
 #include <QXmlAttributes>
 
+#include <QDomDocument>
+#include <QDomElement>
+#include <QDomNamedNodeMap>
+#include <QDomAttr>
+
 #include <iostream>
 
 QString
@@ -83,17 +88,59 @@
 
     for (ParameterList::const_iterator i = parameters.begin();
          i != parameters.end(); ++i) {
-        QString name = stripInvalidParameterNameCharacters
-            (QString(i->name.c_str()));
+        QString name = QString("param-%1")
+            .arg(stripInvalidParameterNameCharacters
+                 (QString(i->name.c_str())));
         bool ok;
         float value = attrs.value(name).trimmed().toFloat(&ok);
         if (ok) {
             setParameter(i->name, value);
         } else {
-            std::cerr << "WARNING: PluginInstance::setParameters: Invalid value \"" << attrs.value(name).toStdString() << "\" for parameter \"" << i->name << "\"" << std::endl;
+            std::cerr << "WARNING: PluginInstance::setParameters: Invalid value \"" << attrs.value(name).toStdString() << "\" for parameter \"" << i->name << "\" (attribute \"" << name.toStdString() << "\")" << std::endl;
         }
     }
 }
+
+void
+PluginInstance::setParametersFromXml(QString xml)
+{
+    QDomDocument doc;
+
+    QString error;
+    int errorLine;
+    int errorColumn;
+
+    if (!doc.setContent(xml, false, &error, &errorLine, &errorColumn)) {
+        std::cerr << "PluginInstance::setParametersFromXml: Error in parsing XML: " << error.toStdString() << " at line " << errorLine << ", column " << errorColumn << std::endl;
+        std::cerr << "Input follows:" << std::endl;
+        std::cerr << xml.toStdString() << std::endl;
+        std::cerr << "Input ends." << std::endl;
+        return;
+    }
+
+    QDomElement pluginElt = doc.firstChildElement("plugin");
+
+    if (pluginElt.isNull()) {
+        std::cerr << "pluginElt is null" << std::endl;
+        pluginElt = doc.documentElement();
+        if (pluginElt.isNull()) {
+            std::cerr << "pluginElt is still null" << std::endl;
+        }
+    }
+
+    QDomNamedNodeMap attrNodes = pluginElt.attributes();
+    QXmlAttributes attrs;
+
+    for (int i = 0; i < attrNodes.length(); ++i) {
+        QDomAttr attr = attrNodes.item(i).toAttr();
+        if (attr.isNull()) continue;
+        std::cerr << "Adding attribute \"" << attr.name().toStdString()
+                  << "\" with value \"" << attr.value().toStdString() << "\"" << std::endl;
+        attrs.append(attr.name(), "", "", attr.value());
+    }
+
+    setParameters(attrs);
+}
     
 QString
 PluginInstance::stripInvalidParameterNameCharacters(QString s) const