2 * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
3 * Copyright (C) 2009-2016 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2009 Carl Hetherington <carl@carlh.net>
5 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
6 * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
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 "pbd/gstdio_compat.h"
25 #include <glibmm/miscutils.h> /* for build_filename() */
27 #include "pbd/error.h"
28 #include "pbd/file_utils.h"
29 #include "pbd/pathexpand.h"
31 #include "ardour/types.h"
32 #include "ardour/types_convert.h"
33 #include "ardour/filesystem_paths.h"
34 #include "ardour/session_configuration.h"
35 #include "ardour/utils.h"
38 using namespace ARDOUR;
41 SessionConfiguration::SessionConfiguration ()
43 /* construct variables */
44 #undef CONFIG_VARIABLE
45 #undef CONFIG_VARIABLE_SPECIAL
46 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
47 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
48 #include "ardour/session_configuration_vars.h"
49 #undef CONFIG_VARIABLE
50 #undef CONFIG_VARIABLE_SPECIAL
57 SessionConfiguration::get_state ()
61 root = new XMLNode ("Ardour");
62 root->add_child_nocopy (get_variables ());
69 SessionConfiguration::get_variables ()
73 node = new XMLNode ("Config");
75 #undef CONFIG_VARIABLE
76 #undef CONFIG_VARIABLE_SPECIAL
77 #define CONFIG_VARIABLE(type,var,Name,value) \
78 var.add_to_node (*node);
79 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
80 var.add_to_node (*node);
81 #include "ardour/session_configuration_vars.h"
82 #undef CONFIG_VARIABLE
83 #undef CONFIG_VARIABLE_SPECIAL
90 SessionConfiguration::set_state (XMLNode const& root, int /*version*/)
92 if (root.name() != "Ardour") {
96 for (XMLNodeConstIterator i = root.children().begin(); i != root.children().end(); ++i) {
97 if ((*i)->name() == "Config") {
106 SessionConfiguration::set_variables (const XMLNode& node)
108 #undef CONFIG_VARIABLE
109 #undef CONFIG_VARIABLE_SPECIAL
110 #define CONFIG_VARIABLE(type,var,name,value) \
111 if (var.set_from_node (node)) { \
112 ParameterChanged (name); \
115 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
116 if (var.set_from_node (node)) { \
117 ParameterChanged (name); \
120 #include "ardour/session_configuration_vars.h"
121 #undef CONFIG_VARIABLE
122 #undef CONFIG_VARIABLE_SPECIAL
126 SessionConfiguration::map_parameters (boost::function<void (std::string)>& functor)
128 #undef CONFIG_VARIABLE
129 #undef CONFIG_VARIABLE_SPECIAL
130 #define CONFIG_VARIABLE(type,var,name,value) functor (name);
131 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name);
132 #include "ardour/session_configuration_vars.h"
133 #undef CONFIG_VARIABLE
134 #undef CONFIG_VARIABLE_SPECIAL
139 SessionConfiguration::load_state ()
143 if (find_file (ardour_config_search_path(), "session.rc", rcfile)) {
144 if (g_stat (rcfile.c_str(), &statbuf)) {
147 if (statbuf.st_size == 0) {
151 if (!tree.read (rcfile.c_str())) {
152 error << string_compose(_("%1: cannot part default session options \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
156 XMLNode& root (*tree.root());
157 if (root.name() != X_("SessionDefaults")) {
158 warning << _("Invalid session default XML Root.") << endmsg;
163 if (((node = find_named_node (root, X_("Config"))) != 0)) {
164 set_variables(*node);
165 info << _("Loaded custom session defaults.") << endmsg;
167 warning << _("Found no session defaults in XML file.") << endmsg;
171 /* CUSTOM OVERRIDES */
172 set_audio_search_path("");
173 set_midi_search_path("");
180 SessionConfiguration::save_state ()
182 const std::string rcfile = Glib::build_filename (user_config_directory(), "session.rc");
183 if (rcfile.empty()) {
188 XMLNode* root = new XMLNode(X_("SessionDefaults"));
189 root->add_child_nocopy (get_variables ());
190 tree.set_root (root);
192 if (!tree.write (rcfile.c_str())) {
193 error << _("Could not save session options") << endmsg;