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/configuration.h>
29 #include <ardour/audio_diskstream.h>
30 #include <ardour/destructive_filesource.h>
31 #include <ardour/control_protocol_manager.h>
35 using namespace ARDOUR;
39 /* this is global so that we do not have to indirect through an object pointer
44 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
47 Configuration::Configuration ()
49 /* construct variables */
50 #undef CONFIG_VARIABLE
51 #undef CONFIG_VARIABLE_SPECIAL
52 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
53 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
54 #include "ardour/configuration_vars.h"
55 #undef CONFIG_VARIABLE
56 #undef CONFIG_VARIABLE_SPECIAL
58 current_owner (ConfigVariableBase::Default)
60 _control_protocol_state = 0;
63 Configuration::~Configuration ()
68 Configuration::set_current_owner (ConfigVariableBase::Owner owner)
70 current_owner = owner;
74 Configuration::load_state ()
78 /* load system configuration first */
80 rcfile = find_config_file ("ardour_system.rc");
82 if (rcfile.length()) {
86 cerr << string_compose (_("loading system configuration file %1"), rcfile) << endl;
88 if (!tree.read (rcfile.c_str())) {
89 error << string_compose(_("Ardour: cannot read system configuration file \"%1\""), rcfile) << endmsg;
93 current_owner = ConfigVariableBase::System;
95 if (set_state (*tree.root())) {
96 error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
102 /* now load configuration file for user */
104 rcfile = find_config_file ("ardour.rc");
106 if (rcfile.length()) {
110 cerr << string_compose (_("loading user configuration file %1"), rcfile) << endl;
112 if (!tree.read (rcfile)) {
113 error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg;
117 current_owner = ConfigVariableBase::Config;
119 if (set_state (*tree.root())) {
120 error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
129 Configuration::save_state()
134 rcfile = get_user_ardour_path ();
135 rcfile += "ardour.rc";
137 if (rcfile.length()) {
138 tree.set_root (&get_state());
139 if (!tree.write (rcfile.c_str())){
140 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
149 Configuration::save_config_options_predicate (ConfigVariableBase::Owner owner)
151 /* only save things that were in the config file to start with */
152 return owner & ConfigVariableBase::Config;
156 Configuration::get_state ()
159 LocaleGuard lg (X_("POSIX"));
161 root = new XMLNode("Ardour");
162 typedef map<string, MidiPortDescriptor*>::const_iterator CI;
163 for(CI m = midi_ports.begin(); m != midi_ports.end(); ++m){
164 root->add_child_nocopy(m->second->get_state());
167 root->add_child_nocopy (get_variables (sigc::mem_fun (*this, &Configuration::save_config_options_predicate)));
170 root->add_child_copy (*_extra_xml);
173 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
179 Configuration::get_variables (sigc::slot<bool,ConfigVariableBase::Owner> predicate)
182 LocaleGuard lg (X_("POSIX"));
184 node = new XMLNode("Config");
186 #undef CONFIG_VARIABLE
187 #undef CONFIG_VARIABLE_SPECIAL
188 #define CONFIG_VARIABLE(type,var,name,value) \
189 if (predicate (var.owner())) { var.add_to_node (*node); }
190 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
191 if (predicate (var.owner())) { var.add_to_node (*node); }
192 #include "ardour/configuration_vars.h"
193 #undef CONFIG_VARIABLE
194 #undef CONFIG_VARIABLE_SPECIAL
200 Configuration::set_state (const XMLNode& root)
202 if (root.name() != "Ardour") {
206 XMLNodeList nlist = root.children();
207 XMLNodeConstIterator niter;
210 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
214 if (node->name() == "MIDI-port") {
217 pair<string,MidiPortDescriptor*> newpair;
218 newpair.second = new MidiPortDescriptor (*node);
219 newpair.first = newpair.second->tag;
220 midi_ports.insert (newpair);
223 catch (failed_constructor& err) {
224 warning << _("ill-formed MIDI port specification in ardour rcfile (ignored)") << endmsg;
227 } else if (node->name() == "Config") {
229 set_variables (*node, ConfigVariableBase::Config);
231 } else if (node->name() == "extra") {
232 _extra_xml = new XMLNode (*node);
234 } else if (node->name() == ControlProtocolManager::state_node_name) {
235 _control_protocol_state = new XMLNode (*node);
239 Diskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample));
245 Configuration::set_variables (const XMLNode& node, ConfigVariableBase::Owner owner)
247 #undef CONFIG_VARIABLE
248 #undef CONFIG_VARIABLE_SPECIAL
249 #define CONFIG_VARIABLE(type,var,name,value) \
250 if (var.set_from_node (node, owner)) { \
251 ParameterChanged (name); \
253 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
254 if (var.set_from_node (node, owner)) { \
255 ParameterChanged (name); \
257 #include "ardour/configuration_vars.h"
258 #undef CONFIG_VARIABLE
259 #undef CONFIG_VARIABLE_SPECIAL
263 Configuration::MidiPortDescriptor::MidiPortDescriptor (const XMLNode& node)
265 const XMLProperty *prop;
266 bool have_tag = false;
267 bool have_device = false;
268 bool have_type = false;
269 bool have_mode = false;
271 if ((prop = node.property ("tag")) != 0) {
276 if ((prop = node.property ("device")) != 0) {
277 device = prop->value();
281 if ((prop = node.property ("type")) != 0) {
282 type = prop->value();
286 if ((prop = node.property ("mode")) != 0) {
287 mode = prop->value();
291 if (!have_tag || !have_device || !have_type || !have_mode) {
292 throw failed_constructor();
297 Configuration::MidiPortDescriptor::get_state()
299 XMLNode* root = new XMLNode("MIDI-port");
301 root->add_property("tag", tag);
302 root->add_property("device", device);
303 root->add_property("type", type);
304 root->add_property("mode", mode);
310 Configuration::map_parameters (sigc::slot<void,const char*> theSlot)
312 #undef CONFIG_VARIABLE
313 #undef CONFIG_VARIABLE_SPECIAL
314 #define CONFIG_VARIABLE(type,var,name,value) theSlot (name);
315 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) theSlot (name);
316 #include "ardour/configuration_vars.h"
317 #undef CONFIG_VARIABLE
318 #undef CONFIG_VARIABLE_SPECIAL