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 (*this, n, desc.lower, desc.upper, desc.toggled, desc.logarithmic);
105 Plugin::PortControllable::PortControllable (Plugin& p, uint32_t port_id, float low, float up, bool t, bool loga)
106 : plugin (p), absolute_port (port_id)
112 range = upper - lower;
116 Plugin::PortControllable::set_value (float value)
127 value = lower + (range * value);
134 value = exp(_lower + log(range) * value);
138 plugin.set_parameter (absolute_port, value);
142 Plugin::PortControllable::get_value (void) const
144 float val = plugin.get_parameter (absolute_port);
156 return ((val - lower) / range);
161 Plugin::get_presets()
163 vector<string> labels;
164 lrdf_uris* set_uris = lrdf_get_setting_uris(unique_id());
167 for (uint32_t i = 0; i < (uint32_t) set_uris->count; ++i) {
168 if (char* label = lrdf_get_label(set_uris->items[i])) {
169 labels.push_back(label);
170 presets[label] = set_uris->items[i];
173 lrdf_free_uris(set_uris);
176 // GTK2FIX find an equivalent way to do this with a vector (needed by GUI apis)
183 Plugin::load_preset(const string preset_label)
185 lrdf_defaults* defs = lrdf_get_setting_values(presets[preset_label].c_str());
188 for (uint32_t i = 0; i < (uint32_t) defs->count; ++i) {
189 // The defs->items[i].pid < defs->count check is to work around
190 // a bug in liblrdf that saves invalid values into the presets file.
191 if (((uint32_t) defs->items[i].pid < (uint32_t) defs->count) && parameter_is_input (defs->items[i].pid)) {
192 set_parameter(defs->items[i].pid, defs->items[i].value);
195 lrdf_free_setting_values(defs);
202 Plugin::save_preset (string name, string domain)
204 lrdf_portvalue portvalues[parameter_count()];
205 lrdf_defaults defaults;
206 defaults.count = parameter_count();
207 defaults.items = portvalues;
209 for (uint32_t i = 0; i < parameter_count(); ++i) {
210 if (parameter_is_input (i)) {
211 portvalues[i].pid = i;
212 portvalues[i].value = get_parameter(i);
217 if ((envvar = getenv ("HOME")) == 0) {
218 warning << _("Could not locate HOME. Preset not saved.") << endmsg;
222 string source(string_compose("file:%1/.%2/rdf/ardour-presets.n3", envvar, domain));
224 free(lrdf_add_preset(source.c_str(), name.c_str(), unique_id(), &defaults));
226 string path = string_compose("%1/.%2", envvar, domain);
227 if (mkdir(path.c_str(), 0775) && errno != EEXIST) {
228 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
233 if (mkdir(path.c_str(), 0775) && errno != EEXIST) {
234 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
238 if (lrdf_export_by_source(source.c_str(), source.substr(5).c_str())) {
239 warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
247 ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginType type)
249 PluginManager *mgr = PluginManager::the_manager();
250 PluginInfoList plugs;
254 plugs = mgr->ladspa_plugin_info();
259 plugs = mgr->vst_plugin_info();
260 unique_id = 0; // VST plugins don't have a unique id.
264 #ifdef HAVE_COREAUDIO
265 case ARDOUR::AudioUnit:
266 plugs = AUPluginInfo::discover ();
267 unique_id = 0; // Neither do AU.
272 return PluginPtr ((Plugin *) 0);
275 PluginInfoList::iterator i;
276 for (i = plugs.begin(); i != plugs.end(); ++i) {
277 if ((name == "" || (*i)->name == name) &&
278 (unique_id == 0 || (*i)->unique_id == unique_id)) {
279 return (*i)->load (session);
283 return PluginPtr ((Plugin*) 0);