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 ()
84 ProcessSerialNumber psn = { 0, kCurrentProcess };
85 OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
86 if( returnCode != 0) {
87 error << _("Cannot become GUI app") << endmsg;
91 if ((s = getenv ("LADSPA_RDF_PATH"))){
95 if (lrdf_path.length() == 0) {
96 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
99 add_lrdf_data(lrdf_path);
100 add_ladspa_presets();
102 if (Config->get_use_vst()) {
105 #endif /* VST_SUPPORT */
107 if ((s = getenv ("LADSPA_PATH"))) {
111 if ((s = getenv ("VST_PATH"))) {
113 } else if ((s = getenv ("VST_PLUGINS"))) {
121 /* the plugin manager is constructed too early to use Profile */
123 if (getenv ("ARDOUR_SAE")) {
124 ladspa_plugin_whitelist.push_back (1203); // single band parametric
125 ladspa_plugin_whitelist.push_back (1772); // caps compressor
126 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
127 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
128 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
129 ladspa_plugin_whitelist.push_back (1216); // gverb
130 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
134 _lv2_world = new LV2World();
137 BootMessage (_("Discovering Plugins"));
143 PluginManager::refresh ()
150 if (Config->get_use_vst()) {
153 #endif // VST_SUPPORT
154 #ifdef HAVE_AUDIOUNITS
160 PluginManager::ladspa_refresh ()
162 _ladspa_plugin_info.clear ();
164 static const char *standard_paths[] = {
165 "/usr/local/lib64/ladspa",
166 "/usr/local/lib/ladspa",
169 "/Library/Audio/Plug-Ins/LADSPA",
173 /* allow LADSPA_PATH to augment, not override standard locations */
175 /* Only add standard locations to ladspa_path if it doesn't
176 * already contain them. Check for trailing '/'s too.
180 for (i = 0; standard_paths[i][0]; i++) {
181 size_t found = ladspa_path.find(standard_paths[i]);
182 if (found != ladspa_path.npos) {
183 switch (ladspa_path[found + strlen(standard_paths[i])]) {
188 if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
189 ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
194 if (!ladspa_path.empty())
197 ladspa_path += standard_paths[i];
201 ladspa_discover_from_path (ladspa_path);
206 PluginManager::add_ladspa_directory (string path)
208 if (ladspa_discover_from_path (path) == 0) {
216 static bool ladspa_filter (const string& str, void *arg)
218 /* Not a dotfile, has a prefix before a period, suffix is "so" */
220 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
224 PluginManager::ladspa_discover_from_path (string path)
227 vector<string *> *plugin_objects;
228 vector<string *>::iterator x;
231 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
233 if (plugin_objects) {
234 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
235 ladspa_discover (**x);
239 vector_delete (plugin_objects);
243 static bool rdf_filter (const string &str, void *arg)
245 return str[0] != '.' &&
246 ((str.find(".rdf") == (str.length() - 4)) ||
247 (str.find(".rdfs") == (str.length() - 5)) ||
248 (str.find(".n3") == (str.length() - 3)));
252 PluginManager::add_ladspa_presets()
254 add_presets ("ladspa");
258 PluginManager::add_vst_presets()
263 PluginManager::add_presets(string domain)
267 vector<string *> *presets;
268 vector<string *>::iterator x;
271 if ((envvar = getenv ("HOME")) == 0) {
275 string path = string_compose("%1/.%2/rdf", envvar, domain);
276 presets = scanner (path, rdf_filter, 0, true, true);
279 for (x = presets->begin(); x != presets->end (); ++x) {
280 string file = "file:" + **x;
281 if (lrdf_read_file(file.c_str())) {
282 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
287 vector_delete (presets);
291 PluginManager::add_lrdf_data (const string &path)
294 vector<string *>* rdf_files;
295 vector<string *>::iterator x;
298 rdf_files = scanner (path, rdf_filter, 0, true, true);
301 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
302 uri = "file://" + **x;
304 if (lrdf_read_file(uri.c_str())) {
305 warning << "Could not parse rdf file: " << uri << endmsg;
310 vector_delete (rdf_files);
314 PluginManager::ladspa_discover (string path)
317 const LADSPA_Descriptor *descriptor;
318 LADSPA_Descriptor_Function dfunc;
321 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
322 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
326 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
328 if ((errstr = dlerror()) != 0) {
329 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
330 error << errstr << endmsg;
335 for (uint32_t i = 0; ; ++i) {
336 if ((descriptor = dfunc (i)) == 0) {
340 if (!ladspa_plugin_whitelist.empty()) {
341 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
346 PluginInfoPtr info(new LadspaPluginInfo);
347 info->name = descriptor->Name;
348 info->category = get_ladspa_category(descriptor->UniqueID);
349 info->creator = descriptor->Maker;
352 info->n_inputs = ChanCount();
353 info->n_outputs = ChanCount();
354 info->type = ARDOUR::LADSPA;
357 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
358 info->unique_id = buf;
360 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
361 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
362 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
363 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
365 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
366 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
371 if(_ladspa_plugin_info.empty()){
372 _ladspa_plugin_info.push_back (info);
375 //Ensure that the plugin is not already in the plugin list.
379 for (PluginInfoList::const_iterator i = _ladspa_plugin_info.begin(); i != _ladspa_plugin_info.end(); ++i) {
380 if(0 == info->unique_id.compare((*i)->unique_id)){
386 _ladspa_plugin_info.push_back (info);
390 // GDB WILL NOT LIKE YOU IF YOU DO THIS
397 PluginManager::get_ladspa_category (uint32_t plugin_id)
400 lrdf_statement pattern;
402 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
403 pattern.subject = buf;
404 pattern.predicate = (char*)RDF_TYPE;
406 pattern.object_type = lrdf_uri;
408 lrdf_statement* matches1 = lrdf_matches (&pattern);
414 pattern.subject = matches1->object;
415 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
417 pattern.object_type = lrdf_literal;
419 lrdf_statement* matches2 = lrdf_matches (&pattern);
420 lrdf_free_statements(matches1);
426 string label = matches2->object;
427 lrdf_free_statements(matches2);
434 PluginManager::lv2_refresh ()
440 PluginManager::lv2_discover ()
442 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
447 #ifdef HAVE_AUDIOUNITS
449 PluginManager::au_refresh ()
455 PluginManager::au_discover ()
457 _au_plugin_info = AUPluginInfo::discover();
466 PluginManager::vst_refresh ()
468 _vst_plugin_info.clear ();
470 if (vst_path.length() == 0) {
471 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
474 vst_discover_from_path (vst_path);
478 PluginManager::add_vst_directory (string path)
480 if (vst_discover_from_path (path) == 0) {
488 static bool vst_filter (const string& str, void *arg)
490 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
492 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
496 PluginManager::vst_discover_from_path (string path)
499 vector<string *> *plugin_objects;
500 vector<string *>::iterator x;
503 info << "detecting VST plugins along " << path << endmsg;
505 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
507 if (plugin_objects) {
508 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
513 vector_delete (plugin_objects);
518 PluginManager::vst_discover (string path)
523 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
524 warning << "Cannot get VST information from " << path << endmsg;
528 if (!finfo->canProcessReplacing) {
529 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
534 PluginInfoPtr info(new VSTPluginInfo);
536 /* what a joke freeware VST is */
538 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
539 info->name = PBD::basename_nosuffix (path);
541 info->name = finfo->name;
545 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
546 info->unique_id = buf;
547 info->category = "VST";
549 info->creator = finfo->creator;
551 info->n_inputs.set_audio (finfo->numInputs);
552 info->n_outputs.set_audio (finfo->numOutputs);
553 info->type = ARDOUR::VST;
555 _vst_plugin_info.push_back (info);
556 fst_free_info (finfo);
561 #endif // VST_SUPPORT
564 PluginManager::is_a_favorite_plugin (const PluginInfoPtr& pi)
566 FavoritePlugin fp (pi->type, pi->unique_id);
567 return find (favorites.begin(), favorites.end(), fp) != favorites.end();
571 PluginManager::save_favorites ()
574 sys::path path = user_config_directory();
575 path /= "favorite_plugins";
577 ofs.open (path.to_string().c_str(), ios_base::openmode (ios::out|ios::trunc));
583 for (FavoritePluginList::iterator i = favorites.begin(); i != favorites.end(); ++i) {
599 ofs << ' ' << (*i).unique_id << endl;
606 PluginManager::load_favorites ()
608 sys::path path = user_config_directory();
609 path /= "favorite_plugins";
610 ifstream ifs (path.to_string().c_str());
632 if (stype == "LADSPA") {
634 } else if (stype == "AudioUnit") {
636 } else if (stype == "LV2") {
638 } else if (stype == "VST") {
641 error << string_compose (_("unknown favorite plugin type \"%1\" - ignored"), stype)
646 add_favorite (type, id);
653 PluginManager::add_favorite (PluginType t, string id)
655 FavoritePlugin fp (t, id);
656 pair<FavoritePluginList::iterator,bool> res = favorites.insert (fp);
657 //cerr << "Added " << t << " " << id << " success ? " << res.second << endl;
661 PluginManager::remove_favorite (PluginType t, string id)
663 FavoritePlugin fp (t, id);
664 favorites.erase (fp);