2 Copyright (C) 2000-2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
26 #include <sys/types.h>
35 #include "pbd/basename.h"
40 #include <ardour/vstfx.h>
41 #include <pbd/basename.h>
43 #endif //LXVST_SUPPORT
45 #include <glibmm/miscutils.h>
47 #include "pbd/pathscanner.h"
48 #include "pbd/whitespace.h"
50 #include "ardour/debug.h"
51 #include "ardour/filesystem_paths.h"
52 #include "ardour/ladspa.h"
53 #include "ardour/ladspa_plugin.h"
54 #include "ardour/plugin.h"
55 #include "ardour/plugin_manager.h"
56 #include "ardour/session.h"
59 #include "ardour/lv2_plugin.h"
63 #include "ardour/vst_plugin.h"
67 #include "ardour/lxvst_plugin.h"
70 #ifdef AUDIOUNIT_SUPPORT
71 #include "ardour/audio_unit.h"
72 #include <Carbon/Carbon.h>
75 #include "pbd/error.h"
76 #include "pbd/stl_delete.h"
80 using namespace ARDOUR;
84 PluginManager* PluginManager::_manager = 0;
86 PluginManager::PluginManager ()
88 , _lxvst_plugin_info(0)
89 , _ladspa_plugin_info(0)
98 if ((s = getenv ("LADSPA_RDF_PATH"))){
102 if (lrdf_path.length() == 0) {
103 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
106 add_lrdf_data(lrdf_path);
107 add_ladspa_presets();
109 if (Config->get_use_vst()) {
112 #endif /* VST_SUPPORT */
115 if (Config->get_use_lxvst()) {
118 #endif /* Native LinuxVST support*/
120 if ((s = getenv ("LADSPA_PATH"))) {
124 if ((s = getenv ("VST_PATH"))) {
126 } else if ((s = getenv ("VST_PLUGINS"))) {
130 if ((s = getenv ("LXVST_PATH"))) {
132 } else if ((s = getenv ("LXVST_PLUGINS"))) {
140 /* the plugin manager is constructed too early to use Profile */
142 if (getenv ("ARDOUR_SAE")) {
143 ladspa_plugin_whitelist.push_back (1203); // single band parametric
144 ladspa_plugin_whitelist.push_back (1772); // caps compressor
145 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
146 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
147 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
148 ladspa_plugin_whitelist.push_back (1216); // gverb
149 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
152 BootMessage (_("Discovering Plugins"));
156 PluginManager::~PluginManager()
162 PluginManager::refresh ()
164 DEBUG_TRACE (DEBUG::PluginManager, "PluginManager::refresh\n");
171 if (Config->get_use_vst()) {
174 #endif // VST_SUPPORT
177 if(Config->get_use_lxvst()) {
180 #endif //Native linuxVST SUPPORT
182 #ifdef AUDIOUNIT_SUPPORT
186 PluginListChanged (); /* EMIT SIGNAL */
190 PluginManager::ladspa_refresh ()
192 if (_ladspa_plugin_info)
193 _ladspa_plugin_info->clear ();
195 _ladspa_plugin_info = new ARDOUR::PluginInfoList ();
197 static const char *standard_paths[] = {
198 "/usr/local/lib64/ladspa",
199 "/usr/local/lib/ladspa",
202 "/Library/Audio/Plug-Ins/LADSPA",
206 /* allow LADSPA_PATH to augment, not override standard locations */
208 /* Only add standard locations to ladspa_path if it doesn't
209 * already contain them. Check for trailing G_DIR_SEPARATOR too.
213 for (i = 0; standard_paths[i][0]; i++) {
214 size_t found = ladspa_path.find(standard_paths[i]);
215 if (found != ladspa_path.npos) {
216 switch (ladspa_path[found + strlen(standard_paths[i])]) {
220 case G_DIR_SEPARATOR :
221 if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
222 ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
227 if (!ladspa_path.empty())
230 ladspa_path += standard_paths[i];
234 DEBUG_TRACE (DEBUG::PluginManager, string_compose ("LADSPA: search along: [%1]\n", ladspa_path));
236 ladspa_discover_from_path (ladspa_path);
241 PluginManager::add_ladspa_directory (string path)
243 if (ladspa_discover_from_path (path) == 0) {
251 static bool ladspa_filter (const string& str, void */*arg*/)
253 /* Not a dotfile, has a prefix before a period, suffix is "so" */
255 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
259 PluginManager::ladspa_discover_from_path (string /*path*/)
262 vector<string *> *plugin_objects;
263 vector<string *>::iterator x;
266 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
268 if (plugin_objects) {
269 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
270 ladspa_discover (**x);
274 vector_delete (plugin_objects);
278 static bool rdf_filter (const string &str, void* /*arg*/)
280 return str[0] != '.' &&
281 ((str.find(".rdf") == (str.length() - 4)) ||
282 (str.find(".rdfs") == (str.length() - 5)) ||
283 (str.find(".n3") == (str.length() - 3)) ||
284 (str.find(".ttl") == (str.length() - 4)));
288 PluginManager::add_ladspa_presets()
290 add_presets ("ladspa");
294 PluginManager::add_vst_presets()
300 PluginManager::add_lxvst_presets()
302 add_presets ("lxvst");
306 PluginManager::add_presets(string domain)
310 vector<string *> *presets;
311 vector<string *>::iterator x;
314 if ((envvar = getenv ("HOME")) == 0) {
318 string path = string_compose("%1/.%2/rdf", envvar, domain);
319 presets = scanner (path, rdf_filter, 0, true, true);
322 for (x = presets->begin(); x != presets->end (); ++x) {
323 string file = "file:" + **x;
324 if (lrdf_read_file(file.c_str())) {
325 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
330 vector_delete (presets);
334 PluginManager::add_lrdf_data (const string &path)
337 vector<string *>* rdf_files;
338 vector<string *>::iterator x;
340 rdf_files = scanner (path, rdf_filter, 0, true, true);
343 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
344 const string uri(string("file://") + **x);
346 if (lrdf_read_file(uri.c_str())) {
347 warning << "Could not parse rdf file: " << uri << endmsg;
352 vector_delete (rdf_files);
356 PluginManager::ladspa_discover (string path)
359 const LADSPA_Descriptor *descriptor;
360 LADSPA_Descriptor_Function dfunc;
363 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
364 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
368 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
370 if ((errstr = dlerror()) != 0) {
371 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
372 error << errstr << endmsg;
377 for (uint32_t i = 0; ; ++i) {
378 if ((descriptor = dfunc (i)) == 0) {
382 if (!ladspa_plugin_whitelist.empty()) {
383 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
388 PluginInfoPtr info(new LadspaPluginInfo);
389 info->name = descriptor->Name;
390 info->category = get_ladspa_category(descriptor->UniqueID);
391 info->creator = descriptor->Maker;
394 info->n_inputs = ChanCount();
395 info->n_outputs = ChanCount();
396 info->type = ARDOUR::LADSPA;
399 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
400 info->unique_id = buf;
402 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
403 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
404 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
405 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
407 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
408 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
413 if(_ladspa_plugin_info->empty()){
414 _ladspa_plugin_info->push_back (info);
417 //Ensure that the plugin is not already in the plugin list.
421 for (PluginInfoList::const_iterator i = _ladspa_plugin_info->begin(); i != _ladspa_plugin_info->end(); ++i) {
422 if(0 == info->unique_id.compare((*i)->unique_id)){
428 _ladspa_plugin_info->push_back (info);
432 // GDB WILL NOT LIKE YOU IF YOU DO THIS
439 PluginManager::get_ladspa_category (uint32_t plugin_id)
442 lrdf_statement pattern;
444 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
445 pattern.subject = buf;
446 pattern.predicate = (char*)RDF_TYPE;
448 pattern.object_type = lrdf_uri;
450 lrdf_statement* matches1 = lrdf_matches (&pattern);
456 pattern.subject = matches1->object;
457 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
459 pattern.object_type = lrdf_literal;
461 lrdf_statement* matches2 = lrdf_matches (&pattern);
462 lrdf_free_statements(matches1);
468 string label = matches2->object;
469 lrdf_free_statements(matches2);
471 /* Kludge LADSPA class names to be singular and match LV2 class names.
472 This avoids duplicate plugin menus for every class, which is necessary
473 to make the plugin category menu at all usable, but is obviously a
476 In the short term, lrdf could be updated so the labels match and a new
477 release made. To support both specs, we should probably be mapping the
478 URIs to the same category in code and perhaps tweaking that hierarchy
479 dynamically to suit the user. Personally, I (drobilla) think that time
480 is better spent replacing the little-used LRDF.
482 In the longer term, we will abandon LRDF entirely in favour of LV2 and
483 use that class hierarchy. Aside from fixing this problem properly, that
484 will also allow for translated labels. SWH plugins have been LV2 for
485 ages; TAP needs porting. I don't know of anything else with LRDF data.
487 if (label == "Utilities") {
489 } else if (label == "Pitch shifters") {
490 return "Pitch Shifter";
491 } else if (label != "Dynamics" && label != "Chorus"
492 &&label[label.length() - 1] == 's'
493 && label[label.length() - 2] != 's') {
494 return label.substr(0, label.length() - 1);
502 PluginManager::lv2_refresh ()
504 delete _lv2_plugin_info;
505 _lv2_plugin_info = LV2PluginInfo::discover();
509 #ifdef AUDIOUNIT_SUPPORT
511 PluginManager::au_refresh ()
513 DEBUG_TRACE (DEBUG::PluginManager, "AU: refresh\n");
514 delete _au_plugin_info;
515 _au_plugin_info = AUPluginInfo::discover();
523 PluginManager::vst_refresh ()
525 if (_vst_plugin_info)
526 _vst_plugin_info->clear ();
528 _vst_plugin_info = new ARDOUR::PluginInfoList();
530 if (vst_path.length() == 0) {
531 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
534 vst_discover_from_path (vst_path);
538 PluginManager::add_vst_directory (string path)
540 if (vst_discover_from_path (path) == 0) {
548 static bool vst_filter (const string& str, void *arg)
550 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
552 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
556 PluginManager::vst_discover_from_path (string path)
559 vector<string *> *plugin_objects;
560 vector<string *>::iterator x;
563 info << "detecting VST plugins along " << path << endmsg;
565 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
567 if (plugin_objects) {
568 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
573 vector_delete (plugin_objects);
578 PluginManager::vst_discover (string path)
583 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
584 warning << "Cannot get VST information from " << path << endmsg;
588 if (!finfo->canProcessReplacing) {
589 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
594 PluginInfoPtr info(new VSTPluginInfo);
596 /* what a joke freeware VST is */
598 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
599 info->name = PBD::basename_nosuffix (path);
601 info->name = finfo->name;
605 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
606 info->unique_id = buf;
607 info->category = "VST";
609 info->creator = finfo->creator;
611 info->n_inputs.set_audio (finfo->numInputs);
612 info->n_outputs.set_audio (finfo->numOutputs);
613 info->n_inputs.set_midi (finfo->wantMidi ? 1 : 0);
614 info->type = ARDOUR::VST;
616 _vst_plugin_info->push_back (info);
617 fst_free_info (finfo);
622 #endif // VST_SUPPORT
627 PluginManager::lxvst_refresh ()
629 if (_lxvst_plugin_info) {
630 _lxvst_plugin_info->clear ();
632 _lxvst_plugin_info = new ARDOUR::PluginInfoList();
635 if (lxvst_path.length() == 0) {
636 lxvst_path = "/usr/local/lib64/lxvst:/usr/local/lib/lxvst:/usr/lib64/lxvst:/usr/lib/lxvst";
639 lxvst_discover_from_path (lxvst_path);
643 PluginManager::add_lxvst_directory (string path)
645 if (lxvst_discover_from_path (path) == 0) {
653 static bool lxvst_filter (const string& str, void *)
655 /* Not a dotfile, has a prefix before a period, suffix is "so" */
657 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
661 PluginManager::lxvst_discover_from_path (string path)
664 vector<string *> *plugin_objects;
665 vector<string *>::iterator x;
668 info << "Discovering linuxVST plugins along " << path << endmsg;
670 plugin_objects = scanner (lxvst_path, lxvst_filter, 0, true, true);
672 if (plugin_objects) {
673 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
674 lxvst_discover (**x);
678 info << "Done linuxVST discover" << endmsg;
680 vector_delete (plugin_objects);
685 PluginManager::lxvst_discover (string path)
690 if ((finfo = vstfx_get_info (const_cast<char *> (path.c_str()))) == 0) {
691 warning << "Cannot get linuxVST information from " << path << endmsg;
695 if (!finfo->canProcessReplacing) {
696 warning << string_compose (_("linuxVST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
701 PluginInfoPtr info(new LXVSTPluginInfo);
703 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
704 info->name = PBD::basename_nosuffix (path);
706 info->name = finfo->name;
710 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
711 info->unique_id = buf;
712 info->category = "linuxVSTs";
714 info->creator = finfo->creator;
716 info->n_inputs.set_audio (finfo->numInputs);
717 info->n_outputs.set_audio (finfo->numOutputs);
718 info->n_inputs.set_midi (finfo->wantMidi ? 1 : 0);
719 info->type = ARDOUR::LXVST;
721 /* Make sure we don't find the same plugin in more than one place along
722 the LXVST_PATH We can't use a simple 'find' because the path is included
723 in the PluginInfo, and that is the one thing we can be sure MUST be
724 different if a duplicate instance is found. So we just compare the type
725 and unique ID (which for some VSTs isn't actually unique...)
728 if (!_lxvst_plugin_info->empty()) {
729 for (PluginInfoList::iterator i =_lxvst_plugin_info->begin(); i != _lxvst_plugin_info->end(); ++i) {
730 if ((info->type == (*i)->type)&&(info->unique_id == (*i)->unique_id)) {
731 vstfx_free_info(finfo);
737 _lxvst_plugin_info->push_back (info);
738 vstfx_free_info (finfo);
743 #endif // LXVST_SUPPORT
746 PluginManager::PluginStatusType
747 PluginManager::get_status (const PluginInfoPtr& pi)
749 PluginStatus ps (pi->type, pi->unique_id);
750 PluginStatusList::const_iterator i = find (statuses.begin(), statuses.end(), ps);
751 if (i == statuses.end() ) {
759 PluginManager::save_statuses ()
762 sys::path path = user_config_directory();
763 path /= "plugin_statuses";
765 ofs.open (path.to_string().c_str(), ios_base::openmode (ios::out|ios::trunc));
771 for (PluginStatusList::iterator i = statuses.begin(); i != statuses.end(); ++i) {
792 switch ((*i).status) {
805 ofs << (*i).unique_id;;
813 PluginManager::load_statuses ()
815 sys::path path = user_config_directory();
816 path /= "plugin_statuses";
817 ifstream ifs (path.to_string().c_str());
827 PluginStatusType status;
844 /* rest of the line is the plugin ID */
846 ifs.getline (buf, sizeof (buf), '\n');
851 if (sstatus == "Normal") {
853 } else if (sstatus == "Favorite") {
855 } else if (sstatus == "Hidden") {
858 error << string_compose (_("unknown plugin status type \"%1\" - all entries ignored"), sstatus)
864 if (stype == "LADSPA") {
866 } else if (stype == "AudioUnit") {
868 } else if (stype == "LV2") {
870 } else if (stype == "VST") {
872 } else if (stype == "LXVST") {
875 error << string_compose (_("unknown plugin type \"%1\" - ignored"), stype)
881 strip_whitespace_edges (id);
882 set_status (type, id, status);
889 PluginManager::set_status (PluginType t, string id, PluginStatusType status)
891 PluginStatus ps (t, id, status);
894 if (status == Normal) {
898 statuses.insert (ps);
901 ARDOUR::PluginInfoList&
902 PluginManager::vst_plugin_info ()
905 if (!_vst_plugin_info)
907 return *_vst_plugin_info;
909 return _empty_plugin_info;
913 ARDOUR::PluginInfoList&
914 PluginManager::lxvst_plugin_info ()
917 if (!_lxvst_plugin_info)
919 return *_lxvst_plugin_info;
921 return _empty_plugin_info;
925 ARDOUR::PluginInfoList&
926 PluginManager::ladspa_plugin_info ()
928 if (!_ladspa_plugin_info)
930 return *_ladspa_plugin_info;
933 ARDOUR::PluginInfoList&
934 PluginManager::lv2_plugin_info ()
937 if (!_lv2_plugin_info)
939 return *_lv2_plugin_info;
941 return _empty_plugin_info;
945 ARDOUR::PluginInfoList&
946 PluginManager::au_plugin_info ()
948 #ifdef AUDIOUNIT_SUPPORT
949 if (!_au_plugin_info)
951 return *_au_plugin_info;
953 return _empty_plugin_info;