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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2541 by schoenebeck, Wed Apr 23 16:49:05 2014 UTC revision 2918 by schoenebeck, Wed May 18 10:10:25 2016 UTC
# Line 1  Line 1 
1  /*  /*
2      Copyright (c) 2014 Christian Schoenebeck      Copyright (c) 2014-2016 Christian Schoenebeck
3            
4      This file is part of "gigedit" and released under the terms of the      This file is part of "gigedit" and released under the terms of the
5      GNU General Public License version 2.      GNU General Public License version 2.
# Line 8  Line 8 
8  #ifndef GIGEDIT_SETTINGS  #ifndef GIGEDIT_SETTINGS
9  #define GIGEDIT_SETTINGS  #define GIGEDIT_SETTINGS
10    
11  // Probably a bit overkill for only one setting (right now), but I saw no better  #include <typeinfo>
12  // place to put this, since warnUserOnExtensions needs to be accessed without  #include <glibmm/object.h>
13  // a MainWindow instance.  #include <glibmm/property.h>
14  struct Settings {  #include <vector>
15      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  
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    
126        // 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    
138        // settings of "DimensionManager" group
139        Property<int> dimensionManagerWindowX;
140        Property<int> dimensionManagerWindowY;
141        Property<int> dimensionManagerWindowW;
142        Property<int> dimensionManagerWindowH;
143    
144        // settings of "ScriptSlots" group
145        Property<int> scriptSlotsWindowX;
146        Property<int> scriptSlotsWindowY;
147        Property<int> scriptSlotsWindowW;
148        Property<int> scriptSlotsWindowH;
149    
150        // settings of "CombineInstruments" group
151        Property<int> combineInstrumentsWindowX;
152        Property<int> combineInstrumentsWindowY;
153        Property<int> combineInstrumentsWindowW;
154        Property<int> combineInstrumentsWindowH;
155    
156        // settings of "MidiRules" group
157        Property<int> midiRulesWindowX;
158        Property<int> midiRulesWindowY;
159        Property<int> midiRulesWindowW;
160        Property<int> midiRulesWindowH;
161    
162        // settings of "FileProps" group
163        Property<int> filePropsWindowX;
164        Property<int> filePropsWindowY;
165        Property<int> filePropsWindowW;
166        Property<int> filePropsWindowH;
167    
168        // settings of "InstrProps" group
169        Property<int> instrPropsWindowX;
170        Property<int> instrPropsWindowY;
171        Property<int> instrPropsWindowW;
172        Property<int> instrPropsWindowH;
173    
174        // settings of "SampleRefs" group
175        Property<int> sampleRefsWindowX;
176        Property<int> sampleRefsWindowY;
177        Property<int> sampleRefsWindowW;
178        Property<int> sampleRefsWindowH;
179    
180      static Settings* singleton();      static Settings* singleton();
181      Settings();      Settings();
182        void load();
183    
184    protected:
185        void onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group);
186    
187    private:
188        std::vector<Glib::PropertyBase*> m_boolProps; ///< Pointers to all 'bool' type properties this Setting class manages.
189        std::vector<Glib::PropertyBase*> m_intProps; ///< Pointers to all 'int' type properties this Setting class manages.
190        bool m_ignoreNotifies;
191  };  };
192    
193  #endif // GIGEDIT_SETTINGS  #endif // GIGEDIT_SETTINGS

Legend:
Removed from v.2541  
changed lines
  Added in v.2918

  ViewVC Help
Powered by ViewVC