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/failed_constructor.h"
28 #include "pbd/xml++.h"
29 #include "pbd/filesystem.h"
30 #include "pbd/file_utils.h"
32 #include "midi++/manager.h"
34 #include "ardour/ardour.h"
35 #include "ardour/rc_configuration.h"
36 #include "ardour/audio_diskstream.h"
37 #include "ardour/control_protocol_manager.h"
38 #include "ardour/filesystem_paths.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 RCConfiguration::RCConfiguration ()
56 /* construct variables */
57 #undef CONFIG_VARIABLE
58 #undef CONFIG_VARIABLE_SPECIAL
59 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
60 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
61 #include "ardour/rc_configuration_vars.h"
62 #undef CONFIG_VARIABLE
63 #undef CONFIG_VARIABLE_SPECIAL
64 _control_protocol_state (0)
69 RCConfiguration::load_state ()
73 sys::path system_rc_file;
76 /* load system configuration first */
78 if (find_file_in_search_path (ardour_search_path() + system_config_search_path(),
79 "ardour_system.rc", system_rc_file) )
84 string rcfile = system_rc_file.to_string();
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) << endl;
95 if (!tree.read (rcfile.c_str())) {
96 error << string_compose(_("Ardour: cannot read system configuration file \"%1\""), rcfile) << endmsg;
100 if (set_state (*tree.root(), Stateful::current_state_version)) {
101 error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
105 error << _("your system Ardour configuration file is empty. This probably means that there as an error installing Ardour") << 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 /* stupid XML parser hates empty files */
123 if (g_stat (rcfile.c_str(), &statbuf)) {
127 if (statbuf.st_size != 0) {
128 info << string_compose (_("Loading user configuration file %1"), rcfile) << endl;
130 if (!tree.read (rcfile)) {
131 error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg;
135 if (set_state (*tree.root(), Stateful::current_state_version)) {
136 error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
140 warning << _("your Ardour configuration file is empty. This is not normal.") << endmsg;
145 error << "Ardour: could not find configuration file (ardour.rc), canvas will look broken." << endmsg;
151 RCConfiguration::save_state()
157 sys::create_directories (user_config_directory ());
159 catch (const sys::filesystem_error& ex)
161 error << "Could not create user configuration directory" << endmsg;
165 sys::path rcfile_path(user_config_directory());
167 rcfile_path /= "ardour.rc";
168 const string rcfile = rcfile_path.to_string();
170 // this test seems bogus?
171 if (rcfile.length()) {
172 tree.set_root (&get_state());
173 if (!tree.write (rcfile.c_str())){
174 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
183 RCConfiguration::add_instant_xml(XMLNode& node)
185 Stateful::add_instant_xml (node, user_config_directory ());
189 RCConfiguration::instant_xml(const string& node_name)
191 return Stateful::instant_xml (node_name, user_config_directory ());
196 RCConfiguration::get_state ()
199 LocaleGuard lg (X_("POSIX"));
201 root = new XMLNode("Ardour");
203 const MIDI::Manager::PortList& ports = MIDI::Manager::instance()->get_midi_ports();
205 for (MIDI::Manager::PortList::const_iterator i = ports.begin(); i != ports.end(); ++i) {
206 root->add_child_nocopy((*i)->get_state());
209 root->add_child_nocopy (get_variables ());
212 root->add_child_copy (*_extra_xml);
215 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
221 RCConfiguration::get_variables ()
224 LocaleGuard lg (X_("POSIX"));
226 node = new XMLNode ("Config");
228 #undef CONFIG_VARIABLE
229 #undef CONFIG_VARIABLE_SPECIAL
230 #define CONFIG_VARIABLE(type,var,Name,value) \
231 var.add_to_node (*node);
232 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
233 var.add_to_node (*node);
234 #include "ardour/rc_configuration_vars.h"
235 #undef CONFIG_VARIABLE
236 #undef CONFIG_VARIABLE_SPECIAL
242 RCConfiguration::set_state (const XMLNode& root, int /*version*/)
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;
263 if ((x = midi_ports.find (desc.tag)) != midi_ports.end()) {
264 warning << string_compose (_("Duplicate MIDI port definition found (tag=\"%1\") - ignored"),
268 midi_ports.insert (pair<string,XMLNode>(desc.tag,*node));
271 catch (failed_constructor& err) {
272 warning << _("ill-formed MIDI port specification in ardour rcfile (ignored)") << endmsg;
275 } else if (node->name() == "Config") {
277 set_variables (*node);
279 } else if (node->name() == "Extra") {
280 _extra_xml = new XMLNode (*node);
282 } else if (node->name() == ControlProtocolManager::state_node_name) {
283 _control_protocol_state = new XMLNode (*node);
287 Diskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample));
293 RCConfiguration::set_variables (const XMLNode& node)
295 #undef CONFIG_VARIABLE
296 #undef CONFIG_VARIABLE_SPECIAL
297 #define CONFIG_VARIABLE(type,var,name,value) \
298 if (var.set_from_node (node)) { \
299 ParameterChanged (name); \
301 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
302 if (var.set_from_node (node)) { \
303 ParameterChanged (name); \
306 #include "ardour/rc_configuration_vars.h"
307 #undef CONFIG_VARIABLE
308 #undef CONFIG_VARIABLE_SPECIAL
312 RCConfiguration::map_parameters (sigc::slot<void, std::string> theSlot)
314 #undef CONFIG_VARIABLE
315 #undef CONFIG_VARIABLE_SPECIAL
316 #define CONFIG_VARIABLE(type,var,name,value) theSlot (name);
317 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) theSlot (name);
318 #include "ardour/rc_configuration_vars.h"
319 #undef CONFIG_VARIABLE
320 #undef CONFIG_VARIABLE_SPECIAL