/[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 2773 by schoenebeck, Fri Jun 12 17:57:52 2015 UTC revision 2891 by schoenebeck, Tue Apr 26 17:42:26 2016 UTC
# Line 1  Line 1 
1  /*  /*
2      Copyright (c) 2014-2015 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 few settings (right now), but I saw  #include <typeinfo>
12  // originnaly no better place to put this, since warnUserOnExtensions needs to  #include <glibmm/object.h>
13  // be accessed without 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      bool syncSamplerInstrumentSelection; ///< if enabled, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit  /**
17      bool moveRootNoteWithRegionMoved; ///< if enabled, the root note(s) of regions are automatically moving when the user drags a region around at the virtual keyboard   * 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        };
41    
42        /**
43         * Extension of regular Glib::Property template class; this one
44         * automatically calls Settings::onPropertyChanged() method passing this
45         * property object as pointer; and it allows to assign new values to this
46         * property by using the regular assignment operator; and requires a
47         * "Setting group" to be assigned to the property at construction time.
48         */
49        template<typename T>
50        class Property : public Glib::Property<T> {
51        public:
52            Property(Settings& object, Group_t group, const Glib::ustring& name)
53                : Glib::Property<T>::Property(object, name)
54            {
55                m_settings = &object;
56                m_group = group;
57                const RawValueType_t type = rawValueType();
58                Glib::Property<T>::get_proxy().signal_changed().connect(
59                    sigc::bind(
60                        sigc::bind(
61                            sigc::bind(
62                                sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
63                                m_group
64                            ),
65                            type
66                        ),
67                        this
68                    )
69                );
70            }
71    
72            Property(Settings& object, Group_t group, const Glib::ustring& name, const T& default_value)
73                : Glib::Property<T>::Property(object, name, default_value)
74            {
75                m_settings = &object;
76                m_group = group;
77                const RawValueType_t type = rawValueType();
78                Glib::Property<T>::get_proxy().signal_changed().connect(
79                    sigc::bind(
80                        sigc::bind(
81                            sigc::bind(
82                                sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
83                                m_group
84                            ),
85                            type
86                        ),
87                        this
88                    )
89                );
90            }
91    
92            Property<T>& operator=(const T value) {
93                Glib::Property<T>::set_value(value);
94                return *this;
95            }
96    
97            RawValueType_t rawValueType() const {
98                const std::string name = typeid(T).name();
99                if (name == "bool" || name == "b") return BOOLEAN;
100                if (name == "int" || name == "i") return INTEGER;
101                return UNKNOWN;
102            }
103    
104            Group_t group() const { return m_group; }
105    
106        private:
107            Settings* m_settings;
108            Group_t m_group;
109        };
110    
111        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
112        Property<bool> syncSamplerInstrumentSelection; ///< if enabled, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit
113        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
114    
115      static Settings* singleton();      static Settings* singleton();
116      Settings();      Settings();
117        void load();
118    
119    protected:
120        void onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group);
121    
122    private:
123        std::vector<Glib::PropertyBase*> m_boolProps; ///< Pointers to all 'bool' type properties this Setting class manages.
124        std::vector<Glib::PropertyBase*> m_intProps; ///< Pointers to all 'int' type properties this Setting class manages.
125        bool m_ignoreNotifies;
126  };  };
127    
128  #endif // GIGEDIT_SETTINGS  #endif // GIGEDIT_SETTINGS

Legend:
Removed from v.2773  
changed lines
  Added in v.2891

  ViewVC Help
Powered by ViewVC