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 #ifdef HAVE_AUDIOUNITS
44 #include <ardour/audio_unit.h>
47 #include <pbd/stl_delete.h>
52 using namespace ARDOUR;
55 Plugin::Plugin (AudioEngine& e, Session& s)
56 : _engine (e), _session (s)
60 Plugin::Plugin (const Plugin& other)
61 : _engine (other._engine), _session (other._session), _info (other._info)
72 vector<string> labels;
74 std::string unique (unique_id());
76 /* XXX problem: AU plugins don't have numeric ID's.
77 Solution: they have a different method of providing presets.
78 XXX sub-problem: implement it.
81 if (!isdigit (unique[0])) {
85 id = atol (unique.c_str());
87 lrdf_uris* set_uris = lrdf_get_setting_uris(id);
90 for (uint32_t i = 0; i < (uint32_t) set_uris->count; ++i) {
91 if (char* label = lrdf_get_label(set_uris->items[i])) {
92 labels.push_back(label);
93 presets[label] = set_uris->items[i];
96 lrdf_free_uris(set_uris);
99 // GTK2FIX find an equivalent way to do this with a vector (needed by GUI apis)
106 Plugin::load_preset(const string preset_label)
108 lrdf_defaults* defs = lrdf_get_setting_values(presets[preset_label].c_str());
111 for (uint32_t i = 0; i < (uint32_t) defs->count; ++i) {
112 // The defs->items[i].pid < defs->count check is to work around
113 // a bug in liblrdf that saves invalid values into the presets file.
114 if (((uint32_t) defs->items[i].pid < (uint32_t) defs->count) && parameter_is_input (defs->items[i].pid)) {
115 set_parameter(defs->items[i].pid, defs->items[i].value);
118 lrdf_free_setting_values(defs);
125 Plugin::save_preset (string name, string domain)
127 lrdf_portvalue portvalues[parameter_count()];
128 lrdf_defaults defaults;
130 std::string unique (unique_id());
132 /* XXX problem: AU plugins don't have numeric ID's.
133 Solution: they have a different method of providing/saving presets.
134 XXX sub-problem: implement it.
137 if (!isdigit (unique[0])) {
141 id = atol (unique.c_str());
143 defaults.count = parameter_count();
144 defaults.items = portvalues;
146 for (uint32_t i = 0; i < parameter_count(); ++i) {
147 if (parameter_is_input (i)) {
148 portvalues[i].pid = i;
149 portvalues[i].value = get_parameter(i);
154 if ((envvar = getenv ("HOME")) == 0) {
155 warning << _("Could not locate HOME. Preset not saved.") << endmsg;
159 string source(string_compose("file:%1/.%2/rdf/ardour-presets.n3", envvar, domain));
161 free(lrdf_add_preset(source.c_str(), name.c_str(), id, &defaults));
163 string path = string_compose("%1/.%2", envvar, domain);
164 if (g_mkdir_with_parents (path.c_str(), 0775)) {
165 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
170 if (g_mkdir_with_parents (path.c_str(), 0775)) {
171 warning << string_compose(_("Could not create %1. Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
175 if (lrdf_export_by_source(source.c_str(), source.substr(5).c_str())) {
176 warning << string_compose(_("Error saving presets file %1."), source) << endmsg;
184 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
186 PluginManager *mgr = PluginManager::the_manager();
187 PluginInfoList plugs;
191 plugs = mgr->ladspa_plugin_info();
196 plugs = mgr->vst_plugin_info();
200 #ifdef HAVE_AUDIOUNITS
201 case ARDOUR::AudioUnit:
202 plugs = mgr->au_plugin_info();
207 return PluginPtr ((Plugin *) 0);
210 PluginInfoList::iterator i;
212 for (i = plugs.begin(); i != plugs.end(); ++i) {
213 if (identifier == (*i)->unique_id){
214 return (*i)->load (session);
218 return PluginPtr ((Plugin*) 0);