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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3409 - (hide annotations) (download) (as text)
Tue Jan 23 16:30:56 2018 UTC (6 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7504 byte(s)
* Added new main menu item "View" -> "Tooltips for Beginners" which allows
  to disable tooltips intended for newbies only (default: on).
* Bumped version (1.1.0.svn3).

1 schoenebeck 2541 /*
2 schoenebeck 3409 Copyright (c) 2014-2018 Christian Schoenebeck
3 schoenebeck 2541
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 schoenebeck 2891 #include <typeinfo>
12     #include <glibmm/object.h>
13     #include <glibmm/property.h>
14     #include <vector>
15 schoenebeck 3157 #include "global.h"
16 schoenebeck 2773
17 schoenebeck 2891 /**
18     * Reflects, saves and restores all settings for the gigedit application.
19     *
20     * This class holds a bunch of custom Property objects which can be accessed
21     * as if they were basic data types (i.e. by using assignment operator, etc.).
22     * As soon as a property gets modified this way, it will automatically be saved
23     * to a local config file.
24     */
25     class Settings : public Glib::Object {
26     public:
27     /**
28     * Data types for the individual settings.
29     */
30     enum RawValueType_t {
31     BOOLEAN,
32     INTEGER,
33     UNKNOWN
34     };
35    
36     /**
37     * All settings are grouped into these settings groups.
38     */
39     enum Group_t {
40 schoenebeck 2893 GLOBAL,
41     MAIN_WINDOW,
42     SCRIPT_EDITOR,
43 schoenebeck 2894 DIMENSION_MANAGER,
44     SCRIPT_SLOTS,
45     COMBINE_INSTRUMENTS,
46     MIDI_RULES,
47     FILE_PROPS,
48     INSTR_PROPS,
49     SAMPLE_REFS,
50 schoenebeck 3151 MACRO_EDITOR,
51 schoenebeck 3157 MACROS_SETUP,
52     MACROS,
53 schoenebeck 2891 };
54    
55     /**
56     * Extension of regular Glib::Property template class; this one
57     * automatically calls Settings::onPropertyChanged() method passing this
58     * property object as pointer; and it allows to assign new values to this
59     * property by using the regular assignment operator; and requires a
60     * "Setting group" to be assigned to the property at construction time.
61     */
62     template<typename T>
63     class Property : public Glib::Property<T> {
64     public:
65     Property(Settings& object, Group_t group, const Glib::ustring& name)
66     : Glib::Property<T>::Property(object, name)
67     {
68     m_settings = &object;
69     m_group = group;
70     const RawValueType_t type = rawValueType();
71     Glib::Property<T>::get_proxy().signal_changed().connect(
72     sigc::bind(
73     sigc::bind(
74     sigc::bind(
75     sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
76     m_group
77     ),
78     type
79     ),
80     this
81     )
82     );
83     }
84    
85     Property(Settings& object, Group_t group, const Glib::ustring& name, const T& default_value)
86     : Glib::Property<T>::Property(object, name, default_value)
87     {
88     m_settings = &object;
89     m_group = group;
90     const RawValueType_t type = rawValueType();
91     Glib::Property<T>::get_proxy().signal_changed().connect(
92     sigc::bind(
93     sigc::bind(
94     sigc::bind(
95     sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
96     m_group
97     ),
98     type
99     ),
100     this
101     )
102     );
103     }
104    
105     Property<T>& operator=(const T value) {
106     Glib::Property<T>::set_value(value);
107     return *this;
108     }
109    
110     RawValueType_t rawValueType() const {
111     const std::string name = typeid(T).name();
112     if (name == "bool" || name == "b") return BOOLEAN;
113     if (name == "int" || name == "i") return INTEGER;
114     return UNKNOWN;
115     }
116    
117     Group_t group() const { return m_group; }
118    
119     private:
120     Settings* m_settings;
121     Group_t m_group;
122     };
123    
124 schoenebeck 2893 // settings of "Global" group
125 schoenebeck 2891 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
126     Property<bool> syncSamplerInstrumentSelection; ///< if enabled, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit
127     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
128 schoenebeck 2918 Property<bool> autoRestoreWindowDimension;
129 schoenebeck 2967 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.
130 schoenebeck 3409 Property<bool> showTooltips; ///< Whether tooltips specifically intended for newbies should be displayed throughout the application (default: yes).
131 schoenebeck 2891
132 schoenebeck 2893 // settings of "MainWindow" group
133     Property<int> mainWindowX;
134     Property<int> mainWindowY;
135     Property<int> mainWindowW;
136     Property<int> mainWindowH;
137    
138     // settings of "ScriptEditor" group
139     Property<int> scriptEditorWindowX;
140     Property<int> scriptEditorWindowY;
141     Property<int> scriptEditorWindowW;
142     Property<int> scriptEditorWindowH;
143 schoenebeck 2956 Property<int> scriptEditorFontSize;
144 schoenebeck 2893
145 schoenebeck 2894 // settings of "DimensionManager" group
146     Property<int> dimensionManagerWindowX;
147     Property<int> dimensionManagerWindowY;
148     Property<int> dimensionManagerWindowW;
149     Property<int> dimensionManagerWindowH;
150    
151     // settings of "ScriptSlots" group
152     Property<int> scriptSlotsWindowX;
153     Property<int> scriptSlotsWindowY;
154     Property<int> scriptSlotsWindowW;
155     Property<int> scriptSlotsWindowH;
156    
157     // settings of "CombineInstruments" group
158     Property<int> combineInstrumentsWindowX;
159     Property<int> combineInstrumentsWindowY;
160     Property<int> combineInstrumentsWindowW;
161     Property<int> combineInstrumentsWindowH;
162    
163     // settings of "MidiRules" group
164     Property<int> midiRulesWindowX;
165     Property<int> midiRulesWindowY;
166     Property<int> midiRulesWindowW;
167     Property<int> midiRulesWindowH;
168    
169     // settings of "FileProps" group
170     Property<int> filePropsWindowX;
171     Property<int> filePropsWindowY;
172     Property<int> filePropsWindowW;
173     Property<int> filePropsWindowH;
174    
175     // settings of "InstrProps" group
176     Property<int> instrPropsWindowX;
177     Property<int> instrPropsWindowY;
178     Property<int> instrPropsWindowW;
179     Property<int> instrPropsWindowH;
180    
181     // settings of "SampleRefs" group
182     Property<int> sampleRefsWindowX;
183     Property<int> sampleRefsWindowY;
184     Property<int> sampleRefsWindowW;
185     Property<int> sampleRefsWindowH;
186    
187 schoenebeck 3151 // settings of "MacroEditor" group
188     Property<int> macroEditorWindowX;
189     Property<int> macroEditorWindowY;
190     Property<int> macroEditorWindowW;
191     Property<int> macroEditorWindowH;
192    
193 schoenebeck 3157 // settings of "MacrosSetup" group
194     Property<int> macrosSetupWindowX;
195     Property<int> macrosSetupWindowY;
196     Property<int> macrosSetupWindowW;
197     Property<int> macrosSetupWindowH;
198    
199 schoenebeck 2541 static Settings* singleton();
200     Settings();
201 schoenebeck 2891 void load();
202 schoenebeck 3157 void loadMacros(std::vector<Serialization::Archive>& macros);
203     void saveMacros(const std::vector<Serialization::Archive>& macros);
204 schoenebeck 2891
205     protected:
206     void onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group);
207    
208     private:
209     std::vector<Glib::PropertyBase*> m_boolProps; ///< Pointers to all 'bool' type properties this Setting class manages.
210     std::vector<Glib::PropertyBase*> m_intProps; ///< Pointers to all 'int' type properties this Setting class manages.
211     bool m_ignoreNotifies;
212 schoenebeck 2541 };
213    
214     #endif // GIGEDIT_SETTINGS

  ViewVC Help
Powered by ViewVC