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 #define __STDC_FORMAT_MACROS 1
24 #include <sys/types.h>
31 #include <pbd/basename.h>
35 #include <pbd/pathscanner.h>
37 #include <ardour/ladspa.h>
38 #include <ardour/session.h>
39 #include <ardour/plugin_manager.h>
40 #include <ardour/plugin.h>
41 #include <ardour/ladspa_plugin.h>
44 #include <ardour/vst_plugin.h>
47 #include <pbd/error.h>
48 #include <pbd/stl_delete.h>
52 using namespace ARDOUR;
55 PluginManager* PluginManager::_manager = 0;
57 PluginManager::PluginManager ()
62 if ((s = getenv ("LADSPA_RDF_PATH"))){
66 if (lrdf_path.length() == 0) {
67 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
70 add_lrdf_data(lrdf_path);
73 if (Config->get_use_vst()) {
76 #endif /* VST_SUPPORT */
78 if ((s = getenv ("LADSPA_PATH"))) {
82 if ((s = getenv ("VST_PATH"))) {
84 } else if ((s = getenv ("VST_PLUGINS"))) {
96 PluginManager::refresh ()
100 if (Config->get_use_vst()) {
103 #endif // VST_SUPPORT
107 PluginManager::ladspa_refresh ()
109 _ladspa_plugin_info.clear ();
111 if (ladspa_path.length() == 0) {
112 ladspa_path = "/usr/local/lib/ladspa:/usr/lib/ladspa";
115 ladspa_discover_from_path (ladspa_path);
119 PluginManager::add_ladspa_directory (string path)
121 if (ladspa_discover_from_path (path) == 0) {
129 static bool ladspa_filter (const string& str, void *arg)
131 /* Not a dotfile, has a prefix before a period, suffix is "so" */
133 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
137 PluginManager::ladspa_discover_from_path (string path)
140 vector<string *> *plugin_objects;
141 vector<string *>::iterator x;
144 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
146 if (plugin_objects) {
147 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
148 ladspa_discover (**x);
152 vector_delete (plugin_objects);
156 static bool rdf_filter (const string &str, void *arg)
158 return str[0] != '.' &&
159 ((str.find(".rdf") == (str.length() - 4)) ||
160 (str.find(".rdfs") == (str.length() - 5)) ||
161 (str.find(".n3") == (str.length() - 3)));
165 PluginManager::add_ladspa_presets()
167 add_presets ("ladspa");
171 PluginManager::add_vst_presets()
176 PluginManager::add_presets(string domain)
180 vector<string *> *presets;
181 vector<string *>::iterator x;
184 if ((envvar = getenv ("HOME")) == 0) {
188 string path = string_compose("%1/.%2/rdf", envvar, domain);
189 presets = scanner (path, rdf_filter, 0, true, true);
192 for (x = presets->begin(); x != presets->end (); ++x) {
193 string file = "file:" + **x;
194 if (lrdf_read_file(file.c_str())) {
195 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
200 vector_delete (presets);
204 PluginManager::add_lrdf_data (const string &path)
207 vector<string *>* rdf_files;
208 vector<string *>::iterator x;
211 rdf_files = scanner (path, rdf_filter, 0, true, true);
214 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
215 uri = "file://" + **x;
217 if (lrdf_read_file(uri.c_str())) {
218 warning << "Could not parse rdf file: " << uri << endmsg;
223 vector_delete (rdf_files);
227 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 PluginInfoPtr info(new LadspaPluginInfo);
254 info->name = descriptor->Name;
255 info->category = get_ladspa_category(descriptor->UniqueID);
260 info->type = ARDOUR::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::get_ladspa_category (uint32_t plugin_id)
287 lrdf_statement pattern;
289 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
290 pattern.subject = buf;
291 pattern.predicate = RDF_TYPE;
293 pattern.object_type = lrdf_uri;
295 lrdf_statement* matches1 = lrdf_matches (&pattern);
301 pattern.subject = matches1->object;
302 pattern.predicate = LADSPA_BASE "hasLabel";
304 pattern.object_type = lrdf_literal;
306 lrdf_statement* matches2 = lrdf_matches (&pattern);
307 lrdf_free_statements(matches1);
313 string label = matches2->object;
314 lrdf_free_statements(matches2);
322 PluginManager::vst_refresh ()
324 _vst_plugin_info.clear ();
326 if (vst_path.length() == 0) {
327 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
330 vst_discover_from_path (vst_path);
334 PluginManager::add_vst_directory (string path)
336 if (vst_discover_from_path (path) == 0) {
344 static bool vst_filter (const string& str, void *arg)
346 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
348 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
352 PluginManager::vst_discover_from_path (string path)
355 vector<string *> *plugin_objects;
356 vector<string *>::iterator x;
359 info << "detecting VST plugins along " << path << endmsg;
361 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
363 if (plugin_objects) {
364 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
369 vector_delete (plugin_objects);
374 PluginManager::vst_discover (string path)
378 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
382 if (!finfo->canProcessReplacing) {
383 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
388 PluginInfoPtr info(new VSTPluginInfo);
390 /* what a goddam joke freeware VST is */
392 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
393 info->name = PBD::basename_nosuffix (path);
395 info->name = finfo->name;
398 info->category = "VST";
401 info->n_inputs = finfo->numInputs;
402 info->n_outputs = finfo->numOutputs;
403 info->type = ARDOUR::VST;
405 _vst_plugin_info.push_back (info);
406 fst_free_info (finfo);
411 #endif // VST_SUPPORT