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/ardour.h"
35 #include "ardour/filesystem_paths.h"
37 #include "ui_config.h"
43 using namespace ARDOUR;
45 UIConfiguration::UIConfiguration ()
47 #undef UI_CONFIG_VARIABLE
48 #undef CANVAS_VARIABLE
49 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
50 #define CANVAS_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
60 UIConfiguration::~UIConfiguration ()
65 UIConfiguration::load_defaults ()
69 sys::path default_ui_rc_file;
72 if (getenv ("ARDOUR_SAE")) {
73 rcfile = "ardour3_ui_sae.conf";
75 rcfile = "ardour3_ui_default.conf";
78 if (find_file_in_search_path (ardour_config_search_path(), rcfile, default_ui_rc_file) ) {
82 string rcfile = default_ui_rc_file.to_string();
84 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
86 if (!tree.read (rcfile.c_str())) {
87 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
91 if (set_state (*tree.root(), Stateful::loading_state_version)) {
92 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
103 UIConfiguration::load_state ()
107 sys::path default_ui_rc_file;
109 if ( find_file_in_search_path (ardour_config_search_path(), "ardour3_ui_default.conf", default_ui_rc_file)) {
113 string rcfile = default_ui_rc_file.to_string();
115 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
117 if (!tree.read (rcfile.c_str())) {
118 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
122 if (set_state (*tree.root(), Stateful::loading_state_version)) {
123 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
128 sys::path user_ui_rc_file;
130 if (find_file_in_search_path (ardour_config_search_path(), "ardour3_ui.conf", user_ui_rc_file)) {
134 string rcfile = user_ui_rc_file.to_string();
136 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
138 if (!tree.read (rcfile)) {
139 error << string_compose(_("cannot read ui configuration file \"%1\""), rcfile) << endmsg;
143 if (set_state (*tree.root(), Stateful::loading_state_version)) {
144 error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
152 error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
160 UIConfiguration::save_state()
165 sys::create_directories (user_config_directory ());
167 catch (const sys::filesystem_error& ex) {
168 error << "Could not create user configuration directory" << endmsg;
172 sys::path rcfile_path(user_config_directory());
174 rcfile_path /= "ardour3_ui.conf";
175 const string rcfile = rcfile_path.to_string();
177 // this test seems bogus?
178 if (rcfile.length()) {
179 tree.set_root (&get_state());
180 if (!tree.write (rcfile.c_str())){
181 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
192 UIConfiguration::get_state ()
195 LocaleGuard lg (X_("POSIX"));
197 root = new XMLNode("Ardour");
199 root->add_child_nocopy (get_variables ("UI"));
200 root->add_child_nocopy (get_variables ("Canvas"));
203 root->add_child_copy (*_extra_xml);
210 UIConfiguration::get_variables (std::string which_node)
213 LocaleGuard lg (X_("POSIX"));
215 node = new XMLNode(which_node);
217 #undef UI_CONFIG_VARIABLE
218 #undef CANVAS_VARIABLE
219 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
220 #define CANVAS_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
230 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
232 if (root.name() != "Ardour") {
236 Stateful::save_extra_xml (root);
238 XMLNodeList nlist = root.children();
239 XMLNodeConstIterator niter;
242 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
246 if (node->name() == "Canvas" || node->name() == "UI") {
247 set_variables (*node);
256 UIConfiguration::set_variables (const XMLNode& node)
258 #undef UI_CONFIG_VARIABLE
259 #undef CANVAS_VARIABLE
260 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
261 if (var.set_from_node (node)) { \
262 ParameterChanged (name); \
264 #define CANVAS_VARIABLE(var,name) \
265 if (var.set_from_node (node)) { \
266 ParameterChanged (name); \
268 #include "ui_config_vars.h"
269 #include "canvas_vars.h"
270 #undef UI_CONFIG_VARIABLE
271 #undef CANVAS_VARIABLE
275 UIConfiguration::pack_canvasvars ()
277 #undef CANVAS_VARIABLE
278 #define CANVAS_VARIABLE(var,name) canvas_colors.insert (std::pair<std::string,UIConfigVariable<uint32_t>* >(name,&var));
279 #include "canvas_vars.h"
280 #undef CANVAS_VARIABLE
284 UIConfiguration::color_by_name (const std::string& name)
286 map<std::string,UIConfigVariable<uint32_t>* >::iterator i = canvas_colors.find (name);
288 if (i != canvas_colors.end()) {
289 return i->second->get();
292 // cerr << string_compose (_("Color %1 not found"), name) << endl;
293 return RGBA_TO_UINT (random()%256,random()%256,random()%256,0xff);
297 UIConfiguration::set_dirty ()
303 UIConfiguration::dirty () const