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.
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/error.h>
28 #include <pbd/localeguard.h>
30 #include <ardour/ardour.h>
32 #include "ui_config.h"
38 using namespace ARDOUR
;
40 UIConfiguration::UIConfiguration ()
42 #undef UI_CONFIG_VARIABLE
43 #undef CANVAS_VARIABLE
44 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
45 #define CANVAS_VARIABLE(var,name) var (name),
46 #include "ui_config_vars.h"
47 #include "canvas_vars.h"
48 #undef UI_CONFIG_VARIABLE
49 #undef CANVAS_VARIABLE
55 UIConfiguration::~UIConfiguration ()
60 UIConfiguration::load_defaults ()
66 ui_conf
= getenv ("ARDOUR_UI_CONF");
68 if (ui_conf
&& ui_conf
[0] != '\0') {
69 rcfile
= find_config_file (ui_conf
);
71 if (getenv ("ARDOUR_SAE")) {
72 rcfile
= find_config_file ("ardour2_ui_sae.conf");
74 rcfile
= find_config_file ("ardour2_ui_default.conf");
78 if (rcfile
.length()) {
83 cerr
<< string_compose (_("loading default ui configuration file %1"), rcfile
) << endl
;
85 if (!tree
.read (rcfile
.c_str())) {
86 error
<< string_compose(_("%1: cannot read default ui configuration file \"%2\""), PROGRAM_NAME
, rcfile
) << endmsg
;
90 if (set_state (*tree
.root())) {
91 error
<< string_compose(_("%1: default ui configuration file \"%2\" not loaded successfully."), PROGRAM_NAME
, rcfile
) << endmsg
;
99 UIConfiguration::load_state ()
101 int found
= load_defaults ();
102 std::string rcfile
= find_config_file ("ardour2_ui.conf");
109 cerr
<< string_compose (_("loading user ui configuration file %1"), rcfile
) << endl
;
111 if (!tree
.read (rcfile
)) {
112 error
<< string_compose(_("%1: cannot read ui configuration file \"%2\""), PROGRAM_NAME
, rcfile
) << endmsg
;
116 if (set_state (*tree
.root())) {
117 error
<< string_compose(_("%1: user ui configuration file \"%2\" not loaded successfully."), PROGRAM_NAME
, rcfile
) << endmsg
;
123 error
<< string_compose (_("%1: could not find any ui configuration file, canvas will look broken."), PROGRAM_NAME
) << endmsg
;
130 UIConfiguration::save_state()
135 rcfile
= Glib::build_filename (get_user_ardour_path (), "ardour2_ui.conf");
137 if (rcfile
.length()) {
138 tree
.set_root (&get_state());
139 if (!tree
.write (rcfile
.c_str())){
140 error
<< string_compose (_("UI config file %1 not saved"), rcfile
) << endmsg
;
149 UIConfiguration::get_state ()
152 LocaleGuard
lg (X_("POSIX"));
154 root
= new XMLNode("Ardour");
156 root
->add_child_nocopy (get_variables ("UI"));
157 root
->add_child_nocopy (get_variables ("Canvas"));
160 root
->add_child_copy (*_extra_xml
);
167 UIConfiguration::get_variables (std::string which_node
)
170 LocaleGuard
lg (X_("POSIX"));
172 node
= new XMLNode(which_node
);
174 #undef UI_CONFIG_VARIABLE
175 #undef CANVAS_VARIABLE
176 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
177 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
178 #include "ui_config_vars.h"
179 #include "canvas_vars.h"
180 #undef UI_CONFIG_VARIABLE
181 #undef CANVAS_VARIABLE
187 UIConfiguration::set_state (const XMLNode
& root
)
189 if (root
.name() != "Ardour") {
193 XMLNodeList nlist
= root
.children();
194 XMLNodeConstIterator niter
;
197 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
) {
200 if (node
->name() == "Canvas" || node
->name() == "UI") {
201 set_variables (*node
);
203 } else if (node
->name() == "extra") {
204 _extra_xml
= new XMLNode (*node
);
212 UIConfiguration::set_variables (const XMLNode
& node
)
214 #undef UI_CONFIG_VARIABLE
215 #undef CANVAS_VARIABLE
216 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
217 if (var.set_from_node (node)) { \
218 ParameterChanged (name); \
220 #define CANVAS_VARIABLE(var,name) \
221 if (var.set_from_node (node)) { \
222 ParameterChanged (name); \
224 #include "ui_config_vars.h"
225 #include "canvas_vars.h"
226 #undef UI_CONFIG_VARIABLE
227 #undef CANVAS_VARIABLE
231 UIConfiguration::pack_canvasvars ()
233 #undef CANVAS_VARIABLE
234 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
235 #include "canvas_vars.h"
236 #undef CANVAS_VARIABLE