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 #define __STDC_FORMAT_MACROS 1
23 #include <sys/types.h>
30 #include <pbd/basename.h>
34 #include <pbd/pathscanner.h>
36 #include <ardour/ladspa.h>
37 #include <ardour/session.h>
38 #include <ardour/plugin_manager.h>
39 #include <ardour/plugin.h>
40 #include <ardour/ladspa_plugin.h>
43 #include <slv2/slv2.h>
44 #include <ardour/lv2_plugin.h>
48 #include <ardour/vst_plugin.h>
51 #ifdef HAVE_AUDIOUNITS
52 #include <ardour/audio_unit.h>
55 #include <pbd/error.h>
56 #include <pbd/stl_delete.h>
60 using namespace ARDOUR;
63 PluginManager* PluginManager::_manager = 0;
65 PluginManager::PluginManager ()
70 if ((s = getenv ("LADSPA_RDF_PATH"))){
74 if (lrdf_path.length() == 0) {
75 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
78 add_lrdf_data(lrdf_path);
81 if (Config->get_use_vst()) {
84 #endif /* VST_SUPPORT */
86 if ((s = getenv ("LADSPA_PATH"))) {
90 if ((s = getenv ("VST_PATH"))) {
92 } else if ((s = getenv ("VST_PLUGINS"))) {
100 /* the plugin manager is constructed too early to use Profile */
102 if (getenv ("ARDOUR_SAE")) {
103 ladspa_plugin_whitelist.push_back (1203); // single band parametric
104 ladspa_plugin_whitelist.push_back (1772); // caps compressor
105 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
106 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
107 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
108 ladspa_plugin_whitelist.push_back (1216); // gverb
109 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
113 _lv2_world = new LV2World();
120 PluginManager::refresh ()
127 if (Config->get_use_vst()) {
130 #endif // VST_SUPPORT
131 #ifdef HAVE_AUDIOUNITS
137 PluginManager::ladspa_refresh ()
139 _ladspa_plugin_info.clear ();
141 if (ladspa_path.length() == 0) {
142 ladspa_path = "/usr/local/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib64/ladspa:/usr/lib/ladspa:/Library/Audio/Plug-Ins/LADSPA";
145 ladspa_discover_from_path (ladspa_path);
150 PluginManager::add_ladspa_directory (string path)
152 if (ladspa_discover_from_path (path) == 0) {
160 static bool ladspa_filter (const string& str, void *arg)
162 /* Not a dotfile, has a prefix before a period, suffix is "so" */
164 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
168 PluginManager::ladspa_discover_from_path (string path)
171 vector<string *> *plugin_objects;
172 vector<string *>::iterator x;
175 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
177 if (plugin_objects) {
178 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
179 ladspa_discover (**x);
183 vector_delete (plugin_objects);
187 static bool rdf_filter (const string &str, void *arg)
189 return str[0] != '.' &&
190 ((str.find(".rdf") == (str.length() - 4)) ||
191 (str.find(".rdfs") == (str.length() - 5)) ||
192 (str.find(".n3") == (str.length() - 3)));
196 PluginManager::add_ladspa_presets()
198 add_presets ("ladspa");
202 PluginManager::add_vst_presets()
207 PluginManager::add_presets(string domain)
211 vector<string *> *presets;
212 vector<string *>::iterator x;
215 if ((envvar = getenv ("HOME")) == 0) {
219 string path = string_compose("%1/.%2/rdf", envvar, domain);
220 presets = scanner (path, rdf_filter, 0, true, true);
223 for (x = presets->begin(); x != presets->end (); ++x) {
224 string file = "file:" + **x;
225 if (lrdf_read_file(file.c_str())) {
226 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
231 vector_delete (presets);
235 PluginManager::add_lrdf_data (const string &path)
238 vector<string *>* rdf_files;
239 vector<string *>::iterator x;
242 rdf_files = scanner (path, rdf_filter, 0, true, true);
245 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
246 uri = "file://" + **x;
248 if (lrdf_read_file(uri.c_str())) {
249 warning << "Could not parse rdf file: " << uri << endmsg;
254 vector_delete (rdf_files);
258 PluginManager::ladspa_discover (string path)
261 const LADSPA_Descriptor *descriptor;
262 LADSPA_Descriptor_Function dfunc;
265 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
266 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
270 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
272 if ((errstr = dlerror()) != 0) {
273 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
274 error << errstr << endmsg;
279 for (uint32_t i = 0; ; ++i) {
280 if ((descriptor = dfunc (i)) == 0) {
284 if (!ladspa_plugin_whitelist.empty()) {
285 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
290 PluginInfoPtr info(new LadspaPluginInfo);
291 info->name = descriptor->Name;
292 info->category = get_ladspa_category(descriptor->UniqueID);
293 info->creator = descriptor->Maker;
296 info->n_inputs = ChanCount();
297 info->n_outputs = ChanCount();
298 info->type = ARDOUR::LADSPA;
301 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
302 info->unique_id = buf;
304 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
305 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
306 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
307 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
309 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
310 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
315 _ladspa_plugin_info.push_back (info);
318 // GDB WILL NOT LIKE YOU IF YOU DO THIS
325 PluginManager::get_ladspa_category (uint32_t plugin_id)
328 lrdf_statement pattern;
330 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
331 pattern.subject = buf;
332 pattern.predicate = (char*)RDF_TYPE;
334 pattern.object_type = lrdf_uri;
336 lrdf_statement* matches1 = lrdf_matches (&pattern);
342 pattern.subject = matches1->object;
343 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
345 pattern.object_type = lrdf_literal;
347 lrdf_statement* matches2 = lrdf_matches (&pattern);
348 lrdf_free_statements(matches1);
354 string label = matches2->object;
355 lrdf_free_statements(matches2);
362 PluginManager::lv2_refresh ()
368 PluginManager::lv2_discover ()
370 _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
375 #ifdef HAVE_AUDIOUNITS
377 PluginManager::au_refresh ()
383 PluginManager::au_discover ()
385 _au_plugin_info = AUPluginInfo::discover();
394 PluginManager::vst_refresh ()
396 _vst_plugin_info.clear ();
398 if (vst_path.length() == 0) {
399 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
402 vst_discover_from_path (vst_path);
406 PluginManager::add_vst_directory (string path)
408 if (vst_discover_from_path (path) == 0) {
416 static bool vst_filter (const string& str, void *arg)
418 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
420 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
424 PluginManager::vst_discover_from_path (string path)
427 vector<string *> *plugin_objects;
428 vector<string *>::iterator x;
431 info << "detecting VST plugins along " << path << endmsg;
433 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
435 if (plugin_objects) {
436 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
441 vector_delete (plugin_objects);
446 PluginManager::vst_discover (string path)
451 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
452 warning << "Cannot get VST information from " << path << endmsg;
456 if (!finfo->canProcessReplacing) {
457 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
462 PluginInfoPtr info(new VSTPluginInfo);
464 /* what a goddam joke freeware VST is */
466 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
467 info->name = PBD::basename_nosuffix (path);
469 info->name = finfo->name;
473 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
474 info->unique_id = buf;
475 info->category = "VST";
477 // need to set info->creator but FST doesn't provide it
479 info->n_inputs = finfo->numInputs;
480 info->n_outputs = finfo->numOutputs;
481 info->type = ARDOUR::VST;
483 _vst_plugin_info.push_back (info);
484 fst_free_info (finfo);
489 #endif // VST_SUPPORT