2 * Copyright (C) 1999-2018 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
5 * Copyright (C) 2012-2016 Tim Mayberry <mojofunk@gmail.com>
6 * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <cstdio> /* for snprintf, grrr */
27 #include "pbd/gstdio_compat.h"
28 #include <glibmm/miscutils.h>
30 #include "pbd/xml++.h"
31 #include "pbd/file_utils.h"
32 #include "pbd/replace_all.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/disk_reader.h"
36 #include "ardour/disk_writer.h"
37 #include "ardour/control_protocol_manager.h"
38 #include "ardour/filesystem_paths.h"
39 #include "ardour/port.h"
40 #include "ardour/rc_configuration.h"
41 #include "ardour/session_metadata.h"
42 #include "ardour/transport_master_manager.h"
43 #include "ardour/types_convert.h"
47 using namespace ARDOUR;
51 /* this is global so that we do not have to indirect through an object pointer
56 float speed_quietning = 0.251189; // -12dB reduction for ffwd or rewind
59 static const char* user_config_file_name = "config";
60 static const char* system_config_file_name = "system_config";
62 RCConfiguration::RCConfiguration ()
64 /* construct variables */
65 #undef CONFIG_VARIABLE
66 #undef CONFIG_VARIABLE_SPECIAL
67 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
68 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
69 #include "ardour/rc_configuration_vars.h"
70 #undef CONFIG_VARIABLE
71 #undef CONFIG_VARIABLE_SPECIAL
72 _control_protocol_state (0)
73 , _transport_master_state (0)
77 RCConfiguration::~RCConfiguration ()
79 delete _control_protocol_state;
80 delete _transport_master_state;
84 RCConfiguration::load_state ()
89 /* load system configuration first */
91 if (find_file (ardour_config_search_path(), system_config_file_name, rcfile)) {
93 /* stupid XML Parser hates empty files */
95 if (g_stat (rcfile.c_str(), &statbuf)) {
99 if (statbuf.st_size != 0) {
100 info << string_compose (_("Loading system configuration file %1"), rcfile) << endmsg;
103 if (!tree.read (rcfile.c_str())) {
104 error << string_compose(_("%1: cannot read system configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
108 if (set_state (*tree.root(), Stateful::current_state_version)) {
109 error << string_compose(_("%1: system configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
113 error << string_compose (_("Your system %1 configuration file is empty. This probably means that there was an error installing %1"), PROGRAM_NAME) << endmsg;
117 /* now load configuration file for user */
119 if (find_file (ardour_config_search_path(), user_config_file_name, rcfile)) {
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) << endmsg;
131 if (!tree.read (rcfile)) {
132 error << string_compose(_("%1: cannot read configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
136 if (set_state (*tree.root(), Stateful::current_state_version)) {
137 error << string_compose(_("%1: user configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
141 warning << string_compose (_("your %1 configuration file is empty. This is not normal."), PROGRAM_NAME) << endmsg;
149 RCConfiguration::save_state()
151 const std::string rcfile = Glib::build_filename (user_config_directory(), user_config_file_name);
153 // this test seems bogus?
154 if (!rcfile.empty()) {
156 tree.set_root (&get_state());
157 if (!tree.write (rcfile.c_str())){
158 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
167 RCConfiguration::add_instant_xml(XMLNode& node)
169 Stateful::add_instant_xml (node, user_config_directory ());
173 RCConfiguration::instant_xml(const string& node_name)
175 return Stateful::instant_xml (node_name, user_config_directory ());
180 RCConfiguration::get_state ()
184 root = new XMLNode("Ardour");
186 root->add_child_nocopy (get_variables ());
188 root->add_child_nocopy (SessionMetadata::Metadata()->get_user_state());
191 root->add_child_copy (*_extra_xml);
194 root->add_child_nocopy (ControlProtocolManager::instance().get_state());
196 if (TransportMasterManager::exists()) {
197 root->add_child_nocopy (TransportMasterManager::instance().get_state());
204 RCConfiguration::get_variables ()
208 node = new XMLNode ("Config");
210 #undef CONFIG_VARIABLE
211 #undef CONFIG_VARIABLE_SPECIAL
212 #define CONFIG_VARIABLE(type,var,Name,value) \
213 var.add_to_node (*node);
214 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
215 var.add_to_node (*node);
216 #include "ardour/rc_configuration_vars.h"
217 #undef CONFIG_VARIABLE
218 #undef CONFIG_VARIABLE_SPECIAL
224 RCConfiguration::set_state (const XMLNode& root, int version)
226 if (root.name() != "Ardour") {
230 XMLNodeList nlist = root.children();
231 XMLNodeConstIterator niter;
234 Stateful::save_extra_xml (root);
236 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
240 if (node->name() == "Config") {
241 set_variables (*node);
242 } else if (node->name() == "Metadata") {
243 SessionMetadata::Metadata()->set_state (*node, version);
244 } else if (node->name() == ControlProtocolManager::state_node_name) {
245 _control_protocol_state = new XMLNode (*node);
246 } else if (node->name() == TransportMasterManager::state_node_name) {
247 _transport_master_state = new XMLNode (*node);
251 DiskReader::set_chunk_samples (minimum_disk_read_bytes.get() / sizeof (Sample));
252 DiskWriter::set_chunk_samples (minimum_disk_write_bytes.get() / sizeof (Sample));
258 RCConfiguration::set_variables (const XMLNode& node)
260 #undef CONFIG_VARIABLE
261 #undef CONFIG_VARIABLE_SPECIAL
262 #define CONFIG_VARIABLE(type,var,name,value) \
263 if (var.set_from_node (node)) { \
264 ParameterChanged (name); \
267 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
268 if (var.set_from_node (node)) { \
269 ParameterChanged (name); \
272 #include "ardour/rc_configuration_vars.h"
273 #undef CONFIG_VARIABLE
274 #undef CONFIG_VARIABLE_SPECIAL
278 RCConfiguration::map_parameters (boost::function<void (std::string)>& functor)
280 #undef CONFIG_VARIABLE
281 #undef CONFIG_VARIABLE_SPECIAL
282 #define CONFIG_VARIABLE(type,var,name,value) functor (name);
283 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name);
284 #include "ardour/rc_configuration_vars.h"
285 #undef CONFIG_VARIABLE
286 #undef CONFIG_VARIABLE_SPECIAL