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()
155 PluginManager::refresh ()
162 if (Config->get_use_vst()) {
165 #endif // VST_SUPPORT
166 #ifdef HAVE_AUDIOUNITS
170 PluginListChanged (); /* EMIT SIGNAL */
174 PluginManager::ladspa_refresh ()
176 if (_ladspa_plugin_info)
177 _ladspa_plugin_info->clear ();
179 _ladspa_plugin_info = new ARDOUR::PluginInfoList ();
181 static const char *standard_paths[] = {
182 "/usr/local/lib64/ladspa",
183 "/usr/local/lib/ladspa",
186 "/Library/Audio/Plug-Ins/LADSPA",
190 /* allow LADSPA_PATH to augment, not override standard locations */
192 /* Only add standard locations to ladspa_path if it doesn't
193 * already contain them. Check for trailing '/'s too.
197 for (i = 0; standard_paths[i][0]; i++) {
198 size_t found = ladspa_path.find(standard_paths[i]);
199 if (found != ladspa_path.npos) {
200 switch (ladspa_path[found + strlen(standard_paths[i])]) {
205 if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
206 ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
211 if (!ladspa_path.empty())
214 ladspa_path += standard_paths[i];
218 ladspa_discover_from_path (ladspa_path);
223 PluginManager::add_ladspa_directory (string path)
225 if (ladspa_discover_from_path (path) == 0) {
233 static bool ladspa_filter (const string& str, void */*arg*/)
235 /* Not a dotfile, has a prefix before a period, suffix is "so" */
237 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
241 PluginManager::ladspa_discover_from_path (string /*path*/)
244 vector<string *> *plugin_objects;
245 vector<string *>::iterator x;
248 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
250 if (plugin_objects) {
251 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
252 ladspa_discover (**x);
256 vector_delete (plugin_objects);
260 static bool rdf_filter (const string &str, void* /*arg*/)
262 return str[0] != '.' &&
263 ((str.find(".rdf") == (str.length() - 4)) ||
264 (str.find(".rdfs") == (str.length() - 5)) ||
265 (str.find(".n3") == (str.length() - 3)) ||
266 (str.find(".ttl") == (str.length() - 4)));
270 PluginManager::add_ladspa_presets()
272 add_presets ("ladspa");
276 PluginManager::add_vst_presets()
281 PluginManager::add_presets(string domain)
285 vector<string *> *presets;
286 vector<string *>::iterator x;
289 if ((envvar = getenv ("HOME")) == 0) {
293 string path = string_compose("%1/.%2/rdf", envvar, domain);
294 presets = scanner (path, rdf_filter, 0, true, true);
297 for (x = presets->begin(); x != presets->end (); ++x) {
298 string file = "file:" + **x;
299 if (lrdf_read_file(file.c_str())) {
300 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
305 vector_delete (presets);
309 PluginManager::add_lrdf_data (const string &path)
312 vector<string *>* rdf_files;
313 vector<string *>::iterator x;
315 rdf_files = scanner (path, rdf_filter, 0, true, true);
318 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
319 const string uri(string("file://") + **x);
321 if (lrdf_read_file(uri.c_str())) {
322 warning << "Could not parse rdf file: " << uri << endmsg;
327 vector_delete (rdf_files);
331 PluginManager::ladspa_discover (string path)
334 const LADSPA_Descriptor *descriptor;
335 LADSPA_Descriptor_Function dfunc;
338 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
339 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
343 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
345 if ((errstr = dlerror()) != 0) {
346 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
347 error << errstr << endmsg;
352 for (uint32_t i = 0; ; ++i) {
353 if ((descriptor = dfunc (i)) == 0) {
357 if (!ladspa_plugin_whitelist.empty()) {
358 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
363 PluginInfoPtr info(new LadspaPluginInfo);
364 info->name = descriptor->Name;
365 info->category = get_ladspa_category(descriptor->UniqueID);
366 info->creator = descriptor->Maker;
369 info->n_inputs = ChanCount();
370 info->n_outputs = ChanCount();
371 info->type = ARDOUR::LADSPA;
374 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
375 info->unique_id = buf;
377 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
378 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
379 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
380 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
382 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
383 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
388 if(_ladspa_plugin_info->empty()){
389 _ladspa_plugin_info->push_back (info);
392 //Ensure that the plugin is not already in the plugin list.
396 for (PluginInfoList::const_iterator i = _ladspa_plugin_info->begin(); i != _ladspa_plugin_info->end(); ++i) {
397 if(0 == info->unique_id.compare((*i)->unique_id)){
403 _ladspa_plugin_info->push_back (info);
407 // GDB WILL NOT LIKE YOU IF YOU DO THIS
414 PluginManager::get_ladspa_category (uint32_t plugin_id)
417 lrdf_statement pattern;
419 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
420 pattern.subject = buf;
421 pattern.predicate = (char*)RDF_TYPE;
423 pattern.object_type = lrdf_uri;
425 lrdf_statement* matches1 = lrdf_matches (&pattern);
431 pattern.subject = matches1->object;
432 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
434 pattern.object_type = lrdf_literal;
436 lrdf_statement* matches2 = lrdf_matches (&pattern);
437 lrdf_free_statements(matches1);
443 string label = matches2->object;
444 lrdf_free_statements(matches2);
451 PluginManager::lv2_refresh ()
453 delete _lv2_plugin_info;
454 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
458 #ifdef HAVE_AUDIOUNITS
460 PluginManager::au_refresh ()
462 delete _au_plugin_info;
463 _au_plugin_info = AUPluginInfo::discover();
471 PluginManager::vst_refresh ()
473 if (_vst_plugin_info)
474 _vst_plugin_info->clear ();
476 _vst_plugin_info = new ARDOUR::PluginInfoList();
478 if (vst_path.length() == 0) {
479 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
482 vst_discover_from_path (vst_path);
486 PluginManager::add_vst_directory (string path)
488 if (vst_discover_from_path (path) == 0) {
496 static bool vst_filter (const string& str, void *arg)
498 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
500 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
504 PluginManager::vst_discover_from_path (string path)
507 vector<string *> *plugin_objects;
508 vector<string *>::iterator x;
511 info << "detecting VST plugins along " << path << endmsg;
513 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
515 if (plugin_objects) {
516 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
521 vector_delete (plugin_objects);
526 PluginManager::vst_discover (string path)
531 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
532 warning << "Cannot get VST information from " << path << endmsg;
536 if (!finfo->canProcessReplacing) {
537 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
542 PluginInfoPtr info(new VSTPluginInfo);
544 /* what a joke freeware VST is */
546 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
547 info->name = PBD::basename_nosuffix (path);
549 info->name = finfo->name;
553 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
554 info->unique_id = buf;
555 info->category = "VST";
557 info->creator = finfo->creator;
559 info->n_inputs.set_audio (finfo->numInputs);
560 info->n_outputs.set_audio (finfo->numOutputs);
561 info->n_inputs.set_midi (finfo->wantMidi ? 1 : 0);
562 info->type = ARDOUR::VST;
564 _vst_plugin_info->push_back (info);
565 fst_free_info (finfo);
570 #endif // VST_SUPPORT
572 PluginManager::PluginStatusType
573 PluginManager::get_status (const PluginInfoPtr& pi)
575 PluginStatus ps (pi->type, pi->unique_id);
576 PluginStatusList::const_iterator i = find (statuses.begin(), statuses.end(), ps);
577 if (i == statuses.end() ) {
585 PluginManager::save_statuses ()
588 sys::path path = user_config_directory();
589 path /= "plugin_statuses";
591 ofs.open (path.to_string().c_str(), ios_base::openmode (ios::out|ios::trunc));
597 for (PluginStatusList::iterator i = statuses.begin(); i != statuses.end(); ++i) {
615 switch ((*i).status) {
628 ofs << (*i).unique_id;;
636 PluginManager::load_statuses ()
638 sys::path path = user_config_directory();
639 path /= "plugin_statuses";
640 ifstream ifs (path.to_string().c_str());
650 PluginStatusType status;
667 /* rest of the line is the plugin ID */
669 ifs.getline (buf, sizeof (buf), '\n');
674 if (sstatus == "Normal") {
676 } else if (sstatus == "Favorite") {
678 } else if (sstatus == "Hidden") {
681 error << string_compose (_("unknown plugin status type \"%1\" - all entries ignored"), sstatus)
687 if (stype == "LADSPA") {
689 } else if (stype == "AudioUnit") {
691 } else if (stype == "LV2") {
693 } else if (stype == "VST") {
696 error << string_compose (_("unknown plugin type \"%1\" - ignored"), stype)
702 strip_whitespace_edges (id);
703 set_status (type, id, status);
710 PluginManager::set_status (PluginType t, string id, PluginStatusType status)
712 PluginStatus ps (t, id, status);
715 if (status == Normal) {
719 pair<PluginStatusList::iterator, bool> res = statuses.insert (ps);
720 //cerr << "Added " << t << " " << id << " " << status << " success ? " << res.second << endl;
723 ARDOUR::PluginInfoList&
724 PluginManager::vst_plugin_info ()
727 if (!_vst_plugin_info)
729 return *_vst_plugin_info;
731 return _empty_plugin_info;
735 ARDOUR::PluginInfoList&
736 PluginManager::ladspa_plugin_info ()
738 if (!_ladspa_plugin_info)
740 return *_ladspa_plugin_info;
743 ARDOUR::PluginInfoList&
744 PluginManager::lv2_plugin_info ()
747 if (!_lv2_plugin_info)
749 return *_lv2_plugin_info;
751 return _empty_plugin_info;
755 ARDOUR::PluginInfoList&
756 PluginManager::au_plugin_info ()
758 #ifdef HAVE_AUDIOUNITS
759 if (!_au_plugin_info)
761 return *_au_plugin_info;
763 return _empty_plugin_info;