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 rcfile = find_config_file ("ardour2_ui_default.conf");
73 if (rcfile.length()) {
78 cerr << string_compose (_("loading default ui configuration file %1"), rcfile) << endl;
80 if (!tree.read (rcfile.c_str())) {
81 error << string_compose(_("Ardour: cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
85 if (set_state (*tree.root())) {
86 error << string_compose(_("Ardour: default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
94 UIConfiguration::load_state ()
96 int found = load_defaults ();
97 std::string rcfile = find_config_file ("ardour2_ui.conf");
104 cerr << string_compose (_("loading user ui configuration file %1"), rcfile) << endl;
106 if (!tree.read (rcfile)) {
107 error << string_compose(_("Ardour: cannot read ui configuration file \"%1\""), rcfile) << endmsg;
111 if (set_state (*tree.root())) {
112 error << string_compose(_("Ardour: user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
118 error << "Ardour: could not find any ui configuration file, canvas will look broken." << endmsg;
125 UIConfiguration::save_state()
130 rcfile = Glib::build_filename (get_user_ardour_path (), "ardour2_ui.conf");
132 if (rcfile.length()) {
133 tree.set_root (&get_state());
134 if (!tree.write (rcfile.c_str())){
135 error << string_compose (_("UI config file %1 not saved"), rcfile) << endmsg;
144 UIConfiguration::get_state ()
147 LocaleGuard lg (X_("POSIX"));
149 root = new XMLNode("Ardour");
151 root->add_child_nocopy (get_variables ("UI"));
152 root->add_child_nocopy (get_variables ("Canvas"));
155 root->add_child_copy (*_extra_xml);
162 UIConfiguration::get_variables (std::string which_node)
165 LocaleGuard lg (X_("POSIX"));
167 node = new XMLNode(which_node);
169 #undef UI_CONFIG_VARIABLE
170 #undef CANVAS_VARIABLE
171 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
172 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
173 #include "ui_config_vars.h"
174 #include "canvas_vars.h"
175 #undef UI_CONFIG_VARIABLE
176 #undef CANVAS_VARIABLE
182 UIConfiguration::set_state (const XMLNode& root)
184 if (root.name() != "Ardour") {
188 XMLNodeList nlist = root.children();
189 XMLNodeConstIterator niter;
192 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
195 if (node->name() == "Canvas" || node->name() == "UI") {
196 set_variables (*node);
198 } else if (node->name() == "extra") {
199 _extra_xml = new XMLNode (*node);
207 UIConfiguration::set_variables (const XMLNode& node)
209 #undef UI_CONFIG_VARIABLE
210 #undef CANVAS_VARIABLE
211 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
212 if (var.set_from_node (node)) { \
213 ParameterChanged (name); \
215 #define CANVAS_VARIABLE(var,name) \
216 if (var.set_from_node (node)) { \
217 ParameterChanged (name); \
219 #include "ui_config_vars.h"
220 #include "canvas_vars.h"
221 #undef UI_CONFIG_VARIABLE
222 #undef CANVAS_VARIABLE
226 UIConfiguration::pack_canvasvars ()
228 #undef CANVAS_VARIABLE
229 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
230 #include "canvas_vars.h"
231 #undef CANVAS_VARIABLE