comparison plugin/LADSPAPluginFactory.cpp @ 1429:48e9f538e6e9

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents 75aefcc9f07d
children 91bb68146dfc
comparison
equal deleted inserted replaced
1428:87ae75da6527 1429:48e9f538e6e9
49 } 49 }
50 50
51 LADSPAPluginFactory::~LADSPAPluginFactory() 51 LADSPAPluginFactory::~LADSPAPluginFactory()
52 { 52 {
53 for (std::set<RealTimePluginInstance *>::iterator i = m_instances.begin(); 53 for (std::set<RealTimePluginInstance *>::iterator i = m_instances.begin();
54 i != m_instances.end(); ++i) { 54 i != m_instances.end(); ++i) {
55 (*i)->setFactory(0); 55 (*i)->setFactory(0);
56 delete *i; 56 delete *i;
57 } 57 }
58 m_instances.clear(); 58 m_instances.clear();
59 unloadUnusedLibraries(); 59 unloadUnusedLibraries();
60 60
61 #ifdef HAVE_LRDF 61 #ifdef HAVE_LRDF
73 LADSPAPluginFactory::enumeratePlugins(std::vector<QString> &list) 73 LADSPAPluginFactory::enumeratePlugins(std::vector<QString> &list)
74 { 74 {
75 Profiler profiler("LADSPAPluginFactory::enumeratePlugins"); 75 Profiler profiler("LADSPAPluginFactory::enumeratePlugins");
76 76
77 for (std::vector<QString>::iterator i = m_identifiers.begin(); 77 for (std::vector<QString>::iterator i = m_identifiers.begin();
78 i != m_identifiers.end(); ++i) { 78 i != m_identifiers.end(); ++i) {
79 79
80 const LADSPA_Descriptor *descriptor = getLADSPADescriptor(*i); 80 const LADSPA_Descriptor *descriptor = getLADSPADescriptor(*i);
81 81
82 if (!descriptor) { 82 if (!descriptor) {
83 cerr << "WARNING: LADSPAPluginFactory::enumeratePlugins: couldn't get descriptor for identifier " << *i << endl; 83 cerr << "WARNING: LADSPAPluginFactory::enumeratePlugins: couldn't get descriptor for identifier " << *i << endl;
84 continue; 84 continue;
85 } 85 }
86 86
87 list.push_back(*i); 87 list.push_back(*i);
88 list.push_back(descriptor->Name); 88 list.push_back(descriptor->Name);
89 list.push_back(QString("%1").arg(descriptor->UniqueID)); 89 list.push_back(QString("%1").arg(descriptor->UniqueID));
90 list.push_back(descriptor->Label); 90 list.push_back(descriptor->Label);
91 list.push_back(descriptor->Maker); 91 list.push_back(descriptor->Maker);
92 list.push_back(descriptor->Copyright); 92 list.push_back(descriptor->Copyright);
93 list.push_back("false"); // is synth 93 list.push_back("false"); // is synth
94 list.push_back("false"); // is grouped 94 list.push_back("false"); // is grouped
95 95
96 if (m_taxonomy.find(*i) != m_taxonomy.end() && m_taxonomy[*i] != "") { 96 if (m_taxonomy.find(*i) != m_taxonomy.end() && m_taxonomy[*i] != "") {
97 // cerr << "LADSPAPluginFactory: cat for " << *i << " found in taxonomy as " << m_taxonomy[descriptor->UniqueID] << endl; 97 // cerr << "LADSPAPluginFactory: cat for " << *i << " found in taxonomy as " << m_taxonomy[descriptor->UniqueID] << endl;
98 list.push_back(m_taxonomy[*i]); 98 list.push_back(m_taxonomy[*i]);
99 } else { 99 } else {
100 list.push_back(""); 100 list.push_back("");
101 // cerr << "LADSPAPluginFactory: cat for " << *i << " not found (despite having " << m_fallbackCategories.size() << " fallbacks)" << endl; 101 // cerr << "LADSPAPluginFactory: cat for " << *i << " not found (despite having " << m_fallbackCategories.size() << " fallbacks)" << endl;
102 102
103 } 103 }
104 104
105 list.push_back(QString("%1").arg(descriptor->PortCount)); 105 list.push_back(QString("%1").arg(descriptor->PortCount));
106 106
107 for (int p = 0; p < (int)descriptor->PortCount; ++p) { 107 for (int p = 0; p < (int)descriptor->PortCount; ++p) {
108 108
109 int type = 0; 109 int type = 0;
110 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) { 110 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) {
111 type |= PortType::Control; 111 type |= PortType::Control;
112 } else { 112 } else {
113 type |= PortType::Audio; 113 type |= PortType::Audio;
114 } 114 }
115 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) { 115 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) {
116 type |= PortType::Input; 116 type |= PortType::Input;
117 } else { 117 } else {
118 type |= PortType::Output; 118 type |= PortType::Output;
119 } 119 }
120 120
121 list.push_back(QString("%1").arg(p)); 121 list.push_back(QString("%1").arg(p));
122 list.push_back(descriptor->PortNames[p]); 122 list.push_back(descriptor->PortNames[p]);
123 list.push_back(QString("%1").arg(type)); 123 list.push_back(QString("%1").arg(type));
124 list.push_back(QString("%1").arg(getPortDisplayHint(descriptor, p))); 124 list.push_back(QString("%1").arg(getPortDisplayHint(descriptor, p)));
125 list.push_back(QString("%1").arg(getPortMinimum(descriptor, p))); 125 list.push_back(QString("%1").arg(getPortMinimum(descriptor, p)));
126 list.push_back(QString("%1").arg(getPortMaximum(descriptor, p))); 126 list.push_back(QString("%1").arg(getPortMaximum(descriptor, p)));
127 list.push_back(QString("%1").arg(getPortDefault(descriptor, p))); 127 list.push_back(QString("%1").arg(getPortDefault(descriptor, p)));
128 } 128 }
129 } 129 }
130 130
131 unloadUnusedLibraries(); 131 unloadUnusedLibraries();
132 } 132 }
133 133
134 const RealTimePluginDescriptor * 134 const RealTimePluginDescriptor *
135 LADSPAPluginFactory::getPluginDescriptor(QString identifier) const 135 LADSPAPluginFactory::getPluginDescriptor(QString identifier) const
136 { 136 {
137 std::map<QString, RealTimePluginDescriptor *>::const_iterator i = 137 std::map<QString, RealTimePluginDescriptor *>::const_iterator i =
138 m_rtDescriptors.find(identifier); 138 m_rtDescriptors.find(identifier);
146 146
147 float 147 float
148 LADSPAPluginFactory::getPortMinimum(const LADSPA_Descriptor *descriptor, int port) 148 LADSPAPluginFactory::getPortMinimum(const LADSPA_Descriptor *descriptor, int port)
149 { 149 {
150 LADSPA_PortRangeHintDescriptor d = 150 LADSPA_PortRangeHintDescriptor d =
151 descriptor->PortRangeHints[port].HintDescriptor; 151 descriptor->PortRangeHints[port].HintDescriptor;
152 152
153 float minimum = 0.f; 153 float minimum = 0.f;
154 154
155 if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) { 155 if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) {
156 float lb = descriptor->PortRangeHints[port].LowerBound; 156 float lb = descriptor->PortRangeHints[port].LowerBound;
157 minimum = lb; 157 minimum = lb;
158 } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) { 158 } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
159 float ub = descriptor->PortRangeHints[port].UpperBound; 159 float ub = descriptor->PortRangeHints[port].UpperBound;
160 minimum = std::min(0.f, ub - 1.f); 160 minimum = std::min(0.f, ub - 1.f);
161 } 161 }
162 162
163 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) { 163 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
164 minimum = float(minimum * m_sampleRate); 164 minimum = float(minimum * m_sampleRate);
165 } 165 }
166 166
167 if (LADSPA_IS_HINT_LOGARITHMIC(d)) { 167 if (LADSPA_IS_HINT_LOGARITHMIC(d)) {
168 if (minimum == 0.f) minimum = 1.f; 168 if (minimum == 0.f) minimum = 1.f;
169 } 169 }
173 173
174 float 174 float
175 LADSPAPluginFactory::getPortMaximum(const LADSPA_Descriptor *descriptor, int port) 175 LADSPAPluginFactory::getPortMaximum(const LADSPA_Descriptor *descriptor, int port)
176 { 176 {
177 LADSPA_PortRangeHintDescriptor d = 177 LADSPA_PortRangeHintDescriptor d =
178 descriptor->PortRangeHints[port].HintDescriptor; 178 descriptor->PortRangeHints[port].HintDescriptor;
179 179
180 float maximum = 1.f; 180 float maximum = 1.f;
181 181
182 if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) { 182 if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
183 float ub = descriptor->PortRangeHints[port].UpperBound; 183 float ub = descriptor->PortRangeHints[port].UpperBound;
184 maximum = ub; 184 maximum = ub;
185 } else { 185 } else {
186 float lb = descriptor->PortRangeHints[port].LowerBound; 186 float lb = descriptor->PortRangeHints[port].LowerBound;
187 maximum = lb + 1.f; 187 maximum = lb + 1.f;
188 } 188 }
189 189
190 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) { 190 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
191 maximum = float(maximum * m_sampleRate); 191 maximum = float(maximum * m_sampleRate);
192 } 192 }
193 193
194 return maximum; 194 return maximum;
195 } 195 }
196 196
200 float minimum = getPortMinimum(descriptor, port); 200 float minimum = getPortMinimum(descriptor, port);
201 float maximum = getPortMaximum(descriptor, port); 201 float maximum = getPortMaximum(descriptor, port);
202 float deft; 202 float deft;
203 203
204 if (m_portDefaults.find(descriptor->UniqueID) != 204 if (m_portDefaults.find(descriptor->UniqueID) !=
205 m_portDefaults.end()) { 205 m_portDefaults.end()) {
206 if (m_portDefaults[descriptor->UniqueID].find(port) != 206 if (m_portDefaults[descriptor->UniqueID].find(port) !=
207 m_portDefaults[descriptor->UniqueID].end()) { 207 m_portDefaults[descriptor->UniqueID].end()) {
208 208
209 deft = m_portDefaults[descriptor->UniqueID][port]; 209 deft = m_portDefaults[descriptor->UniqueID][port];
210 if (deft < minimum) deft = minimum; 210 if (deft < minimum) deft = minimum;
211 if (deft > maximum) deft = maximum; 211 if (deft > maximum) deft = maximum;
212 return deft; 212 return deft;
213 } 213 }
214 } 214 }
215 215
216 LADSPA_PortRangeHintDescriptor d = 216 LADSPA_PortRangeHintDescriptor d =
217 descriptor->PortRangeHints[port].HintDescriptor; 217 descriptor->PortRangeHints[port].HintDescriptor;
218 218
219 bool logarithmic = LADSPA_IS_HINT_LOGARITHMIC(d); 219 bool logarithmic = LADSPA_IS_HINT_LOGARITHMIC(d);
220 220
221 float logmin = 0, logmax = 0; 221 float logmin = 0, logmax = 0;
222 if (logarithmic) { 222 if (logarithmic) {
228 } 228 }
229 229
230 // SVDEBUG << "LADSPAPluginFactory::getPortDefault: hint = " << d << endl; 230 // SVDEBUG << "LADSPAPluginFactory::getPortDefault: hint = " << d << endl;
231 231
232 if (!LADSPA_IS_HINT_HAS_DEFAULT(d)) { 232 if (!LADSPA_IS_HINT_HAS_DEFAULT(d)) {
233 233
234 deft = minimum; 234 deft = minimum;
235 235
236 } else if (LADSPA_IS_HINT_DEFAULT_MINIMUM(d)) { 236 } else if (LADSPA_IS_HINT_DEFAULT_MINIMUM(d)) {
237 237
238 deft = minimum; 238 deft = minimum;
239 239
240 } else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) { 240 } else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) {
241 241
242 if (logarithmic) { 242 if (logarithmic) {
243 deft = powf(10, logmin * 0.75f + logmax * 0.25f); 243 deft = powf(10, logmin * 0.75f + logmax * 0.25f);
244 } else { 244 } else {
245 deft = minimum * 0.75f + maximum * 0.25f; 245 deft = minimum * 0.75f + maximum * 0.25f;
246 } 246 }
247 247
248 } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) { 248 } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) {
249 249
250 if (logarithmic) { 250 if (logarithmic) {
251 deft = powf(10, logmin * 0.5f + logmax * 0.5f); 251 deft = powf(10, logmin * 0.5f + logmax * 0.5f);
252 } else { 252 } else {
253 deft = minimum * 0.5f + maximum * 0.5f; 253 deft = minimum * 0.5f + maximum * 0.5f;
254 } 254 }
255 255
256 } else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) { 256 } else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) {
257 257
258 if (logarithmic) { 258 if (logarithmic) {
259 deft = powf(10, logmin * 0.25f + logmax * 0.75f); 259 deft = powf(10, logmin * 0.25f + logmax * 0.75f);
260 } else { 260 } else {
261 deft = minimum * 0.25f + maximum * 0.75f; 261 deft = minimum * 0.25f + maximum * 0.75f;
262 } 262 }
263 263
264 } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(d)) { 264 } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(d)) {
265 265
266 deft = maximum; 266 deft = maximum;
267 267
268 } else if (LADSPA_IS_HINT_DEFAULT_0(d)) { 268 } else if (LADSPA_IS_HINT_DEFAULT_0(d)) {
269 269
270 deft = 0.0; 270 deft = 0.0;
271 271
272 } else if (LADSPA_IS_HINT_DEFAULT_1(d)) { 272 } else if (LADSPA_IS_HINT_DEFAULT_1(d)) {
273 273
274 deft = 1.0; 274 deft = 1.0;
275 275
276 } else if (LADSPA_IS_HINT_DEFAULT_100(d)) { 276 } else if (LADSPA_IS_HINT_DEFAULT_100(d)) {
277 277
278 deft = 100.0; 278 deft = 100.0;
279 279
280 } else if (LADSPA_IS_HINT_DEFAULT_440(d)) { 280 } else if (LADSPA_IS_HINT_DEFAULT_440(d)) {
281 281
282 // deft = 440.0; 282 // deft = 440.0;
283 deft = (float)Preferences::getInstance()->getTuningFrequency(); 283 deft = (float)Preferences::getInstance()->getTuningFrequency();
284 284
285 } else { 285 } else {
286 286
287 deft = minimum; 287 deft = minimum;
288 } 288 }
289 289
290 //!!! No -- the min and max have already been multiplied by the rate, 290 //!!! No -- the min and max have already been multiplied by the rate,
291 //so it would happen twice if we did it here -- and e.g. DEFAULT_440 291 //so it would happen twice if we did it here -- and e.g. DEFAULT_440
292 //doesn't want to be multiplied by the rate either 292 //doesn't want to be multiplied by the rate either
293 293
294 // if (LADSPA_IS_HINT_SAMPLE_RATE(d)) { 294 // if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
295 // deft *= m_sampleRate; 295 // deft *= m_sampleRate;
296 // } 296 // }
297 297
298 return deft; 298 return deft;
299 } 299 }
300 300
314 314
315 int 315 int
316 LADSPAPluginFactory::getPortDisplayHint(const LADSPA_Descriptor *descriptor, int port) 316 LADSPAPluginFactory::getPortDisplayHint(const LADSPA_Descriptor *descriptor, int port)
317 { 317 {
318 LADSPA_PortRangeHintDescriptor d = 318 LADSPA_PortRangeHintDescriptor d =
319 descriptor->PortRangeHints[port].HintDescriptor; 319 descriptor->PortRangeHints[port].HintDescriptor;
320 int hint = PortHint::NoHint; 320 int hint = PortHint::NoHint;
321 321
322 if (LADSPA_IS_HINT_TOGGLED(d)) hint |= PortHint::Toggled; 322 if (LADSPA_IS_HINT_TOGGLED(d)) hint |= PortHint::Toggled;
323 if (LADSPA_IS_HINT_INTEGER(d)) hint |= PortHint::Integer; 323 if (LADSPA_IS_HINT_INTEGER(d)) hint |= PortHint::Integer;
324 if (LADSPA_IS_HINT_LOGARITHMIC(d)) hint |= PortHint::Logarithmic; 324 if (LADSPA_IS_HINT_LOGARITHMIC(d)) hint |= PortHint::Logarithmic;
327 } 327 }
328 328
329 329
330 RealTimePluginInstance * 330 RealTimePluginInstance *
331 LADSPAPluginFactory::instantiatePlugin(QString identifier, 331 LADSPAPluginFactory::instantiatePlugin(QString identifier,
332 int instrument, 332 int instrument,
333 int position, 333 int position,
334 sv_samplerate_t sampleRate, 334 sv_samplerate_t sampleRate,
335 int blockSize, 335 int blockSize,
336 int channels) 336 int channels)
337 { 337 {
338 Profiler profiler("LADSPAPluginFactory::instantiatePlugin"); 338 Profiler profiler("LADSPAPluginFactory::instantiatePlugin");
339 339
340 const LADSPA_Descriptor *descriptor = getLADSPADescriptor(identifier); 340 const LADSPA_Descriptor *descriptor = getLADSPADescriptor(identifier);
341 341
342 if (descriptor) { 342 if (descriptor) {
343 343
344 LADSPAPluginInstance *instance = 344 LADSPAPluginInstance *instance =
345 new LADSPAPluginInstance 345 new LADSPAPluginInstance
346 (this, instrument, identifier, position, sampleRate, blockSize, channels, 346 (this, instrument, identifier, position, sampleRate, blockSize, channels,
347 descriptor); 347 descriptor);
348 348
349 m_instances.insert(instance); 349 m_instances.insert(instance);
350 350
351 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 351 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
352 SVDEBUG << "LADSPAPluginFactory::instantiatePlugin(" 352 SVDEBUG << "LADSPAPluginFactory::instantiatePlugin("
353 << identifier << ": now have " << m_instances.size() << " instances" << endl; 353 << identifier << ": now have " << m_instances.size() << " instances" << endl;
354 #endif 354 #endif
355 355
356 return instance; 356 return instance;
357 } 357 }
358 358
359 return 0; 359 return 0;
360 } 360 }
361 361
362 void 362 void
363 LADSPAPluginFactory::releasePlugin(RealTimePluginInstance *instance, 363 LADSPAPluginFactory::releasePlugin(RealTimePluginInstance *instance,
364 QString identifier) 364 QString identifier)
365 { 365 {
366 Profiler profiler("LADSPAPluginFactory::releasePlugin"); 366 Profiler profiler("LADSPAPluginFactory::releasePlugin");
367 367
368 if (m_instances.find(instance) == m_instances.end()) { 368 if (m_instances.find(instance) == m_instances.end()) {
369 cerr << "WARNING: LADSPAPluginFactory::releasePlugin: Not one of mine!" 369 cerr << "WARNING: LADSPAPluginFactory::releasePlugin: Not one of mine!"
370 << endl; 370 << endl;
371 return; 371 return;
372 } 372 }
373 373
374 QString type, soname, label; 374 QString type, soname, label;
375 PluginIdentifier::parseIdentifier(identifier, type, soname, label); 375 PluginIdentifier::parseIdentifier(identifier, type, soname, label);
376 376
377 m_instances.erase(instance); 377 m_instances.erase(instance);
378 378
379 bool stillInUse = false; 379 bool stillInUse = false;
380 380
381 for (std::set<RealTimePluginInstance *>::iterator ii = m_instances.begin(); 381 for (std::set<RealTimePluginInstance *>::iterator ii = m_instances.begin();
382 ii != m_instances.end(); ++ii) { 382 ii != m_instances.end(); ++ii) {
383 QString itype, isoname, ilabel; 383 QString itype, isoname, ilabel;
384 PluginIdentifier::parseIdentifier((*ii)->getPluginIdentifier(), itype, isoname, ilabel); 384 PluginIdentifier::parseIdentifier((*ii)->getPluginIdentifier(), itype, isoname, ilabel);
385 if (isoname == soname) { 385 if (isoname == soname) {
386 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 386 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
387 SVDEBUG << "LADSPAPluginFactory::releasePlugin: dll " << soname << " is still in use for plugin " << ilabel << endl; 387 SVDEBUG << "LADSPAPluginFactory::releasePlugin: dll " << soname << " is still in use for plugin " << ilabel << endl;
388 #endif 388 #endif
389 stillInUse = true; 389 stillInUse = true;
390 break; 390 break;
391 } 391 }
392 } 392 }
393 393
394 if (!stillInUse) { 394 if (!stillInUse) {
395 if (soname != PluginIdentifier::BUILTIN_PLUGIN_SONAME) { 395 if (soname != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
396 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 396 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
411 { 411 {
412 QString type, soname, label; 412 QString type, soname, label;
413 PluginIdentifier::parseIdentifier(identifier, type, soname, label); 413 PluginIdentifier::parseIdentifier(identifier, type, soname, label);
414 414
415 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { 415 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) {
416 loadLibrary(soname); 416 loadLibrary(soname);
417 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { 417 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) {
418 cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: loadLibrary failed for " << soname << endl; 418 cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: loadLibrary failed for " << soname << endl;
419 return 0; 419 return 0;
420 } 420 }
421 } 421 }
422 422
423 void *libraryHandle = m_libraryHandles[soname]; 423 void *libraryHandle = m_libraryHandles[soname];
424 424
425 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function) 425 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
426 DLSYM(libraryHandle, "ladspa_descriptor"); 426 DLSYM(libraryHandle, "ladspa_descriptor");
427 427
428 if (!fn) { 428 if (!fn) {
429 cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No descriptor function in library " << soname << endl; 429 cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No descriptor function in library " << soname << endl;
430 return 0; 430 return 0;
431 } 431 }
432 432
433 const LADSPA_Descriptor *descriptor = 0; 433 const LADSPA_Descriptor *descriptor = 0;
434 434
435 int index = 0; 435 int index = 0;
436 while ((descriptor = fn(index))) { 436 while ((descriptor = fn(index))) {
437 if (descriptor->Label == label) return descriptor; 437 if (descriptor->Label == label) return descriptor;
438 ++index; 438 ++index;
439 } 439 }
440 440
441 cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No such plugin as " << label << " in library " << soname << endl; 441 cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No such plugin as " << label << " in library " << soname << endl;
442 442
443 return 0; 443 return 0;
463 463
464 QString fileName = QFile(soName).fileName(); 464 QString fileName = QFile(soName).fileName();
465 QString base = QFileInfo(soName).baseName(); 465 QString base = QFileInfo(soName).baseName();
466 466
467 for (std::vector<QString>::iterator i = pathList.begin(); 467 for (std::vector<QString>::iterator i = pathList.begin();
468 i != pathList.end(); ++i) { 468 i != pathList.end(); ++i) {
469 469
470 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 470 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
471 SVDEBUG << "Looking at: " << (*i) << endl; 471 SVDEBUG << "Looking at: " << (*i) << endl;
472 #endif 472 #endif
473 473
484 m_libraryHandles[soName] = libraryHandle; 484 m_libraryHandles[soName] = libraryHandle;
485 return; 485 return;
486 } 486 }
487 } 487 }
488 488
489 for (unsigned int j = 0; j < dir.count(); ++j) { 489 for (unsigned int j = 0; j < dir.count(); ++j) {
490 QString file = dir.filePath(dir[j]); 490 QString file = dir.filePath(dir[j]);
491 if (QFileInfo(file).baseName() == base) { 491 if (QFileInfo(file).baseName() == base) {
492 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 492 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
493 cerr << "Loading: " << file << endl; 493 cerr << "Loading: " << file << endl;
494 #endif 494 #endif
507 void 507 void
508 LADSPAPluginFactory::unloadLibrary(QString soName) 508 LADSPAPluginFactory::unloadLibrary(QString soName)
509 { 509 {
510 LibraryHandleMap::iterator li = m_libraryHandles.find(soName); 510 LibraryHandleMap::iterator li = m_libraryHandles.find(soName);
511 if (li != m_libraryHandles.end()) { 511 if (li != m_libraryHandles.end()) {
512 // SVDEBUG << "unloading " << soname << endl; 512 // SVDEBUG << "unloading " << soname << endl;
513 DLCLOSE(m_libraryHandles[soName]); 513 DLCLOSE(m_libraryHandles[soName]);
514 m_libraryHandles.erase(li); 514 m_libraryHandles.erase(li);
515 } 515 }
516 } 516 }
517 517
518 void 518 void
519 LADSPAPluginFactory::unloadUnusedLibraries() 519 LADSPAPluginFactory::unloadUnusedLibraries()
520 { 520 {
521 std::vector<QString> toUnload; 521 std::vector<QString> toUnload;
522 522
523 for (LibraryHandleMap::iterator i = m_libraryHandles.begin(); 523 for (LibraryHandleMap::iterator i = m_libraryHandles.begin();
524 i != m_libraryHandles.end(); ++i) { 524 i != m_libraryHandles.end(); ++i) {
525 525
526 bool stillInUse = false; 526 bool stillInUse = false;
527 527
528 for (std::set<RealTimePluginInstance *>::iterator ii = m_instances.begin(); 528 for (std::set<RealTimePluginInstance *>::iterator ii = m_instances.begin();
529 ii != m_instances.end(); ++ii) { 529 ii != m_instances.end(); ++ii) {
530 530
531 QString itype, isoname, ilabel; 531 QString itype, isoname, ilabel;
532 PluginIdentifier::parseIdentifier((*ii)->getPluginIdentifier(), itype, isoname, ilabel); 532 PluginIdentifier::parseIdentifier((*ii)->getPluginIdentifier(), itype, isoname, ilabel);
533 if (isoname == i->first) { 533 if (isoname == i->first) {
534 stillInUse = true; 534 stillInUse = true;
535 break; 535 break;
536 } 536 }
537 } 537 }
538 538
539 if (!stillInUse) toUnload.push_back(i->first); 539 if (!stillInUse) toUnload.push_back(i->first);
540 } 540 }
541 541
542 for (std::vector<QString>::iterator i = toUnload.begin(); 542 for (std::vector<QString>::iterator i = toUnload.begin();
543 i != toUnload.end(); ++i) { 543 i != toUnload.end(); ++i) {
544 if (*i != PluginIdentifier::BUILTIN_PLUGIN_SONAME) { 544 if (*i != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
545 unloadLibrary(*i); 545 unloadLibrary(*i);
546 } 546 }
547 } 547 }
548 } 548 }
567 567
568 if (path == "") { 568 if (path == "") {
569 569
570 path = DEFAULT_LADSPA_PATH; 570 path = DEFAULT_LADSPA_PATH;
571 571
572 char *home = getenv("HOME"); 572 char *home = getenv("HOME");
573 if (home) { 573 if (home) {
574 std::string::size_type f; 574 std::string::size_type f;
575 while ((f = path.find("$HOME")) != std::string::npos && 575 while ((f = path.find("$HOME")) != std::string::npos &&
576 f < path.length()) { 576 f < path.length()) {
577 path.replace(f, 5, home); 577 path.replace(f, 5, home);
578 } 578 }
592 } 592 }
593 593
594 std::string::size_type index = 0, newindex = 0; 594 std::string::size_type index = 0, newindex = 0;
595 595
596 while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) { 596 while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) {
597 pathList.push_back(path.substr(index, newindex - index).c_str()); 597 pathList.push_back(path.substr(index, newindex - index).c_str());
598 index = newindex + 1; 598 index = newindex + 1;
599 } 599 }
600 600
601 pathList.push_back(path.substr(index).c_str()); 601 pathList.push_back(path.substr(index).c_str());
602 602
603 return pathList; 603 return pathList;
614 614
615 lrdfPaths.push_back("/usr/local/share/ladspa/rdf"); 615 lrdfPaths.push_back("/usr/local/share/ladspa/rdf");
616 lrdfPaths.push_back("/usr/share/ladspa/rdf"); 616 lrdfPaths.push_back("/usr/share/ladspa/rdf");
617 617
618 for (std::vector<QString>::iterator i = pathList.begin(); 618 for (std::vector<QString>::iterator i = pathList.begin();
619 i != pathList.end(); ++i) { 619 i != pathList.end(); ++i) {
620 lrdfPaths.push_back(*i + "/rdf"); 620 lrdfPaths.push_back(*i + "/rdf");
621 } 621 }
622 622
623 baseUri = LADSPA_BASE; 623 baseUri = LADSPA_BASE;
624 #else 624 #else
625 baseUri = ""; 625 baseUri = "";
634 Profiler profiler("LADSPAPluginFactory::discoverPlugins"); 634 Profiler profiler("LADSPAPluginFactory::discoverPlugins");
635 635
636 std::vector<QString> pathList = getPluginPath(); 636 std::vector<QString> pathList = getPluginPath();
637 637
638 // SVDEBUG << "LADSPAPluginFactory::discoverPlugins - " 638 // SVDEBUG << "LADSPAPluginFactory::discoverPlugins - "
639 // << "discovering plugins; path is "; 639 // << "discovering plugins; path is ";
640 // for (std::vector<QString>::iterator i = pathList.begin(); 640 // for (std::vector<QString>::iterator i = pathList.begin();
641 // i != pathList.end(); ++i) { 641 // i != pathList.end(); ++i) {
642 // SVDEBUG << "[" << i-<< "] "; 642 // SVDEBUG << "[" << i-<< "] ";
643 // } 643 // }
644 // SVDEBUG << endl; 644 // SVDEBUG << endl;
645 645
646 #ifdef HAVE_LRDF 646 #ifdef HAVE_LRDF
647 // read the description files 647 // read the description files
650 std::vector<QString> lrdfPaths = getLRDFPath(baseUri); 650 std::vector<QString> lrdfPaths = getLRDFPath(baseUri);
651 651
652 bool haveSomething = false; 652 bool haveSomething = false;
653 653
654 for (size_t i = 0; i < lrdfPaths.size(); ++i) { 654 for (size_t i = 0; i < lrdfPaths.size(); ++i) {
655 QDir dir(lrdfPaths[i], "*.rdf;*.rdfs"); 655 QDir dir(lrdfPaths[i], "*.rdf;*.rdfs");
656 for (unsigned int j = 0; j < dir.count(); ++j) { 656 for (unsigned int j = 0; j < dir.count(); ++j) {
657 if (!lrdf_read_file(QString("file:" + lrdfPaths[i] + "/" + dir[j]).toStdString().c_str())) { 657 if (!lrdf_read_file(QString("file:" + lrdfPaths[i] + "/" + dir[j]).toStdString().c_str())) {
658 // cerr << "LADSPAPluginFactory: read RDF file " << (lrdfPaths[i] + "/" + dir[j]) << endl; 658 // cerr << "LADSPAPluginFactory: read RDF file " << (lrdfPaths[i] + "/" + dir[j]) << endl;
659 haveSomething = true; 659 haveSomething = true;
660 } 660 }
661 } 661 }
662 } 662 }
663 663
664 if (haveSomething) { 664 if (haveSomething) {
665 generateTaxonomy(baseUri + "Plugin", ""); 665 generateTaxonomy(baseUri + "Plugin", "");
666 } 666 }
667 #endif // HAVE_LRDF 667 #endif // HAVE_LRDF
668 668
669 generateFallbackCategories(); 669 generateFallbackCategories();
670 670
686 << soname << " - " << DLERROR() << endl; 686 << soname << " - " << DLERROR() << endl;
687 return; 687 return;
688 } 688 }
689 689
690 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function) 690 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
691 DLSYM(libraryHandle, "ladspa_descriptor"); 691 DLSYM(libraryHandle, "ladspa_descriptor");
692 692
693 if (!fn) { 693 if (!fn) {
694 cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: No descriptor function in " << soname << endl; 694 cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: No descriptor function in " << soname << endl;
695 return; 695 return;
696 } 696 }
697 697
698 const LADSPA_Descriptor *descriptor = 0; 698 const LADSPA_Descriptor *descriptor = 0;
699 699
700 int index = 0; 700 int index = 0;
710 rtd->parameterCount = 0; 710 rtd->parameterCount = 0;
711 rtd->audioInputPortCount = 0; 711 rtd->audioInputPortCount = 0;
712 rtd->audioOutputPortCount = 0; 712 rtd->audioOutputPortCount = 0;
713 rtd->controlOutputPortCount = 0; 713 rtd->controlOutputPortCount = 0;
714 714
715 QString identifier = PluginIdentifier::createIdentifier 715 QString identifier = PluginIdentifier::createIdentifier
716 ("ladspa", soname, descriptor->Label); 716 ("ladspa", soname, descriptor->Label);
717 717
718 #ifdef HAVE_LRDF 718 #ifdef HAVE_LRDF
719 char *def_uri = 0; 719 char *def_uri = 0;
720 lrdf_defaults *defs = 0; 720 lrdf_defaults *defs = 0;
721 721
722 if (m_lrdfTaxonomy[descriptor->UniqueID] != "") { 722 if (m_lrdfTaxonomy[descriptor->UniqueID] != "") {
723 m_taxonomy[identifier] = m_lrdfTaxonomy[descriptor->UniqueID]; 723 m_taxonomy[identifier] = m_lrdfTaxonomy[descriptor->UniqueID];
724 // cerr << "set id \"" << identifier << "\" to cat \"" << m_taxonomy[identifier] << "\" from LRDF" << endl; 724 // cerr << "set id \"" << identifier << "\" to cat \"" << m_taxonomy[identifier] << "\" from LRDF" << endl;
725 // cout << identifier << "::" << m_taxonomy[identifier] << endl; 725 // cout << identifier << "::" << m_taxonomy[identifier] << endl;
726 } 726 }
727 727
728 QString category = m_taxonomy[identifier]; 728 QString category = m_taxonomy[identifier];
729 729
730 if (category == "") { 730 if (category == "") {
731 std::string name = rtd->name; 731 std::string name = rtd->name;
732 if (name.length() > 4 && 732 if (name.length() > 4 &&
733 name.substr(name.length() - 4) == " VST") { 733 name.substr(name.length() - 4) == " VST") {
734 category = "VST effects"; 734 category = "VST effects";
735 m_taxonomy[identifier] = category; 735 m_taxonomy[identifier] = category;
736 } 736 }
737 } 737 }
738 738
739 rtd->category = category.toStdString(); 739 rtd->category = category.toStdString();
740 740
741 // cerr << "Plugin id is " << descriptor->UniqueID 741 // cerr << "Plugin id is " << descriptor->UniqueID
742 // << ", category is \"" << (category ? category : QString("(none)")) 742 // << ", category is \"" << (category ? category : QString("(none)"))
743 // << "\", name is " << descriptor->Name 743 // << "\", name is " << descriptor->Name
744 // << ", label is " << descriptor->Label 744 // << ", label is " << descriptor->Label
745 // << endl; 745 // << endl;
746 746
747 def_uri = lrdf_get_default_uri(descriptor->UniqueID); 747 def_uri = lrdf_get_default_uri(descriptor->UniqueID);
748 if (def_uri) { 748 if (def_uri) {
749 defs = lrdf_get_setting_values(def_uri); 749 defs = lrdf_get_setting_values(def_uri);
750 } 750 }
751 751
752 unsigned int controlPortNumber = 1; 752 unsigned int controlPortNumber = 1;
753 753
754 for (int i = 0; i < (int)descriptor->PortCount; i++) { 754 for (int i = 0; i < (int)descriptor->PortCount; i++) {
755 755
756 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) { 756 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
757 757
758 if (def_uri && defs) { 758 if (def_uri && defs) {
759 759
760 for (unsigned int j = 0; j < defs->count; j++) { 760 for (unsigned int j = 0; j < defs->count; j++) {
761 if (defs->items[j].pid == controlPortNumber) { 761 if (defs->items[j].pid == controlPortNumber) {
762 // 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; 762 // 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;
763 m_portDefaults[descriptor->UniqueID][i] = 763 m_portDefaults[descriptor->UniqueID][i] =
764 defs->items[j].value; 764 defs->items[j].value;
765 } 765 }
766 } 766 }
767 } 767 }
768 768
769 ++controlPortNumber; 769 ++controlPortNumber;
770 } 770 }
771 } 771 }
772 #endif // HAVE_LRDF 772 #endif // HAVE_LRDF
773 773
774 for (int i = 0; i < (int)descriptor->PortCount; i++) { 774 for (int i = 0; i < (int)descriptor->PortCount; i++) {
775 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) { 775 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
776 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) { 776 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
777 ++rtd->parameterCount; 777 ++rtd->parameterCount;
778 } else { 778 } else {
779 if (strcmp(descriptor->PortNames[i], "latency") && 779 if (strcmp(descriptor->PortNames[i], "latency") &&
780 strcmp(descriptor->PortNames[i], "_latency")) { 780 strcmp(descriptor->PortNames[i], "_latency")) {
790 ++rtd->audioOutputPortCount; 790 ++rtd->audioOutputPortCount;
791 } 791 }
792 } 792 }
793 } 793 }
794 794
795 m_identifiers.push_back(identifier); 795 m_identifiers.push_back(identifier);
796 796
797 m_rtDescriptors[identifier] = rtd; 797 m_rtDescriptors[identifier] = rtd;
798 798
799 ++index; 799 ++index;
800 } 800 }
801 801
802 if (DLCLOSE(libraryHandle) != 0) { 802 if (DLCLOSE(libraryHandle) != 0) {
803 cerr << "WARNING: LADSPAPluginFactory::discoverPlugins - can't unload " << libraryHandle << endl; 803 cerr << "WARNING: LADSPAPluginFactory::discoverPlugins - can't unload " << libraryHandle << endl;
804 return; 804 return;
810 { 810 {
811 std::vector<QString> pluginPath = getPluginPath(); 811 std::vector<QString> pluginPath = getPluginPath();
812 std::vector<QString> path; 812 std::vector<QString> path;
813 813
814 for (size_t i = 0; i < pluginPath.size(); ++i) { 814 for (size_t i = 0; i < pluginPath.size(); ++i) {
815 if (pluginPath[i].contains("/lib/")) { 815 if (pluginPath[i].contains("/lib/")) {
816 QString p(pluginPath[i]); 816 QString p(pluginPath[i]);
817 path.push_back(p); 817 path.push_back(p);
818 p.replace("/lib/", "/share/"); 818 p.replace("/lib/", "/share/");
819 path.push_back(p); 819 path.push_back(p);
820 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: path element " << p << endl; 820 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: path element " << p << endl;
821 } 821 }
822 path.push_back(pluginPath[i]); 822 path.push_back(pluginPath[i]);
823 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: path element " << pluginPath[i] << endl; 823 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: path element " << pluginPath[i] << endl;
824 } 824 }
825 825
826 for (size_t i = 0; i < path.size(); ++i) { 826 for (size_t i = 0; i < path.size(); ++i) {
827 827
828 QDir dir(path[i], "*.cat"); 828 QDir dir(path[i], "*.cat");
829 829
830 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i] << " has " << dir.count() << " .cat files" << endl; 830 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i] << " has " << dir.count() << " .cat files" << endl;
831 for (unsigned int j = 0; j < dir.count(); ++j) { 831 for (unsigned int j = 0; j < dir.count(); ++j) {
832 832
833 QFile file(path[i] + "/" + dir[j]); 833 QFile file(path[i] + "/" + dir[j]);
834 834
835 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i]+ "/" + dir[j]) << endl; 835 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i]+ "/" + dir[j]) << endl;
836 836
837 if (file.open(QIODevice::ReadOnly)) { 837 if (file.open(QIODevice::ReadOnly)) {
838 // cerr << "...opened" << endl; 838 // cerr << "...opened" << endl;
839 QTextStream stream(&file); 839 QTextStream stream(&file);
840 QString line; 840 QString line;
841 841
842 while (!stream.atEnd()) { 842 while (!stream.atEnd()) {
843 line = stream.readLine(); 843 line = stream.readLine();
844 // cerr << "line is: \"" << line << "\"" << endl; 844 // cerr << "line is: \"" << line << "\"" << endl;
845 QString id = PluginIdentifier::canonicalise 845 QString id = PluginIdentifier::canonicalise
846 (line.section("::", 0, 0)); 846 (line.section("::", 0, 0));
847 QString cat = line.section("::", 1, 1); 847 QString cat = line.section("::", 1, 1);
848 m_taxonomy[id] = cat; 848 m_taxonomy[id] = cat;
849 // cerr << "set id \"" << id << "\" to cat \"" << cat << "\"" << endl; 849 // cerr << "set id \"" << id << "\" to cat \"" << cat << "\"" << endl;
850 } 850 }
851 } 851 }
852 } 852 }
853 } 853 }
854 } 854 }
855 855
856 void 856 void
857 LADSPAPluginFactory::generateTaxonomy(QString uri, QString base) 857 LADSPAPluginFactory::generateTaxonomy(QString uri, QString base)
858 { 858 {
859 #ifdef HAVE_LRDF 859 #ifdef HAVE_LRDF
860 lrdf_uris *uris = lrdf_get_instances(uri.toStdString().c_str()); 860 lrdf_uris *uris = lrdf_get_instances(uri.toStdString().c_str());
861 861
862 if (uris != NULL) { 862 if (uris != NULL) {
863 for (unsigned int i = 0; i < uris->count; ++i) { 863 for (unsigned int i = 0; i < uris->count; ++i) {
864 m_lrdfTaxonomy[lrdf_get_uid(uris->items[i])] = base; 864 m_lrdfTaxonomy[lrdf_get_uid(uris->items[i])] = base;
865 } 865 }
866 lrdf_free_uris(uris); 866 lrdf_free_uris(uris);
867 } 867 }
868 868
869 uris = lrdf_get_subclasses(uri.toStdString().c_str()); 869 uris = lrdf_get_subclasses(uri.toStdString().c_str());
870 870
871 if (uris != NULL) { 871 if (uris != NULL) {
872 for (unsigned int i = 0; i < uris->count; ++i) { 872 for (unsigned int i = 0; i < uris->count; ++i) {
873 char *label = lrdf_get_label(uris->items[i]); 873 char *label = lrdf_get_label(uris->items[i]);
874 generateTaxonomy(uris->items[i], 874 generateTaxonomy(uris->items[i],
875 base + (base.length() > 0 ? " > " : "") + label); 875 base + (base.length() > 0 ? " > " : "") + label);
876 } 876 }
877 lrdf_free_uris(uris); 877 lrdf_free_uris(uris);
878 } 878 }
879 #else 879 #else
880 // avoid unused parameter 880 // avoid unused parameter
881 (void)uri; 881 (void)uri;
882 (void)base; 882 (void)base;