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 #include <sys/types.h>
27 #include <pbd/basename.h>
31 #include <pbd/pathscanner.h>
33 #include <ardour/ladspa.h>
34 #include <ardour/session.h>
35 #include <ardour/plugin_manager.h>
36 #include <ardour/plugin.h>
37 #include <ardour/ladspa_plugin.h>
40 #include <ardour/vst_plugin.h>
43 #include <pbd/error.h>
44 #include <pbd/stl_delete.h>
48 using namespace ARDOUR;
51 PluginManager* PluginManager::_manager = 0;
53 PluginManager::PluginManager ()
58 if ((s = getenv ("LADSPA_RDF_PATH"))){
62 if (lrdf_path.length() == 0) {
63 lrdf_path = "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
66 add_lrdf_data(lrdf_path);
69 if (Config->get_use_vst()) {
72 #endif /* VST_SUPPORT */
74 if ((s = getenv ("LADSPA_PATH"))) {
78 if ((s = getenv ("VST_PATH"))) {
80 } else if ((s = getenv ("VST_PLUGINS"))) {
91 PluginManager::refresh ()
95 if (Config->get_use_vst()) {
102 PluginManager::ladspa_refresh ()
104 _ladspa_plugin_info.clear ();
106 if (ladspa_path.length() == 0) {
107 ladspa_path = "/usr/local/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib64/ladspa:/usr/lib/ladspa:/Library/Audio/Plug-Ins/LADSPA";
110 ladspa_discover_from_path (ladspa_path);
114 PluginManager::add_ladspa_directory (string path)
116 if (ladspa_discover_from_path (path) == 0) {
124 static bool ladspa_filter (const string& str, void *arg)
126 /* Not a dotfile, has a prefix before a period, suffix is "so" */
128 return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
132 PluginManager::ladspa_discover_from_path (string path)
135 vector<string *> *plugin_objects;
136 vector<string *>::iterator x;
139 plugin_objects = scanner (ladspa_path, ladspa_filter, 0, true, true);
141 if (plugin_objects) {
142 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
143 ladspa_discover (**x);
147 vector_delete (plugin_objects);
151 static bool rdf_filter (const string &str, void *arg)
153 return str[0] != '.' &&
154 ((str.find(".rdf") == (str.length() - 4)) ||
155 (str.find(".rdfs") == (str.length() - 5)) ||
156 (str.find(".n3") == (str.length() - 3)));
160 PluginManager::add_ladspa_presets()
162 add_presets ("ladspa");
166 PluginManager::add_vst_presets()
171 PluginManager::add_presets(string domain)
175 vector<string *> *presets;
176 vector<string *>::iterator x;
179 if ((envvar = getenv ("HOME")) == 0) {
183 string path = string_compose("%1/.%2/rdf", envvar, domain);
184 presets = scanner (path, rdf_filter, 0, true, true);
187 for (x = presets->begin(); x != presets->end (); ++x) {
188 string file = "file:" + **x;
189 if (lrdf_read_file(file.c_str())) {
190 warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
195 vector_delete (presets);
199 PluginManager::add_lrdf_data (const string &path)
202 vector<string *>* rdf_files;
203 vector<string *>::iterator x;
206 rdf_files = scanner (path, rdf_filter, 0, true, true);
209 for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
210 uri = "file://" + **x;
212 if (lrdf_read_file(uri.c_str())) {
213 warning << "Could not parse rdf file: " << uri << endmsg;
218 vector_delete (rdf_files);
222 PluginManager::ladspa_discover (string path)
225 const LADSPA_Descriptor *descriptor;
226 LADSPA_Descriptor_Function dfunc;
229 if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
230 error << string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path, dlerror()) << endmsg;
234 dfunc = (LADSPA_Descriptor_Function) dlsym (module, "ladspa_descriptor");
236 if ((errstr = dlerror()) != 0) {
237 error << string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path) << endmsg;
238 error << errstr << endmsg;
243 for (uint32_t i = 0; ; ++i) {
244 if ((descriptor = dfunc (i)) == 0) {
248 PluginInfoPtr info(new LadspaPluginInfo);
249 info->name = descriptor->Name;
250 info->category = get_ladspa_category(descriptor->UniqueID);
255 info->type = ARDOUR::LADSPA;
256 info->unique_id = descriptor->UniqueID;
258 for (uint32_t n=0; n < descriptor->PortCount; ++n) {
259 if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
260 if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
263 else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
269 _ladspa_plugin_info.push_back (info);
272 // GDB WILL NOT LIKE YOU IF YOU DO THIS
279 PluginManager::get_ladspa_category (uint32_t plugin_id)
282 lrdf_statement pattern;
284 snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
285 pattern.subject = buf;
286 pattern.predicate = RDF_TYPE;
288 pattern.object_type = lrdf_uri;
290 lrdf_statement* matches1 = lrdf_matches (&pattern);
296 pattern.subject = matches1->object;
297 pattern.predicate = LADSPA_BASE "hasLabel";
299 pattern.object_type = lrdf_literal;
301 lrdf_statement* matches2 = lrdf_matches (&pattern);
302 lrdf_free_statements(matches1);
308 string label = matches2->object;
309 lrdf_free_statements(matches2);
317 PluginManager::vst_refresh ()
319 _vst_plugin_info.clear ();
321 if (vst_path.length() == 0) {
322 vst_path = "/usr/local/lib/vst:/usr/lib/vst";
325 vst_discover_from_path (vst_path);
329 PluginManager::add_vst_directory (string path)
331 if (vst_discover_from_path (path) == 0) {
339 static bool vst_filter (const string& str, void *arg)
341 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
343 return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
347 PluginManager::vst_discover_from_path (string path)
350 vector<string *> *plugin_objects;
351 vector<string *>::iterator x;
354 info << "detecting VST plugins along " << path << endmsg;
356 plugin_objects = scanner (vst_path, vst_filter, 0, true, true);
358 if (plugin_objects) {
359 for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
364 vector_delete (plugin_objects);
369 PluginManager::vst_discover (string path)
373 if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
374 warning << "Cannot get VST information from " << path << endmsg;
378 if (!finfo->canProcessReplacing) {
379 warning << string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
384 PluginInfoPtr info(new VSTPluginInfo);
386 /* what a goddam joke freeware VST is */
388 if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
389 info->name = PBD::basename_nosuffix (path);
391 info->name = finfo->name;
394 info->category = "VST";
397 info->n_inputs = finfo->numInputs;
398 info->n_outputs = finfo->numOutputs;
399 info->type = ARDOUR::VST;
401 _vst_plugin_info.push_back (info);
402 fst_free_info (finfo);
407 #endif // VST_SUPPORT