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"
24 #define __STDC_FORMAT_MACROS 1
27 #include <sys/types.h>
36 #include "pbd/basename.h"
40 #include <glibmm/miscutils.h>
42 #include "pbd/pathscanner.h"
43 #include "pbd/whitespace.h"
45 #include "ardour/ladspa.h"
46 #include "ardour/session.h"
47 #include "ardour/plugin_manager.h"
48 #include "ardour/plugin.h"
49 #include "ardour/ladspa_plugin.h"
50 #include "ardour/filesystem_paths.h"
53 #include <slv2/slv2.h>
54 #include "ardour/lv2_plugin.h"
58 #include "ardour/vst_plugin.h"
61 #ifdef HAVE_AUDIOUNITS
62 #include "ardour/audio_unit.h"
63 #include <Carbon/Carbon.h>
66 #include "pbd/error.h"
67 #include "pbd/stl_delete.h"
71 using namespace ARDOUR;
75 PluginManager* PluginManager::_manager = 0;
77 PluginManager::PluginManager ()
79 , _ladspa_plugin_info(0)
88 #ifdef HAVE_AUDIOUNITS
89 ProcessSerialNumber psn = { 0, kCurrentProcess };
90 OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
91 if( returnCode != 0) {
92 error << _("Cannot become GUI app") << endmsg;
96 if ((s = getenv ("LADSPA_RDF_PATH"))){
100 if (lrdf_path.length() == 0) {
101 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
104 add_lrdf_data(lrdf_path);
105 add_ladspa_presets();
107 if (Config->get_use_vst()) {
110 #endif /* VST_SUPPORT */
112 if ((s = getenv ("LADSPA_PATH"))) {
116 if ((s = getenv ("VST_PATH"))) {
118 } else if ((s = getenv ("VST_PLUGINS"))) {
126 /* the plugin manager is constructed too early to use Profile */
128 if (getenv ("ARDOUR_SAE")) {
129 ladspa_plugin_whitelist.push_back (1203); // single band parametric
130 ladspa_plugin_whitelist.push_back (1772); // caps compressor
131 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
132 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
133 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
134 ladspa_plugin_whitelist.push_back (1216); // gverb
135 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
139 _lv2_world = new LV2World();
142 BootMessage (_("Discovering Plugins"));
146 PluginManager::~PluginManager()
153 PluginManager::refresh ()
160 if (Config->get_use_vst()) {
163 #endif // VST_SUPPORT
164 #ifdef HAVE_AUDIOUNITS
168 PluginListChanged (); /* EMIT SIGNAL */
172 PluginManager::ladspa_refresh ()
174 if (_ladspa_plugin_info)
175 _ladspa_plugin_info->clear ();
177 _ladspa_plugin_info = new ARDOUR::PluginInfoList ();
179 static const char *standard_paths[] = {
180 "/usr/local/lib64/ladspa",
181 "/usr/local/lib/ladspa",
184 "/Library/Audio/Plug-Ins/LADSPA",
188 /* allow LADSPA_PATH to augment, not override standard locations */
190 /* Only add standard locations to ladspa_path if it doesn't
191 * already contain them. Check for trailing '/'s too.
195 for (i = 0; standard_paths[i][0]; i++) {
196 size_t found = ladspa_path.find(standard_paths[i]);
197 if (found != ladspa_path.npos) {
198 switch (ladspa_path[found + strlen(standard_paths[i])]) {
203 if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
204 ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
209 if (!ladspa_path.empty())
212 ladspa_path += standard_paths[i];
216 ladspa_discover_from_path (ladspa_path);
221 PluginManager::add_ladspa_directory (string path)
223 if (ladspa_discover_from_path (path) == 0) {
231 static bool ladspa_filter (const string& str, void */*arg*/)
233 /* Not a dotfile, has a prefix before a period, suffix is "so" */
235 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
239 PluginManager::ladspa_discover_from_path (string /*path*/)
242 vector<string *> *plugin_objects;
243 vector<string *>::iterator x;
246 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
248 if (plugin_objects) {
249 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
250 ladspa_discover (**x);
254 vector_delete (plugin_objects);
258 static bool rdf_filter (const string &str, void* /*arg*/)
260 return str[0] != '.' &&
261 ((str.find(".rdf") == (str.length() - 4)) ||
262 (str.find(".rdfs") == (str.length() - 5)) ||
263 (str.find(".n3") == (str.length() - 3)) ||
264 (str.find(".ttl") == (str.length() - 4)));
268 PluginManager::add_ladspa_presets()
270 add_presets ("ladspa");
274 PluginManager::add_vst_presets()
279 PluginManager::add_presets(string domain)
283 vector<string *> *presets;
284 vector<string *>::iterator x;
287 if ((envvar = getenv ("HOME")) == 0) {
291 string path = string_compose("%1/.%2/rdf", envvar, domain);
292 presets = scanner (path, rdf_filter, 0, true, true);
295 for (x = presets->begin(); x != presets->end (); ++x) {
296 string file = "file:" + **x;
297 if (lrdf_read_file(file.c_str())) {
298 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
303 vector_delete (presets);
307 PluginManager::add_lrdf_data (const string &path)
310 vector<string *>* rdf_files;
311 vector<string *>::iterator x;
313 rdf_files = scanner (path, rdf_filter, 0, true, true);
316 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
317 const string uri(string("file://") + **x);
319 if (lrdf_read_file(uri.c_str())) {
320 warning << "Could not parse rdf file: " << uri << endmsg;
325 vector_delete (rdf_files);
329 PluginManager::ladspa_discover (string path)
332 const LADSPA_Descriptor *descriptor;
333 LADSPA_Descriptor_Function dfunc;
336 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
337 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
341 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
343 if ((errstr = dlerror()) != 0) {
344 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
345 error << errstr << endmsg;
350 for (uint32_t i = 0; ; ++i) {
351 if ((descriptor = dfunc (i)) == 0) {
355 if (!ladspa_plugin_whitelist.empty()) {
356 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
361 PluginInfoPtr info(new LadspaPluginInfo);
362 info->name = descriptor->Name;
363 info->category = get_ladspa_category(descriptor->UniqueID);
364 info->creator = descriptor->Maker;
367 info->n_inputs = ChanCount();
368 info->n_outputs = ChanCount();
369 info->type = ARDOUR::LADSPA;
372 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
373 info->unique_id = buf;
375 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
376 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
377 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
378 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
380 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
381 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
386 if(_ladspa_plugin_info->empty()){
387 _ladspa_plugin_info->push_back (info);
390 //Ensure that the plugin is not already in the plugin list.
394 for (PluginInfoList::const_iterator i = _ladspa_plugin_info->begin(); i != _ladspa_plugin_info->end(); ++i) {
395 if(0 == info->unique_id.compare((*i)->unique_id)){
401 _ladspa_plugin_info->push_back (info);
405 // GDB WILL NOT LIKE YOU IF YOU DO THIS
412 PluginManager::get_ladspa_category (uint32_t plugin_id)
415 lrdf_statement pattern;
417 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
418 pattern.subject = buf;
419 pattern.predicate = (char*)RDF_TYPE;
421 pattern.object_type = lrdf_uri;
423 lrdf_statement* matches1 = lrdf_matches (&pattern);
429 pattern.subject = matches1->object;
430 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
432 pattern.object_type = lrdf_literal;
434 lrdf_statement* matches2 = lrdf_matches (&pattern);
435 lrdf_free_statements(matches1);
441 string label = matches2->object;
442 lrdf_free_statements(matches2);
449 PluginManager::lv2_refresh ()
451 delete _lv2_plugin_info;
452 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
456 #ifdef HAVE_AUDIOUNITS
458 PluginManager::au_refresh ()
460 delete _au_plugin_info;
461 _au_plugin_info = AUPluginInfo::discover();
469 PluginManager::vst_refresh ()
471 if (_vst_plugin_info)
472 _vst_plugin_info->clear ();
474 _vst_plugin_info = new ARDOUR::PluginInfoList();
476 if (vst_path.length() == 0) {
477 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
480 vst_discover_from_path (vst_path);
484 PluginManager::add_vst_directory (string path)
486 if (vst_discover_from_path (path) == 0) {
494 static bool vst_filter (const string& str, void *arg)
496 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
498 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
502 PluginManager::vst_discover_from_path (string path)
505 vector<string *> *plugin_objects;
506 vector<string *>::iterator x;
509 info << "detecting VST plugins along " << path << endmsg;
511 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
513 if (plugin_objects) {
514 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
519 vector_delete (plugin_objects);
524 PluginManager::vst_discover (string path)
529 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
530 warning << "Cannot get VST information from " << path << endmsg;
534 if (!finfo->canProcessReplacing) {
535 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
540 PluginInfoPtr info(new VSTPluginInfo);
542 /* what a joke freeware VST is */
544 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
545 info->name = PBD::basename_nosuffix (path);
547 info->name = finfo->name;
551 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
552 info->unique_id = buf;
553 info->category = "VST";
555 info->creator = finfo->creator;
557 info->n_inputs.set_audio (finfo->numInputs);
558 info->n_outputs.set_audio (finfo->numOutputs);
559 info->type = ARDOUR::VST;
561 _vst_plugin_info->push_back (info);
562 fst_free_info (finfo);
567 #endif // VST_SUPPORT
569 PluginManager::PluginStatusType
570 PluginManager::get_status (const PluginInfoPtr& pi)
572 PluginStatus ps (pi->type, pi->unique_id);
573 PluginStatusList::const_iterator i = find (statuses.begin(), statuses.end(), ps);
574 if (i == statuses.end() ) {
582 PluginManager::save_statuses ()
585 sys::path path = user_config_directory();
586 path /= "plugin_statuses";
588 ofs.open (path.to_string().c_str(), ios_base::openmode (ios::out|ios::trunc));
594 for (PluginStatusList::iterator i = statuses.begin(); i != statuses.end(); ++i) {
612 switch ((*i).status) {
625 ofs << (*i).unique_id;;
633 PluginManager::load_statuses ()
635 sys::path path = user_config_directory();
636 path /= "plugin_statuses";
637 ifstream ifs (path.to_string().c_str());
647 PluginStatusType status;
664 /* rest of the line is the plugin ID */
666 ifs.getline (buf, sizeof (buf), '\n');
671 if (sstatus == "Normal") {
673 } else if (sstatus == "Favorite") {
675 } else if (sstatus == "Hidden") {
678 error << string_compose (_("unknown plugin status type \"%1\" - all entries ignored"), sstatus)
684 if (stype == "LADSPA") {
686 } else if (stype == "AudioUnit") {
688 } else if (stype == "LV2") {
690 } else if (stype == "VST") {
693 error << string_compose (_("unknown plugin type \"%1\" - ignored"), stype)
699 strip_whitespace_edges (id);
700 set_status (type, id, status);
707 PluginManager::set_status (PluginType t, string id, PluginStatusType status)
709 PluginStatus ps (t, id, status);
712 if (status == Normal) {
716 pair<PluginStatusList::iterator, bool> res = statuses.insert (ps);
717 //cerr << "Added " << t << " " << id << " " << status << " success ? " << res.second << endl;
720 ARDOUR::PluginInfoList&
721 PluginManager::vst_plugin_info ()
724 if (!_vst_plugin_info)
726 return *_vst_plugin_info;
728 return _empty_plugin_info;
732 ARDOUR::PluginInfoList&
733 PluginManager::ladspa_plugin_info ()
735 if (!_ladspa_plugin_info)
737 return *_ladspa_plugin_info;
740 ARDOUR::PluginInfoList&
741 PluginManager::lv2_plugin_info ()
744 if (!_lv2_plugin_info)
746 return *_lv2_plugin_info;
748 return _empty_plugin_info;
752 ARDOUR::PluginInfoList&
753 PluginManager::au_plugin_info ()
755 #ifdef HAVE_AUDIOUNITS
756 if (!_au_plugin_info)
758 return *_au_plugin_info;
760 return _empty_plugin_info;