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
162 PluginManager::ladspa_refresh ()
164 if (_ladspa_plugin_info)
165 _ladspa_plugin_info->clear ();
167 _ladspa_plugin_info = new ARDOUR::PluginInfoList ();
169 static const char *standard_paths[] = {
170 "/usr/local/lib64/ladspa",
171 "/usr/local/lib/ladspa",
174 "/Library/Audio/Plug-Ins/LADSPA",
178 /* allow LADSPA_PATH to augment, not override standard locations */
180 /* Only add standard locations to ladspa_path if it doesn't
181 * already contain them. Check for trailing '/'s too.
185 for (i = 0; standard_paths[i][0]; i++) {
186 size_t found = ladspa_path.find(standard_paths[i]);
187 if (found != ladspa_path.npos) {
188 switch (ladspa_path[found + strlen(standard_paths[i])]) {
193 if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
194 ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
199 if (!ladspa_path.empty())
202 ladspa_path += standard_paths[i];
206 ladspa_discover_from_path (ladspa_path);
211 PluginManager::add_ladspa_directory (string path)
213 if (ladspa_discover_from_path (path) == 0) {
221 static bool ladspa_filter (const string& str, void */*arg*/)
223 /* Not a dotfile, has a prefix before a period, suffix is "so" */
225 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
229 PluginManager::ladspa_discover_from_path (string /*path*/)
232 vector<string *> *plugin_objects;
233 vector<string *>::iterator x;
236 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
238 if (plugin_objects) {
239 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
240 ladspa_discover (**x);
244 vector_delete (plugin_objects);
248 static bool rdf_filter (const string &str, void* /*arg*/)
250 return str[0] != '.' &&
251 ((str.find(".rdf") == (str.length() - 4)) ||
252 (str.find(".rdfs") == (str.length() - 5)) ||
253 (str.find(".n3") == (str.length() - 3)) ||
254 (str.find(".ttl") == (str.length() - 4)));
258 PluginManager::add_ladspa_presets()
260 add_presets ("ladspa");
264 PluginManager::add_vst_presets()
269 PluginManager::add_presets(string domain)
273 vector<string *> *presets;
274 vector<string *>::iterator x;
277 if ((envvar = getenv ("HOME")) == 0) {
281 string path = string_compose("%1/.%2/rdf", envvar, domain);
282 presets = scanner (path, rdf_filter, 0, true, true);
285 for (x = presets->begin(); x != presets->end (); ++x) {
286 string file = "file:" + **x;
287 if (lrdf_read_file(file.c_str())) {
288 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
293 vector_delete (presets);
297 PluginManager::add_lrdf_data (const string &path)
300 vector<string *>* rdf_files;
301 vector<string *>::iterator x;
304 rdf_files = scanner (path, rdf_filter, 0, true, true);
307 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
308 uri = "file://" + **x;
310 if (lrdf_read_file(uri.c_str())) {
311 warning << "Could not parse rdf file: " << uri << endmsg;
316 vector_delete (rdf_files);
320 PluginManager::ladspa_discover (string path)
323 const LADSPA_Descriptor *descriptor;
324 LADSPA_Descriptor_Function dfunc;
327 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
328 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
332 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
334 if ((errstr = dlerror()) != 0) {
335 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
336 error << errstr << endmsg;
341 for (uint32_t i = 0; ; ++i) {
342 if ((descriptor = dfunc (i)) == 0) {
346 if (!ladspa_plugin_whitelist.empty()) {
347 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
352 PluginInfoPtr info(new LadspaPluginInfo);
353 info->name = descriptor->Name;
354 info->category = get_ladspa_category(descriptor->UniqueID);
355 info->creator = descriptor->Maker;
358 info->n_inputs = ChanCount();
359 info->n_outputs = ChanCount();
360 info->type = ARDOUR::LADSPA;
363 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
364 info->unique_id = buf;
366 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
367 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
368 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
369 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
371 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
372 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
377 if(_ladspa_plugin_info->empty()){
378 _ladspa_plugin_info->push_back (info);
381 //Ensure that the plugin is not already in the plugin list.
385 for (PluginInfoList::const_iterator i = _ladspa_plugin_info->begin(); i != _ladspa_plugin_info->end(); ++i) {
386 if(0 == info->unique_id.compare((*i)->unique_id)){
392 _ladspa_plugin_info->push_back (info);
396 // GDB WILL NOT LIKE YOU IF YOU DO THIS
403 PluginManager::get_ladspa_category (uint32_t plugin_id)
406 lrdf_statement pattern;
408 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
409 pattern.subject = buf;
410 pattern.predicate = (char*)RDF_TYPE;
412 pattern.object_type = lrdf_uri;
414 lrdf_statement* matches1 = lrdf_matches (&pattern);
420 pattern.subject = matches1->object;
421 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
423 pattern.object_type = lrdf_literal;
425 lrdf_statement* matches2 = lrdf_matches (&pattern);
426 lrdf_free_statements(matches1);
432 string label = matches2->object;
433 lrdf_free_statements(matches2);
440 PluginManager::lv2_refresh ()
442 delete _lv2_plugin_info;
443 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
447 #ifdef HAVE_AUDIOUNITS
449 PluginManager::au_refresh ()
451 delete _au_plugin_info;
452 _au_plugin_info = AUPluginInfo::discover();
460 PluginManager::vst_refresh ()
462 if (_vst_plugin_info)
463 _vst_plugin_info->clear ();
465 _vst_plugin_info = new ARDOUR::PluginInfoList();
467 if (vst_path.length() == 0) {
468 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
471 vst_discover_from_path (vst_path);
475 PluginManager::add_vst_directory (string path)
477 if (vst_discover_from_path (path) == 0) {
485 static bool vst_filter (const string& str, void *arg)
487 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
489 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
493 PluginManager::vst_discover_from_path (string path)
496 vector<string *> *plugin_objects;
497 vector<string *>::iterator x;
500 info << "detecting VST plugins along " << path << endmsg;
502 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
504 if (plugin_objects) {
505 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
510 vector_delete (plugin_objects);
515 PluginManager::vst_discover (string path)
520 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
521 warning << "Cannot get VST information from " << path << endmsg;
525 if (!finfo->canProcessReplacing) {
526 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
531 PluginInfoPtr info(new VSTPluginInfo);
533 /* what a joke freeware VST is */
535 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
536 info->name = PBD::basename_nosuffix (path);
538 info->name = finfo->name;
542 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
543 info->unique_id = buf;
544 info->category = "VST";
546 info->creator = finfo->creator;
548 info->n_inputs.set_audio (finfo->numInputs);
549 info->n_outputs.set_audio (finfo->numOutputs);
550 info->type = ARDOUR::VST;
552 _vst_plugin_info->push_back (info);
553 fst_free_info (finfo);
558 #endif // VST_SUPPORT
561 PluginManager::is_a_favorite_plugin (const PluginInfoPtr& pi)
563 FavoritePlugin fp (pi->type, pi->unique_id);
564 return find (favorites.begin(), favorites.end(), fp) != favorites.end();
568 PluginManager::save_favorites ()
571 sys::path path = user_config_directory();
572 path /= "favorite_plugins";
574 ofs.open (path.to_string().c_str(), ios_base::openmode (ios::out|ios::trunc));
580 for (FavoritePluginList::iterator i = favorites.begin(); i != favorites.end(); ++i) {
596 ofs << ' ' << (*i).unique_id << endl;
603 PluginManager::load_favorites ()
605 sys::path path = user_config_directory();
606 path /= "favorite_plugins";
607 ifstream ifs (path.to_string().c_str());
629 if (stype == "LADSPA") {
631 } else if (stype == "AudioUnit") {
633 } else if (stype == "LV2") {
635 } else if (stype == "VST") {
638 error << string_compose (_("unknown favorite plugin type \"%1\" - ignored"), stype)
643 add_favorite (type, id);
650 PluginManager::add_favorite (PluginType t, string id)
652 FavoritePlugin fp (t, id);
653 pair<FavoritePluginList::iterator,bool> res = favorites.insert (fp);
654 //cerr << "Added " << t << " " << id << " success ? " << res.second << endl;
658 PluginManager::remove_favorite (PluginType t, string id)
660 FavoritePlugin fp (t, id);
661 favorites.erase (fp);
664 ARDOUR::PluginInfoList&
665 PluginManager::vst_plugin_info ()
668 if (!_vst_plugin_info)
670 return *_vst_plugin_info;
672 return _empty_plugin_info;
676 ARDOUR::PluginInfoList&
677 PluginManager::ladspa_plugin_info ()
679 if (!_ladspa_plugin_info)
681 return *_ladspa_plugin_info;
684 ARDOUR::PluginInfoList&
685 PluginManager::lv2_plugin_info ()
688 if (!_lv2_plugin_info)
690 return *_lv2_plugin_info;
692 return _empty_plugin_info;
696 ARDOUR::PluginInfoList&
697 PluginManager::au_plugin_info ()
699 #ifdef HAVE_AUDIOUNITS
700 if (!_au_plugin_info)
702 return *_au_plugin_info;
704 return _empty_plugin_info;