Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
55:6befca60ab4e | 56:2157fa46c1e7 |
---|---|
15 | 15 |
16 #include "PluginInstance.h" | 16 #include "PluginInstance.h" |
17 | 17 |
18 #include <QRegExp> | 18 #include <QRegExp> |
19 #include <QXmlAttributes> | 19 #include <QXmlAttributes> |
20 | |
21 #include <QDomDocument> | |
22 #include <QDomElement> | |
23 #include <QDomNamedNodeMap> | |
24 #include <QDomAttr> | |
20 | 25 |
21 #include <iostream> | 26 #include <iostream> |
22 | 27 |
23 QString | 28 QString |
24 PluginInstance::toXmlString(QString indent, QString extraAttributes) const | 29 PluginInstance::toXmlString(QString indent, QString extraAttributes) const |
81 | 86 |
82 ParameterList parameters = getParameterDescriptors(); | 87 ParameterList parameters = getParameterDescriptors(); |
83 | 88 |
84 for (ParameterList::const_iterator i = parameters.begin(); | 89 for (ParameterList::const_iterator i = parameters.begin(); |
85 i != parameters.end(); ++i) { | 90 i != parameters.end(); ++i) { |
86 QString name = stripInvalidParameterNameCharacters | 91 QString name = QString("param-%1") |
87 (QString(i->name.c_str())); | 92 .arg(stripInvalidParameterNameCharacters |
93 (QString(i->name.c_str()))); | |
88 bool ok; | 94 bool ok; |
89 float value = attrs.value(name).trimmed().toFloat(&ok); | 95 float value = attrs.value(name).trimmed().toFloat(&ok); |
90 if (ok) { | 96 if (ok) { |
91 setParameter(i->name, value); | 97 setParameter(i->name, value); |
92 } else { | 98 } else { |
93 std::cerr << "WARNING: PluginInstance::setParameters: Invalid value \"" << attrs.value(name).toStdString() << "\" for parameter \"" << i->name << "\"" << std::endl; | 99 std::cerr << "WARNING: PluginInstance::setParameters: Invalid value \"" << attrs.value(name).toStdString() << "\" for parameter \"" << i->name << "\" (attribute \"" << name.toStdString() << "\")" << std::endl; |
94 } | 100 } |
95 } | 101 } |
102 } | |
103 | |
104 void | |
105 PluginInstance::setParametersFromXml(QString xml) | |
106 { | |
107 QDomDocument doc; | |
108 | |
109 QString error; | |
110 int errorLine; | |
111 int errorColumn; | |
112 | |
113 if (!doc.setContent(xml, false, &error, &errorLine, &errorColumn)) { | |
114 std::cerr << "PluginInstance::setParametersFromXml: Error in parsing XML: " << error.toStdString() << " at line " << errorLine << ", column " << errorColumn << std::endl; | |
115 std::cerr << "Input follows:" << std::endl; | |
116 std::cerr << xml.toStdString() << std::endl; | |
117 std::cerr << "Input ends." << std::endl; | |
118 return; | |
119 } | |
120 | |
121 QDomElement pluginElt = doc.firstChildElement("plugin"); | |
122 | |
123 if (pluginElt.isNull()) { | |
124 std::cerr << "pluginElt is null" << std::endl; | |
125 pluginElt = doc.documentElement(); | |
126 if (pluginElt.isNull()) { | |
127 std::cerr << "pluginElt is still null" << std::endl; | |
128 } | |
129 } | |
130 | |
131 QDomNamedNodeMap attrNodes = pluginElt.attributes(); | |
132 QXmlAttributes attrs; | |
133 | |
134 for (int i = 0; i < attrNodes.length(); ++i) { | |
135 QDomAttr attr = attrNodes.item(i).toAttr(); | |
136 if (attr.isNull()) continue; | |
137 std::cerr << "Adding attribute \"" << attr.name().toStdString() | |
138 << "\" with value \"" << attr.value().toStdString() << "\"" << std::endl; | |
139 attrs.append(attr.name(), "", "", attr.value()); | |
140 } | |
141 | |
142 setParameters(attrs); | |
96 } | 143 } |
97 | 144 |
98 QString | 145 QString |
99 PluginInstance::stripInvalidParameterNameCharacters(QString s) const | 146 PluginInstance::stripInvalidParameterNameCharacters(QString s) const |
100 { | 147 { |