diff --git a/src/controllers/controllerengine.cpp b/src/controllers/controllerengine.cpp index a44878b113e1..eab1d6ecafff 100644 --- a/src/controllers/controllerengine.cpp +++ b/src/controllers/controllerengine.cpp @@ -22,12 +22,22 @@ // (closure compatible version of connectControl) #include -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) @@ -86,12 +96,16 @@ void ControllerEngine::callFunctionOnObjects(QList 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 + 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); @@ -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; } @@ -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; } @@ -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); } @@ -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); } @@ -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; @@ -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;