Add API allowing plugin preset load to affect automation
[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 <boost/function.hpp>
28 #include <boost/bind.hpp>
29
30 #include "ardour/types.h" // required for opeators used in pbd/configuration_variable.h
31
32 #include "pbd/stateful.h"
33 #include "pbd/xml++.h"
34 #include "pbd/configuration_variable.h"
35
36 #include "canvas/colors.h"
37
38 #include "utils.h"
39
40 class UIConfiguration : public PBD::Stateful
41 {
42 private:
43         UIConfiguration();
44         ~UIConfiguration();
45
46     public:
47         static UIConfiguration& instance();
48
49         static std::string color_file_suffix;
50
51         void load_rc_file (bool themechange, bool allow_own = true);
52
53         int load_state ();
54         int save_state ();
55         int load_defaults ();
56         int load_color_theme (bool allow_own);
57
58         int set_state (const XMLNode&, int version);
59         XMLNode& get_state (void);
60         XMLNode& get_variables (std::string);
61         void set_variables (const XMLNode&);
62
63         std::string  color_file_name (bool use_my, bool with_version) const;
64
65         typedef std::map<std::string,ArdourCanvas::Color> Colors;
66         typedef std::map<std::string,std::string> ColorAliases;
67         typedef std::map<std::string,ArdourCanvas::SVAModifier> Modifiers;
68
69         Colors         colors;
70         ColorAliases   color_aliases;
71         Modifiers      modifiers;
72
73         void set_alias (std::string const & name, std::string const & alias);
74         void set_color (const std::string& name, ArdourCanvas::Color);
75         void set_modifier (std::string const &, ArdourCanvas::SVAModifier svam);
76
77         std::string color_as_alias (ArdourCanvas::Color c);
78         ArdourCanvas::Color quantized (ArdourCanvas::Color) const;
79
80         ArdourCanvas::Color color (const std::string&, bool* failed = 0) const;
81         ArdourCanvas::Color color_mod (std::string const & color, std::string const & modifier) const;
82         ArdourCanvas::Color color_mod (const ArdourCanvas::Color& color, std::string const & modifier) const;
83         ArdourCanvas::HSV  color_hsv (const std::string&) const;
84         ArdourCanvas::SVAModifier modifier (const std::string&) const;
85
86         sigc::signal<void>  ColorsChanged;
87
88         void reset_dpi ();
89
90         float get_ui_scale ();
91
92         sigc::signal<void>  DPIReset;
93
94         sigc::signal<void,std::string> ParameterChanged;
95         void map_parameters (boost::function<void (std::string)>&);
96
97         void parameter_changed (std::string);
98
99         /** called before initializing any part of the GUI. Sets up
100          *  any runtime environment required to make the GUI work
101          *  in specific ways.
102          */
103         int pre_gui_init ();
104
105         /** called after the GUI toolkit has been initialized.
106          */
107         UIConfiguration* post_gui_init ();
108
109 #undef UI_CONFIG_VARIABLE
110 #define UI_CONFIG_VARIABLE(Type,var,name,value) \
111         Type get_##var () const { return var.get(); } \
112         bool set_##var (Type val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret;  }
113 #include "ui_config_vars.h"
114 #undef  UI_CONFIG_VARIABLE
115 #define CANVAS_FONT_VARIABLE(var,name) \
116         Pango::FontDescription get_##var () const { return ARDOUR_UI_UTILS::sanitized_font (var.get()); } \
117         bool set_##var (const std::string& val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret;  }
118 #include "canvas_vars.h"
119 #undef CANVAS_FONT_VARIABLE
120
121   private:
122         /* declare variables */
123
124 #undef  UI_CONFIG_VARIABLE
125 #define UI_CONFIG_VARIABLE(Type,var,name,value) PBD::ConfigVariable<Type> var;
126 #include "ui_config_vars.h"
127 #undef UI_CONFIG_VARIABLE
128
129 #define CANVAS_FONT_VARIABLE(var,name) PBD::ConfigVariable<std::string> var;
130 #include "canvas_vars.h"
131 #undef CANVAS_FONT_VARIABLE
132
133         XMLNode& state ();
134         bool _dirty;
135         bool aliases_modified;
136         bool colors_modified;
137         bool modifiers_modified;
138
139         int  store_color_theme ();
140         void load_color_aliases (XMLNode const &);
141         void load_colors (XMLNode const &);
142         void load_modifiers (XMLNode const &);
143         void reset_gtk_theme ();
144         int  load_color_file (std::string const &);
145         void colors_changed ();
146
147         uint32_t block_save;
148 };
149
150 #endif /* __ardour_ui_configuration_h__ */