/[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 2894 - (hide annotations) (download) (as text)
Sat Apr 30 14:42:14 2016 UTC (7 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6410 byte(s)
* Enabled auto save & restore of window size & position of all
  remaining windows.
* Bumped version (1.0.0.svn7).

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

  ViewVC Help
Powered by ViewVC