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>
56 #include <pbd/error.h>
57 #include <pbd/stl_delete.h>
61 using namespace ARDOUR;
65 PluginManager* PluginManager::_manager = 0;
67 PluginManager::PluginManager ()
74 if ((s = getenv ("LADSPA_RDF_PATH"))){
78 if (lrdf_path.length() == 0) {
79 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
82 add_lrdf_data(lrdf_path);
85 if (Config->get_use_vst()) {
88 #endif /* VST_SUPPORT */
90 if ((s = getenv ("LADSPA_PATH"))) {
94 if ((s = getenv ("VST_PATH"))) {
96 } else if ((s = getenv ("VST_PLUGINS"))) {
104 /* the plugin manager is constructed too early to use Profile */
106 if (getenv ("ARDOUR_SAE")) {
107 ladspa_plugin_whitelist.push_back (1203); // single band parametric
108 ladspa_plugin_whitelist.push_back (1772); // caps compressor
109 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
110 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
111 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
112 ladspa_plugin_whitelist.push_back (1216); // gverb
113 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
117 _lv2_world = new LV2World();
124 PluginManager::refresh ()
131 if (Config->get_use_vst()) {
134 #endif // VST_SUPPORT
135 #ifdef HAVE_AUDIOUNITS
141 PluginManager::ladspa_refresh ()
143 _ladspa_plugin_info.clear ();
145 if (ladspa_path.length() == 0) {
146 ladspa_path = "/usr/local/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib64/ladspa:/usr/lib/ladspa:/Library/Audio/Plug-Ins/LADSPA";
149 ladspa_discover_from_path (ladspa_path);
154 PluginManager::add_ladspa_directory (string path)
156 if (ladspa_discover_from_path (path) == 0) {
164 static bool ladspa_filter (const string& str, void *arg)
166 /* Not a dotfile, has a prefix before a period, suffix is "so" */
168 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
172 PluginManager::ladspa_discover_from_path (string path)
175 vector<string *> *plugin_objects;
176 vector<string *>::iterator x;
179 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
181 if (plugin_objects) {
182 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
183 ladspa_discover (**x);
187 vector_delete (plugin_objects);
191 static bool rdf_filter (const string &str, void *arg)
193 return str[0] != '.' &&
194 ((str.find(".rdf") == (str.length() - 4)) ||
195 (str.find(".rdfs") == (str.length() - 5)) ||
196 (str.find(".n3") == (str.length() - 3)));
200 PluginManager::add_ladspa_presets()
202 add_presets ("ladspa");
206 PluginManager::add_vst_presets()
211 PluginManager::add_presets(string domain)
215 vector<string *> *presets;
216 vector<string *>::iterator x;
219 if ((envvar = getenv ("HOME")) == 0) {
223 string path = string_compose("%1/.%2/rdf", envvar, domain);
224 presets = scanner (path, rdf_filter, 0, true, true);
227 for (x = presets->begin(); x != presets->end (); ++x) {
228 string file = "file:" + **x;
229 if (lrdf_read_file(file.c_str())) {
230 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
235 vector_delete (presets);
239 PluginManager::add_lrdf_data (const string &path)
242 vector<string *>* rdf_files;
243 vector<string *>::iterator x;
246 rdf_files = scanner (path, rdf_filter, 0, true, true);
249 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
250 uri = "file://" + **x;
252 if (lrdf_read_file(uri.c_str())) {
253 warning << "Could not parse rdf file: " << uri << endmsg;
258 vector_delete (rdf_files);
262 PluginManager::ladspa_discover (string path)
265 const LADSPA_Descriptor *descriptor;
266 LADSPA_Descriptor_Function dfunc;
269 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
270 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
274 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
276 if ((errstr = dlerror()) != 0) {
277 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
278 error << errstr << endmsg;
283 for (uint32_t i = 0; ; ++i) {
284 if ((descriptor = dfunc (i)) == 0) {
288 if (!ladspa_plugin_whitelist.empty()) {
289 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
294 PluginInfoPtr info(new LadspaPluginInfo);
295 info->name = descriptor->Name;
296 info->category = get_ladspa_category(descriptor->UniqueID);
297 info->creator = descriptor->Maker;
302 info->type = ARDOUR::LADSPA;
305 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
306 info->unique_id = buf;
308 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
309 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
310 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
313 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
319 _ladspa_plugin_info.push_back (info);
322 // GDB WILL NOT LIKE YOU IF YOU DO THIS
329 PluginManager::get_ladspa_category (uint32_t plugin_id)
332 lrdf_statement pattern;
334 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
335 pattern.subject = buf;
336 pattern.predicate = (char*)RDF_TYPE;
338 pattern.object_type = lrdf_uri;
340 lrdf_statement* matches1 = lrdf_matches (&pattern);
346 pattern.subject = matches1->object;
347 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
349 pattern.object_type = lrdf_literal;
351 lrdf_statement* matches2 = lrdf_matches (&pattern);
352 lrdf_free_statements(matches1);
358 string label = matches2->object;
359 lrdf_free_statements(matches2);
366 PluginManager::lv2_refresh ()
372 PluginManager::lv2_discover ()
374 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
379 #ifdef HAVE_AUDIOUNITS
381 PluginManager::au_refresh ()
387 PluginManager::au_discover ()
389 _au_plugin_info = AUPluginInfo::discover();
398 PluginManager::vst_refresh ()
400 _vst_plugin_info.clear ();
402 if (vst_path.length() == 0) {
403 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
406 vst_discover_from_path (vst_path);
410 PluginManager::add_vst_directory (string path)
412 if (vst_discover_from_path (path) == 0) {
420 static bool vst_filter (const string& str, void *arg)
422 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
424 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
428 PluginManager::vst_discover_from_path (string path)
431 vector<string *> *plugin_objects;
432 vector<string *>::iterator x;
435 info << "detecting VST plugins along " << path << endmsg;
437 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
439 if (plugin_objects) {
440 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
445 vector_delete (plugin_objects);
450 PluginManager::vst_discover (string path)
455 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
456 warning << "Cannot get VST information from " << path << endmsg;
460 if (!finfo->canProcessReplacing) {
461 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
466 PluginInfoPtr info(new VSTPluginInfo);
468 /* what a goddam joke freeware VST is */
470 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
471 info->name = PBD::basename_nosuffix (path);
473 info->name = finfo->name;
477 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
478 info->unique_id = buf;
479 info->category = "VST";
481 // need to set info->creator but FST doesn't provide it
483 info->n_inputs = finfo->numInputs;
484 info->n_outputs = finfo->numOutputs;
485 info->type = ARDOUR::VST;
487 _vst_plugin_info.push_back (info);
488 fst_free_info (finfo);
493 #endif // VST_SUPPORT
496 PluginManager::is_a_favorite_plugin (const PluginInfoPtr& pi)
498 FavoritePlugin fp (pi->type, pi->unique_id);
499 return find (favorites.begin(), favorites.end(), fp) != favorites.end();
503 PluginManager::save_favorites ()
505 Glib::ustring path = Glib::build_filename (get_user_ardour_path (), "favorite_plugins");
508 ofs.open (path.c_str(), ios_base::openmode (ios::out|ios::trunc));
514 for (FavoritePluginList::iterator i = favorites.begin(); i != favorites.end(); ++i) {
530 ofs << ' ' << (*i).unique_id << endl;
537 PluginManager::load_favorites ()
539 Glib::ustring path = Glib::build_filename (get_user_ardour_path (),"favorite_plugins");
541 ifstream ifs (path.c_str());
563 if (stype == "LADSPA") {
565 } else if (stype == "AudioUnit") {
567 } else if (stype == "LV2") {
569 } else if (stype == "VST") {
572 error << string_compose (_("unknown favorite plugin type \"%1\" - ignored"), stype)
577 add_favorite (type, id);
584 PluginManager::add_favorite (PluginType t, string id)
586 FavoritePlugin fp (t, id);
587 pair<FavoritePluginList::iterator,bool> res = favorites.insert (fp);
588 cerr << "Added " << t << " " << id << " success ? " << res.second << endl;
592 PluginManager::remove_favorite (PluginType t, string id)
594 FavoritePlugin fp (t, id);
595 favorites.erase (fp);