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"
44 #include "ardour/ladspa.h"
45 #include "ardour/session.h"
46 #include "ardour/plugin_manager.h"
47 #include "ardour/plugin.h"
48 #include "ardour/ladspa_plugin.h"
49 #include "ardour/filesystem_paths.h"
52 #include <slv2/slv2.h>
53 #include "ardour/lv2_plugin.h"
57 #include "ardour/vst_plugin.h"
60 #ifdef HAVE_AUDIOUNITS
61 #include "ardour/audio_unit.h"
62 #include <Carbon/Carbon.h>
65 #include "pbd/error.h"
66 #include "pbd/stl_delete.h"
70 using namespace ARDOUR;
74 PluginManager* PluginManager::_manager = 0;
76 PluginManager::PluginManager ()
78 , _ladspa_plugin_info(0)
87 #ifdef HAVE_AUDIOUNITS
88 ProcessSerialNumber psn = { 0, kCurrentProcess };
89 OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
90 if( returnCode != 0) {
91 error << _("Cannot become GUI app") << endmsg;
95 if ((s = getenv ("LADSPA_RDF_PATH"))){
99 if (lrdf_path.length() == 0) {
100 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
103 add_lrdf_data(lrdf_path);
104 add_ladspa_presets();
106 if (Config->get_use_vst()) {
109 #endif /* VST_SUPPORT */
111 if ((s = getenv ("LADSPA_PATH"))) {
115 if ((s = getenv ("VST_PATH"))) {
117 } else if ((s = getenv ("VST_PLUGINS"))) {
125 /* the plugin manager is constructed too early to use Profile */
127 if (getenv ("ARDOUR_SAE")) {
128 ladspa_plugin_whitelist.push_back (1203); // single band parametric
129 ladspa_plugin_whitelist.push_back (1772); // caps compressor
130 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
131 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
132 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
133 ladspa_plugin_whitelist.push_back (1216); // gverb
134 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
138 _lv2_world = new LV2World();
141 BootMessage (_("Discovering Plugins"));
145 PluginManager::refresh ()
152 if (Config->get_use_vst()) {
155 #endif // VST_SUPPORT
156 #ifdef HAVE_AUDIOUNITS
160 PluginListChanged (); /* EMIT SIGNAL */
164 PluginManager::ladspa_refresh ()
166 if (_ladspa_plugin_info)
167 _ladspa_plugin_info->clear ();
169 _ladspa_plugin_info = new ARDOUR::PluginInfoList ();
171 static const char *standard_paths[] = {
172 "/usr/local/lib64/ladspa",
173 "/usr/local/lib/ladspa",
176 "/Library/Audio/Plug-Ins/LADSPA",
180 /* allow LADSPA_PATH to augment, not override standard locations */
182 /* Only add standard locations to ladspa_path if it doesn't
183 * already contain them. Check for trailing '/'s too.
187 for (i = 0; standard_paths[i][0]; i++) {
188 size_t found = ladspa_path.find(standard_paths[i]);
189 if (found != ladspa_path.npos) {
190 switch (ladspa_path[found + strlen(standard_paths[i])]) {
195 if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
196 ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
201 if (!ladspa_path.empty())
204 ladspa_path += standard_paths[i];
208 ladspa_discover_from_path (ladspa_path);
213 PluginManager::add_ladspa_directory (string path)
215 if (ladspa_discover_from_path (path) == 0) {
223 static bool ladspa_filter (const string& str, void */*arg*/)
225 /* Not a dotfile, has a prefix before a period, suffix is "so" */
227 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
231 PluginManager::ladspa_discover_from_path (string /*path*/)
234 vector<string *> *plugin_objects;
235 vector<string *>::iterator x;
238 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
240 if (plugin_objects) {
241 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
242 ladspa_discover (**x);
246 vector_delete (plugin_objects);
250 static bool rdf_filter (const string &str, void* /*arg*/)
252 return str[0] != '.' &&
253 ((str.find(".rdf") == (str.length() - 4)) ||
254 (str.find(".rdfs") == (str.length() - 5)) ||
255 (str.find(".n3") == (str.length() - 3)) ||
256 (str.find(".ttl") == (str.length() - 4)));
260 PluginManager::add_ladspa_presets()
262 add_presets ("ladspa");
266 PluginManager::add_vst_presets()
271 PluginManager::add_presets(string domain)
275 vector<string *> *presets;
276 vector<string *>::iterator x;
279 if ((envvar = getenv ("HOME")) == 0) {
283 string path = string_compose("%1/.%2/rdf", envvar, domain);
284 presets = scanner (path, rdf_filter, 0, true, true);
287 for (x = presets->begin(); x != presets->end (); ++x) {
288 string file = "file:" + **x;
289 if (lrdf_read_file(file.c_str())) {
290 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
295 vector_delete (presets);
299 PluginManager::add_lrdf_data (const string &path)
302 vector<string *>* rdf_files;
303 vector<string *>::iterator x;
306 rdf_files = scanner (path, rdf_filter, 0, true, true);
309 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
310 uri = "file://" + **x;
312 if (lrdf_read_file(uri.c_str())) {
313 warning << "Could not parse rdf file: " << uri << endmsg;
318 vector_delete (rdf_files);
322 PluginManager::ladspa_discover (string path)
325 const LADSPA_Descriptor *descriptor;
326 LADSPA_Descriptor_Function dfunc;
329 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
330 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
334 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
336 if ((errstr = dlerror()) != 0) {
337 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
338 error << errstr << endmsg;
343 for (uint32_t i = 0; ; ++i) {
344 if ((descriptor = dfunc (i)) == 0) {
348 if (!ladspa_plugin_whitelist.empty()) {
349 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
354 PluginInfoPtr info(new LadspaPluginInfo);
355 info->name = descriptor->Name;
356 info->category = get_ladspa_category(descriptor->UniqueID);
357 info->creator = descriptor->Maker;
360 info->n_inputs = ChanCount();
361 info->n_outputs = ChanCount();
362 info->type = ARDOUR::LADSPA;
365 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
366 info->unique_id = buf;
368 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
369 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
370 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
371 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
373 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
374 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
379 if(_ladspa_plugin_info->empty()){
380 _ladspa_plugin_info->push_back (info);
383 //Ensure that the plugin is not already in the plugin list.
387 for (PluginInfoList::const_iterator i = _ladspa_plugin_info->begin(); i != _ladspa_plugin_info->end(); ++i) {
388 if(0 == info->unique_id.compare((*i)->unique_id)){
394 _ladspa_plugin_info->push_back (info);
398 // GDB WILL NOT LIKE YOU IF YOU DO THIS
405 PluginManager::get_ladspa_category (uint32_t plugin_id)
408 lrdf_statement pattern;
410 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
411 pattern.subject = buf;
412 pattern.predicate = (char*)RDF_TYPE;
414 pattern.object_type = lrdf_uri;
416 lrdf_statement* matches1 = lrdf_matches (&pattern);
422 pattern.subject = matches1->object;
423 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
425 pattern.object_type = lrdf_literal;
427 lrdf_statement* matches2 = lrdf_matches (&pattern);
428 lrdf_free_statements(matches1);
434 string label = matches2->object;
435 lrdf_free_statements(matches2);
442 PluginManager::lv2_refresh ()
444 delete _lv2_plugin_info;
445 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
449 #ifdef HAVE_AUDIOUNITS
451 PluginManager::au_refresh ()
453 delete _au_plugin_info;
454 _au_plugin_info = AUPluginInfo::discover();
462 PluginManager::vst_refresh ()
464 if (_vst_plugin_info)
465 _vst_plugin_info->clear ();
467 _vst_plugin_info = new ARDOUR::PluginInfoList();
469 if (vst_path.length() == 0) {
470 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
473 vst_discover_from_path (vst_path);
477 PluginManager::add_vst_directory (string path)
479 if (vst_discover_from_path (path) == 0) {
487 static bool vst_filter (const string& str, void *arg)
489 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
491 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
495 PluginManager::vst_discover_from_path (string path)
498 vector<string *> *plugin_objects;
499 vector<string *>::iterator x;
502 info << "detecting VST plugins along " << path << endmsg;
504 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
506 if (plugin_objects) {
507 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
512 vector_delete (plugin_objects);
517 PluginManager::vst_discover (string path)
522 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
523 warning << "Cannot get VST information from " << path << endmsg;
527 if (!finfo->canProcessReplacing) {
528 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
533 PluginInfoPtr info(new VSTPluginInfo);
535 /* what a joke freeware VST is */
537 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
538 info->name = PBD::basename_nosuffix (path);
540 info->name = finfo->name;
544 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
545 info->unique_id = buf;
546 info->category = "VST";
548 info->creator = finfo->creator;
550 info->n_inputs.set_audio (finfo->numInputs);
551 info->n_outputs.set_audio (finfo->numOutputs);
552 info->type = ARDOUR::VST;
554 _vst_plugin_info->push_back (info);
555 fst_free_info (finfo);
560 #endif // VST_SUPPORT
562 PluginManager::PluginStatusType
563 PluginManager::get_status (const PluginInfoPtr& pi)
565 PluginStatus ps (pi->type, pi->unique_id);
566 PluginStatusList::const_iterator i = find (statuses.begin(), statuses.end(), ps);
567 if (i == statuses.end() ) {
575 PluginManager::save_statuses ()
578 sys::path path = user_config_directory();
579 path /= "plugin_statuses";
581 ofs.open (path.to_string().c_str(), ios_base::openmode (ios::out|ios::trunc));
587 for (PluginStatusList::iterator i = statuses.begin(); i != statuses.end(); ++i) {
603 ofs << ' ' << (*i).unique_id << ' ';
605 switch ((*i).status) {
624 PluginManager::load_statuses ()
626 sys::path path = user_config_directory();
627 path /= "plugin_statuses";
628 ifstream ifs (path.to_string().c_str());
638 PluginStatusType status;
658 if (stype == "LADSPA") {
660 } else if (stype == "AudioUnit") {
662 } else if (stype == "LV2") {
664 } else if (stype == "VST") {
667 error << string_compose (_("unknown plugin type \"%1\" - ignored"), stype)
671 if (sstatus == "Normal") {
673 } else if (sstatus == "Favorite") {
675 } else if (sstatus == "Hidden") {
678 error << string_compose (_("unknown plugin status type \"%1\" - ignored"), stype)
683 set_status (type, id, status);
690 PluginManager::set_status (PluginType t, string id, PluginStatusType status)
692 PluginStatus ps (t, id, status);
695 if (status == Normal) {
699 pair<PluginStatusList::iterator, bool> res = statuses.insert (ps);
700 //cerr << "Added " << t << " " << id << " " << status << " success ? " << res.second << endl;
703 ARDOUR::PluginInfoList&
704 PluginManager::vst_plugin_info ()
707 if (!_vst_plugin_info)
709 return *_vst_plugin_info;
711 return _empty_plugin_info;
715 ARDOUR::PluginInfoList&
716 PluginManager::ladspa_plugin_info ()
718 if (!_ladspa_plugin_info)
720 return *_ladspa_plugin_info;
723 ARDOUR::PluginInfoList&
724 PluginManager::lv2_plugin_info ()
727 if (!_lv2_plugin_info)
729 return *_lv2_plugin_info;
731 return _empty_plugin_info;
735 ARDOUR::PluginInfoList&
736 PluginManager::au_plugin_info ()
738 #ifdef HAVE_AUDIOUNITS
739 if (!_au_plugin_info)
741 return *_au_plugin_info;
743 return _empty_plugin_info;