2 Copyright (C) 1999-2006 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.
22 #include <cstdio> /* for snprintf, grrr */
24 #include <pbd/failed_constructor.h>
25 #include <pbd/xml++.h>
27 #include <ardour/ardour.h>
28 #include <ardour/audio_library.h>
29 #include <ardour/configuration.h>
30 #include <ardour/audio_diskstream.h>
31 #include <ardour/destructive_filesource.h>
32 #include <ardour/control_protocol_manager.h>
36 using namespace ARDOUR;
40 /* this is global so that we do not have to indirect through an object pointer
45 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
48 Configuration::Configuration ()
50 /* construct variables */
51 #undef CONFIG_VARIABLE
52 #undef CONFIG_VARIABLE_SPECIAL
53 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
54 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
55 #include "ardour/configuration_vars.h"
56 #undef CONFIG_VARIABLE
57 #undef CONFIG_VARIABLE_SPECIAL
59 current_owner (ConfigVariableBase::Default)
61 _control_protocol_state = 0;
64 Configuration::~Configuration ()
69 Configuration::set_current_owner (ConfigVariableBase::Owner owner)
71 current_owner = owner;
75 Configuration::load_state ()
79 /* load system configuration first */
81 rcfile = find_config_file ("ardour_system.rc");
83 if (rcfile.length()) {
87 cerr << string_compose (_("loading system configuration file %1"), rcfile) << endl;
89 if (!tree.read (rcfile.c_str())) {
90 error << string_compose(_("Ardour: cannot read system configuration file \"%1\""), rcfile) << endmsg;
94 current_owner = ConfigVariableBase::System;
96 if (set_state (*tree.root())) {
97 error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
103 /* now load configuration file for user */
105 rcfile = find_config_file ("ardour.rc");
107 if (rcfile.length()) {
111 cerr << string_compose (_("loading user configuration file %1"), rcfile) << endl;
113 if (!tree.read (rcfile)) {
114 error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg;
118 current_owner = ConfigVariableBase::Config;
120 if (set_state (*tree.root())) {
121 error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
130 Configuration::save_state()
135 /* Note: this only writes the state not touched by Session or Interface
138 rcfile = get_user_ardour_path ();
139 rcfile += "ardour.rc";
141 if (rcfile.length()) {
142 tree.set_root (&state (ConfigVariableBase::Config));
143 if (!tree.write (rcfile.c_str())){
144 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
153 Configuration::get_state ()
155 return state (ConfigVariableBase::Config);
159 Configuration::get_partial_state (ConfigVariableBase::Owner owner)
161 return state (owner);
165 Configuration::state (ConfigVariableBase::Owner owner)
169 LocaleGuard lg (X_("POSIX"));
171 node = new XMLNode("Config");
173 #undef CONFIG_VARIABLE
174 #undef CONFIG_VARIABLE_SPECIAL
175 #define CONFIG_VARIABLE(type,var,name,value) \
176 if (var.owner() <= owner) var.add_to_node (*node);
177 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
178 if (var.owner() <= owner) var.add_to_node (*node);
179 #include "ardour/configuration_vars.h"
180 #undef CONFIG_VARIABLE
181 #undef CONFIG_VARIABLE_SPECIAL
183 if (owner == ConfigVariableBase::Config) {
185 root = new XMLNode("Ardour");
186 typedef map<string, MidiPortDescriptor*>::const_iterator CI;
187 for(CI m = midi_ports.begin(); m != midi_ports.end(); ++m){
188 root->add_child_nocopy(m->second->get_state());
191 root->add_child_nocopy (*node);
194 root->add_child_copy (*_extra_xml);
197 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
198 root->add_child_nocopy (Library->get_state());
209 Configuration::set_state (const XMLNode& root)
211 if (root.name() != "Ardour") {
215 XMLNodeList nlist = root.children();
216 XMLNodeConstIterator niter;
219 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
223 if (node->name() == "MIDI-port") {
226 pair<string,MidiPortDescriptor*> newpair;
227 newpair.second = new MidiPortDescriptor (*node);
228 newpair.first = newpair.second->tag;
229 midi_ports.insert (newpair);
232 catch (failed_constructor& err) {
233 warning << _("ill-formed MIDI port specification in ardour rcfile (ignored)") << endmsg;
236 } else if (node->name() == "Config") {
238 set_variables (*node, ConfigVariableBase::Config);
240 } else if (node->name() == "extra") {
241 _extra_xml = new XMLNode (*node);
243 } else if (node->name() == ControlProtocolManager::state_node_name) {
244 _control_protocol_state = new XMLNode (*node);
245 } else if (node->name() == AudioLibrary::state_node_name) {
246 Library->set_state (*node);
250 Diskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample));
256 Configuration::set_variables (const XMLNode& node, ConfigVariableBase::Owner owner)
258 #undef CONFIG_VARIABLE
259 #undef CONFIG_VARIABLE_SPECIAL
260 #define CONFIG_VARIABLE(type,var,name,value) \
261 if (var.set_from_node (node, owner)) { \
262 ParameterChanged (name); \
264 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
265 if (var.set_from_node (node, owner)) { \
266 ParameterChanged (name); \
268 #include "ardour/configuration_vars.h"
269 #undef CONFIG_VARIABLE
270 #undef CONFIG_VARIABLE_SPECIAL
274 Configuration::MidiPortDescriptor::MidiPortDescriptor (const XMLNode& node)
276 const XMLProperty *prop;
277 bool have_tag = false;
278 bool have_device = false;
279 bool have_type = false;
280 bool have_mode = false;
282 if ((prop = node.property ("tag")) != 0) {
287 if ((prop = node.property ("device")) != 0) {
288 device = prop->value();
292 if ((prop = node.property ("type")) != 0) {
293 type = prop->value();
297 if ((prop = node.property ("mode")) != 0) {
298 mode = prop->value();
302 if (!have_tag || !have_device || !have_type || !have_mode) {
303 throw failed_constructor();
308 Configuration::MidiPortDescriptor::get_state()
310 XMLNode* root = new XMLNode("MIDI-port");
312 root->add_property("tag", tag);
313 root->add_property("device", device);
314 root->add_property("type", type);
315 root->add_property("mode", mode);
321 Configuration::map_parameters (sigc::slot<void,const char*> theSlot)
323 #undef CONFIG_VARIABLE
324 #undef CONFIG_VARIABLE_SPECIAL
325 #define CONFIG_VARIABLE(type,var,name,value) theSlot (name);
326 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) theSlot (name);
327 #include "ardour/configuration_vars.h"
328 #undef CONFIG_VARIABLE
329 #undef CONFIG_VARIABLE_SPECIAL