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