Chris@330
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@330
|
2
|
Chris@330
|
3 /*
|
Chris@330
|
4 Sonic Visualiser
|
Chris@330
|
5 An audio file viewer and annotation editor.
|
Chris@330
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@330
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@330
|
8
|
Chris@330
|
9 This program is free software; you can redistribute it and/or
|
Chris@330
|
10 modify it under the terms of the GNU General Public License as
|
Chris@330
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@330
|
12 License, or (at your option) any later version. See the file
|
Chris@330
|
13 COPYING included with this distribution for more information.
|
Chris@330
|
14 */
|
Chris@330
|
15
|
Chris@330
|
16 #include "TransformFactory.h"
|
Chris@330
|
17
|
Chris@330
|
18 #include "plugin/FeatureExtractionPluginFactory.h"
|
Chris@330
|
19 #include "plugin/RealTimePluginFactory.h"
|
Chris@332
|
20 #include "plugin/RealTimePluginInstance.h"
|
Chris@330
|
21 #include "plugin/PluginXml.h"
|
Chris@330
|
22
|
Chris@332
|
23 #include "vamp-sdk/Plugin.h"
|
Chris@330
|
24 #include "vamp-sdk/PluginHostAdapter.h"
|
Chris@332
|
25 #include "vamp-sdk/hostext/PluginWrapper.h"
|
Chris@330
|
26
|
Chris@457
|
27 #include "rdf/PluginRDFIndexer.h"
|
Chris@457
|
28 #include "rdf/PluginRDFDescription.h"
|
Chris@457
|
29
|
Chris@446
|
30 #include "base/XmlExportable.h"
|
Chris@446
|
31
|
Chris@330
|
32 #include <iostream>
|
Chris@330
|
33 #include <set>
|
Chris@330
|
34
|
Chris@330
|
35 #include <QRegExp>
|
Chris@350
|
36 #include <QTextStream>
|
Chris@330
|
37
|
Chris@460
|
38 #include "base/Thread.h"
|
Chris@460
|
39
|
Chris@443
|
40 using std::cerr;
|
Chris@443
|
41 using std::endl;
|
Chris@443
|
42
|
Chris@330
|
43 TransformFactory *
|
Chris@330
|
44 TransformFactory::m_instance = new TransformFactory;
|
Chris@330
|
45
|
Chris@330
|
46 TransformFactory *
|
Chris@330
|
47 TransformFactory::getInstance()
|
Chris@330
|
48 {
|
Chris@330
|
49 return m_instance;
|
Chris@330
|
50 }
|
Chris@330
|
51
|
Chris@457
|
52 TransformFactory::TransformFactory() :
|
Chris@457
|
53 m_transformsPopulated(false),
|
Chris@457
|
54 m_uninstalledTransformsPopulated(false)
|
Chris@457
|
55 {
|
Chris@460
|
56 UninstalledTransformsPopulateThread *thread =
|
Chris@460
|
57 new UninstalledTransformsPopulateThread(this);
|
Chris@460
|
58 thread->start();
|
Chris@457
|
59 }
|
Chris@457
|
60
|
Chris@330
|
61 TransformFactory::~TransformFactory()
|
Chris@330
|
62 {
|
Chris@330
|
63 }
|
Chris@330
|
64
|
Chris@330
|
65 TransformList
|
Chris@350
|
66 TransformFactory::getAllTransformDescriptions()
|
Chris@330
|
67 {
|
Chris@460
|
68 populateTransforms();
|
Chris@330
|
69
|
Chris@330
|
70 std::set<TransformDescription> dset;
|
Chris@330
|
71 for (TransformDescriptionMap::const_iterator i = m_transforms.begin();
|
Chris@330
|
72 i != m_transforms.end(); ++i) {
|
Chris@443
|
73 // cerr << "inserting transform into set: id = " << i->second.identifier.toStdString() << endl;
|
Chris@330
|
74 dset.insert(i->second);
|
Chris@330
|
75 }
|
Chris@330
|
76
|
Chris@330
|
77 TransformList list;
|
Chris@330
|
78 for (std::set<TransformDescription>::const_iterator i = dset.begin();
|
Chris@330
|
79 i != dset.end(); ++i) {
|
Chris@443
|
80 // cerr << "inserting transform into list: id = " << i->identifier.toStdString() << endl;
|
Chris@330
|
81 list.push_back(*i);
|
Chris@330
|
82 }
|
Chris@330
|
83
|
Chris@330
|
84 return list;
|
Chris@330
|
85 }
|
Chris@330
|
86
|
Chris@350
|
87 TransformDescription
|
Chris@350
|
88 TransformFactory::getTransformDescription(TransformId id)
|
Chris@350
|
89 {
|
Chris@460
|
90 populateTransforms();
|
Chris@350
|
91
|
Chris@350
|
92 if (m_transforms.find(id) == m_transforms.end()) {
|
Chris@350
|
93 return TransformDescription();
|
Chris@350
|
94 }
|
Chris@350
|
95
|
Chris@350
|
96 return m_transforms[id];
|
Chris@350
|
97 }
|
Chris@350
|
98
|
Chris@457
|
99 TransformList
|
Chris@457
|
100 TransformFactory::getUninstalledTransformDescriptions()
|
Chris@457
|
101 {
|
Chris@460
|
102 populateUninstalledTransforms();
|
Chris@457
|
103
|
Chris@457
|
104 std::set<TransformDescription> dset;
|
Chris@457
|
105 for (TransformDescriptionMap::const_iterator i = m_uninstalledTransforms.begin();
|
Chris@457
|
106 i != m_uninstalledTransforms.end(); ++i) {
|
Chris@457
|
107 // cerr << "inserting transform into set: id = " << i->second.identifier.toStdString() << endl;
|
Chris@457
|
108 dset.insert(i->second);
|
Chris@457
|
109 }
|
Chris@457
|
110
|
Chris@457
|
111 TransformList list;
|
Chris@457
|
112 for (std::set<TransformDescription>::const_iterator i = dset.begin();
|
Chris@457
|
113 i != dset.end(); ++i) {
|
Chris@460
|
114 // cerr << "inserting transform into uninstalled list: id = " << i->identifier.toStdString() << endl;
|
Chris@457
|
115 list.push_back(*i);
|
Chris@457
|
116 }
|
Chris@457
|
117
|
Chris@457
|
118 return list;
|
Chris@457
|
119 }
|
Chris@457
|
120
|
Chris@457
|
121 TransformDescription
|
Chris@457
|
122 TransformFactory::getUninstalledTransformDescription(TransformId id)
|
Chris@457
|
123 {
|
Chris@460
|
124 populateUninstalledTransforms();
|
Chris@457
|
125
|
Chris@457
|
126 if (m_uninstalledTransforms.find(id) == m_uninstalledTransforms.end()) {
|
Chris@457
|
127 return TransformDescription();
|
Chris@457
|
128 }
|
Chris@457
|
129
|
Chris@457
|
130 return m_uninstalledTransforms[id];
|
Chris@457
|
131 }
|
Chris@457
|
132
|
Chris@457
|
133 TransformFactory::TransformInstallStatus
|
Chris@457
|
134 TransformFactory::getTransformInstallStatus(TransformId id)
|
Chris@457
|
135 {
|
Chris@460
|
136 populateTransforms();
|
Chris@460
|
137 populateUninstalledTransforms();
|
Chris@457
|
138
|
Chris@457
|
139 if (m_transforms.find(id) != m_transforms.end()) {
|
Chris@457
|
140 return TransformInstalled;
|
Chris@457
|
141 }
|
Chris@457
|
142 if (m_uninstalledTransforms.find(id) != m_uninstalledTransforms.end()) {
|
Chris@457
|
143 return TransformNotInstalled;
|
Chris@457
|
144 }
|
Chris@457
|
145 return TransformUnknown;
|
Chris@457
|
146 }
|
Chris@457
|
147
|
Chris@457
|
148
|
Chris@330
|
149 std::vector<QString>
|
Chris@330
|
150 TransformFactory::getAllTransformTypes()
|
Chris@330
|
151 {
|
Chris@460
|
152 populateTransforms();
|
Chris@330
|
153
|
Chris@330
|
154 std::set<QString> types;
|
Chris@330
|
155 for (TransformDescriptionMap::const_iterator i = m_transforms.begin();
|
Chris@330
|
156 i != m_transforms.end(); ++i) {
|
Chris@330
|
157 types.insert(i->second.type);
|
Chris@330
|
158 }
|
Chris@330
|
159
|
Chris@330
|
160 std::vector<QString> rv;
|
Chris@330
|
161 for (std::set<QString>::iterator i = types.begin(); i != types.end(); ++i) {
|
Chris@330
|
162 rv.push_back(*i);
|
Chris@330
|
163 }
|
Chris@330
|
164
|
Chris@330
|
165 return rv;
|
Chris@330
|
166 }
|
Chris@330
|
167
|
Chris@330
|
168 std::vector<QString>
|
Chris@330
|
169 TransformFactory::getTransformCategories(QString transformType)
|
Chris@330
|
170 {
|
Chris@460
|
171 populateTransforms();
|
Chris@330
|
172
|
Chris@330
|
173 std::set<QString> categories;
|
Chris@330
|
174 for (TransformDescriptionMap::const_iterator i = m_transforms.begin();
|
Chris@330
|
175 i != m_transforms.end(); ++i) {
|
Chris@330
|
176 if (i->second.type == transformType) {
|
Chris@330
|
177 categories.insert(i->second.category);
|
Chris@330
|
178 }
|
Chris@330
|
179 }
|
Chris@330
|
180
|
Chris@330
|
181 bool haveEmpty = false;
|
Chris@330
|
182
|
Chris@330
|
183 std::vector<QString> rv;
|
Chris@330
|
184 for (std::set<QString>::iterator i = categories.begin();
|
Chris@330
|
185 i != categories.end(); ++i) {
|
Chris@330
|
186 if (*i != "") rv.push_back(*i);
|
Chris@330
|
187 else haveEmpty = true;
|
Chris@330
|
188 }
|
Chris@330
|
189
|
Chris@330
|
190 if (haveEmpty) rv.push_back(""); // make sure empty category sorts last
|
Chris@330
|
191
|
Chris@330
|
192 return rv;
|
Chris@330
|
193 }
|
Chris@330
|
194
|
Chris@330
|
195 std::vector<QString>
|
Chris@330
|
196 TransformFactory::getTransformMakers(QString transformType)
|
Chris@330
|
197 {
|
Chris@460
|
198 populateTransforms();
|
Chris@330
|
199
|
Chris@330
|
200 std::set<QString> makers;
|
Chris@330
|
201 for (TransformDescriptionMap::const_iterator i = m_transforms.begin();
|
Chris@330
|
202 i != m_transforms.end(); ++i) {
|
Chris@330
|
203 if (i->second.type == transformType) {
|
Chris@330
|
204 makers.insert(i->second.maker);
|
Chris@330
|
205 }
|
Chris@330
|
206 }
|
Chris@330
|
207
|
Chris@330
|
208 bool haveEmpty = false;
|
Chris@330
|
209
|
Chris@330
|
210 std::vector<QString> rv;
|
Chris@330
|
211 for (std::set<QString>::iterator i = makers.begin();
|
Chris@330
|
212 i != makers.end(); ++i) {
|
Chris@330
|
213 if (*i != "") rv.push_back(*i);
|
Chris@330
|
214 else haveEmpty = true;
|
Chris@330
|
215 }
|
Chris@330
|
216
|
Chris@330
|
217 if (haveEmpty) rv.push_back(""); // make sure empty category sorts last
|
Chris@330
|
218
|
Chris@330
|
219 return rv;
|
Chris@330
|
220 }
|
Chris@330
|
221
|
Chris@330
|
222 void
|
Chris@330
|
223 TransformFactory::populateTransforms()
|
Chris@330
|
224 {
|
Chris@460
|
225 MutexLocker locker(&m_transformsMutex,
|
Chris@460
|
226 "TransformFactory::populateTransforms");
|
Chris@460
|
227 if (m_transformsPopulated) {
|
Chris@460
|
228 return;
|
Chris@460
|
229 }
|
Chris@460
|
230
|
Chris@330
|
231 TransformDescriptionMap transforms;
|
Chris@330
|
232
|
Chris@330
|
233 populateFeatureExtractionPlugins(transforms);
|
Chris@330
|
234 populateRealTimePlugins(transforms);
|
Chris@330
|
235
|
Chris@330
|
236 // disambiguate plugins with similar names
|
Chris@330
|
237
|
Chris@330
|
238 std::map<QString, int> names;
|
Chris@330
|
239 std::map<QString, QString> pluginSources;
|
Chris@330
|
240 std::map<QString, QString> pluginMakers;
|
Chris@330
|
241
|
Chris@330
|
242 for (TransformDescriptionMap::iterator i = transforms.begin();
|
Chris@330
|
243 i != transforms.end(); ++i) {
|
Chris@330
|
244
|
Chris@330
|
245 TransformDescription desc = i->second;
|
Chris@330
|
246
|
Chris@330
|
247 QString td = desc.name;
|
Chris@330
|
248 QString tn = td.section(": ", 0, 0);
|
Chris@330
|
249 QString pn = desc.identifier.section(":", 1, 1);
|
Chris@330
|
250
|
Chris@330
|
251 if (pluginSources.find(tn) != pluginSources.end()) {
|
Chris@330
|
252 if (pluginSources[tn] != pn && pluginMakers[tn] != desc.maker) {
|
Chris@330
|
253 ++names[tn];
|
Chris@330
|
254 }
|
Chris@330
|
255 } else {
|
Chris@330
|
256 ++names[tn];
|
Chris@330
|
257 pluginSources[tn] = pn;
|
Chris@330
|
258 pluginMakers[tn] = desc.maker;
|
Chris@330
|
259 }
|
Chris@330
|
260 }
|
Chris@330
|
261
|
Chris@330
|
262 std::map<QString, int> counts;
|
Chris@330
|
263 m_transforms.clear();
|
Chris@330
|
264
|
Chris@330
|
265 for (TransformDescriptionMap::iterator i = transforms.begin();
|
Chris@330
|
266 i != transforms.end(); ++i) {
|
Chris@330
|
267
|
Chris@330
|
268 TransformDescription desc = i->second;
|
Chris@330
|
269 QString identifier = desc.identifier;
|
Chris@330
|
270 QString maker = desc.maker;
|
Chris@330
|
271
|
Chris@330
|
272 QString td = desc.name;
|
Chris@330
|
273 QString tn = td.section(": ", 0, 0);
|
Chris@330
|
274 QString to = td.section(": ", 1);
|
Chris@330
|
275
|
Chris@330
|
276 if (names[tn] > 1) {
|
Chris@330
|
277 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
|
Chris@330
|
278 tn = QString("%1 [%2]").arg(tn).arg(maker);
|
Chris@330
|
279 }
|
Chris@330
|
280
|
Chris@330
|
281 if (to != "") {
|
Chris@330
|
282 desc.name = QString("%1: %2").arg(tn).arg(to);
|
Chris@330
|
283 } else {
|
Chris@330
|
284 desc.name = tn;
|
Chris@330
|
285 }
|
Chris@330
|
286
|
Chris@330
|
287 m_transforms[identifier] = desc;
|
Chris@330
|
288 }
|
Chris@457
|
289
|
Chris@457
|
290 m_transformsPopulated = true;
|
Chris@330
|
291 }
|
Chris@330
|
292
|
Chris@330
|
293 void
|
Chris@330
|
294 TransformFactory::populateFeatureExtractionPlugins(TransformDescriptionMap &transforms)
|
Chris@330
|
295 {
|
Chris@330
|
296 std::vector<QString> plugs =
|
Chris@330
|
297 FeatureExtractionPluginFactory::getAllPluginIdentifiers();
|
Chris@330
|
298
|
Chris@330
|
299 for (size_t i = 0; i < plugs.size(); ++i) {
|
Chris@330
|
300
|
Chris@330
|
301 QString pluginId = plugs[i];
|
Chris@330
|
302
|
Chris@330
|
303 FeatureExtractionPluginFactory *factory =
|
Chris@330
|
304 FeatureExtractionPluginFactory::instanceFor(pluginId);
|
Chris@330
|
305
|
Chris@330
|
306 if (!factory) {
|
Chris@443
|
307 cerr << "WARNING: TransformFactory::populateTransforms: No feature extraction plugin factory for instance " << pluginId.toLocal8Bit().data() << endl;
|
Chris@330
|
308 continue;
|
Chris@330
|
309 }
|
Chris@330
|
310
|
Chris@330
|
311 Vamp::Plugin *plugin =
|
Chris@350
|
312 factory->instantiatePlugin(pluginId, 44100);
|
Chris@330
|
313
|
Chris@330
|
314 if (!plugin) {
|
Chris@443
|
315 cerr << "WARNING: TransformFactory::populateTransforms: Failed to instantiate plugin " << pluginId.toLocal8Bit().data() << endl;
|
Chris@330
|
316 continue;
|
Chris@330
|
317 }
|
Chris@330
|
318
|
Chris@330
|
319 QString pluginName = plugin->getName().c_str();
|
Chris@330
|
320 QString category = factory->getPluginCategory(pluginId);
|
Chris@330
|
321
|
Chris@330
|
322 Vamp::Plugin::OutputList outputs =
|
Chris@330
|
323 plugin->getOutputDescriptors();
|
Chris@330
|
324
|
Chris@330
|
325 for (size_t j = 0; j < outputs.size(); ++j) {
|
Chris@330
|
326
|
Chris@330
|
327 QString transformId = QString("%1:%2")
|
Chris@330
|
328 .arg(pluginId).arg(outputs[j].identifier.c_str());
|
Chris@330
|
329
|
Chris@330
|
330 QString userName;
|
Chris@330
|
331 QString friendlyName;
|
Chris@330
|
332 QString units = outputs[j].unit.c_str();
|
Chris@330
|
333 QString description = plugin->getDescription().c_str();
|
Chris@330
|
334 QString maker = plugin->getMaker().c_str();
|
Chris@330
|
335 if (maker == "") maker = tr("<unknown maker>");
|
Chris@330
|
336
|
Chris@443
|
337 QString longDescription = description;
|
Chris@443
|
338
|
Chris@443
|
339 if (longDescription == "") {
|
Chris@330
|
340 if (outputs.size() == 1) {
|
Chris@443
|
341 longDescription = tr("Extract features using \"%1\" plugin (from %2)")
|
Chris@330
|
342 .arg(pluginName).arg(maker);
|
Chris@330
|
343 } else {
|
Chris@443
|
344 longDescription = tr("Extract features using \"%1\" output of \"%2\" plugin (from %3)")
|
Chris@330
|
345 .arg(outputs[j].name.c_str()).arg(pluginName).arg(maker);
|
Chris@330
|
346 }
|
Chris@330
|
347 } else {
|
Chris@330
|
348 if (outputs.size() == 1) {
|
Chris@443
|
349 longDescription = tr("%1 using \"%2\" plugin (from %3)")
|
Chris@443
|
350 .arg(longDescription).arg(pluginName).arg(maker);
|
Chris@330
|
351 } else {
|
Chris@443
|
352 longDescription = tr("%1 using \"%2\" output of \"%3\" plugin (from %4)")
|
Chris@443
|
353 .arg(longDescription).arg(outputs[j].name.c_str()).arg(pluginName).arg(maker);
|
Chris@330
|
354 }
|
Chris@330
|
355 }
|
Chris@330
|
356
|
Chris@330
|
357 if (outputs.size() == 1) {
|
Chris@330
|
358 userName = pluginName;
|
Chris@330
|
359 friendlyName = pluginName;
|
Chris@330
|
360 } else {
|
Chris@330
|
361 userName = QString("%1: %2")
|
Chris@330
|
362 .arg(pluginName)
|
Chris@330
|
363 .arg(outputs[j].name.c_str());
|
Chris@330
|
364 friendlyName = outputs[j].name.c_str();
|
Chris@330
|
365 }
|
Chris@330
|
366
|
Chris@330
|
367 bool configurable = (!plugin->getPrograms().empty() ||
|
Chris@330
|
368 !plugin->getParameterDescriptors().empty());
|
Chris@330
|
369
|
Chris@443
|
370 // cerr << "Feature extraction plugin transform: " << transformId.toStdString() << " friendly name: " << friendlyName.toStdString() << endl;
|
Chris@330
|
371
|
Chris@330
|
372 transforms[transformId] =
|
Chris@330
|
373 TransformDescription(tr("Analysis"),
|
Chris@332
|
374 category,
|
Chris@332
|
375 transformId,
|
Chris@332
|
376 userName,
|
Chris@332
|
377 friendlyName,
|
Chris@332
|
378 description,
|
Chris@443
|
379 longDescription,
|
Chris@332
|
380 maker,
|
Chris@332
|
381 units,
|
Chris@332
|
382 configurable);
|
Chris@330
|
383 }
|
Chris@330
|
384
|
Chris@330
|
385 delete plugin;
|
Chris@330
|
386 }
|
Chris@330
|
387 }
|
Chris@330
|
388
|
Chris@330
|
389 void
|
Chris@330
|
390 TransformFactory::populateRealTimePlugins(TransformDescriptionMap &transforms)
|
Chris@330
|
391 {
|
Chris@330
|
392 std::vector<QString> plugs =
|
Chris@330
|
393 RealTimePluginFactory::getAllPluginIdentifiers();
|
Chris@330
|
394
|
Chris@330
|
395 static QRegExp unitRE("[\\[\\(]([A-Za-z0-9/]+)[\\)\\]]$");
|
Chris@330
|
396
|
Chris@330
|
397 for (size_t i = 0; i < plugs.size(); ++i) {
|
Chris@330
|
398
|
Chris@330
|
399 QString pluginId = plugs[i];
|
Chris@330
|
400
|
Chris@330
|
401 RealTimePluginFactory *factory =
|
Chris@330
|
402 RealTimePluginFactory::instanceFor(pluginId);
|
Chris@330
|
403
|
Chris@330
|
404 if (!factory) {
|
Chris@443
|
405 cerr << "WARNING: TransformFactory::populateTransforms: No real time plugin factory for instance " << pluginId.toLocal8Bit().data() << endl;
|
Chris@330
|
406 continue;
|
Chris@330
|
407 }
|
Chris@330
|
408
|
Chris@330
|
409 const RealTimePluginDescriptor *descriptor =
|
Chris@330
|
410 factory->getPluginDescriptor(pluginId);
|
Chris@330
|
411
|
Chris@330
|
412 if (!descriptor) {
|
Chris@443
|
413 cerr << "WARNING: TransformFactory::populateTransforms: Failed to query plugin " << pluginId.toLocal8Bit().data() << endl;
|
Chris@330
|
414 continue;
|
Chris@330
|
415 }
|
Chris@330
|
416
|
Chris@330
|
417 //!!! if (descriptor->controlOutputPortCount == 0 ||
|
Chris@330
|
418 // descriptor->audioInputPortCount == 0) continue;
|
Chris@330
|
419
|
Chris@443
|
420 // std::cout << "TransformFactory::populateRealTimePlugins: plugin " << pluginId.toStdString() << " has " << descriptor->controlOutputPortCount << " control output ports, " << descriptor->audioOutputPortCount << " audio outputs, " << descriptor->audioInputPortCount << " audio inputs" << endl;
|
Chris@330
|
421
|
Chris@330
|
422 QString pluginName = descriptor->name.c_str();
|
Chris@330
|
423 QString category = factory->getPluginCategory(pluginId);
|
Chris@330
|
424 bool configurable = (descriptor->parameterCount > 0);
|
Chris@330
|
425 QString maker = descriptor->maker.c_str();
|
Chris@330
|
426 if (maker == "") maker = tr("<unknown maker>");
|
Chris@330
|
427
|
Chris@330
|
428 if (descriptor->audioInputPortCount > 0) {
|
Chris@330
|
429
|
Chris@330
|
430 for (size_t j = 0; j < descriptor->controlOutputPortCount; ++j) {
|
Chris@330
|
431
|
Chris@330
|
432 QString transformId = QString("%1:%2").arg(pluginId).arg(j);
|
Chris@330
|
433 QString userName;
|
Chris@330
|
434 QString units;
|
Chris@330
|
435 QString portName;
|
Chris@330
|
436
|
Chris@330
|
437 if (j < descriptor->controlOutputPortNames.size() &&
|
Chris@330
|
438 descriptor->controlOutputPortNames[j] != "") {
|
Chris@330
|
439
|
Chris@330
|
440 portName = descriptor->controlOutputPortNames[j].c_str();
|
Chris@330
|
441
|
Chris@330
|
442 userName = tr("%1: %2")
|
Chris@330
|
443 .arg(pluginName)
|
Chris@330
|
444 .arg(portName);
|
Chris@330
|
445
|
Chris@330
|
446 if (unitRE.indexIn(portName) >= 0) {
|
Chris@330
|
447 units = unitRE.cap(1);
|
Chris@330
|
448 }
|
Chris@330
|
449
|
Chris@330
|
450 } else if (descriptor->controlOutputPortCount > 1) {
|
Chris@330
|
451
|
Chris@330
|
452 userName = tr("%1: Output %2")
|
Chris@330
|
453 .arg(pluginName)
|
Chris@330
|
454 .arg(j + 1);
|
Chris@330
|
455
|
Chris@330
|
456 } else {
|
Chris@330
|
457
|
Chris@330
|
458 userName = pluginName;
|
Chris@330
|
459 }
|
Chris@330
|
460
|
Chris@330
|
461 QString description;
|
Chris@330
|
462
|
Chris@330
|
463 if (portName != "") {
|
Chris@330
|
464 description = tr("Extract \"%1\" data output from \"%2\" effect plugin (from %3)")
|
Chris@330
|
465 .arg(portName)
|
Chris@330
|
466 .arg(pluginName)
|
Chris@330
|
467 .arg(maker);
|
Chris@330
|
468 } else {
|
Chris@330
|
469 description = tr("Extract data output %1 from \"%2\" effect plugin (from %3)")
|
Chris@330
|
470 .arg(j + 1)
|
Chris@330
|
471 .arg(pluginName)
|
Chris@330
|
472 .arg(maker);
|
Chris@330
|
473 }
|
Chris@330
|
474
|
Chris@330
|
475 transforms[transformId] =
|
Chris@330
|
476 TransformDescription(tr("Effects Data"),
|
Chris@332
|
477 category,
|
Chris@332
|
478 transformId,
|
Chris@332
|
479 userName,
|
Chris@332
|
480 userName,
|
Chris@443
|
481 "",
|
Chris@332
|
482 description,
|
Chris@332
|
483 maker,
|
Chris@332
|
484 units,
|
Chris@332
|
485 configurable);
|
Chris@330
|
486 }
|
Chris@330
|
487 }
|
Chris@330
|
488
|
Chris@330
|
489 if (!descriptor->isSynth || descriptor->audioInputPortCount > 0) {
|
Chris@330
|
490
|
Chris@330
|
491 if (descriptor->audioOutputPortCount > 0) {
|
Chris@330
|
492
|
Chris@330
|
493 QString transformId = QString("%1:A").arg(pluginId);
|
Chris@330
|
494 QString type = tr("Effects");
|
Chris@330
|
495
|
Chris@330
|
496 QString description = tr("Transform audio signal with \"%1\" effect plugin (from %2)")
|
Chris@330
|
497 .arg(pluginName)
|
Chris@330
|
498 .arg(maker);
|
Chris@330
|
499
|
Chris@330
|
500 if (descriptor->audioInputPortCount == 0) {
|
Chris@330
|
501 type = tr("Generators");
|
Chris@330
|
502 QString description = tr("Generate audio signal using \"%1\" plugin (from %2)")
|
Chris@330
|
503 .arg(pluginName)
|
Chris@330
|
504 .arg(maker);
|
Chris@330
|
505 }
|
Chris@330
|
506
|
Chris@330
|
507 transforms[transformId] =
|
Chris@330
|
508 TransformDescription(type,
|
Chris@332
|
509 category,
|
Chris@332
|
510 transformId,
|
Chris@332
|
511 pluginName,
|
Chris@332
|
512 pluginName,
|
Chris@443
|
513 "",
|
Chris@332
|
514 description,
|
Chris@332
|
515 maker,
|
Chris@332
|
516 "",
|
Chris@332
|
517 configurable);
|
Chris@330
|
518 }
|
Chris@330
|
519 }
|
Chris@330
|
520 }
|
Chris@330
|
521 }
|
Chris@330
|
522
|
Chris@457
|
523 void
|
Chris@457
|
524 TransformFactory::populateUninstalledTransforms()
|
Chris@457
|
525 {
|
Chris@460
|
526 populateTransforms();
|
Chris@460
|
527
|
Chris@460
|
528 MutexLocker locker(&m_uninstalledTransformsMutex,
|
Chris@460
|
529 "TransformFactory::populateUninstalledTransforms");
|
Chris@460
|
530 if (m_uninstalledTransformsPopulated) return;
|
Chris@460
|
531
|
Chris@461
|
532 // ("http://www.vamp-plugins.org/rdf/plugins/vamp-example-plugins");
|
Chris@461
|
533
|
Chris@461
|
534 PluginRDFIndexer::getInstance()->indexConfiguredURLs();
|
Chris@457
|
535
|
Chris@457
|
536 //!!! This will be amazingly slow
|
Chris@457
|
537
|
Chris@457
|
538 QStringList ids = PluginRDFIndexer::getInstance()->getIndexedPluginIds();
|
Chris@457
|
539
|
Chris@457
|
540 for (QStringList::const_iterator i = ids.begin(); i != ids.end(); ++i) {
|
Chris@457
|
541
|
Chris@457
|
542 PluginRDFDescription desc(*i);
|
Chris@457
|
543
|
Chris@457
|
544 QString name = desc.getPluginName();
|
Chris@457
|
545 // if (name == "") {
|
Chris@457
|
546 // std::cerr << "TransformFactory::populateUninstalledTransforms: "
|
Chris@457
|
547 // << "No name available for plugin " << i->toStdString()
|
Chris@457
|
548 // << ", skipping" << std::endl;
|
Chris@457
|
549 // continue;
|
Chris@457
|
550 // }
|
Chris@457
|
551
|
Chris@457
|
552 QString description = desc.getPluginDescription();
|
Chris@457
|
553 QString maker = desc.getPluginMaker();
|
Chris@462
|
554 QString infoUrl = desc.getPluginInfoURL();
|
Chris@457
|
555
|
Chris@457
|
556 QStringList oids = desc.getOutputIds();
|
Chris@457
|
557
|
Chris@457
|
558 for (QStringList::const_iterator j = oids.begin(); j != oids.end(); ++j) {
|
Chris@457
|
559
|
Chris@457
|
560 TransformId tid = Transform::getIdentifierForPluginOutput(*i, *j);
|
Chris@457
|
561
|
Chris@457
|
562 if (m_transforms.find(tid) != m_transforms.end()) {
|
Chris@457
|
563 std::cerr << "TransformFactory::populateUninstalledTransforms: "
|
Chris@468
|
564 << tid.toStdString() << " is installed; adding info url if appropriate, skipping rest" << std::endl;
|
Chris@468
|
565 if (infoUrl != "") {
|
Chris@468
|
566 if (m_transforms[tid].infoUrl == "") {
|
Chris@468
|
567 m_transforms[tid].infoUrl = infoUrl;
|
Chris@468
|
568 }
|
Chris@468
|
569 }
|
Chris@457
|
570 continue;
|
Chris@457
|
571 }
|
Chris@457
|
572
|
Chris@457
|
573 std::cerr << "TransformFactory::populateUninstalledTransforms: "
|
Chris@457
|
574 << "adding " << tid.toStdString() << std::endl;
|
Chris@457
|
575
|
Chris@457
|
576 QString oname = desc.getOutputName(*j);
|
Chris@457
|
577 if (oname == "") oname = *j;
|
Chris@457
|
578
|
Chris@457
|
579 TransformDescription td;
|
Chris@457
|
580 td.type = tr("Analysis"); //!!! should be enum or something
|
Chris@457
|
581 td.category = "";
|
Chris@457
|
582 td.identifier = tid;
|
Chris@457
|
583
|
Chris@457
|
584 if (oids.size() == 1) {
|
Chris@457
|
585 td.name = name;
|
Chris@457
|
586 } else if (name != "") {
|
Chris@457
|
587 td.name = tr("%1: %2").arg(name).arg(oname);
|
Chris@457
|
588 }
|
Chris@457
|
589
|
Chris@462
|
590 QString longDescription = description;
|
Chris@462
|
591 //!!! basically duplicated from above
|
Chris@462
|
592 if (longDescription == "") {
|
Chris@462
|
593 if (oids.size() == 1) {
|
Chris@462
|
594 longDescription = tr("Extract features using \"%1\" plugin (from %2)")
|
Chris@462
|
595 .arg(name).arg(maker);
|
Chris@462
|
596 } else {
|
Chris@462
|
597 longDescription = tr("Extract features using \"%1\" output of \"%2\" plugin (from %3)")
|
Chris@462
|
598 .arg(oname).arg(name).arg(maker);
|
Chris@462
|
599 }
|
Chris@462
|
600 } else {
|
Chris@462
|
601 if (oids.size() == 1) {
|
Chris@462
|
602 longDescription = tr("%1 using \"%2\" plugin (from %3)")
|
Chris@462
|
603 .arg(longDescription).arg(name).arg(maker);
|
Chris@462
|
604 } else {
|
Chris@462
|
605 longDescription = tr("%1 using \"%2\" output of \"%3\" plugin (from %4)")
|
Chris@462
|
606 .arg(longDescription).arg(oname).arg(name).arg(maker);
|
Chris@462
|
607 }
|
Chris@462
|
608 }
|
Chris@462
|
609
|
Chris@457
|
610 td.friendlyName = name; //!!!???
|
Chris@457
|
611 td.description = description;
|
Chris@462
|
612 td.longDescription = longDescription;
|
Chris@457
|
613 td.maker = maker;
|
Chris@462
|
614 td.infoUrl = infoUrl;
|
Chris@457
|
615 td.units = "";
|
Chris@457
|
616 td.configurable = false;
|
Chris@457
|
617
|
Chris@457
|
618 m_uninstalledTransforms[tid] = td;
|
Chris@457
|
619 }
|
Chris@457
|
620 }
|
Chris@457
|
621
|
Chris@457
|
622 m_uninstalledTransformsPopulated = true;
|
Chris@460
|
623
|
Chris@460
|
624 std::cerr << "populateUninstalledTransforms exiting" << std::endl;
|
Chris@457
|
625 }
|
Chris@350
|
626
|
Chris@350
|
627 Transform
|
Chris@350
|
628 TransformFactory::getDefaultTransformFor(TransformId id, size_t rate)
|
Chris@350
|
629 {
|
Chris@350
|
630 Transform t;
|
Chris@350
|
631 t.setIdentifier(id);
|
Chris@350
|
632 if (rate != 0) t.setSampleRate(rate);
|
Chris@350
|
633
|
Chris@351
|
634 Vamp::PluginBase *plugin = instantiateDefaultPluginFor(id, rate);
|
Chris@350
|
635
|
Chris@350
|
636 if (plugin) {
|
Chris@366
|
637 t.setPluginVersion(QString("%1").arg(plugin->getPluginVersion()));
|
Chris@350
|
638 setParametersFromPlugin(t, plugin);
|
Chris@350
|
639 makeContextConsistentWithPlugin(t, plugin);
|
Chris@350
|
640 delete plugin;
|
Chris@350
|
641 }
|
Chris@350
|
642
|
Chris@350
|
643 return t;
|
Chris@350
|
644 }
|
Chris@350
|
645
|
Chris@350
|
646 Vamp::PluginBase *
|
Chris@351
|
647 TransformFactory::instantiatePluginFor(const Transform &transform)
|
Chris@351
|
648 {
|
Chris@351
|
649 Vamp::PluginBase *plugin = instantiateDefaultPluginFor
|
Chris@351
|
650 (transform.getIdentifier(), transform.getSampleRate());
|
Chris@351
|
651 if (plugin) {
|
Chris@351
|
652 setPluginParameters(transform, plugin);
|
Chris@351
|
653 }
|
Chris@351
|
654 return plugin;
|
Chris@351
|
655 }
|
Chris@351
|
656
|
Chris@351
|
657 Vamp::PluginBase *
|
Chris@351
|
658 TransformFactory::instantiateDefaultPluginFor(TransformId identifier, size_t rate)
|
Chris@350
|
659 {
|
Chris@350
|
660 Transform t;
|
Chris@350
|
661 t.setIdentifier(identifier);
|
Chris@350
|
662 if (rate == 0) rate = 44100;
|
Chris@350
|
663 QString pluginId = t.getPluginIdentifier();
|
Chris@350
|
664
|
Chris@350
|
665 Vamp::PluginBase *plugin = 0;
|
Chris@350
|
666
|
Chris@350
|
667 if (t.getType() == Transform::FeatureExtraction) {
|
Chris@350
|
668
|
Chris@350
|
669 FeatureExtractionPluginFactory *factory =
|
Chris@350
|
670 FeatureExtractionPluginFactory::instanceFor(pluginId);
|
Chris@350
|
671
|
Chris@439
|
672 if (factory) {
|
Chris@439
|
673 plugin = factory->instantiatePlugin(pluginId, rate);
|
Chris@439
|
674 }
|
Chris@350
|
675
|
Chris@350
|
676 } else {
|
Chris@350
|
677
|
Chris@350
|
678 RealTimePluginFactory *factory =
|
Chris@350
|
679 RealTimePluginFactory::instanceFor(pluginId);
|
Chris@439
|
680
|
Chris@439
|
681 if (factory) {
|
Chris@439
|
682 plugin = factory->instantiatePlugin(pluginId, 0, 0, rate, 1024, 1);
|
Chris@439
|
683 }
|
Chris@350
|
684 }
|
Chris@350
|
685
|
Chris@350
|
686 return plugin;
|
Chris@350
|
687 }
|
Chris@350
|
688
|
Chris@350
|
689 Vamp::Plugin *
|
Chris@350
|
690 TransformFactory::downcastVampPlugin(Vamp::PluginBase *plugin)
|
Chris@350
|
691 {
|
Chris@350
|
692 Vamp::Plugin *vp = dynamic_cast<Vamp::Plugin *>(plugin);
|
Chris@350
|
693 if (!vp) {
|
Chris@443
|
694 // cerr << "makeConsistentWithPlugin: not a Vamp::Plugin" << endl;
|
Chris@350
|
695 vp = dynamic_cast<Vamp::PluginHostAdapter *>(plugin); //!!! why?
|
Chris@350
|
696 }
|
Chris@350
|
697 if (!vp) {
|
Chris@443
|
698 // cerr << "makeConsistentWithPlugin: not a Vamp::PluginHostAdapter" << endl;
|
Chris@350
|
699 vp = dynamic_cast<Vamp::HostExt::PluginWrapper *>(plugin); //!!! no, I mean really why?
|
Chris@350
|
700 }
|
Chris@350
|
701 if (!vp) {
|
Chris@443
|
702 // cerr << "makeConsistentWithPlugin: not a Vamp::HostExt::PluginWrapper" << endl;
|
Chris@350
|
703 }
|
Chris@350
|
704 return vp;
|
Chris@350
|
705 }
|
Chris@350
|
706
|
Chris@330
|
707 bool
|
Chris@330
|
708 TransformFactory::haveTransform(TransformId identifier)
|
Chris@330
|
709 {
|
Chris@460
|
710 populateTransforms();
|
Chris@330
|
711 return (m_transforms.find(identifier) != m_transforms.end());
|
Chris@330
|
712 }
|
Chris@330
|
713
|
Chris@330
|
714 QString
|
Chris@330
|
715 TransformFactory::getTransformName(TransformId identifier)
|
Chris@330
|
716 {
|
Chris@330
|
717 if (m_transforms.find(identifier) != m_transforms.end()) {
|
Chris@330
|
718 return m_transforms[identifier].name;
|
Chris@330
|
719 } else return "";
|
Chris@330
|
720 }
|
Chris@330
|
721
|
Chris@330
|
722 QString
|
Chris@330
|
723 TransformFactory::getTransformFriendlyName(TransformId identifier)
|
Chris@330
|
724 {
|
Chris@330
|
725 if (m_transforms.find(identifier) != m_transforms.end()) {
|
Chris@330
|
726 return m_transforms[identifier].friendlyName;
|
Chris@330
|
727 } else return "";
|
Chris@330
|
728 }
|
Chris@330
|
729
|
Chris@330
|
730 QString
|
Chris@330
|
731 TransformFactory::getTransformUnits(TransformId identifier)
|
Chris@330
|
732 {
|
Chris@330
|
733 if (m_transforms.find(identifier) != m_transforms.end()) {
|
Chris@330
|
734 return m_transforms[identifier].units;
|
Chris@330
|
735 } else return "";
|
Chris@330
|
736 }
|
Chris@330
|
737
|
Chris@350
|
738 Vamp::Plugin::InputDomain
|
Chris@350
|
739 TransformFactory::getTransformInputDomain(TransformId identifier)
|
Chris@350
|
740 {
|
Chris@350
|
741 Transform transform;
|
Chris@350
|
742 transform.setIdentifier(identifier);
|
Chris@350
|
743
|
Chris@350
|
744 if (transform.getType() != Transform::FeatureExtraction) {
|
Chris@350
|
745 return Vamp::Plugin::TimeDomain;
|
Chris@350
|
746 }
|
Chris@350
|
747
|
Chris@350
|
748 Vamp::Plugin *plugin =
|
Chris@351
|
749 downcastVampPlugin(instantiateDefaultPluginFor(identifier, 0));
|
Chris@350
|
750
|
Chris@350
|
751 if (plugin) {
|
Chris@350
|
752 Vamp::Plugin::InputDomain d = plugin->getInputDomain();
|
Chris@350
|
753 delete plugin;
|
Chris@350
|
754 return d;
|
Chris@350
|
755 }
|
Chris@350
|
756
|
Chris@350
|
757 return Vamp::Plugin::TimeDomain;
|
Chris@350
|
758 }
|
Chris@350
|
759
|
Chris@330
|
760 bool
|
Chris@330
|
761 TransformFactory::isTransformConfigurable(TransformId identifier)
|
Chris@330
|
762 {
|
Chris@330
|
763 if (m_transforms.find(identifier) != m_transforms.end()) {
|
Chris@330
|
764 return m_transforms[identifier].configurable;
|
Chris@330
|
765 } else return false;
|
Chris@330
|
766 }
|
Chris@330
|
767
|
Chris@330
|
768 bool
|
Chris@330
|
769 TransformFactory::getTransformChannelRange(TransformId identifier,
|
Chris@330
|
770 int &min, int &max)
|
Chris@330
|
771 {
|
Chris@330
|
772 QString id = identifier.section(':', 0, 2);
|
Chris@330
|
773
|
Chris@330
|
774 if (FeatureExtractionPluginFactory::instanceFor(id)) {
|
Chris@330
|
775
|
Chris@330
|
776 Vamp::Plugin *plugin =
|
Chris@330
|
777 FeatureExtractionPluginFactory::instanceFor(id)->
|
Chris@350
|
778 instantiatePlugin(id, 44100);
|
Chris@330
|
779 if (!plugin) return false;
|
Chris@330
|
780
|
Chris@330
|
781 min = plugin->getMinChannelCount();
|
Chris@330
|
782 max = plugin->getMaxChannelCount();
|
Chris@330
|
783 delete plugin;
|
Chris@330
|
784
|
Chris@330
|
785 return true;
|
Chris@330
|
786
|
Chris@330
|
787 } else if (RealTimePluginFactory::instanceFor(id)) {
|
Chris@330
|
788
|
Chris@350
|
789 // don't need to instantiate
|
Chris@350
|
790
|
Chris@330
|
791 const RealTimePluginDescriptor *descriptor =
|
Chris@330
|
792 RealTimePluginFactory::instanceFor(id)->
|
Chris@330
|
793 getPluginDescriptor(id);
|
Chris@330
|
794 if (!descriptor) return false;
|
Chris@330
|
795
|
Chris@330
|
796 min = descriptor->audioInputPortCount;
|
Chris@330
|
797 max = descriptor->audioInputPortCount;
|
Chris@330
|
798
|
Chris@330
|
799 return true;
|
Chris@330
|
800 }
|
Chris@330
|
801
|
Chris@330
|
802 return false;
|
Chris@330
|
803 }
|
Chris@332
|
804
|
Chris@332
|
805 void
|
Chris@332
|
806 TransformFactory::setParametersFromPlugin(Transform &transform,
|
Chris@332
|
807 Vamp::PluginBase *plugin)
|
Chris@332
|
808 {
|
Chris@332
|
809 Transform::ParameterMap pmap;
|
Chris@332
|
810
|
Chris@350
|
811 //!!! record plugin & API version
|
Chris@350
|
812
|
Chris@350
|
813 //!!! check that this is the right plugin!
|
Chris@350
|
814
|
Chris@332
|
815 Vamp::PluginBase::ParameterList parameters =
|
Chris@332
|
816 plugin->getParameterDescriptors();
|
Chris@332
|
817
|
Chris@332
|
818 for (Vamp::PluginBase::ParameterList::const_iterator i = parameters.begin();
|
Chris@332
|
819 i != parameters.end(); ++i) {
|
Chris@332
|
820 pmap[i->identifier.c_str()] = plugin->getParameter(i->identifier);
|
Chris@332
|
821 }
|
Chris@332
|
822
|
Chris@332
|
823 transform.setParameters(pmap);
|
Chris@332
|
824
|
Chris@332
|
825 if (plugin->getPrograms().empty()) {
|
Chris@332
|
826 transform.setProgram("");
|
Chris@332
|
827 } else {
|
Chris@332
|
828 transform.setProgram(plugin->getCurrentProgram().c_str());
|
Chris@332
|
829 }
|
Chris@332
|
830
|
Chris@332
|
831 RealTimePluginInstance *rtpi =
|
Chris@332
|
832 dynamic_cast<RealTimePluginInstance *>(plugin);
|
Chris@332
|
833
|
Chris@332
|
834 Transform::ConfigurationMap cmap;
|
Chris@332
|
835
|
Chris@332
|
836 if (rtpi) {
|
Chris@332
|
837
|
Chris@332
|
838 RealTimePluginInstance::ConfigurationPairMap configurePairs =
|
Chris@332
|
839 rtpi->getConfigurePairs();
|
Chris@332
|
840
|
Chris@332
|
841 for (RealTimePluginInstance::ConfigurationPairMap::const_iterator i
|
Chris@332
|
842 = configurePairs.begin(); i != configurePairs.end(); ++i) {
|
Chris@332
|
843 cmap[i->first.c_str()] = i->second.c_str();
|
Chris@332
|
844 }
|
Chris@332
|
845 }
|
Chris@332
|
846
|
Chris@332
|
847 transform.setConfiguration(cmap);
|
Chris@332
|
848 }
|
Chris@332
|
849
|
Chris@332
|
850 void
|
Chris@350
|
851 TransformFactory::setPluginParameters(const Transform &transform,
|
Chris@350
|
852 Vamp::PluginBase *plugin)
|
Chris@350
|
853 {
|
Chris@350
|
854 //!!! check plugin & API version (see e.g. PluginXml::setParameters)
|
Chris@350
|
855
|
Chris@350
|
856 //!!! check that this is the right plugin!
|
Chris@350
|
857
|
Chris@350
|
858 RealTimePluginInstance *rtpi =
|
Chris@350
|
859 dynamic_cast<RealTimePluginInstance *>(plugin);
|
Chris@350
|
860
|
Chris@350
|
861 if (rtpi) {
|
Chris@350
|
862 const Transform::ConfigurationMap &cmap = transform.getConfiguration();
|
Chris@350
|
863 for (Transform::ConfigurationMap::const_iterator i = cmap.begin();
|
Chris@350
|
864 i != cmap.end(); ++i) {
|
Chris@350
|
865 rtpi->configure(i->first.toStdString(), i->second.toStdString());
|
Chris@350
|
866 }
|
Chris@350
|
867 }
|
Chris@350
|
868
|
Chris@350
|
869 if (transform.getProgram() != "") {
|
Chris@350
|
870 plugin->selectProgram(transform.getProgram().toStdString());
|
Chris@350
|
871 }
|
Chris@350
|
872
|
Chris@350
|
873 const Transform::ParameterMap &pmap = transform.getParameters();
|
Chris@350
|
874
|
Chris@350
|
875 Vamp::PluginBase::ParameterList parameters =
|
Chris@350
|
876 plugin->getParameterDescriptors();
|
Chris@350
|
877
|
Chris@350
|
878 for (Vamp::PluginBase::ParameterList::const_iterator i = parameters.begin();
|
Chris@350
|
879 i != parameters.end(); ++i) {
|
Chris@350
|
880 QString key = i->identifier.c_str();
|
Chris@350
|
881 Transform::ParameterMap::const_iterator pmi = pmap.find(key);
|
Chris@350
|
882 if (pmi != pmap.end()) {
|
Chris@350
|
883 plugin->setParameter(i->identifier, pmi->second);
|
Chris@350
|
884 }
|
Chris@350
|
885 }
|
Chris@350
|
886 }
|
Chris@350
|
887
|
Chris@350
|
888 void
|
Chris@332
|
889 TransformFactory::makeContextConsistentWithPlugin(Transform &transform,
|
Chris@332
|
890 Vamp::PluginBase *plugin)
|
Chris@332
|
891 {
|
Chris@350
|
892 const Vamp::Plugin *vp = downcastVampPlugin(plugin);
|
Chris@332
|
893
|
Chris@332
|
894 if (!vp) {
|
Chris@332
|
895 // time domain input for real-time effects plugin
|
Chris@332
|
896 if (!transform.getBlockSize()) {
|
Chris@332
|
897 if (!transform.getStepSize()) transform.setStepSize(1024);
|
Chris@332
|
898 transform.setBlockSize(transform.getStepSize());
|
Chris@332
|
899 } else {
|
Chris@332
|
900 transform.setStepSize(transform.getBlockSize());
|
Chris@332
|
901 }
|
Chris@332
|
902 } else {
|
Chris@332
|
903 Vamp::Plugin::InputDomain domain = vp->getInputDomain();
|
Chris@332
|
904 if (!transform.getStepSize()) {
|
Chris@332
|
905 transform.setStepSize(vp->getPreferredStepSize());
|
Chris@332
|
906 }
|
Chris@332
|
907 if (!transform.getBlockSize()) {
|
Chris@332
|
908 transform.setBlockSize(vp->getPreferredBlockSize());
|
Chris@332
|
909 }
|
Chris@332
|
910 if (!transform.getBlockSize()) {
|
Chris@332
|
911 transform.setBlockSize(1024);
|
Chris@332
|
912 }
|
Chris@332
|
913 if (!transform.getStepSize()) {
|
Chris@332
|
914 if (domain == Vamp::Plugin::FrequencyDomain) {
|
Chris@443
|
915 // cerr << "frequency domain, step = " << blockSize/2 << endl;
|
Chris@332
|
916 transform.setStepSize(transform.getBlockSize()/2);
|
Chris@332
|
917 } else {
|
Chris@443
|
918 // cerr << "time domain, step = " << blockSize/2 << endl;
|
Chris@332
|
919 transform.setStepSize(transform.getBlockSize());
|
Chris@332
|
920 }
|
Chris@332
|
921 }
|
Chris@332
|
922 }
|
Chris@332
|
923 }
|
Chris@332
|
924
|
Chris@350
|
925 QString
|
Chris@350
|
926 TransformFactory::getPluginConfigurationXml(const Transform &t)
|
Chris@332
|
927 {
|
Chris@350
|
928 QString xml;
|
Chris@350
|
929
|
Chris@351
|
930 Vamp::PluginBase *plugin = instantiateDefaultPluginFor
|
Chris@351
|
931 (t.getIdentifier(), 0);
|
Chris@350
|
932 if (!plugin) {
|
Chris@443
|
933 cerr << "TransformFactory::getPluginConfigurationXml: "
|
Chris@350
|
934 << "Unable to instantiate plugin for transform \""
|
Chris@443
|
935 << t.getIdentifier().toStdString() << "\"" << endl;
|
Chris@350
|
936 return xml;
|
Chris@332
|
937 }
|
Chris@332
|
938
|
Chris@351
|
939 setPluginParameters(t, plugin);
|
Chris@351
|
940
|
Chris@350
|
941 QTextStream out(&xml);
|
Chris@350
|
942 PluginXml(plugin).toXml(out);
|
Chris@350
|
943 delete plugin;
|
Chris@332
|
944
|
Chris@350
|
945 return xml;
|
Chris@350
|
946 }
|
Chris@332
|
947
|
Chris@350
|
948 void
|
Chris@350
|
949 TransformFactory::setParametersFromPluginConfigurationXml(Transform &t,
|
Chris@350
|
950 QString xml)
|
Chris@350
|
951 {
|
Chris@351
|
952 Vamp::PluginBase *plugin = instantiateDefaultPluginFor
|
Chris@351
|
953 (t.getIdentifier(), 0);
|
Chris@350
|
954 if (!plugin) {
|
Chris@443
|
955 cerr << "TransformFactory::setParametersFromPluginConfigurationXml: "
|
Chris@350
|
956 << "Unable to instantiate plugin for transform \""
|
Chris@443
|
957 << t.getIdentifier().toStdString() << "\"" << endl;
|
Chris@350
|
958 return;
|
Chris@332
|
959 }
|
Chris@332
|
960
|
Chris@350
|
961 PluginXml(plugin).setParametersFromXml(xml);
|
Chris@350
|
962 setParametersFromPlugin(t, plugin);
|
Chris@350
|
963 delete plugin;
|
Chris@332
|
964 }
|
Chris@332
|
965
|
Chris@443
|
966 TransformFactory::SearchResults
|
Chris@443
|
967 TransformFactory::search(QString keyword)
|
Chris@443
|
968 {
|
Chris@443
|
969 QStringList keywords;
|
Chris@443
|
970 keywords << keyword;
|
Chris@443
|
971 return search(keywords);
|
Chris@443
|
972 }
|
Chris@443
|
973
|
Chris@443
|
974 TransformFactory::SearchResults
|
Chris@443
|
975 TransformFactory::search(QStringList keywords)
|
Chris@443
|
976 {
|
Chris@460
|
977 populateTransforms();
|
Chris@443
|
978
|
Chris@447
|
979 if (keywords.size() > 1) {
|
Chris@447
|
980 // Additional score for all keywords in a row
|
Chris@447
|
981 keywords.push_back(keywords.join(" "));
|
Chris@447
|
982 }
|
Chris@447
|
983
|
Chris@443
|
984 SearchResults results;
|
Chris@457
|
985 TextMatcher matcher;
|
Chris@443
|
986
|
Chris@443
|
987 for (TransformDescriptionMap::const_iterator i = m_transforms.begin();
|
Chris@443
|
988 i != m_transforms.end(); ++i) {
|
Chris@443
|
989
|
Chris@457
|
990 TextMatcher::Match match;
|
Chris@443
|
991
|
Chris@457
|
992 match.key = i->first;
|
Chris@443
|
993
|
Chris@457
|
994 matcher.test(match, keywords, i->second.type, tr("Plugin type"), 5);
|
Chris@457
|
995 matcher.test(match, keywords, i->second.category, tr("Category"), 20);
|
Chris@457
|
996 matcher.test(match, keywords, i->second.identifier, tr("System Identifier"), 6);
|
Chris@457
|
997 matcher.test(match, keywords, i->second.name, tr("Name"), 30);
|
Chris@457
|
998 matcher.test(match, keywords, i->second.description, tr("Description"), 20);
|
Chris@457
|
999 matcher.test(match, keywords, i->second.maker, tr("Maker"), 10);
|
Chris@457
|
1000 matcher.test(match, keywords, i->second.units, tr("Units"), 10);
|
Chris@457
|
1001
|
Chris@457
|
1002 if (match.score > 0) results[i->first] = match;
|
Chris@457
|
1003 }
|
Chris@457
|
1004
|
Chris@460
|
1005 if (!m_uninstalledTransformsMutex.tryLock()) {
|
Chris@460
|
1006 // uninstalled transforms are being populated; this may take some time,
|
Chris@460
|
1007 // and they aren't critical
|
Chris@460
|
1008 std::cerr << "TransformFactory::search: Uninstalled transforms mutex is held, skipping" << std::endl;
|
Chris@460
|
1009 return results;
|
Chris@460
|
1010 }
|
Chris@460
|
1011
|
Chris@460
|
1012 if (!m_uninstalledTransformsPopulated) {
|
Chris@460
|
1013 std::cerr << "WARNING: TransformFactory::search: Uninstalled transforms are not populated yet" << endl
|
Chris@460
|
1014 << "and are not being populated either -- was the thread not started correctly?" << endl;
|
Chris@460
|
1015 m_uninstalledTransformsMutex.unlock();
|
Chris@460
|
1016 return results;
|
Chris@460
|
1017 }
|
Chris@460
|
1018
|
Chris@460
|
1019 m_uninstalledTransformsMutex.unlock();
|
Chris@457
|
1020
|
Chris@457
|
1021 for (TransformDescriptionMap::const_iterator i = m_uninstalledTransforms.begin();
|
Chris@457
|
1022 i != m_uninstalledTransforms.end(); ++i) {
|
Chris@457
|
1023
|
Chris@457
|
1024 TextMatcher::Match match;
|
Chris@457
|
1025
|
Chris@457
|
1026 match.key = i->first;
|
Chris@457
|
1027
|
Chris@457
|
1028 matcher.test(match, keywords, i->second.type, tr("Plugin type"), 2);
|
Chris@457
|
1029 matcher.test(match, keywords, i->second.category, tr("Category"), 10);
|
Chris@457
|
1030 matcher.test(match, keywords, i->second.identifier, tr("System Identifier"), 3);
|
Chris@457
|
1031 matcher.test(match, keywords, i->second.name, tr("Name"), 15);
|
Chris@457
|
1032 matcher.test(match, keywords, i->second.description, tr("Description"), 10);
|
Chris@457
|
1033 matcher.test(match, keywords, i->second.maker, tr("Maker"), 5);
|
Chris@457
|
1034 matcher.test(match, keywords, i->second.units, tr("Units"), 5);
|
Chris@443
|
1035
|
Chris@443
|
1036 if (match.score > 0) results[i->first] = match;
|
Chris@443
|
1037 }
|
Chris@443
|
1038
|
Chris@443
|
1039 return results;
|
Chris@443
|
1040 }
|
Chris@443
|
1041
|