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_state ()
61 std::string rcfile = find_config_file ("ardour2_ui_default.conf");
68 cerr << string_compose (_("loading default ui configuration file %1"), rcfile) << endl;
70 if (!tree.read (rcfile.c_str())) {
71 error << string_compose(_("Ardour: cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
75 if (set_state (*tree.root())) {
76 error << string_compose(_("Ardour: default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
81 rcfile = find_config_file ("ardour2_ui.conf");
88 cerr << string_compose (_("loading user ui configuration file %1"), rcfile) << endl;
90 if (!tree.read (rcfile)) {
91 error << string_compose(_("Ardour: cannot read ui configuration file \"%1\""), rcfile) << endmsg;
95 if (set_state (*tree.root())) {
96 error << string_compose(_("Ardour: user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
102 error << "Ardour: could not find any ui configuration file, canvas will look broken." << endmsg;
109 UIConfiguration::save_state()
114 rcfile = get_user_ardour_path ();
115 rcfile += "ardour2_ui.conf";
117 if (rcfile.length()) {
118 tree.set_root (&get_state());
119 if (!tree.write (rcfile.c_str())){
120 error << string_compose (_("UI config file %1 not saved"), rcfile) << endmsg;
129 UIConfiguration::get_state ()
132 LocaleGuard lg (X_("POSIX"));
134 root = new XMLNode("Ardour");
136 root->add_child_nocopy (get_variables ("UI"));
137 root->add_child_nocopy (get_variables ("Canvas"));
140 root->add_child_copy (*_extra_xml);
147 UIConfiguration::get_variables (std::string which_node)
150 LocaleGuard lg (X_("POSIX"));
152 node = new XMLNode(which_node);
154 #undef UI_CONFIG_VARIABLE
155 #undef CANVAS_VARIABLE
156 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
157 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
158 #include "ui_config_vars.h"
159 #include "canvas_vars.h"
160 #undef UI_CONFIG_VARIABLE
161 #undef CANVAS_VARIABLE
167 UIConfiguration::set_state (const XMLNode& root)
169 if (root.name() != "Ardour") {
173 XMLNodeList nlist = root.children();
174 XMLNodeConstIterator niter;
177 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
180 if (node->name() == "Canvas" || node->name() == "UI") {
181 set_variables (*node);
183 } else if (node->name() == "extra") {
184 _extra_xml = new XMLNode (*node);
192 UIConfiguration::set_variables (const XMLNode& node)
194 #undef UI_CONFIG_VARIABLE
195 #undef CANVAS_VARIABLE
196 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
197 if (var.set_from_node (node)) { \
198 ParameterChanged (name); \
200 #define CANVAS_VARIABLE(var,name) \
201 if (var.set_from_node (node)) { \
202 ParameterChanged (name); \
204 #include "ui_config_vars.h"
205 #include "canvas_vars.h"
206 #undef UI_CONFIG_VARIABLE
207 #undef CANVAS_VARIABLE
211 UIConfiguration::pack_canvasvars ()
213 #undef CANVAS_VARIABLE
214 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
215 #include "canvas_vars.h"
216 #undef CANVAS_VARIABLE
217 cerr << "Configuration::pack_canvasvars () called, canvas_colors.size() = " << canvas_colors.size() << endl;