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/xml++.h"
28 #include "pbd/file_utils.h"
30 #include "ardour/audioengine.h"
31 #include "ardour/control_protocol_manager.h"
32 #include "ardour/diskstream.h"
33 #include "ardour/filesystem_paths.h"
34 #include "ardour/port.h"
35 #include "ardour/rc_configuration.h"
36 #include "ardour/session_metadata.h"
40 using namespace ARDOUR;
44 /* this is global so that we do not have to indirect through an object pointer
49 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
52 RCConfiguration::RCConfiguration ()
54 /* construct variables */
55 #undef CONFIG_VARIABLE
56 #undef CONFIG_VARIABLE_SPECIAL
57 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
58 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
59 #include "ardour/rc_configuration_vars.h"
60 #undef CONFIG_VARIABLE
61 #undef CONFIG_VARIABLE_SPECIAL
62 _control_protocol_state (0)
66 RCConfiguration::~RCConfiguration ()
68 for (list<XMLNode*>::iterator i = _old_midi_port_states.begin(); i != _old_midi_port_states.end(); ++i) {
72 for (list<XMLNode*>::iterator i = _midi_port_states.begin(); i != _midi_port_states.end(); ++i) {
76 delete _control_protocol_state;
80 RCConfiguration::load_state ()
85 /* load system configuration first */
87 if (find_file_in_search_path (ardour_config_search_path(), "ardour_system.rc", rcfile)) {
89 /* stupid XML Parser hates empty files */
91 if (g_stat (rcfile.c_str(), &statbuf)) {
95 if (statbuf.st_size != 0) {
96 info << string_compose (_("Loading system configuration file %1"), rcfile) << endl;
99 if (!tree.read (rcfile.c_str())) {
100 error << string_compose(_("%1: cannot read system configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
104 if (set_state (*tree.root(), Stateful::current_state_version)) {
105 error << string_compose(_("%1: system configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
109 error << string_compose (_("Your system %1 configuration file is empty. This probably means that there was an error installing %1"), PROGRAM_NAME) << endmsg;
113 /* now load configuration file for user */
115 if (find_file_in_search_path (ardour_config_search_path(), "ardour.rc", rcfile)) {
117 /* stupid XML parser hates empty files */
119 if (g_stat (rcfile.c_str(), &statbuf)) {
123 if (statbuf.st_size != 0) {
124 info << string_compose (_("Loading user configuration file %1"), rcfile) << endl;
127 if (!tree.read (rcfile)) {
128 error << string_compose(_("%1: cannot read configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
132 if (set_state (*tree.root(), Stateful::current_state_version)) {
133 error << string_compose(_("%1: user configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
137 warning << string_compose (_("your %1 configuration file is empty. This is not normal."), PROGRAM_NAME) << endmsg;
145 RCConfiguration::save_state()
147 const std::string rcfile = Glib::build_filename (user_config_directory(), "ardour.rc");
149 // this test seems bogus?
150 if (!rcfile.empty()) {
152 tree.set_root (&get_state());
153 if (!tree.write (rcfile.c_str())){
154 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
163 RCConfiguration::add_instant_xml(XMLNode& node)
165 Stateful::add_instant_xml (node, user_config_directory ());
169 RCConfiguration::instant_xml(const string& node_name)
171 return Stateful::instant_xml (node_name, user_config_directory ());
176 RCConfiguration::get_state ()
179 LocaleGuard lg (X_("POSIX"));
181 root = new XMLNode("Ardour");
183 list<XMLNode*> midi_port_nodes = AudioEngine::instance()->get_midi_port_states();
184 for (list<XMLNode*>::const_iterator n = midi_port_nodes.begin(); n != midi_port_nodes.end(); ++n) {
185 root->add_child_nocopy (**n);
188 root->add_child_nocopy (get_variables ());
190 root->add_child_nocopy (SessionMetadata::Metadata()->get_user_state());
193 root->add_child_copy (*_extra_xml);
196 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
202 RCConfiguration::get_variables ()
205 LocaleGuard lg (X_("POSIX"));
207 node = new XMLNode ("Config");
209 #undef CONFIG_VARIABLE
210 #undef CONFIG_VARIABLE_SPECIAL
211 #define CONFIG_VARIABLE(type,var,Name,value) \
212 var.add_to_node (*node);
213 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
214 var.add_to_node (*node);
215 #include "ardour/rc_configuration_vars.h"
216 #undef CONFIG_VARIABLE
217 #undef CONFIG_VARIABLE_SPECIAL
223 RCConfiguration::set_state (const XMLNode& root, int version)
225 if (root.name() != "Ardour") {
229 XMLNodeList nlist = root.children();
230 XMLNodeConstIterator niter;
233 for (list<XMLNode*>::iterator i = _midi_port_states.begin(); i != _midi_port_states.end(); ++i) {
237 _midi_port_states.clear ();
239 Stateful::save_extra_xml (root);
241 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
245 if (node->name() == "Config") {
246 set_variables (*node);
247 } else if (node->name() == "Metadata") {
248 SessionMetadata::Metadata()->set_state (*node, version);
249 } else if (node->name() == ControlProtocolManager::state_node_name) {
250 _control_protocol_state = new XMLNode (*node);
251 } else if (node->name() == MIDI::Port::state_node_name) {
252 _old_midi_port_states.push_back (new XMLNode (*node));
253 } else if (node->name() == ARDOUR::Port::state_node_name) {
254 _midi_port_states.push_back (new XMLNode (*node));
258 Diskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample));
264 RCConfiguration::set_variables (const XMLNode& node)
266 #undef CONFIG_VARIABLE
267 #undef CONFIG_VARIABLE_SPECIAL
268 #define CONFIG_VARIABLE(type,var,name,value) \
269 if (var.set_from_node (node)) { \
270 ParameterChanged (name); \
272 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
273 if (var.set_from_node (node)) { \
274 ParameterChanged (name); \
277 #include "ardour/rc_configuration_vars.h"
278 #undef CONFIG_VARIABLE
279 #undef CONFIG_VARIABLE_SPECIAL
283 RCConfiguration::map_parameters (boost::function<void (std::string)>& functor)
285 #undef CONFIG_VARIABLE
286 #undef CONFIG_VARIABLE_SPECIAL
287 #define CONFIG_VARIABLE(type,var,name,value) functor (name);
288 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name);
289 #include "ardour/rc_configuration_vars.h"
290 #undef CONFIG_VARIABLE
291 #undef CONFIG_VARIABLE_SPECIAL