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_search_path() + system_config_search_path(),
79 rcfile, default_ui_rc_file) ) {
83 string rcfile = default_ui_rc_file.to_string();
85 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
87 if (!tree.read (rcfile.c_str())) {
88 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
92 if (set_state (*tree.root(), Stateful::loading_state_version)) {
93 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
104 UIConfiguration::load_state ()
108 sys::path default_ui_rc_file;
110 if ( find_file_in_search_path (ardour_search_path() + system_config_search_path(),
111 "ardour3_ui_default.conf", default_ui_rc_file) ) {
115 string rcfile = default_ui_rc_file.to_string();
117 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
119 if (!tree.read (rcfile.c_str())) {
120 error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
124 if (set_state (*tree.root(), Stateful::loading_state_version)) {
125 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
130 sys::path user_ui_rc_file;
132 if (find_file_in_search_path (ardour_search_path() + user_config_directory(),
133 "ardour3_ui.conf", user_ui_rc_file)) {
137 string rcfile = user_ui_rc_file.to_string();
139 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
141 if (!tree.read (rcfile)) {
142 error << string_compose(_("cannot read ui configuration file \"%1\""), rcfile) << endmsg;
146 if (set_state (*tree.root(), Stateful::loading_state_version)) {
147 error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
155 error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
163 UIConfiguration::save_state()
168 sys::create_directories (user_config_directory ());
170 catch (const sys::filesystem_error& ex) {
171 error << "Could not create user configuration directory" << endmsg;
175 sys::path rcfile_path(user_config_directory());
177 rcfile_path /= "ardour3_ui.conf";
178 const string rcfile = rcfile_path.to_string();
180 // this test seems bogus?
181 if (rcfile.length()) {
182 tree.set_root (&get_state());
183 if (!tree.write (rcfile.c_str())){
184 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
195 UIConfiguration::get_state ()
198 LocaleGuard lg (X_("POSIX"));
200 root = new XMLNode("Ardour");
202 root->add_child_nocopy (get_variables ("UI"));
203 root->add_child_nocopy (get_variables ("Canvas"));
206 root->add_child_copy (*_extra_xml);
213 UIConfiguration::get_variables (std::string which_node)
216 LocaleGuard lg (X_("POSIX"));
218 node = new XMLNode(which_node);
220 #undef UI_CONFIG_VARIABLE
221 #undef CANVAS_VARIABLE
222 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
223 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
224 #include "ui_config_vars.h"
225 #include "canvas_vars.h"
226 #undef UI_CONFIG_VARIABLE
227 #undef CANVAS_VARIABLE
233 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
235 if (root.name() != "Ardour") {
239 Stateful::save_extra_xml (root);
241 XMLNodeList nlist = root.children();
242 XMLNodeConstIterator niter;
245 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
249 if (node->name() == "Canvas" || node->name() == "UI") {
250 set_variables (*node);
259 UIConfiguration::set_variables (const XMLNode& node)
261 #undef UI_CONFIG_VARIABLE
262 #undef CANVAS_VARIABLE
263 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
264 if (var.set_from_node (node)) { \
265 ParameterChanged (name); \
267 #define CANVAS_VARIABLE(var,name) \
268 if (var.set_from_node (node)) { \
269 ParameterChanged (name); \
271 #include "ui_config_vars.h"
272 #include "canvas_vars.h"
273 #undef UI_CONFIG_VARIABLE
274 #undef CANVAS_VARIABLE
278 UIConfiguration::pack_canvasvars ()
280 #undef CANVAS_VARIABLE
281 #define CANVAS_VARIABLE(var,name) canvas_colors.insert (std::pair<std::string,UIConfigVariable<uint32_t>* >(name,&var));
282 #include "canvas_vars.h"
283 #undef CANVAS_VARIABLE
287 UIConfiguration::color_by_name (const std::string& name)
289 map<std::string,UIConfigVariable<uint32_t>* >::iterator i = canvas_colors.find (name);
291 if (i != canvas_colors.end()) {
292 return i->second->get();
295 cerr << string_compose (_("Color %1 not found"), name) << endl;
296 return RGBA_TO_UINT (random()%256,random()%256,random()%256,0xff);
300 UIConfiguration::set_dirty ()
306 UIConfiguration::dirty () const