2 Copyright (C) 2009 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 "pbd/gstdio_compat.h"
22 #include <glibmm/miscutils.h> /* for build_filename() */
24 #include "pbd/error.h"
25 #include "pbd/file_utils.h"
26 #include "pbd/locale_guard.h"
27 #include "pbd/pathexpand.h"
29 #include "ardour/types.h"
30 #include "ardour/types_convert.h"
31 #include "ardour/filesystem_paths.h"
32 #include "ardour/session_configuration.h"
33 #include "ardour/utils.h"
36 using namespace ARDOUR;
39 SessionConfiguration::SessionConfiguration ()
41 /* construct variables */
42 #undef CONFIG_VARIABLE
43 #undef CONFIG_VARIABLE_SPECIAL
44 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
45 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
46 #include "ardour/session_configuration_vars.h"
47 #undef CONFIG_VARIABLE
48 #undef CONFIG_VARIABLE_SPECIAL
55 SessionConfiguration::get_state ()
60 root = new XMLNode ("Ardour");
61 root->add_child_nocopy (get_variables ());
68 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); \
114 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
115 if (var.set_from_node (node)) { \
116 ParameterChanged (name); \
119 #include "ardour/session_configuration_vars.h"
120 #undef CONFIG_VARIABLE
121 #undef CONFIG_VARIABLE_SPECIAL
125 SessionConfiguration::map_parameters (boost::function<void (std::string)>& functor)
127 #undef CONFIG_VARIABLE
128 #undef CONFIG_VARIABLE_SPECIAL
129 #define CONFIG_VARIABLE(type,var,name,value) functor (name);
130 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name);
131 #include "ardour/session_configuration_vars.h"
132 #undef CONFIG_VARIABLE
133 #undef CONFIG_VARIABLE_SPECIAL
138 SessionConfiguration::load_state ()
142 if (find_file (ardour_config_search_path(), "session.rc", rcfile)) {
143 if (g_stat (rcfile.c_str(), &statbuf)) {
146 if (statbuf.st_size == 0) {
150 if (!tree.read (rcfile.c_str())) {
151 error << string_compose(_("%1: cannot part default session options \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
155 XMLNode& root (*tree.root());
156 if (root.name() != X_("SessionDefaults")) {
157 warning << _("Invalid session default XML Root.") << endmsg;
162 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;