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
32 #include <pbd/compose.h>
33 #include <pbd/error.h>
34 #include <pbd/pathscanner.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 #include <pbd/stl_delete.h>
49 using namespace ARDOUR;
52 Plugin::Plugin (AudioEngine& e, Session& s)
53 : _engine (e), _session (s)
57 Plugin::Plugin (const Plugin& other)
58 : _engine (other._engine), _session (other._session), _info (other._info)
63 Plugin::setup_controls ()
65 uint32_t port_cnt = parameter_count();
67 /* set up a vector of null pointers for the controls.
68 we'll fill this in on an as-needed basis.
71 for (uint32_t i = 0; i < port_cnt; ++i) {
72 controls.push_back (0);
78 for (vector<PortControllable*>::iterator i = controls.begin(); i != controls.end(); ++i) {
86 Plugin::get_nth_control (uint32_t n)
88 if (n >= parameter_count()) {
92 if (controls[n] == 0) {
94 Plugin::ParameterDescriptor desc;
96 get_parameter_descriptor (n, desc);
98 controls[n] = new PortControllable (describe_parameter (n), *this, n,
99 desc.lower, desc.upper, desc.toggled, desc.logarithmic);
105 Plugin::PortControllable::PortControllable (string name, Plugin& p, uint32_t port_id,
106 float low, float up, bool t, bool loga)
107 : Controllable (name), plugin (p), absolute_port (port_id)
113 range = upper - lower;
117 Plugin::PortControllable::set_value (float value)
128 value = lower + (range * value);
135 value = exp(_lower + log(range) * value);
139 plugin.set_parameter (absolute_port, value);
143 Plugin::PortControllable::get_value (void) const
145 float val = plugin.get_parameter (absolute_port);
157 return ((val - lower) / range);
162 Plugin::get_presets()
164 vector<string> labels;
165 lrdf_uris* set_uris = lrdf_get_setting_uris(unique_id());
168 for (uint32_t i = 0; i < (uint32_t) set_uris->count; ++i) {
169 if (char* label = lrdf_get_label(set_uris->items[i])) {
170 labels.push_back(label);
171 presets[label] = set_uris->items[i];
174 lrdf_free_uris(set_uris);
177 // GTK2FIX find an equivalent way to do this with a vector (needed by GUI apis)
184 Plugin::load_preset(const string preset_label)
186 lrdf_defaults* defs = lrdf_get_setting_values(presets[preset_label].c_str());
189 for (uint32_t i = 0; i < (uint32_t) defs->count; ++i) {
190 // The defs->items[i].pid < defs->count check is to work around
191 // a bug in liblrdf that saves invalid values into the presets file.
192 if (((uint32_t) defs->items[i].pid < (uint32_t) defs->count) && parameter_is_input (defs->items[i].pid)) {
193 set_parameter(defs->items[i].pid, defs->items[i].value);
196 lrdf_free_setting_values(defs);
203 Plugin::save_preset (string name, string domain)
205 lrdf_portvalue portvalues[parameter_count()];
206 lrdf_defaults defaults;
207 defaults.count = parameter_count();
208 defaults.items = portvalues;
210 for (uint32_t i = 0; i < parameter_count(); ++i) {
211 if (parameter_is_input (i)) {
212 portvalues[i].pid = i;
213 portvalues[i].value = get_parameter(i);
218 if ((envvar = getenv ("HOME")) == 0) {
219 warning << _("Could not locate HOME. Preset not saved.") << endmsg;
223 string source(string_compose("file:%1/.%2/rdf/ardour-presets.n3", envvar, domain));
225 free(lrdf_add_preset(source.c_str(), name.c_str(), unique_id(), &defaults));
227 string path = string_compose("%1/.%2", envvar, domain);
228 if (g_mkdir_with_parents (path.c_str(), 0775)) {
229 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
234 if (g_mkdir_with_parents (path.c_str(), 0775)) {
235 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
239 if (lrdf_export_by_source(source.c_str(), source.substr(5).c_str())) {
240 warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
248 ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginType type)
250 PluginManager *mgr = PluginManager::the_manager();
251 PluginInfoList plugs;
255 plugs = mgr->ladspa_plugin_info();
260 plugs = mgr->vst_plugin_info();
261 unique_id = 0; // VST plugins don't have a unique id.
265 #ifdef HAVE_AUDIOUNITS
266 case ARDOUR::AudioUnit:
267 plugs = AUPluginInfo::discover ();
268 unique_id = 0; // Neither do AU.
273 return PluginPtr ((Plugin *) 0);
276 PluginInfoList::iterator i;
277 for (i = plugs.begin(); i != plugs.end(); ++i) {
278 if ((name == "" || (*i)->name == name) &&
279 (unique_id == 0 || (*i)->unique_id == unique_id)) {
280 return (*i)->load (session);
284 return PluginPtr ((Plugin*) 0);