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
110 _lv2_world = new LV2World();
117 PluginManager::refresh ()
124 if (Config->get_use_vst()) {
127 #endif // VST_SUPPORT
128 #ifdef HAVE_AUDIOUNITS
134 PluginManager::ladspa_refresh ()
136 _ladspa_plugin_info.clear ();
138 if (ladspa_path.length() == 0) {
139 ladspa_path = "/usr/local/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib64/ladspa:/usr/lib/ladspa:/Library/Audio/Plug-Ins/LADSPA";
142 ladspa_discover_from_path (ladspa_path);
147 PluginManager::add_ladspa_directory (string path)
149 if (ladspa_discover_from_path (path) == 0) {
157 static bool ladspa_filter (const string& str, void *arg)
159 /* Not a dotfile, has a prefix before a period, suffix is "so" */
161 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
165 PluginManager::ladspa_discover_from_path (string path)
168 vector<string *> *plugin_objects;
169 vector<string *>::iterator x;
172 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
174 if (plugin_objects) {
175 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
176 ladspa_discover (**x);
180 vector_delete (plugin_objects);
184 static bool rdf_filter (const string &str, void *arg)
186 return str[0] != '.' &&
187 ((str.find(".rdf") == (str.length() - 4)) ||
188 (str.find(".rdfs") == (str.length() - 5)) ||
189 (str.find(".n3") == (str.length() - 3)));
193 PluginManager::add_ladspa_presets()
195 add_presets ("ladspa");
199 PluginManager::add_vst_presets()
204 PluginManager::add_presets(string domain)
208 vector<string *> *presets;
209 vector<string *>::iterator x;
212 if ((envvar = getenv ("HOME")) == 0) {
216 string path = string_compose("%1/.%2/rdf", envvar, domain);
217 presets = scanner (path, rdf_filter, 0, true, true);
220 for (x = presets->begin(); x != presets->end (); ++x) {
221 string file = "file:" + **x;
222 if (lrdf_read_file(file.c_str())) {
223 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
228 vector_delete (presets);
232 PluginManager::add_lrdf_data (const string &path)
235 vector<string *>* rdf_files;
236 vector<string *>::iterator x;
239 rdf_files = scanner (path, rdf_filter, 0, true, true);
242 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
243 uri = "file://" + **x;
245 if (lrdf_read_file(uri.c_str())) {
246 warning << "Could not parse rdf file: " << uri << endmsg;
251 vector_delete (rdf_files);
255 PluginManager::ladspa_discover (string path)
258 const LADSPA_Descriptor *descriptor;
259 LADSPA_Descriptor_Function dfunc;
262 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
263 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
267 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
269 if ((errstr = dlerror()) != 0) {
270 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
271 error << errstr << endmsg;
276 for (uint32_t i = 0; ; ++i) {
277 if ((descriptor = dfunc (i)) == 0) {
281 if (!ladspa_plugin_whitelist.empty()) {
282 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
287 PluginInfoPtr info(new LadspaPluginInfo);
288 info->name = descriptor->Name;
289 info->category = get_ladspa_category(descriptor->UniqueID);
290 info->creator = descriptor->Maker;
295 info->type = ARDOUR::LADSPA;
298 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
299 info->unique_id = buf;
301 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
302 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
303 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
306 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
312 _ladspa_plugin_info.push_back (info);
315 // GDB WILL NOT LIKE YOU IF YOU DO THIS
322 PluginManager::get_ladspa_category (uint32_t plugin_id)
325 lrdf_statement pattern;
327 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
328 pattern.subject = buf;
329 pattern.predicate = (char*)RDF_TYPE;
331 pattern.object_type = lrdf_uri;
333 lrdf_statement* matches1 = lrdf_matches (&pattern);
339 pattern.subject = matches1->object;
340 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
342 pattern.object_type = lrdf_literal;
344 lrdf_statement* matches2 = lrdf_matches (&pattern);
345 lrdf_free_statements(matches1);
351 string label = matches2->object;
352 lrdf_free_statements(matches2);
359 PluginManager::lv2_refresh ()
365 PluginManager::lv2_discover ()
367 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
372 #ifdef HAVE_AUDIOUNITS
374 PluginManager::au_refresh ()
380 PluginManager::au_discover ()
382 _au_plugin_info = AUPluginInfo::discover();
391 PluginManager::vst_refresh ()
393 _vst_plugin_info.clear ();
395 if (vst_path.length() == 0) {
396 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
399 vst_discover_from_path (vst_path);
403 PluginManager::add_vst_directory (string path)
405 if (vst_discover_from_path (path) == 0) {
413 static bool vst_filter (const string& str, void *arg)
415 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
417 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
421 PluginManager::vst_discover_from_path (string path)
424 vector<string *> *plugin_objects;
425 vector<string *>::iterator x;
428 info << "detecting VST plugins along " << path << endmsg;
430 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
432 if (plugin_objects) {
433 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
438 vector_delete (plugin_objects);
443 PluginManager::vst_discover (string path)
448 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
449 warning << "Cannot get VST information from " << path << endmsg;
453 if (!finfo->canProcessReplacing) {
454 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
459 PluginInfoPtr info(new VSTPluginInfo);
461 /* what a goddam joke freeware VST is */
463 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
464 info->name = PBD::basename_nosuffix (path);
466 info->name = finfo->name;
470 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
471 info->unique_id = buf;
472 info->category = "VST";
474 // need to set info->creator but FST doesn't provide it
476 info->n_inputs = finfo->numInputs;
477 info->n_outputs = finfo->numOutputs;
478 info->type = ARDOUR::VST;
480 _vst_plugin_info.push_back (info);
481 fst_free_info (finfo);
486 #endif // VST_SUPPORT