2 Copyright (C) 2000-2004 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.
21 #include <sys/types.h>
28 #include <pbd/basename.h>
32 #include <pbd/pathscanner.h>
34 #include <ardour/ladspa.h>
35 #include <ardour/session.h>
36 #include <ardour/plugin_manager.h>
37 #include <ardour/plugin.h>
38 #include <ardour/ladspa_plugin.h>
39 #include <ardour/vst_plugin.h>
41 #include <pbd/error.h>
42 #include <pbd/stl_delete.h>
46 using namespace ARDOUR;
49 PluginManager* PluginManager::_manager = 0;
51 PluginManager::PluginManager (AudioEngine& e)
57 if ((s = getenv ("LADSPA_RDF_PATH"))){
61 if (lrdf_path.length() == 0) {
62 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
65 add_lrdf_data(lrdf_path);
68 if (Config->get_use_vst()) {
71 #endif /* VST_SUPPORT */
73 if ((s = getenv ("LADSPA_PATH"))) {
77 if ((s = getenv ("VST_PATH"))) {
79 } else if ((s = getenv ("VST_PLUGINS"))) {
91 PluginManager::refresh ()
95 if (Config->get_use_vst()) {
102 PluginManager::ladspa_refresh ()
104 for (std::list<PluginInfo*>::iterator i = _ladspa_plugin_info.begin(); i != _ladspa_plugin_info.end(); ++i) {
108 _ladspa_plugin_info.clear ();
110 if (ladspa_path.length() == 0) {
111 ladspa_path = "/usr/local/lib/ladspa:/usr/lib/ladspa";
114 ladspa_discover_from_path (ladspa_path);
118 PluginManager::add_ladspa_directory (string path)
120 if (ladspa_discover_from_path (path) == 0) {
128 static bool ladspa_filter (const string& str, void *arg)
130 /* Not a dotfile, has a prefix before a period, suffix is "so" */
132 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
136 PluginManager::ladspa_discover_from_path (string path)
139 vector<string *> *plugin_objects;
140 vector<string *>::iterator x;
143 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
145 if (plugin_objects) {
146 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
147 ladspa_discover (**x);
151 vector_delete (plugin_objects);
155 static bool rdf_filter (const string &str, void *arg)
157 return str[0] != '.' &&
158 ((str.find(".rdf") == (str.length() - 4)) ||
159 (str.find(".rdfs") == (str.length() - 5)) ||
160 (str.find(".n3") == (str.length() - 3)));
164 PluginManager::add_ladspa_presets()
166 add_presets ("ladspa");
170 PluginManager::add_vst_presets()
175 PluginManager::add_presets(string domain)
179 vector<string *> *presets;
180 vector<string *>::iterator x;
183 if ((envvar = getenv ("HOME")) == 0) {
187 string path = string_compose("%1/.%2/rdf", envvar, domain);
188 presets = scanner (path, rdf_filter, 0, true, true);
191 for (x = presets->begin(); x != presets->end (); ++x) {
192 string file = "file:" + **x;
193 if (lrdf_read_file(file.c_str())) {
194 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
199 vector_delete (presets);
203 PluginManager::add_lrdf_data (const string &path)
206 vector<string *>* rdf_files;
207 vector<string *>::iterator x;
210 rdf_files = scanner (path, rdf_filter, 0, true, true);
213 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
214 uri = "file://" + **x;
216 if (lrdf_read_file(uri.c_str())) {
217 warning << "Could not parse rdf file: " << uri << endmsg;
222 vector_delete (rdf_files);
226 PluginManager::ladspa_discover (string path)
230 const LADSPA_Descriptor *descriptor;
231 LADSPA_Descriptor_Function dfunc;
234 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
235 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
239 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
241 if ((errstr = dlerror()) != 0) {
242 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
243 error << errstr << endmsg;
248 for (uint32_t i = 0; ; ++i) {
249 if ((descriptor = dfunc (i)) == 0) {
253 info = new PluginInfo;
254 info->name = descriptor->Name;
255 info->category = get_ladspa_category(descriptor->UniqueID);
260 info->type = PluginInfo::LADSPA;
261 info->unique_id = descriptor->UniqueID;
263 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
264 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
265 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
268 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
274 _ladspa_plugin_info.push_back (info);
277 // GDB WILL NOT LIKE YOU IF YOU DO THIS
284 PluginManager::load (Session& session, PluginInfo *info)
290 if (info->type == PluginInfo::VST) {
293 if (Config->get_use_vst()) {
296 if ((handle = fst_load (info->path.c_str())) == 0) {
297 error << string_compose(_("VST: cannot load module from \"%1\""), info->path) << endmsg;
299 plugin = new VSTPlugin (_engine, session, handle);
302 error << _("You asked ardour to not use any VST plugins") << endmsg;
305 error << _("This version of ardour has no support for VST plugins") << endmsg;
311 if ((module = dlopen (info->path.c_str(), RTLD_NOW)) == 0) {
312 error << string_compose(_("LADSPA: cannot load module from \"%1\""), info->path) << endmsg;
313 error << dlerror() << endmsg;
315 plugin = new LadspaPlugin (module, _engine, session, info->index, session.frame_rate());
319 plugin->set_info(*info);
322 catch (failed_constructor &err) {
330 ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginInfo::Type type)
332 PluginManager *mgr = PluginManager::the_manager();
333 list<PluginInfo *>::iterator i;
334 list<PluginInfo *>* plugs = 0;
337 case PluginInfo::LADSPA:
338 plugs = &mgr->ladspa_plugin_info();
340 case PluginInfo::VST:
341 plugs = &mgr->vst_plugin_info();
342 unique_id = 0; // VST plugins don't have a unique id.
344 case PluginInfo::AudioUnit:
349 for (i = plugs->begin(); i != plugs->end(); ++i) {
350 if ((name == "" || (*i)->name == name) &&
351 (unique_id == 0 || (*i)->unique_id == unique_id)) {
352 return mgr->load (session, *i);
360 PluginManager::get_ladspa_category (uint32_t plugin_id)
363 lrdf_statement pattern;
365 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
366 pattern.subject = buf;
367 pattern.predicate = RDF_TYPE;
369 pattern.object_type = lrdf_uri;
371 lrdf_statement* matches1 = lrdf_matches (&pattern);
377 pattern.subject = matches1->object;
378 pattern.predicate = LADSPA_BASE "hasLabel";
380 pattern.object_type = lrdf_literal;
382 lrdf_statement* matches2 = lrdf_matches (&pattern);
383 lrdf_free_statements(matches1);
389 string label = matches2->object;
390 lrdf_free_statements(matches2);
398 PluginManager::vst_refresh ()
400 for (std::list<PluginInfo*>::iterator i = _vst_plugin_info.begin(); i != _vst_plugin_info.end(); ++i) {
404 _vst_plugin_info.clear ();
406 if (vst_path.length() == 0) {
407 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
410 vst_discover_from_path (vst_path);
414 PluginManager::add_vst_directory (string path)
416 if (vst_discover_from_path (path) == 0) {
424 static bool vst_filter (const string& str, void *arg)
426 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
428 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
432 PluginManager::vst_discover_from_path (string path)
435 vector<string *> *plugin_objects;
436 vector<string *>::iterator x;
439 info << "detecting VST plugins along " << path << endmsg;
441 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
443 if (plugin_objects) {
444 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
449 vector_delete (plugin_objects);
454 PluginManager::vst_discover (string path)
459 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
463 if (!finfo->canProcessReplacing) {
464 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
469 info = new PluginInfo;
471 /* what a goddam joke freeware VST is */
473 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
474 info->name = PBD::basename_nosuffix (path);
476 info->name = finfo->name;
479 info->category = "VST";
482 info->n_inputs = finfo->numInputs;
483 info->n_outputs = finfo->numOutputs;
484 info->type = PluginInfo::VST;
486 _vst_plugin_info.push_back (info);
487 fst_free_info (finfo);