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/ladspa.h"
51 #include "ardour/session.h"
52 #include "ardour/plugin_manager.h"
53 #include "ardour/plugin.h"
54 #include "ardour/ladspa_plugin.h"
55 #include "ardour/filesystem_paths.h"
58 #include "ardour/lv2_plugin.h"
62 #include "ardour/vst_plugin.h"
66 #include "ardour/lxvst_plugin.h"
69 #ifdef HAVE_AUDIOUNITS
70 #include "ardour/audio_unit.h"
71 #include <Carbon/Carbon.h>
74 #include "pbd/error.h"
75 #include "pbd/stl_delete.h"
79 using namespace ARDOUR;
83 PluginManager* PluginManager::_manager = 0;
85 PluginManager::PluginManager ()
87 , _lxvst_plugin_info(0)
88 , _ladspa_plugin_info(0)
97 #ifdef HAVE_AUDIOUNITS
98 ProcessSerialNumber psn = { 0, kCurrentProcess };
99 OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
100 if( returnCode != 0) {
101 error << _("Cannot become GUI app") << endmsg;
105 if ((s = getenv ("LADSPA_RDF_PATH"))){
109 if (lrdf_path.length() == 0) {
110 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
113 add_lrdf_data(lrdf_path);
114 add_ladspa_presets();
116 if (Config->get_use_vst()) {
119 #endif /* VST_SUPPORT */
122 if (Config->get_use_lxvst()) {
125 #endif /* Native LinuxVST support*/
127 if ((s = getenv ("LADSPA_PATH"))) {
131 if ((s = getenv ("VST_PATH"))) {
133 } else if ((s = getenv ("VST_PLUGINS"))) {
137 if ((s = getenv ("LXVST_PATH"))) {
139 } else if ((s = getenv ("LXVST_PLUGINS"))) {
147 /* the plugin manager is constructed too early to use Profile */
149 if (getenv ("ARDOUR_SAE")) {
150 ladspa_plugin_whitelist.push_back (1203); // single band parametric
151 ladspa_plugin_whitelist.push_back (1772); // caps compressor
152 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
153 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
154 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
155 ladspa_plugin_whitelist.push_back (1216); // gverb
156 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
159 BootMessage (_("Discovering Plugins"));
163 PluginManager::~PluginManager()
169 PluginManager::refresh ()
176 if (Config->get_use_vst()) {
179 #endif // VST_SUPPORT
182 if(Config->get_use_lxvst()) {
185 #endif //Native linuxVST SUPPORT
187 #ifdef HAVE_AUDIOUNITS
191 PluginListChanged (); /* EMIT SIGNAL */
195 PluginManager::ladspa_refresh ()
197 if (_ladspa_plugin_info)
198 _ladspa_plugin_info->clear ();
200 _ladspa_plugin_info = new ARDOUR::PluginInfoList ();
202 static const char *standard_paths[] = {
203 "/usr/local/lib64/ladspa",
204 "/usr/local/lib/ladspa",
207 "/Library/Audio/Plug-Ins/LADSPA",
211 /* allow LADSPA_PATH to augment, not override standard locations */
213 /* Only add standard locations to ladspa_path if it doesn't
214 * already contain them. Check for trailing G_DIR_SEPARATOR too.
218 for (i = 0; standard_paths[i][0]; i++) {
219 size_t found = ladspa_path.find(standard_paths[i]);
220 if (found != ladspa_path.npos) {
221 switch (ladspa_path[found + strlen(standard_paths[i])]) {
225 case G_DIR_SEPARATOR :
226 if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
227 ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
232 if (!ladspa_path.empty())
235 ladspa_path += standard_paths[i];
239 ladspa_discover_from_path (ladspa_path);
244 PluginManager::add_ladspa_directory (string path)
246 if (ladspa_discover_from_path (path) == 0) {
254 static bool ladspa_filter (const string& str, void */*arg*/)
256 /* Not a dotfile, has a prefix before a period, suffix is "so" */
258 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
262 PluginManager::ladspa_discover_from_path (string /*path*/)
265 vector<string *> *plugin_objects;
266 vector<string *>::iterator x;
269 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
271 if (plugin_objects) {
272 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
273 ladspa_discover (**x);
277 vector_delete (plugin_objects);
281 static bool rdf_filter (const string &str, void* /*arg*/)
283 return str[0] != '.' &&
284 ((str.find(".rdf") == (str.length() - 4)) ||
285 (str.find(".rdfs") == (str.length() - 5)) ||
286 (str.find(".n3") == (str.length() - 3)) ||
287 (str.find(".ttl") == (str.length() - 4)));
291 PluginManager::add_ladspa_presets()
293 add_presets ("ladspa");
297 PluginManager::add_vst_presets()
303 PluginManager::add_lxvst_presets()
305 add_presets ("lxvst");
309 PluginManager::add_presets(string domain)
313 vector<string *> *presets;
314 vector<string *>::iterator x;
317 if ((envvar = getenv ("HOME")) == 0) {
321 string path = string_compose("%1/.%2/rdf", envvar, domain);
322 presets = scanner (path, rdf_filter, 0, true, true);
325 for (x = presets->begin(); x != presets->end (); ++x) {
326 string file = "file:" + **x;
327 if (lrdf_read_file(file.c_str())) {
328 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
333 vector_delete (presets);
337 PluginManager::add_lrdf_data (const string &path)
340 vector<string *>* rdf_files;
341 vector<string *>::iterator x;
343 rdf_files = scanner (path, rdf_filter, 0, true, true);
346 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
347 const string uri(string("file://") + **x);
349 if (lrdf_read_file(uri.c_str())) {
350 warning << "Could not parse rdf file: " << uri << endmsg;
355 vector_delete (rdf_files);
359 PluginManager::ladspa_discover (string path)
362 const LADSPA_Descriptor *descriptor;
363 LADSPA_Descriptor_Function dfunc;
366 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
367 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
371 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
373 if ((errstr = dlerror()) != 0) {
374 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
375 error << errstr << endmsg;
380 for (uint32_t i = 0; ; ++i) {
381 if ((descriptor = dfunc (i)) == 0) {
385 if (!ladspa_plugin_whitelist.empty()) {
386 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
391 PluginInfoPtr info(new LadspaPluginInfo);
392 info->name = descriptor->Name;
393 info->category = get_ladspa_category(descriptor->UniqueID);
394 info->creator = descriptor->Maker;
397 info->n_inputs = ChanCount();
398 info->n_outputs = ChanCount();
399 info->type = ARDOUR::LADSPA;
402 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
403 info->unique_id = buf;
405 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
406 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
407 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
408 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
410 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
411 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
416 if(_ladspa_plugin_info->empty()){
417 _ladspa_plugin_info->push_back (info);
420 //Ensure that the plugin is not already in the plugin list.
424 for (PluginInfoList::const_iterator i = _ladspa_plugin_info->begin(); i != _ladspa_plugin_info->end(); ++i) {
425 if(0 == info->unique_id.compare((*i)->unique_id)){
431 _ladspa_plugin_info->push_back (info);
435 // GDB WILL NOT LIKE YOU IF YOU DO THIS
442 PluginManager::get_ladspa_category (uint32_t plugin_id)
445 lrdf_statement pattern;
447 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
448 pattern.subject = buf;
449 pattern.predicate = (char*)RDF_TYPE;
451 pattern.object_type = lrdf_uri;
453 lrdf_statement* matches1 = lrdf_matches (&pattern);
459 pattern.subject = matches1->object;
460 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
462 pattern.object_type = lrdf_literal;
464 lrdf_statement* matches2 = lrdf_matches (&pattern);
465 lrdf_free_statements(matches1);
471 string label = matches2->object;
472 lrdf_free_statements(matches2);
474 /* Kludge LADSPA class names to be singular and match LV2 class names.
475 This avoids duplicate plugin menus for every class, which is necessary
476 to make the plugin category menu at all usable, but is obviously a
479 In the short term, lrdf could be updated so the labels match and a new
480 release made. To support both specs, we should probably be mapping the
481 URIs to the same category in code and perhaps tweaking that hierarchy
482 dynamically to suit the user. Personally, I (drobilla) think that time
483 is better spent replacing the little-used LRDF.
485 In the longer term, we will abandon LRDF entirely in favour of LV2 and
486 use that class hierarchy. Aside from fixing this problem properly, that
487 will also allow for translated labels. SWH plugins have been LV2 for
488 ages; TAP needs porting. I don't know of anything else with LRDF data.
490 if (label == "Utilities") {
492 } else if (label == "Pitch shifters") {
493 return "Pitch Shifter";
494 } else if (label != "Dynamics" && label != "Chorus"
495 &&label[label.length() - 1] == 's'
496 && label[label.length() - 2] != 's') {
497 return label.substr(0, label.length() - 1);
505 PluginManager::lv2_refresh ()
507 delete _lv2_plugin_info;
508 _lv2_plugin_info = LV2PluginInfo::discover();
512 #ifdef HAVE_AUDIOUNITS
514 PluginManager::au_refresh ()
516 delete _au_plugin_info;
517 _au_plugin_info = AUPluginInfo::discover();
525 PluginManager::vst_refresh ()
527 if (_vst_plugin_info)
528 _vst_plugin_info->clear ();
530 _vst_plugin_info = new ARDOUR::PluginInfoList();
532 if (vst_path.length() == 0) {
533 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
536 vst_discover_from_path (vst_path);
540 PluginManager::add_vst_directory (string path)
542 if (vst_discover_from_path (path) == 0) {
550 static bool vst_filter (const string& str, void *arg)
552 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
554 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
558 PluginManager::vst_discover_from_path (string path)
561 vector<string *> *plugin_objects;
562 vector<string *>::iterator x;
565 info << "detecting VST plugins along " << path << endmsg;
567 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
569 if (plugin_objects) {
570 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
575 vector_delete (plugin_objects);
580 PluginManager::vst_discover (string path)
585 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
586 warning << "Cannot get VST information from " << path << endmsg;
590 if (!finfo->canProcessReplacing) {
591 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
596 PluginInfoPtr info(new VSTPluginInfo);
598 /* what a joke freeware VST is */
600 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
601 info->name = PBD::basename_nosuffix (path);
603 info->name = finfo->name;
607 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
608 info->unique_id = buf;
609 info->category = "VST";
611 info->creator = finfo->creator;
613 info->n_inputs.set_audio (finfo->numInputs);
614 info->n_outputs.set_audio (finfo->numOutputs);
615 info->n_inputs.set_midi (finfo->wantMidi ? 1 : 0);
616 info->type = ARDOUR::VST;
618 _vst_plugin_info->push_back (info);
619 fst_free_info (finfo);
624 #endif // VST_SUPPORT
629 PluginManager::lxvst_refresh ()
631 if (_lxvst_plugin_info) {
632 _lxvst_plugin_info->clear ();
634 _lxvst_plugin_info = new ARDOUR::PluginInfoList();
637 if (lxvst_path.length() == 0) {
638 lxvst_path = "/usr/local/lib64/lxvst:/usr/local/lib/lxvst:/usr/lib64/lxvst:/usr/lib/lxvst";
641 lxvst_discover_from_path (lxvst_path);
645 PluginManager::add_lxvst_directory (string path)
647 if (lxvst_discover_from_path (path) == 0) {
655 static bool lxvst_filter (const string& str, void *)
657 /* Not a dotfile, has a prefix before a period, suffix is "so" */
659 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
663 PluginManager::lxvst_discover_from_path (string path)
666 vector<string *> *plugin_objects;
667 vector<string *>::iterator x;
670 info << "Discovering linuxVST plugins along " << path << endmsg;
672 plugin_objects = scanner (lxvst_path, lxvst_filter, 0, true, true);
674 if (plugin_objects) {
675 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
676 lxvst_discover (**x);
680 info << "Done linuxVST discover" << endmsg;
682 vector_delete (plugin_objects);
687 PluginManager::lxvst_discover (string path)
692 if ((finfo = vstfx_get_info (const_cast<char *> (path.c_str()))) == 0) {
693 warning << "Cannot get linuxVST information from " << path << endmsg;
697 if (!finfo->canProcessReplacing) {
698 warning << string_compose (_("linuxVST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
703 PluginInfoPtr info(new LXVSTPluginInfo);
705 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
706 info->name = PBD::basename_nosuffix (path);
708 info->name = finfo->name;
712 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
713 info->unique_id = buf;
714 info->category = "linuxVSTs";
716 info->creator = finfo->creator;
718 info->n_inputs.set_audio (finfo->numInputs);
719 info->n_outputs.set_audio (finfo->numOutputs);
720 info->n_inputs.set_midi (finfo->wantMidi ? 1 : 0);
721 info->type = ARDOUR::LXVST;
723 _lxvst_plugin_info->push_back (info);
724 vstfx_free_info (finfo);
729 #endif // LXVST_SUPPORT
732 PluginManager::PluginStatusType
733 PluginManager::get_status (const PluginInfoPtr& pi)
735 PluginStatus ps (pi->type, pi->unique_id);
736 PluginStatusList::const_iterator i = find (statuses.begin(), statuses.end(), ps);
737 if (i == statuses.end() ) {
745 PluginManager::save_statuses ()
748 sys::path path = user_config_directory();
749 path /= "plugin_statuses";
751 ofs.open (path.to_string().c_str(), ios_base::openmode (ios::out|ios::trunc));
757 for (PluginStatusList::iterator i = statuses.begin(); i != statuses.end(); ++i) {
778 switch ((*i).status) {
791 ofs << (*i).unique_id;;
799 PluginManager::load_statuses ()
801 sys::path path = user_config_directory();
802 path /= "plugin_statuses";
803 ifstream ifs (path.to_string().c_str());
813 PluginStatusType status;
830 /* rest of the line is the plugin ID */
832 ifs.getline (buf, sizeof (buf), '\n');
837 if (sstatus == "Normal") {
839 } else if (sstatus == "Favorite") {
841 } else if (sstatus == "Hidden") {
844 error << string_compose (_("unknown plugin status type \"%1\" - all entries ignored"), sstatus)
850 if (stype == "LADSPA") {
852 } else if (stype == "AudioUnit") {
854 } else if (stype == "LV2") {
856 } else if (stype == "VST") {
858 } else if (stype == "LXVST") {
861 error << string_compose (_("unknown plugin type \"%1\" - ignored"), stype)
867 strip_whitespace_edges (id);
868 set_status (type, id, status);
875 PluginManager::set_status (PluginType t, string id, PluginStatusType status)
877 PluginStatus ps (t, id, status);
880 if (status == Normal) {
884 statuses.insert (ps);
887 ARDOUR::PluginInfoList&
888 PluginManager::vst_plugin_info ()
891 if (!_vst_plugin_info)
893 return *_vst_plugin_info;
895 return _empty_plugin_info;
899 ARDOUR::PluginInfoList&
900 PluginManager::lxvst_plugin_info ()
903 if (!_lxvst_plugin_info)
905 return *_lxvst_plugin_info;
907 return _empty_plugin_info;
911 ARDOUR::PluginInfoList&
912 PluginManager::ladspa_plugin_info ()
914 if (!_ladspa_plugin_info)
916 return *_ladspa_plugin_info;
919 ARDOUR::PluginInfoList&
920 PluginManager::lv2_plugin_info ()
923 if (!_lv2_plugin_info)
925 return *_lv2_plugin_info;
927 return _empty_plugin_info;
931 ARDOUR::PluginInfoList&
932 PluginManager::au_plugin_info ()
934 #ifdef HAVE_AUDIOUNITS
935 if (!_au_plugin_info)
937 return *_au_plugin_info;
939 return _empty_plugin_info;