Merge branch 'windows' into windows+cc
[ardour.git] / gtk2_ardour / ui_config.h
1 /*
2     Copyright (C) 2000-2007 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_ui_configuration_h__
21 #define __ardour_ui_configuration_h__
22
23 #include <sstream>
24 #include <ostream>
25 #include <iostream>
26
27 #include "pbd/stateful.h"
28 #include "pbd/xml++.h"
29 #include "ardour/configuration_variable.h"
30
31 template<class T>
32 class UIConfigVariable : public ARDOUR::ConfigVariableBase
33 {
34   public:
35         UIConfigVariable (std::string str) : ARDOUR::ConfigVariableBase (str) {}
36         UIConfigVariable (std::string str, T val) : ARDOUR::ConfigVariableBase (str), value (val) {}
37
38         bool set (T val) {
39                 if (val == value) {
40                         return false;
41                 }
42                 value = val;
43                 return true;
44         }
45
46         T get() const {
47                 return value;
48         }
49
50         std::string get_as_string () const {
51                 std::stringstream ss;
52                 ss << std::hex;
53                 ss.fill('0');
54                 ss.width(8);
55                 ss << value;
56                 return ss.str ();
57         }
58
59         void set_from_string (std::string const & s) {
60                 std::stringstream ss;
61                 ss << std::hex;
62                 ss << s;
63                 ss >> value;
64         }
65
66   protected:
67         T get_for_save() { return value; }
68         T value;
69 };
70
71 class UIConfiguration : public PBD::Stateful
72 {
73   public:
74         UIConfiguration();
75         ~UIConfiguration();
76
77         std::map<std::string,UIConfigVariable<uint32_t> *> canvas_colors;
78
79         bool dirty () const;
80         void set_dirty ();
81
82         int load_state ();
83         int save_state ();
84         int load_defaults ();
85
86         int set_state (const XMLNode&, int version);
87         XMLNode& get_state (void);
88         XMLNode& get_variables (std::string);
89         void set_variables (const XMLNode&);
90         void pack_canvasvars ();
91
92         uint32_t color_by_name (const std::string&);
93
94         sigc::signal<void,std::string> ParameterChanged;
95         void map_parameters (boost::function<void (std::string)>&);
96
97 #undef UI_CONFIG_VARIABLE
98 #define UI_CONFIG_VARIABLE(Type,var,name,value) \
99         Type get_##var () const { return var.get(); } \
100         bool set_##var (Type val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret;  }
101 #include "ui_config_vars.h"
102 #undef  UI_CONFIG_VARIABLE
103 #undef CANVAS_VARIABLE
104 #define CANVAS_VARIABLE(var,name) \
105         uint32_t get_##var () const { return var.get(); } \
106         bool set_##var (uint32_t val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret;  }
107 #include "canvas_vars.h"
108 #undef  CANVAS_VARIABLE
109
110   private:
111
112         /* declare variables */
113
114 #undef  UI_CONFIG_VARIABLE
115 #define UI_CONFIG_VARIABLE(Type,var,name,value) UIConfigVariable<Type> var;
116 #include "ui_config_vars.h"
117 #undef UI_CONFIG_VARIABLE
118
119 #undef CANVAS_VARIABLE
120 #define CANVAS_VARIABLE(var,name) UIConfigVariable<uint32_t> var;
121 #include "canvas_vars.h"
122 #undef  CANVAS_VARIABLE
123
124         XMLNode& state ();
125         bool _dirty;
126 };
127
128 #endif /* __ardour_ui_configuration_h__ */
129