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