Chris@49
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@52
|
4 Sonic Visualiser
|
Chris@52
|
5 An audio file viewer and annotation editor.
|
Chris@52
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@0
|
7
|
Chris@52
|
8 This program is free software; you can redistribute it and/or
|
Chris@52
|
9 modify it under the terms of the GNU General Public License as
|
Chris@52
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@52
|
11 License, or (at your option) any later version. See the file
|
Chris@52
|
12 COPYING included with this distribution for more information.
|
Chris@0
|
13 */
|
Chris@0
|
14
|
Chris@0
|
15 /*
|
Chris@0
|
16 This is a modified version of a source file from the
|
Chris@0
|
17 Rosegarden MIDI and audio sequencer and notation editor.
|
Chris@17
|
18 This file copyright 2000-2006 Chris Cannam and Richard Bown.
|
Chris@0
|
19 */
|
Chris@0
|
20
|
Chris@0
|
21 #include "LADSPAPluginFactory.h"
|
Chris@0
|
22 #include <iostream>
|
Chris@0
|
23
|
Chris@0
|
24 #include <QDir>
|
Chris@0
|
25 #include <QFile>
|
Chris@0
|
26 #include <QTextStream>
|
Chris@0
|
27
|
Chris@0
|
28 #include <cmath>
|
Chris@0
|
29
|
Chris@0
|
30 #include "LADSPAPluginInstance.h"
|
Chris@0
|
31 #include "PluginIdentifier.h"
|
Chris@0
|
32
|
Chris@150
|
33 #include "system/System.h"
|
Chris@145
|
34 #include "base/Preferences.h"
|
Chris@408
|
35 #include "base/Profiler.h"
|
Chris@0
|
36
|
Chris@260
|
37 //#define DEBUG_LADSPA_PLUGIN_FACTORY 1
|
Chris@260
|
38
|
Chris@35
|
39 #ifdef HAVE_LRDF
|
Chris@0
|
40 #include "lrdf.h"
|
Chris@35
|
41 #endif // HAVE_LRDF
|
Chris@0
|
42
|
Chris@0
|
43
|
Chris@0
|
44 LADSPAPluginFactory::LADSPAPluginFactory()
|
Chris@0
|
45 {
|
Chris@166
|
46 #ifdef HAVE_LRDF
|
Chris@166
|
47 lrdf_init();
|
Chris@166
|
48 #endif
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 LADSPAPluginFactory::~LADSPAPluginFactory()
|
Chris@0
|
52 {
|
Chris@0
|
53 for (std::set<RealTimePluginInstance *>::iterator i = m_instances.begin();
|
Chris@1429
|
54 i != m_instances.end(); ++i) {
|
Chris@1429
|
55 (*i)->setFactory(0);
|
Chris@1429
|
56 delete *i;
|
Chris@0
|
57 }
|
Chris@0
|
58 m_instances.clear();
|
Chris@0
|
59 unloadUnusedLibraries();
|
Chris@166
|
60
|
Chris@166
|
61 #ifdef HAVE_LRDF
|
Chris@166
|
62 lrdf_cleanup();
|
Chris@166
|
63 #endif // HAVE_LRDF
|
Chris@0
|
64 }
|
Chris@0
|
65
|
Chris@0
|
66 const std::vector<QString> &
|
Chris@0
|
67 LADSPAPluginFactory::getPluginIdentifiers() const
|
Chris@0
|
68 {
|
Chris@0
|
69 return m_identifiers;
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@1464
|
72 QString
|
Chris@1464
|
73 LADSPAPluginFactory::getPluginLibraryPath(QString identifier)
|
Chris@1464
|
74 {
|
Chris@1464
|
75 return m_libraries[identifier];
|
Chris@1464
|
76 }
|
Chris@1464
|
77
|
Chris@0
|
78 void
|
Chris@0
|
79 LADSPAPluginFactory::enumeratePlugins(std::vector<QString> &list)
|
Chris@0
|
80 {
|
Chris@408
|
81 Profiler profiler("LADSPAPluginFactory::enumeratePlugins");
|
Chris@408
|
82
|
Chris@0
|
83 for (std::vector<QString>::iterator i = m_identifiers.begin();
|
Chris@1429
|
84 i != m_identifiers.end(); ++i) {
|
Chris@0
|
85
|
Chris@1429
|
86 const LADSPA_Descriptor *descriptor = getLADSPADescriptor(*i);
|
Chris@0
|
87
|
Chris@1429
|
88 if (!descriptor) {
|
Chris@1429
|
89 cerr << "WARNING: LADSPAPluginFactory::enumeratePlugins: couldn't get descriptor for identifier " << *i << endl;
|
Chris@1429
|
90 continue;
|
Chris@1429
|
91 }
|
Chris@1429
|
92
|
Chris@1429
|
93 list.push_back(*i);
|
Chris@1429
|
94 list.push_back(descriptor->Name);
|
Chris@1429
|
95 list.push_back(QString("%1").arg(descriptor->UniqueID));
|
Chris@1429
|
96 list.push_back(descriptor->Label);
|
Chris@1429
|
97 list.push_back(descriptor->Maker);
|
Chris@1429
|
98 list.push_back(descriptor->Copyright);
|
Chris@1429
|
99 list.push_back("false"); // is synth
|
Chris@1429
|
100 list.push_back("false"); // is grouped
|
Chris@165
|
101
|
Chris@1429
|
102 if (m_taxonomy.find(*i) != m_taxonomy.end() && m_taxonomy[*i] != "") {
|
Chris@1429
|
103 // cerr << "LADSPAPluginFactory: cat for " << *i << " found in taxonomy as " << m_taxonomy[descriptor->UniqueID] << endl;
|
Chris@1429
|
104 list.push_back(m_taxonomy[*i]);
|
Chris@1429
|
105 } else {
|
Chris@1429
|
106 list.push_back("");
|
Chris@1429
|
107 // cerr << "LADSPAPluginFactory: cat for " << *i << " not found (despite having " << m_fallbackCategories.size() << " fallbacks)" << endl;
|
Chris@1429
|
108
|
Chris@1429
|
109 }
|
Chris@0
|
110
|
Chris@1429
|
111 list.push_back(QString("%1").arg(descriptor->PortCount));
|
Chris@0
|
112
|
Chris@1429
|
113 for (int p = 0; p < (int)descriptor->PortCount; ++p) {
|
Chris@0
|
114
|
Chris@1429
|
115 int type = 0;
|
Chris@1429
|
116 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) {
|
Chris@1429
|
117 type |= PortType::Control;
|
Chris@1429
|
118 } else {
|
Chris@1429
|
119 type |= PortType::Audio;
|
Chris@1429
|
120 }
|
Chris@1429
|
121 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) {
|
Chris@1429
|
122 type |= PortType::Input;
|
Chris@1429
|
123 } else {
|
Chris@1429
|
124 type |= PortType::Output;
|
Chris@1429
|
125 }
|
Chris@0
|
126
|
Chris@1429
|
127 list.push_back(QString("%1").arg(p));
|
Chris@1429
|
128 list.push_back(descriptor->PortNames[p]);
|
Chris@1429
|
129 list.push_back(QString("%1").arg(type));
|
Chris@1429
|
130 list.push_back(QString("%1").arg(getPortDisplayHint(descriptor, p)));
|
Chris@1429
|
131 list.push_back(QString("%1").arg(getPortMinimum(descriptor, p)));
|
Chris@1429
|
132 list.push_back(QString("%1").arg(getPortMaximum(descriptor, p)));
|
Chris@1429
|
133 list.push_back(QString("%1").arg(getPortDefault(descriptor, p)));
|
Chris@1429
|
134 }
|
Chris@0
|
135 }
|
Chris@0
|
136
|
Chris@0
|
137 unloadUnusedLibraries();
|
Chris@0
|
138 }
|
Chris@1429
|
139
|
Chris@60
|
140 const RealTimePluginDescriptor *
|
Chris@60
|
141 LADSPAPluginFactory::getPluginDescriptor(QString identifier) const
|
Chris@60
|
142 {
|
Chris@60
|
143 std::map<QString, RealTimePluginDescriptor *>::const_iterator i =
|
Chris@60
|
144 m_rtDescriptors.find(identifier);
|
Chris@60
|
145
|
Chris@60
|
146 if (i != m_rtDescriptors.end()) {
|
Chris@60
|
147 return i->second;
|
Chris@60
|
148 }
|
Chris@60
|
149
|
Chris@60
|
150 return 0;
|
Chris@60
|
151 }
|
Chris@60
|
152
|
Chris@0
|
153 float
|
Chris@0
|
154 LADSPAPluginFactory::getPortMinimum(const LADSPA_Descriptor *descriptor, int port)
|
Chris@0
|
155 {
|
Chris@0
|
156 LADSPA_PortRangeHintDescriptor d =
|
Chris@1429
|
157 descriptor->PortRangeHints[port].HintDescriptor;
|
Chris@0
|
158
|
Chris@1039
|
159 float minimum = 0.f;
|
Chris@1429
|
160
|
Chris@0
|
161 if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) {
|
Chris@1429
|
162 float lb = descriptor->PortRangeHints[port].LowerBound;
|
Chris@1429
|
163 minimum = lb;
|
Chris@0
|
164 } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
|
Chris@1429
|
165 float ub = descriptor->PortRangeHints[port].UpperBound;
|
Chris@1429
|
166 minimum = std::min(0.f, ub - 1.f);
|
Chris@0
|
167 }
|
Chris@0
|
168
|
Chris@0
|
169 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
|
Chris@1429
|
170 minimum = float(minimum * m_sampleRate);
|
Chris@0
|
171 }
|
Chris@0
|
172
|
Chris@356
|
173 if (LADSPA_IS_HINT_LOGARITHMIC(d)) {
|
Chris@356
|
174 if (minimum == 0.f) minimum = 1.f;
|
Chris@356
|
175 }
|
Chris@356
|
176
|
Chris@0
|
177 return minimum;
|
Chris@0
|
178 }
|
Chris@0
|
179
|
Chris@0
|
180 float
|
Chris@0
|
181 LADSPAPluginFactory::getPortMaximum(const LADSPA_Descriptor *descriptor, int port)
|
Chris@0
|
182 {
|
Chris@0
|
183 LADSPA_PortRangeHintDescriptor d =
|
Chris@1429
|
184 descriptor->PortRangeHints[port].HintDescriptor;
|
Chris@0
|
185
|
Chris@1039
|
186 float maximum = 1.f;
|
Chris@0
|
187
|
Chris@0
|
188 if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
|
Chris@1429
|
189 float ub = descriptor->PortRangeHints[port].UpperBound;
|
Chris@1429
|
190 maximum = ub;
|
Chris@0
|
191 } else {
|
Chris@1429
|
192 float lb = descriptor->PortRangeHints[port].LowerBound;
|
Chris@1429
|
193 maximum = lb + 1.f;
|
Chris@0
|
194 }
|
Chris@0
|
195
|
Chris@0
|
196 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
|
Chris@1429
|
197 maximum = float(maximum * m_sampleRate);
|
Chris@0
|
198 }
|
Chris@0
|
199
|
Chris@0
|
200 return maximum;
|
Chris@0
|
201 }
|
Chris@0
|
202
|
Chris@0
|
203 float
|
Chris@0
|
204 LADSPAPluginFactory::getPortDefault(const LADSPA_Descriptor *descriptor, int port)
|
Chris@0
|
205 {
|
Chris@0
|
206 float minimum = getPortMinimum(descriptor, port);
|
Chris@0
|
207 float maximum = getPortMaximum(descriptor, port);
|
Chris@0
|
208 float deft;
|
Chris@0
|
209
|
Chris@0
|
210 if (m_portDefaults.find(descriptor->UniqueID) !=
|
Chris@1429
|
211 m_portDefaults.end()) {
|
Chris@1429
|
212 if (m_portDefaults[descriptor->UniqueID].find(port) !=
|
Chris@1429
|
213 m_portDefaults[descriptor->UniqueID].end()) {
|
Chris@0
|
214
|
Chris@1429
|
215 deft = m_portDefaults[descriptor->UniqueID][port];
|
Chris@1429
|
216 if (deft < minimum) deft = minimum;
|
Chris@1429
|
217 if (deft > maximum) deft = maximum;
|
Chris@1429
|
218 return deft;
|
Chris@1429
|
219 }
|
Chris@0
|
220 }
|
Chris@0
|
221
|
Chris@0
|
222 LADSPA_PortRangeHintDescriptor d =
|
Chris@1429
|
223 descriptor->PortRangeHints[port].HintDescriptor;
|
Chris@0
|
224
|
Chris@0
|
225 bool logarithmic = LADSPA_IS_HINT_LOGARITHMIC(d);
|
Chris@0
|
226
|
Chris@356
|
227 float logmin = 0, logmax = 0;
|
Chris@356
|
228 if (logarithmic) {
|
Chris@356
|
229 float thresh = powf(10, -10);
|
Chris@356
|
230 if (minimum < thresh) logmin = -10;
|
Chris@356
|
231 else logmin = log10f(minimum);
|
Chris@356
|
232 if (maximum < thresh) logmax = -10;
|
Chris@356
|
233 else logmax = log10f(maximum);
|
Chris@356
|
234 }
|
Chris@356
|
235
|
Chris@690
|
236 // SVDEBUG << "LADSPAPluginFactory::getPortDefault: hint = " << d << endl;
|
Chris@356
|
237
|
Chris@0
|
238 if (!LADSPA_IS_HINT_HAS_DEFAULT(d)) {
|
Chris@1429
|
239
|
Chris@1429
|
240 deft = minimum;
|
Chris@1429
|
241
|
Chris@0
|
242 } else if (LADSPA_IS_HINT_DEFAULT_MINIMUM(d)) {
|
Chris@1429
|
243
|
Chris@1429
|
244 deft = minimum;
|
Chris@1429
|
245
|
Chris@0
|
246 } else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) {
|
Chris@1429
|
247
|
Chris@1429
|
248 if (logarithmic) {
|
Chris@1429
|
249 deft = powf(10, logmin * 0.75f + logmax * 0.25f);
|
Chris@1429
|
250 } else {
|
Chris@1429
|
251 deft = minimum * 0.75f + maximum * 0.25f;
|
Chris@1429
|
252 }
|
Chris@1429
|
253
|
Chris@0
|
254 } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) {
|
Chris@1429
|
255
|
Chris@1429
|
256 if (logarithmic) {
|
Chris@1429
|
257 deft = powf(10, logmin * 0.5f + logmax * 0.5f);
|
Chris@1429
|
258 } else {
|
Chris@1429
|
259 deft = minimum * 0.5f + maximum * 0.5f;
|
Chris@1429
|
260 }
|
Chris@1429
|
261
|
Chris@0
|
262 } else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) {
|
Chris@1429
|
263
|
Chris@1429
|
264 if (logarithmic) {
|
Chris@1429
|
265 deft = powf(10, logmin * 0.25f + logmax * 0.75f);
|
Chris@1429
|
266 } else {
|
Chris@1429
|
267 deft = minimum * 0.25f + maximum * 0.75f;
|
Chris@1429
|
268 }
|
Chris@1429
|
269
|
Chris@0
|
270 } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(d)) {
|
Chris@1429
|
271
|
Chris@1429
|
272 deft = maximum;
|
Chris@1429
|
273
|
Chris@0
|
274 } else if (LADSPA_IS_HINT_DEFAULT_0(d)) {
|
Chris@1429
|
275
|
Chris@1429
|
276 deft = 0.0;
|
Chris@1429
|
277
|
Chris@0
|
278 } else if (LADSPA_IS_HINT_DEFAULT_1(d)) {
|
Chris@1429
|
279
|
Chris@1429
|
280 deft = 1.0;
|
Chris@1429
|
281
|
Chris@0
|
282 } else if (LADSPA_IS_HINT_DEFAULT_100(d)) {
|
Chris@1429
|
283
|
Chris@1429
|
284 deft = 100.0;
|
Chris@1429
|
285
|
Chris@0
|
286 } else if (LADSPA_IS_HINT_DEFAULT_440(d)) {
|
Chris@1429
|
287
|
Chris@1429
|
288 // deft = 440.0;
|
Chris@1039
|
289 deft = (float)Preferences::getInstance()->getTuningFrequency();
|
Chris@1429
|
290
|
Chris@0
|
291 } else {
|
Chris@1429
|
292
|
Chris@1429
|
293 deft = minimum;
|
Chris@0
|
294 }
|
Chris@356
|
295
|
Chris@356
|
296 //!!! No -- the min and max have already been multiplied by the rate,
|
Chris@356
|
297 //so it would happen twice if we did it here -- and e.g. DEFAULT_440
|
Chris@356
|
298 //doesn't want to be multiplied by the rate either
|
Chris@0
|
299
|
Chris@356
|
300 // if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
|
Chris@1429
|
301 // deft *= m_sampleRate;
|
Chris@356
|
302 // }
|
Chris@0
|
303
|
Chris@0
|
304 return deft;
|
Chris@0
|
305 }
|
Chris@0
|
306
|
Chris@57
|
307 float
|
Chris@57
|
308 LADSPAPluginFactory::getPortQuantization(const LADSPA_Descriptor *descriptor, int port)
|
Chris@57
|
309 {
|
Chris@57
|
310 int displayHint = getPortDisplayHint(descriptor, port);
|
Chris@57
|
311 if (displayHint & PortHint::Toggled) {
|
Chris@1039
|
312 return float(lrintf(getPortMaximum(descriptor, port)) -
|
Chris@1039
|
313 lrintf(getPortMinimum(descriptor, port)));
|
Chris@57
|
314 }
|
Chris@57
|
315 if (displayHint & PortHint::Integer) {
|
Chris@57
|
316 return 1.0;
|
Chris@57
|
317 }
|
Chris@57
|
318 return 0.0;
|
Chris@57
|
319 }
|
Chris@57
|
320
|
Chris@0
|
321 int
|
Chris@0
|
322 LADSPAPluginFactory::getPortDisplayHint(const LADSPA_Descriptor *descriptor, int port)
|
Chris@0
|
323 {
|
Chris@0
|
324 LADSPA_PortRangeHintDescriptor d =
|
Chris@1429
|
325 descriptor->PortRangeHints[port].HintDescriptor;
|
Chris@0
|
326 int hint = PortHint::NoHint;
|
Chris@0
|
327
|
Chris@0
|
328 if (LADSPA_IS_HINT_TOGGLED(d)) hint |= PortHint::Toggled;
|
Chris@0
|
329 if (LADSPA_IS_HINT_INTEGER(d)) hint |= PortHint::Integer;
|
Chris@0
|
330 if (LADSPA_IS_HINT_LOGARITHMIC(d)) hint |= PortHint::Logarithmic;
|
Chris@0
|
331
|
Chris@0
|
332 return hint;
|
Chris@0
|
333 }
|
Chris@0
|
334
|
Chris@0
|
335
|
Chris@0
|
336 RealTimePluginInstance *
|
Chris@0
|
337 LADSPAPluginFactory::instantiatePlugin(QString identifier,
|
Chris@1429
|
338 int instrument,
|
Chris@1429
|
339 int position,
|
Chris@1429
|
340 sv_samplerate_t sampleRate,
|
Chris@1429
|
341 int blockSize,
|
Chris@1429
|
342 int channels)
|
Chris@0
|
343 {
|
Chris@408
|
344 Profiler profiler("LADSPAPluginFactory::instantiatePlugin");
|
Chris@408
|
345
|
Chris@0
|
346 const LADSPA_Descriptor *descriptor = getLADSPADescriptor(identifier);
|
Chris@0
|
347
|
Chris@0
|
348 if (descriptor) {
|
Chris@0
|
349
|
Chris@1429
|
350 LADSPAPluginInstance *instance =
|
Chris@1429
|
351 new LADSPAPluginInstance
|
Chris@1429
|
352 (this, instrument, identifier, position, sampleRate, blockSize, channels,
|
Chris@1429
|
353 descriptor);
|
Chris@0
|
354
|
Chris@1429
|
355 m_instances.insert(instance);
|
Chris@0
|
356
|
Chris@260
|
357 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
|
Chris@690
|
358 SVDEBUG << "LADSPAPluginFactory::instantiatePlugin("
|
Chris@687
|
359 << identifier << ": now have " << m_instances.size() << " instances" << endl;
|
Chris@260
|
360 #endif
|
Chris@78
|
361
|
Chris@1429
|
362 return instance;
|
Chris@0
|
363 }
|
Chris@0
|
364
|
Chris@0
|
365 return 0;
|
Chris@0
|
366 }
|
Chris@0
|
367
|
Chris@0
|
368 void
|
Chris@0
|
369 LADSPAPluginFactory::releasePlugin(RealTimePluginInstance *instance,
|
Chris@1429
|
370 QString identifier)
|
Chris@0
|
371 {
|
Chris@408
|
372 Profiler profiler("LADSPAPluginFactory::releasePlugin");
|
Chris@408
|
373
|
Chris@0
|
374 if (m_instances.find(instance) == m_instances.end()) {
|
Chris@1429
|
375 cerr << "WARNING: LADSPAPluginFactory::releasePlugin: Not one of mine!"
|
Chris@1429
|
376 << endl;
|
Chris@1429
|
377 return;
|
Chris@0
|
378 }
|
Chris@0
|
379
|
Chris@0
|
380 QString type, soname, label;
|
Chris@0
|
381 PluginIdentifier::parseIdentifier(identifier, type, soname, label);
|
Chris@0
|
382
|
Chris@0
|
383 m_instances.erase(instance);
|
Chris@0
|
384
|
Chris@0
|
385 bool stillInUse = false;
|
Chris@0
|
386
|
Chris@0
|
387 for (std::set<RealTimePluginInstance *>::iterator ii = m_instances.begin();
|
Chris@1429
|
388 ii != m_instances.end(); ++ii) {
|
Chris@1429
|
389 QString itype, isoname, ilabel;
|
Chris@1429
|
390 PluginIdentifier::parseIdentifier((*ii)->getPluginIdentifier(), itype, isoname, ilabel);
|
Chris@1429
|
391 if (isoname == soname) {
|
Chris@260
|
392 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
|
Chris@1429
|
393 SVDEBUG << "LADSPAPluginFactory::releasePlugin: dll " << soname << " is still in use for plugin " << ilabel << endl;
|
Chris@260
|
394 #endif
|
Chris@1429
|
395 stillInUse = true;
|
Chris@1429
|
396 break;
|
Chris@1429
|
397 }
|
Chris@0
|
398 }
|
Chris@0
|
399
|
Chris@0
|
400 if (!stillInUse) {
|
Chris@118
|
401 if (soname != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
|
Chris@260
|
402 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
|
Chris@690
|
403 SVDEBUG << "LADSPAPluginFactory::releasePlugin: dll " << soname << " no longer in use, unloading" << endl;
|
Chris@260
|
404 #endif
|
Chris@118
|
405 unloadLibrary(soname);
|
Chris@118
|
406 }
|
Chris@0
|
407 }
|
Chris@78
|
408
|
Chris@260
|
409 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
|
Chris@690
|
410 SVDEBUG << "LADSPAPluginFactory::releasePlugin("
|
Chris@687
|
411 << identifier << ": now have " << m_instances.size() << " instances" << endl;
|
Chris@260
|
412 #endif
|
Chris@0
|
413 }
|
Chris@0
|
414
|
Chris@0
|
415 const LADSPA_Descriptor *
|
Chris@0
|
416 LADSPAPluginFactory::getLADSPADescriptor(QString identifier)
|
Chris@0
|
417 {
|
Chris@0
|
418 QString type, soname, label;
|
Chris@0
|
419 PluginIdentifier::parseIdentifier(identifier, type, soname, label);
|
Chris@0
|
420
|
Chris@0
|
421 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) {
|
Chris@1429
|
422 loadLibrary(soname);
|
Chris@1429
|
423 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) {
|
Chris@1429
|
424 cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: loadLibrary failed for " << soname << endl;
|
Chris@1429
|
425 return 0;
|
Chris@1429
|
426 }
|
Chris@0
|
427 }
|
Chris@0
|
428
|
Chris@0
|
429 void *libraryHandle = m_libraryHandles[soname];
|
Chris@0
|
430
|
Chris@0
|
431 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
|
Chris@1429
|
432 DLSYM(libraryHandle, "ladspa_descriptor");
|
Chris@0
|
433
|
Chris@0
|
434 if (!fn) {
|
Chris@1429
|
435 cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No descriptor function in library " << soname << endl;
|
Chris@1429
|
436 return 0;
|
Chris@0
|
437 }
|
Chris@0
|
438
|
Chris@0
|
439 const LADSPA_Descriptor *descriptor = 0;
|
Chris@0
|
440
|
Chris@0
|
441 int index = 0;
|
Chris@0
|
442 while ((descriptor = fn(index))) {
|
Chris@1429
|
443 if (descriptor->Label == label) return descriptor;
|
Chris@1429
|
444 ++index;
|
Chris@0
|
445 }
|
Chris@0
|
446
|
Chris@843
|
447 cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No such plugin as " << label << " in library " << soname << endl;
|
Chris@0
|
448
|
Chris@0
|
449 return 0;
|
Chris@0
|
450 }
|
Chris@0
|
451
|
Chris@0
|
452 void
|
Chris@0
|
453 LADSPAPluginFactory::loadLibrary(QString soName)
|
Chris@0
|
454 {
|
Chris@0
|
455 void *libraryHandle = DLOPEN(soName, RTLD_NOW);
|
Chris@106
|
456 if (libraryHandle) {
|
Chris@106
|
457 m_libraryHandles[soName] = libraryHandle;
|
Chris@690
|
458 SVDEBUG << "LADSPAPluginFactory::loadLibrary: Loaded library \"" << soName << "\"" << endl;
|
Chris@106
|
459 return;
|
Chris@106
|
460 }
|
Chris@106
|
461
|
Chris@106
|
462 if (QFileInfo(soName).exists()) {
|
Chris@106
|
463 DLERROR();
|
Chris@843
|
464 cerr << "LADSPAPluginFactory::loadLibrary: Library \"" << soName << "\" exists, but failed to load it" << endl;
|
Chris@106
|
465 return;
|
Chris@106
|
466 }
|
Chris@106
|
467
|
Chris@106
|
468 std::vector<QString> pathList = getPluginPath();
|
Chris@106
|
469
|
Chris@106
|
470 QString fileName = QFile(soName).fileName();
|
Chris@106
|
471 QString base = QFileInfo(soName).baseName();
|
Chris@106
|
472
|
Chris@106
|
473 for (std::vector<QString>::iterator i = pathList.begin();
|
Chris@1429
|
474 i != pathList.end(); ++i) {
|
Chris@106
|
475
|
Chris@260
|
476 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
|
Chris@690
|
477 SVDEBUG << "Looking at: " << (*i) << endl;
|
Chris@260
|
478 #endif
|
Chris@106
|
479
|
Chris@106
|
480 QDir dir(*i, PLUGIN_GLOB,
|
Chris@106
|
481 QDir::Name | QDir::IgnoreCase,
|
Chris@106
|
482 QDir::Files | QDir::Readable);
|
Chris@106
|
483
|
Chris@106
|
484 if (QFileInfo(dir.filePath(fileName)).exists()) {
|
Chris@260
|
485 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
|
Chris@843
|
486 cerr << "Loading: " << fileName << endl;
|
Chris@260
|
487 #endif
|
Chris@106
|
488 libraryHandle = DLOPEN(dir.filePath(fileName), RTLD_NOW);
|
Chris@166
|
489 if (libraryHandle) {
|
Chris@166
|
490 m_libraryHandles[soName] = libraryHandle;
|
Chris@166
|
491 return;
|
Chris@166
|
492 }
|
Chris@106
|
493 }
|
Chris@106
|
494
|
Chris@1429
|
495 for (unsigned int j = 0; j < dir.count(); ++j) {
|
Chris@106
|
496 QString file = dir.filePath(dir[j]);
|
Chris@106
|
497 if (QFileInfo(file).baseName() == base) {
|
Chris@260
|
498 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
|
Chris@843
|
499 cerr << "Loading: " << file << endl;
|
Chris@260
|
500 #endif
|
Chris@106
|
501 libraryHandle = DLOPEN(file, RTLD_NOW);
|
Chris@166
|
502 if (libraryHandle) {
|
Chris@166
|
503 m_libraryHandles[soName] = libraryHandle;
|
Chris@166
|
504 return;
|
Chris@166
|
505 }
|
Chris@106
|
506 }
|
Chris@106
|
507 }
|
Chris@106
|
508 }
|
Chris@106
|
509
|
Chris@843
|
510 cerr << "LADSPAPluginFactory::loadLibrary: Failed to locate plugin library \"" << soName << "\"" << endl;
|
Chris@0
|
511 }
|
Chris@0
|
512
|
Chris@0
|
513 void
|
Chris@0
|
514 LADSPAPluginFactory::unloadLibrary(QString soName)
|
Chris@0
|
515 {
|
Chris@0
|
516 LibraryHandleMap::iterator li = m_libraryHandles.find(soName);
|
Chris@0
|
517 if (li != m_libraryHandles.end()) {
|
Chris@1429
|
518 // SVDEBUG << "unloading " << soname << endl;
|
Chris@1429
|
519 DLCLOSE(m_libraryHandles[soName]);
|
Chris@1429
|
520 m_libraryHandles.erase(li);
|
Chris@0
|
521 }
|
Chris@0
|
522 }
|
Chris@0
|
523
|
Chris@0
|
524 void
|
Chris@0
|
525 LADSPAPluginFactory::unloadUnusedLibraries()
|
Chris@0
|
526 {
|
Chris@0
|
527 std::vector<QString> toUnload;
|
Chris@0
|
528
|
Chris@0
|
529 for (LibraryHandleMap::iterator i = m_libraryHandles.begin();
|
Chris@1429
|
530 i != m_libraryHandles.end(); ++i) {
|
Chris@0
|
531
|
Chris@1429
|
532 bool stillInUse = false;
|
Chris@0
|
533
|
Chris@1429
|
534 for (std::set<RealTimePluginInstance *>::iterator ii = m_instances.begin();
|
Chris@1429
|
535 ii != m_instances.end(); ++ii) {
|
Chris@0
|
536
|
Chris@1429
|
537 QString itype, isoname, ilabel;
|
Chris@1429
|
538 PluginIdentifier::parseIdentifier((*ii)->getPluginIdentifier(), itype, isoname, ilabel);
|
Chris@1429
|
539 if (isoname == i->first) {
|
Chris@1429
|
540 stillInUse = true;
|
Chris@1429
|
541 break;
|
Chris@1429
|
542 }
|
Chris@1429
|
543 }
|
Chris@0
|
544
|
Chris@1429
|
545 if (!stillInUse) toUnload.push_back(i->first);
|
Chris@0
|
546 }
|
Chris@0
|
547
|
Chris@0
|
548 for (std::vector<QString>::iterator i = toUnload.begin();
|
Chris@1429
|
549 i != toUnload.end(); ++i) {
|
Chris@118
|
550 if (*i != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
|
Chris@118
|
551 unloadLibrary(*i);
|
Chris@118
|
552 }
|
Chris@0
|
553 }
|
Chris@0
|
554 }
|
Chris@0
|
555
|
Chris@0
|
556
|
Chris@0
|
557 // It is only later, after they've gone,
|
Chris@0
|
558 // I realize they have delivered a letter.
|
Chris@0
|
559 // It's a letter from my wife. "What are you doing
|
Chris@0
|
560 // there?" my wife asks. "Are you drinking?"
|
Chris@0
|
561 // I study the postmark for hours. Then it, too, begins to fade.
|
Chris@0
|
562 // I hope someday to forget all this.
|
Chris@0
|
563
|
Chris@0
|
564
|
Chris@0
|
565 std::vector<QString>
|
Chris@0
|
566 LADSPAPluginFactory::getPluginPath()
|
Chris@0
|
567 {
|
Chris@0
|
568 std::vector<QString> pathList;
|
Chris@0
|
569 std::string path;
|
Chris@0
|
570
|
Chris@0
|
571 char *cpath = getenv("LADSPA_PATH");
|
Chris@0
|
572 if (cpath) path = cpath;
|
Chris@0
|
573
|
Chris@0
|
574 if (path == "") {
|
Chris@186
|
575
|
Chris@186
|
576 path = DEFAULT_LADSPA_PATH;
|
Chris@186
|
577
|
Chris@1429
|
578 char *home = getenv("HOME");
|
Chris@1429
|
579 if (home) {
|
Chris@186
|
580 std::string::size_type f;
|
Chris@186
|
581 while ((f = path.find("$HOME")) != std::string::npos &&
|
Chris@186
|
582 f < path.length()) {
|
Chris@186
|
583 path.replace(f, 5, home);
|
Chris@186
|
584 }
|
Chris@186
|
585 }
|
Chris@186
|
586
|
Chris@186
|
587 #ifdef _WIN32
|
Chris@1218
|
588 const char *pfiles = getenv("ProgramFiles");
|
Chris@220
|
589 if (!pfiles) pfiles = "C:\\Program Files";
|
Chris@220
|
590 {
|
Chris@186
|
591 std::string::size_type f;
|
Chris@186
|
592 while ((f = path.find("%ProgramFiles%")) != std::string::npos &&
|
Chris@186
|
593 f < path.length()) {
|
Chris@186
|
594 path.replace(f, 14, pfiles);
|
Chris@186
|
595 }
|
Chris@220
|
596 }
|
Chris@186
|
597 #endif
|
Chris@0
|
598 }
|
Chris@0
|
599
|
Chris@0
|
600 std::string::size_type index = 0, newindex = 0;
|
Chris@0
|
601
|
Chris@223
|
602 while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) {
|
Chris@1429
|
603 pathList.push_back(path.substr(index, newindex - index).c_str());
|
Chris@1429
|
604 index = newindex + 1;
|
Chris@0
|
605 }
|
Chris@0
|
606
|
Chris@0
|
607 pathList.push_back(path.substr(index).c_str());
|
Chris@0
|
608
|
Chris@0
|
609 return pathList;
|
Chris@0
|
610 }
|
Chris@0
|
611
|
Chris@0
|
612
|
Chris@0
|
613 std::vector<QString>
|
Chris@0
|
614 LADSPAPluginFactory::getLRDFPath(QString &baseUri)
|
Chris@0
|
615 {
|
Chris@150
|
616 std::vector<QString> lrdfPaths;
|
Chris@150
|
617
|
Chris@150
|
618 #ifdef HAVE_LRDF
|
Chris@0
|
619 std::vector<QString> pathList = getPluginPath();
|
Chris@0
|
620
|
Chris@0
|
621 lrdfPaths.push_back("/usr/local/share/ladspa/rdf");
|
Chris@0
|
622 lrdfPaths.push_back("/usr/share/ladspa/rdf");
|
Chris@0
|
623
|
Chris@0
|
624 for (std::vector<QString>::iterator i = pathList.begin();
|
Chris@1429
|
625 i != pathList.end(); ++i) {
|
Chris@1429
|
626 lrdfPaths.push_back(*i + "/rdf");
|
Chris@0
|
627 }
|
Chris@0
|
628
|
Chris@0
|
629 baseUri = LADSPA_BASE;
|
Chris@953
|
630 #else
|
Chris@953
|
631 baseUri = "";
|
Chris@150
|
632 #endif
|
Chris@150
|
633
|
Chris@0
|
634 return lrdfPaths;
|
Chris@0
|
635 }
|
Chris@0
|
636
|
Chris@0
|
637 void
|
Chris@0
|
638 LADSPAPluginFactory::discoverPlugins()
|
Chris@0
|
639 {
|
Chris@408
|
640 Profiler profiler("LADSPAPluginFactory::discoverPlugins");
|
Chris@408
|
641
|
Chris@0
|
642 std::vector<QString> pathList = getPluginPath();
|
Chris@0
|
643
|
Chris@690
|
644 // SVDEBUG << "LADSPAPluginFactory::discoverPlugins - "
|
Chris@1429
|
645 // << "discovering plugins; path is ";
|
Chris@259
|
646 // for (std::vector<QString>::iterator i = pathList.begin();
|
Chris@1429
|
647 // i != pathList.end(); ++i) {
|
Chris@1429
|
648 // SVDEBUG << "[" << i-<< "] ";
|
Chris@259
|
649 // }
|
Chris@690
|
650 // SVDEBUG << endl;
|
Chris@0
|
651
|
Chris@35
|
652 #ifdef HAVE_LRDF
|
Chris@166
|
653 // read the description files
|
Chris@0
|
654 //
|
Chris@0
|
655 QString baseUri;
|
Chris@0
|
656 std::vector<QString> lrdfPaths = getLRDFPath(baseUri);
|
Chris@0
|
657
|
Chris@0
|
658 bool haveSomething = false;
|
Chris@0
|
659
|
Chris@0
|
660 for (size_t i = 0; i < lrdfPaths.size(); ++i) {
|
Chris@1429
|
661 QDir dir(lrdfPaths[i], "*.rdf;*.rdfs");
|
Chris@1429
|
662 for (unsigned int j = 0; j < dir.count(); ++j) {
|
Chris@1429
|
663 if (!lrdf_read_file(QString("file:" + lrdfPaths[i] + "/" + dir[j]).toStdString().c_str())) {
|
Chris@1429
|
664 // cerr << "LADSPAPluginFactory: read RDF file " << (lrdfPaths[i] + "/" + dir[j]) << endl;
|
Chris@1429
|
665 haveSomething = true;
|
Chris@1429
|
666 }
|
Chris@1429
|
667 }
|
Chris@0
|
668 }
|
Chris@0
|
669
|
Chris@0
|
670 if (haveSomething) {
|
Chris@1429
|
671 generateTaxonomy(baseUri + "Plugin", "");
|
Chris@0
|
672 }
|
Chris@35
|
673 #endif // HAVE_LRDF
|
Chris@0
|
674
|
Chris@0
|
675 generateFallbackCategories();
|
Chris@0
|
676
|
Chris@1246
|
677 auto candidates =
|
Chris@1179
|
678 PluginScan::getInstance()->getCandidateLibrariesFor(getPluginType());
|
Chris@0
|
679
|
Chris@1246
|
680 for (auto c: candidates) {
|
Chris@1246
|
681 discoverPluginsFrom(c.libraryPath);
|
Chris@0
|
682 }
|
Chris@0
|
683 }
|
Chris@0
|
684
|
Chris@0
|
685 void
|
Chris@929
|
686 LADSPAPluginFactory::discoverPluginsFrom(QString soname)
|
Chris@0
|
687 {
|
Chris@0
|
688 void *libraryHandle = DLOPEN(soname, RTLD_LAZY);
|
Chris@0
|
689
|
Chris@0
|
690 if (!libraryHandle) {
|
Chris@843
|
691 cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: couldn't load plugin library "
|
Chris@843
|
692 << soname << " - " << DLERROR() << endl;
|
Chris@0
|
693 return;
|
Chris@0
|
694 }
|
Chris@0
|
695
|
Chris@0
|
696 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
|
Chris@1429
|
697 DLSYM(libraryHandle, "ladspa_descriptor");
|
Chris@0
|
698
|
Chris@0
|
699 if (!fn) {
|
Chris@1429
|
700 cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: No descriptor function in " << soname << endl;
|
Chris@1429
|
701 return;
|
Chris@0
|
702 }
|
Chris@0
|
703
|
Chris@0
|
704 const LADSPA_Descriptor *descriptor = 0;
|
Chris@0
|
705
|
Chris@0
|
706 int index = 0;
|
Chris@0
|
707 while ((descriptor = fn(index))) {
|
Chris@0
|
708
|
Chris@60
|
709 RealTimePluginDescriptor *rtd = new RealTimePluginDescriptor;
|
Chris@60
|
710 rtd->name = descriptor->Name;
|
Chris@60
|
711 rtd->label = descriptor->Label;
|
Chris@60
|
712 rtd->maker = descriptor->Maker;
|
Chris@60
|
713 rtd->copyright = descriptor->Copyright;
|
Chris@60
|
714 rtd->category = "";
|
Chris@60
|
715 rtd->isSynth = false;
|
Chris@60
|
716 rtd->parameterCount = 0;
|
Chris@60
|
717 rtd->audioInputPortCount = 0;
|
Chris@166
|
718 rtd->audioOutputPortCount = 0;
|
Chris@60
|
719 rtd->controlOutputPortCount = 0;
|
Chris@60
|
720
|
Chris@1429
|
721 QString identifier = PluginIdentifier::createIdentifier
|
Chris@1429
|
722 ("ladspa", soname, descriptor->Label);
|
Chris@165
|
723
|
Chris@35
|
724 #ifdef HAVE_LRDF
|
Chris@1429
|
725 char *def_uri = 0;
|
Chris@1429
|
726 lrdf_defaults *defs = 0;
|
Chris@1429
|
727
|
Chris@165
|
728 if (m_lrdfTaxonomy[descriptor->UniqueID] != "") {
|
Chris@165
|
729 m_taxonomy[identifier] = m_lrdfTaxonomy[descriptor->UniqueID];
|
Chris@843
|
730 // cerr << "set id \"" << identifier << "\" to cat \"" << m_taxonomy[identifier] << "\" from LRDF" << endl;
|
Chris@843
|
731 // cout << identifier << "::" << m_taxonomy[identifier] << endl;
|
Chris@165
|
732 }
|
Chris@165
|
733
|
Chris@1429
|
734 QString category = m_taxonomy[identifier];
|
Chris@1429
|
735
|
Chris@1429
|
736 if (category == "") {
|
Chris@1429
|
737 std::string name = rtd->name;
|
Chris@1429
|
738 if (name.length() > 4 &&
|
Chris@1429
|
739 name.substr(name.length() - 4) == " VST") {
|
Chris@1429
|
740 category = "VST effects";
|
Chris@1429
|
741 m_taxonomy[identifier] = category;
|
Chris@1429
|
742 }
|
Chris@1429
|
743 }
|
Chris@1429
|
744
|
Chris@60
|
745 rtd->category = category.toStdString();
|
Chris@60
|
746
|
Chris@1429
|
747 // cerr << "Plugin id is " << descriptor->UniqueID
|
Chris@1429
|
748 // << ", category is \"" << (category ? category : QString("(none)"))
|
Chris@1429
|
749 // << "\", name is " << descriptor->Name
|
Chris@1429
|
750 // << ", label is " << descriptor->Label
|
Chris@1429
|
751 // << endl;
|
Chris@1429
|
752
|
Chris@1429
|
753 def_uri = lrdf_get_default_uri(descriptor->UniqueID);
|
Chris@1429
|
754 if (def_uri) {
|
Chris@1429
|
755 defs = lrdf_get_setting_values(def_uri);
|
Chris@1429
|
756 }
|
Chris@0
|
757
|
Chris@1429
|
758 unsigned int controlPortNumber = 1;
|
Chris@1429
|
759
|
Chris@1429
|
760 for (int i = 0; i < (int)descriptor->PortCount; i++) {
|
Chris@1429
|
761
|
Chris@1429
|
762 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
|
Chris@1429
|
763
|
Chris@1429
|
764 if (def_uri && defs) {
|
Chris@1429
|
765
|
Chris@1429
|
766 for (unsigned int j = 0; j < defs->count; j++) {
|
Chris@1429
|
767 if (defs->items[j].pid == controlPortNumber) {
|
Chris@1429
|
768 // cerr << "Default for this port (" << defs->items[j].pid << ", " << defs->items[j].label << ") is " << defs->items[j].value << "; applying this to port number " << i << " with name " << descriptor->PortNames[i] << endl;
|
Chris@1429
|
769 m_portDefaults[descriptor->UniqueID][i] =
|
Chris@1429
|
770 defs->items[j].value;
|
Chris@1429
|
771 }
|
Chris@1429
|
772 }
|
Chris@1429
|
773 }
|
Chris@1429
|
774
|
Chris@1429
|
775 ++controlPortNumber;
|
Chris@1429
|
776 }
|
Chris@1429
|
777 }
|
Chris@35
|
778 #endif // HAVE_LRDF
|
Chris@0
|
779
|
Chris@1429
|
780 for (int i = 0; i < (int)descriptor->PortCount; i++) {
|
Chris@1429
|
781 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
|
Chris@60
|
782 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
|
Chris@60
|
783 ++rtd->parameterCount;
|
Chris@60
|
784 } else {
|
Chris@60
|
785 if (strcmp(descriptor->PortNames[i], "latency") &&
|
Chris@60
|
786 strcmp(descriptor->PortNames[i], "_latency")) {
|
Chris@60
|
787 ++rtd->controlOutputPortCount;
|
Chris@60
|
788 rtd->controlOutputPortNames.push_back
|
Chris@60
|
789 (descriptor->PortNames[i]);
|
Chris@60
|
790 }
|
Chris@60
|
791 }
|
Chris@60
|
792 } else {
|
Chris@60
|
793 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
|
Chris@60
|
794 ++rtd->audioInputPortCount;
|
Chris@166
|
795 } else if (LADSPA_IS_PORT_OUTPUT(descriptor->PortDescriptors[i])) {
|
Chris@166
|
796 ++rtd->audioOutputPortCount;
|
Chris@60
|
797 }
|
Chris@60
|
798 }
|
Chris@60
|
799 }
|
Chris@60
|
800
|
Chris@1429
|
801 m_identifiers.push_back(identifier);
|
Chris@0
|
802
|
Chris@1464
|
803 m_libraries[identifier] = soname;
|
Chris@1464
|
804
|
Chris@60
|
805 m_rtDescriptors[identifier] = rtd;
|
Chris@60
|
806
|
Chris@1429
|
807 ++index;
|
Chris@0
|
808 }
|
Chris@0
|
809
|
Chris@0
|
810 if (DLCLOSE(libraryHandle) != 0) {
|
Chris@843
|
811 cerr << "WARNING: LADSPAPluginFactory::discoverPlugins - can't unload " << libraryHandle << endl;
|
Chris@0
|
812 return;
|
Chris@0
|
813 }
|
Chris@0
|
814 }
|
Chris@0
|
815
|
Chris@0
|
816 void
|
Chris@0
|
817 LADSPAPluginFactory::generateFallbackCategories()
|
Chris@0
|
818 {
|
Chris@0
|
819 std::vector<QString> pluginPath = getPluginPath();
|
Chris@0
|
820 std::vector<QString> path;
|
Chris@0
|
821
|
Chris@0
|
822 for (size_t i = 0; i < pluginPath.size(); ++i) {
|
Chris@1429
|
823 if (pluginPath[i].contains("/lib/")) {
|
Chris@1429
|
824 QString p(pluginPath[i]);
|
Chris@165
|
825 path.push_back(p);
|
Chris@1429
|
826 p.replace("/lib/", "/share/");
|
Chris@1429
|
827 path.push_back(p);
|
Chris@1429
|
828 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: path element " << p << endl;
|
Chris@1429
|
829 }
|
Chris@1429
|
830 path.push_back(pluginPath[i]);
|
Chris@1429
|
831 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: path element " << pluginPath[i] << endl;
|
Chris@0
|
832 }
|
Chris@0
|
833
|
Chris@0
|
834 for (size_t i = 0; i < path.size(); ++i) {
|
Chris@0
|
835
|
Chris@1429
|
836 QDir dir(path[i], "*.cat");
|
Chris@0
|
837
|
Chris@1429
|
838 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i] << " has " << dir.count() << " .cat files" << endl;
|
Chris@1429
|
839 for (unsigned int j = 0; j < dir.count(); ++j) {
|
Chris@0
|
840
|
Chris@1429
|
841 QFile file(path[i] + "/" + dir[j]);
|
Chris@0
|
842
|
Chris@1429
|
843 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i]+ "/" + dir[j]) << endl;
|
Chris@0
|
844
|
Chris@1429
|
845 if (file.open(QIODevice::ReadOnly)) {
|
Chris@1429
|
846 // cerr << "...opened" << endl;
|
Chris@1429
|
847 QTextStream stream(&file);
|
Chris@1429
|
848 QString line;
|
Chris@0
|
849
|
Chris@1429
|
850 while (!stream.atEnd()) {
|
Chris@1429
|
851 line = stream.readLine();
|
Chris@1429
|
852 // cerr << "line is: \"" << line << "\"" << endl;
|
Chris@1429
|
853 QString id = PluginIdentifier::canonicalise
|
Chris@165
|
854 (line.section("::", 0, 0));
|
Chris@1429
|
855 QString cat = line.section("::", 1, 1);
|
Chris@1429
|
856 m_taxonomy[id] = cat;
|
Chris@1429
|
857 // cerr << "set id \"" << id << "\" to cat \"" << cat << "\"" << endl;
|
Chris@1429
|
858 }
|
Chris@1429
|
859 }
|
Chris@1429
|
860 }
|
Chris@0
|
861 }
|
Chris@0
|
862 }
|
Chris@0
|
863
|
Chris@0
|
864 void
|
Chris@0
|
865 LADSPAPluginFactory::generateTaxonomy(QString uri, QString base)
|
Chris@0
|
866 {
|
Chris@35
|
867 #ifdef HAVE_LRDF
|
Chris@0
|
868 lrdf_uris *uris = lrdf_get_instances(uri.toStdString().c_str());
|
Chris@0
|
869
|
Chris@0
|
870 if (uris != NULL) {
|
Chris@1429
|
871 for (unsigned int i = 0; i < uris->count; ++i) {
|
Chris@1429
|
872 m_lrdfTaxonomy[lrdf_get_uid(uris->items[i])] = base;
|
Chris@1429
|
873 }
|
Chris@1429
|
874 lrdf_free_uris(uris);
|
Chris@0
|
875 }
|
Chris@0
|
876
|
Chris@0
|
877 uris = lrdf_get_subclasses(uri.toStdString().c_str());
|
Chris@0
|
878
|
Chris@0
|
879 if (uris != NULL) {
|
Chris@1429
|
880 for (unsigned int i = 0; i < uris->count; ++i) {
|
Chris@1429
|
881 char *label = lrdf_get_label(uris->items[i]);
|
Chris@1429
|
882 generateTaxonomy(uris->items[i],
|
Chris@1429
|
883 base + (base.length() > 0 ? " > " : "") + label);
|
Chris@1429
|
884 }
|
Chris@1429
|
885 lrdf_free_uris(uris);
|
Chris@0
|
886 }
|
Chris@953
|
887 #else
|
Chris@953
|
888 // avoid unused parameter
|
Chris@953
|
889 (void)uri;
|
Chris@953
|
890 (void)base;
|
Chris@0
|
891 #endif
|
Chris@0
|
892 }
|
Chris@0
|
893
|
Chris@165
|
894 QString
|
Chris@165
|
895 LADSPAPluginFactory::getPluginCategory(QString identifier)
|
Chris@165
|
896 {
|
Chris@165
|
897 return m_taxonomy[identifier];
|
Chris@165
|
898 }
|
Chris@0
|
899
|