/[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 2956 - (hide annotations) (download) (as text)
Sat Jul 16 15:31:47 2016 UTC (7 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6497 byte(s)
* Script Editor: Added "Font Size ..." to editor's menu.
* Bumped version (1.0.0.svn18).

1 schoenebeck 2541 /*
2 schoenebeck 2891 Copyright (c) 2014-2016 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 2773
16 schoenebeck 2891 /**
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 schoenebeck 2893 GLOBAL,
40     MAIN_WINDOW,
41     SCRIPT_EDITOR,
42 schoenebeck 2894 DIMENSION_MANAGER,
43     SCRIPT_SLOTS,
44     COMBINE_INSTRUMENTS,
45     MIDI_RULES,
46     FILE_PROPS,
47     INSTR_PROPS,
48     SAMPLE_REFS,
49 schoenebeck 2891 };
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 schoenebeck 2893 // settings of "Global" group
121 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
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 schoenebeck 2918 Property<bool> autoRestoreWindowDimension;
125 schoenebeck 2891
126 schoenebeck 2893 // settings of "MainWindow" group
127     Property<int> mainWindowX;
128     Property<int> mainWindowY;
129     Property<int> mainWindowW;
130     Property<int> mainWindowH;
131    
132     // settings of "ScriptEditor" group
133     Property<int> scriptEditorWindowX;
134     Property<int> scriptEditorWindowY;
135     Property<int> scriptEditorWindowW;
136     Property<int> scriptEditorWindowH;
137 schoenebeck 2956 Property<int> scriptEditorFontSize;
138 schoenebeck 2893
139 schoenebeck 2894 // settings of "DimensionManager" group
140     Property<int> dimensionManagerWindowX;
141     Property<int> dimensionManagerWindowY;
142     Property<int> dimensionManagerWindowW;
143     Property<int> dimensionManagerWindowH;
144    
145     // settings of "ScriptSlots" group
146     Property<int> scriptSlotsWindowX;
147     Property<int> scriptSlotsWindowY;
148     Property<int> scriptSlotsWindowW;
149     Property<int> scriptSlotsWindowH;
150    
151     // settings of "CombineInstruments" group
152     Property<int> combineInstrumentsWindowX;
153     Property<int> combineInstrumentsWindowY;
154     Property<int> combineInstrumentsWindowW;
155     Property<int> combineInstrumentsWindowH;
156    
157     // settings of "MidiRules" group
158     Property<int> midiRulesWindowX;
159     Property<int> midiRulesWindowY;
160     Property<int> midiRulesWindowW;
161     Property<int> midiRulesWindowH;
162    
163     // settings of "FileProps" group
164     Property<int> filePropsWindowX;
165     Property<int> filePropsWindowY;
166     Property<int> filePropsWindowW;
167     Property<int> filePropsWindowH;
168    
169     // settings of "InstrProps" group
170     Property<int> instrPropsWindowX;
171     Property<int> instrPropsWindowY;
172     Property<int> instrPropsWindowW;
173     Property<int> instrPropsWindowH;
174    
175     // settings of "SampleRefs" group
176     Property<int> sampleRefsWindowX;
177     Property<int> sampleRefsWindowY;
178     Property<int> sampleRefsWindowW;
179     Property<int> sampleRefsWindowH;
180    
181 schoenebeck 2541 static Settings* singleton();
182     Settings();
183 schoenebeck 2891 void load();
184    
185     protected:
186     void onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group);
187    
188     private:
189     std::vector<Glib::PropertyBase*> m_boolProps; ///< Pointers to all 'bool' type properties this Setting class manages.
190     std::vector<Glib::PropertyBase*> m_intProps; ///< Pointers to all 'int' type properties this Setting class manages.
191     bool m_ignoreNotifies;
192 schoenebeck 2541 };
193    
194     #endif // GIGEDIT_SETTINGS

  ViewVC Help
Powered by ViewVC