Mercurial > hg > svcore
diff 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 |
line wrap: on
line diff
--- a/plugin/DSSIPluginFactory.cpp Mon Dec 12 15:18:52 2016 +0000 +++ b/plugin/DSSIPluginFactory.cpp Mon Sep 17 13:51:14 2018 +0100 @@ -39,6 +39,7 @@ #include "lrdf.h" #endif // HAVE_LRDF +using std::string; DSSIPluginFactory::DSSIPluginFactory() : LADSPAPluginFactory() @@ -61,61 +62,61 @@ Profiler profiler("DSSIPluginFactory::enumeratePlugins"); for (std::vector<QString>::iterator i = m_identifiers.begin(); - i != m_identifiers.end(); ++i) { + i != m_identifiers.end(); ++i) { - const DSSI_Descriptor *ddesc = getDSSIDescriptor(*i); - if (!ddesc) continue; + const DSSI_Descriptor *ddesc = getDSSIDescriptor(*i); + if (!ddesc) continue; - const LADSPA_Descriptor *descriptor = ddesc->LADSPA_Plugin; - if (!descriptor) continue; - -// SVDEBUG << "DSSIPluginFactory::enumeratePlugins: Name " << (descriptor->Name ? descriptor->Name : "NONE" ) << endl; + const LADSPA_Descriptor *descriptor = ddesc->LADSPA_Plugin; + if (!descriptor) continue; + +// SVDEBUG << "DSSIPluginFactory::enumeratePlugins: Name " << (descriptor->Name ? descriptor->Name : "NONE" ) << endl; - list.push_back(*i); - list.push_back(descriptor->Name); - list.push_back(QString("%1").arg(descriptor->UniqueID)); - list.push_back(descriptor->Label); - list.push_back(descriptor->Maker); - list.push_back(descriptor->Copyright); - list.push_back((ddesc->run_synth || ddesc->run_multiple_synths) ? "true" : "false"); - list.push_back(ddesc->run_multiple_synths ? "true" : "false"); - list.push_back(m_taxonomy[*i]); - list.push_back(QString("%1").arg(descriptor->PortCount)); + list.push_back(*i); + list.push_back(descriptor->Name); + list.push_back(QString("%1").arg(descriptor->UniqueID)); + list.push_back(descriptor->Label); + list.push_back(descriptor->Maker); + list.push_back(descriptor->Copyright); + list.push_back((ddesc->run_synth || ddesc->run_multiple_synths) ? "true" : "false"); + list.push_back(ddesc->run_multiple_synths ? "true" : "false"); + list.push_back(m_taxonomy[*i]); + list.push_back(QString("%1").arg(descriptor->PortCount)); - for (int p = 0; p < (int)descriptor->PortCount; ++p) { + for (int p = 0; p < (int)descriptor->PortCount; ++p) { - int type = 0; - if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) { - type |= PortType::Control; - } else { - type |= PortType::Audio; - } - if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) { - type |= PortType::Input; - } else { - type |= PortType::Output; - } + int type = 0; + if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) { + type |= PortType::Control; + } else { + type |= PortType::Audio; + } + if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) { + type |= PortType::Input; + } else { + type |= PortType::Output; + } - list.push_back(QString("%1").arg(p)); - list.push_back(descriptor->PortNames[p]); - list.push_back(QString("%1").arg(type)); - list.push_back(QString("%1").arg(getPortDisplayHint(descriptor, p))); - list.push_back(QString("%1").arg(getPortMinimum(descriptor, p))); - list.push_back(QString("%1").arg(getPortMaximum(descriptor, p))); - list.push_back(QString("%1").arg(getPortDefault(descriptor, p))); - } + list.push_back(QString("%1").arg(p)); + list.push_back(descriptor->PortNames[p]); + list.push_back(QString("%1").arg(type)); + list.push_back(QString("%1").arg(getPortDisplayHint(descriptor, p))); + list.push_back(QString("%1").arg(getPortMinimum(descriptor, p))); + list.push_back(QString("%1").arg(getPortMaximum(descriptor, p))); + list.push_back(QString("%1").arg(getPortDefault(descriptor, p))); + } } unloadUnusedLibraries(); } - + RealTimePluginInstance * DSSIPluginFactory::instantiatePlugin(QString identifier, - int instrument, - int position, - sv_samplerate_t sampleRate, - int blockSize, - int channels) + int instrument, + int position, + sv_samplerate_t sampleRate, + int blockSize, + int channels) { Profiler profiler("DSSIPluginFactory::instantiatePlugin"); @@ -123,14 +124,14 @@ if (descriptor) { - DSSIPluginInstance *instance = - new DSSIPluginInstance - (this, instrument, identifier, position, sampleRate, blockSize, channels, - descriptor); + DSSIPluginInstance *instance = + new DSSIPluginInstance + (this, instrument, identifier, position, sampleRate, blockSize, channels, + descriptor); - m_instances.insert(instance); + m_instances.insert(instance); - return instance; + return instance; } return 0; @@ -143,49 +144,49 @@ PluginIdentifier::parseIdentifier(identifier, type, soname, label); if (soname == PluginIdentifier::BUILTIN_PLUGIN_SONAME) { - if (label == "sample_player") { - const DSSI_Descriptor *descriptor = SamplePlayer::getDescriptor(0); - if (descriptor) { - descriptor->receive_host_descriptor(&m_hostDescriptor); - } - return descriptor; - } else { - return 0; - } + if (label == "sample_player") { + const DSSI_Descriptor *descriptor = SamplePlayer::getDescriptor(0); + if (descriptor) { + descriptor->receive_host_descriptor(&m_hostDescriptor); + } + return descriptor; + } else { + return 0; + } } bool firstInLibrary = false; if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { - loadLibrary(soname); - if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { - cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: loadLibrary failed for " << soname << endl; - return 0; - } - firstInLibrary = true; + loadLibrary(soname); + if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { + cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: loadLibrary failed for " << soname << endl; + return 0; + } + firstInLibrary = true; } void *libraryHandle = m_libraryHandles[soname]; DSSI_Descriptor_Function fn = (DSSI_Descriptor_Function) - DLSYM(libraryHandle, "dssi_descriptor"); + DLSYM(libraryHandle, "dssi_descriptor"); if (!fn) { - cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: No descriptor function in library " << soname << endl; - return 0; + cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: No descriptor function in library " << soname << endl; + return 0; } const DSSI_Descriptor *descriptor = 0; int index = 0; while ((descriptor = fn(index))) { - if (descriptor->LADSPA_Plugin->Label == label) { - if (firstInLibrary && (descriptor->DSSI_API_Version >= 2)) { - descriptor->receive_host_descriptor(&m_hostDescriptor); - } - return descriptor; - } - ++index; + if (descriptor->LADSPA_Plugin->Label == label) { + if (firstInLibrary && (descriptor->DSSI_API_Version >= 2)) { + descriptor->receive_host_descriptor(&m_hostDescriptor); + } + return descriptor; + } + ++index; } cerr << "WARNING: DSSIPluginFactory::getDSSIDescriptor: No such plugin as " << label << " in library " << soname << endl; @@ -206,42 +207,42 @@ DSSIPluginFactory::getPluginPath() { std::vector<QString> pathList; - std::string path; + string path; - char *cpath = getenv("DSSI_PATH"); - if (cpath) path = cpath; + (void)getEnvUtf8("DSSI_PATH", path); if (path == "") { path = DEFAULT_DSSI_PATH; - char *home = getenv("HOME"); - if (home) { - std::string::size_type f; - while ((f = path.find("$HOME")) != std::string::npos && + string home; + if (getEnvUtf8("HOME", home)) { + string::size_type f; + while ((f = path.find("$HOME")) != string::npos && f < path.length()) { path.replace(f, 5, home); } } #ifdef _WIN32 - const char *pfiles = getenv("ProgramFiles"); - if (!pfiles) pfiles = "C:\\Program Files"; - { - std::string::size_type f; - while ((f = path.find("%ProgramFiles%")) != std::string::npos && + string pfiles; + if (!getEnvUtf8("ProgramFiles", pfiles)) { + pfiles = "C:\\Program Files"; + } + + string::size_type f; + while ((f = path.find("%ProgramFiles%")) != string::npos && f < path.length()) { path.replace(f, 14, pfiles); } - } #endif } - std::string::size_type index = 0, newindex = 0; + string::size_type index = 0, newindex = 0; while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) { - pathList.push_back(path.substr(index, newindex - index).c_str()); - index = newindex + 1; + pathList.push_back(path.substr(index, newindex - index).c_str()); + index = newindex + 1; } pathList.push_back(path.substr(index).c_str()); @@ -265,8 +266,8 @@ lrdfPaths.push_back("/usr/share/ladspa/rdf"); for (std::vector<QString>::iterator i = pathList.begin(); - i != pathList.end(); ++i) { - lrdfPaths.push_back(*i + "/rdf"); + i != pathList.end(); ++i) { + lrdfPaths.push_back(*i + "/rdf"); } #ifdef DSSI_BASE @@ -300,11 +301,11 @@ } DSSI_Descriptor_Function fn = (DSSI_Descriptor_Function) - DLSYM(libraryHandle, "dssi_descriptor"); + DLSYM(libraryHandle, "dssi_descriptor"); if (!fn) { - cerr << "WARNING: DSSIPluginFactory::discoverPlugins: No descriptor function in " << soname << endl; - return; + cerr << "WARNING: DSSIPluginFactory::discoverPlugins: No descriptor function in " << soname << endl; + return; } const DSSI_Descriptor *descriptor = 0; @@ -312,12 +313,12 @@ int index = 0; while ((descriptor = fn(index))) { - const LADSPA_Descriptor *ladspaDescriptor = descriptor->LADSPA_Plugin; - if (!ladspaDescriptor) { - cerr << "WARNING: DSSIPluginFactory::discoverPlugins: No LADSPA descriptor for plugin " << index << " in " << soname << endl; - ++index; - continue; - } + const LADSPA_Descriptor *ladspaDescriptor = descriptor->LADSPA_Plugin; + if (!ladspaDescriptor) { + cerr << "WARNING: DSSIPluginFactory::discoverPlugins: No LADSPA descriptor for plugin " << index << " in " << soname << endl; + ++index; + continue; + } RealTimePluginDescriptor *rtd = new RealTimePluginDescriptor; rtd->name = ladspaDescriptor->Name; @@ -332,71 +333,71 @@ rtd->audioOutputPortCount = 0; rtd->controlOutputPortCount = 0; - QString identifier = PluginIdentifier::createIdentifier - ("dssi", soname, ladspaDescriptor->Label); + QString identifier = PluginIdentifier::createIdentifier + ("dssi", soname, ladspaDescriptor->Label); #ifdef HAVE_LRDF - char *def_uri = 0; - lrdf_defaults *defs = 0; - - QString category = m_taxonomy[identifier]; + char *def_uri = 0; + lrdf_defaults *defs = 0; + + QString category = m_taxonomy[identifier]; if (category == "" && m_lrdfTaxonomy[ladspaDescriptor->UniqueID] != "") { m_taxonomy[identifier] = m_lrdfTaxonomy[ladspaDescriptor->UniqueID]; category = m_taxonomy[identifier]; } - if (category == "") { - std::string name = rtd->name; - if (name.length() > 4 && - name.substr(name.length() - 4) == " VST") { - if (descriptor->run_synth || descriptor->run_multiple_synths) { - category = "VST instruments"; - } else { - category = "VST effects"; - } - m_taxonomy[identifier] = category; - } - } + if (category == "") { + string name = rtd->name; + if (name.length() > 4 && + name.substr(name.length() - 4) == " VST") { + if (descriptor->run_synth || descriptor->run_multiple_synths) { + category = "VST instruments"; + } else { + category = "VST effects"; + } + m_taxonomy[identifier] = category; + } + } rtd->category = category.toStdString(); - -// cerr << "Plugin id is " << ladspaDescriptor->UniqueID + +// cerr << "Plugin id is " << ladspaDescriptor->UniqueID // << ", identifier is \"" << identifier -// << "\", category is \"" << category -// << "\", name is " << ladspaDescriptor->Name -// << ", label is " << ladspaDescriptor->Label -// << endl; - - def_uri = lrdf_get_default_uri(ladspaDescriptor->UniqueID); - if (def_uri) { - defs = lrdf_get_setting_values(def_uri); - } - - unsigned int controlPortNumber = 1; - - for (int i = 0; i < (int)ladspaDescriptor->PortCount; i++) { - - if (LADSPA_IS_PORT_CONTROL(ladspaDescriptor->PortDescriptors[i])) { - - if (def_uri && defs) { - - for (int j = 0; j < (int)defs->count; j++) { - if (defs->items[j].pid == controlPortNumber) { -// 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; - m_portDefaults[ladspaDescriptor->UniqueID][i] = - defs->items[j].value; - } - } - } - - ++controlPortNumber; - } - } +// << "\", category is \"" << category +// << "\", name is " << ladspaDescriptor->Name +// << ", label is " << ladspaDescriptor->Label +// << endl; + + def_uri = lrdf_get_default_uri(ladspaDescriptor->UniqueID); + if (def_uri) { + defs = lrdf_get_setting_values(def_uri); + } + + unsigned int controlPortNumber = 1; + + for (int i = 0; i < (int)ladspaDescriptor->PortCount; i++) { + + if (LADSPA_IS_PORT_CONTROL(ladspaDescriptor->PortDescriptors[i])) { + + if (def_uri && defs) { + + for (int j = 0; j < (int)defs->count; j++) { + if (defs->items[j].pid == controlPortNumber) { +// 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; + m_portDefaults[ladspaDescriptor->UniqueID][i] = + defs->items[j].value; + } + } + } + + ++controlPortNumber; + } + } #endif // HAVE_LRDF - for (unsigned long i = 0; i < ladspaDescriptor->PortCount; i++) { - if (LADSPA_IS_PORT_CONTROL(ladspaDescriptor->PortDescriptors[i])) { + for (unsigned long i = 0; i < ladspaDescriptor->PortCount; i++) { + if (LADSPA_IS_PORT_CONTROL(ladspaDescriptor->PortDescriptors[i])) { if (LADSPA_IS_PORT_INPUT(ladspaDescriptor->PortDescriptors[i])) { ++rtd->parameterCount; } else { @@ -416,11 +417,13 @@ } } - m_identifiers.push_back(identifier); + m_identifiers.push_back(identifier); + + m_libraries[identifier] = soname; m_rtDescriptors[identifier] = rtd; - ++index; + ++index; } if (DLCLOSE(libraryHandle) != 0) {