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.
22 #include <cstdio> /* for snprintf, grrr */
24 #include <glibmm/miscutils.h>
26 #include "pbd/failed_constructor.h"
27 #include "pbd/xml++.h"
28 #include "pbd/file_utils.h"
29 #include "pbd/error.h"
31 #include "gtkmm2ext/rgb_macros.h"
33 #include "ardour/filesystem_paths.h"
35 #include "ui_config.h"
41 using namespace ARDOUR;
43 UIConfiguration::UIConfiguration ()
45 #undef UI_CONFIG_VARIABLE
46 #undef CANVAS_VARIABLE
47 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
48 #define CANVAS_VARIABLE(var,name) var (name),
49 #define CANVAS_STRING_VARIABLE(var,name) var (name),
50 #define CANVAS_FONT_VARIABLE(var,name) var (name),
51 #include "ui_config_vars.h"
52 #include "canvas_vars.h"
53 #undef UI_CONFIG_VARIABLE
54 #undef CANVAS_VARIABLE
55 #undef CANVAS_STRING_VARIABLE
56 #undef CANVAS_FONT_VARIABLE
62 UIConfiguration::~UIConfiguration ()
67 UIConfiguration::map_parameters (boost::function<void (std::string)>& functor)
69 #undef UI_CONFIG_VARIABLE
70 #define UI_CONFIG_VARIABLE(Type,var,Name,value) functor (Name);
71 #include "ui_config_vars.h"
72 #undef UI_CONFIG_VARIABLE
76 UIConfiguration::load_defaults ()
80 std::string default_ui_rc_file;
83 if (getenv ("ARDOUR_SAE")) {
84 rcfile = "ardour3_ui_sae.conf";
86 rcfile = "ardour3_ui_default.conf";
89 if (find_file (ardour_config_search_path(), rcfile, default_ui_rc_file) ) {
93 string rcfile = default_ui_rc_file;
95 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
97 if (!tree.read (rcfile.c_str())) {
98 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
102 if (set_state (*tree.root(), Stateful::loading_state_version)) {
103 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
114 UIConfiguration::load_state ()
118 std::string default_ui_rc_file;
120 if ( find_file (ardour_config_search_path(), "ardour3_ui_default.conf", default_ui_rc_file)) {
124 string rcfile = default_ui_rc_file;
126 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
128 if (!tree.read (rcfile.c_str())) {
129 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
133 if (set_state (*tree.root(), Stateful::loading_state_version)) {
134 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
139 std::string user_ui_rc_file;
141 if (find_file (ardour_config_search_path(), "ardour3_ui.conf", user_ui_rc_file)) {
145 string rcfile = user_ui_rc_file;
147 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
149 if (!tree.read (rcfile)) {
150 error << string_compose(_("cannot read ui configuration file \"%1\""), rcfile) << endmsg;
154 if (set_state (*tree.root(), Stateful::loading_state_version)) {
155 error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
163 error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
171 UIConfiguration::save_state()
175 std::string rcfile(user_config_directory());
176 rcfile = Glib::build_filename (rcfile, "ardour3_ui.conf");
178 // this test seems bogus?
179 if (rcfile.length()) {
180 tree.set_root (&get_state());
181 if (!tree.write (rcfile.c_str())){
182 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
193 UIConfiguration::get_state ()
196 LocaleGuard lg (X_("POSIX"));
198 root = new XMLNode("Ardour");
200 root->add_child_nocopy (get_variables ("UI"));
201 root->add_child_nocopy (get_variables ("Canvas"));
204 root->add_child_copy (*_extra_xml);
211 UIConfiguration::get_variables (std::string which_node)
214 LocaleGuard lg (X_("POSIX"));
216 node = new XMLNode(which_node);
218 #undef UI_CONFIG_VARIABLE
219 #undef CANVAS_VARIABLE
220 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
221 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
222 #define CANVAS_STRING_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
223 #define CANVAS_FONT_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
224 #include "ui_config_vars.h"
225 #include "canvas_vars.h"
226 #undef UI_CONFIG_VARIABLE
227 #undef CANVAS_VARIABLE
228 #undef CANVAS_STRING_VARIABLE
229 #undef CANVAS_FONT_VARIABLE
235 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
237 if (root.name() != "Ardour") {
241 Stateful::save_extra_xml (root);
243 XMLNodeList nlist = root.children();
244 XMLNodeConstIterator niter;
247 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
251 if (node->name() == "Canvas" || node->name() == "UI") {
252 set_variables (*node);
261 UIConfiguration::set_variables (const XMLNode& node)
263 #undef UI_CONFIG_VARIABLE
264 #undef CANVAS_VARIABLE
265 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
266 if (var.set_from_node (node)) { \
267 ParameterChanged (name); \
269 #define CANVAS_VARIABLE(var,name) \
270 if (var.set_from_node (node)) { \
271 ParameterChanged (name); \
273 #define CANVAS_STRING_VARIABLE(var,name) \
274 if (var.set_from_node (node)) { \
275 ParameterChanged (name); \
277 #define CANVAS_FONT_VARIABLE(var,name) \
278 if (var.set_from_node (node)) { \
279 ParameterChanged (name); \
281 #include "ui_config_vars.h"
282 #include "canvas_vars.h"
283 #undef UI_CONFIG_VARIABLE
284 #undef CANVAS_VARIABLE
285 #undef CANVAS_STRING_VARIABLE
286 #undef CANVAS_FONT_VARIABLE
290 UIConfiguration::pack_canvasvars ()
292 #undef CANVAS_VARIABLE
293 #define CANVAS_VARIABLE(var,name) canvas_colors.insert (std::pair<std::string,ColorVariable<uint32_t>* >(name,&var));
294 #define CANVAS_STRING_VARIABLE(var,name)
295 #define CANVAS_FONT_VARIABLE(var,name)
296 #include "canvas_vars.h"
297 #undef CANVAS_VARIABLE
298 #undef CANVAS_STRING_VARIABLE
299 #undef CANVAS_FONT_VARIABLE
303 UIConfiguration::color_by_name (const std::string& name)
305 map<std::string,ColorVariable<uint32_t>* >::iterator i = canvas_colors.find (name);
307 if (i != canvas_colors.end()) {
308 return i->second->get();
311 // cerr << string_compose (_("Color %1 not found"), name) << endl;
312 return RGBA_TO_UINT (g_random_int()%256,g_random_int()%256,g_random_int()%256,0xff);
316 UIConfiguration::set_dirty ()
322 UIConfiguration::dirty () const