forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose Controller and ControllerEngine scripting apis through a proxy
Since QJSEngine takes ownership of exposed QObjects it tried to delete controller and controllerengine when QJSEngine was destroyed (i.e script reload and mixxx shutdown). See https://bugreports.qt.io/browse/QTBUG-41171 This also has the benefit that we have a tighter control on what's exposed. Since, Signals and slots, properties and children of object are available as properties of the created QJSValue, lots of undesired things were leaked into the JS engine.
- Loading branch information
1 parent
9be45f3
commit a0339e3
Showing
6 changed files
with
230 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#include "controllerenginejsproxy.h" | ||
#include "controllers/engine/controllerengine.h" | ||
|
||
ControllerEngineJSProxy::ControllerEngineJSProxy(ControllerEngine* m_pEngine) | ||
: m_pEngine(m_pEngine) { | ||
|
||
} | ||
|
||
ControllerEngineJSProxy::~ControllerEngineJSProxy() { | ||
|
||
} | ||
|
||
double ControllerEngineJSProxy::getValue(QString group, QString name) { | ||
return m_pEngine->getValue(group, name); | ||
} | ||
|
||
void ControllerEngineJSProxy::setValue(QString group, QString name, | ||
double newValue) { | ||
m_pEngine->setValue(group, name, newValue); | ||
} | ||
|
||
double ControllerEngineJSProxy::getParameter(QString group, QString name) { | ||
return m_pEngine->getParameter(group, name); | ||
} | ||
|
||
void ControllerEngineJSProxy::setParameter(QString group, QString name, | ||
double newValue) { | ||
m_pEngine->setParameter(group, name, newValue); | ||
} | ||
|
||
double ControllerEngineJSProxy::getParameterForValue(QString group, | ||
QString name, double value) { | ||
return m_pEngine->getParameterForValue(group, name, value); | ||
} | ||
|
||
void ControllerEngineJSProxy::reset(QString group, QString name) { | ||
m_pEngine->reset(group, name); | ||
} | ||
|
||
double ControllerEngineJSProxy::getDefaultValue(QString group, QString name) { | ||
return m_pEngine->getDefaultValue(group, name); | ||
} | ||
|
||
double ControllerEngineJSProxy::getDefaultParameter(QString group, | ||
QString name) { | ||
return m_pEngine->getDefaultParameter(group, name); | ||
} | ||
|
||
QJSValue ControllerEngineJSProxy::makeConnection(QString group, QString name, | ||
const QJSValue callback) { | ||
return m_pEngine->makeConnection(group, name, callback); | ||
} | ||
|
||
QJSValue ControllerEngineJSProxy::connectControl(QString group, QString name, | ||
const QJSValue passedCallback, bool disconnect) { | ||
return m_pEngine->connectControl(group, name, passedCallback, disconnect); | ||
} | ||
|
||
void ControllerEngineJSProxy::trigger(QString group, QString name) { | ||
m_pEngine->trigger(group, name); | ||
} | ||
|
||
void ControllerEngineJSProxy::log(QString message) { | ||
m_pEngine->log(message); | ||
} | ||
|
||
int ControllerEngineJSProxy::beginTimer(int interval, QJSValue scriptCode, | ||
bool oneShot) { | ||
return m_pEngine->beginTimer(interval, scriptCode, oneShot); | ||
} | ||
|
||
void ControllerEngineJSProxy::stopTimer(int timerId) { | ||
m_pEngine->stopTimer(timerId); | ||
} | ||
|
||
void ControllerEngineJSProxy::scratchEnable(int deck, int intervalsPerRev, | ||
double rpm, double alpha, double beta, bool ramp) { | ||
m_pEngine->scratchEnable(deck, intervalsPerRev, rpm, alpha, beta, ramp); | ||
} | ||
|
||
void ControllerEngineJSProxy::scratchTick(int deck, int interval) { | ||
m_pEngine->scratchTick(deck, interval); | ||
} | ||
|
||
void ControllerEngineJSProxy::scratchDisable(int deck, bool ramp) { | ||
m_pEngine->scratchDisable(deck, ramp); | ||
} | ||
|
||
bool ControllerEngineJSProxy::isScratching(int deck) { | ||
return m_pEngine->isScratching(deck); | ||
} | ||
|
||
void ControllerEngineJSProxy::softTakeover(QString group, QString name, | ||
bool set) { | ||
m_pEngine->softTakeover(group, name, set); | ||
} | ||
|
||
void ControllerEngineJSProxy::softTakeoverIgnoreNextValue(QString group, | ||
QString name) { | ||
m_pEngine->softTakeoverIgnoreNextValue(group, name); | ||
} | ||
|
||
void ControllerEngineJSProxy::brake(int deck, bool activate, double factor, | ||
double rate) { | ||
m_pEngine->brake(deck, activate, factor, rate); | ||
} | ||
|
||
void ControllerEngineJSProxy::spinback(int deck, bool activate, double factor, | ||
double rate) { | ||
m_pEngine->spinback(deck, activate, factor, rate); | ||
} | ||
|
||
void ControllerEngineJSProxy::softStart(int deck, bool activate, | ||
double factor) { | ||
m_pEngine->softStart(deck, activate, factor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef CONTROLLERENGINEJSPROXY_H | ||
#define CONTROLLERENGINEJSPROXY_H | ||
|
||
#include <QObject> | ||
#include <QJSValue> | ||
|
||
class ControllerEngine; | ||
|
||
// An object of this class gets exposed to the JS engine, so the methods of this class | ||
// constitute the api that is provided to scripts under "engine" object. | ||
// | ||
// The implementation simply forwards its method calls to the ControllerEngine. | ||
// We cannot expose ControllerEngine directly to the JS engine because the JS engine would take | ||
// ownership of ControllerEngine. This is problematic when we reload a script file, because we | ||
// destroy the existing JS engine to create a new one. Then, since the JS engine owns ControllerEngine | ||
// it will try to delete it. See this Qt bug: https://bugreports.qt.io/browse/QTBUG-41171 | ||
class ControllerEngineJSProxy: public QObject { | ||
Q_OBJECT | ||
public: | ||
|
||
ControllerEngineJSProxy(ControllerEngine* m_pEngine); | ||
|
||
virtual ~ControllerEngineJSProxy(); | ||
|
||
Q_INVOKABLE double getValue(QString group, QString name); | ||
Q_INVOKABLE void setValue(QString group, QString name, double newValue); | ||
Q_INVOKABLE double getParameter(QString group, QString name); | ||
Q_INVOKABLE void setParameter(QString group, QString name, double newValue); | ||
Q_INVOKABLE double getParameterForValue(QString group, QString name, double value); | ||
Q_INVOKABLE void reset(QString group, QString name); | ||
Q_INVOKABLE double getDefaultValue(QString group, QString name); | ||
Q_INVOKABLE double getDefaultParameter(QString group, QString name); | ||
Q_INVOKABLE QJSValue makeConnection(QString group, QString name, | ||
const QJSValue callback); | ||
// DEPRECATED: Use makeConnection instead. | ||
Q_INVOKABLE QJSValue connectControl(QString group, QString name, | ||
const QJSValue passedCallback, | ||
bool disconnect = false); | ||
// Called indirectly by the objects returned by connectControl | ||
Q_INVOKABLE void trigger(QString group, QString name); | ||
Q_INVOKABLE void log(QString message); | ||
Q_INVOKABLE int beginTimer(int interval, QJSValue scriptCode, bool oneShot = false); | ||
Q_INVOKABLE void stopTimer(int timerId); | ||
Q_INVOKABLE void scratchEnable(int deck, int intervalsPerRev, double rpm, | ||
double alpha, double beta, bool ramp = true); | ||
Q_INVOKABLE void scratchTick(int deck, int interval); | ||
Q_INVOKABLE void scratchDisable(int deck, bool ramp = true); | ||
Q_INVOKABLE bool isScratching(int deck); | ||
Q_INVOKABLE void softTakeover(QString group, QString name, bool set); | ||
Q_INVOKABLE void softTakeoverIgnoreNextValue(QString group, QString name); | ||
Q_INVOKABLE void brake(int deck, bool activate, double factor=1.0, double rate=1.0); | ||
Q_INVOKABLE void spinback(int deck, bool activate, double factor=1.8, double rate=-10.0); | ||
Q_INVOKABLE void softStart(int deck, bool activate, double factor=1.0); | ||
|
||
private: | ||
ControllerEngine* m_pEngine; | ||
}; | ||
|
||
#endif // CONTROLLERENGINEJSPROXY_H |