/[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 2893 by schoenebeck, Fri Apr 29 14:19:53 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        };
43    
44        /**
45         * Extension of regular Glib::Property template class; this one
46         * automatically calls Settings::onPropertyChanged() method passing this
47         * property object as pointer; and it allows to assign new values to this
48         * property by using the regular assignment operator; and requires a
49         * "Setting group" to be assigned to the property at construction time.
50         */
51        template<typename T>
52        class Property : public Glib::Property<T> {
53        public:
54            Property(Settings& object, Group_t group, const Glib::ustring& name)
55                : Glib::Property<T>::Property(object, name)
56            {
57                m_settings = &object;
58                m_group = group;
59                const RawValueType_t type = rawValueType();
60                Glib::Property<T>::get_proxy().signal_changed().connect(
61                    sigc::bind(
62                        sigc::bind(
63                            sigc::bind(
64                                sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
65                                m_group
66                            ),
67                            type
68                        ),
69                        this
70                    )
71                );
72            }
73    
74            Property(Settings& object, Group_t group, const Glib::ustring& name, const T& default_value)
75                : Glib::Property<T>::Property(object, name, default_value)
76            {
77                m_settings = &object;
78                m_group = group;
79                const RawValueType_t type = rawValueType();
80                Glib::Property<T>::get_proxy().signal_changed().connect(
81                    sigc::bind(
82                        sigc::bind(
83                            sigc::bind(
84                                sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
85                                m_group
86                            ),
87                            type
88                        ),
89                        this
90                    )
91                );
92            }
93    
94            Property<T>& operator=(const T value) {
95                Glib::Property<T>::set_value(value);
96                return *this;
97            }
98    
99            RawValueType_t rawValueType() const {
100                const std::string name = typeid(T).name();
101                if (name == "bool" || name == "b") return BOOLEAN;
102                if (name == "int" || name == "i") return INTEGER;
103                return UNKNOWN;
104            }
105    
106            Group_t group() const { return m_group; }
107    
108        private:
109            Settings* m_settings;
110            Group_t m_group;
111        };
112    
113        // settings of "Global" group
114        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
115        Property<bool> syncSamplerInstrumentSelection; ///< if enabled, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit
116        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
117    
118        // settings of "MainWindow" group
119        Property<int> mainWindowX;
120        Property<int> mainWindowY;
121        Property<int> mainWindowW;
122        Property<int> mainWindowH;
123    
124        // settings of "ScriptEditor" group
125        Property<int> scriptEditorWindowX;
126        Property<int> scriptEditorWindowY;
127        Property<int> scriptEditorWindowW;
128        Property<int> scriptEditorWindowH;
129    
130      static Settings* singleton();      static Settings* singleton();
131      Settings();      Settings();
132        void load();
133    
134    protected:
135        void onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group);
136    
137    private:
138        std::vector<Glib::PropertyBase*> m_boolProps; ///< Pointers to all 'bool' type properties this Setting class manages.
139        std::vector<Glib::PropertyBase*> m_intProps; ///< Pointers to all 'int' type properties this Setting class manages.
140        bool m_ignoreNotifies;
141  };  };
142    
143  #endif // GIGEDIT_SETTINGS  #endif // GIGEDIT_SETTINGS

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

  ViewVC Help
Powered by ViewVC