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 #include <pbd/error.h>
47 #include <pbd/stl_delete.h>
51 using namespace ARDOUR;
54 PluginManager* PluginManager::_manager = 0;
56 PluginManager::PluginManager ()
61 if ((s = getenv ("LADSPA_RDF_PATH"))){
65 if (lrdf_path.length() == 0) {
66 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
69 add_lrdf_data(lrdf_path);
72 if (Config->get_use_vst()) {
75 #endif /* VST_SUPPORT */
77 if ((s = getenv ("LADSPA_PATH"))) {
81 if ((s = getenv ("VST_PATH"))) {
83 } else if ((s = getenv ("VST_PLUGINS"))) {
94 PluginManager::refresh ()
98 if (Config->get_use_vst()) {
101 #endif // VST_SUPPORT
105 PluginManager::ladspa_refresh ()
107 _ladspa_plugin_info.clear ();
109 if (ladspa_path.length() == 0) {
110 ladspa_path = "/usr/local/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib64/ladspa:/usr/lib/ladspa:/Library/Audio/Plug-Ins/LADSPA";
113 ladspa_discover_from_path (ladspa_path);
117 PluginManager::add_ladspa_directory (string path)
119 if (ladspa_discover_from_path (path) == 0) {
127 static bool ladspa_filter (const string& str, void *arg)
129 /* Not a dotfile, has a prefix before a period, suffix is "so" */
131 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
135 PluginManager::ladspa_discover_from_path (string path)
138 vector<string *> *plugin_objects;
139 vector<string *>::iterator x;
142 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
144 if (plugin_objects) {
145 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
146 ladspa_discover (**x);
150 vector_delete (plugin_objects);
154 static bool rdf_filter (const string &str, void *arg)
156 return str[0] != '.' &&
157 ((str.find(".rdf") == (str.length() - 4)) ||
158 (str.find(".rdfs") == (str.length() - 5)) ||
159 (str.find(".n3") == (str.length() - 3)));
163 PluginManager::add_ladspa_presets()
165 add_presets ("ladspa");
169 PluginManager::add_vst_presets()
174 PluginManager::add_presets(string domain)
178 vector<string *> *presets;
179 vector<string *>::iterator x;
182 if ((envvar = getenv ("HOME")) == 0) {
186 string path = string_compose("%1/.%2/rdf", envvar, domain);
187 presets = scanner (path, rdf_filter, 0, true, true);
190 for (x = presets->begin(); x != presets->end (); ++x) {
191 string file = "file:" + **x;
192 if (lrdf_read_file(file.c_str())) {
193 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
198 vector_delete (presets);
202 PluginManager::add_lrdf_data (const string &path)
205 vector<string *>* rdf_files;
206 vector<string *>::iterator x;
209 rdf_files = scanner (path, rdf_filter, 0, true, true);
212 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
213 uri = "file://" + **x;
215 if (lrdf_read_file(uri.c_str())) {
216 warning << "Could not parse rdf file: " << uri << endmsg;
221 vector_delete (rdf_files);
225 PluginManager::ladspa_discover (string path)
228 const LADSPA_Descriptor *descriptor;
229 LADSPA_Descriptor_Function dfunc;
232 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
233 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
237 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
239 if ((errstr = dlerror()) != 0) {
240 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
241 error << errstr << endmsg;
246 for (uint32_t i = 0; ; ++i) {
247 if ((descriptor = dfunc (i)) == 0) {
251 PluginInfoPtr info(new LadspaPluginInfo);
252 info->name = descriptor->Name;
253 info->category = get_ladspa_category(descriptor->UniqueID);
254 info->creator = descriptor->Maker;
257 info->n_inputs = ChanCount();
258 info->n_outputs = ChanCount();
259 info->type = ARDOUR::LADSPA;
260 info->unique_id = descriptor->UniqueID;
262 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
263 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
264 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
265 info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
267 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
268 info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
273 _ladspa_plugin_info.push_back (info);
276 // GDB WILL NOT LIKE YOU IF YOU DO THIS
283 PluginManager::get_ladspa_category (uint32_t plugin_id)
286 lrdf_statement pattern;
288 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
289 pattern.subject = buf;
290 pattern.predicate = RDF_TYPE;
292 pattern.object_type = lrdf_uri;
294 lrdf_statement* matches1 = lrdf_matches (&pattern);
300 pattern.subject = matches1->object;
301 pattern.predicate = LADSPA_BASE "hasLabel";
303 pattern.object_type = lrdf_literal;
305 lrdf_statement* matches2 = lrdf_matches (&pattern);
306 lrdf_free_statements(matches1);
312 string label = matches2->object;
313 lrdf_free_statements(matches2);
321 PluginManager::vst_refresh ()
323 _vst_plugin_info.clear ();
325 if (vst_path.length() == 0) {
326 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
329 vst_discover_from_path (vst_path);
333 PluginManager::add_vst_directory (string path)
335 if (vst_discover_from_path (path) == 0) {
343 static bool vst_filter (const string& str, void *arg)
345 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
347 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
351 PluginManager::vst_discover_from_path (string path)
354 vector<string *> *plugin_objects;
355 vector<string *>::iterator x;
358 info << "detecting VST plugins along " << path << endmsg;
360 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
362 if (plugin_objects) {
363 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
368 vector_delete (plugin_objects);
373 PluginManager::vst_discover (string path)
377 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
378 warning << "Cannot get VST information from " << path << endmsg;
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";
400 // need to set info->creator but FST doesn't provide it
402 info->n_inputs = finfo->numInputs;
403 info->n_outputs = finfo->numOutputs;
404 info->type = ARDOUR::VST;
406 _vst_plugin_info.push_back (info);
407 fst_free_info (finfo);
412 #endif // VST_SUPPORT