26 #include <QTextStream> 53 for (std::set<RealTimePluginInstance *>::iterator i =
m_instances.begin();
66 const std::vector<QString> &
75 Profiler profiler(
"LADSPAPluginFactory::enumeratePlugins");
77 for (std::vector<QString>::iterator i =
m_identifiers.begin();
83 cerr <<
"WARNING: LADSPAPluginFactory::enumeratePlugins: couldn't get descriptor for identifier " << *i << endl;
88 list.push_back(descriptor->Name);
89 list.push_back(QString(
"%1").arg(descriptor->UniqueID));
90 list.push_back(descriptor->Label);
91 list.push_back(descriptor->Maker);
92 list.push_back(descriptor->Copyright);
93 list.push_back(
"false");
94 list.push_back(
"false");
105 list.push_back(QString(
"%1").arg(descriptor->PortCount));
107 for (
unsigned long p = 0; p < descriptor->PortCount; ++p) {
110 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) {
115 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) {
121 list.push_back(QString(
"%1").arg(p));
122 list.push_back(descriptor->PortNames[p]);
123 list.push_back(QString(
"%1").arg(type));
137 std::map<QString, RealTimePluginDescriptor *>::const_iterator i =
150 LADSPA_PortRangeHintDescriptor d =
151 descriptor->PortRangeHints[port].HintDescriptor;
155 if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) {
156 float lb = descriptor->PortRangeHints[port].LowerBound;
158 }
else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
159 float ub = descriptor->PortRangeHints[port].UpperBound;
160 minimum = std::min(0.0, ub - 1.0);
163 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
167 if (LADSPA_IS_HINT_LOGARITHMIC(d)) {
168 if (minimum == 0.f) minimum = 1.f;
177 LADSPA_PortRangeHintDescriptor d =
178 descriptor->PortRangeHints[port].HintDescriptor;
182 if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
183 float ub = descriptor->PortRangeHints[port].UpperBound;
186 float lb = descriptor->PortRangeHints[port].LowerBound;
190 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
210 if (deft < minimum) deft = minimum;
211 if (deft > maximum) deft = maximum;
216 LADSPA_PortRangeHintDescriptor d =
217 descriptor->PortRangeHints[port].HintDescriptor;
219 bool logarithmic = LADSPA_IS_HINT_LOGARITHMIC(d);
221 float logmin = 0, logmax = 0;
223 float thresh = powf(10, -10);
224 if (minimum < thresh) logmin = -10;
225 else logmin = log10f(minimum);
226 if (maximum < thresh) logmax = -10;
227 else logmax = log10f(maximum);
232 if (!LADSPA_IS_HINT_HAS_DEFAULT(d)) {
236 }
else if (LADSPA_IS_HINT_DEFAULT_MINIMUM(d)) {
240 }
else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) {
243 deft = powf(10, logmin * 0.75 + logmax * 0.25);
245 deft = minimum * 0.75 + maximum * 0.25;
248 }
else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) {
251 deft = powf(10, logmin * 0.5 + logmax * 0.5);
253 deft = minimum * 0.5 + maximum * 0.5;
256 }
else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) {
259 deft = powf(10, logmin * 0.25 + logmax * 0.75);
261 deft = minimum * 0.25 + maximum * 0.75;
264 }
else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(d)) {
268 }
else if (LADSPA_IS_HINT_DEFAULT_0(d)) {
272 }
else if (LADSPA_IS_HINT_DEFAULT_1(d)) {
276 }
else if (LADSPA_IS_HINT_DEFAULT_100(d)) {
280 }
else if (LADSPA_IS_HINT_DEFAULT_440(d)) {
318 LADSPA_PortRangeHintDescriptor d =
319 descriptor->PortRangeHints[port].HintDescriptor;
334 unsigned int sampleRate,
335 unsigned int blockSize,
336 unsigned int channels)
338 Profiler profiler(
"LADSPAPluginFactory::instantiatePlugin");
346 (
this, instrument, identifier, position, sampleRate, blockSize, channels,
351 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 352 SVDEBUG <<
"LADSPAPluginFactory::instantiatePlugin(" 353 << identifier <<
": now have " <<
m_instances.size() <<
" instances" << endl;
366 Profiler profiler(
"LADSPAPluginFactory::releasePlugin");
369 cerr <<
"WARNING: LADSPAPluginFactory::releasePlugin: Not one of mine!" 374 QString type, soname, label;
379 bool stillInUse =
false;
381 for (std::set<RealTimePluginInstance *>::iterator ii =
m_instances.begin();
383 QString itype, isoname, ilabel;
385 if (isoname == soname) {
386 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 387 SVDEBUG <<
"LADSPAPluginFactory::releasePlugin: dll " << soname <<
" is still in use for plugin " << ilabel << endl;
396 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 397 SVDEBUG <<
"LADSPAPluginFactory::releasePlugin: dll " << soname <<
" no longer in use, unloading" << endl;
403 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 404 SVDEBUG <<
"LADSPAPluginFactory::releasePlugin(" 405 << identifier <<
": now have " <<
m_instances.size() <<
" instances" << endl;
409 const LADSPA_Descriptor *
412 QString type, soname, label;
418 cerr <<
"WARNING: LADSPAPluginFactory::getLADSPADescriptor: loadLibrary failed for " << soname << endl;
425 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
426 DLSYM(libraryHandle,
"ladspa_descriptor");
429 cerr <<
"WARNING: LADSPAPluginFactory::getLADSPADescriptor: No descriptor function in library " << soname << endl;
433 const LADSPA_Descriptor *descriptor = 0;
436 while ((descriptor = fn(index))) {
437 if (descriptor->Label == label)
return descriptor;
441 cerr <<
"WARNING: LADSPAPluginFactory::getLADSPADescriptor: No such plugin as " << label <<
" in library " << soname << endl;
449 void *libraryHandle =
DLOPEN(soName, RTLD_NOW);
452 SVDEBUG <<
"LADSPAPluginFactory::loadLibrary: Loaded library \"" << soName <<
"\"" << endl;
456 if (QFileInfo(soName).exists()) {
458 cerr <<
"LADSPAPluginFactory::loadLibrary: Library \"" << soName <<
"\" exists, but failed to load it" << endl;
464 QString fileName = QFile(soName).fileName();
465 QString base = QFileInfo(soName).baseName();
467 for (std::vector<QString>::iterator i = pathList.begin();
468 i != pathList.end(); ++i) {
470 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 471 SVDEBUG <<
"Looking at: " << (*i) << endl;
475 QDir::Name | QDir::IgnoreCase,
476 QDir::Files | QDir::Readable);
478 if (QFileInfo(dir.filePath(fileName)).exists()) {
479 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 480 cerr <<
"Loading: " << fileName << endl;
482 libraryHandle =
DLOPEN(dir.filePath(fileName), RTLD_NOW);
489 for (
unsigned int j = 0; j < dir.count(); ++j) {
490 QString file = dir.filePath(dir[j]);
491 if (QFileInfo(file).baseName() == base) {
492 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 493 cerr <<
"Loading: " << file << endl;
495 libraryHandle =
DLOPEN(file, RTLD_NOW);
504 cerr <<
"LADSPAPluginFactory::loadLibrary: Failed to locate plugin library \"" << soName <<
"\"" << endl;
521 std::vector<QString> toUnload;
526 bool stillInUse =
false;
528 for (std::set<RealTimePluginInstance *>::iterator ii =
m_instances.begin();
531 QString itype, isoname, ilabel;
533 if (isoname == i->first) {
539 if (!stillInUse) toUnload.push_back(i->first);
542 for (std::vector<QString>::iterator i = toUnload.begin();
543 i != toUnload.end(); ++i) {
562 std::vector<QString> pathList;
565 char *cpath = getenv(
"LADSPA_PATH");
566 if (cpath) path = cpath;
572 char *home = getenv(
"HOME");
574 std::string::size_type f;
575 while ((f = path.find(
"$HOME")) != std::string::npos &&
577 path.replace(f, 5, home);
582 char *pfiles = getenv(
"ProgramFiles");
583 if (!pfiles) pfiles =
"C:\\Program Files";
585 std::string::size_type f;
586 while ((f = path.find(
"%ProgramFiles%")) != std::string::npos &&
588 path.replace(f, 14, pfiles);
594 std::string::size_type index = 0, newindex = 0;
596 while ((newindex = path.find(
PATH_SEPARATOR, index)) < path.size()) {
597 pathList.push_back(path.substr(index, newindex - index).c_str());
598 index = newindex + 1;
601 pathList.push_back(path.substr(index).c_str());
610 std::vector<QString> lrdfPaths;
615 lrdfPaths.push_back(
"/usr/local/share/ladspa/rdf");
616 lrdfPaths.push_back(
"/usr/share/ladspa/rdf");
618 for (std::vector<QString>::iterator i = pathList.begin();
619 i != pathList.end(); ++i) {
620 lrdfPaths.push_back(*i +
"/rdf");
623 baseUri = LADSPA_BASE;
634 Profiler profiler(
"LADSPAPluginFactory::discoverPlugins");
650 std::vector<QString> lrdfPaths =
getLRDFPath(baseUri);
652 bool haveSomething =
false;
654 for (
size_t i = 0; i < lrdfPaths.size(); ++i) {
655 QDir dir(lrdfPaths[i],
"*.rdf;*.rdfs");
656 for (
unsigned int j = 0; j < dir.count(); ++j) {
657 if (!lrdf_read_file(QString(
"file:" + lrdfPaths[i] +
"/" + dir[j]).toStdString().c_str())) {
659 haveSomething =
true;
671 for (std::vector<QString>::iterator i = pathList.begin();
672 i != pathList.end(); ++i) {
676 for (
unsigned int j = 0; j < pluginDir.count(); ++j) {
685 void *libraryHandle =
DLOPEN(soname, RTLD_LAZY);
687 if (!libraryHandle) {
688 cerr <<
"WARNING: LADSPAPluginFactory::discoverPlugins: couldn't load plugin library " 689 << soname <<
" - " <<
DLERROR() << endl;
693 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
694 DLSYM(libraryHandle,
"ladspa_descriptor");
697 cerr <<
"WARNING: LADSPAPluginFactory::discoverPlugins: No descriptor function in " << soname << endl;
701 const LADSPA_Descriptor *descriptor = 0;
704 while ((descriptor = fn(index))) {
707 rtd->
name = descriptor->Name;
708 rtd->
label = descriptor->Label;
709 rtd->
maker = descriptor->Maker;
719 (
"ladspa", soname, descriptor->Label);
723 lrdf_defaults *defs = 0;
733 if (category ==
"") {
734 std::string name = rtd->
name;
735 if (name.length() > 4 &&
736 name.substr(name.length() - 4) ==
" VST") {
737 category =
"VST effects";
742 rtd->
category = category.toStdString();
750 def_uri = lrdf_get_default_uri(descriptor->UniqueID);
752 defs = lrdf_get_setting_values(def_uri);
755 unsigned int controlPortNumber = 1;
757 for (
unsigned long i = 0; i < descriptor->PortCount; i++) {
759 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
761 if (def_uri && defs) {
763 for (
unsigned int j = 0; j < defs->count; j++) {
764 if (defs->items[j].pid == controlPortNumber) {
767 defs->items[j].value;
777 for (
unsigned long i = 0; i < descriptor->PortCount; i++) {
778 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
779 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
782 if (strcmp(descriptor->PortNames[i],
"latency") &&
783 strcmp(descriptor->PortNames[i],
"_latency")) {
786 (descriptor->PortNames[i]);
790 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
792 }
else if (LADSPA_IS_PORT_OUTPUT(descriptor->PortDescriptors[i])) {
805 if (
DLCLOSE(libraryHandle) != 0) {
806 cerr <<
"WARNING: LADSPAPluginFactory::discoverPlugins - can't unload " << libraryHandle << endl;
815 std::vector<QString> path;
817 for (
size_t i = 0; i < pluginPath.size(); ++i) {
818 if (pluginPath[i].contains(
"/lib/")) {
819 QString p(pluginPath[i]);
821 p.replace(
"/lib/",
"/share/");
825 path.push_back(pluginPath[i]);
829 for (
size_t i = 0; i < path.size(); ++i) {
831 QDir dir(path[i],
"*.cat");
834 for (
unsigned int j = 0; j < dir.count(); ++j) {
836 QFile file(path[i] +
"/" + dir[j]);
840 if (file.open(QIODevice::ReadOnly)) {
842 QTextStream stream(&file);
845 while (!stream.atEnd()) {
846 line = stream.readLine();
849 (line.section(
"::", 0, 0));
850 QString cat = line.section(
"::", 1, 1);
863 lrdf_uris *uris = lrdf_get_instances(uri.toStdString().c_str());
866 for (
unsigned int i = 0; i < uris->count; ++i) {
869 lrdf_free_uris(uris);
872 uris = lrdf_get_subclasses(uri.toStdString().c_str());
875 for (
unsigned int i = 0; i < uris->count; ++i) {
876 char *label = lrdf_get_label(uris->items[i]);
878 base + (base.length() > 0 ?
" > " :
"") + label);
880 lrdf_free_uris(uris);
float getTuningFrequency() const
std::vector< std::string > controlOutputPortNames
virtual void discoverPlugins()
Look up the plugin path and find the plugins in it.
virtual ~LADSPAPluginFactory()
void unloadLibrary(QString soName)
int getPortDisplayHint(const LADSPA_Descriptor *, int port)
static QString canonicalise(QString identifier)
LibraryHandleMap m_libraryHandles
virtual void generateTaxonomy(QString uri, QString base)
static void parseIdentifier(QString identifier, QString &type, QString &soName, QString &label)
static Preferences * getInstance()
static QString createIdentifier(QString type, QString soName, QString label)
float getPortDefault(const LADSPA_Descriptor *, int port)
unsigned int audioInputPortCount
virtual QString getPluginCategory(QString identifier)
Get category metadata about a plugin (without instantiating it).
unsigned int parameterCount
unsigned int controlOutputPortCount
virtual std::vector< QString > getPluginPath()
virtual void generateFallbackCategories()
virtual void releasePlugin(RealTimePluginInstance *, QString)
float getPortMaximum(const LADSPA_Descriptor *, int port)
static QString BUILTIN_PLUGIN_SONAME
void unloadUnusedLibraries()
float getPortQuantization(const LADSPA_Descriptor *, int port)
#define DEFAULT_LADSPA_PATH
virtual const std::vector< QString > & getPluginIdentifiers() const
Return a reference to a list of all plugin identifiers that can be created by this factory.
virtual std::vector< QString > getLRDFPath(QString &baseUri)
std::map< unsigned long, std::map< int, float > > m_portDefaults
std::set< RealTimePluginInstance * > m_instances
std::map< QString, QString > m_taxonomy
std::map< QString, RealTimePluginDescriptor * > m_rtDescriptors
static const int Logarithmic
std::vector< QString > m_identifiers
virtual void discoverPluginsFrom(QString soName)
std::map< unsigned long, QString > m_lrdfTaxonomy
virtual RealTimePluginInstance * instantiatePlugin(QString identifier, int clientId, int position, unsigned int sampleRate, unsigned int blockSize, unsigned int channels)
Instantiate a plugin.
static RealTimePluginFactory * instance(QString pluginType)
virtual const RealTimePluginDescriptor * getPluginDescriptor(QString identifier) const
Get some basic information about a plugin (rapidly).
void loadLibrary(QString soName)
virtual void enumeratePlugins(std::vector< QString > &list)
Append to the given list descriptions of all the available plugins and their ports.
float getPortMinimum(const LADSPA_Descriptor *, int port)
virtual const LADSPA_Descriptor * getLADSPADescriptor(QString identifier)
unsigned int audioOutputPortCount
Profile point instance class.