fix inverse solo push to work properly in both exclusive and non-exclusive solo modes
[ardour2.git] / gtk2_ardour / ui_config.cc
blobd541a49b772f0d3b0a6869a3f77f60632ce5a3f4
1 /*
2 Copyright (C) 1999-2006 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.
20 #include <unistd.h>
21 #include <cstdio> /* for snprintf, grrr */
23 #include <glibmm/miscutils.h>
25 #include "pbd/failed_constructor.h"
26 #include "pbd/xml++.h"
27 #include "pbd/filesystem.h"
28 #include "pbd/file_utils.h"
29 #include "pbd/error.h"
31 #include "ardour/ardour.h"
32 #include "ardour/filesystem_paths.h"
34 #include "ui_config.h"
36 #include "i18n.h"
38 using namespace std;
39 using namespace PBD;
40 using namespace ARDOUR;
42 UIConfiguration::UIConfiguration ()
44 #undef UI_CONFIG_VARIABLE
45 #undef CANVAS_VARIABLE
46 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
47 #define CANVAS_VARIABLE(var,name) var (name),
48 #include "ui_config_vars.h"
49 #include "canvas_vars.h"
50 #undef UI_CONFIG_VARIABLE
51 #undef CANVAS_VARIABLE
52 hack(true)
54 load_state();
57 UIConfiguration::~UIConfiguration ()
61 int
62 UIConfiguration::load_defaults ()
64 int found = 0;
66 sys::path default_ui_rc_file;
67 std::string rcfile;
69 if (getenv ("ARDOUR_SAE")) {
70 rcfile = "ardour3_ui_sae.conf";
71 } else {
72 rcfile = "ardour3_ui_default.conf";
74 if ( !find_file_in_search_path (ardour_search_path() + system_config_search_path(),
75 rcfile, default_ui_rc_file) )
77 XMLTree tree;
78 found = 1;
80 string rcfile = default_ui_rc_file.to_string();
82 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
84 if (!tree.read (rcfile.c_str())) {
85 error << string_compose(_("Ardour: cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
86 return -1;
89 if (set_state (*tree.root(), Stateful::loading_state_version)) {
90 error << string_compose(_("Ardour: default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
91 return -1;
94 return found;
97 int
98 UIConfiguration::load_state ()
100 bool found = false;
102 sys::path default_ui_rc_file;
104 if ( find_file_in_search_path (ardour_search_path() + system_config_search_path(),
105 "ardour3_ui_default.conf", default_ui_rc_file) )
107 XMLTree tree;
108 found = true;
110 string rcfile = default_ui_rc_file.to_string();
112 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
114 if (!tree.read (rcfile.c_str())) {
115 error << string_compose(_("Ardour: cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
116 return -1;
119 if (set_state (*tree.root(), Stateful::loading_state_version)) {
120 error << string_compose(_("Ardour: default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
121 return -1;
125 sys::path user_ui_rc_file;
127 if (find_file_in_search_path (ardour_search_path() + user_config_directory(),
128 "ardour3_ui.conf", user_ui_rc_file))
130 XMLTree tree;
131 found = true;
133 string rcfile = user_ui_rc_file.to_string();
135 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endl;
137 if (!tree.read (rcfile)) {
138 error << string_compose(_("Ardour: cannot read ui configuration file \"%1\""), rcfile) << endmsg;
139 return -1;
142 if (set_state (*tree.root(), Stateful::loading_state_version)) {
143 error << string_compose(_("Ardour: user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
144 return -1;
148 if (!found)
149 error << "Ardour: could not find any ui configuration file, canvas will look broken." << endmsg;
151 pack_canvasvars();
152 return 0;
156 UIConfiguration::save_state()
158 XMLTree tree;
160 try {
161 sys::create_directories (user_config_directory ());
163 catch (const sys::filesystem_error& ex) {
164 error << "Could not create user configuration directory" << endmsg;
165 return -1;
168 sys::path rcfile_path(user_config_directory());
170 rcfile_path /= "ardour3_ui.conf";
171 const string rcfile = rcfile_path.to_string();
173 // this test seems bogus?
174 if (rcfile.length()) {
175 tree.set_root (&get_state());
176 if (!tree.write (rcfile.c_str())){
177 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
178 return -1;
182 return 0;
185 XMLNode&
186 UIConfiguration::get_state ()
188 XMLNode* root;
189 LocaleGuard lg (X_("POSIX"));
191 root = new XMLNode("Ardour");
193 root->add_child_nocopy (get_variables ("UI"));
194 root->add_child_nocopy (get_variables ("Canvas"));
196 if (_extra_xml) {
197 root->add_child_copy (*_extra_xml);
200 return *root;
203 XMLNode&
204 UIConfiguration::get_variables (std::string which_node)
206 XMLNode* node;
207 LocaleGuard lg (X_("POSIX"));
209 node = new XMLNode(which_node);
211 #undef UI_CONFIG_VARIABLE
212 #undef CANVAS_VARIABLE
213 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
214 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
215 #include "ui_config_vars.h"
216 #include "canvas_vars.h"
217 #undef UI_CONFIG_VARIABLE
218 #undef CANVAS_VARIABLE
220 return *node;
224 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
226 if (root.name() != "Ardour") {
227 return -1;
230 XMLNodeList nlist = root.children();
231 XMLNodeConstIterator niter;
232 XMLNode *node;
234 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
236 node = *niter;
237 if (node->name() == "Canvas" || node->name() == "UI") {
238 set_variables (*node);
240 } else if (node->name() == "Extra") {
241 _extra_xml = new XMLNode (*node);
245 return 0;
248 void
249 UIConfiguration::set_variables (const XMLNode& node)
251 #undef UI_CONFIG_VARIABLE
252 #undef CANVAS_VARIABLE
253 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
254 if (var.set_from_node (node)) { \
255 ParameterChanged (name); \
257 #define CANVAS_VARIABLE(var,name) \
258 if (var.set_from_node (node)) { \
259 ParameterChanged (name); \
261 #include "ui_config_vars.h"
262 #include "canvas_vars.h"
263 #undef UI_CONFIG_VARIABLE
264 #undef CANVAS_VARIABLE
267 void
268 UIConfiguration::pack_canvasvars ()
270 #undef CANVAS_VARIABLE
271 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
272 #include "canvas_vars.h"
273 #undef CANVAS_VARIABLE