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>
25 #include <pbd/filesystem.h>
26 #include <pbd/file_utils.h>
28 #include <midi++/manager.h>
30 #include <ardour/ardour.h>
31 #include <ardour/configuration.h>
32 #include <ardour/audio_diskstream.h>
33 #include <ardour/control_protocol_manager.h>
34 #include <ardour/filesystem_paths.h>
38 using namespace ARDOUR;
42 /* this is global so that we do not have to indirect through an object pointer
47 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
50 Configuration::Configuration ()
52 /* construct variables */
53 #undef CONFIG_VARIABLE
54 #undef CONFIG_VARIABLE_SPECIAL
55 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
56 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
57 #include "ardour/configuration_vars.h"
58 #undef CONFIG_VARIABLE
59 #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 ()
82 sys::path system_rc_file;
84 /* load system configuration first */
86 if ( find_file_in_search_path (ardour_search_path() + system_config_search_path(),
87 "ardour_system.rc", system_rc_file) )
92 string rcfile = system_rc_file.to_string();
94 cerr << string_compose (_("loading system configuration file %1"), rcfile) << endl;
96 if (!tree.read (rcfile.c_str())) {
97 error << string_compose(_("Ardour: cannot read system configuration file \"%1\""), rcfile) << endmsg;
101 current_owner = ConfigVariableBase::System;
103 if (set_state (*tree.root())) {
104 error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
109 /* now load configuration file for user */
111 sys::path user_rc_file;
113 if (find_file_in_search_path (ardour_search_path() + user_config_directory(),
114 "ardour.rc", user_rc_file))
119 string rcfile = user_rc_file.to_string();
121 cerr << string_compose (_("loading user configuration file %1"), rcfile) << endl;
123 if (!tree.read (rcfile)) {
124 error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg;
128 current_owner = ConfigVariableBase::Config;
130 if (set_state (*tree.root())) {
131 error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
137 error << "Ardour: could not find configuration file (ardour.rc), canvas will look broken." << endmsg;
143 Configuration::save_state()
149 sys::create_directories (user_config_directory ());
151 catch (const sys::filesystem_error& ex)
153 error << "Could not create user configuration directory" << endmsg;
157 sys::path rcfile_path(user_config_directory());
159 rcfile_path /= "ardour.rc";
160 const string rcfile = rcfile_path.to_string();
162 // this test seems bogus?
163 if (rcfile.length()) {
164 tree.set_root (&get_state());
165 if (!tree.write (rcfile.c_str())){
166 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
175 Configuration::add_instant_xml(XMLNode& node)
177 Stateful::add_instant_xml (node, user_config_directory ());
181 Configuration::instant_xml(const string& node_name)
183 return Stateful::instant_xml (node_name, user_config_directory ());
188 Configuration::save_config_options_predicate (ConfigVariableBase::Owner owner)
190 /* only save things that were in the config file to start with */
191 return owner & ConfigVariableBase::Config;
195 Configuration::get_state ()
198 LocaleGuard lg (X_("POSIX"));
200 root = new XMLNode("Ardour");
202 MIDI::Manager::PortMap::const_iterator i;
203 const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
205 for (i = ports.begin(); i != ports.end(); ++i) {
206 root->add_child_nocopy(i->second->get_state());
209 root->add_child_nocopy (get_variables (sigc::mem_fun (*this, &Configuration::save_config_options_predicate), "Config"));
212 root->add_child_copy (*_extra_xml);
215 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
221 Configuration::get_variables (sigc::slot<bool,ConfigVariableBase::Owner> predicate, std::string which_node)
224 LocaleGuard lg (X_("POSIX"));
226 node = new XMLNode(which_node);
228 #undef CONFIG_VARIABLE
229 #undef CONFIG_VARIABLE_SPECIAL
230 #define CONFIG_VARIABLE(type,var,Name,value) \
231 if (node->name() == "Config") { if (predicate (var.owner())) { var.add_to_node (*node); }}
232 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
233 if (node->name() == "Config") { if (predicate (var.owner())) { var.add_to_node (*node); }}
234 #include "ardour/configuration_vars.h"
235 #undef CONFIG_VARIABLE
236 #undef CONFIG_VARIABLE_SPECIAL
242 Configuration::set_state (const XMLNode& root)
244 if (root.name() != "Ardour") {
248 XMLNodeList nlist = root.children();
249 XMLNodeConstIterator niter;
252 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
256 if (node->name() == "MIDI-port") {
260 MIDI::Port::Descriptor desc (*node);
261 map<string,XMLNode>::iterator x;
262 if ((x = midi_ports.find (desc.tag)) != midi_ports.end()) {
263 midi_ports.erase (x);
265 midi_ports.insert (pair<string,XMLNode>(desc.tag,*node));
268 catch (failed_constructor& err) {
269 warning << _("ill-formed MIDI port specification in ardour rcfile (ignored)") << endmsg;
272 } else if (node->name() == "Config") {
274 set_variables (*node, ConfigVariableBase::Config);
276 } else if (node->name() == "extra") {
277 _extra_xml = new XMLNode (*node);
279 } else if (node->name() == ControlProtocolManager::state_node_name) {
280 _control_protocol_state = new XMLNode (*node);
284 Diskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample));
290 Configuration::set_variables (const XMLNode& node, ConfigVariableBase::Owner owner)
292 #undef CONFIG_VARIABLE
293 #undef CONFIG_VARIABLE_SPECIAL
294 #define CONFIG_VARIABLE(type,var,name,value) \
295 if (var.set_from_node (node, owner)) { \
296 ParameterChanged (name); \
298 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
299 if (var.set_from_node (node, owner)) { \
300 ParameterChanged (name); \
303 #include "ardour/configuration_vars.h"
304 #undef CONFIG_VARIABLE
305 #undef CONFIG_VARIABLE_SPECIAL
309 Configuration::map_parameters (sigc::slot<void,const char*> theSlot)
311 #undef CONFIG_VARIABLE
312 #undef CONFIG_VARIABLE_SPECIAL
313 #define CONFIG_VARIABLE(type,var,name,value) theSlot (name);
314 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) theSlot (name);
315 #include "ardour/configuration_vars.h"
316 #undef CONFIG_VARIABLE
317 #undef CONFIG_VARIABLE_SPECIAL
320 bool ConfigVariableBase::show_stores = false;
323 ConfigVariableBase::set_show_stored_values (bool yn)
329 ConfigVariableBase::show_stored_value (const string& str)
332 cerr << "Config variable " << _name << " stored as " << str << endl;
337 ConfigVariableBase::notify ()
339 // placeholder for any debugging desired when a config variable is modified
343 ConfigVariableBase::miss ()
345 // placeholder for any debugging desired when a config variable
346 // is set but to the same value as it already has