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/filesystem_paths.h"
31 #include "ardour/session_configuration.h"
32 #include "ardour/utils.h"
35 using namespace ARDOUR;
38 SessionConfiguration::SessionConfiguration ()
40 /* construct variables */
41 #undef CONFIG_VARIABLE
42 #undef CONFIG_VARIABLE_SPECIAL
43 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
44 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
45 #include "ardour/session_configuration_vars.h"
46 #undef CONFIG_VARIABLE
47 #undef CONFIG_VARIABLE_SPECIAL
54 SessionConfiguration::get_state ()
59 root = new XMLNode ("Ardour");
60 root->add_child_nocopy (get_variables ());
67 SessionConfiguration::get_variables ()
72 node = new XMLNode ("Config");
74 #undef CONFIG_VARIABLE
75 #undef CONFIG_VARIABLE_SPECIAL
76 #define CONFIG_VARIABLE(type,var,Name,value) \
77 var.add_to_node (*node);
78 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
79 var.add_to_node (*node);
80 #include "ardour/session_configuration_vars.h"
81 #undef CONFIG_VARIABLE
82 #undef CONFIG_VARIABLE_SPECIAL
89 SessionConfiguration::set_state (XMLNode const& root, int /*version*/)
91 if (root.name() != "Ardour") {
95 for (XMLNodeConstIterator i = root.children().begin(); i != root.children().end(); ++i) {
96 if ((*i)->name() == "Config") {
105 SessionConfiguration::set_variables (const XMLNode& node)
107 #undef CONFIG_VARIABLE
108 #undef CONFIG_VARIABLE_SPECIAL
109 #define CONFIG_VARIABLE(type,var,name,value) \
110 if (var.set_from_node (node)) { \
111 ParameterChanged (name); \
113 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
114 if (var.set_from_node (node)) { \
115 ParameterChanged (name); \
118 #include "ardour/session_configuration_vars.h"
119 #undef CONFIG_VARIABLE
120 #undef CONFIG_VARIABLE_SPECIAL
124 SessionConfiguration::map_parameters (boost::function<void (std::string)>& functor)
126 #undef CONFIG_VARIABLE
127 #undef CONFIG_VARIABLE_SPECIAL
128 #define CONFIG_VARIABLE(type,var,name,value) functor (name);
129 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name);
130 #include "ardour/session_configuration_vars.h"
131 #undef CONFIG_VARIABLE
132 #undef CONFIG_VARIABLE_SPECIAL
137 SessionConfiguration::load_state ()
141 if (find_file (ardour_config_search_path(), "session.rc", rcfile)) {
142 if (g_stat (rcfile.c_str(), &statbuf)) {
145 if (statbuf.st_size == 0) {
149 if (!tree.read (rcfile.c_str())) {
150 error << string_compose(_("%1: cannot part default session options \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
154 XMLNode& root (*tree.root());
155 if (root.name() != X_("SessionDefaults")) {
156 warning << _("Invalid session default XML Root.") << endmsg;
161 if (((node = find_named_node (root, X_("Config"))) != 0)) {
163 set_variables(*node);
164 info << _("Loaded custom session defaults.") << endmsg;
166 warning << _("Found no session defaults in XML file.") << endmsg;
170 /* CUSTOM OVERRIDES */
171 set_audio_search_path("");
172 set_midi_search_path("");
179 SessionConfiguration::save_state ()
181 const std::string rcfile = Glib::build_filename (user_config_directory(), "session.rc");
182 if (rcfile.empty()) {
187 XMLNode* root = new XMLNode(X_("SessionDefaults"));
188 root->add_child_nocopy (get_variables ());
189 tree.set_root (root);
191 if (!tree.write (rcfile.c_str())) {
192 error << _("Could not save session options") << endmsg;