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 */
24 #include <glib/gstdio.h> /* for g_stat() */
25 #include <glibmm/miscutils.h>
27 #include <pbd/failed_constructor.h>
28 #include <pbd/xml++.h>
30 #include <midi++/manager.h>
32 #include <ardour/ardour.h>
33 #include <ardour/configuration.h>
34 #include <ardour/audio_diskstream.h>
35 #include <ardour/control_protocol_manager.h>
39 using namespace ARDOUR;
43 /* this is global so that we do not have to indirect through an object pointer
48 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
51 Configuration::Configuration ()
53 /* construct variables */
54 #undef CONFIG_VARIABLE
55 #undef CONFIG_VARIABLE_SPECIAL
56 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
57 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
58 #include "ardour/configuration_vars.h"
59 #undef CONFIG_VARIABLE
60 #undef CONFIG_VARIABLE_SPECIAL
62 current_owner (ConfigVariableBase::Default)
64 _control_protocol_state = 0;
67 Configuration::~Configuration ()
72 Configuration::set_current_owner (ConfigVariableBase::Owner owner)
74 current_owner = owner;
78 Configuration::load_state ()
83 /* load system configuration first */
85 rcfile = find_config_file ("ardour_system.rc");
87 if (rcfile.length()) {
91 /* stupid XML Parser hates empty files */
93 if (g_stat (rcfile.c_str(), &statbuf)) {
97 if (statbuf.st_size != 0) {
98 cerr << string_compose (_("loading system configuration file %1"), rcfile) << endl;
100 if (!tree.read (rcfile.c_str())) {
101 error << string_compose(_("Ardour: cannot read system configuration file \"%1\""), rcfile) << endmsg;
105 current_owner = ConfigVariableBase::System;
107 if (set_state (*tree.root())) {
108 error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
112 error << _("your system Ardour configuration file is empty. This probably means that there as an error installing Ardour") << endmsg;
117 /* now load configuration file for user */
119 rcfile = find_config_file ("ardour.rc");
121 if (rcfile.length()) {
125 /* stupid XML parser hates empty files */
127 if (g_stat (rcfile.c_str(), &statbuf)) {
131 if (statbuf.st_size != 0) {
132 cerr << string_compose (_("loading user configuration file %1"), rcfile) << endl;
134 if (!tree.read (rcfile)) {
135 error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg;
139 current_owner = ConfigVariableBase::Config;
141 if (set_state (*tree.root())) {
142 error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
146 warning << _("your Ardour configuration file is empty. This is not normal.") << endmsg;
154 Configuration::save_state()
159 rcfile = Glib::build_filename (get_user_ardour_path (), "ardour.rc");
161 if (rcfile.length()) {
162 tree.set_root (&get_state());
163 if (!tree.write (rcfile.c_str())){
164 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
173 Configuration::save_config_options_predicate (ConfigVariableBase::Owner owner)
175 /* only save things that were in the config file to start with */
176 return owner & ConfigVariableBase::Config;
180 Configuration::get_state ()
183 LocaleGuard lg (X_("POSIX"));
185 root = new XMLNode("Ardour");
187 MIDI::Manager::PortMap::const_iterator i;
188 const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
190 for(i = ports.begin(); i != ports.end(); ++i) {
191 root->add_child_nocopy(i->second->get_state());
194 root->add_child_nocopy (get_variables (sigc::mem_fun (*this, &Configuration::save_config_options_predicate)));
197 root->add_child_copy (*_extra_xml);
200 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
206 Configuration::get_variables (sigc::slot<bool,ConfigVariableBase::Owner> predicate)
209 LocaleGuard lg (X_("POSIX"));
211 node = new XMLNode("Config");
213 #undef CONFIG_VARIABLE
214 #undef CONFIG_VARIABLE_SPECIAL
215 #define CONFIG_VARIABLE(type,var,name,value) \
216 if (predicate (var.owner())) { var.add_to_node (*node); }
217 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
218 if (predicate (var.owner())) { var.add_to_node (*node); }
219 #include "ardour/configuration_vars.h"
220 #undef CONFIG_VARIABLE
221 #undef CONFIG_VARIABLE_SPECIAL
227 Configuration::set_state (const XMLNode& root)
229 if (root.name() != "Ardour") {
233 XMLNodeList nlist = root.children();
234 XMLNodeConstIterator niter;
237 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
241 if (node->name() == "MIDI-port") {
244 MIDI::Port::Descriptor desc (*node);
245 map<string,XMLNode>::iterator x;
246 if ((x = midi_ports.find (desc.tag)) != midi_ports.end()) {
247 midi_ports.erase (x);
249 midi_ports.insert (pair<string,XMLNode>(desc.tag,*node));
252 catch (failed_constructor& err) {
253 warning << _("ill-formed MIDI port specification in ardour rcfile (ignored)") << endmsg;
256 } else if (node->name() == "Config") {
258 set_variables (*node, ConfigVariableBase::Config);
260 } else if (node->name() == "extra") {
261 _extra_xml = new XMLNode (*node);
263 } else if (node->name() == ControlProtocolManager::state_node_name) {
264 _control_protocol_state = new XMLNode (*node);
268 Diskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample));
274 Configuration::set_variables (const XMLNode& node, ConfigVariableBase::Owner owner)
276 #undef CONFIG_VARIABLE
277 #undef CONFIG_VARIABLE_SPECIAL
278 #define CONFIG_VARIABLE(type,var,name,value) \
279 if (var.set_from_node (node, owner)) { \
280 ParameterChanged (name); \
282 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
283 if (var.set_from_node (node, owner)) { \
284 ParameterChanged (name); \
286 #include "ardour/configuration_vars.h"
287 #undef CONFIG_VARIABLE
288 #undef CONFIG_VARIABLE_SPECIAL
293 Configuration::map_parameters (sigc::slot<void,const char*> theSlot)
295 #undef CONFIG_VARIABLE
296 #undef CONFIG_VARIABLE_SPECIAL
297 #define CONFIG_VARIABLE(type,var,name,value) theSlot (name);
298 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) theSlot (name);
299 #include "ardour/configuration_vars.h"
300 #undef CONFIG_VARIABLE
301 #undef CONFIG_VARIABLE_SPECIAL
304 bool ConfigVariableBase::show_stores = false;
307 ConfigVariableBase::set_show_stored_values (bool yn)
313 ConfigVariableBase::show_stored_value (const string& str)
316 cerr << "Config variable " << _name << " stored as " << str << endl;
321 ConfigVariableBase::notify ()
323 // placeholder for any debugging desired when a config variable is modified
327 ConfigVariableBase::miss ()
329 // placeholder for any debugging desired when a config variable
330 // is set but to the same value as it already has