~mixxxdevelopers/mixxx/engine-control-refactor

« back to all changes in this revision

Viewing changes to mixxx/src/control/control.h

  • Committer: RJ Ryan
  • Date: 2013-06-04 00:41:29 UTC
  • mfrom: (2890.22.101 mixxx)
  • Revision ID: rryan@mixxx.org-20130604004129-8jjxkicsb3givu4a
MergingĀ fromĀ lp:mixxx.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef CONTROL_H
 
2
#define CONTROL_H
 
3
 
 
4
#include <QHash>
 
5
#include <QMutex>
 
6
#include <QString>
 
7
#include <QObject>
 
8
#include <QAtomicPointer>
 
9
 
 
10
#include "control/controlbehavior.h"
 
11
#include "control/controlvalue.h"
 
12
#include "configobject.h"
 
13
 
 
14
class ControlDoublePrivate : public QObject {
 
15
    Q_OBJECT
 
16
  public:
 
17
    ControlDoublePrivate();
 
18
    ControlDoublePrivate(ConfigKey key, bool bIgnoreNops, bool bTrack);
 
19
    virtual ~ControlDoublePrivate();
 
20
 
 
21
    // Gets the ControlDoublePrivate matching the given ConfigKey. If bCreate
 
22
    // is true, allocates a new ControlDoublePrivate for the ConfigKey if one
 
23
    // does not exist.
 
24
    static ControlDoublePrivate* getControl(
 
25
        const ConfigKey& key,
 
26
        bool bCreate, bool bIgnoreNops=true, bool bTrack=false);
 
27
    static inline ControlDoublePrivate* getControl(
 
28
        const QString& group, const QString& item,
 
29
        bool bCreate, bool bIgnoreNops=true, bool bTrack=false) {
 
30
        ConfigKey key(group, item);
 
31
        return getControl(key, bCreate, bIgnoreNops, bTrack);
 
32
    }
 
33
 
 
34
    // Sets the control value.
 
35
    void set(const double& value, QObject* pSetter);
 
36
    // Gets the control value.
 
37
    double get() const;
 
38
    // Resets the control value to its default.
 
39
    void reset(QObject* pSetter);
 
40
 
 
41
    // Set the behavior to be used when setting values and translating between
 
42
    // parameter and value space. Returns the previously set behavior (if any).
 
43
    // Caller must handle appropriate destruction of the previous behavior or
 
44
    // memory will leak.
 
45
    ControlNumericBehavior* setBehavior(ControlNumericBehavior* pBehavior);
 
46
 
 
47
    void setWidgetParameter(double dParam, QObject* pSetter);
 
48
    double getWidgetParameter() const;
 
49
 
 
50
    void setMidiParameter(MidiOpCode opcode, double dParam);
 
51
    double getMidiParameter() const;
 
52
 
 
53
    inline bool ignoreNops() const {
 
54
        return m_bIgnoreNops;
 
55
    }
 
56
 
 
57
    inline void setDefaultValue(double dValue) {
 
58
        m_defaultValue.setValue(dValue);
 
59
    }
 
60
    inline double defaultValue() const {
 
61
        double default_value = m_defaultValue.getValue();
 
62
        return m_pBehavior ? m_pBehavior->defaultValue(default_value) : default_value;
 
63
    }
 
64
 
 
65
  signals:
 
66
    // Emitted when the ControlDoublePrivate value changes. pSetter is a
 
67
    // pointer to the setter of the value (potentially NULL).
 
68
    void valueChanged(double value, QObject* pSetter);
 
69
 
 
70
  private:
 
71
    ConfigKey m_key;
 
72
    // Whether to ignore sets which would have no effect.
 
73
    bool m_bIgnoreNops;
 
74
 
 
75
    // Whether to track value changes with the stats framework.
 
76
    bool m_bTrack;
 
77
    QString m_trackKey;
 
78
    int m_trackType;
 
79
    int m_trackFlags;
 
80
 
 
81
    // The control value.
 
82
    ControlValueAtomic<double> m_value;
 
83
    // The default control value.
 
84
    ControlValueAtomic<double> m_defaultValue;
 
85
 
 
86
    QAtomicPointer<ControlNumericBehavior> m_pBehavior;
 
87
 
 
88
    // Hash of ControlDoublePrivate instantiations.
 
89
    static QHash<ConfigKey,ControlDoublePrivate*> m_sqCOHash;
 
90
    // Mutex guarding access to the ControlDoublePrivate hash.
 
91
    static QMutex m_sqCOHashMutex;
 
92
};
 
93
 
 
94
 
 
95
#endif /* CONTROL_H */