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/xml++.h>
36 #include <ardour/ardour.h>
37 #include <ardour/session.h>
38 #include <ardour/audioengine.h>
39 #include <ardour/plugin.h>
40 #include <ardour/ladspa_plugin.h>
41 #include <ardour/plugin_manager.h>
43 #include <pbd/stl_delete.h>
48 using namespace ARDOUR;
51 Plugin::Plugin (AudioEngine& e, Session& s)
52 : _engine (e), _session (s)
56 Plugin::Plugin (const Plugin& other)
57 : _engine (other._engine), _session (other._session), _info (other._info)
68 vector<string> labels;
69 lrdf_uris* set_uris = lrdf_get_setting_uris(unique_id());
72 for (uint32_t i = 0; i < (uint32_t) set_uris->count; ++i) {
73 if (char* label = lrdf_get_label(set_uris->items[i])) {
74 labels.push_back(label);
75 presets[label] = set_uris->items[i];
78 lrdf_free_uris(set_uris);
81 // GTK2FIX find an equivalent way to do this with a vector (needed by GUI apis)
88 Plugin::load_preset(const string preset_label)
90 lrdf_defaults* defs = lrdf_get_setting_values(presets[preset_label].c_str());
93 for (uint32_t i = 0; i < (uint32_t) defs->count; ++i) {
94 // The defs->items[i].pid < defs->count check is to work around
95 // a bug in liblrdf that saves invalid values into the presets file.
96 if (((uint32_t) defs->items[i].pid < (uint32_t) defs->count) && parameter_is_input (defs->items[i].pid)) {
97 set_parameter(defs->items[i].pid, defs->items[i].value);
100 lrdf_free_setting_values(defs);
107 Plugin::save_preset (string name, string domain)
109 lrdf_portvalue portvalues[parameter_count()];
110 lrdf_defaults defaults;
111 defaults.count = parameter_count();
112 defaults.items = portvalues;
114 for (uint32_t i = 0; i < parameter_count(); ++i) {
115 if (parameter_is_input (i)) {
116 portvalues[i].pid = i;
117 portvalues[i].value = get_parameter(i);
122 if ((envvar = getenv ("HOME")) == 0) {
123 warning << _("Could not locate HOME. Preset not saved.") << endmsg;
127 string source(string_compose("file:%1/.%2/rdf/ardour-presets.n3", envvar, domain));
129 free(lrdf_add_preset(source.c_str(), name.c_str(), unique_id(), &defaults));
131 string path = string_compose("%1/.%2", envvar, domain);
132 if (g_mkdir_with_parents (path.c_str(), 0775)) {
133 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
138 if (g_mkdir_with_parents (path.c_str(), 0775)) {
139 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
143 if (lrdf_export_by_source(source.c_str(), source.substr(5).c_str())) {
144 warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
152 ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginType type)
154 PluginManager *mgr = PluginManager::the_manager();
155 PluginInfoList plugs;
159 plugs = mgr->ladspa_plugin_info();
164 plugs = mgr->vst_plugin_info();
165 unique_id = 0; // VST plugins don't have a unique id.
169 #ifdef HAVE_AUDIOUNITS
170 case ARDOUR::AudioUnit:
171 plugs = AUPluginInfo::discover ();
172 unique_id = 0; // Neither do AU.
177 return PluginPtr ((Plugin *) 0);
180 PluginInfoList::iterator i;
181 for (i = plugs.begin(); i != plugs.end(); ++i) {
182 if ((name == "" || (*i)->name == name) &&
183 (unique_id == 0 || (*i)->unique_id == unique_id)) {
184 return (*i)->load (session);
188 return PluginPtr ((Plugin*) 0);