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 <pbd/failed_constructor.h>
24 #include <pbd/xml++.h>
25 #include <pbd/error.h>
27 #include <ardour/ardour.h>
29 #include "ui_config.h"
35 using namespace ARDOUR;
37 UIConfiguration::UIConfiguration ()
39 #undef UI_CONFIG_VARIABLE
40 #undef CANVAS_VARIABLE
41 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
42 #define CANVAS_VARIABLE(var,name) var (name),
43 #include "ui_config_vars.h"
44 #include "canvas_vars.h"
45 #undef UI_CONFIG_VARIABLE
46 #undef CANVAS_VARIABLE
52 UIConfiguration::~UIConfiguration ()
57 UIConfiguration::load_defaults ()
63 ui_conf = getenv ("ARDOUR_UI_CONF");
65 if (ui_conf && ui_conf[0] != '\0') {
66 rcfile = find_config_file (ui_conf);
68 rcfile = find_config_file ("ardour2_ui_default.conf");
71 if (rcfile.length()) {
76 cerr << string_compose (_("loading default ui configuration file %1"), rcfile) << endl;
78 if (!tree.read (rcfile.c_str())) {
79 error << string_compose(_("Ardour: cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
83 if (set_state (*tree.root())) {
84 error << string_compose(_("Ardour: default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
92 UIConfiguration::load_state ()
94 int found = load_defaults ();
95 std::string rcfile = find_config_file ("ardour2_ui.conf");
102 cerr << string_compose (_("loading user ui configuration file %1"), rcfile) << endl;
104 if (!tree.read (rcfile)) {
105 error << string_compose(_("Ardour: cannot read ui configuration file \"%1\""), rcfile) << endmsg;
109 if (set_state (*tree.root())) {
110 error << string_compose(_("Ardour: user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
116 error << "Ardour: could not find any ui configuration file, canvas will look broken." << endmsg;
123 UIConfiguration::save_state()
128 rcfile = get_user_ardour_path ();
129 rcfile += "ardour2_ui.conf";
131 if (rcfile.length()) {
132 tree.set_root (&get_state());
133 if (!tree.write (rcfile.c_str())){
134 error << string_compose (_("UI config file %1 not saved"), rcfile) << endmsg;
143 UIConfiguration::get_state ()
146 LocaleGuard lg (X_("POSIX"));
148 root = new XMLNode("Ardour");
150 root->add_child_nocopy (get_variables ("UI"));
151 root->add_child_nocopy (get_variables ("Canvas"));
154 root->add_child_copy (*_extra_xml);
161 UIConfiguration::get_variables (std::string which_node)
164 LocaleGuard lg (X_("POSIX"));
166 node = new XMLNode(which_node);
168 #undef UI_CONFIG_VARIABLE
169 #undef CANVAS_VARIABLE
170 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
171 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
172 #include "ui_config_vars.h"
173 #include "canvas_vars.h"
174 #undef UI_CONFIG_VARIABLE
175 #undef CANVAS_VARIABLE
181 UIConfiguration::set_state (const XMLNode& root)
183 if (root.name() != "Ardour") {
187 XMLNodeList nlist = root.children();
188 XMLNodeConstIterator niter;
191 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
194 if (node->name() == "Canvas" || node->name() == "UI") {
195 set_variables (*node);
197 } else if (node->name() == "extra") {
198 _extra_xml = new XMLNode (*node);
206 UIConfiguration::set_variables (const XMLNode& node)
208 #undef UI_CONFIG_VARIABLE
209 #undef CANVAS_VARIABLE
210 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
211 if (var.set_from_node (node)) { \
212 ParameterChanged (name); \
214 #define CANVAS_VARIABLE(var,name) \
215 if (var.set_from_node (node)) { \
216 ParameterChanged (name); \
218 #include "ui_config_vars.h"
219 #include "canvas_vars.h"
220 #undef UI_CONFIG_VARIABLE
221 #undef CANVAS_VARIABLE
225 UIConfiguration::pack_canvasvars ()
227 #undef CANVAS_VARIABLE
228 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
229 #include "canvas_vars.h"
230 #undef CANVAS_VARIABLE