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)
67 Plugin::Plugin (const Plugin& other)
68 : _engine (other._engine)
69 , _session (other._session)
72 , presets (other.presets)
80 const Plugin::PresetRecord*
81 Plugin::preset_by_label(const string& label)
84 for (map<string,PresetRecord>::const_iterator i = presets.begin(); i != presets.end(); ++i) {
85 if (i->second.label == label) {
92 const Plugin::PresetRecord*
93 Plugin::preset_by_uri(const string& uri)
95 map<string,PresetRecord>::const_iterator pr = presets.find(uri);
96 if (pr != presets.end()) {
103 vector<Plugin::PresetRecord>
104 Plugin::get_presets()
106 vector<PresetRecord> result;
108 std::string unique (unique_id());
110 /* XXX problem: AU plugins don't have numeric ID's.
111 Solution: they have a different method of providing presets.
112 XXX sub-problem: implement it.
115 if (!isdigit (unique[0])) {
119 id = atol (unique.c_str());
121 lrdf_uris* set_uris = lrdf_get_setting_uris(id);
124 for (uint32_t i = 0; i < (uint32_t) set_uris->count; ++i) {
125 if (char* label = lrdf_get_label(set_uris->items[i])) {
126 PresetRecord rec(set_uris->items[i], label);
127 result.push_back(rec);
128 presets.insert(std::make_pair(set_uris->items[i], rec));
131 lrdf_free_uris(set_uris);
138 Plugin::load_preset(const string preset_uri)
140 lrdf_defaults* defs = lrdf_get_setting_values(preset_uri.c_str());
143 for (uint32_t i = 0; i < (uint32_t) defs->count; ++i) {
144 // The defs->items[i].pid < defs->count check is to work around
145 // a bug in liblrdf that saves invalid values into the presets file.
146 if (((uint32_t) defs->items[i].pid < (uint32_t) defs->count) && parameter_is_input (defs->items[i].pid)) {
147 set_parameter(defs->items[i].pid, defs->items[i].value);
150 lrdf_free_setting_values(defs);
157 Plugin::save_preset (string uri, string domain)
159 lrdf_portvalue portvalues[parameter_count()];
160 lrdf_defaults defaults;
162 std::string unique (unique_id());
164 /* XXX problem: AU plugins don't have numeric ID's.
165 Solution: they have a different method of providing/saving presets.
166 XXX sub-problem: implement it.
169 if (!isdigit (unique[0])) {
173 id = atol (unique.c_str());
175 defaults.count = parameter_count();
176 defaults.items = portvalues;
178 for (uint32_t i = 0; i < parameter_count(); ++i) {
179 if (parameter_is_input (i)) {
180 portvalues[i].pid = i;
181 portvalues[i].value = get_parameter(i);
186 if ((envvar = getenv ("HOME")) == 0) {
187 warning << _("Could not locate HOME. Preset not saved.") << endmsg;
191 string source(string_compose("file:%1/.%2/rdf/ardour-presets.n3", envvar, domain));
193 map<string,PresetRecord>::const_iterator pr = presets.find(uri);
194 if (pr == presets.end()) {
195 warning << _("Could not find preset ") << uri << endmsg;
198 free(lrdf_add_preset(source.c_str(), pr->second.label.c_str(), id, &defaults));
200 string path = string_compose("%1/.%2", envvar, domain);
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;
207 if (g_mkdir_with_parents (path.c_str(), 0775)) {
208 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
212 if (lrdf_export_by_source(source.c_str(), source.substr(5).c_str())) {
213 warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
221 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
223 PluginManager *mgr = PluginManager::the_manager();
224 PluginInfoList plugs;
228 plugs = mgr->ladspa_plugin_info();
233 plugs = mgr->lv2_plugin_info();
239 plugs = mgr->vst_plugin_info();
243 #ifdef HAVE_AUDIOUNITS
244 case ARDOUR::AudioUnit:
245 plugs = mgr->au_plugin_info();
250 return PluginPtr ((Plugin *) 0);
253 PluginInfoList::iterator i;
255 for (i = plugs.begin(); i != plugs.end(); ++i) {
256 if (identifier == (*i)->unique_id){
257 return (*i)->load (session);
262 /* hmm, we didn't find it. could be because in older versions of Ardour.
263 we used to store the name of a VST plugin, not its unique ID. so try
267 for (i = plugs.begin(); i != plugs.end(); ++i) {
268 if (identifier == (*i)->name){
269 return (*i)->load (session);
274 return PluginPtr ((Plugin*) 0);
278 Plugin::output_streams () const
280 /* LADSPA & VST should not get here because they do not
281 return "infinite" i/o counts.
283 return ChanCount::ZERO;
287 Plugin::input_streams () const
289 /* LADSPA & VST should not get here because they do not
290 return "infinite" i/o counts.
292 return ChanCount::ZERO;