/[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 2967 - (show annotations) (download) (as text)
Mon Jul 18 11:22:38 2016 UTC (2 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6750 byte(s)
* Added option to main menu for performing "Save" operation with a
  tempoary file (may perform faster than directly modifying existing
  .gig file).
* Bumped version (2.0.0.svn19).

1 /*
2 Copyright (c) 2014-2016 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 };
50
51 /**
52 * Extension of regular Glib::Property template class; this one
53 * automatically calls Settings::onPropertyChanged() method passing this
54 * property object as pointer; and it allows to assign new values to this
55 * property by using the regular assignment operator; and requires a
56 * "Setting group" to be assigned to the property at construction time.
57 */
58 template<typename T>
59 class Property : public Glib::Property<T> {
60 public:
61 Property(Settings& object, Group_t group, const Glib::ustring& name)
62 : Glib::Property<T>::Property(object, name)
63 {
64 m_settings = &object;
65 m_group = group;
66 const RawValueType_t type = rawValueType();
67 Glib::Property<T>::get_proxy().signal_changed().connect(
68 sigc::bind(
69 sigc::bind(
70 sigc::bind(
71 sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
72 m_group
73 ),
74 type
75 ),
76 this
77 )
78 );
79 }
80
81 Property(Settings& object, Group_t group, const Glib::ustring& name, const T& default_value)
82 : Glib::Property<T>::Property(object, name, default_value)
83 {
84 m_settings = &object;
85 m_group = group;
86 const RawValueType_t type = rawValueType();
87 Glib::Property<T>::get_proxy().signal_changed().connect(
88 sigc::bind(
89 sigc::bind(
90 sigc::bind(
91 sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
92 m_group
93 ),
94 type
95 ),
96 this
97 )
98 );
99 }
100
101 Property<T>& operator=(const T value) {
102 Glib::Property<T>::set_value(value);
103 return *this;
104 }
105
106 RawValueType_t rawValueType() const {
107 const std::string name = typeid(T).name();
108 if (name == "bool" || name == "b") return BOOLEAN;
109 if (name == "int" || name == "i") return INTEGER;
110 return UNKNOWN;
111 }
112
113 Group_t group() const { return m_group; }
114
115 private:
116 Settings* m_settings;
117 Group_t m_group;
118 };
119
120 // settings of "Global" group
121 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
122 Property<bool> syncSamplerInstrumentSelection; ///< if enabled, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit
123 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
124 Property<bool> autoRestoreWindowDimension;
125 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.
126
127 // settings of "MainWindow" group
128 Property<int> mainWindowX;
129 Property<int> mainWindowY;
130 Property<int> mainWindowW;
131 Property<int> mainWindowH;
132
133 // settings of "ScriptEditor" group
134 Property<int> scriptEditorWindowX;
135 Property<int> scriptEditorWindowY;
136 Property<int> scriptEditorWindowW;
137 Property<int> scriptEditorWindowH;
138 Property<int> scriptEditorFontSize;
139
140 // settings of "DimensionManager" group
141 Property<int> dimensionManagerWindowX;
142 Property<int> dimensionManagerWindowY;
143 Property<int> dimensionManagerWindowW;
144 Property<int> dimensionManagerWindowH;
145
146 // settings of "ScriptSlots" group
147 Property<int> scriptSlotsWindowX;
148 Property<int> scriptSlotsWindowY;
149 Property<int> scriptSlotsWindowW;
150 Property<int> scriptSlotsWindowH;
151
152 // settings of "CombineInstruments" group
153 Property<int> combineInstrumentsWindowX;
154 Property<int> combineInstrumentsWindowY;
155 Property<int> combineInstrumentsWindowW;
156 Property<int> combineInstrumentsWindowH;
157
158 // settings of "MidiRules" group
159 Property<int> midiRulesWindowX;
160 Property<int> midiRulesWindowY;
161 Property<int> midiRulesWindowW;
162 Property<int> midiRulesWindowH;
163
164 // settings of "FileProps" group
165 Property<int> filePropsWindowX;
166 Property<int> filePropsWindowY;
167 Property<int> filePropsWindowW;
168 Property<int> filePropsWindowH;
169
170 // settings of "InstrProps" group
171 Property<int> instrPropsWindowX;
172 Property<int> instrPropsWindowY;
173 Property<int> instrPropsWindowW;
174 Property<int> instrPropsWindowH;
175
176 // settings of "SampleRefs" group
177 Property<int> sampleRefsWindowX;
178 Property<int> sampleRefsWindowY;
179 Property<int> sampleRefsWindowW;
180 Property<int> sampleRefsWindowH;
181
182 static Settings* singleton();
183 Settings();
184 void load();
185
186 protected:
187 void onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group);
188
189 private:
190 std::vector<Glib::PropertyBase*> m_boolProps; ///< Pointers to all 'bool' type properties this Setting class manages.
191 std::vector<Glib::PropertyBase*> m_intProps; ///< Pointers to all 'int' type properties this Setting class manages.
192 bool m_ignoreNotifies;
193 };
194
195 #endif // GIGEDIT_SETTINGS

  ViewVC Help
Powered by ViewVC