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.
20 #include <sys/types.h>
29 #include <pbd/basename.h>
33 #include <glibmm/miscutils.h>
35 #include <pbd/pathscanner.h>
37 #include <ardour/ladspa.h>
38 #include <ardour/session.h>
39 #include <ardour/plugin_manager.h>
40 #include <ardour/plugin.h>
41 #include <ardour/ladspa_plugin.h>
44 #include <slv2/slv2.h>
45 #include <ardour/lv2_plugin.h>
49 #include <ardour/vst_plugin.h>
52 #ifdef HAVE_AUDIOUNITS
53 #include <ardour/audio_unit.h>
54 #include <Carbon/Carbon.h>
57 #include <pbd/error.h>
58 #include <pbd/stl_delete.h>
62 using namespace ARDOUR;
66 PluginManager* PluginManager::_manager = 0;
68 PluginManager::PluginManager ()
76 ProcessSerialNumber psn = { 0, kCurrentProcess };
77 OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
78 if( returnCode != 0) {
79 error << _("Cannot become GUI app") << endmsg;
83 if ((s = getenv ("LADSPA_RDF_PATH"))){
87 if (lrdf_path.length() == 0) {
88 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
91 add_lrdf_data(lrdf_path);
94 if (Config->get_use_vst()) {
97 #endif /* VST_SUPPORT */
99 if ((s = getenv ("LADSPA_PATH"))) {
103 if ((s = getenv ("VST_PATH"))) {
105 } else if ((s = getenv ("VST_PLUGINS"))) {
113 /* the plugin manager is constructed too early to use Profile */
115 if (getenv ("ARDOUR_SAE")) {
116 ladspa_plugin_whitelist.push_back (1203); // single band parametric
117 ladspa_plugin_whitelist.push_back (1772); // caps compressor
118 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
119 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
120 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
121 ladspa_plugin_whitelist.push_back (1216); // gverb
122 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
126 _lv2_world = new LV2World();
129 BootMessage (_("Discovering Plugins"));
135 PluginManager::refresh ()
142 if (Config->get_use_vst()) {
145 #endif // VST_SUPPORT
146 #ifdef HAVE_AUDIOUNITS
152 PluginManager::ladspa_refresh ()
154 _ladspa_plugin_info.clear ();
155 static const char *standard_path = "/usr/local/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib64/ladspa:/usr/lib/ladspa:/Library/Audio/Plug-Ins/LADSPA";
157 /* allow LADSPA_PATH to augment, not override standard locations */
159 if (ladspa_path.empty()) {
160 ladspa_path = standard_path;
163 ladspa_path += standard_path;
166 ladspa_discover_from_path (ladspa_path);
171 PluginManager::add_ladspa_directory (string path)
173 if (ladspa_discover_from_path (path) == 0) {
181 static bool ladspa_filter (const string& str, void *arg)
183 /* Not a dotfile, has a prefix before a period, suffix is "so" */
185 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
189 PluginManager::ladspa_discover_from_path (string path)
192 vector<string *> *plugin_objects;
193 vector<string *>::iterator x;
196 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
198 if (plugin_objects) {
199 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
200 ladspa_discover (**x);
204 vector_delete (plugin_objects);
208 static bool rdf_filter (const string &str, void *arg)
210 return str[0] != '.' &&
211 ((str.find(".rdf") == (str.length() - 4)) ||
212 (str.find(".rdfs") == (str.length() - 5)) ||
213 (str.find(".n3") == (str.length() - 3)));
217 PluginManager::add_ladspa_presets()
219 add_presets ("ladspa");
223 PluginManager::add_vst_presets()
228 PluginManager::add_presets(string domain)
232 vector<string *> *presets;
233 vector<string *>::iterator x;
236 if ((envvar = getenv ("HOME")) == 0) {
240 string path = string_compose("%1/.%2/rdf", envvar, domain);
241 presets = scanner (path, rdf_filter, 0, true, true);
244 for (x = presets->begin(); x != presets->end (); ++x) {
245 string file = "file:" + **x;
246 if (lrdf_read_file(file.c_str())) {
247 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
252 vector_delete (presets);
256 PluginManager::add_lrdf_data (const string &path)
259 vector<string *>* rdf_files;
260 vector<string *>::iterator x;
263 rdf_files = scanner (path, rdf_filter, 0, true, true);
266 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
267 uri = "file://" + **x;
269 if (lrdf_read_file(uri.c_str())) {
270 warning << "Could not parse rdf file: " << uri << endmsg;
275 vector_delete (rdf_files);
279 PluginManager::ladspa_discover (string path)
282 const LADSPA_Descriptor *descriptor;
283 LADSPA_Descriptor_Function dfunc;
286 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
287 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
291 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
293 if ((errstr = dlerror()) != 0) {
294 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
295 error << errstr << endmsg;
300 for (uint32_t i = 0; ; ++i) {
301 if ((descriptor = dfunc (i)) == 0) {
305 if (!ladspa_plugin_whitelist.empty()) {
306 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
311 PluginInfoPtr info(new LadspaPluginInfo);
312 info->name = descriptor->Name;
313 info->category = get_ladspa_category(descriptor->UniqueID);
314 info->creator = descriptor->Maker;
319 info->type = ARDOUR::LADSPA;
322 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
323 info->unique_id = buf;
325 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
326 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
327 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
330 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
336 _ladspa_plugin_info.push_back (info);
339 // GDB WILL NOT LIKE YOU IF YOU DO THIS
346 PluginManager::get_ladspa_category (uint32_t plugin_id)
349 lrdf_statement pattern;
351 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
352 pattern.subject = buf;
353 pattern.predicate = (char*)RDF_TYPE;
355 pattern.object_type = lrdf_uri;
357 lrdf_statement* matches1 = lrdf_matches (&pattern);
363 pattern.subject = matches1->object;
364 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
366 pattern.object_type = lrdf_literal;
368 lrdf_statement* matches2 = lrdf_matches (&pattern);
369 lrdf_free_statements(matches1);
375 string label = matches2->object;
376 lrdf_free_statements(matches2);
383 PluginManager::lv2_refresh ()
389 PluginManager::lv2_discover ()
391 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
396 #ifdef HAVE_AUDIOUNITS
398 PluginManager::au_refresh ()
404 PluginManager::au_discover ()
406 _au_plugin_info = AUPluginInfo::discover();
415 PluginManager::vst_refresh ()
417 _vst_plugin_info.clear ();
419 if (vst_path.length() == 0) {
420 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
423 vst_discover_from_path (vst_path);
427 PluginManager::add_vst_directory (string path)
429 if (vst_discover_from_path (path) == 0) {
437 static bool vst_filter (const string& str, void *arg)
439 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
441 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
445 PluginManager::vst_discover_from_path (string path)
448 vector<string *> *plugin_objects;
449 vector<string *>::iterator x;
452 info << "detecting VST plugins along " << path << endmsg;
454 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
456 if (plugin_objects) {
457 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
462 vector_delete (plugin_objects);
467 PluginManager::vst_discover (string path)
472 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
473 warning << "Cannot get VST information from " << path << endmsg;
477 if (!finfo->canProcessReplacing) {
478 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
483 PluginInfoPtr info(new VSTPluginInfo);
485 /* what a goddam joke freeware VST is */
487 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
488 info->name = PBD::basename_nosuffix (path);
490 info->name = finfo->name;
494 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
495 info->unique_id = buf;
496 info->category = "VST";
498 // need to set info->creator but FST doesn't provide it
500 info->n_inputs = finfo->numInputs;
501 info->n_outputs = finfo->numOutputs;
502 info->type = ARDOUR::VST;
504 _vst_plugin_info.push_back (info);
505 fst_free_info (finfo);
510 #endif // VST_SUPPORT
513 PluginManager::is_a_favorite_plugin (const PluginInfoPtr& pi)
515 FavoritePlugin fp (pi->type, pi->unique_id);
516 return find (favorites.begin(), favorites.end(), fp) != favorites.end();
520 PluginManager::save_favorites ()
522 Glib::ustring path = Glib::build_filename (get_user_ardour_path (), "favorite_plugins");
525 ofs.open (path.c_str(), ios_base::openmode (ios::out|ios::trunc));
531 for (FavoritePluginList::iterator i = favorites.begin(); i != favorites.end(); ++i) {
547 ofs << ' ' << (*i).unique_id << endl;
554 PluginManager::load_favorites ()
556 Glib::ustring path = Glib::build_filename (get_user_ardour_path (),"favorite_plugins");
558 ifstream ifs (path.c_str());
580 if (stype == "LADSPA") {
582 } else if (stype == "AudioUnit") {
584 } else if (stype == "LV2") {
586 } else if (stype == "VST") {
589 error << string_compose (_("unknown favorite plugin type \"%1\" - ignored"), stype)
594 add_favorite (type, id);
601 PluginManager::add_favorite (PluginType t, string id)
603 FavoritePlugin fp (t, id);
604 pair<FavoritePluginList::iterator,bool> res = favorites.insert (fp);
605 //cerr << "Added " << t << " " << id << " success ? " << res.second << endl;
609 PluginManager::remove_favorite (PluginType t, string id)
611 FavoritePlugin fp (t, id);
612 favorites.erase (fp);