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 "pbd/gstdio_compat.h"
25 #include <glibmm/miscutils.h>
27 #include "pbd/xml++.h"
28 #include "pbd/file_utils.h"
29 #include "pbd/replace_all.h"
31 #include "ardour/audioengine.h"
32 #include "ardour/disk_reader.h"
33 #include "ardour/disk_writer.h"
34 #include "ardour/control_protocol_manager.h"
35 #include "ardour/filesystem_paths.h"
36 #include "ardour/port.h"
37 #include "ardour/rc_configuration.h"
38 #include "ardour/session_metadata.h"
39 #include "ardour/transport_master_manager.h"
40 #include "ardour/types_convert.h"
44 using namespace ARDOUR;
48 /* this is global so that we do not have to indirect through an object pointer
53 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
56 static const char* user_config_file_name = "config";
57 static const char* system_config_file_name = "system_config";
59 RCConfiguration::RCConfiguration ()
61 /* construct variables */
62 #undef CONFIG_VARIABLE
63 #undef CONFIG_VARIABLE_SPECIAL
64 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
65 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
66 #include "ardour/rc_configuration_vars.h"
67 #undef CONFIG_VARIABLE
68 #undef CONFIG_VARIABLE_SPECIAL
69 _control_protocol_state (0)
70 , _transport_master_state (0)
74 RCConfiguration::~RCConfiguration ()
76 delete _control_protocol_state;
77 delete _transport_master_state;
81 RCConfiguration::load_state ()
86 /* load system configuration first */
88 if (find_file (ardour_config_search_path(), system_config_file_name, rcfile)) {
90 /* stupid XML Parser hates empty files */
92 if (g_stat (rcfile.c_str(), &statbuf)) {
96 if (statbuf.st_size != 0) {
97 info << string_compose (_("Loading system configuration file %1"), rcfile) << endmsg;
100 if (!tree.read (rcfile.c_str())) {
101 error << string_compose(_("%1: cannot read system configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
105 if (set_state (*tree.root(), Stateful::current_state_version)) {
106 error << string_compose(_("%1: system configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
110 error << string_compose (_("Your system %1 configuration file is empty. This probably means that there was an error installing %1"), PROGRAM_NAME) << endmsg;
114 /* now load configuration file for user */
116 if (find_file (ardour_config_search_path(), user_config_file_name, rcfile)) {
118 /* stupid XML parser hates empty files */
120 if (g_stat (rcfile.c_str(), &statbuf)) {
124 if (statbuf.st_size != 0) {
125 info << string_compose (_("Loading user configuration file %1"), rcfile) << endmsg;
128 if (!tree.read (rcfile)) {
129 error << string_compose(_("%1: cannot read configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
133 if (set_state (*tree.root(), Stateful::current_state_version)) {
134 error << string_compose(_("%1: user configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
138 warning << string_compose (_("your %1 configuration file is empty. This is not normal."), PROGRAM_NAME) << endmsg;
146 RCConfiguration::save_state()
148 const std::string rcfile = Glib::build_filename (user_config_directory(), user_config_file_name);
150 // this test seems bogus?
151 if (!rcfile.empty()) {
153 tree.set_root (&get_state());
154 if (!tree.write (rcfile.c_str())){
155 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
164 RCConfiguration::add_instant_xml(XMLNode& node)
166 Stateful::add_instant_xml (node, user_config_directory ());
170 RCConfiguration::instant_xml(const string& node_name)
172 return Stateful::instant_xml (node_name, user_config_directory ());
177 RCConfiguration::get_state ()
181 root = new XMLNode("Ardour");
183 root->add_child_nocopy (get_variables ());
185 root->add_child_nocopy (SessionMetadata::Metadata()->get_user_state());
188 root->add_child_copy (*_extra_xml);
191 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
193 if (TransportMasterManager::exists()) {
194 root->add_child_nocopy (TransportMasterManager::instance().get_state());
201 RCConfiguration::get_variables ()
205 node = new XMLNode ("Config");
207 #undef CONFIG_VARIABLE
208 #undef CONFIG_VARIABLE_SPECIAL
209 #define CONFIG_VARIABLE(type,var,Name,value) \
210 var.add_to_node (*node);
211 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
212 var.add_to_node (*node);
213 #include "ardour/rc_configuration_vars.h"
214 #undef CONFIG_VARIABLE
215 #undef CONFIG_VARIABLE_SPECIAL
221 RCConfiguration::set_state (const XMLNode& root, int version)
223 if (root.name() != "Ardour") {
227 XMLNodeList nlist = root.children();
228 XMLNodeConstIterator niter;
231 Stateful::save_extra_xml (root);
233 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
237 if (node->name() == "Config") {
238 set_variables (*node);
239 } else if (node->name() == "Metadata") {
240 SessionMetadata::Metadata()->set_state (*node, version);
241 } else if (node->name() == ControlProtocolManager::state_node_name) {
242 _control_protocol_state = new XMLNode (*node);
243 } else if (node->name() == TransportMasterManager::state_node_name) {
244 _transport_master_state = new XMLNode (*node);
248 DiskReader::set_chunk_samples (minimum_disk_read_bytes.get() / sizeof (Sample));
249 DiskWriter::set_chunk_samples (minimum_disk_write_bytes.get() / sizeof (Sample));
255 RCConfiguration::set_variables (const XMLNode& node)
257 #undef CONFIG_VARIABLE
258 #undef CONFIG_VARIABLE_SPECIAL
259 #define CONFIG_VARIABLE(type,var,name,value) \
260 if (var.set_from_node (node)) { \
261 ParameterChanged (name); \
263 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
264 if (var.set_from_node (node)) { \
265 ParameterChanged (name); \
268 #include "ardour/rc_configuration_vars.h"
269 #undef CONFIG_VARIABLE
270 #undef CONFIG_VARIABLE_SPECIAL
274 RCConfiguration::map_parameters (boost::function<void (std::string)>& functor)
276 #undef CONFIG_VARIABLE
277 #undef CONFIG_VARIABLE_SPECIAL
278 #define CONFIG_VARIABLE(type,var,name,value) functor (name);
279 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name);
280 #include "ardour/rc_configuration_vars.h"
281 #undef CONFIG_VARIABLE
282 #undef CONFIG_VARIABLE_SPECIAL