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>
27 #include <pbd/basename.h>
31 #include <pbd/pathscanner.h>
33 #include <ardour/ladspa.h>
34 #include <ardour/session.h>
35 #include <ardour/plugin_manager.h>
36 #include <ardour/plugin.h>
37 #include <ardour/ladspa_plugin.h>
40 #include <slv2/slv2.h>
41 #include <ardour/lv2_plugin.h>
45 #include <ardour/vst_plugin.h>
48 #ifdef HAVE_AUDIOUNITS
49 #include <ardour/audio_unit.h>
52 #include <pbd/error.h>
53 #include <pbd/stl_delete.h>
57 using namespace ARDOUR;
60 PluginManager* PluginManager::_manager = 0;
62 PluginManager::PluginManager ()
67 if ((s = getenv ("LADSPA_RDF_PATH"))){
71 if (lrdf_path.length() == 0) {
72 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
75 add_lrdf_data(lrdf_path);
78 if (Config->get_use_vst()) {
81 #endif /* VST_SUPPORT */
83 if ((s = getenv ("LADSPA_PATH"))) {
87 if ((s = getenv ("VST_PATH"))) {
89 } else if ((s = getenv ("VST_PLUGINS"))) {
97 /* the plugin manager is constructed too early to use Profile */
99 if (getenv ("ARDOUR_SAE")) {
100 ladspa_plugin_whitelist.push_back (1203); // single band parametric
101 ladspa_plugin_whitelist.push_back (1772); // caps compressor
102 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
103 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
104 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
105 ladspa_plugin_whitelist.push_back (1216); // gverb
106 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
109 _lv2_world = slv2_world_new();
110 slv2_world_load_all(_lv2_world);
116 PluginManager::refresh ()
123 if (Config->get_use_vst()) {
126 #endif // VST_SUPPORT
127 #ifdef HAVE_AUDIOUNITS
133 PluginManager::ladspa_refresh ()
135 _ladspa_plugin_info.clear ();
137 if (ladspa_path.length() == 0) {
138 ladspa_path = "/usr/local/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib64/ladspa:/usr/lib/ladspa:/Library/Audio/Plug-Ins/LADSPA";
141 ladspa_discover_from_path (ladspa_path);
146 PluginManager::add_ladspa_directory (string path)
148 if (ladspa_discover_from_path (path) == 0) {
156 static bool ladspa_filter (const string& str, void *arg)
158 /* Not a dotfile, has a prefix before a period, suffix is "so" */
160 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
164 PluginManager::ladspa_discover_from_path (string path)
167 vector<string *> *plugin_objects;
168 vector<string *>::iterator x;
171 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
173 if (plugin_objects) {
174 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
175 ladspa_discover (**x);
179 vector_delete (plugin_objects);
183 static bool rdf_filter (const string &str, void *arg)
185 return str[0] != '.' &&
186 ((str.find(".rdf") == (str.length() - 4)) ||
187 (str.find(".rdfs") == (str.length() - 5)) ||
188 (str.find(".n3") == (str.length() - 3)));
192 PluginManager::add_ladspa_presets()
194 add_presets ("ladspa");
198 PluginManager::add_vst_presets()
203 PluginManager::add_presets(string domain)
207 vector<string *> *presets;
208 vector<string *>::iterator x;
211 if ((envvar = getenv ("HOME")) == 0) {
215 string path = string_compose("%1/.%2/rdf", envvar, domain);
216 presets = scanner (path, rdf_filter, 0, true, true);
219 for (x = presets->begin(); x != presets->end (); ++x) {
220 string file = "file:" + **x;
221 if (lrdf_read_file(file.c_str())) {
222 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
227 vector_delete (presets);
231 PluginManager::add_lrdf_data (const string &path)
234 vector<string *>* rdf_files;
235 vector<string *>::iterator x;
238 rdf_files = scanner (path, rdf_filter, 0, true, true);
241 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
242 uri = "file://" + **x;
244 if (lrdf_read_file(uri.c_str())) {
245 warning << "Could not parse rdf file: " << uri << endmsg;
250 vector_delete (rdf_files);
254 PluginManager::ladspa_discover (string path)
257 const LADSPA_Descriptor *descriptor;
258 LADSPA_Descriptor_Function dfunc;
261 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
262 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
266 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
268 if ((errstr = dlerror()) != 0) {
269 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
270 error << errstr << endmsg;
275 for (uint32_t i = 0; ; ++i) {
276 if ((descriptor = dfunc (i)) == 0) {
280 if (!ladspa_plugin_whitelist.empty()) {
281 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
286 PluginInfoPtr info(new LadspaPluginInfo);
287 info->name = descriptor->Name;
288 info->category = get_ladspa_category(descriptor->UniqueID);
289 info->creator = descriptor->Maker;
294 info->type = ARDOUR::LADSPA;
297 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
298 info->unique_id = buf;
300 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
301 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
302 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
305 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
311 _ladspa_plugin_info.push_back (info);
314 // GDB WILL NOT LIKE YOU IF YOU DO THIS
321 PluginManager::get_ladspa_category (uint32_t plugin_id)
324 lrdf_statement pattern;
326 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
327 pattern.subject = buf;
328 pattern.predicate = (char*)RDF_TYPE;
330 pattern.object_type = lrdf_uri;
332 lrdf_statement* matches1 = lrdf_matches (&pattern);
338 pattern.subject = matches1->object;
339 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
341 pattern.object_type = lrdf_literal;
343 lrdf_statement* matches2 = lrdf_matches (&pattern);
344 lrdf_free_statements(matches1);
350 string label = matches2->object;
351 lrdf_free_statements(matches2);
358 PluginManager::lv2_refresh ()
364 PluginManager::lv2_discover ()
366 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
371 #ifdef HAVE_AUDIOUNITS
373 PluginManager::au_refresh ()
379 PluginManager::au_discover ()
381 _au_plugin_info = AUPluginInfo::discover();
390 PluginManager::vst_refresh ()
392 _vst_plugin_info.clear ();
394 if (vst_path.length() == 0) {
395 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
398 vst_discover_from_path (vst_path);
402 PluginManager::add_vst_directory (string path)
404 if (vst_discover_from_path (path) == 0) {
412 static bool vst_filter (const string& str, void *arg)
414 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
416 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
420 PluginManager::vst_discover_from_path (string path)
423 vector<string *> *plugin_objects;
424 vector<string *>::iterator x;
427 info << "detecting VST plugins along " << path << endmsg;
429 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
431 if (plugin_objects) {
432 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
437 vector_delete (plugin_objects);
442 PluginManager::vst_discover (string path)
447 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
448 warning << "Cannot get VST information from " << path << endmsg;
452 if (!finfo->canProcessReplacing) {
453 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
458 PluginInfoPtr info(new VSTPluginInfo);
460 /* what a goddam joke freeware VST is */
462 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
463 info->name = PBD::basename_nosuffix (path);
465 info->name = finfo->name;
469 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
470 info->unique_id = buf;
471 info->category = "VST";
473 // need to set info->creator but FST doesn't provide it
475 info->n_inputs = finfo->numInputs;
476 info->n_outputs = finfo->numOutputs;
477 info->type = ARDOUR::VST;
479 _vst_plugin_info.push_back (info);
480 fst_free_info (finfo);
485 #endif // VST_SUPPORT