comparison 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
comparison
equal deleted inserted replaced
55:6befca60ab4e 56:2157fa46c1e7
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "TransformFactory.h" 16 #include "TransformFactory.h"
17 17
18 #include "BeatDetectTransform.h"
19 #include "BeatDetectionFunctionTransform.h"
20 #include "FeatureExtractionPluginTransform.h" 18 #include "FeatureExtractionPluginTransform.h"
21 19
22 #include "plugin/FeatureExtractionPluginFactory.h" 20 #include "plugin/FeatureExtractionPluginFactory.h"
21
22 #include "widgets/PluginParameterDialog.h"
23 23
24 #include <iostream> 24 #include <iostream>
25 25
26 TransformFactory * 26 TransformFactory *
27 TransformFactory::m_instance = new TransformFactory; 27 TransformFactory::m_instance = new TransformFactory;
40 TransformFactory::getAllTransforms() 40 TransformFactory::getAllTransforms()
41 { 41 {
42 if (m_transforms.empty()) populateTransforms(); 42 if (m_transforms.empty()) populateTransforms();
43 43
44 TransformList list; 44 TransformList list;
45 for (TransformMap::const_iterator i = m_transforms.begin(); 45 for (TransformDescriptionMap::const_iterator i = m_transforms.begin();
46 i != m_transforms.end(); ++i) { 46 i != m_transforms.end(); ++i) {
47 list.push_back(TransformDesc(i->first, i->second)); 47 list.push_back(i->second);
48 } 48 }
49 49
50 return list; 50 return list;
51 } 51 }
52 52
95 userDescription = QString("%1: %2") 95 userDescription = QString("%1: %2")
96 .arg(pluginDescription) 96 .arg(pluginDescription)
97 .arg(outputs[j].description.c_str()); 97 .arg(outputs[j].description.c_str());
98 } 98 }
99 99
100 m_transforms[transformName] = userDescription; 100 bool configurable = (!plugin->getPrograms().empty() ||
101 !plugin->getParameterDescriptors().empty());
102
103 m_transforms[transformName] =
104 TransformDesc(transformName,
105 userDescription,
106 configurable);
101 107
102 makers[transformName] = plugin->getMaker().c_str(); 108 makers[transformName] = plugin->getMaker().c_str();
103 } 109 }
104 } 110 }
105 111
106 // disambiguate plugins with similar descriptions 112 // disambiguate plugins with similar descriptions
107 113
108 std::map<QString, int> descriptions; 114 std::map<QString, int> descriptions;
109 115
110 for (TransformMap::iterator i = m_transforms.begin(); i != m_transforms.end(); 116 for (TransformDescriptionMap::iterator i = m_transforms.begin();
111 ++i) { 117 i != m_transforms.end(); ++i) {
112 118
113 QString name = i->first, description = i->second; 119 TransformDesc desc = i->second;
114 120
115 ++descriptions[description]; 121 ++descriptions[desc.description];
116 ++descriptions[QString("%1 [%2]").arg(description).arg(makers[name])]; 122 ++descriptions[QString("%1 [%2]").arg(desc.description).arg(makers[desc.name])];
117 } 123 }
118 124
119 std::map<QString, int> counts; 125 std::map<QString, int> counts;
120 TransformMap newMap; 126 TransformDescriptionMap newMap;
121 127
122 for (TransformMap::iterator i = m_transforms.begin(); i != m_transforms.end(); 128 for (TransformDescriptionMap::iterator i = m_transforms.begin();
123 ++i) { 129 i != m_transforms.end(); ++i) {
124 130
125 QString name = i->first, description = i->second; 131 TransformDesc desc = i->second;
132 QString name = desc.name, description = desc.description;
126 133
127 if (descriptions[description] > 1) { 134 if (descriptions[description] > 1) {
128 description = QString("%1 [%2]").arg(description).arg(makers[name]); 135 description = QString("%1 [%2]").arg(description).arg(makers[name]);
129 if (descriptions[description] > 1) { 136 if (descriptions[description] > 1) {
130 description = QString("%1 <%2>") 137 description = QString("%1 <%2>")
131 .arg(description).arg(++counts[description]); 138 .arg(description).arg(++counts[description]);
132 } 139 }
133 } 140 }
134 141
135 newMap[name] = description; 142 desc.description = description;
143 newMap[name] = desc;
136 } 144 }
137 145
138 m_transforms = newMap; 146 m_transforms = newMap;
139 } 147 }
140 148
141 QString 149 QString
142 TransformFactory::getTransformDescription(TransformName name) 150 TransformFactory::getTransformDescription(TransformName name)
143 { 151 {
144 if (m_transforms.find(name) != m_transforms.end()) { 152 if (m_transforms.find(name) != m_transforms.end()) {
145 return m_transforms[name]; 153 return m_transforms[name].description;
146 } else return ""; 154 } else return "";
147 } 155 }
148 156
149 QString 157 QString
150 TransformFactory::getTransformFriendlyName(TransformName name) 158 TransformFactory::getTransformFriendlyName(TransformName name)
157 } else { 165 } else {
158 return description; 166 return description;
159 } 167 }
160 } 168 }
161 169
162 Transform * 170 bool
163 TransformFactory::createTransform(TransformName name, Model *inputModel) 171 TransformFactory::getConfigurationForTransform(TransformName name,
164 { 172 Model *inputModel,
165 return createTransform(name, inputModel, true); 173 QString &configurationXml)
174 {
175 QString id = name.section(':', 0, 2);
176 QString output = name.section(':', 3);
177
178 bool ok = false;
179 configurationXml = m_lastConfigurations[name];
180
181 std::cerr << "last configuration: " << configurationXml.toStdString() << std::endl;
182
183 if (FeatureExtractionPluginFactory::instanceFor(id)) {
184 FeatureExtractionPlugin *plugin =
185 FeatureExtractionPluginFactory::instanceFor(id)->instantiatePlugin
186 (id, inputModel->getSampleRate());
187 if (plugin) {
188 if (configurationXml != "") {
189 plugin->setParametersFromXml(configurationXml);
190 }
191 PluginParameterDialog *dialog = new PluginParameterDialog(plugin);
192 if (dialog->exec() == QDialog::Accepted) {
193 ok = true;
194 }
195 configurationXml = plugin->toXmlString();
196 delete plugin;
197 }
198 }
199
200 if (ok) m_lastConfigurations[name] = configurationXml;
201
202 return ok;
166 } 203 }
167 204
168 Transform * 205 Transform *
169 TransformFactory::createTransform(TransformName name, Model *inputModel, 206 TransformFactory::createTransform(TransformName name, Model *inputModel,
170 bool start) 207 QString configurationXml, bool start)
171 { 208 {
172 Transform *transform = 0; 209 Transform *transform = 0;
173 210
174 if (name == BeatDetectTransform::getName()) { 211 // The only transform type we support at the moment is the
175 transform = new BeatDetectTransform(inputModel); 212 // FeatureExtractionPluginTransform. In future we may wish to
176 } else if (name == BeatDetectionFunctionTransform::getName()) { 213 // support e.g. RealTimePluginTransform for audio->audio or
177 transform = new BeatDetectionFunctionTransform(inputModel); 214 // audio->midi transforms using standard effects plugins.
215
216 QString id = name.section(':', 0, 2);
217 QString output = name.section(':', 3);
218
219 if (FeatureExtractionPluginFactory::instanceFor(id)) {
220 transform = new FeatureExtractionPluginTransform(inputModel,
221 id,
222 configurationXml,
223 output);
178 } else { 224 } else {
179 QString id = name.section(':', 0, 2); 225 std::cerr << "TransformFactory::createTransform: Unknown transform "
180 QString output = name.section(':', 3); 226 << name.toStdString() << std::endl;
181 if (FeatureExtractionPluginFactory::instanceFor(id)) {
182 transform = new FeatureExtractionPluginTransform(inputModel,
183 id, output);
184 } else {
185 std::cerr << "TransformFactory::createTransform: Unknown transform "
186 << name.toStdString() << std::endl;
187 }
188 } 227 }
189 228
190 if (start && transform) transform->start(); 229 if (start && transform) transform->start();
191 transform->setObjectName(name); 230 transform->setObjectName(name);
192 return transform; 231 return transform;
193 } 232 }
194 233
195 Model * 234 Model *
196 TransformFactory::transform(TransformName name, Model *inputModel) 235 TransformFactory::transform(TransformName name, Model *inputModel,
197 { 236 QString configurationXml)
198 Transform *t = createTransform(name, inputModel, false); 237 {
238 Transform *t = createTransform(name, inputModel, configurationXml, false);
199 239
200 if (!t) return 0; 240 if (!t) return 0;
201 241
202 connect(t, SIGNAL(finished()), this, SLOT(transformFinished())); 242 connect(t, SIGNAL(finished()), this, SLOT(transformFinished()));
203 243