~mixxxdevelopers/mixxx/engine-control-refactor

« back to all changes in this revision

Viewing changes to mixxx/src/controlobjectthread.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:
24
24
#include <qwaitcondition.h>
25
25
#include <QQueue>
26
26
 
 
27
#include "configobject.h"
 
28
 
 
29
class ControlDoublePrivate;
27
30
class ControlObject;
28
31
 
29
 
 
30
 
/**
31
 
  *@author Tue Haste Andersen
32
 
  *
33
 
  * This class is used to store a control value as used by an EngineObject.
34
 
  * ControlEngine is thread safe, and sends a user event to a ControlObject
35
 
  * whenever it's value is changed. setExtern is used for external threads
36
 
  * to set it's value.
37
 
  */
38
 
 
39
 
class ControlObjectThread : public QObject
40
 
{
 
32
class ControlObjectThread : public QObject {
41
33
    Q_OBJECT
42
 
public:
 
34
  public:
43
35
    ControlObjectThread(ControlObject *pControlObject, QObject* pParent=NULL);
44
36
    virtual ~ControlObjectThread();
45
 
    /** Returns the value of the object */
46
 
    double get();
47
 
    /** Setting the value from an external controller. This happen when a ControlObject has
48
 
      * changed and its value is syncronized with this object. Thread safe, non blocking. Returns
49
 
      * true if successful, otherwise false. Thread safe, non blocking. */
50
 
    virtual bool setExtern(double v);
51
 
    /** Adds a value to the value property of the ControlEngine. Notification in a similar way
52
 
     * to set. Thread safe, blocking. */
53
 
    void add(double v);
54
 
    /** Subtracts a value to the value property. Notification in a similar way
55
 
     * to set. Thread safe, blocking. */
56
 
    void sub(double v);
57
 
    /** Updates the object with changes from the corresponding ControlObject, and emits
58
 
     * valueChagned signal. Returns true if this it was updated*/
59
 
    static bool update();
 
37
 
60
38
    /** Called from update(); */
61
39
    void emitValueChanged();
62
40
 
63
 
 
64
 
    // FIXME: Dangerous GED hack
65
 
    ControlObject* getControlObject();
66
 
 
67
 
public slots:
68
 
    /** The value is changed by the engine, and the corresponding ControlObject is updated.
69
 
      * Thread safe, blocking. */
70
 
    void slotSet(double v);
71
 
 
72
 
    // The danger signal! This is for safety in wierd shutdown scenarios where the
73
 
    // ControlObject dies to avoid segfaults.
74
 
    void slotParentDead();
75
 
 
76
 
signals:
 
41
    inline ConfigKey getKey() const {
 
42
        return m_key;
 
43
    }
 
44
 
 
45
    // Returns the value of the object. Thread safe, non-blocking.
 
46
    virtual double get();
 
47
 
 
48
    bool valid() const;
 
49
 
 
50
  public slots:
 
51
    // Set the control to a new value. Non-blocking.
 
52
    virtual void slotSet(double v);
 
53
    // Sets the control value to v. Thread safe, non-blocking.
 
54
    virtual void set(double v);
 
55
    // Resets the control to its default value. Thread safe, non-blocking.
 
56
    virtual void reset();
 
57
 
 
58
  signals:
77
59
    void valueChanged(double);
78
 
 
79
 
protected:
80
 
    /** The actual value of the object */
81
 
    double m_dValue;
82
 
    /** Mutex controlling access to static members*/
83
 
    static QMutex m_sqMutex;
84
 
    /** Mutex controlling access to non-static members*/
85
 
    QMutex m_dataMutex;
86
 
    /** Pointer to corresponding ControlObject */
87
 
    ControlObject *m_pControlObject;
88
 
 
89
 
private:
90
 
    /** Update corresponding ControlObject */
91
 
    virtual void updateControlObject();
92
 
 
93
 
    /** Wait condition, used to wait for changes */
94
 
    static QWaitCondition m_sqWait;
95
 
    /** Queue used to keep changes */
96
 
    static QQueue<ControlObjectThread*> m_sqQueue;
 
60
    // This means that the control value has changed as a result of a mutation
 
61
    // (set/add/sub/reset) originating from this object.
 
62
    void valueChangedByThis(double);
 
63
 
 
64
  protected slots:
 
65
    // Receives the value from the master control and re-emits either
 
66
    // valueChanged(double) or valueChangedByThis(double) based on pSetter.
 
67
    virtual void slotValueChanged(double v, QObject* pSetter);
 
68
 
 
69
  protected:
 
70
    ConfigKey m_key;
 
71
    // Pointer to connected control.
 
72
    ControlDoublePrivate* m_pControl;
97
73
};
98
74
 
99
75
#endif