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.
25 #include <cstdio> // so libraptor doesn't complain
33 #include <pbd/compose.h>
34 #include <pbd/error.h>
35 #include <pbd/pathscanner.h>
36 #include <pbd/xml++.h>
38 #include <ardour/ardour.h>
39 #include <ardour/session.h>
40 #include <ardour/audioengine.h>
41 #include <ardour/plugin.h>
42 #include <ardour/ladspa_plugin.h>
43 #include <ardour/plugin_manager.h>
45 #include <pbd/stl_delete.h>
50 using namespace ARDOUR;
53 Plugin::Plugin (AudioEngine& e, Session& s)
54 : _engine (e), _session (s)
58 Plugin::Plugin (const Plugin& other)
59 : _engine (other._engine), _session (other._session), _info (other._info)
64 Plugin::setup_controls ()
66 uint32_t port_cnt = parameter_count();
68 /* set up a vector of null pointers for the controls.
69 we'll fill this in on an as-needed basis.
72 for (uint32_t i = 0; i < port_cnt; ++i) {
73 controls.push_back (0);
79 for (vector<PortControllable*>::iterator i = controls.begin(); i != controls.end(); ++i) {
87 Plugin::get_nth_control (uint32_t n)
89 if (n >= parameter_count()) {
93 if (controls[n] == 0) {
95 Plugin::ParameterDescriptor desc;
97 get_parameter_descriptor (n, desc);
99 controls[n] = new PortControllable (describe_parameter (n), *this, n,
100 desc.lower, desc.upper, desc.toggled, desc.logarithmic);
106 Plugin::PortControllable::PortControllable (string name, Plugin& p, uint32_t port_id,
107 float low, float up, bool t, bool loga)
108 : Controllable (name), plugin (p), absolute_port (port_id)
114 range = upper - lower;
118 Plugin::PortControllable::set_value (float value)
129 value = lower + (range * value);
136 value = exp(_lower + log(range) * value);
140 plugin.set_parameter (absolute_port, value);
144 Plugin::PortControllable::get_value (void) const
146 float val = plugin.get_parameter (absolute_port);
158 return ((val - lower) / range);
163 Plugin::get_presets()
165 vector<string> labels;
166 lrdf_uris* set_uris = lrdf_get_setting_uris(unique_id());
169 for (uint32_t i = 0; i < (uint32_t) set_uris->count; ++i) {
170 if (char* label = lrdf_get_label(set_uris->items[i])) {
171 labels.push_back(label);
172 presets[label] = set_uris->items[i];
175 lrdf_free_uris(set_uris);
178 // GTK2FIX find an equivalent way to do this with a vector (needed by GUI apis)
185 Plugin::load_preset(const string preset_label)
187 lrdf_defaults* defs = lrdf_get_setting_values(presets[preset_label].c_str());
190 for (uint32_t i = 0; i < (uint32_t) defs->count; ++i) {
191 // The defs->items[i].pid < defs->count check is to work around
192 // a bug in liblrdf that saves invalid values into the presets file.
193 if (((uint32_t) defs->items[i].pid < (uint32_t) defs->count) && parameter_is_input (defs->items[i].pid)) {
194 set_parameter(defs->items[i].pid, defs->items[i].value);
197 lrdf_free_setting_values(defs);
204 Plugin::save_preset (string name, string domain)
206 lrdf_portvalue portvalues[parameter_count()];
207 lrdf_defaults defaults;
208 defaults.count = parameter_count();
209 defaults.items = portvalues;
211 for (uint32_t i = 0; i < parameter_count(); ++i) {
212 if (parameter_is_input (i)) {
213 portvalues[i].pid = i;
214 portvalues[i].value = get_parameter(i);
219 if ((envvar = getenv ("HOME")) == 0) {
220 warning << _("Could not locate HOME. Preset not saved.") << endmsg;
224 string source(string_compose("file:%1/.%2/rdf/ardour-presets.n3", envvar, domain));
226 free(lrdf_add_preset(source.c_str(), name.c_str(), unique_id(), &defaults));
228 string path = string_compose("%1/.%2", envvar, domain);
229 if (g_mkdir_with_parents (path.c_str(), 0775)) {
230 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
235 if (g_mkdir_with_parents (path.c_str(), 0775)) {
236 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
240 if (lrdf_export_by_source(source.c_str(), source.substr(5).c_str())) {
241 warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
249 ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginType type)
251 PluginManager *mgr = PluginManager::the_manager();
252 PluginInfoList plugs;
256 plugs = mgr->ladspa_plugin_info();
261 plugs = mgr->vst_plugin_info();
262 unique_id = 0; // VST plugins don't have a unique id.
266 #ifdef HAVE_AUDIOUNITS
267 case ARDOUR::AudioUnit:
268 plugs = AUPluginInfo::discover ();
269 unique_id = 0; // Neither do AU.
274 return PluginPtr ((Plugin *) 0);
277 PluginInfoList::iterator i;
278 for (i = plugs.begin(); i != plugs.end(); ++i) {
279 if ((name == "" || (*i)->name == name) &&
280 (unique_id == 0 || (*i)->unique_id == unique_id)) {
281 return (*i)->load (session);
285 return PluginPtr ((Plugin*) 0);