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 <ardour/vst_plugin.h>
46 #ifdef HAVE_AUDIOUNITS
47 #include <ardour/audio_unit.h>
50 #include <pbd/error.h>
51 #include <pbd/stl_delete.h>
55 using namespace ARDOUR;
58 PluginManager* PluginManager::_manager = 0;
60 PluginManager::PluginManager ()
65 if ((s = getenv ("LADSPA_RDF_PATH"))){
69 if (lrdf_path.length() == 0) {
70 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
73 add_lrdf_data(lrdf_path);
76 if (Config->get_use_vst()) {
79 #endif /* VST_SUPPORT */
81 if ((s = getenv ("LADSPA_PATH"))) {
85 if ((s = getenv ("VST_PATH"))) {
87 } else if ((s = getenv ("VST_PLUGINS"))) {
95 /* the plugin manager is constructed too early to use Profile */
97 if (getenv ("ARDOUR_SAE")) {
98 ladspa_plugin_whitelist.push_back (1203); // single band parametric
99 ladspa_plugin_whitelist.push_back (1772); // caps compressor
100 ladspa_plugin_whitelist.push_back (1913); // fast lookahead limiter
101 ladspa_plugin_whitelist.push_back (1075); // simple RMS expander
102 ladspa_plugin_whitelist.push_back (1061); // feedback delay line (max 5s)
103 ladspa_plugin_whitelist.push_back (1216); // gverb
104 ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
111 PluginManager::refresh ()
115 if (Config->get_use_vst()) {
118 #endif // VST_SUPPORT
119 #ifdef HAVE_AUDIOUNITS
125 PluginManager::ladspa_refresh ()
127 _ladspa_plugin_info.clear ();
129 if (ladspa_path.length() == 0) {
130 ladspa_path = "/usr/local/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib64/ladspa:/usr/lib/ladspa:/Library/Audio/Plug-Ins/LADSPA";
133 ladspa_discover_from_path (ladspa_path);
138 PluginManager::add_ladspa_directory (string path)
140 if (ladspa_discover_from_path (path) == 0) {
148 static bool ladspa_filter (const string& str, void *arg)
150 /* Not a dotfile, has a prefix before a period, suffix is "so" */
152 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
156 PluginManager::ladspa_discover_from_path (string path)
159 vector<string *> *plugin_objects;
160 vector<string *>::iterator x;
163 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
165 if (plugin_objects) {
166 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
167 ladspa_discover (**x);
171 vector_delete (plugin_objects);
175 static bool rdf_filter (const string &str, void *arg)
177 return str[0] != '.' &&
178 ((str.find(".rdf") == (str.length() - 4)) ||
179 (str.find(".rdfs") == (str.length() - 5)) ||
180 (str.find(".n3") == (str.length() - 3)));
184 PluginManager::add_ladspa_presets()
186 add_presets ("ladspa");
190 PluginManager::add_vst_presets()
195 PluginManager::add_presets(string domain)
199 vector<string *> *presets;
200 vector<string *>::iterator x;
203 if ((envvar = getenv ("HOME")) == 0) {
207 string path = string_compose("%1/.%2/rdf", envvar, domain);
208 presets = scanner (path, rdf_filter, 0, true, true);
211 for (x = presets->begin(); x != presets->end (); ++x) {
212 string file = "file:" + **x;
213 if (lrdf_read_file(file.c_str())) {
214 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
219 vector_delete (presets);
223 PluginManager::add_lrdf_data (const string &path)
226 vector<string *>* rdf_files;
227 vector<string *>::iterator x;
230 rdf_files = scanner (path, rdf_filter, 0, true, true);
233 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
234 uri = "file://" + **x;
236 if (lrdf_read_file(uri.c_str())) {
237 warning << "Could not parse rdf file: " << uri << endmsg;
242 vector_delete (rdf_files);
246 PluginManager::ladspa_discover (string path)
249 const LADSPA_Descriptor *descriptor;
250 LADSPA_Descriptor_Function dfunc;
253 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
254 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
258 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
260 if ((errstr = dlerror()) != 0) {
261 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
262 error << errstr << endmsg;
267 for (uint32_t i = 0; ; ++i) {
268 if ((descriptor = dfunc (i)) == 0) {
272 if (!ladspa_plugin_whitelist.empty()) {
273 if (find (ladspa_plugin_whitelist.begin(), ladspa_plugin_whitelist.end(), descriptor->UniqueID) == ladspa_plugin_whitelist.end()) {
278 PluginInfoPtr info(new LadspaPluginInfo);
279 info->name = descriptor->Name;
280 info->category = get_ladspa_category(descriptor->UniqueID);
281 info->creator = descriptor->Maker;
284 info->n_inputs = ChanCount();
285 info->n_outputs = ChanCount();
286 info->type = ARDOUR::LADSPA;
289 snprintf (buf, sizeof (buf), "%lu", descriptor->UniqueID);
290 info->unique_id = buf;
292 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
293 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
294 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
295 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
297 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
298 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
303 _ladspa_plugin_info.push_back (info);
306 // GDB WILL NOT LIKE YOU IF YOU DO THIS
313 PluginManager::get_ladspa_category (uint32_t plugin_id)
316 lrdf_statement pattern;
318 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
319 pattern.subject = buf;
320 pattern.predicate = (char*)RDF_TYPE;
322 pattern.object_type = lrdf_uri;
324 lrdf_statement* matches1 = lrdf_matches (&pattern);
330 pattern.subject = matches1->object;
331 pattern.predicate = (char*)(LADSPA_BASE "hasLabel");
333 pattern.object_type = lrdf_literal;
335 lrdf_statement* matches2 = lrdf_matches (&pattern);
336 lrdf_free_statements(matches1);
342 string label = matches2->object;
343 lrdf_free_statements(matches2);
348 #ifdef HAVE_AUDIOUNITS
350 PluginManager::au_refresh ()
356 PluginManager::au_discover ()
358 _au_plugin_info = AUPluginInfo::discover();
367 PluginManager::vst_refresh ()
369 _vst_plugin_info.clear ();
371 if (vst_path.length() == 0) {
372 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
375 vst_discover_from_path (vst_path);
379 PluginManager::add_vst_directory (string path)
381 if (vst_discover_from_path (path) == 0) {
389 static bool vst_filter (const string& str, void *arg)
391 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
393 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
397 PluginManager::vst_discover_from_path (string path)
400 vector<string *> *plugin_objects;
401 vector<string *>::iterator x;
404 info << "detecting VST plugins along " << path << endmsg;
406 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
408 if (plugin_objects) {
409 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
414 vector_delete (plugin_objects);
419 PluginManager::vst_discover (string path)
424 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
425 warning << "Cannot get VST information from " << path << endmsg;
429 if (!finfo->canProcessReplacing) {
430 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
435 PluginInfoPtr info(new VSTPluginInfo);
437 /* what a goddam joke freeware VST is */
439 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
440 info->name = PBD::basename_nosuffix (path);
442 info->name = finfo->name;
446 snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
447 info->unique_id = buf;
448 info->category = "VST";
450 // need to set info->creator but FST doesn't provide it
452 info->n_inputs = finfo->numInputs;
453 info->n_outputs = finfo->numOutputs;
454 info->type = ARDOUR::VST;
456 _vst_plugin_info.push_back (info);
457 fst_free_info (finfo);
462 #endif // VST_SUPPORT