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 #define __STDC_FORMAT_MACROS 1
23 #include <sys/types.h>
32 #include "pbd/basename.h"
36 #include <glibmm/miscutils.h>
38 #include "pbd/pathscanner.h"
40 #include "ardour/ladspa.h"
41 #include "ardour/session.h"
42 #include "ardour/plugin_manager.h"
43 #include "ardour/plugin.h"
44 #include "ardour/ladspa_plugin.h"
45 #include "ardour/filesystem_paths.h"
48 #include <slv2/slv2.h>
49 #include "ardour/lv2_plugin.h"
53 #include "ardour/vst_plugin.h"
56 #ifdef HAVE_AUDIOUNITS
57 #include "ardour/audio_unit.h"
58 #include <Carbon/Carbon.h>
61 #include "pbd/error.h"
62 #include "pbd/stl_delete.h"
66 using namespace ARDOUR;
70 PluginManager* PluginManager::_manager = 0;
72 PluginManager::PluginManager ()
80 ProcessSerialNumber psn = { 0, kCurrentProcess };
81 OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
82 if( returnCode != 0) {
83 error << _("Cannot become GUI app") << endmsg;
87 if ((s = getenv ("LADSPA_RDF_PATH"))){
91 if (lrdf_path.length() == 0) {
92 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
95 add_lrdf_data(lrdf_path);
98 if (Config->get_use_vst()) {
101 #endif /* VST_SUPPORT */
103 if ((s = getenv ("LADSPA_PATH"))) {
107 if ((s = getenv ("VST_PATH"))) {
109 } else if ((s = getenv ("VST_PLUGINS"))) {
117 /* the plugin manager is constructed too early to use Profile */
119 if (getenv ("ARDOUR_SAE")) {
120 ladspa_plugin_whitelist.push_back (1203); // single band parametric
121 ladspa_plugin_whitelist.push_back (1772); // caps compressor
122 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
123 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
124 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
125 ladspa_plugin_whitelist.push_back (1216); // gverb
126 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
130 _lv2_world = new LV2World();
133 BootMessage (_("Discovering Plugins"));
139 PluginManager::refresh ()
146 if (Config->get_use_vst()) {
149 #endif // VST_SUPPORT
150 #ifdef HAVE_AUDIOUNITS
156 PluginManager::ladspa_refresh ()
158 _ladspa_plugin_info.clear ();
160 static const char *standard_paths[] = {
161 "/usr/local/lib64/ladspa",
162 "/usr/local/lib/ladspa",
165 "/Library/Audio/Plug-Ins/LADSPA",
169 /* allow LADSPA_PATH to augment, not override standard locations */
171 /* Only add standard locations to ladspa_path if it doesn't
172 * already contain them. Check for trailing '/'s too.
176 for (i = 0; standard_paths[i][0]; i++) {
177 size_t found = ladspa_path.find(standard_paths[i]);
178 if (found != ladspa_path.npos) {
179 switch (ladspa_path[found + strlen(standard_paths[i])]) {
184 if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
185 ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
190 if (!ladspa_path.empty())
193 ladspa_path += standard_paths[i];
197 ladspa_discover_from_path (ladspa_path);
202 PluginManager::add_ladspa_directory (string path)
204 if (ladspa_discover_from_path (path) == 0) {
212 static bool ladspa_filter (const string& str, void *arg)
214 /* Not a dotfile, has a prefix before a period, suffix is "so" */
216 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
220 PluginManager::ladspa_discover_from_path (string path)
223 vector<string *> *plugin_objects;
224 vector<string *>::iterator x;
227 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
229 if (plugin_objects) {
230 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
231 ladspa_discover (**x);
235 vector_delete (plugin_objects);
239 static bool rdf_filter (const string &str, void *arg)
241 return str[0] != '.' &&
242 ((str.find(".rdf") == (str.length() - 4)) ||
243 (str.find(".rdfs") == (str.length() - 5)) ||
244 (str.find(".n3") == (str.length() - 3)));
248 PluginManager::add_ladspa_presets()
250 add_presets ("ladspa");
254 PluginManager::add_vst_presets()
259 PluginManager::add_presets(string domain)
263 vector<string *> *presets;
264 vector<string *>::iterator x;
267 if ((envvar = getenv ("HOME")) == 0) {
271 string path = string_compose("%1/.%2/rdf", envvar, domain);
272 presets = scanner (path, rdf_filter, 0, true, true);
275 for (x = presets->begin(); x != presets->end (); ++x) {
276 string file = "file:" + **x;
277 if (lrdf_read_file(file.c_str())) {
278 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
283 vector_delete (presets);
287 PluginManager::add_lrdf_data (const string &path)
290 vector<string *>* rdf_files;
291 vector<string *>::iterator x;
294 rdf_files = scanner (path, rdf_filter, 0, true, true);
297 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
298 uri = "file://" + **x;
300 if (lrdf_read_file(uri.c_str())) {
301 warning << "Could not parse rdf file: " << uri << endmsg;
306 vector_delete (rdf_files);
310 PluginManager::ladspa_discover (string path)
313 const LADSPA_Descriptor *descriptor;
314 LADSPA_Descriptor_Function dfunc;
317 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
318 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
322 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
324 if ((errstr = dlerror()) != 0) {
325 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
326 error << errstr << endmsg;
331 for (uint32_t i = 0; ; ++i) {
332 if ((descriptor = dfunc (i)) == 0) {
336 if (!ladspa_plugin_whitelist.empty()) {
337 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
342 PluginInfoPtr info(new LadspaPluginInfo);
343 info->name = descriptor->Name;
344 info->category = get_ladspa_category(descriptor->UniqueID);
345 info->creator = descriptor->Maker;
348 info->n_inputs = ChanCount();
349 info->n_outputs = ChanCount();
350 info->type = ARDOUR::LADSPA;
353 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
354 info->unique_id = buf;
356 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
357 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
358 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
359 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
361 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
362 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
367 if(_ladspa_plugin_info.empty()){
368 _ladspa_plugin_info.push_back (info);
371 //Ensure that the plugin is not already in the plugin list.
375 for (PluginInfoList::const_iterator i = _ladspa_plugin_info.begin(); i != _ladspa_plugin_info.end(); ++i) {
376 if(0 == info->unique_id.compare((*i)->unique_id)){
382 _ladspa_plugin_info.push_back (info);
386 // GDB WILL NOT LIKE YOU IF YOU DO THIS
393 PluginManager::get_ladspa_category (uint32_t plugin_id)
396 lrdf_statement pattern;
398 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
399 pattern.subject = buf;
400 pattern.predicate = (char*)RDF_TYPE;
402 pattern.object_type = lrdf_uri;
404 lrdf_statement* matches1 = lrdf_matches (&pattern);
410 pattern.subject = matches1->object;
411 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
413 pattern.object_type = lrdf_literal;
415 lrdf_statement* matches2 = lrdf_matches (&pattern);
416 lrdf_free_statements(matches1);
422 string label = matches2->object;
423 lrdf_free_statements(matches2);
430 PluginManager::lv2_refresh ()
436 PluginManager::lv2_discover ()
438 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
443 #ifdef HAVE_AUDIOUNITS
445 PluginManager::au_refresh ()
451 PluginManager::au_discover ()
453 _au_plugin_info = AUPluginInfo::discover();
462 PluginManager::vst_refresh ()
464 _vst_plugin_info.clear ();
466 if (vst_path.length() == 0) {
467 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
470 vst_discover_from_path (vst_path);
474 PluginManager::add_vst_directory (string path)
476 if (vst_discover_from_path (path) == 0) {
484 static bool vst_filter (const string& str, void *arg)
486 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
488 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
492 PluginManager::vst_discover_from_path (string path)
495 vector<string *> *plugin_objects;
496 vector<string *>::iterator x;
499 info << "detecting VST plugins along " << path << endmsg;
501 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
503 if (plugin_objects) {
504 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
509 vector_delete (plugin_objects);
514 PluginManager::vst_discover (string path)
519 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
520 warning << "Cannot get VST information from " << path << endmsg;
524 if (!finfo->canProcessReplacing) {
525 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
530 PluginInfoPtr info(new VSTPluginInfo);
532 /* what a joke freeware VST is */
534 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
535 info->name = PBD::basename_nosuffix (path);
537 info->name = finfo->name;
541 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
542 info->unique_id = buf;
543 info->category = "VST";
545 info->creator = finfo->creator;
547 info->n_inputs.set_audio (finfo->numInputs);
548 info->n_outputs.set_audio (finfo->numOutputs);
549 info->type = ARDOUR::VST;
551 _vst_plugin_info.push_back (info);
552 fst_free_info (finfo);
557 #endif // VST_SUPPORT
560 PluginManager::is_a_favorite_plugin (const PluginInfoPtr& pi)
562 FavoritePlugin fp (pi->type, pi->unique_id);
563 return find (favorites.begin(), favorites.end(), fp) != favorites.end();
567 PluginManager::save_favorites ()
570 sys::path path = user_config_directory();
571 path /= "favorite_plugins";
573 ofs.open (path.to_string().c_str(), ios_base::openmode (ios::out|ios::trunc));
579 for (FavoritePluginList::iterator i = favorites.begin(); i != favorites.end(); ++i) {
595 ofs << ' ' << (*i).unique_id << endl;
602 PluginManager::load_favorites ()
604 sys::path path = user_config_directory();
605 path /= "favorite_plugins";
606 ifstream ifs (path.to_string().c_str());
628 if (stype == "LADSPA") {
630 } else if (stype == "AudioUnit") {
632 } else if (stype == "LV2") {
634 } else if (stype == "VST") {
637 error << string_compose (_("unknown favorite plugin type \"%1\" - ignored"), stype)
642 add_favorite (type, id);
649 PluginManager::add_favorite (PluginType t, string id)
651 FavoritePlugin fp (t, id);
652 pair<FavoritePluginList::iterator,bool> res = favorites.insert (fp);
653 //cerr << "Added " << t << " " << id << " success ? " << res.second << endl;
657 PluginManager::remove_favorite (PluginType t, string id)
659 FavoritePlugin fp (t, id);
660 favorites.erase (fp);