2 Copyright (C) 2000-2002 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.
24 #include <cstdio> // so libraptor doesn't complain
33 #include <pbd/compose.h>
34 #include <pbd/error.h>
35 #include <pbd/xml++.h>
37 #include <ardour/ardour.h>
38 #include <ardour/session.h>
39 #include <ardour/audioengine.h>
40 #include <ardour/plugin.h>
41 #include <ardour/ladspa_plugin.h>
42 #include <ardour/plugin_manager.h>
44 #ifdef HAVE_AUDIOUNITS
45 #include <ardour/audio_unit.h>
49 #include <ardour/lv2_plugin.h>
52 #include <pbd/stl_delete.h>
57 using namespace ARDOUR;
60 Plugin::Plugin (AudioEngine& e, Session& s)
61 : _engine (e), _session (s)
65 Plugin::Plugin (const Plugin& other)
66 : _engine (other._engine), _session (other._session), _info (other._info)
74 const Plugin::PresetRecord*
75 Plugin::preset_by_label(const string& label)
78 for (map<string,PresetRecord>::const_iterator i = presets.begin(); i != presets.end(); ++i) {
79 if (i->second.label == label) {
86 const Plugin::PresetRecord*
87 Plugin::preset_by_uri(const string& uri)
89 map<string,PresetRecord>::const_iterator pr = presets.find(uri);
90 if (pr != presets.end()) {
97 vector<Plugin::PresetRecord>
100 vector<PresetRecord> result;
102 std::string unique (unique_id());
104 /* XXX problem: AU plugins don't have numeric ID's.
105 Solution: they have a different method of providing presets.
106 XXX sub-problem: implement it.
109 if (!isdigit (unique[0])) {
113 id = atol (unique.c_str());
115 lrdf_uris* set_uris = lrdf_get_setting_uris(id);
118 for (uint32_t i = 0; i < (uint32_t) set_uris->count; ++i) {
119 if (char* label = lrdf_get_label(set_uris->items[i])) {
120 PresetRecord rec(set_uris->items[i], label);
121 result.push_back(rec);
122 presets.insert(std::make_pair(set_uris->items[i], rec));
125 lrdf_free_uris(set_uris);
132 Plugin::load_preset(const string preset_uri)
134 lrdf_defaults* defs = lrdf_get_setting_values(preset_uri.c_str());
137 for (uint32_t i = 0; i < (uint32_t) defs->count; ++i) {
138 // The defs->items[i].pid < defs->count check is to work around
139 // a bug in liblrdf that saves invalid values into the presets file.
140 if (((uint32_t) defs->items[i].pid < (uint32_t) defs->count) && parameter_is_input (defs->items[i].pid)) {
141 set_parameter(defs->items[i].pid, defs->items[i].value);
144 lrdf_free_setting_values(defs);
151 Plugin::save_preset (string uri, string domain)
153 lrdf_portvalue portvalues[parameter_count()];
154 lrdf_defaults defaults;
156 std::string unique (unique_id());
158 /* XXX problem: AU plugins don't have numeric ID's.
159 Solution: they have a different method of providing/saving presets.
160 XXX sub-problem: implement it.
163 if (!isdigit (unique[0])) {
167 id = atol (unique.c_str());
169 defaults.count = parameter_count();
170 defaults.items = portvalues;
172 for (uint32_t i = 0; i < parameter_count(); ++i) {
173 if (parameter_is_input (i)) {
174 portvalues[i].pid = i;
175 portvalues[i].value = get_parameter(i);
180 if ((envvar = getenv ("HOME")) == 0) {
181 warning << _("Could not locate HOME. Preset not saved.") << endmsg;
185 string source(string_compose("file:%1/.%2/rdf/ardour-presets.n3", envvar, domain));
187 map<string,PresetRecord>::const_iterator pr = presets.find(uri);
188 if (pr == presets.end()) {
189 warning << _("Could not find preset ") << uri << endmsg;
192 free(lrdf_add_preset(source.c_str(), pr->second.label.c_str(), id, &defaults));
194 string path = string_compose("%1/.%2", envvar, domain);
195 if (g_mkdir_with_parents (path.c_str(), 0775)) {
196 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
201 if (g_mkdir_with_parents (path.c_str(), 0775)) {
202 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
206 if (lrdf_export_by_source(source.c_str(), source.substr(5).c_str())) {
207 warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
215 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
217 PluginManager *mgr = PluginManager::the_manager();
218 PluginInfoList plugs;
222 plugs = mgr->ladspa_plugin_info();
227 plugs = mgr->lv2_plugin_info();
233 plugs = mgr->vst_plugin_info();
237 #ifdef HAVE_AUDIOUNITS
238 case ARDOUR::AudioUnit:
239 plugs = mgr->au_plugin_info();
244 return PluginPtr ((Plugin *) 0);
247 PluginInfoList::iterator i;
249 for (i = plugs.begin(); i != plugs.end(); ++i) {
250 if (identifier == (*i)->unique_id){
251 return (*i)->load (session);
256 /* hmm, we didn't find it. could be because in older versions of Ardour.
257 we used to store the name of a VST plugin, not its unique ID. so try
261 for (i = plugs.begin(); i != plugs.end(); ++i) {
262 if (identifier == (*i)->name){
263 return (*i)->load (session);
268 return PluginPtr ((Plugin*) 0);
272 Plugin::output_streams () const
274 /* LADSPA & VST should not get here because they do not
275 return "infinite" i/o counts.
277 return ChanCount::ZERO;
281 Plugin::input_streams () const
283 /* LADSPA & VST should not get here because they do not
284 return "infinite" i/o counts.
286 return ChanCount::ZERO;