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::load_defaults ()
67 std::string default_ui_rc_file;
70 if (getenv ("ARDOUR_SAE")) {
71 rcfile = "ardour3_ui_sae.conf";
73 rcfile = "ardour3_ui_default.conf";
76 if (find_file_in_search_path (ardour_config_search_path(), rcfile, default_ui_rc_file) ) {
80 string rcfile = default_ui_rc_file;
82 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
84 if (!tree.read (rcfile.c_str())) {
85 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
89 if (set_state (*tree.root(), Stateful::loading_state_version)) {
90 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
101 UIConfiguration::load_state ()
105 std::string default_ui_rc_file;
107 if ( find_file_in_search_path (ardour_config_search_path(), "ardour3_ui_default.conf", default_ui_rc_file)) {
111 string rcfile = default_ui_rc_file;
113 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
115 if (!tree.read (rcfile.c_str())) {
116 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
120 if (set_state (*tree.root(), Stateful::loading_state_version)) {
121 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
126 std::string user_ui_rc_file;
128 if (find_file_in_search_path (ardour_config_search_path(), "ardour3_ui.conf", user_ui_rc_file)) {
132 string rcfile = user_ui_rc_file;
134 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
136 if (!tree.read (rcfile)) {
137 error << string_compose(_("cannot read ui configuration file \"%1\""), rcfile) << endmsg;
141 if (set_state (*tree.root(), Stateful::loading_state_version)) {
142 error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
150 error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
158 UIConfiguration::save_state()
162 std::string rcfile(user_config_directory());
163 rcfile = Glib::build_filename (rcfile, "ardour3_ui.conf");
165 // this test seems bogus?
166 if (rcfile.length()) {
167 tree.set_root (&get_state());
168 if (!tree.write (rcfile.c_str())){
169 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
180 UIConfiguration::get_state ()
183 LocaleGuard lg (X_("POSIX"));
185 root = new XMLNode("Ardour");
187 root->add_child_nocopy (get_variables ("UI"));
188 root->add_child_nocopy (get_variables ("Canvas"));
191 root->add_child_copy (*_extra_xml);
198 UIConfiguration::get_variables (std::string which_node)
201 LocaleGuard lg (X_("POSIX"));
203 node = new XMLNode(which_node);
205 #undef UI_CONFIG_VARIABLE
206 #undef CANVAS_VARIABLE
207 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
208 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
209 #include "ui_config_vars.h"
210 #include "canvas_vars.h"
211 #undef UI_CONFIG_VARIABLE
212 #undef CANVAS_VARIABLE
218 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
220 if (root.name() != "Ardour") {
224 Stateful::save_extra_xml (root);
226 XMLNodeList nlist = root.children();
227 XMLNodeConstIterator niter;
230 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
234 if (node->name() == "Canvas" || node->name() == "UI") {
235 set_variables (*node);
244 UIConfiguration::set_variables (const XMLNode& node)
246 #undef UI_CONFIG_VARIABLE
247 #undef CANVAS_VARIABLE
248 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
249 if (var.set_from_node (node)) { \
250 ParameterChanged (name); \
252 #define CANVAS_VARIABLE(var,name) \
253 if (var.set_from_node (node)) { \
254 ParameterChanged (name); \
256 #include "ui_config_vars.h"
257 #include "canvas_vars.h"
258 #undef UI_CONFIG_VARIABLE
259 #undef CANVAS_VARIABLE
263 UIConfiguration::pack_canvasvars ()
265 #undef CANVAS_VARIABLE
266 #define CANVAS_VARIABLE(var,name) canvas_colors.insert (std::pair<std::string,UIConfigVariable<uint32_t>* >(name,&var));
267 #include "canvas_vars.h"
268 #undef CANVAS_VARIABLE
272 UIConfiguration::color_by_name (const std::string& name)
274 map<std::string,UIConfigVariable<uint32_t>* >::iterator i = canvas_colors.find (name);
276 if (i != canvas_colors.end()) {
277 return i->second->get();
280 // cerr << string_compose (_("Color %1 not found"), name) << endl;
281 return RGBA_TO_UINT (random()%256,random()%256,random()%256,0xff);
285 UIConfiguration::set_dirty ()
291 UIConfiguration::dirty () const