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;
38 /* this is global so that we do not have to indirect through an object pointer
43 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
46 Configuration::Configuration ()
48 /* construct variables */
49 #undef CONFIG_VARIABLE
50 #undef CONFIG_VARIABLE_SPECIAL
51 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
52 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
53 #include "ardour/configuration_vars.h"
54 #undef CONFIG_VARIABLE
55 #undef CONFIG_VARIABLE_SPECIAL
57 user_configuration (false)
59 _control_protocol_state = 0;
62 Configuration::~Configuration ()
67 Configuration::load_state ()
71 /* load system configuration first */
73 rcfile = find_config_file ("ardour_system.rc");
75 if (rcfile.length()) {
79 cerr << string_compose (_("loading system configuration file %1"), rcfile) << endl;
81 if (!tree.read (rcfile.c_str())) {
82 error << string_compose(_("Ardour: cannot read system configuration file \"%1\""), rcfile) << endmsg;
86 if (set_state (*tree.root())) {
87 error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
92 /* from this point on, all configuration changes are user driven */
94 user_configuration = true;
96 /* now load configuration file for user */
98 rcfile = find_config_file ("ardour.rc");
100 if (rcfile.length()) {
104 cerr << string_compose (_("loading user configuration file %1"), rcfile) << endl;
106 if (!tree.read (rcfile)) {
107 error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg;
111 if (set_state (*tree.root())) {
112 error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
121 Configuration::save_state()
126 /* Note: this only writes the per-user file, and therefore
127 only saves variables marked as user-set or modified
130 rcfile = get_user_ardour_path ();
131 rcfile += "ardour.rc";
133 if (rcfile.length()) {
134 tree.set_root (&state (true));
135 if (!tree.write (rcfile.c_str())){
136 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
145 Configuration::get_state ()
147 return state (false);
151 Configuration::state (bool user_only)
153 XMLNode* root = new XMLNode("Ardour");
154 LocaleGuard lg (X_("POSIX"));
156 typedef map<string, MidiPortDescriptor*>::const_iterator CI;
157 for(CI m = midi_ports.begin(); m != midi_ports.end(); ++m){
158 root->add_child_nocopy(m->second->get_state());
161 XMLNode* node = new XMLNode("Config");
163 #undef CONFIG_VARIABLE
164 #undef CONFIG_VARIABLE_SPECIAL
165 #define CONFIG_VARIABLE(type,var,name,value) \
166 if (!user_only || var.is_user()) var.add_to_node (*node);
167 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
168 if (!user_only || var.is_user()) var.add_to_node (*node);
169 #include "ardour/configuration_vars.h"
170 #undef CONFIG_VARIABLE
171 #undef CONFIG_VARIABLE_SPECIAL
173 root->add_child_nocopy (*node);
176 root->add_child_copy (*_extra_xml);
179 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
185 Configuration::set_state (const XMLNode& root)
187 if (root.name() != "Ardour") {
191 XMLNodeList nlist = root.children();
192 XMLNodeConstIterator niter;
195 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
199 if (node->name() == "MIDI-port") {
202 pair<string,MidiPortDescriptor*> newpair;
203 newpair.second = new MidiPortDescriptor (*node);
204 newpair.first = newpair.second->tag;
205 midi_ports.insert (newpair);
208 catch (failed_constructor& err) {
209 warning << _("ill-formed MIDI port specification in ardour rcfile (ignored)") << endmsg;
212 } else if (node->name() == "Config") {
214 #undef CONFIG_VARIABLE
215 #undef CONFIG_VARIABLE_SPECIAL
216 #define CONFIG_VARIABLE(type,var,name,value) \
217 var.set_from_node (*node); \
218 var.set_is_user (user_configuration);
219 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
220 var.set_from_node (*node); \
221 var.set_is_user (user_configuration);
222 #include "ardour/configuration_vars.h"
223 #undef CONFIG_VARIABLE
224 #undef CONFIG_VARIABLE_SPECIAL
226 } else if (node->name() == "extra") {
227 _extra_xml = new XMLNode (*node);
229 } else if (node->name() == ControlProtocolManager::state_node_name) {
230 _control_protocol_state = new XMLNode (*node);
234 AudioDiskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample));
239 Configuration::MidiPortDescriptor::MidiPortDescriptor (const XMLNode& node)
241 const XMLProperty *prop;
242 bool have_tag = false;
243 bool have_device = false;
244 bool have_type = false;
245 bool have_mode = false;
247 if ((prop = node.property ("tag")) != 0) {
252 if ((prop = node.property ("device")) != 0) {
253 device = prop->value();
257 if ((prop = node.property ("type")) != 0) {
258 type = prop->value();
262 if ((prop = node.property ("mode")) != 0) {
263 mode = prop->value();
267 if (!have_tag || !have_device || !have_type || !have_mode) {
268 throw failed_constructor();
273 Configuration::MidiPortDescriptor::get_state()
275 XMLNode* root = new XMLNode("MIDI-port");
277 root->add_property("tag", tag);
278 root->add_property("device", device);
279 root->add_property("type", type);
280 root->add_property("mode", mode);