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>
27 #include <ardour/ardour.h>
28 #include <ardour/configuration.h>
29 #include <ardour/audio_diskstream.h>
30 #include <ardour/control_protocol_manager.h>
31 #include <ardour/filesystem_paths.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 #undef CANVAS_VARIABLE
59 #define CANVAS_VARIABLE(var,name) var (name), // <-- is this really so bad?
60 #include "ardour/canvas_vars.h"
61 #undef CANVAS_VARIABLE
63 current_owner (ConfigVariableBase::Default)
65 _control_protocol_state = 0;
68 Configuration::~Configuration ()
73 Configuration::set_current_owner (ConfigVariableBase::Owner owner)
75 current_owner = owner;
79 Configuration::load_state ()
85 /* load system configuration first */
87 rcfile = find_config_file ("ardour_system.rc");
89 if (rcfile.length()) {
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;
110 /* now load configuration file for user */
112 rcfile = find_config_file ("ardour.rc");
114 if (rcfile.length()) {
119 cerr << string_compose (_("loading user configuration file %1"), rcfile) << endl;
121 if (!tree.read (rcfile)) {
122 error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg;
126 current_owner = ConfigVariableBase::Config;
128 if (set_state (*tree.root())) {
129 error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
135 error << "Ardour: could not find configuration file (ardour.rc), canvas will look broken." << endmsg;
142 Configuration::save_state()
147 rcfile = get_user_ardour_path ();
148 rcfile += "ardour.rc";
150 if (rcfile.length()) {
151 tree.set_root (&get_state());
152 if (!tree.write (rcfile.c_str())){
153 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
162 Configuration::add_instant_xml(XMLNode& node)
164 Stateful::add_instant_xml (node, user_config_directory ());
168 Configuration::instant_xml(const string& node_name)
170 return Stateful::instant_xml (node_name, user_config_directory ());
175 Configuration::save_config_options_predicate (ConfigVariableBase::Owner owner)
177 /* only save things that were in the config file to start with */
178 return owner & ConfigVariableBase::Config;
182 Configuration::get_state ()
185 LocaleGuard lg (X_("POSIX"));
187 root = new XMLNode("Ardour");
188 typedef map<string, MidiPortDescriptor*>::const_iterator CI;
189 for(CI m = midi_ports.begin(); m != midi_ports.end(); ++m){
190 root->add_child_nocopy(m->second->get_state());
193 root->add_child_nocopy (get_variables (sigc::mem_fun (*this, &Configuration::save_config_options_predicate), "Config"));
194 root->add_child_nocopy (get_variables (sigc::mem_fun (*this, &Configuration::save_config_options_predicate), "Canvas"));
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, std::string which_node)
209 LocaleGuard lg (X_("POSIX"));
211 node = new XMLNode(which_node);
213 #undef CONFIG_VARIABLE
214 #undef CONFIG_VARIABLE_SPECIAL
215 #define CONFIG_VARIABLE(type,var,Name,value) \
216 if (node->name() == "Config") { if (predicate (var.owner())) { var.add_to_node (*node); }}
217 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
218 if (node->name() == "Config") { if (predicate (var.owner())) { var.add_to_node (*node); }}
219 #include "ardour/configuration_vars.h"
220 #undef CONFIG_VARIABLE
221 #undef CONFIG_VARIABLE_SPECIAL
223 #undef CANVAS_VARIABLE
224 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { if (predicate (ConfigVariableBase::Config)) { var.add_to_node (*node); }}
225 #include "ardour/canvas_vars.h"
226 #undef CANVAS_VARIABLE
232 Configuration::set_state (const XMLNode& root)
234 if (root.name() != "Ardour") {
238 XMLNodeList nlist = root.children();
239 XMLNodeConstIterator niter;
242 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
246 if (node->name() == "MIDI-port") {
249 pair<string,MidiPortDescriptor*> newpair;
250 newpair.second = new MidiPortDescriptor (*node);
251 newpair.first = newpair.second->tag;
252 midi_ports.insert (newpair);
255 catch (failed_constructor& err) {
256 warning << _("ill-formed MIDI port specification in ardour rcfile (ignored)") << endmsg;
259 } else if (node->name() == "Config" || node->name() == "Canvas" ) {
261 set_variables (*node, ConfigVariableBase::Config);
263 } else if (node->name() == "extra") {
264 _extra_xml = new XMLNode (*node);
266 } else if (node->name() == ControlProtocolManager::state_node_name) {
267 _control_protocol_state = new XMLNode (*node);
271 Diskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample));
277 Configuration::set_variables (const XMLNode& node, ConfigVariableBase::Owner owner)
279 #undef CONFIG_VARIABLE
280 #undef CONFIG_VARIABLE_SPECIAL
281 #define CONFIG_VARIABLE(type,var,name,value) \
282 if (var.set_from_node (node, owner)) { \
283 ParameterChanged (name); \
285 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
286 if (var.set_from_node (node, owner)) { \
287 ParameterChanged (name); \
290 #include "ardour/configuration_vars.h"
291 #undef CONFIG_VARIABLE
292 #undef CONFIG_VARIABLE_SPECIAL
294 #undef CANVAS_VARIABLE
295 #define CANVAS_VARIABLE(var,name) \
296 if (var.set_from_node (node, owner)) { \
297 ParameterChanged (name); \
299 #include "ardour/canvas_vars.h"
300 #undef CANVAS_VARIABLE
305 Configuration::pack_canvasvars ()
307 #undef CANVAS_VARIABLE
308 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
309 #include "ardour/canvas_vars.h"
310 #undef CANVAS_VARIABLE
311 cerr << "Configuration::pack_canvasvars () called, canvas_colors.size() = " << canvas_colors.size() << endl;
315 Configuration::MidiPortDescriptor::MidiPortDescriptor (const XMLNode& node)
317 const XMLProperty *prop;
318 bool have_tag = false;
319 bool have_device = false;
320 bool have_type = false;
321 bool have_mode = false;
323 if ((prop = node.property ("tag")) != 0) {
328 if ((prop = node.property ("device")) != 0) {
329 device = prop->value();
333 if ((prop = node.property ("type")) != 0) {
334 type = prop->value();
338 if ((prop = node.property ("mode")) != 0) {
339 mode = prop->value();
343 if (!have_tag || !have_device || !have_type || !have_mode) {
344 throw failed_constructor();
349 Configuration::MidiPortDescriptor::get_state()
351 XMLNode* root = new XMLNode("MIDI-port");
353 root->add_property("tag", tag);
354 root->add_property("device", device);
355 root->add_property("type", type);
356 root->add_property("mode", mode);
362 Configuration::map_parameters (sigc::slot<void,const char*> theSlot)
364 #undef CONFIG_VARIABLE
365 #undef CONFIG_VARIABLE_SPECIAL
366 #define CONFIG_VARIABLE(type,var,name,value) theSlot (name);
367 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) theSlot (name);
368 #include "ardour/configuration_vars.h"
369 #undef CONFIG_VARIABLE
370 #undef CONFIG_VARIABLE_SPECIAL
373 bool ConfigVariableBase::show_stores = false;
376 ConfigVariableBase::set_show_stored_values (bool yn)
382 ConfigVariableBase::show_stored_value (const string& str)
385 cerr << "Config variable " << _name << " stored as " << str << endl;
390 ConfigVariableBase::notify ()
392 // placeholder for any debugging desired when a config variable is modified
396 ConfigVariableBase::miss ()
398 // placeholder for any debugging desired when a config variable
399 // is set but to the same value as it already has