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>
29 #include <ardour/ardour.h>
31 #include "ui_config.h"
37 using namespace ARDOUR
;
39 UIConfiguration::UIConfiguration ()
41 #undef UI_CONFIG_VARIABLE
42 #undef CANVAS_VARIABLE
43 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
44 #define CANVAS_VARIABLE(var,name) var (name),
45 #include "ui_config_vars.h"
46 #include "canvas_vars.h"
47 #undef UI_CONFIG_VARIABLE
48 #undef CANVAS_VARIABLE
54 UIConfiguration::~UIConfiguration ()
59 UIConfiguration::load_defaults ()
65 ui_conf
= getenv ("ARDOUR_UI_CONF");
67 if (ui_conf
&& ui_conf
[0] != '\0') {
68 rcfile
= find_config_file (ui_conf
);
70 if (getenv ("ARDOUR_SAE")) {
71 rcfile
= find_config_file ("ardour2_ui_sae.conf");
73 rcfile
= find_config_file ("ardour2_ui_default.conf");
77 if (rcfile
.length()) {
82 cerr
<< 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
;
89 if (set_state (*tree
.root())) {
90 error
<< string_compose(_("Ardour: default ui configuration file \"%1\" not loaded successfully."), rcfile
) << endmsg
;
98 UIConfiguration::load_state ()
100 int found
= load_defaults ();
101 std::string rcfile
= find_config_file ("ardour2_ui.conf");
108 cerr
<< string_compose (_("loading user ui configuration file %1"), rcfile
) << endl
;
110 if (!tree
.read (rcfile
)) {
111 error
<< string_compose(_("Ardour: cannot read ui configuration file \"%1\""), rcfile
) << endmsg
;
115 if (set_state (*tree
.root())) {
116 error
<< string_compose(_("Ardour: user ui configuration file \"%1\" not loaded successfully."), rcfile
) << endmsg
;
122 error
<< "Ardour: could not find any ui configuration file, canvas will look broken." << endmsg
;
129 UIConfiguration::save_state()
134 rcfile
= Glib::build_filename (get_user_ardour_path (), "ardour2_ui.conf");
136 if (rcfile
.length()) {
137 tree
.set_root (&get_state());
138 if (!tree
.write (rcfile
.c_str())){
139 error
<< string_compose (_("UI config file %1 not saved"), rcfile
) << endmsg
;
148 UIConfiguration::get_state ()
151 LocaleGuard
lg (X_("POSIX"));
153 root
= new XMLNode("Ardour");
155 root
->add_child_nocopy (get_variables ("UI"));
156 root
->add_child_nocopy (get_variables ("Canvas"));
159 root
->add_child_copy (*_extra_xml
);
166 UIConfiguration::get_variables (std::string which_node
)
169 LocaleGuard
lg (X_("POSIX"));
171 node
= new XMLNode(which_node
);
173 #undef UI_CONFIG_VARIABLE
174 #undef CANVAS_VARIABLE
175 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
176 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
177 #include "ui_config_vars.h"
178 #include "canvas_vars.h"
179 #undef UI_CONFIG_VARIABLE
180 #undef CANVAS_VARIABLE
186 UIConfiguration::set_state (const XMLNode
& root
)
188 if (root
.name() != "Ardour") {
192 XMLNodeList nlist
= root
.children();
193 XMLNodeConstIterator niter
;
196 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
) {
199 if (node
->name() == "Canvas" || node
->name() == "UI") {
200 set_variables (*node
);
202 } else if (node
->name() == "extra") {
203 _extra_xml
= new XMLNode (*node
);
211 UIConfiguration::set_variables (const XMLNode
& node
)
213 #undef UI_CONFIG_VARIABLE
214 #undef CANVAS_VARIABLE
215 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
216 if (var.set_from_node (node)) { \
217 ParameterChanged (name); \
219 #define CANVAS_VARIABLE(var,name) \
220 if (var.set_from_node (node)) { \
221 ParameterChanged (name); \
223 #include "ui_config_vars.h"
224 #include "canvas_vars.h"
225 #undef UI_CONFIG_VARIABLE
226 #undef CANVAS_VARIABLE
230 UIConfiguration::pack_canvasvars ()
232 #undef CANVAS_VARIABLE
233 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
234 #include "canvas_vars.h"
235 #undef CANVAS_VARIABLE