comparison plugin/DSSIPluginFactory.cpp @ 1527:710e6250a401 zoom

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