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.
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>
41 #include <ardour/vst_plugin.h>
44 #include <pbd/error.h>
45 #include <pbd/stl_delete.h>
49 using namespace ARDOUR;
52 PluginManager* PluginManager::_manager = 0;
54 PluginManager::PluginManager ()
59 if ((s = getenv ("LADSPA_RDF_PATH"))){
63 if (lrdf_path.length() == 0) {
64 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
67 add_lrdf_data(lrdf_path);
70 if (Config->get_use_vst()) {
73 #endif /* VST_SUPPORT */
75 if ((s = getenv ("LADSPA_PATH"))) {
79 if ((s = getenv ("VST_PATH"))) {
81 } else if ((s = getenv ("VST_PLUGINS"))) {
93 PluginManager::refresh ()
97 if (Config->get_use_vst()) {
100 #endif // VST_SUPPORT
104 PluginManager::ladspa_refresh ()
106 _ladspa_plugin_info.clear ();
108 if (ladspa_path.length() == 0) {
109 ladspa_path = "/usr/local/lib/ladspa:/usr/lib/ladspa";
112 ladspa_discover_from_path (ladspa_path);
116 PluginManager::add_ladspa_directory (string path)
118 if (ladspa_discover_from_path (path) == 0) {
126 static bool ladspa_filter (const string& str, void *arg)
128 /* Not a dotfile, has a prefix before a period, suffix is "so" */
130 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
134 PluginManager::ladspa_discover_from_path (string path)
137 vector<string *> *plugin_objects;
138 vector<string *>::iterator x;
141 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
143 if (plugin_objects) {
144 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
145 ladspa_discover (**x);
149 vector_delete (plugin_objects);
153 static bool rdf_filter (const string &str, void *arg)
155 return str[0] != '.' &&
156 ((str.find(".rdf") == (str.length() - 4)) ||
157 (str.find(".rdfs") == (str.length() - 5)) ||
158 (str.find(".n3") == (str.length() - 3)));
162 PluginManager::add_ladspa_presets()
164 add_presets ("ladspa");
168 PluginManager::add_vst_presets()
173 PluginManager::add_presets(string domain)
177 vector<string *> *presets;
178 vector<string *>::iterator x;
181 if ((envvar = getenv ("HOME")) == 0) {
185 string path = string_compose("%1/.%2/rdf", envvar, domain);
186 presets = scanner (path, rdf_filter, 0, true, true);
189 for (x = presets->begin(); x != presets->end (); ++x) {
190 string file = "file:" + **x;
191 if (lrdf_read_file(file.c_str())) {
192 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
197 vector_delete (presets);
201 PluginManager::add_lrdf_data (const string &path)
204 vector<string *>* rdf_files;
205 vector<string *>::iterator x;
208 rdf_files = scanner (path, rdf_filter, 0, true, true);
211 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
212 uri = "file://" + **x;
214 if (lrdf_read_file(uri.c_str())) {
215 warning << "Could not parse rdf file: " << uri << endmsg;
220 vector_delete (rdf_files);
224 PluginManager::ladspa_discover (string path)
227 const LADSPA_Descriptor *descriptor;
228 LADSPA_Descriptor_Function dfunc;
231 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
232 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
236 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
238 if ((errstr = dlerror()) != 0) {
239 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
240 error << errstr << endmsg;
245 for (uint32_t i = 0; ; ++i) {
246 if ((descriptor = dfunc (i)) == 0) {
250 PluginInfoPtr info(new LadspaPluginInfo);
251 info->name = descriptor->Name;
252 info->category = get_ladspa_category(descriptor->UniqueID);
257 info->type = ARDOUR::LADSPA;
258 info->unique_id = descriptor->UniqueID;
260 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
261 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
262 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
265 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
271 _ladspa_plugin_info.push_back (info);
274 // GDB WILL NOT LIKE YOU IF YOU DO THIS
281 PluginManager::get_ladspa_category (uint32_t plugin_id)
284 lrdf_statement pattern;
286 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
287 pattern.subject = buf;
288 pattern.predicate = RDF_TYPE;
290 pattern.object_type = lrdf_uri;
292 lrdf_statement* matches1 = lrdf_matches (&pattern);
298 pattern.subject = matches1->object;
299 pattern.predicate = LADSPA_BASE "hasLabel";
301 pattern.object_type = lrdf_literal;
303 lrdf_statement* matches2 = lrdf_matches (&pattern);
304 lrdf_free_statements(matches1);
310 string label = matches2->object;
311 lrdf_free_statements(matches2);
319 PluginManager::vst_refresh ()
321 _vst_plugin_info.clear ();
323 if (vst_path.length() == 0) {
324 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
327 vst_discover_from_path (vst_path);
331 PluginManager::add_vst_directory (string path)
333 if (vst_discover_from_path (path) == 0) {
341 static bool vst_filter (const string& str, void *arg)
343 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
345 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
349 PluginManager::vst_discover_from_path (string path)
352 vector<string *> *plugin_objects;
353 vector<string *>::iterator x;
356 info << "detecting VST plugins along " << path << endmsg;
358 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
360 if (plugin_objects) {
361 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
366 vector_delete (plugin_objects);
371 PluginManager::vst_discover (string path)
375 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
379 if (!finfo->canProcessReplacing) {
380 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
385 PluginInfoPtr info(new VSTPluginInfo);
387 /* what a goddam joke freeware VST is */
389 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
390 info->name = PBD::basename_nosuffix (path);
392 info->name = finfo->name;
395 info->category = "VST";
398 info->n_inputs = finfo->numInputs;
399 info->n_outputs = finfo->numOutputs;
400 info->type = ARDOUR::VST;
402 _vst_plugin_info.push_back (info);
403 fst_free_info (finfo);
408 #endif // VST_SUPPORT