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 <glib/gstdio.h> /* for g_stat() */
22 #include <glibmm/miscutils.h> /* for build_filename() */
24 #include "pbd/file_utils.h"
25 #include "pbd/pathexpand.h"
27 #include "ardour/types.h"
28 #include "ardour/filesystem_paths.h"
29 #include "ardour/session_configuration.h"
32 using namespace ARDOUR;
35 SessionConfiguration::SessionConfiguration ()
37 /* construct variables */
38 #undef CONFIG_VARIABLE
39 #undef CONFIG_VARIABLE_SPECIAL
40 #define CONFIG_VARIABLE(Type,var,name,value) var (name,value),
41 #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator),
42 #include "ardour/session_configuration_vars.h"
43 #undef CONFIG_VARIABLE
44 #undef CONFIG_VARIABLE_SPECIAL
51 SessionConfiguration::get_state ()
54 LocaleGuard lg (X_("POSIX"));
56 root = new XMLNode ("Ardour");
57 root->add_child_nocopy (get_variables ());
64 SessionConfiguration::get_variables ()
67 LocaleGuard lg (X_("POSIX"));
69 node = new XMLNode ("Config");
71 #undef CONFIG_VARIABLE
72 #undef CONFIG_VARIABLE_SPECIAL
73 #define CONFIG_VARIABLE(type,var,Name,value) \
74 var.add_to_node (*node);
75 #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
76 var.add_to_node (*node);
77 #include "ardour/session_configuration_vars.h"
78 #undef CONFIG_VARIABLE
79 #undef CONFIG_VARIABLE_SPECIAL
86 SessionConfiguration::set_state (XMLNode const& root, int /*version*/)
88 if (root.name() != "Ardour") {
92 for (XMLNodeConstIterator i = root.children().begin(); i != root.children().end(); ++i) {
93 if ((*i)->name() == "Config") {
102 SessionConfiguration::set_variables (const XMLNode& node)
104 #undef CONFIG_VARIABLE
105 #undef CONFIG_VARIABLE_SPECIAL
106 #define CONFIG_VARIABLE(type,var,name,value) \
107 if (var.set_from_node (node)) { \
108 ParameterChanged (name); \
110 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
111 if (var.set_from_node (node)) { \
112 ParameterChanged (name); \
115 #include "ardour/session_configuration_vars.h"
116 #undef CONFIG_VARIABLE
117 #undef CONFIG_VARIABLE_SPECIAL
121 SessionConfiguration::map_parameters (boost::function<void (std::string)>& functor)
123 #undef CONFIG_VARIABLE
124 #undef CONFIG_VARIABLE_SPECIAL
125 #define CONFIG_VARIABLE(type,var,name,value) functor (name);
126 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name);
127 #include "ardour/session_configuration_vars.h"
128 #undef CONFIG_VARIABLE
129 #undef CONFIG_VARIABLE_SPECIAL
134 SessionConfiguration::load_state ()
138 if (find_file (ardour_config_search_path(), "session.rc", rcfile)) {
139 if (g_stat (rcfile.c_str(), &statbuf)) {
142 if (statbuf.st_size == 0) {
146 if (!tree.read (rcfile.c_str())) {
147 error << string_compose(_("%1: cannot part default session options \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
151 XMLNode& root (*tree.root());
152 if (root.name() != X_("SessionDefaults")) {
153 warning << _("Invalid session default XML Root.") << endmsg;
158 if (((node = find_named_node (root, X_("Config"))) != 0)) {
159 LocaleGuard lg (X_("POSIX"));
160 set_variables(*node);
161 info << _("Loaded custom session defaults.") << endmsg;
163 warning << _("Found no session defaults in XML file.") << endmsg;
167 /* CUSTOM OVERRIDES */
168 set_audio_search_path("");
169 set_midi_search_path("");
176 SessionConfiguration::save_state ()
178 const std::string rcfile = Glib::build_filename (user_config_directory(), "session.rc");
179 if (rcfile.empty()) {
184 XMLNode* root = new XMLNode(X_("SessionDefaults"));
185 root->add_child_nocopy (get_variables ());
186 tree.set_root (root);
188 if (!tree.write (rcfile.c_str())) {
189 error << _("Could not save session options") << endmsg;