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 #include "ui_config_vars.h"
50 #include "canvas_vars.h"
51 #undef UI_CONFIG_VARIABLE
52 #undef CANVAS_VARIABLE
58 UIConfiguration::~UIConfiguration ()
63 UIConfiguration::map_parameters (boost::function<void (std::string)>& functor)
65 #undef UI_CONFIG_VARIABLE
66 #define UI_CONFIG_VARIABLE(Type,var,Name,value) functor (Name);
67 #include "ui_config_vars.h"
68 #undef UI_CONFIG_VARIABLE
72 UIConfiguration::load_defaults ()
76 std::string default_ui_rc_file;
79 if (getenv ("ARDOUR_SAE")) {
80 rcfile = "ardour3_ui_sae.conf";
82 rcfile = "ardour3_ui_default.conf";
85 if (find_file_in_search_path (ardour_config_search_path(), rcfile, default_ui_rc_file) ) {
89 string rcfile = default_ui_rc_file;
91 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
93 if (!tree.read (rcfile.c_str())) {
94 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
98 if (set_state (*tree.root(), Stateful::loading_state_version)) {
99 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
110 UIConfiguration::load_state ()
114 std::string default_ui_rc_file;
116 if ( find_file_in_search_path (ardour_config_search_path(), "ardour3_ui_default.conf", default_ui_rc_file)) {
120 string rcfile = default_ui_rc_file;
122 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
124 if (!tree.read (rcfile.c_str())) {
125 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
129 if (set_state (*tree.root(), Stateful::loading_state_version)) {
130 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
135 std::string user_ui_rc_file;
137 if (find_file_in_search_path (ardour_config_search_path(), "ardour3_ui.conf", user_ui_rc_file)) {
141 string rcfile = user_ui_rc_file;
143 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
145 if (!tree.read (rcfile)) {
146 error << string_compose(_("cannot read ui configuration file \"%1\""), rcfile) << endmsg;
150 if (set_state (*tree.root(), Stateful::loading_state_version)) {
151 error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
159 error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
167 UIConfiguration::save_state()
171 std::string rcfile(user_config_directory());
172 rcfile = Glib::build_filename (rcfile, "ardour3_ui.conf");
174 // this test seems bogus?
175 if (rcfile.length()) {
176 tree.set_root (&get_state());
177 if (!tree.write (rcfile.c_str())){
178 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
189 UIConfiguration::get_state ()
192 LocaleGuard lg (X_("POSIX"));
194 root = new XMLNode("Ardour");
196 root->add_child_nocopy (get_variables ("UI"));
197 root->add_child_nocopy (get_variables ("Canvas"));
200 root->add_child_copy (*_extra_xml);
207 UIConfiguration::get_variables (std::string which_node)
210 LocaleGuard lg (X_("POSIX"));
212 node = new XMLNode(which_node);
214 #undef UI_CONFIG_VARIABLE
215 #undef CANVAS_VARIABLE
216 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
217 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
218 #include "ui_config_vars.h"
219 #include "canvas_vars.h"
220 #undef UI_CONFIG_VARIABLE
221 #undef CANVAS_VARIABLE
227 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
229 if (root.name() != "Ardour") {
233 Stateful::save_extra_xml (root);
235 XMLNodeList nlist = root.children();
236 XMLNodeConstIterator niter;
239 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
243 if (node->name() == "Canvas" || node->name() == "UI") {
244 set_variables (*node);
253 UIConfiguration::set_variables (const XMLNode& node)
255 #undef UI_CONFIG_VARIABLE
256 #undef CANVAS_VARIABLE
257 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
258 if (var.set_from_node (node)) { \
259 ParameterChanged (name); \
261 #define CANVAS_VARIABLE(var,name) \
262 if (var.set_from_node (node)) { \
263 ParameterChanged (name); \
265 #include "ui_config_vars.h"
266 #include "canvas_vars.h"
267 #undef UI_CONFIG_VARIABLE
268 #undef CANVAS_VARIABLE
272 UIConfiguration::pack_canvasvars ()
274 #undef CANVAS_VARIABLE
275 #define CANVAS_VARIABLE(var,name) canvas_colors.insert (std::pair<std::string,UIConfigVariable<uint32_t>* >(name,&var));
276 #include "canvas_vars.h"
277 #undef CANVAS_VARIABLE
281 UIConfiguration::color_by_name (const std::string& name)
283 map<std::string,UIConfigVariable<uint32_t>* >::iterator i = canvas_colors.find (name);
285 if (i != canvas_colors.end()) {
286 return i->second->get();
289 // cerr << string_compose (_("Color %1 not found"), name) << endl;
290 return RGBA_TO_UINT (g_random_int()%256,g_random_int()%256,g_random_int()%256,0xff);
294 UIConfiguration::set_dirty ()
300 UIConfiguration::dirty () const