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 #include "ui_config_vars.h"
51 #include "canvas_vars.h"
52 #undef UI_CONFIG_VARIABLE
53 #undef CANVAS_VARIABLE
54 #undef CANVAS_STRING_VARIABLE
60 UIConfiguration::~UIConfiguration ()
65 UIConfiguration::map_parameters (boost::function<void (std::string)>& functor)
67 #undef UI_CONFIG_VARIABLE
68 #define UI_CONFIG_VARIABLE(Type,var,Name,value) functor (Name);
69 #include "ui_config_vars.h"
70 #undef UI_CONFIG_VARIABLE
74 UIConfiguration::load_defaults ()
78 std::string default_ui_rc_file;
81 if (getenv ("ARDOUR_SAE")) {
82 rcfile = "ardour3_ui_sae.conf";
84 rcfile = "ardour3_ui_default.conf";
87 if (find_file_in_search_path (ardour_config_search_path(), rcfile, default_ui_rc_file) ) {
91 string rcfile = default_ui_rc_file;
93 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
95 if (!tree.read (rcfile.c_str())) {
96 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
100 if (set_state (*tree.root(), Stateful::loading_state_version)) {
101 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
112 UIConfiguration::load_state ()
116 std::string default_ui_rc_file;
118 if ( find_file_in_search_path (ardour_config_search_path(), "ardour3_ui_default.conf", default_ui_rc_file)) {
122 string rcfile = default_ui_rc_file;
124 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
126 if (!tree.read (rcfile.c_str())) {
127 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
131 if (set_state (*tree.root(), Stateful::loading_state_version)) {
132 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
137 std::string user_ui_rc_file;
139 if (find_file_in_search_path (ardour_config_search_path(), "ardour3_ui.conf", user_ui_rc_file)) {
143 string rcfile = user_ui_rc_file;
145 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
147 if (!tree.read (rcfile)) {
148 error << string_compose(_("cannot read ui configuration file \"%1\""), rcfile) << endmsg;
152 if (set_state (*tree.root(), Stateful::loading_state_version)) {
153 error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
161 error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
169 UIConfiguration::save_state()
173 std::string rcfile(user_config_directory());
174 rcfile = Glib::build_filename (rcfile, "ardour3_ui.conf");
176 // this test seems bogus?
177 if (rcfile.length()) {
178 tree.set_root (&get_state());
179 if (!tree.write (rcfile.c_str())){
180 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
191 UIConfiguration::get_state ()
194 LocaleGuard lg (X_("POSIX"));
196 root = new XMLNode("Ardour");
198 root->add_child_nocopy (get_variables ("UI"));
199 root->add_child_nocopy (get_variables ("Canvas"));
202 root->add_child_copy (*_extra_xml);
209 UIConfiguration::get_variables (std::string which_node)
212 LocaleGuard lg (X_("POSIX"));
214 node = new XMLNode(which_node);
216 #undef UI_CONFIG_VARIABLE
217 #undef CANVAS_VARIABLE
218 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
219 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
220 #define CANVAS_STRING_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
221 #include "ui_config_vars.h"
222 #include "canvas_vars.h"
223 #undef UI_CONFIG_VARIABLE
224 #undef CANVAS_VARIABLE
225 #undef CANVAS_STRING_VARIABLE
231 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
233 if (root.name() != "Ardour") {
237 Stateful::save_extra_xml (root);
239 XMLNodeList nlist = root.children();
240 XMLNodeConstIterator niter;
243 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
247 if (node->name() == "Canvas" || node->name() == "UI") {
248 set_variables (*node);
257 UIConfiguration::set_variables (const XMLNode& node)
259 #undef UI_CONFIG_VARIABLE
260 #undef CANVAS_VARIABLE
261 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
262 if (var.set_from_node (node)) { \
263 ParameterChanged (name); \
265 #define CANVAS_VARIABLE(var,name) \
266 if (var.set_from_node (node)) { \
267 ParameterChanged (name); \
269 #define CANVAS_STRING_VARIABLE(var,name) \
270 if (var.set_from_node (node)) { \
271 ParameterChanged (name); \
273 #include "ui_config_vars.h"
274 #include "canvas_vars.h"
275 #undef UI_CONFIG_VARIABLE
276 #undef CANVAS_VARIABLE
277 #undef CANVAS_STRING_VARIABLE
281 UIConfiguration::pack_canvasvars ()
283 #undef CANVAS_VARIABLE
284 #define CANVAS_VARIABLE(var,name) canvas_colors.insert (std::pair<std::string,ColorVariable<uint32_t>* >(name,&var));
285 #define CANVAS_STRING_VARIABLE(var,name)
286 #include "canvas_vars.h"
287 #undef CANVAS_VARIABLE
288 #undef CANVAS_STRING_VARIABLE
292 UIConfiguration::color_by_name (const std::string& name)
294 map<std::string,ColorVariable<uint32_t>* >::iterator i = canvas_colors.find (name);
296 if (i != canvas_colors.end()) {
297 return i->second->get();
300 // cerr << string_compose (_("Color %1 not found"), name) << endl;
301 return RGBA_TO_UINT (g_random_int()%256,g_random_int()%256,g_random_int()%256,0xff);
305 UIConfiguration::set_dirty ()
311 UIConfiguration::dirty () const