Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions src/controllers/controllerengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@
// (closure compatible version of connectControl)
#include <QUuid>

const int kDecks = 16;
namespace {
constexpr int kDecks = 16;

// Use 1ms for the Alpha-Beta dt. We're assuming the OS actually gives us a 1ms
// timer.
const int kScratchTimerMs = 1;
const double kAlphaBetaDt = kScratchTimerMs / 1000.0;
constexpr int kScratchTimerMs = 1;
constexpr double kAlphaBetaDt = kScratchTimerMs / 1000.0;

inline ControlFlags onlyAssertOnControllerDebug() {
if (ControllerDebug::enabled()) {
return ControlFlag::None;
}

return ControlFlag::AllowMissingOrInvalid;
}
} // namespace

ControllerEngine::ControllerEngine(
Controller* controller, UserSettingsPointer pConfig)
Expand Down Expand Up @@ -86,12 +96,16 @@ void ControllerEngine::callFunctionOnObjects(QList<QString> scriptFunctionPrefix
QScriptValue prefix = global.property(prefixName);
if (!prefix.isValid() || !prefix.isObject()) {
qWarning() << "ControllerEngine: No" << prefixName << "object in script";
// Throw a debug assertion if controllerDebug is enabled
Comment thread
uklotzde marked this conversation as resolved.
DEBUG_ASSERT(!ControllerDebug::enabled());
continue;
}

QScriptValue init = prefix.property(function);
if (!init.isValid() || !init.isFunction()) {
qWarning() << "ControllerEngine:" << prefixName << "has no" << function << " method";
// Throw a debug assertion if controllerDebug is enabled
DEBUG_ASSERT(!ControllerDebug::enabled());
continue;
}
controllerDebug("ControllerEngine: Executing" << prefixName << "." << function);
Expand Down Expand Up @@ -443,22 +457,28 @@ bool ControllerEngine::internalExecute(QScriptValue thisObject,
}

if (functionObject.isError()) {
qDebug() << "ControllerEngine::internalExecute:"
<< functionObject.toString();
qWarning() << "ControllerEngine::internalExecute:"
<< functionObject.toString();
// Throw a debug assertion if controllerDebug is enabled
DEBUG_ASSERT(!ControllerDebug::enabled());
return false;
}

// If it's not a function, we're done.
if (!functionObject.isFunction()) {
qDebug() << "ControllerEngine::internalExecute:"
<< functionObject.toVariant() << "Not a function";
qWarning() << "ControllerEngine::internalExecute:"
<< functionObject.toVariant() << "Not a function";
// Throw a debug assertion if controllerDebug is enabled
DEBUG_ASSERT(!ControllerDebug::enabled());
return false;
}

// If it does happen to be a function, call it.
QScriptValue rc = functionObject.call(thisObject, args);
if (!rc.isValid()) {
qDebug() << "QScriptValue is not a function or ...";
qWarning() << "QScriptValue is not a function or ...";
// Throw a debug assertion if controllerDebug is enabled
DEBUG_ASSERT(!ControllerDebug::enabled());
return false;
}

Expand Down Expand Up @@ -636,6 +656,8 @@ ControlObjectScript* ControllerEngine::getControlObjectScript(const QString& gro

if (!key.isValid()) {
qWarning() << "ControllerEngine: Requested control with invalid key" << key;
// Throw a debug assertion if controllerDebug is enabled
DEBUG_ASSERT(!ControllerDebug::enabled());
return nullptr;
}

Expand Down Expand Up @@ -683,7 +705,7 @@ void ControllerEngine::setValue(QString group, QString name, double newValue) {

if (coScript) {
ControlObject* pControl = ControlObject::getControl(
coScript->getKey(), ControlFlag::AllowMissingOrInvalid);
coScript->getKey(), onlyAssertOnControllerDebug());
if (pControl && !m_st.ignore(pControl, coScript->getParameterForValue(newValue))) {
coScript->slotSet(newValue);
}
Expand Down Expand Up @@ -720,7 +742,7 @@ void ControllerEngine::setParameter(QString group, QString name, double newParam

if (coScript) {
ControlObject* pControl = ControlObject::getControl(
coScript->getKey(), ControlFlag::AllowMissingOrInvalid);
coScript->getKey(), onlyAssertOnControllerDebug());
if (pControl && !m_st.ignore(pControl, newParameter)) {
coScript->setParameter(newParameter);
}
Expand Down Expand Up @@ -1448,7 +1470,7 @@ bool ControllerEngine::isScratching(int deck) {
-------- ------------------------------------------------------ */
void ControllerEngine::softTakeover(QString group, QString name, bool set) {
ConfigKey key = ConfigKey(group, name);
ControlObject* pControl = ControlObject::getControl(key, ControlFlag::AllowMissingOrInvalid);
ControlObject* pControl = ControlObject::getControl(key, onlyAssertOnControllerDebug());
if (!pControl) {
qWarning() << "Failed to" << (set ? "enable" : "disable")
<< "softTakeover for invalid control" << key;
Expand All @@ -1473,7 +1495,7 @@ void ControllerEngine::softTakeover(QString group, QString name, bool set) {
void ControllerEngine::softTakeoverIgnoreNextValue(
QString group, const QString name) {
ConfigKey key = ConfigKey(group, name);
ControlObject* pControl = ControlObject::getControl(key, ControlFlag::AllowMissingOrInvalid);
ControlObject* pControl = ControlObject::getControl(key, onlyAssertOnControllerDebug());
if (!pControl) {
qWarning() << "Failed to call softTakeoverIgnoreNextValue for invalid control" << key;
return;
Expand Down