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 ();
156 static const char *standard_paths[] = {
157 "/usr/local/lib64/ladspa",
158 "/usr/local/lib/ladspa",
161 "/Library/Audio/Plug-Ins/LADSPA",
165 /* allow LADSPA_PATH to augment, not override standard locations */
167 /* Only add standard locations to ladspa_path if it doesn't
168 * already contain them. Check for trailing '/'s too.
172 for (i = 0; standard_paths[i][0]; i++) {
173 size_t found = ladspa_path.find(standard_paths[i]);
174 if (found != ladspa_path.npos) {
175 switch (ladspa_path[found + strlen(standard_paths[i])]) {
180 if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
181 ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
186 if (!ladspa_path.empty())
189 ladspa_path += standard_paths[i];
193 ladspa_discover_from_path (ladspa_path);
198 PluginManager::add_ladspa_directory (string path)
200 if (ladspa_discover_from_path (path) == 0) {
208 static bool ladspa_filter (const string& str, void *arg)
210 /* Not a dotfile, has a prefix before a period, suffix is "so" */
212 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
216 PluginManager::ladspa_discover_from_path (string path)
219 vector<string *> *plugin_objects;
220 vector<string *>::iterator x;
223 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
225 if (plugin_objects) {
226 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
227 ladspa_discover (**x);
231 vector_delete (plugin_objects);
235 static bool rdf_filter (const string &str, void *arg)
237 return str[0] != '.' &&
238 ((str.find(".rdf") == (str.length() - 4)) ||
239 (str.find(".rdfs") == (str.length() - 5)) ||
240 (str.find(".n3") == (str.length() - 3)));
244 PluginManager::add_ladspa_presets()
246 add_presets ("ladspa");
250 PluginManager::add_vst_presets()
255 PluginManager::add_presets(string domain)
259 vector<string *> *presets;
260 vector<string *>::iterator x;
263 if ((envvar = getenv ("HOME")) == 0) {
267 string path = string_compose("%1/.%2/rdf", envvar, domain);
268 presets = scanner (path, rdf_filter, 0, true, true);
271 for (x = presets->begin(); x != presets->end (); ++x) {
272 string file = "file:" + **x;
273 if (lrdf_read_file(file.c_str())) {
274 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
279 vector_delete (presets);
283 PluginManager::add_lrdf_data (const string &path)
286 vector<string *>* rdf_files;
287 vector<string *>::iterator x;
290 rdf_files = scanner (path, rdf_filter, 0, true, true);
293 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
294 uri = "file://" + **x;
296 if (lrdf_read_file(uri.c_str())) {
297 warning << "Could not parse rdf file: " << uri << endmsg;
302 vector_delete (rdf_files);
306 PluginManager::ladspa_discover (string path)
309 const LADSPA_Descriptor *descriptor;
310 LADSPA_Descriptor_Function dfunc;
313 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
314 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
318 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
320 if ((errstr = dlerror()) != 0) {
321 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
322 error << errstr << endmsg;
327 for (uint32_t i = 0; ; ++i) {
328 if ((descriptor = dfunc (i)) == 0) {
332 if (!ladspa_plugin_whitelist.empty()) {
333 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
338 PluginInfoPtr info(new LadspaPluginInfo);
339 info->name = descriptor->Name;
340 info->category = get_ladspa_category(descriptor->UniqueID);
341 info->creator = descriptor->Maker;
346 info->type = ARDOUR::LADSPA;
349 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
350 info->unique_id = buf;
352 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
353 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
354 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
357 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
363 if(_ladspa_plugin_info.empty()){
364 _ladspa_plugin_info.push_back (info);
367 //Ensure that the plugin is not already in the plugin list.
371 for (PluginInfoList::const_iterator i = _ladspa_plugin_info.begin(); i != _ladspa_plugin_info.end(); ++i) {
372 if(0 == info->unique_id.compare((*i)->unique_id)){
378 _ladspa_plugin_info.push_back (info);
382 // GDB WILL NOT LIKE YOU IF YOU DO THIS
389 PluginManager::get_ladspa_category (uint32_t plugin_id)
392 lrdf_statement pattern;
394 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
395 pattern.subject = buf;
396 pattern.predicate = (char*)RDF_TYPE;
398 pattern.object_type = lrdf_uri;
400 lrdf_statement* matches1 = lrdf_matches (&pattern);
406 pattern.subject = matches1->object;
407 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
409 pattern.object_type = lrdf_literal;
411 lrdf_statement* matches2 = lrdf_matches (&pattern);
412 lrdf_free_statements(matches1);
418 string label = matches2->object;
419 lrdf_free_statements(matches2);
426 PluginManager::lv2_refresh ()
432 PluginManager::lv2_discover ()
434 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
439 #ifdef HAVE_AUDIOUNITS
441 PluginManager::au_refresh ()
447 PluginManager::au_discover ()
449 _au_plugin_info = AUPluginInfo::discover();
458 PluginManager::vst_refresh ()
460 _vst_plugin_info.clear ();
462 if (vst_path.length() == 0) {
463 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
466 vst_discover_from_path (vst_path);
470 PluginManager::add_vst_directory (string path)
472 if (vst_discover_from_path (path) == 0) {
480 static bool vst_filter (const string& str, void *arg)
482 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
484 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
488 PluginManager::vst_discover_from_path (string path)
491 vector<string *> *plugin_objects;
492 vector<string *>::iterator x;
495 info << "detecting VST plugins along " << path << endmsg;
497 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
499 if (plugin_objects) {
500 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
501 std::cerr << " discovering " << **x << std::endl;
506 vector_delete (plugin_objects);
511 PluginManager::vst_discover (string path)
516 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
517 warning << "Cannot get VST information from " << path << endmsg;
521 if (!finfo->canProcessReplacing) {
522 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
527 PluginInfoPtr info(new VSTPluginInfo);
529 /* what a goddam joke freeware VST is */
531 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
532 info->name = PBD::basename_nosuffix (path);
534 info->name = finfo->name;
538 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
539 info->unique_id = buf;
540 info->category = "VST";
542 info->creator = finfo->creator;
544 info->n_inputs = finfo->numInputs;
545 info->n_outputs = finfo->numOutputs;
546 info->type = ARDOUR::VST;
548 _vst_plugin_info.push_back (info);
549 fst_free_info (finfo);
554 #endif // VST_SUPPORT
557 PluginManager::is_a_favorite_plugin (const PluginInfoPtr& pi)
559 FavoritePlugin fp (pi->type, pi->unique_id);
560 return find (favorites.begin(), favorites.end(), fp) != favorites.end();
564 PluginManager::save_favorites ()
566 Glib::ustring path = Glib::build_filename (get_user_ardour_path (), "favorite_plugins");
569 ofs.open (path.c_str(), ios_base::openmode (ios::out|ios::trunc));
575 for (FavoritePluginList::iterator i = favorites.begin(); i != favorites.end(); ++i) {
591 ofs << ' ' << (*i).unique_id << endl;
598 PluginManager::load_favorites ()
600 Glib::ustring path = Glib::build_filename (get_user_ardour_path (),"favorite_plugins");
602 ifstream ifs (path.c_str());
624 if (stype == "LADSPA") {
626 } else if (stype == "AudioUnit") {
628 } else if (stype == "LV2") {
630 } else if (stype == "VST") {
633 error << string_compose (_("unknown favorite plugin type \"%1\" - ignored"), stype)
638 add_favorite (type, id);
645 PluginManager::add_favorite (PluginType t, string id)
647 FavoritePlugin fp (t, id);
648 pair<FavoritePluginList::iterator,bool> res = favorites.insert (fp);
649 //cerr << "Added " << t << " " << id << " success ? " << res.second << endl;
653 PluginManager::remove_favorite (PluginType t, string id)
655 FavoritePlugin fp (t, id);
656 favorites.erase (fp);