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/filesystem.h"
29 #include "pbd/file_utils.h"
30 #include "pbd/error.h"
32 #include "gtkmm2ext/rgb_macros.h"
34 #include "ardour/filesystem_paths.h"
36 #include "ui_config.h"
42 using namespace ARDOUR;
44 UIConfiguration::UIConfiguration ()
46 #undef UI_CONFIG_VARIABLE
47 #undef CANVAS_VARIABLE
48 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
49 #define CANVAS_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
59 UIConfiguration::~UIConfiguration ()
64 UIConfiguration::load_defaults ()
68 std::string default_ui_rc_file;
71 if (getenv ("ARDOUR_SAE")) {
72 rcfile = "ardour3_ui_sae.conf";
74 rcfile = "ardour3_ui_default.conf";
77 if (find_file_in_search_path (ardour_config_search_path(), rcfile, default_ui_rc_file) ) {
81 string rcfile = default_ui_rc_file;
83 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
85 if (!tree.read (rcfile.c_str())) {
86 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
90 if (set_state (*tree.root(), Stateful::loading_state_version)) {
91 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
102 UIConfiguration::load_state ()
106 std::string default_ui_rc_file;
108 if ( find_file_in_search_path (ardour_config_search_path(), "ardour3_ui_default.conf", default_ui_rc_file)) {
112 string rcfile = default_ui_rc_file;
114 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
116 if (!tree.read (rcfile.c_str())) {
117 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
121 if (set_state (*tree.root(), Stateful::loading_state_version)) {
122 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
127 std::string user_ui_rc_file;
129 if (find_file_in_search_path (ardour_config_search_path(), "ardour3_ui.conf", user_ui_rc_file)) {
133 string rcfile = user_ui_rc_file;
135 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
137 if (!tree.read (rcfile)) {
138 error << string_compose(_("cannot read ui configuration file \"%1\""), rcfile) << endmsg;
142 if (set_state (*tree.root(), Stateful::loading_state_version)) {
143 error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
151 error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
159 UIConfiguration::save_state()
163 sys::path rcfile_path(user_config_directory());
165 rcfile_path /= "ardour3_ui.conf";
166 const string rcfile = rcfile_path.to_string();
168 // this test seems bogus?
169 if (rcfile.length()) {
170 tree.set_root (&get_state());
171 if (!tree.write (rcfile.c_str())){
172 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
183 UIConfiguration::get_state ()
186 LocaleGuard lg (X_("POSIX"));
188 root = new XMLNode("Ardour");
190 root->add_child_nocopy (get_variables ("UI"));
191 root->add_child_nocopy (get_variables ("Canvas"));
194 root->add_child_copy (*_extra_xml);
201 UIConfiguration::get_variables (std::string which_node)
204 LocaleGuard lg (X_("POSIX"));
206 node = new XMLNode(which_node);
208 #undef UI_CONFIG_VARIABLE
209 #undef CANVAS_VARIABLE
210 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
211 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
212 #include "ui_config_vars.h"
213 #include "canvas_vars.h"
214 #undef UI_CONFIG_VARIABLE
215 #undef CANVAS_VARIABLE
221 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
223 if (root.name() != "Ardour") {
227 Stateful::save_extra_xml (root);
229 XMLNodeList nlist = root.children();
230 XMLNodeConstIterator niter;
233 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
237 if (node->name() == "Canvas" || node->name() == "UI") {
238 set_variables (*node);
247 UIConfiguration::set_variables (const XMLNode& node)
249 #undef UI_CONFIG_VARIABLE
250 #undef CANVAS_VARIABLE
251 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
252 if (var.set_from_node (node)) { \
253 ParameterChanged (name); \
255 #define CANVAS_VARIABLE(var,name) \
256 if (var.set_from_node (node)) { \
257 ParameterChanged (name); \
259 #include "ui_config_vars.h"
260 #include "canvas_vars.h"
261 #undef UI_CONFIG_VARIABLE
262 #undef CANVAS_VARIABLE
266 UIConfiguration::pack_canvasvars ()
268 #undef CANVAS_VARIABLE
269 #define CANVAS_VARIABLE(var,name) canvas_colors.insert (std::pair<std::string,UIConfigVariable<uint32_t>* >(name,&var));
270 #include "canvas_vars.h"
271 #undef CANVAS_VARIABLE
275 UIConfiguration::color_by_name (const std::string& name)
277 map<std::string,UIConfigVariable<uint32_t>* >::iterator i = canvas_colors.find (name);
279 if (i != canvas_colors.end()) {
280 return i->second->get();
283 // cerr << string_compose (_("Color %1 not found"), name) << endl;
284 return RGBA_TO_UINT (random()%256,random()%256,random()%256,0xff);
288 UIConfiguration::set_dirty ()
294 UIConfiguration::dirty () const