~keithsalisbury/mixxx/advanced_autodj

« back to all changes in this revision

Viewing changes to mixxx/src/controllers/controllerengine.h

  • Committer: RJ Ryan
  • Date: 2012-05-26 23:19:28 UTC
  • mfrom: (2840.3.47 mixxx-script)
  • Revision ID: rryan@mit.edu-20120526231928-ke63jqts6m0k5xsb
Merging lp:~mixxxdevelopers/mixxx/features_direct_bind into lp:mixxx.

* Changed use of ControlObject to ControlObjectThread to prevent priority inversion with the engine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
// Forward declaration(s)
21
21
class Controller;
22
22
class ControlObjectThread;
 
23
class ControllerEngine;
 
24
 
 
25
// ControllerEngineConnection class for closure-compatible engine.connectControl
 
26
class ControllerEngineConnection {
 
27
  public:
 
28
    ConfigKey key;
 
29
    QString id;
 
30
    QScriptValue function;
 
31
    ControllerEngine *ce;
 
32
    QScriptValue context;
 
33
};
 
34
 
 
35
class ControllerEngineConnectionScriptValue : public QObject {
 
36
    Q_OBJECT
 
37
    Q_PROPERTY(QString id READ readId)
 
38
    // We cannot expose ConfigKey directly since it's not a
 
39
    // QObject
 
40
    //Q_PROPERTY(ConfigKey key READ key)
 
41
    // There's little use in exposing the function...
 
42
    //Q_PROPERTY(QScriptValue function READ function)
 
43
  public:
 
44
    ControllerEngineConnectionScriptValue(ControllerEngineConnection conn) {
 
45
        this->conn = conn;
 
46
    }
 
47
    QString readId() const { return this->conn.id; }
 
48
    Q_INVOKABLE void disconnect();
 
49
    
 
50
  private:
 
51
   ControllerEngineConnection conn;
 
52
};
 
53
 
 
54
/* comparison function for ControllerEngineConnection */
 
55
inline bool operator==(const ControllerEngineConnection &c1, const ControllerEngineConnection &c2) {
 
56
    return c1.id == c2.id && c1.key.group == c2.key.group && c1.key.item == c2.key.item;
 
57
}
23
58
 
24
59
class ControllerEngine : public QObject {
25
60
    Q_OBJECT
39
74
        m_bPopups = bPopups;
40
75
    }
41
76
 
42
 
    // Look up registered script functions
43
 
    QStringList getScriptFunctions();
44
 
 
45
 
    // Look up registered script function prefixes
 
77
    /** Resolve a function name to a QScriptValue. */
 
78
    QScriptValue resolveFunction(QString function) const;
 
79
    /** Look up registered script function prefixes */
46
80
    QList<QString>& getScriptFunctionPrefixes() { return m_scriptFunctionPrefixes; };
 
81
    /** Disconnect a ControllerEngineConnection */
 
82
    void disconnectControl(const ControllerEngineConnection conn);
47
83
 
48
84
  protected:
49
85
    Q_INVOKABLE double getValue(QString group, QString name);
50
86
    Q_INVOKABLE void setValue(QString group, QString name, double newValue);
51
 
    Q_INVOKABLE bool connectControl(QString group, QString name,
52
 
                                    QString function, bool disconnect = false);
 
87
    Q_INVOKABLE QScriptValue connectControl(QString group, QString name,
 
88
                                    QScriptValue function, bool disconnect = false);
 
89
    // Called indirectly by the objects returned by connectControl
53
90
    Q_INVOKABLE void trigger(QString group, QString name);
54
91
    Q_INVOKABLE void log(QString message);
55
 
    Q_INVOKABLE int beginTimer(int interval, QString scriptCode, bool oneShot = false);
 
92
    Q_INVOKABLE int beginTimer(int interval, QScriptValue scriptCode, bool oneShot = false);
56
93
    Q_INVOKABLE void stopTimer(int timerId);
57
94
    Q_INVOKABLE void scratchEnable(int deck, int intervalsPerRev, float rpm,
58
95
                                   float alpha, float beta, bool ramp = true);
69
106
    void slotValueChanged(double value);
70
107
    // Evaluate a script file
71
108
    bool evaluate(QString filepath);
 
109
 
72
110
    // Execute a particular function
73
111
    bool execute(QString function);
74
112
    // Execute a particular function with a list of arguments
75
113
    bool execute(QString function, QScriptValueList args);
 
114
    bool execute(QScriptValue function, QScriptValueList args);
76
115
    // Execute a particular function with a data string (e.g. a device ID)
77
116
    bool execute(QString function, QString data);
 
117
    // Execute a particular function with a list of arguments
 
118
    bool execute(QString function, const QByteArray data);
 
119
    bool execute(QScriptValue function, const QByteArray data);
78
120
    // Execute a particular function with a data buffer
79
 
    bool execute(QString function, const QByteArray data);
 
121
    //TODO: redo this one
 
122
    //bool execute(QString function, const QByteArray data);
80
123
    void loadScriptFiles(QString configPath,
81
124
                         QList<QString> scriptFileNames);
82
125
    void initializeScripts(const QList<QString> scriptFunctionPrefixes);
92
135
  private:
93
136
    bool evaluate(QString scriptName, QList<QString> scriptPaths);
94
137
    bool internalExecute(QString scriptCode);
 
138
    bool internalExecute(QScriptValue thisObject, QString scriptCode);
 
139
    bool internalExecute(QScriptValue thisObject, QScriptValue functionObject);
95
140
    void initializeScriptEngine();
96
141
 
97
142
    void scriptErrorDialog(QString detailedError);
98
143
    void generateScriptFunctions(QString code);
99
144
    void stopAllTimers();
100
145
 
 
146
    void callFunctionOnObjects(QList<QString>, QString, QScriptValueList args = QScriptValueList());
101
147
    bool checkException();
102
148
    QScriptEngine *m_pEngine;
103
149
 
109
155
    Controller* m_pController;
110
156
    bool m_bDebug;
111
157
    bool m_bPopups;
112
 
    QMultiHash<ConfigKey, QString> m_connectedControls;
113
 
    QStringList m_scriptFunctions;
 
158
    QMultiHash<ConfigKey, ControllerEngineConnection> m_connectedControls;
114
159
    QList<QString> m_scriptFunctionPrefixes;
115
160
    QMap<QString,QStringList> m_scriptErrors;
116
161
    QHash<ConfigKey, ControlObjectThread*> m_controlCache;
117
 
    QHash<int, QPair<QString, bool> > m_timers;
 
162
    struct TimerInfo {
 
163
        QScriptValue callback;
 
164
        QScriptValue context;
 
165
        bool oneShot;
 
166
    };
 
167
    QHash<int, TimerInfo> m_timers;
118
168
    SoftTakeover m_st;
119
169
    ByteArrayClass *m_pBaClass;
120
170
    // 256 (default) available virtual decks is enough I would think.