Mercurial > hg > svcore
comparison plugin/DSSIPluginFactory.cpp @ 1429:48e9f538e6e9
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | 6b847a59d908 |
children | 91bb68146dfc |
comparison
equal
deleted
inserted
replaced
1428:87ae75da6527 | 1429:48e9f538e6e9 |
---|---|
59 DSSIPluginFactory::enumeratePlugins(std::vector<QString> &list) | 59 DSSIPluginFactory::enumeratePlugins(std::vector<QString> &list) |
60 { | 60 { |
61 Profiler profiler("DSSIPluginFactory::enumeratePlugins"); | 61 Profiler profiler("DSSIPluginFactory::enumeratePlugins"); |
62 | 62 |
63 for (std::vector<QString>::iterator i = m_identifiers.begin(); | 63 for (std::vector<QString>::iterator i = m_identifiers.begin(); |
64 i != m_identifiers.end(); ++i) { | 64 i != m_identifiers.end(); ++i) { |
65 | 65 |
66 const DSSI_Descriptor *ddesc = getDSSIDescriptor(*i); | 66 const DSSI_Descriptor *ddesc = getDSSIDescriptor(*i); |
67 if (!ddesc) continue; | 67 if (!ddesc) continue; |
68 | 68 |
69 const LADSPA_Descriptor *descriptor = ddesc->LADSPA_Plugin; | 69 const LADSPA_Descriptor *descriptor = ddesc->LADSPA_Plugin; |
70 if (!descriptor) continue; | 70 if (!descriptor) continue; |
71 | 71 |
72 // SVDEBUG << "DSSIPluginFactory::enumeratePlugins: Name " << (descriptor->Name ? descriptor->Name : "NONE" ) << endl; | 72 // SVDEBUG << "DSSIPluginFactory::enumeratePlugins: Name " << (descriptor->Name ? descriptor->Name : "NONE" ) << endl; |
73 | 73 |
74 list.push_back(*i); | 74 list.push_back(*i); |
75 list.push_back(descriptor->Name); | 75 list.push_back(descriptor->Name); |
76 list.push_back(QString("%1").arg(descriptor->UniqueID)); | 76 list.push_back(QString("%1").arg(descriptor->UniqueID)); |
77 list.push_back(descriptor->Label); | 77 list.push_back(descriptor->Label); |
78 list.push_back(descriptor->Maker); | 78 list.push_back(descriptor->Maker); |
79 list.push_back(descriptor->Copyright); | 79 list.push_back(descriptor->Copyright); |
80 list.push_back((ddesc->run_synth || ddesc->run_multiple_synths) ? "true" : "false"); | 80 list.push_back((ddesc->run_synth || ddesc->run_multiple_synths) ? "true" : "false"); |
81 list.push_back(ddesc->run_multiple_synths ? "true" : "false"); | 81 list.push_back(ddesc->run_multiple_synths ? "true" : "false"); |
82 list.push_back(m_taxonomy[*i]); | 82 list.push_back(m_taxonomy[*i]); |
83 list.push_back(QString("%1").arg(descriptor->PortCount)); | 83 list.push_back(QString("%1").arg(descriptor->PortCount)); |
84 | 84 |
85 for (int p = 0; p < (int)descriptor->PortCount; ++p) { | 85 for (int p = 0; p < (int)descriptor->PortCount; ++p) { |
86 | 86 |
87 int type = 0; | 87 int type = 0; |
88 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) { | 88 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) { |
89 type |= PortType::Control; | 89 type |= PortType::Control; |
90 } else { | 90 } else { |
91 type |= PortType::Audio; | 91 type |= PortType::Audio; |
92 } | 92 } |
93 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) { | 93 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) { |
94 type |= PortType::Input; | 94 type |= PortType::Input; |
95 } else { | 95 } else { |
96 type |= PortType::Output; | 96 type |= PortType::Output; |
97 } | 97 } |
98 | 98 |
99 list.push_back(QString("%1").arg(p)); | 99 list.push_back(QString("%1").arg(p)); |
100 list.push_back(descriptor->PortNames[p]); | 100 list.push_back(descriptor->PortNames[p]); |
101 list.push_back(QString("%1").arg(type)); | 101 list.push_back(QString("%1").arg(type)); |
102 list.push_back(QString("%1").arg(getPortDisplayHint(descriptor, p))); | 102 list.push_back(QString("%1").arg(getPortDisplayHint(descriptor, p))); |
103 list.push_back(QString("%1").arg(getPortMinimum(descriptor, p))); | 103 list.push_back(QString("%1").arg(getPortMinimum(descriptor, p))); |
104 list.push_back(QString("%1").arg(getPortMaximum(descriptor, p))); | 104 list.push_back(QString("%1").arg(getPortMaximum(descriptor, p))); |
105 list.push_back(QString("%1").arg(getPortDefault(descriptor, p))); | 105 list.push_back(QString("%1").arg(getPortDefault(descriptor, p))); |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 unloadUnusedLibraries(); | 109 unloadUnusedLibraries(); |
110 } | 110 } |
111 | 111 |
112 RealTimePluginInstance * | 112 RealTimePluginInstance * |
113 DSSIPluginFactory::instantiatePlugin(QString identifier, | 113 DSSIPluginFactory::instantiatePlugin(QString identifier, |
114 int instrument, | 114 int instrument, |
115 int position, | 115 int position, |
116 sv_samplerate_t sampleRate, | 116 sv_samplerate_t sampleRate, |
117 int blockSize, | 117 int blockSize, |
118 int channels) | 118 int channels) |
119 { | 119 { |
120 Profiler profiler("DSSIPluginFactory::instantiatePlugin"); | 120 Profiler profiler("DSSIPluginFactory::instantiatePlugin"); |
121 | 121 |
122 const DSSI_Descriptor *descriptor = getDSSIDescriptor(identifier); | 122 const DSSI_Descriptor *descriptor = getDSSIDescriptor(identifier); |
123 | 123 |
124 if (descriptor) { | 124 if (descriptor) { |
125 | 125 |
126 DSSIPluginInstance *instance = | 126 DSSIPluginInstance *instance = |
127 new DSSIPluginInstance | 127 new DSSIPluginInstance |
128 (this, instrument, identifier, position, sampleRate, blockSize, channels, | 128 (this, instrument, identifier, position, sampleRate, blockSize, channels, |
129 descriptor); | 129 descriptor); |
130 | 130 |
131 m_instances.insert(instance); | 131 m_instances.insert(instance); |
132 | 132 |
133 return instance; | 133 return instance; |
134 } | 134 } |
135 | 135 |
136 return 0; | 136 return 0; |
137 } | 137 } |
138 | 138 |
141 { | 141 { |
142 QString type, soname, label; | 142 QString type, soname, label; |
143 PluginIdentifier::parseIdentifier(identifier, type, soname, label); | 143 PluginIdentifier::parseIdentifier(identifier, type, soname, label); |
144 | 144 |
145 if (soname == PluginIdentifier::BUILTIN_PLUGIN_SONAME) { | 145 if (soname == PluginIdentifier::BUILTIN_PLUGIN_SONAME) { |
146 if (label == "sample_player") { | 146 if (label == "sample_player") { |
147 const DSSI_Descriptor *descriptor = SamplePlayer::getDescriptor(0); | 147 const DSSI_Descriptor *descriptor = SamplePlayer::getDescriptor(0); |
148 if (descriptor) { | 148 if (descriptor) { |
149 descriptor->receive_host_descriptor(&m_hostDescriptor); | 149 descriptor->receive_host_descriptor(&m_hostDescriptor); |
150 } | 150 } |
151 return descriptor; | 151 return descriptor; |
152 } else { | 152 } else { |
153 return 0; | 153 return 0; |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 bool firstInLibrary = false; | 157 bool firstInLibrary = false; |
158 | 158 |
159 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { | 159 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { |
160 loadLibrary(soname); | 160 loadLibrary(soname); |
161 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { | 161 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { |
162 cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: loadLibrary failed for " << soname << endl; | 162 cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: loadLibrary failed for " << soname << endl; |
163 return 0; | 163 return 0; |
164 } | 164 } |
165 firstInLibrary = true; | 165 firstInLibrary = true; |
166 } | 166 } |
167 | 167 |
168 void *libraryHandle = m_libraryHandles[soname]; | 168 void *libraryHandle = m_libraryHandles[soname]; |
169 | 169 |
170 DSSI_Descriptor_Function fn = (DSSI_Descriptor_Function) | 170 DSSI_Descriptor_Function fn = (DSSI_Descriptor_Function) |
171 DLSYM(libraryHandle, "dssi_descriptor"); | 171 DLSYM(libraryHandle, "dssi_descriptor"); |
172 | 172 |
173 if (!fn) { | 173 if (!fn) { |
174 cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: No descriptor function in library " << soname << endl; | 174 cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: No descriptor function in library " << soname << endl; |
175 return 0; | 175 return 0; |
176 } | 176 } |
177 | 177 |
178 const DSSI_Descriptor *descriptor = 0; | 178 const DSSI_Descriptor *descriptor = 0; |
179 | 179 |
180 int index = 0; | 180 int index = 0; |
181 while ((descriptor = fn(index))) { | 181 while ((descriptor = fn(index))) { |
182 if (descriptor->LADSPA_Plugin->Label == label) { | 182 if (descriptor->LADSPA_Plugin->Label == label) { |
183 if (firstInLibrary && (descriptor->DSSI_API_Version >= 2)) { | 183 if (firstInLibrary && (descriptor->DSSI_API_Version >= 2)) { |
184 descriptor->receive_host_descriptor(&m_hostDescriptor); | 184 descriptor->receive_host_descriptor(&m_hostDescriptor); |
185 } | 185 } |
186 return descriptor; | 186 return descriptor; |
187 } | 187 } |
188 ++index; | 188 ++index; |
189 } | 189 } |
190 | 190 |
191 cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: No such plugin as " << label << " in library " << soname << endl; | 191 cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: No such plugin as " << label << " in library " << soname << endl; |
192 | 192 |
193 return 0; | 193 return 0; |
213 | 213 |
214 if (path == "") { | 214 if (path == "") { |
215 | 215 |
216 path = DEFAULT_DSSI_PATH; | 216 path = DEFAULT_DSSI_PATH; |
217 | 217 |
218 char *home = getenv("HOME"); | 218 char *home = getenv("HOME"); |
219 if (home) { | 219 if (home) { |
220 std::string::size_type f; | 220 std::string::size_type f; |
221 while ((f = path.find("$HOME")) != std::string::npos && | 221 while ((f = path.find("$HOME")) != std::string::npos && |
222 f < path.length()) { | 222 f < path.length()) { |
223 path.replace(f, 5, home); | 223 path.replace(f, 5, home); |
224 } | 224 } |
238 } | 238 } |
239 | 239 |
240 std::string::size_type index = 0, newindex = 0; | 240 std::string::size_type index = 0, newindex = 0; |
241 | 241 |
242 while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) { | 242 while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) { |
243 pathList.push_back(path.substr(index, newindex - index).c_str()); | 243 pathList.push_back(path.substr(index, newindex - index).c_str()); |
244 index = newindex + 1; | 244 index = newindex + 1; |
245 } | 245 } |
246 | 246 |
247 pathList.push_back(path.substr(index).c_str()); | 247 pathList.push_back(path.substr(index).c_str()); |
248 | 248 |
249 return pathList; | 249 return pathList; |
263 | 263 |
264 lrdfPaths.push_back("/usr/local/share/ladspa/rdf"); | 264 lrdfPaths.push_back("/usr/local/share/ladspa/rdf"); |
265 lrdfPaths.push_back("/usr/share/ladspa/rdf"); | 265 lrdfPaths.push_back("/usr/share/ladspa/rdf"); |
266 | 266 |
267 for (std::vector<QString>::iterator i = pathList.begin(); | 267 for (std::vector<QString>::iterator i = pathList.begin(); |
268 i != pathList.end(); ++i) { | 268 i != pathList.end(); ++i) { |
269 lrdfPaths.push_back(*i + "/rdf"); | 269 lrdfPaths.push_back(*i + "/rdf"); |
270 } | 270 } |
271 | 271 |
272 #ifdef DSSI_BASE | 272 #ifdef DSSI_BASE |
273 baseUri = DSSI_BASE; | 273 baseUri = DSSI_BASE; |
274 #else | 274 #else |
298 << soname << " - " << DLERROR() << endl; | 298 << soname << " - " << DLERROR() << endl; |
299 return; | 299 return; |
300 } | 300 } |
301 | 301 |
302 DSSI_Descriptor_Function fn = (DSSI_Descriptor_Function) | 302 DSSI_Descriptor_Function fn = (DSSI_Descriptor_Function) |
303 DLSYM(libraryHandle, "dssi_descriptor"); | 303 DLSYM(libraryHandle, "dssi_descriptor"); |
304 | 304 |
305 if (!fn) { | 305 if (!fn) { |
306 cerr << "WARNING: DSSIPluginFactory::discoverPlugins: No descriptor function in " << soname << endl; | 306 cerr << "WARNING: DSSIPluginFactory::discoverPlugins: No descriptor function in " << soname << endl; |
307 return; | 307 return; |
308 } | 308 } |
309 | 309 |
310 const DSSI_Descriptor *descriptor = 0; | 310 const DSSI_Descriptor *descriptor = 0; |
311 | 311 |
312 int index = 0; | 312 int index = 0; |
313 while ((descriptor = fn(index))) { | 313 while ((descriptor = fn(index))) { |
314 | 314 |
315 const LADSPA_Descriptor *ladspaDescriptor = descriptor->LADSPA_Plugin; | 315 const LADSPA_Descriptor *ladspaDescriptor = descriptor->LADSPA_Plugin; |
316 if (!ladspaDescriptor) { | 316 if (!ladspaDescriptor) { |
317 cerr << "WARNING: DSSIPluginFactory::discoverPlugins: No LADSPA descriptor for plugin " << index << " in " << soname << endl; | 317 cerr << "WARNING: DSSIPluginFactory::discoverPlugins: No LADSPA descriptor for plugin " << index << " in " << soname << endl; |
318 ++index; | 318 ++index; |
319 continue; | 319 continue; |
320 } | 320 } |
321 | 321 |
322 RealTimePluginDescriptor *rtd = new RealTimePluginDescriptor; | 322 RealTimePluginDescriptor *rtd = new RealTimePluginDescriptor; |
323 rtd->name = ladspaDescriptor->Name; | 323 rtd->name = ladspaDescriptor->Name; |
324 rtd->label = ladspaDescriptor->Label; | 324 rtd->label = ladspaDescriptor->Label; |
325 rtd->maker = ladspaDescriptor->Maker; | 325 rtd->maker = ladspaDescriptor->Maker; |
330 rtd->parameterCount = 0; | 330 rtd->parameterCount = 0; |
331 rtd->audioInputPortCount = 0; | 331 rtd->audioInputPortCount = 0; |
332 rtd->audioOutputPortCount = 0; | 332 rtd->audioOutputPortCount = 0; |
333 rtd->controlOutputPortCount = 0; | 333 rtd->controlOutputPortCount = 0; |
334 | 334 |
335 QString identifier = PluginIdentifier::createIdentifier | 335 QString identifier = PluginIdentifier::createIdentifier |
336 ("dssi", soname, ladspaDescriptor->Label); | 336 ("dssi", soname, ladspaDescriptor->Label); |
337 | 337 |
338 #ifdef HAVE_LRDF | 338 #ifdef HAVE_LRDF |
339 char *def_uri = 0; | 339 char *def_uri = 0; |
340 lrdf_defaults *defs = 0; | 340 lrdf_defaults *defs = 0; |
341 | 341 |
342 QString category = m_taxonomy[identifier]; | 342 QString category = m_taxonomy[identifier]; |
343 | 343 |
344 if (category == "" && m_lrdfTaxonomy[ladspaDescriptor->UniqueID] != "") { | 344 if (category == "" && m_lrdfTaxonomy[ladspaDescriptor->UniqueID] != "") { |
345 m_taxonomy[identifier] = m_lrdfTaxonomy[ladspaDescriptor->UniqueID]; | 345 m_taxonomy[identifier] = m_lrdfTaxonomy[ladspaDescriptor->UniqueID]; |
346 category = m_taxonomy[identifier]; | 346 category = m_taxonomy[identifier]; |
347 } | 347 } |
348 | 348 |
349 if (category == "") { | 349 if (category == "") { |
350 std::string name = rtd->name; | 350 std::string name = rtd->name; |
351 if (name.length() > 4 && | 351 if (name.length() > 4 && |
352 name.substr(name.length() - 4) == " VST") { | 352 name.substr(name.length() - 4) == " VST") { |
353 if (descriptor->run_synth || descriptor->run_multiple_synths) { | 353 if (descriptor->run_synth || descriptor->run_multiple_synths) { |
354 category = "VST instruments"; | 354 category = "VST instruments"; |
355 } else { | 355 } else { |
356 category = "VST effects"; | 356 category = "VST effects"; |
357 } | 357 } |
358 m_taxonomy[identifier] = category; | 358 m_taxonomy[identifier] = category; |
359 } | 359 } |
360 } | 360 } |
361 | 361 |
362 rtd->category = category.toStdString(); | 362 rtd->category = category.toStdString(); |
363 | 363 |
364 // cerr << "Plugin id is " << ladspaDescriptor->UniqueID | 364 // cerr << "Plugin id is " << ladspaDescriptor->UniqueID |
365 // << ", identifier is \"" << identifier | 365 // << ", identifier is \"" << identifier |
366 // << "\", category is \"" << category | 366 // << "\", category is \"" << category |
367 // << "\", name is " << ladspaDescriptor->Name | 367 // << "\", name is " << ladspaDescriptor->Name |
368 // << ", label is " << ladspaDescriptor->Label | 368 // << ", label is " << ladspaDescriptor->Label |
369 // << endl; | 369 // << endl; |
370 | 370 |
371 def_uri = lrdf_get_default_uri(ladspaDescriptor->UniqueID); | 371 def_uri = lrdf_get_default_uri(ladspaDescriptor->UniqueID); |
372 if (def_uri) { | 372 if (def_uri) { |
373 defs = lrdf_get_setting_values(def_uri); | 373 defs = lrdf_get_setting_values(def_uri); |
374 } | 374 } |
375 | 375 |
376 unsigned int controlPortNumber = 1; | 376 unsigned int controlPortNumber = 1; |
377 | 377 |
378 for (int i = 0; i < (int)ladspaDescriptor->PortCount; i++) { | 378 for (int i = 0; i < (int)ladspaDescriptor->PortCount; i++) { |
379 | 379 |
380 if (LADSPA_IS_PORT_CONTROL(ladspaDescriptor->PortDescriptors[i])) { | 380 if (LADSPA_IS_PORT_CONTROL(ladspaDescriptor->PortDescriptors[i])) { |
381 | 381 |
382 if (def_uri && defs) { | 382 if (def_uri && defs) { |
383 | 383 |
384 for (int j = 0; j < (int)defs->count; j++) { | 384 for (int j = 0; j < (int)defs->count; j++) { |
385 if (defs->items[j].pid == controlPortNumber) { | 385 if (defs->items[j].pid == controlPortNumber) { |
386 // 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 " << ladspaDescriptor->PortNames[i] << endl; | 386 // 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 " << ladspaDescriptor->PortNames[i] << endl; |
387 m_portDefaults[ladspaDescriptor->UniqueID][i] = | 387 m_portDefaults[ladspaDescriptor->UniqueID][i] = |
388 defs->items[j].value; | 388 defs->items[j].value; |
389 } | 389 } |
390 } | 390 } |
391 } | 391 } |
392 | 392 |
393 ++controlPortNumber; | 393 ++controlPortNumber; |
394 } | 394 } |
395 } | 395 } |
396 #endif // HAVE_LRDF | 396 #endif // HAVE_LRDF |
397 | 397 |
398 for (unsigned long i = 0; i < ladspaDescriptor->PortCount; i++) { | 398 for (unsigned long i = 0; i < ladspaDescriptor->PortCount; i++) { |
399 if (LADSPA_IS_PORT_CONTROL(ladspaDescriptor->PortDescriptors[i])) { | 399 if (LADSPA_IS_PORT_CONTROL(ladspaDescriptor->PortDescriptors[i])) { |
400 if (LADSPA_IS_PORT_INPUT(ladspaDescriptor->PortDescriptors[i])) { | 400 if (LADSPA_IS_PORT_INPUT(ladspaDescriptor->PortDescriptors[i])) { |
401 ++rtd->parameterCount; | 401 ++rtd->parameterCount; |
402 } else { | 402 } else { |
403 if (strcmp(ladspaDescriptor->PortNames[i], "latency") && | 403 if (strcmp(ladspaDescriptor->PortNames[i], "latency") && |
404 strcmp(ladspaDescriptor->PortNames[i], "_latency")) { | 404 strcmp(ladspaDescriptor->PortNames[i], "_latency")) { |
414 ++rtd->audioOutputPortCount; | 414 ++rtd->audioOutputPortCount; |
415 } | 415 } |
416 } | 416 } |
417 } | 417 } |
418 | 418 |
419 m_identifiers.push_back(identifier); | 419 m_identifiers.push_back(identifier); |
420 | 420 |
421 m_rtDescriptors[identifier] = rtd; | 421 m_rtDescriptors[identifier] = rtd; |
422 | 422 |
423 ++index; | 423 ++index; |
424 } | 424 } |
425 | 425 |
426 if (DLCLOSE(libraryHandle) != 0) { | 426 if (DLCLOSE(libraryHandle) != 0) { |
427 cerr << "WARNING: DSSIPluginFactory::discoverPlugins - can't unload " << libraryHandle << endl; | 427 cerr << "WARNING: DSSIPluginFactory::discoverPlugins - can't unload " << libraryHandle << endl; |
428 return; | 428 return; |