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>
29 #include <pbd/basename.h>
33 #include <glibmm/miscutils.h>
35 #include <pbd/pathscanner.h>
36 #include <pbd/whitespace.h>
38 #include <ardour/ladspa.h>
39 #include <ardour/session.h>
40 #include <ardour/plugin_manager.h>
41 #include <ardour/plugin.h>
42 #include <ardour/ladspa_plugin.h>
45 #include <slv2/slv2.h>
46 #include <ardour/lv2_plugin.h>
50 #include <ardour/vst_plugin.h>
53 #ifdef HAVE_AUDIOUNITS
54 #include <ardour/audio_unit.h>
55 #include <Carbon/Carbon.h>
58 #include <pbd/error.h>
59 #include <pbd/stl_delete.h>
63 using namespace ARDOUR
;
67 PluginManager
* PluginManager::_manager
= 0;
69 PluginManager::PluginManager ()
77 ProcessSerialNumber psn
= { 0, kCurrentProcess
};
78 OSStatus returnCode
= TransformProcessType(& psn
, kProcessTransformToForegroundApplication
);
79 if( returnCode
!= 0) {
80 error
<< _("Cannot become GUI app") << endmsg
;
84 if ((s
= getenv ("LADSPA_RDF_PATH"))){
88 if (lrdf_path
.length() == 0) {
89 lrdf_path
= "/usr/local/share/ladspa/rdf:/usr/share/ladspa/rdf";
92 add_lrdf_data(lrdf_path
);
95 if (Config
->get_use_vst()) {
98 #endif /* VST_SUPPORT */
100 if ((s
= getenv ("LADSPA_PATH"))) {
104 if ((s
= getenv ("VST_PATH"))) {
106 } else if ((s
= getenv ("VST_PLUGINS"))) {
114 /* the plugin manager is constructed too early to use Profile */
116 if (getenv ("ARDOUR_SAE")) {
117 ladspa_plugin_whitelist
.push_back (1203); // single band parametric
118 ladspa_plugin_whitelist
.push_back (1772); // caps compressor
119 ladspa_plugin_whitelist
.push_back (1913); // fast lookahead limiter
120 ladspa_plugin_whitelist
.push_back (1075); // simple RMS expander
121 ladspa_plugin_whitelist
.push_back (1061); // feedback delay line (max 5s)
122 ladspa_plugin_whitelist
.push_back (1216); // gverb
123 ladspa_plugin_whitelist
.push_back (2150); // tap pitch shifter
127 _lv2_world
= new LV2World();
130 BootMessage (_("Discovering Plugins"));
136 PluginManager::refresh ()
143 if (Config
->get_use_vst()) {
146 #endif // VST_SUPPORT
147 #ifdef HAVE_AUDIOUNITS
153 PluginManager::ladspa_refresh ()
155 _ladspa_plugin_info
.clear ();
157 static const char *standard_paths
[] = {
158 "/usr/local/lib64/ladspa",
159 "/usr/local/lib/ladspa",
162 "/Library/Audio/Plug-Ins/LADSPA",
166 /* allow LADSPA_PATH to augment, not override standard locations */
168 /* Only add standard locations to ladspa_path if it doesn't
169 * already contain them. Check for trailing '/'s too.
173 for (i
= 0; standard_paths
[i
][0]; i
++) {
174 size_t found
= ladspa_path
.find(standard_paths
[i
]);
175 if (found
!= ladspa_path
.npos
) {
176 switch (ladspa_path
[found
+ strlen(standard_paths
[i
])]) {
181 if (ladspa_path
[found
+ strlen(standard_paths
[i
]) + 1] == ':' ||
182 ladspa_path
[found
+ strlen(standard_paths
[i
]) + 1] == '\0') {
187 if (!ladspa_path
.empty())
190 ladspa_path
+= standard_paths
[i
];
194 ladspa_discover_from_path (ladspa_path
);
199 PluginManager::add_ladspa_directory (string path
)
201 if (ladspa_discover_from_path (path
) == 0) {
209 static bool ladspa_filter (const string
& str
, void *arg
)
211 /* Not a dotfile, has a prefix before a period, suffix is "so" */
213 return str
[0] != '.' && (str
.length() > 3 && str
.find (".so") == (str
.length() - 3));
217 PluginManager::ladspa_discover_from_path (string path
)
220 vector
<string
*> *plugin_objects
;
221 vector
<string
*>::iterator x
;
224 plugin_objects
= scanner (ladspa_path
, ladspa_filter
, 0, true, true);
226 if (plugin_objects
) {
227 for (x
= plugin_objects
->begin(); x
!= plugin_objects
->end (); ++x
) {
228 ladspa_discover (**x
);
232 vector_delete (plugin_objects
);
236 static bool rdf_filter (const string
&str
, void *arg
)
238 return str
[0] != '.' &&
239 ((str
.find(".rdf") == (str
.length() - 4)) ||
240 (str
.find(".rdfs") == (str
.length() - 5)) ||
241 (str
.find(".n3") == (str
.length() - 3)));
245 PluginManager::add_ladspa_presets()
247 add_presets ("ladspa");
251 PluginManager::add_vst_presets()
256 PluginManager::add_presets(string domain
)
260 vector
<string
*> *presets
;
261 vector
<string
*>::iterator x
;
264 if ((envvar
= getenv ("HOME")) == 0) {
268 string path
= string_compose("%1/.%2/rdf", envvar
, domain
);
269 presets
= scanner (path
, rdf_filter
, 0, true, true);
272 for (x
= presets
->begin(); x
!= presets
->end (); ++x
) {
273 string file
= "file:" + **x
;
274 if (lrdf_read_file(file
.c_str())) {
275 warning
<< string_compose(_("Could not parse rdf file: %1"), *x
) << endmsg
;
280 vector_delete (presets
);
284 PluginManager::add_lrdf_data (const string
&path
)
287 vector
<string
*>* rdf_files
;
288 vector
<string
*>::iterator x
;
291 rdf_files
= scanner (path
, rdf_filter
, 0, true, true);
294 for (x
= rdf_files
->begin(); x
!= rdf_files
->end (); ++x
) {
295 uri
= "file://" + **x
;
297 if (lrdf_read_file(uri
.c_str())) {
298 warning
<< "Could not parse rdf file: " << uri
<< endmsg
;
303 vector_delete (rdf_files
);
307 PluginManager::ladspa_discover (string path
)
310 const LADSPA_Descriptor
*descriptor
;
311 LADSPA_Descriptor_Function dfunc
;
314 if ((module
= dlopen (path
.c_str(), RTLD_NOW
)) == 0) {
315 error
<< string_compose(_("LADSPA: cannot load module \"%1\" (%2)"), path
, dlerror()) << endmsg
;
319 dfunc
= (LADSPA_Descriptor_Function
) dlsym (module
, "ladspa_descriptor");
321 if ((errstr
= dlerror()) != 0) {
322 error
<< string_compose(_("LADSPA: module \"%1\" has no descriptor function."), path
) << endmsg
;
323 error
<< errstr
<< endmsg
;
328 for (uint32_t i
= 0; ; ++i
) {
329 if ((descriptor
= dfunc (i
)) == 0) {
333 if (!ladspa_plugin_whitelist
.empty()) {
334 if (find (ladspa_plugin_whitelist
.begin(), ladspa_plugin_whitelist
.end(), descriptor
->UniqueID
) == ladspa_plugin_whitelist
.end()) {
339 PluginInfoPtr
info(new LadspaPluginInfo
);
340 info
->name
= descriptor
->Name
;
341 info
->category
= get_ladspa_category(descriptor
->UniqueID
);
342 info
->creator
= descriptor
->Maker
;
347 info
->type
= ARDOUR::LADSPA
;
350 snprintf (buf
, sizeof (buf
), "%lu", descriptor
->UniqueID
);
351 info
->unique_id
= buf
;
353 for (uint32_t n
=0; n
< descriptor
->PortCount
; ++n
) {
354 if ( LADSPA_IS_PORT_AUDIO (descriptor
->PortDescriptors
[n
]) ) {
355 if ( LADSPA_IS_PORT_INPUT (descriptor
->PortDescriptors
[n
]) ) {
358 else if ( LADSPA_IS_PORT_OUTPUT (descriptor
->PortDescriptors
[n
]) ) {
364 if(_ladspa_plugin_info
.empty()){
365 _ladspa_plugin_info
.push_back (info
);
368 //Ensure that the plugin is not already in the plugin list.
372 for (PluginInfoList::const_iterator i
= _ladspa_plugin_info
.begin(); i
!= _ladspa_plugin_info
.end(); ++i
) {
373 if(0 == info
->unique_id
.compare((*i
)->unique_id
)){
379 _ladspa_plugin_info
.push_back (info
);
383 // GDB WILL NOT LIKE YOU IF YOU DO THIS
390 PluginManager::get_ladspa_category (uint32_t plugin_id
)
393 lrdf_statement pattern
;
395 snprintf(buf
, sizeof(buf
), "%s%" PRIu32
, LADSPA_BASE
, plugin_id
);
396 pattern
.subject
= buf
;
397 pattern
.predicate
= (char*)RDF_TYPE
;
399 pattern
.object_type
= lrdf_uri
;
401 lrdf_statement
* matches1
= lrdf_matches (&pattern
);
407 pattern
.subject
= matches1
->object
;
408 pattern
.predicate
= (char*)(LADSPA_BASE
"hasLabel");
410 pattern
.object_type
= lrdf_literal
;
412 lrdf_statement
* matches2
= lrdf_matches (&pattern
);
413 lrdf_free_statements(matches1
);
419 string label
= matches2
->object
;
420 lrdf_free_statements(matches2
);
427 PluginManager::lv2_refresh ()
433 PluginManager::lv2_discover ()
435 _lv2_plugin_info
= LV2PluginInfo::discover(_lv2_world
);
440 #ifdef HAVE_AUDIOUNITS
442 PluginManager::au_refresh ()
448 PluginManager::au_discover ()
450 _au_plugin_info
= AUPluginInfo::discover();
459 PluginManager::vst_refresh ()
461 _vst_plugin_info
.clear ();
463 if (vst_path
.length() == 0) {
464 vst_path
= "/usr/local/lib/vst:/usr/lib/vst";
467 vst_discover_from_path (vst_path
);
471 PluginManager::add_vst_directory (string path
)
473 if (vst_discover_from_path (path
) == 0) {
481 static bool vst_filter (const string
& str
, void *arg
)
483 /* Not a dotfile, has a prefix before a period, suffix is "dll" */
485 return str
[0] != '.' && (str
.length() > 4 && str
.find (".dll") == (str
.length() - 4));
489 PluginManager::vst_discover_from_path (string path
)
492 vector
<string
*> *plugin_objects
;
493 vector
<string
*>::iterator x
;
496 info
<< "detecting VST plugins along " << path
<< endmsg
;
498 plugin_objects
= scanner (vst_path
, vst_filter
, 0, true, true);
500 if (plugin_objects
) {
501 for (x
= plugin_objects
->begin(); x
!= plugin_objects
->end (); ++x
) {
502 std::cerr
<< " discovering " << **x
<< std::endl
;
507 vector_delete (plugin_objects
);
512 PluginManager::vst_discover (string path
)
517 if ((finfo
= fst_get_info (const_cast<char *> (path
.c_str()))) == 0) {
518 warning
<< "Cannot get VST information from " << path
<< endmsg
;
522 if (!finfo
->canProcessReplacing
) {
523 warning
<< string_compose (_("VST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
528 PluginInfoPtr
info(new VSTPluginInfo
);
530 /* what a goddam joke freeware VST is */
532 if (!strcasecmp ("The Unnamed plugin", finfo
->name
)) {
533 info
->name
= PBD::basename_nosuffix (path
);
535 info
->name
= finfo
->name
;
539 snprintf (buf
, sizeof (buf
), "%d", finfo
->UniqueID
);
540 info
->unique_id
= buf
;
541 info
->category
= "VST";
543 info
->creator
= finfo
->creator
;
545 info
->n_inputs
= finfo
->numInputs
;
546 info
->n_outputs
= finfo
->numOutputs
;
547 info
->type
= ARDOUR::VST
;
549 _vst_plugin_info
.push_back (info
);
550 fst_free_info (finfo
);
555 #endif // VST_SUPPORT
557 PluginManager::PluginStatusType
558 PluginManager::get_status (const PluginInfoPtr
& pi
)
560 PluginStatus
ps (pi
->type
, pi
->unique_id
);
561 PluginStatusList::const_iterator i
= find (statuses
.begin(), statuses
.end(), ps
);
562 if (i
== statuses
.end() ) {
570 PluginManager::save_statuses ()
572 Glib::ustring path
= Glib::build_filename (get_user_ardour_path (), "plugin_statuses");
575 ofs
.open (path
.c_str(), ios_base::openmode (ios::out
|ios::trunc
));
581 for (PluginStatusList::iterator i
= statuses
.begin(); i
!= statuses
.end(); ++i
) {
599 switch ((*i
).status
) {
613 ofs
<< (*i
).unique_id
;
622 PluginManager::load_statuses ()
624 Glib::ustring path
= Glib::build_filename (get_user_ardour_path (),"plugin_statuses");
626 ifstream
ifs (path
.c_str());
636 PluginStatusType status
;
653 /* rest of the line is the plugin ID */
655 ifs
.getline (buf
, sizeof (buf
), '\n');
660 if (sstatus
== "Normal") {
662 } else if (sstatus
== "Favorite") {
664 } else if (sstatus
== "Hidden") {
667 error
<< string_compose (_("unknown plugin status type \"%1\" - all entries ignored"), sstatus
)
673 if (stype
== "LADSPA") {
675 } else if (stype
== "AudioUnit") {
677 } else if (stype
== "LV2") {
679 } else if (stype
== "VST") {
682 error
<< string_compose (_("unknown plugin type \"%1\" - ignored"), stype
)
688 strip_whitespace_edges (id
);
690 #ifdef HAVE_AUDIOUNITS
691 if (type
== AudioUnit
) {
692 string fixed
= AUPlugin::maybe_fix_broken_au_id (id
);
694 error
<< string_compose (_("Your favorite plugin list contains an AU plugin whose ID cannot be understood - ignored (%1)"), id
) << endmsg
;
700 set_status (type
, id
, status
);
707 PluginManager::set_status (PluginType t
, string id
, PluginStatusType status
)
709 PluginStatus
ps (t
, id
, status
);
712 if (status
== Normal
) {
716 pair
<PluginStatusList::iterator
, bool> res
= statuses
.insert (ps
);