Skip to content

Commit

Permalink
controllers: fix clazy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Be-ing committed Dec 1, 2020
1 parent 20fbcb0 commit b5cf59d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/controllers/scripting/controllerscriptenginebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void ControllerScriptEngineBase::reload() {
}

bool ControllerScriptEngineBase::executeFunction(
QJSValue functionObject, QJSValueList args) {
QJSValue functionObject, const QJSValueList& args) {
// This function is called from outside the controller engine, so we can't
// use VERIFY_OR_DEBUG_ASSERT here
if (!m_pJSEngine) {
Expand Down Expand Up @@ -104,7 +104,7 @@ bool ControllerScriptEngineBase::executeFunction(
}

void ControllerScriptEngineBase::showScriptExceptionDialog(
QJSValue evaluationResult, bool bFatalError) {
const QJSValue& evaluationResult, bool bFatalError) {
VERIFY_OR_DEBUG_ASSERT(evaluationResult.isError()) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/scripting/controllerscriptenginebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class ControllerScriptEngineBase : public QObject {

virtual bool initialize();

bool executeFunction(QJSValue functionObject, QJSValueList arguments);
bool executeFunction(QJSValue functionObject, const QJSValueList& arguments);

/// Shows a UI dialog notifying of a script evaluation error.
/// Precondition: QJSValue.isError() == true
void showScriptExceptionDialog(QJSValue evaluationResult, bool bFatal = false);
void showScriptExceptionDialog(const QJSValue& evaluationResult, bool bFatal = false);
void throwJSError(const QString& message);

inline void setTesting(bool testing) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/scripting/controllerscriptmoduleengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ControllerScriptModuleEngine : public ControllerScriptEngineBase {

bool initialize() override;

void setModuleFileInfo(QFileInfo moduleFileInfo) {
void setModuleFileInfo(const QFileInfo& moduleFileInfo) {
m_moduleFileInfo = moduleFileInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ ControllerScriptEngineLegacy::~ControllerScriptEngineLegacy() {
shutdown();
}

bool ControllerScriptEngineLegacy::callFunctionOnObjects(QList<QString> scriptFunctionPrefixes,
bool ControllerScriptEngineLegacy::callFunctionOnObjects(
const QList<QString>& scriptFunctionPrefixes,
const QString& function,
QJSValueList args,
const QJSValueList& args,
bool bFatalError) {
VERIFY_OR_DEBUG_ASSERT(m_pJSEngine) {
return false;
Expand Down Expand Up @@ -98,7 +99,7 @@ bool ControllerScriptEngineLegacy::initialize() {
engineGlobalObject.setProperty(
"engine", m_pJSEngine->newQObject(legacyScriptInterface));

for (const ControllerPreset::ScriptFileInfo& script : m_scriptFiles) {
for (const ControllerPreset::ScriptFileInfo& script : std::as_const(m_scriptFiles)) {
if (!evaluateScriptFile(script.file)) {
shutdown();
return false;
Expand Down Expand Up @@ -158,7 +159,7 @@ bool ControllerScriptEngineLegacy::handleIncomingData(const QByteArray& data) {
args << m_pJSEngine->toScriptValue(data);
args << QJSValue(data.size());

for (const QJSValue& function : m_incomingDataFunctions) {
for (const QJSValue& function : std::as_const(m_incomingDataFunctions)) {
ControllerScriptEngineBase::executeFunction(function, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class ControllerScriptEngineLegacy : public ControllerScriptEngineBase {
bool evaluateScriptFile(const QFileInfo& scriptFile);
void shutdown() override;

bool callFunctionOnObjects(QList<QString>,
bool callFunctionOnObjects(const QList<QString>& scriptFunctionPrefixes,
const QString&,
QJSValueList args = QJSValueList(),
const QJSValueList& args = QJSValueList(),
bool bFatalError = false);

QList<QString> m_scriptFunctionPrefixes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ControlObjectScript* ControllerScriptInterfaceLegacy::getControlObjectScript(
return coScript;
}

double ControllerScriptInterfaceLegacy::getValue(QString group, QString name) {
double ControllerScriptInterfaceLegacy::getValue(const QString& group, const QString& name) {
ControlObjectScript* coScript = getControlObjectScript(group, name);
if (coScript == nullptr) {
qWarning() << "Unknown control" << group << name
Expand All @@ -110,7 +110,7 @@ double ControllerScriptInterfaceLegacy::getValue(QString group, QString name) {
}

void ControllerScriptInterfaceLegacy::setValue(
QString group, QString name, double newValue) {
const QString& group, const QString& name, double newValue) {
if (isnan(newValue)) {
qWarning() << "script setting [" << group << ","
<< name << "] to NotANumber, ignoring.";
Expand All @@ -130,7 +130,7 @@ void ControllerScriptInterfaceLegacy::setValue(
}
}

double ControllerScriptInterfaceLegacy::getParameter(QString group, QString name) {
double ControllerScriptInterfaceLegacy::getParameter(const QString& group, const QString& name) {
ControlObjectScript* coScript = getControlObjectScript(group, name);
if (coScript == nullptr) {
qWarning() << "Unknown control" << group << name
Expand All @@ -141,7 +141,7 @@ double ControllerScriptInterfaceLegacy::getParameter(QString group, QString name
}

void ControllerScriptInterfaceLegacy::setParameter(
QString group, QString name, double newParameter) {
const QString& group, const QString& name, double newParameter) {
if (isnan(newParameter)) {
qWarning() << "script setting [" << group << ","
<< name << "] to NotANumber, ignoring.";
Expand All @@ -160,7 +160,7 @@ void ControllerScriptInterfaceLegacy::setParameter(
}

double ControllerScriptInterfaceLegacy::getParameterForValue(
QString group, QString name, double value) {
const QString& group, const QString& name, double value) {
if (isnan(value)) {
qWarning() << "script setting [" << group << ","
<< name << "] to NotANumber, ignoring.";
Expand All @@ -178,14 +178,14 @@ double ControllerScriptInterfaceLegacy::getParameterForValue(
return coScript->getParameterForValue(value);
}

void ControllerScriptInterfaceLegacy::reset(QString group, QString name) {
void ControllerScriptInterfaceLegacy::reset(const QString& group, const QString& name) {
ControlObjectScript* coScript = getControlObjectScript(group, name);
if (coScript != nullptr) {
coScript->reset();
}
}

double ControllerScriptInterfaceLegacy::getDefaultValue(QString group, QString name) {
double ControllerScriptInterfaceLegacy::getDefaultValue(const QString& group, const QString& name) {
ControlObjectScript* coScript = getControlObjectScript(group, name);

if (coScript == nullptr) {
Expand All @@ -198,7 +198,7 @@ double ControllerScriptInterfaceLegacy::getDefaultValue(QString group, QString n
}

double ControllerScriptInterfaceLegacy::getDefaultParameter(
QString group, QString name) {
const QString& group, const QString& name) {
ControlObjectScript* coScript = getControlObjectScript(group, name);

if (coScript == nullptr) {
Expand All @@ -211,7 +211,7 @@ double ControllerScriptInterfaceLegacy::getDefaultParameter(
}

QJSValue ControllerScriptInterfaceLegacy::makeConnection(
QString group, QString name, const QJSValue callback) {
const QString& group, const QString& name, const QJSValue& callback) {
auto pJsEngine = m_pScriptEngineLegacy->jsEngine();
VERIFY_OR_DEBUG_ASSERT(pJsEngine) {
return QJSValue();
Expand Down Expand Up @@ -254,7 +254,7 @@ QJSValue ControllerScriptInterfaceLegacy::makeConnection(
}

bool ControllerScriptInterfaceLegacy::removeScriptConnection(
const ScriptConnection connection) {
const ScriptConnection& connection) {
ControlObjectScript* coScript =
getControlObjectScript(connection.key.group, connection.key.item);

Expand All @@ -266,7 +266,7 @@ bool ControllerScriptInterfaceLegacy::removeScriptConnection(
}

void ControllerScriptInterfaceLegacy::triggerScriptConnection(
const ScriptConnection connection) {
const ScriptConnection& connection) {
VERIFY_OR_DEBUG_ASSERT(m_pScriptEngineLegacy->jsEngine()) {
return;
}
Expand All @@ -288,8 +288,10 @@ void ControllerScriptInterfaceLegacy::triggerScriptConnection(
// it is disconnected.
// WARNING: These behaviors are quirky and confusing, so if you change this function,
// be sure to run the ControllerScriptInterfaceTest suite to make sure you do not break old scripts.
QJSValue ControllerScriptInterfaceLegacy::connectControl(
QString group, QString name, QJSValue passedCallback, bool disconnect) {
QJSValue ControllerScriptInterfaceLegacy::connectControl(const QString& group,
const QString& name,
const QJSValue& passedCallback,
bool disconnect) {
// The passedCallback may or may not actually be a function, so when
// the actual callback function is found, store it in this variable.
QJSValue actualCallbackFunction;
Expand Down Expand Up @@ -404,14 +406,14 @@ QJSValue ControllerScriptInterfaceLegacy::connectControl(
return makeConnection(group, name, actualCallbackFunction);
}

void ControllerScriptInterfaceLegacy::trigger(QString group, QString name) {
void ControllerScriptInterfaceLegacy::trigger(const QString& group, const QString& name) {
ControlObjectScript* coScript = getControlObjectScript(group, name);
if (coScript != nullptr) {
coScript->emitValueChanged();
}
}

void ControllerScriptInterfaceLegacy::log(QString message) {
void ControllerScriptInterfaceLegacy::log(const QString& message) {
controllerDebug(message);
}
int ControllerScriptInterfaceLegacy::beginTimer(
Expand Down Expand Up @@ -494,7 +496,7 @@ void ControllerScriptInterfaceLegacy::timerEvent(QTimerEvent* event) {
}

void ControllerScriptInterfaceLegacy::softTakeover(
QString group, QString name, bool set) {
const QString& group, const QString& name, bool set) {
ControlObject* pControl = ControlObject::getControl(
ConfigKey(group, name), ControllerDebug::shouldAssertForInvalidControlObjects());
if (!pControl) {
Expand All @@ -508,7 +510,7 @@ void ControllerScriptInterfaceLegacy::softTakeover(
}

void ControllerScriptInterfaceLegacy::softTakeoverIgnoreNextValue(
QString group, const QString name) {
const QString& group, const QString& name) {
ControlObject* pControl = ControlObject::getControl(
ConfigKey(group, name), ControllerDebug::shouldAssertForInvalidControlObjects());
if (!pControl) {
Expand Down Expand Up @@ -553,7 +555,7 @@ void ControllerScriptInterfaceLegacy::scratchEnable(int deck,
double beta,
bool ramp) {
// If we're already scratching this deck, override that with this request
if (m_dx[deck]) {
if (static_cast<bool>(m_dx[deck])) {
//qDebug() << "Already scratching deck" << deck << ". Overriding.";
int timerId = m_scratchTimers.key(deck);
killTimer(timerId);
Expand Down Expand Up @@ -603,7 +605,7 @@ void ControllerScriptInterfaceLegacy::scratchEnable(int deck,
}

// Initialize scratch filter
if (alpha && beta) {
if (static_cast<bool>(alpha) && static_cast<bool>(beta)) {
m_scratchFilters[deck]->init(kAlphaBetaDt, initVelocity, alpha, beta);
} else {
// Use filter's defaults if not specified
Expand Down
38 changes: 20 additions & 18 deletions src/controllers/scripting/legacy/controllerscriptinterfacelegacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ class ControllerScriptInterfaceLegacy : public QObject {

virtual ~ControllerScriptInterfaceLegacy();

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);
Q_INVOKABLE double getValue(const QString& group, const QString& name);
Q_INVOKABLE void setValue(const QString& group, const QString& name, double newValue);
Q_INVOKABLE double getParameter(const QString& group, const QString& name);
Q_INVOKABLE void setParameter(const QString& group, const QString& name, double newValue);
Q_INVOKABLE double getParameterForValue(
const QString& group, const QString& name, double value);
Q_INVOKABLE void reset(const QString& group, const QString& name);
Q_INVOKABLE double getDefaultValue(const QString& group, const QString& name);
Q_INVOKABLE double getDefaultParameter(const QString& group, const QString& name);
Q_INVOKABLE QJSValue makeConnection(
const QString& group, const QString& name, const QJSValue& callback);
// DEPRECATED: Use makeConnection instead.
Q_INVOKABLE QJSValue connectControl(QString group,
QString name,
const QJSValue passedCallback,
Q_INVOKABLE QJSValue connectControl(const QString& group,
const 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 void trigger(const QString& group, const QString& name);
Q_INVOKABLE void log(const 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,
Expand All @@ -48,15 +50,15 @@ class ControllerScriptInterfaceLegacy : public QObject {
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 softTakeover(const QString& group, const QString& name, bool set);
Q_INVOKABLE void softTakeoverIgnoreNextValue(const QString& group, const 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);

bool removeScriptConnection(const ScriptConnection conn);
bool removeScriptConnection(const ScriptConnection& conn);
/// Execute a ScriptConnection's JS callback
void triggerScriptConnection(const ScriptConnection conn);
void triggerScriptConnection(const ScriptConnection& conn);

/// Handler for timers that scripts set.
virtual void timerEvent(QTimerEvent* event);
Expand Down

0 comments on commit b5cf59d

Please sign in to comment.