Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@0: A waveform viewer and audio annotation editor. Chris@2: Chris Cannam, Queen Mary University of London, 2005-2006 Chris@0: Chris@0: This is experimental software. Not for distribution. Chris@0: */ Chris@0: Chris@0: /* Chris@0: This is a modified version of a source file from the Chris@0: Rosegarden MIDI and audio sequencer and notation editor. Chris@17: This file copyright 2000-2006 Chris Cannam and Richard Bown. Chris@0: */ Chris@0: Chris@0: #include "LADSPAPluginFactory.h" Chris@0: #include Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include Chris@0: Chris@0: #include "LADSPAPluginInstance.h" Chris@0: #include "PluginIdentifier.h" Chris@0: Chris@0: #include "base/System.h" Chris@0: Chris@35: #ifdef HAVE_LRDF Chris@0: #include "lrdf.h" Chris@35: #endif // HAVE_LRDF Chris@0: Chris@0: Chris@0: LADSPAPluginFactory::LADSPAPluginFactory() Chris@0: { Chris@0: } Chris@0: Chris@0: LADSPAPluginFactory::~LADSPAPluginFactory() Chris@0: { Chris@0: for (std::set::iterator i = m_instances.begin(); Chris@0: i != m_instances.end(); ++i) { Chris@0: (*i)->setFactory(0); Chris@0: delete *i; Chris@0: } Chris@0: m_instances.clear(); Chris@0: unloadUnusedLibraries(); Chris@0: } Chris@0: Chris@0: const std::vector & Chris@0: LADSPAPluginFactory::getPluginIdentifiers() const Chris@0: { Chris@0: return m_identifiers; Chris@0: } Chris@0: Chris@0: void Chris@0: LADSPAPluginFactory::enumeratePlugins(std::vector &list) Chris@0: { Chris@0: for (std::vector::iterator i = m_identifiers.begin(); Chris@0: i != m_identifiers.end(); ++i) { Chris@0: Chris@0: const LADSPA_Descriptor *descriptor = getLADSPADescriptor(*i); Chris@0: Chris@0: if (!descriptor) { Chris@0: std::cerr << "WARNING: LADSPAPluginFactory::enumeratePlugins: couldn't get descriptor for identifier " << i->toStdString() << std::endl; Chris@0: continue; Chris@0: } Chris@0: Chris@0: list.push_back(*i); Chris@0: list.push_back(descriptor->Name); Chris@0: list.push_back(QString("%1").arg(descriptor->UniqueID)); Chris@0: list.push_back(descriptor->Label); Chris@0: list.push_back(descriptor->Maker); Chris@0: list.push_back(descriptor->Copyright); Chris@0: list.push_back("false"); // is synth Chris@0: list.push_back("false"); // is grouped Chris@0: Chris@0: if (m_taxonomy.find(descriptor->UniqueID) != m_taxonomy.end() && Chris@0: m_taxonomy[descriptor->UniqueID] != "") { Chris@0: // std::cerr << "LADSPAPluginFactory: cat for " << i->toStdString()<< " found in taxonomy as " << m_taxonomy[descriptor->UniqueID] << std::endl; Chris@0: list.push_back(m_taxonomy[descriptor->UniqueID]); Chris@0: Chris@0: } else if (m_fallbackCategories.find(*i) != Chris@0: m_fallbackCategories.end()) { Chris@0: list.push_back(m_fallbackCategories[*i]); Chris@0: // std::cerr << "LADSPAPluginFactory: cat for " << i->toStdString() <<" found in fallbacks as " << m_fallbackCategories[*i] << std::endl; Chris@0: Chris@0: } else { Chris@0: list.push_back(""); Chris@0: // std::cerr << "LADSPAPluginFactory: cat for " << i->toStdString() << " not found (despite having " << m_fallbackCategories.size() << " fallbacks)" << std::endl; Chris@0: Chris@0: } Chris@0: Chris@0: list.push_back(QString("%1").arg(descriptor->PortCount)); Chris@0: Chris@0: for (unsigned long p = 0; p < descriptor->PortCount; ++p) { Chris@0: Chris@0: int type = 0; Chris@0: if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) { Chris@0: type |= PortType::Control; Chris@0: } else { Chris@0: type |= PortType::Audio; Chris@0: } Chris@0: if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) { Chris@0: type |= PortType::Input; Chris@0: } else { Chris@0: type |= PortType::Output; Chris@0: } Chris@0: Chris@0: list.push_back(QString("%1").arg(p)); Chris@0: list.push_back(descriptor->PortNames[p]); Chris@0: list.push_back(QString("%1").arg(type)); Chris@0: list.push_back(QString("%1").arg(getPortDisplayHint(descriptor, p))); Chris@0: list.push_back(QString("%1").arg(getPortMinimum(descriptor, p))); Chris@0: list.push_back(QString("%1").arg(getPortMaximum(descriptor, p))); Chris@0: list.push_back(QString("%1").arg(getPortDefault(descriptor, p))); Chris@0: } Chris@0: } Chris@0: Chris@0: unloadUnusedLibraries(); Chris@0: } Chris@0: Chris@0: float Chris@0: LADSPAPluginFactory::getPortMinimum(const LADSPA_Descriptor *descriptor, int port) Chris@0: { Chris@0: LADSPA_PortRangeHintDescriptor d = Chris@0: descriptor->PortRangeHints[port].HintDescriptor; Chris@0: Chris@0: float minimum = 0.0; Chris@0: Chris@0: if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) { Chris@0: float lb = descriptor->PortRangeHints[port].LowerBound; Chris@0: minimum = lb; Chris@0: } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) { Chris@0: float ub = descriptor->PortRangeHints[port].UpperBound; Chris@0: minimum = std::min(0.0, ub - 1.0); Chris@0: } Chris@0: Chris@0: if (LADSPA_IS_HINT_SAMPLE_RATE(d)) { Chris@0: minimum *= m_sampleRate; Chris@0: } Chris@0: Chris@0: return minimum; Chris@0: } Chris@0: Chris@0: float Chris@0: LADSPAPluginFactory::getPortMaximum(const LADSPA_Descriptor *descriptor, int port) Chris@0: { Chris@0: LADSPA_PortRangeHintDescriptor d = Chris@0: descriptor->PortRangeHints[port].HintDescriptor; Chris@0: Chris@0: float maximum = 1.0; Chris@0: Chris@0: if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) { Chris@0: float ub = descriptor->PortRangeHints[port].UpperBound; Chris@0: maximum = ub; Chris@0: } else { Chris@0: float lb = descriptor->PortRangeHints[port].LowerBound; Chris@0: maximum = lb + 1.0; Chris@0: } Chris@0: Chris@0: if (LADSPA_IS_HINT_SAMPLE_RATE(d)) { Chris@0: maximum *= m_sampleRate; Chris@0: } Chris@0: Chris@0: return maximum; Chris@0: } Chris@0: Chris@0: float Chris@0: LADSPAPluginFactory::getPortDefault(const LADSPA_Descriptor *descriptor, int port) Chris@0: { Chris@0: float minimum = getPortMinimum(descriptor, port); Chris@0: float maximum = getPortMaximum(descriptor, port); Chris@0: float deft; Chris@0: Chris@0: if (m_portDefaults.find(descriptor->UniqueID) != Chris@0: m_portDefaults.end()) { Chris@0: if (m_portDefaults[descriptor->UniqueID].find(port) != Chris@0: m_portDefaults[descriptor->UniqueID].end()) { Chris@0: Chris@0: deft = m_portDefaults[descriptor->UniqueID][port]; Chris@0: if (deft < minimum) deft = minimum; Chris@0: if (deft > maximum) deft = maximum; Chris@0: return deft; Chris@0: } Chris@0: } Chris@0: Chris@0: LADSPA_PortRangeHintDescriptor d = Chris@0: descriptor->PortRangeHints[port].HintDescriptor; Chris@0: Chris@0: bool logarithmic = LADSPA_IS_HINT_LOGARITHMIC(d); Chris@0: Chris@0: if (!LADSPA_IS_HINT_HAS_DEFAULT(d)) { Chris@0: Chris@0: deft = minimum; Chris@0: Chris@0: } else if (LADSPA_IS_HINT_DEFAULT_MINIMUM(d)) { Chris@0: Chris@0: deft = minimum; Chris@0: Chris@0: } else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) { Chris@0: Chris@0: if (logarithmic) { Chris@0: deft = powf(10, log10(minimum) * 0.75 + Chris@0: log10(maximum) * 0.25); Chris@0: } else { Chris@0: deft = minimum * 0.75 + maximum * 0.25; Chris@0: } Chris@0: Chris@0: } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) { Chris@0: Chris@0: if (logarithmic) { Chris@0: deft = powf(10, log10(minimum) * 0.5 + Chris@0: log10(maximum) * 0.5); Chris@0: } else { Chris@0: deft = minimum * 0.5 + maximum * 0.5; Chris@0: } Chris@0: Chris@0: } else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) { Chris@0: Chris@0: if (logarithmic) { Chris@0: deft = powf(10, log10(minimum) * 0.25 + Chris@0: log10(maximum) * 0.75); Chris@0: } else { Chris@0: deft = minimum * 0.25 + maximum * 0.75; Chris@0: } Chris@0: Chris@0: } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(d)) { Chris@0: Chris@0: deft = maximum; Chris@0: Chris@0: } else if (LADSPA_IS_HINT_DEFAULT_0(d)) { Chris@0: Chris@0: deft = 0.0; Chris@0: Chris@0: } else if (LADSPA_IS_HINT_DEFAULT_1(d)) { Chris@0: Chris@0: deft = 1.0; Chris@0: Chris@0: } else if (LADSPA_IS_HINT_DEFAULT_100(d)) { Chris@0: Chris@0: deft = 100.0; Chris@0: Chris@0: } else if (LADSPA_IS_HINT_DEFAULT_440(d)) { Chris@0: Chris@0: deft = 440.0; Chris@0: Chris@0: } else { Chris@0: Chris@0: deft = minimum; Chris@0: } Chris@0: Chris@0: if (LADSPA_IS_HINT_SAMPLE_RATE(d)) { Chris@0: deft *= m_sampleRate; Chris@0: } Chris@0: Chris@0: return deft; Chris@0: } Chris@0: Chris@0: int Chris@0: LADSPAPluginFactory::getPortDisplayHint(const LADSPA_Descriptor *descriptor, int port) Chris@0: { Chris@0: LADSPA_PortRangeHintDescriptor d = Chris@0: descriptor->PortRangeHints[port].HintDescriptor; Chris@0: int hint = PortHint::NoHint; Chris@0: Chris@0: if (LADSPA_IS_HINT_TOGGLED(d)) hint |= PortHint::Toggled; Chris@0: if (LADSPA_IS_HINT_INTEGER(d)) hint |= PortHint::Integer; Chris@0: if (LADSPA_IS_HINT_LOGARITHMIC(d)) hint |= PortHint::Logarithmic; Chris@0: Chris@0: return hint; Chris@0: } Chris@0: Chris@0: Chris@0: RealTimePluginInstance * Chris@0: LADSPAPluginFactory::instantiatePlugin(QString identifier, Chris@0: int instrument, Chris@0: int position, Chris@0: unsigned int sampleRate, Chris@0: unsigned int blockSize, Chris@0: unsigned int channels) Chris@0: { Chris@0: const LADSPA_Descriptor *descriptor = getLADSPADescriptor(identifier); Chris@0: Chris@0: if (descriptor) { Chris@0: Chris@0: LADSPAPluginInstance *instance = Chris@0: new LADSPAPluginInstance Chris@0: (this, instrument, identifier, position, sampleRate, blockSize, channels, Chris@0: descriptor); Chris@0: Chris@0: m_instances.insert(instance); Chris@0: Chris@0: return instance; Chris@0: } Chris@0: Chris@0: return 0; Chris@0: } Chris@0: Chris@0: void Chris@0: LADSPAPluginFactory::releasePlugin(RealTimePluginInstance *instance, Chris@0: QString identifier) Chris@0: { Chris@0: if (m_instances.find(instance) == m_instances.end()) { Chris@0: std::cerr << "WARNING: LADSPAPluginFactory::releasePlugin: Not one of mine!" Chris@0: << std::endl; Chris@0: return; Chris@0: } Chris@0: Chris@0: QString type, soname, label; Chris@0: PluginIdentifier::parseIdentifier(identifier, type, soname, label); Chris@0: Chris@0: m_instances.erase(instance); Chris@0: Chris@0: bool stillInUse = false; Chris@0: Chris@0: for (std::set::iterator ii = m_instances.begin(); Chris@0: ii != m_instances.end(); ++ii) { Chris@0: QString itype, isoname, ilabel; Chris@0: PluginIdentifier::parseIdentifier((*ii)->getIdentifier(), itype, isoname, ilabel); Chris@0: if (isoname == soname) { Chris@0: // std::cerr << "LADSPAPluginFactory::releasePlugin: dll " << soname.toStdString() << " is still in use for plugin " << ilabel << std::endl; Chris@0: stillInUse = true; Chris@0: break; Chris@0: } Chris@0: } Chris@0: Chris@0: if (!stillInUse) { Chris@0: // std::cerr << "LADSPAPluginFactory::releasePlugin: dll " << soname.toStdString() << " no longer in use, unloading" << std::endl; Chris@0: unloadLibrary(soname); Chris@0: } Chris@0: } Chris@0: Chris@0: const LADSPA_Descriptor * Chris@0: LADSPAPluginFactory::getLADSPADescriptor(QString identifier) Chris@0: { Chris@0: QString type, soname, label; Chris@0: PluginIdentifier::parseIdentifier(identifier, type, soname, label); Chris@0: Chris@0: if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { Chris@0: loadLibrary(soname); Chris@0: if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { Chris@0: std::cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: loadLibrary failed for " << soname.toStdString() << std::endl; Chris@0: return 0; Chris@0: } Chris@0: } Chris@0: Chris@0: void *libraryHandle = m_libraryHandles[soname]; Chris@0: Chris@0: LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function) Chris@0: DLSYM(libraryHandle, "ladspa_descriptor"); Chris@0: Chris@0: if (!fn) { Chris@0: std::cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No descriptor function in library " << soname.toStdString() << std::endl; Chris@0: return 0; Chris@0: } Chris@0: Chris@0: const LADSPA_Descriptor *descriptor = 0; Chris@0: Chris@0: int index = 0; Chris@0: while ((descriptor = fn(index))) { Chris@0: if (descriptor->Label == label) return descriptor; Chris@0: ++index; Chris@0: } Chris@0: Chris@0: std::cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No such plugin as " << label.toStdString() << " in library " << soname.toStdString() << std::endl; Chris@0: Chris@0: return 0; Chris@0: } Chris@0: Chris@0: void Chris@0: LADSPAPluginFactory::loadLibrary(QString soName) Chris@0: { Chris@0: void *libraryHandle = DLOPEN(soName, RTLD_NOW); Chris@0: if (libraryHandle) m_libraryHandles[soName] = libraryHandle; Chris@0: } Chris@0: Chris@0: void Chris@0: LADSPAPluginFactory::unloadLibrary(QString soName) Chris@0: { Chris@0: LibraryHandleMap::iterator li = m_libraryHandles.find(soName); Chris@0: if (li != m_libraryHandles.end()) { Chris@0: // std::cerr << "unloading " << soname.toStdString() << std::endl; Chris@0: DLCLOSE(m_libraryHandles[soName]); Chris@0: m_libraryHandles.erase(li); Chris@0: } Chris@0: } Chris@0: Chris@0: void Chris@0: LADSPAPluginFactory::unloadUnusedLibraries() Chris@0: { Chris@0: std::vector toUnload; Chris@0: Chris@0: for (LibraryHandleMap::iterator i = m_libraryHandles.begin(); Chris@0: i != m_libraryHandles.end(); ++i) { Chris@0: Chris@0: bool stillInUse = false; Chris@0: Chris@0: for (std::set::iterator ii = m_instances.begin(); Chris@0: ii != m_instances.end(); ++ii) { Chris@0: Chris@0: QString itype, isoname, ilabel; Chris@0: PluginIdentifier::parseIdentifier((*ii)->getIdentifier(), itype, isoname, ilabel); Chris@0: if (isoname == i->first) { Chris@0: stillInUse = true; Chris@0: break; Chris@0: } Chris@0: } Chris@0: Chris@0: if (!stillInUse) toUnload.push_back(i->first); Chris@0: } Chris@0: Chris@0: for (std::vector::iterator i = toUnload.begin(); Chris@0: i != toUnload.end(); ++i) { Chris@0: unloadLibrary(*i); Chris@0: } Chris@0: } Chris@0: Chris@0: Chris@0: // It is only later, after they've gone, Chris@0: // I realize they have delivered a letter. Chris@0: // It's a letter from my wife. "What are you doing Chris@0: // there?" my wife asks. "Are you drinking?" Chris@0: // I study the postmark for hours. Then it, too, begins to fade. Chris@0: // I hope someday to forget all this. Chris@0: Chris@0: Chris@0: std::vector Chris@0: LADSPAPluginFactory::getPluginPath() Chris@0: { Chris@0: std::vector pathList; Chris@0: std::string path; Chris@0: Chris@0: char *cpath = getenv("LADSPA_PATH"); Chris@0: if (cpath) path = cpath; Chris@0: Chris@0: if (path == "") { Chris@0: path = "/usr/local/lib/ladspa:/usr/lib/ladspa"; Chris@0: char *home = getenv("HOME"); Chris@0: if (home) path = std::string(home) + "/.ladspa:" + path; Chris@0: } Chris@0: Chris@0: std::string::size_type index = 0, newindex = 0; Chris@0: Chris@0: while ((newindex = path.find(':', index)) < path.size()) { Chris@0: pathList.push_back(path.substr(index, newindex - index).c_str()); Chris@0: index = newindex + 1; Chris@0: } Chris@0: Chris@0: pathList.push_back(path.substr(index).c_str()); Chris@0: Chris@0: return pathList; Chris@0: } Chris@0: Chris@0: Chris@35: #ifdef HAVE_LRDF Chris@0: std::vector Chris@0: LADSPAPluginFactory::getLRDFPath(QString &baseUri) Chris@0: { Chris@0: std::vector pathList = getPluginPath(); Chris@0: std::vector lrdfPaths; Chris@0: Chris@0: lrdfPaths.push_back("/usr/local/share/ladspa/rdf"); Chris@0: lrdfPaths.push_back("/usr/share/ladspa/rdf"); Chris@0: Chris@0: for (std::vector::iterator i = pathList.begin(); Chris@0: i != pathList.end(); ++i) { Chris@0: lrdfPaths.push_back(*i + "/rdf"); Chris@0: } Chris@0: Chris@0: baseUri = LADSPA_BASE; Chris@0: return lrdfPaths; Chris@0: } Chris@0: #endif Chris@0: Chris@0: void Chris@0: LADSPAPluginFactory::discoverPlugins() Chris@0: { Chris@0: std::vector pathList = getPluginPath(); Chris@0: Chris@0: // std::cerr << "LADSPAPluginFactory::discoverPlugins - " Chris@0: // << "discovering plugins; path is "; Chris@0: for (std::vector::iterator i = pathList.begin(); Chris@0: i != pathList.end(); ++i) { Chris@0: std::cerr << "[" << i->toStdString() << "] "; Chris@0: } Chris@0: std::cerr << std::endl; Chris@0: Chris@35: #ifdef HAVE_LRDF Chris@0: // Initialise liblrdf and read the description files Chris@0: // Chris@0: lrdf_init(); Chris@0: Chris@0: QString baseUri; Chris@0: std::vector lrdfPaths = getLRDFPath(baseUri); Chris@0: Chris@0: bool haveSomething = false; Chris@0: Chris@0: for (size_t i = 0; i < lrdfPaths.size(); ++i) { Chris@0: QDir dir(lrdfPaths[i], "*.rdf;*.rdfs"); Chris@0: for (unsigned int j = 0; j < dir.count(); ++j) { Chris@0: if (!lrdf_read_file(QString("file:" + lrdfPaths[i] + "/" + dir[j]).toStdString().c_str())) { Chris@0: // std::cerr << "LADSPAPluginFactory: read RDF file " << (lrdfPaths[i] + "/" + dir[j]) << std::endl; Chris@0: haveSomething = true; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: if (haveSomething) { Chris@0: generateTaxonomy(baseUri + "Plugin", ""); Chris@0: } Chris@35: #endif // HAVE_LRDF Chris@0: Chris@0: generateFallbackCategories(); Chris@0: Chris@0: for (std::vector::iterator i = pathList.begin(); Chris@0: i != pathList.end(); ++i) { Chris@0: Chris@0: QDir pluginDir(*i, PLUGIN_GLOB); Chris@0: Chris@0: for (unsigned int j = 0; j < pluginDir.count(); ++j) { Chris@0: discoverPlugins(QString("%1/%2").arg(*i).arg(pluginDir[j])); Chris@0: } Chris@0: } Chris@0: Chris@35: #ifdef HAVE_LRDF Chris@0: // Cleanup after the RDF library Chris@0: // Chris@0: lrdf_cleanup(); Chris@35: #endif // HAVE_LRDF Chris@0: } Chris@0: Chris@0: void Chris@0: LADSPAPluginFactory::discoverPlugins(QString soname) Chris@0: { Chris@0: void *libraryHandle = DLOPEN(soname, RTLD_LAZY); Chris@0: Chris@0: if (!libraryHandle) { Chris@0: std::cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: couldn't load plugin library " Chris@0: << soname.toStdString() << " - " << DLERROR() << std::endl; Chris@0: return; Chris@0: } Chris@0: Chris@0: LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function) Chris@0: DLSYM(libraryHandle, "ladspa_descriptor"); Chris@0: Chris@0: if (!fn) { Chris@0: std::cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: No descriptor function in " << soname.toStdString() << std::endl; Chris@0: return; Chris@0: } Chris@0: Chris@0: const LADSPA_Descriptor *descriptor = 0; Chris@0: Chris@0: int index = 0; Chris@0: while ((descriptor = fn(index))) { Chris@0: Chris@35: #ifdef HAVE_LRDF Chris@0: char *def_uri = 0; Chris@0: lrdf_defaults *defs = 0; Chris@0: Chris@0: QString category = m_taxonomy[descriptor->UniqueID]; Chris@0: Chris@0: if (category == "" && descriptor->Name != 0) { Chris@0: std::string name = descriptor->Name; Chris@0: if (name.length() > 4 && Chris@0: name.substr(name.length() - 4) == " VST") { Chris@0: category = "VST effects"; Chris@0: m_taxonomy[descriptor->UniqueID] = category; Chris@0: } Chris@0: } Chris@0: Chris@0: // std::cerr << "Plugin id is " << descriptor->UniqueID Chris@0: // << ", category is \"" << (category ? category : QString("(none)")) Chris@0: // << "\", name is " << descriptor->Name Chris@0: // << ", label is " << descriptor->Label Chris@0: // << std::endl; Chris@0: Chris@0: def_uri = lrdf_get_default_uri(descriptor->UniqueID); Chris@0: if (def_uri) { Chris@0: defs = lrdf_get_setting_values(def_uri); Chris@0: } Chris@0: Chris@0: int controlPortNumber = 1; Chris@0: Chris@0: for (unsigned long i = 0; i < descriptor->PortCount; i++) { Chris@0: Chris@0: if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) { Chris@0: Chris@0: if (def_uri && defs) { Chris@0: Chris@0: for (int j = 0; j < defs->count; j++) { Chris@0: if (defs->items[j].pid == controlPortNumber) { Chris@0: // std::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] << std::endl; Chris@0: m_portDefaults[descriptor->UniqueID][i] = Chris@0: defs->items[j].value; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: ++controlPortNumber; Chris@0: } Chris@0: } Chris@35: #endif // HAVE_LRDF Chris@0: Chris@0: QString identifier = PluginIdentifier::createIdentifier Chris@0: ("ladspa", soname, descriptor->Label); Chris@0: m_identifiers.push_back(identifier); Chris@0: Chris@0: ++index; Chris@0: } Chris@0: Chris@0: if (DLCLOSE(libraryHandle) != 0) { Chris@0: std::cerr << "WARNING: LADSPAPluginFactory::discoverPlugins - can't unload " << libraryHandle << std::endl; Chris@0: return; Chris@0: } Chris@0: } Chris@0: Chris@0: void Chris@0: LADSPAPluginFactory::generateFallbackCategories() Chris@0: { Chris@0: std::vector pluginPath = getPluginPath(); Chris@0: std::vector path; Chris@0: Chris@0: for (size_t i = 0; i < pluginPath.size(); ++i) { Chris@0: if (pluginPath[i].contains("/lib/")) { Chris@0: QString p(pluginPath[i]); Chris@0: p.replace("/lib/", "/share/"); Chris@0: path.push_back(p); Chris@0: // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: path element " << p << std::endl; Chris@0: } Chris@0: path.push_back(pluginPath[i]); Chris@0: // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: path element " << pluginPath[i] << std::endl; Chris@0: } Chris@0: Chris@0: for (size_t i = 0; i < path.size(); ++i) { Chris@0: Chris@0: QDir dir(path[i], "*.cat"); Chris@0: Chris@0: // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i] << " has " << dir.count() << " .cat files" << std::endl; Chris@0: for (unsigned int j = 0; j < dir.count(); ++j) { Chris@0: Chris@0: QFile file(path[i] + "/" + dir[j]); Chris@0: Chris@0: // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i] + "/" + dir[j]) << std::endl; Chris@0: Chris@0: if (file.open(QIODevice::ReadOnly)) { Chris@0: // std::cerr << "...opened" << std::endl; Chris@0: QTextStream stream(&file); Chris@0: QString line; Chris@0: Chris@0: while (!stream.atEnd()) { Chris@0: line = stream.readLine(); Chris@0: // std::cerr << "line is: \"" << line << "\"" << std::endl; Chris@0: QString id = line.section("::", 0, 0); Chris@0: QString cat = line.section("::", 1, 1); Chris@0: m_fallbackCategories[id] = cat; Chris@0: // std::cerr << "set id \"" << id << "\" to cat \"" << cat << "\"" << std::endl; Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: void Chris@0: LADSPAPluginFactory::generateTaxonomy(QString uri, QString base) Chris@0: { Chris@35: #ifdef HAVE_LRDF Chris@0: lrdf_uris *uris = lrdf_get_instances(uri.toStdString().c_str()); Chris@0: Chris@0: if (uris != NULL) { Chris@0: for (int i = 0; i < uris->count; ++i) { Chris@0: m_taxonomy[lrdf_get_uid(uris->items[i])] = base; Chris@0: } Chris@0: lrdf_free_uris(uris); Chris@0: } Chris@0: Chris@0: uris = lrdf_get_subclasses(uri.toStdString().c_str()); Chris@0: Chris@0: if (uris != NULL) { Chris@0: for (int i = 0; i < uris->count; ++i) { Chris@0: char *label = lrdf_get_label(uris->items[i]); Chris@0: generateTaxonomy(uris->items[i], Chris@0: base + (base.length() > 0 ? " > " : "") + label); Chris@0: } Chris@0: lrdf_free_uris(uris); Chris@0: } Chris@0: #endif Chris@0: } Chris@0: Chris@0: