/[svn]/gigedit/trunk/src/gigedit/Settings.h
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/Settings.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3151 - (show annotations) (download) (as text)
Fri May 5 18:44:59 2017 UTC (2 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6964 byte(s)
* WIP: Added initial draft implementation of macro editor
  (accessible for copied clipboard content via Alt+x).
* Bumped version (1.0.0.svn35).

1 /*
2 Copyright (c) 2014-2017 Christian Schoenebeck
3
4 This file is part of "gigedit" and released under the terms of the
5 GNU General Public License version 2.
6 */
7
8 #ifndef GIGEDIT_SETTINGS
9 #define GIGEDIT_SETTINGS
10
11 #include <typeinfo>
12 #include <glibmm/object.h>
13 #include <glibmm/property.h>
14 #include <vector>
15
16 /**
17 * Reflects, saves and restores all settings for the gigedit application.
18 *
19 * This class holds a bunch of custom Property objects which can be accessed
20 * as if they were basic data types (i.e. by using assignment operator, etc.).
21 * As soon as a property gets modified this way, it will automatically be saved
22 * to a local config file.
23 */
24 class Settings : public Glib::Object {
25 public:
26 /**
27 * Data types for the individual settings.
28 */
29 enum RawValueType_t {
30 BOOLEAN,
31 INTEGER,
32 UNKNOWN
33 };
34
35 /**
36 * All settings are grouped into these settings groups.
37 */
38 enum Group_t {
39 GLOBAL,
40 MAIN_WINDOW,
41 SCRIPT_EDITOR,
42 DIMENSION_MANAGER,
43 SCRIPT_SLOTS,
44 COMBINE_INSTRUMENTS,
45 MIDI_RULES,
46 FILE_PROPS,
47 INSTR_PROPS,
48 SAMPLE_REFS,
49 MACRO_EDITOR,
50 };
51
52 /**
53 * Extension of regular Glib::Property template class; this one
54 * automatically calls Settings::onPropertyChanged() method passing this
55 * property object as pointer; and it allows to assign new values to this
56 * property by using the regular assignment operator; and requires a
57 * "Setting group" to be assigned to the property at construction time.
58 */
59 template<typename T>
60 class Property : public Glib::Property<T> {
61 public:
62 Property(Settings& object, Group_t group, const Glib::ustring& name)
63 : Glib::Property<T>::Property(object, name)
64 {
65 m_settings = &object;
66 m_group = group;
67 const RawValueType_t type = rawValueType();
68 Glib::Property<T>::get_proxy().signal_changed().connect(
69 sigc::bind(
70 sigc::bind(
71 sigc::bind(
72 sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
73 m_group
74 ),
75 type
76 ),
77 this
78 )
79 );
80 }
81
82 Property(Settings& object, Group_t group, const Glib::ustring& name, const T& default_value)
83 : Glib::Property<T>::Property(object, name, default_value)
84 {
85 m_settings = &object;
86 m_group = group;
87 const RawValueType_t type = rawValueType();
88 Glib::Property<T>::get_proxy().signal_changed().connect(
89 sigc::bind(
90 sigc::bind(
91 sigc::bind(
92 sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
93 m_group
94 ),
95 type
96 ),
97 this
98 )
99 );
100 }
101
102 Property<T>& operator=(const T value) {
103 Glib::Property<T>::set_value(value);
104 return *this;
105 }
106
107 RawValueType_t rawValueType() const {
108 const std::string name = typeid(T).name();
109 if (name == "bool" || name == "b") return BOOLEAN;
110 if (name == "int" || name == "i") return INTEGER;
111 return UNKNOWN;
112 }
113
114 Group_t group() const { return m_group; }
115
116 private:
117 Settings* m_settings;
118 Group_t m_group;
119 };
120
121 // settings of "Global" group
122 Property<bool> warnUserOnExtensions; ///< if enabled, the user shall he be warned if he is trying to use a gig format extension that will not work with Gigasampler/GigaStudio
123 Property<bool> syncSamplerInstrumentSelection; ///< if enabled, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit
124 Property<bool> moveRootNoteWithRegionMoved; ///< if enabled, the root note(s) of regions are automatically moving when the user drags a region around at the virtual keyboard
125 Property<bool> autoRestoreWindowDimension;
126 Property<bool> saveWithTemporaryFile; ///< If enabled and the user selects "Save" from the main menu, then the file is first saved as separate temporary file and after the save operation completed the temporary file is moved over the original file.
127
128 // settings of "MainWindow" group
129 Property<int> mainWindowX;
130 Property<int> mainWindowY;
131 Property<int> mainWindowW;
132 Property<int> mainWindowH;
133
134 // settings of "ScriptEditor" group
135 Property<int> scriptEditorWindowX;
136 Property<int> scriptEditorWindowY;
137 Property<int> scriptEditorWindowW;
138 Property<int> scriptEditorWindowH;
139 Property<int> scriptEditorFontSize;
140
141 // settings of "DimensionManager" group
142 Property<int> dimensionManagerWindowX;
143 Property<int> dimensionManagerWindowY;
144 Property<int> dimensionManagerWindowW;
145 Property<int> dimensionManagerWindowH;
146
147 // settings of "ScriptSlots" group
148 Property<int> scriptSlotsWindowX;
149 Property<int> scriptSlotsWindowY;
150 Property<int> scriptSlotsWindowW;
151 Property<int> scriptSlotsWindowH;
152
153 // settings of "CombineInstruments" group
154 Property<int> combineInstrumentsWindowX;
155 Property<int> combineInstrumentsWindowY;
156 Property<int> combineInstrumentsWindowW;
157 Property<int> combineInstrumentsWindowH;
158
159 // settings of "MidiRules" group
160 Property<int> midiRulesWindowX;
161 Property<int> midiRulesWindowY;
162 Property<int> midiRulesWindowW;
163 Property<int> midiRulesWindowH;
164
165 // settings of "FileProps" group
166 Property<int> filePropsWindowX;
167 Property<int> filePropsWindowY;
168 Property<int> filePropsWindowW;
169 Property<int> filePropsWindowH;
170
171 // settings of "InstrProps" group
172 Property<int> instrPropsWindowX;
173 Property<int> instrPropsWindowY;
174 Property<int> instrPropsWindowW;
175 Property<int> instrPropsWindowH;
176
177 // settings of "SampleRefs" group
178 Property<int> sampleRefsWindowX;
179 Property<int> sampleRefsWindowY;
180 Property<int> sampleRefsWindowW;
181 Property<int> sampleRefsWindowH;
182
183 // settings of "MacroEditor" group
184 Property<int> macroEditorWindowX;
185 Property<int> macroEditorWindowY;
186 Property<int> macroEditorWindowW;
187 Property<int> macroEditorWindowH;
188
189 static Settings* singleton();
190 Settings();
191 void load();
192
193 protected:
194 void onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group);
195
196 private:
197 std::vector<Glib::PropertyBase*> m_boolProps; ///< Pointers to all 'bool' type properties this Setting class manages.
198 std::vector<Glib::PropertyBase*> m_intProps; ///< Pointers to all 'int' type properties this Setting class manages.
199 bool m_ignoreNotifies;
200 };
201
202 #endif // GIGEDIT_SETTINGS

  ViewVC Help
Powered by ViewVC