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/control_protocol_manager.h"
33 #include "ardour/diskstream.h"
34 #include "ardour/filesystem_paths.h"
35 #include "ardour/port.h"
36 #include "ardour/rc_configuration.h"
37 #include "ardour/session_metadata.h"
38 #include "ardour/types_convert.h"
42 using namespace ARDOUR;
46 /* this is global so that we do not have to indirect through an object pointer
51 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
54 static const char* user_config_file_name = "config";
55 static const char* system_config_file_name = "system_config";
57 RCConfiguration::RCConfiguration ()
59 /* construct variables */
60 #undef CONFIG_VARIABLE
61 #undef CONFIG_VARIABLE_SPECIAL
62 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
63 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
64 #include "ardour/rc_configuration_vars.h"
65 #undef CONFIG_VARIABLE
66 #undef CONFIG_VARIABLE_SPECIAL
67 _control_protocol_state (0)
71 RCConfiguration::~RCConfiguration ()
73 delete _control_protocol_state;
77 RCConfiguration::load_state ()
82 /* load system configuration first */
84 if (find_file (ardour_config_search_path(), system_config_file_name, rcfile)) {
86 /* stupid XML Parser hates empty files */
88 if (g_stat (rcfile.c_str(), &statbuf)) {
92 if (statbuf.st_size != 0) {
93 info << string_compose (_("Loading system configuration file %1"), rcfile) << endmsg;
96 if (!tree.read (rcfile.c_str())) {
97 error << string_compose(_("%1: cannot read system configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
101 if (set_state (*tree.root(), Stateful::current_state_version)) {
102 error << string_compose(_("%1: system configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
106 error << string_compose (_("Your system %1 configuration file is empty. This probably means that there was an error installing %1"), PROGRAM_NAME) << endmsg;
110 /* now load configuration file for user */
112 if (find_file (ardour_config_search_path(), user_config_file_name, rcfile)) {
114 /* stupid XML parser hates empty files */
116 if (g_stat (rcfile.c_str(), &statbuf)) {
120 if (statbuf.st_size != 0) {
121 info << string_compose (_("Loading user configuration file %1"), rcfile) << endmsg;
124 if (!tree.read (rcfile)) {
125 error << string_compose(_("%1: cannot read configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
129 if (set_state (*tree.root(), Stateful::current_state_version)) {
130 error << string_compose(_("%1: user configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
134 warning << string_compose (_("your %1 configuration file is empty. This is not normal."), PROGRAM_NAME) << endmsg;
142 RCConfiguration::save_state()
144 const std::string rcfile = Glib::build_filename (user_config_directory(), user_config_file_name);
146 // this test seems bogus?
147 if (!rcfile.empty()) {
149 tree.set_root (&get_state());
150 if (!tree.write (rcfile.c_str())){
151 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
160 RCConfiguration::add_instant_xml(XMLNode& node)
162 Stateful::add_instant_xml (node, user_config_directory ());
166 RCConfiguration::instant_xml(const string& node_name)
168 return Stateful::instant_xml (node_name, user_config_directory ());
173 RCConfiguration::get_state ()
177 root = new XMLNode("Ardour");
179 root->add_child_nocopy (get_variables ());
181 root->add_child_nocopy (SessionMetadata::Metadata()->get_user_state());
184 root->add_child_copy (*_extra_xml);
187 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
193 RCConfiguration::get_variables ()
197 node = new XMLNode ("Config");
199 #undef CONFIG_VARIABLE
200 #undef CONFIG_VARIABLE_SPECIAL
201 #define CONFIG_VARIABLE(type,var,Name,value) \
202 var.add_to_node (*node);
203 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
204 var.add_to_node (*node);
205 #include "ardour/rc_configuration_vars.h"
206 #undef CONFIG_VARIABLE
207 #undef CONFIG_VARIABLE_SPECIAL
213 RCConfiguration::set_state (const XMLNode& root, int version)
215 if (root.name() != "Ardour") {
219 XMLNodeList nlist = root.children();
220 XMLNodeConstIterator niter;
223 Stateful::save_extra_xml (root);
225 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
229 if (node->name() == "Config") {
230 set_variables (*node);
231 } else if (node->name() == "Metadata") {
232 SessionMetadata::Metadata()->set_state (*node, version);
233 } else if (node->name() == ControlProtocolManager::state_node_name) {
234 _control_protocol_state = new XMLNode (*node);
238 Diskstream::set_disk_read_chunk_frames (minimum_disk_read_bytes.get() / sizeof (Sample));
239 Diskstream::set_disk_write_chunk_frames (minimum_disk_write_bytes.get() / sizeof (Sample));
245 RCConfiguration::set_variables (const XMLNode& node)
247 #undef CONFIG_VARIABLE
248 #undef CONFIG_VARIABLE_SPECIAL
249 #define CONFIG_VARIABLE(type,var,name,value) \
250 if (var.set_from_node (node)) { \
251 ParameterChanged (name); \
253 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
254 if (var.set_from_node (node)) { \
255 ParameterChanged (name); \
258 #include "ardour/rc_configuration_vars.h"
259 #undef CONFIG_VARIABLE
260 #undef CONFIG_VARIABLE_SPECIAL
264 RCConfiguration::map_parameters (boost::function<void (std::string)>& functor)
266 #undef CONFIG_VARIABLE
267 #undef CONFIG_VARIABLE_SPECIAL
268 #define CONFIG_VARIABLE(type,var,name,value) functor (name);
269 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name);
270 #include "ardour/rc_configuration_vars.h"
271 #undef CONFIG_VARIABLE
272 #undef CONFIG_VARIABLE_SPECIAL