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.
21 #include <cstdio> /* for snprintf, grrr */
23 #include <pbd/failed_constructor.h>
24 #include <pbd/xml++.h>
26 #include <ardour/ardour.h>
27 #include <ardour/configuration.h>
28 #include <ardour/audio_diskstream.h>
29 #include <ardour/control_protocol_manager.h>
33 using namespace ARDOUR;
37 /* this is global so that we do not have to indirect through an object pointer
42 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
45 Configuration::Configuration ()
47 /* construct variables */
48 #undef CONFIG_VARIABLE
49 #undef CONFIG_VARIABLE_SPECIAL
50 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
51 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
52 #include "ardour/configuration_vars.h"
53 #undef CONFIG_VARIABLE
54 #undef CONFIG_VARIABLE_SPECIAL
56 current_owner (ConfigVariableBase::Default)
58 _control_protocol_state = 0;
61 Configuration::~Configuration ()
66 Configuration::set_current_owner (ConfigVariableBase::Owner owner)
68 current_owner = owner;
72 Configuration::load_state ()
76 /* load system configuration first */
78 rcfile = find_config_file ("ardour_system.rc");
80 if (rcfile.length()) {
84 cerr << string_compose (_("loading system configuration file %1"), rcfile) << endl;
86 if (!tree.read (rcfile.c_str())) {
87 error << string_compose(_("Ardour: cannot read system configuration file \"%1\""), rcfile) << endmsg;
91 current_owner = ConfigVariableBase::System;
93 if (set_state (*tree.root())) {
94 error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
100 /* now load configuration file for user */
102 rcfile = find_config_file ("ardour.rc");
104 if (rcfile.length()) {
108 cerr << string_compose (_("loading user configuration file %1"), rcfile) << endl;
110 if (!tree.read (rcfile)) {
111 error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg;
115 current_owner = ConfigVariableBase::Config;
117 if (set_state (*tree.root())) {
118 error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
127 Configuration::save_state()
132 rcfile = get_user_ardour_path ();
133 rcfile += "ardour.rc";
135 if (rcfile.length()) {
136 tree.set_root (&get_state());
137 if (!tree.write (rcfile.c_str())){
138 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
147 Configuration::save_config_options_predicate (ConfigVariableBase::Owner owner)
149 /* only save things that were in the config file to start with */
150 return owner & ConfigVariableBase::Config;
154 Configuration::get_state ()
157 LocaleGuard lg (X_("POSIX"));
159 root = new XMLNode("Ardour");
160 typedef map<string, MidiPortDescriptor*>::const_iterator CI;
161 for(CI m = midi_ports.begin(); m != midi_ports.end(); ++m){
162 root->add_child_nocopy(m->second->get_state());
165 root->add_child_nocopy (get_variables (sigc::mem_fun (*this, &Configuration::save_config_options_predicate)));
168 root->add_child_copy (*_extra_xml);
171 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
177 Configuration::get_variables (sigc::slot<bool,ConfigVariableBase::Owner> predicate)
180 LocaleGuard lg (X_("POSIX"));
182 node = new XMLNode("Config");
184 #undef CONFIG_VARIABLE
185 #undef CONFIG_VARIABLE_SPECIAL
186 #define CONFIG_VARIABLE(type,var,name,value) \
187 if (predicate (var.owner())) { var.add_to_node (*node); }
188 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
189 if (predicate (var.owner())) { var.add_to_node (*node); }
190 #include "ardour/configuration_vars.h"
191 #undef CONFIG_VARIABLE
192 #undef CONFIG_VARIABLE_SPECIAL
198 Configuration::set_state (const XMLNode& root)
200 if (root.name() != "Ardour") {
204 XMLNodeList nlist = root.children();
205 XMLNodeConstIterator niter;
208 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
212 if (node->name() == "MIDI-port") {
215 pair<string,MidiPortDescriptor*> newpair;
216 newpair.second = new MidiPortDescriptor (*node);
217 newpair.first = newpair.second->tag;
218 midi_ports.insert (newpair);
221 catch (failed_constructor& err) {
222 warning << _("ill-formed MIDI port specification in ardour rcfile (ignored)") << endmsg;
225 } else if (node->name() == "Config") {
227 set_variables (*node, ConfigVariableBase::Config);
229 } else if (node->name() == "extra") {
230 _extra_xml = new XMLNode (*node);
232 } else if (node->name() == ControlProtocolManager::state_node_name) {
233 _control_protocol_state = new XMLNode (*node);
237 Diskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample));
243 Configuration::set_variables (const XMLNode& node, ConfigVariableBase::Owner owner)
245 #undef CONFIG_VARIABLE
246 #undef CONFIG_VARIABLE_SPECIAL
247 #define CONFIG_VARIABLE(type,var,name,value) \
248 if (var.set_from_node (node, owner)) { \
249 ParameterChanged (name); \
251 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
252 if (var.set_from_node (node, owner)) { \
253 ParameterChanged (name); \
255 #include "ardour/configuration_vars.h"
256 #undef CONFIG_VARIABLE
257 #undef CONFIG_VARIABLE_SPECIAL
261 Configuration::MidiPortDescriptor::MidiPortDescriptor (const XMLNode& node)
263 const XMLProperty *prop;
264 bool have_tag = false;
265 bool have_device = false;
266 bool have_type = false;
267 bool have_mode = false;
269 if ((prop = node.property ("tag")) != 0) {
274 if ((prop = node.property ("device")) != 0) {
275 device = prop->value();
279 if ((prop = node.property ("type")) != 0) {
280 type = prop->value();
284 if ((prop = node.property ("mode")) != 0) {
285 mode = prop->value();
289 if (!have_tag || !have_device || !have_type || !have_mode) {
290 throw failed_constructor();
295 Configuration::MidiPortDescriptor::get_state()
297 XMLNode* root = new XMLNode("MIDI-port");
299 root->add_property("tag", tag);
300 root->add_property("device", device);
301 root->add_property("type", type);
302 root->add_property("mode", mode);
308 Configuration::map_parameters (sigc::slot<void,const char*> theSlot)
310 #undef CONFIG_VARIABLE
311 #undef CONFIG_VARIABLE_SPECIAL
312 #define CONFIG_VARIABLE(type,var,name,value) theSlot (name);
313 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) theSlot (name);
314 #include "ardour/configuration_vars.h"
315 #undef CONFIG_VARIABLE
316 #undef CONFIG_VARIABLE_SPECIAL
319 bool ConfigVariableBase::show_stores = false;
322 ConfigVariableBase::set_show_stored_values (bool yn)
328 ConfigVariableBase::show_stored_value (const string& str)
331 cerr << "Config variable " << _name << " stored as " << str << endl;
336 ConfigVariableBase::notify ()
338 // placeholder for any debugging desired when a config variable is modified
342 ConfigVariableBase::miss ()
344 // placeholder for any debugging desired when a config variable
345 // is set but to the same value as it already has