diff options
author | Jan Holthuis <jan.holthuis@ruhr-uni-bochum.de> | 2020-12-02 21:11:43 +0100 |
---|---|---|
committer | Jan Holthuis <jan.holthuis@ruhr-uni-bochum.de> | 2020-12-02 21:11:43 +0100 |
commit | b207bd38e1574cb75315a2c66e7a598c22fc55ca (patch) | |
tree | 05b3a58ac8261e1f43a944018e48c15171032052 /src/controllers | |
parent | 8e18359de7cfc2521045671007ec6115c150dd55 (diff) | |
parent | 532b713e0e570083c8ecd5708942cacb66835838 (diff) |
Merge branch '2.3' of github.com:mixxxdj/mixxx into cleanup-headers
Diffstat (limited to 'src/controllers')
45 files changed, 653 insertions, 415 deletions
diff --git a/src/controllers/bulk/bulkcontroller.cpp b/src/controllers/bulk/bulkcontroller.cpp index b81b61defa..5000e9c626 100644 --- a/src/controllers/bulk/bulkcontroller.cpp +++ b/src/controllers/bulk/bulkcontroller.cpp @@ -80,7 +80,7 @@ BulkController::BulkController(UserSettingsPointer pConfig, setDeviceCategory(tr("USB Controller")); - setDeviceName(QString("%1 %2").arg(product).arg(m_sUID)); + setDeviceName(QString("%1 %2").arg(product, m_sUID)); setInputDevice(true); setOutputDevice(true); @@ -227,7 +227,7 @@ void BulkController::send(QList<int> data, unsigned int length) { send(temp); } -void BulkController::send(QByteArray data) { +void BulkController::send(const QByteArray& data) { int ret; int transferred; diff --git a/src/controllers/bulk/bulkcontroller.h b/src/controllers/bulk/bulkcontroller.h index 3ee2073628..a8d8f242c9 100644 --- a/src/controllers/bulk/bulkcontroller.h +++ b/src/controllers/bulk/bulkcontroller.h @@ -21,7 +21,7 @@ class BulkReader : public QThread { void stop(); signals: - void incomingData(QByteArray data, mixxx::Duration timestamp); + void incomingData(const QByteArray& data, mixxx::Duration timestamp); protected: void run(); @@ -74,7 +74,7 @@ class BulkController : public Controller { private: // For devices which only support a single report, reportID must be set to // 0x0. - void send(QByteArray data) override; + void send(const QByteArray& data) override; // Returns a pointer to the currently loaded controller preset. For internal // use only. diff --git a/src/controllers/colormapper.h b/src/controllers/colormapper.h index 05e2cb9055..10157ed257 100644 --- a/src/controllers/colormapper.h +++ b/src/controllers/colormapper.h @@ -13,7 +13,7 @@ class ColorMapper final { public: ColorMapper() = delete; - explicit ColorMapper(QMap<QRgb, QVariant> availableColors) + explicit ColorMapper(const QMap<QRgb, QVariant>& availableColors) : m_availableColors(availableColors) { DEBUG_ASSERT(!m_availableColors.isEmpty()); } diff --git a/src/controllers/colormapperjsproxy.cpp b/src/controllers/colormapperjsproxy.cpp index c8d7cf1590..3272bd0494 100644 --- a/src/controllers/colormapperjsproxy.cpp +++ b/src/controllers/colormapperjsproxy.cpp @@ -2,7 +2,8 @@ #include "controllers/colormapperjsproxy.h" -ColorMapperJSProxy::ColorMapperJSProxy(QScriptEngine* pScriptEngine, QMap<QRgb, QVariant> availableColors) +ColorMapperJSProxy::ColorMapperJSProxy(QScriptEngine* pScriptEngine, + const QMap<QRgb, QVariant>& availableColors) : m_pScriptEngine(pScriptEngine), m_colorMapper(new ColorMapper(availableColors)) { } diff --git a/src/controllers/colormapperjsproxy.h b/src/controllers/colormapperjsproxy.h index 3a08f062d5..898b5cb033 100644 --- a/src/controllers/colormapperjsproxy.h +++ b/src/controllers/colormapperjsproxy.h @@ -12,7 +12,7 @@ class ColorMapperJSProxy final : public QObject { Q_OBJECT public: ColorMapperJSProxy() = delete; - ColorMapperJSProxy(QScriptEngine* pScriptEngine, QMap<QRgb, QVariant> availableColors); + ColorMapperJSProxy(QScriptEngine* pScriptEngine, const QMap<QRgb, QVariant>& availableColors); ~ColorMapperJSProxy() override { delete m_colorMapper; diff --git a/src/controllers/controller.cpp b/src/controllers/controller.cpp index 43b0a58291..f5eb46d6a4 100644 --- a/src/controllers/controller.cpp +++ b/src/controllers/controller.cpp @@ -78,7 +78,7 @@ void Controller::stopLearning() { } -void Controller::send(QList<int> data, unsigned int length) { +void Controller::send(const QList<int>& data, unsigned int length) { // If you change this implementation, also change it in HidController (That // function is required due to HID devices having report IDs) @@ -100,8 +100,7 @@ void Controller::triggerActivity() m_userActivityInhibitTimer.start(); } } -void Controller::receive(const QByteArray data, mixxx::Duration timestamp) { - +void Controller::receive(const QByteArray& data, mixxx::Duration timestamp) { if (m_pEngine == NULL) { //qWarning() << "Controller::receive called with no active engine!"; // Don't complain, since this will always show after closing a device as @@ -114,7 +113,9 @@ void Controller::receive(const QByteArray data, mixxx::Duration timestamp) { if (ControllerDebug::enabled()) { // Formatted packet display QString message = QString("%1: t:%2, %3 bytes:\n") - .arg(m_sDeviceName).arg(timestamp.formatMillisWithUnit()).arg(length); + .arg(m_sDeviceName, + timestamp.formatMillisWithUnit(), + QString::number(length)); for(int i=0; i<length; i++) { QString spacer=" "; if ((i+1) % 4 == 0) spacer=" "; diff --git a/src/controllers/controller.h b/src/controllers/controller.h index 24c3f28975..92f75b1e42 100644 --- a/src/controllers/controller.h +++ b/src/controllers/controller.h @@ -74,7 +74,7 @@ class Controller : public QObject, ConstControllerPresetVisitor { // Handles packets of raw bytes and passes them to an ".incomingData" script // function that is assumed to exist. (Sub-classes may want to reimplement // this if they have an alternate way of handling such data.) - virtual void receive(const QByteArray data, mixxx::Duration timestamp); + virtual void receive(const QByteArray& data, mixxx::Duration timestamp); /// Apply the preset to the controller. /// Initializes both controller engine and static output mappings. @@ -91,7 +91,7 @@ class Controller : public QObject, ConstControllerPresetVisitor { protected: // The length parameter is here for backwards compatibility for when scripts // were required to specify it. - Q_INVOKABLE void send(QList<int> data, unsigned int length = 0); + Q_INVOKABLE void send(const QList<int>& data, unsigned int length = 0); // To be called in sub-class' open() functions after opening the device but // before starting any input polling/processing. @@ -107,10 +107,10 @@ class Controller : public QObject, ConstControllerPresetVisitor { inline ControllerEngine* getEngine() const { return m_pEngine; } - inline void setDeviceName(QString deviceName) { + inline void setDeviceName(const QString& deviceName) { m_sDeviceName = deviceName; } - inline void setDeviceCategory(QString deviceCategory) { + inline void setDeviceCategory(const QString& deviceCategory) { m_sDeviceCategory = deviceCategory; } inline void setOutputDevice(bool outputDevice) { @@ -141,7 +141,7 @@ class Controller : public QObject, ConstControllerPresetVisitor { private: // This must be reimplemented by sub-classes desiring to send raw bytes to a // controller. - virtual void send(QByteArray data) = 0; + virtual void send(const QByteArray& data) = 0; // Returns a pointer to the currently loaded controller preset. For internal // use only. diff --git a/src/controllers/controllerdebug.h b/src/controllers/controllerdebug.h index f3fc5837cf..c8bc556531 100644 --- a/src/controllers/controllerdebug.h +++ b/src/controllers/controllerdebug.h @@ -8,7 +8,8 @@ class ControllerDebug { public: // Any debug statement starting with this prefix bypasses the --logLevel // command line flags. - static constexpr const char* kLogMessagePrefix = "CDBG"; + static constexpr const char kLogMessagePrefix[] = "CDBG"; + static constexpr int kLogMessagePrefixLength = sizeof(kLogMessagePrefix) - 1; static bool enabled(); diff --git a/src/controllers/controllerengine.cpp b/src/controllers/controllerengine.cpp index c7f1b44c3c..7002f3cb85 100644 --- a/src/controllers/controllerengine.cpp +++ b/src/controllers/controllerengine.cpp @@ -84,8 +84,9 @@ Purpose: Calls the same method on a list of JS Objects Input: - Output: - -------- ------------------------------------------------------ */ -void ControllerEngine::callFunctionOnObjects(QList<QString> scriptFunctionPrefixes, - const QString& function, QScriptValueList args) { +void ControllerEngine::callFunctionOnObjects(const QList<QString>& scriptFunctionPrefixes, + const QString& function, + const QScriptValueList& args) { VERIFY_OR_DEBUG_ASSERT(m_pEngine) { return; } @@ -283,8 +284,10 @@ bool ControllerEngine::loadScriptFiles(const QList<ControllerPreset::ScriptFileI m_lastScriptFiles = scripts; - connect(&m_scriptWatcher, SIGNAL(fileChanged(QString)), - this, SLOT(scriptHasChanged(QString))); + connect(&m_scriptWatcher, + &QFileSystemWatcher::fileChanged, + this, + &ControllerEngine::scriptHasChanged); bool success = result && m_scriptErrors.isEmpty(); if (!success) { @@ -301,8 +304,10 @@ void ControllerEngine::scriptHasChanged(const QString& scriptFilename) { qDebug() << "ControllerEngine: Reloading Scripts"; ControllerPresetPointer pPreset = m_pController->getPreset(); - disconnect(&m_scriptWatcher, SIGNAL(fileChanged(QString)), - this, SLOT(scriptHasChanged(QString))); + disconnect(&m_scriptWatcher, + &QFileSystemWatcher::fileChanged, + this, + &ControllerEngine::scriptHasChanged); gracefulShutdown(); uninitializeScriptEngine(); @@ -417,7 +422,7 @@ Input: 'this' object if applicable, Code string Output: false if an exception -------- ------------------------------------------------------ */ bool ControllerEngine::internalExecute( - QScriptValue thisObject, const QString& scriptCode) { + const QScriptValue& thisObject, const QString& scriptCode) { // A special version of safeExecute since we're evaluating strings, not actual functions // (execute() would print an error that it's not a function every time a timer fires.) if (m_pEngine == nullptr) { @@ -448,9 +453,9 @@ Purpose: Evaluate & run script code Input: 'this' object if applicable, Code string Output: false if an exception -------- ------------------------------------------------------ */ -bool ControllerEngine::internalExecute(QScriptValue thisObject, +bool ControllerEngine::internalExecute(const QScriptValue& thisObject, QScriptValue functionObject, - QScriptValueList args) { + const QScriptValueList& args) { if (m_pEngine == nullptr) { qDebug() << "ControllerEngine::execute: No script engine exists!"; return false; @@ -485,7 +490,7 @@ bool ControllerEngine::internalExecute(QScriptValue thisObject, return !checkException(); } -bool ControllerEngine::execute(QScriptValue functionObject, +bool ControllerEngine::execute(const QScriptValue& functionObject, unsigned char channel, unsigned char control, unsigned char value, @@ -505,8 +510,8 @@ bool ControllerEngine::execute(QScriptValue functionObject, return internalExecute(m_pEngine->globalObject(), functionObject, args); } -bool ControllerEngine::execute(QScriptValue function, - const QByteArray data, +bool ControllerEngine::execute(const QScriptValue& function, + const QByteArray& data, mixxx::Duration timestamp) { Q_UNUSED(timestamp); if (m_pEngine == nullptr) { @@ -627,8 +632,10 @@ void ControllerEngine::scriptErrorDialog( if (ErrorDialogHandler::instance()->requestErrorDialog(props)) { // Enable custom handling of the dialog buttons - connect(ErrorDialogHandler::instance(), SIGNAL(stdButtonClicked(QString, QMessageBox::StandardButton)), - this, SLOT(errorDialogButton(QString, QMessageBox::StandardButton))); + connect(ErrorDialogHandler::instance(), + &ErrorDialogHandler::stdButtonClicked, + this, + &ControllerEngine::errorDialogButton); } } @@ -642,9 +649,9 @@ void ControllerEngine::errorDialogButton(const QString& key, QMessageBox::Standa // Something was clicked, so disable this signal now disconnect(ErrorDialogHandler::instance(), - SIGNAL(stdButtonClicked(QString, QMessageBox::StandardButton)), - this, - SLOT(errorDialogButton(QString, QMessageBox::StandardButton))); + &ErrorDialogHandler::stdButtonClicked, + this, + &ControllerEngine::errorDialogButton); if (button == QMessageBox::Retry) { emit resetController(); @@ -680,7 +687,7 @@ ControlObjectScript* ControllerEngine::getControlObjectScript(const QString& gro Input: Control group (e.g. [Channel1]), Key name (e.g. [filterHigh]) Output: The value -------- ------------------------------------------------------ */ -double ControllerEngine::getValue(QString group, QString name) { +double ControllerEngine::getValue(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript == nullptr) { qWarning() << "ControllerEngine: Unknown control" << group << name << ", returning 0.0"; @@ -694,7 +701,7 @@ double ControllerEngine::getValue(QString group, QString name) { Input: Control group, Key name, new value Output: - -------- ------------------------------------------------------ */ -void ControllerEngine::setValue(QString group, QString name, double newValue) { +void ControllerEngine::setValue(const QString& group, const QString& name, double newValue) { if (isnan(newValue)) { qWarning() << "ControllerEngine: script setting [" << group << "," << name << "] to NotANumber, ignoring."; @@ -717,7 +724,7 @@ void ControllerEngine::setValue(QString group, QString name, double newValue) { Input: Control group (e.g. [Channel1]), Key name (e.g. [filterHigh]) Output: The value -------- ------------------------------------------------------ */ -double ControllerEngine::getParameter(QString group, QString name) { +double ControllerEngine::getParameter(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript == nullptr) { qWarning() << "ControllerEngine: Unknown control" << group << name << ", returning 0.0"; @@ -731,7 +738,8 @@ double ControllerEngine::getParameter(QString group, QString name) { Input: Control group, Key name, new value Output: - -------- ------------------------------------------------------ */ -void ControllerEngine::setParameter(QString group, QString name, double newParameter) { +void ControllerEngine::setParameter( + const QString& group, const QString& name, double newParameter) { if (isnan(newParameter)) { qWarning() << "ControllerEngine: script setting [" << group << "," << name << "] to NotANumber, ignoring."; @@ -754,7 +762,8 @@ void ControllerEngine::setParameter(QString group, QString name, double newParam Input: Control group, Key name, new value Output: - -------- ------------------------------------------------------ */ -double ControllerEngine::getParameterForValue(QString group, QString name, double value) { +double ControllerEngine::getParameterForValue( + const QString& group, const QString& name, double value) { if (isnan(value)) { qWarning() << "ControllerEngine: script setting [" << group << "," << name << "] to NotANumber, ignoring."; @@ -776,7 +785,7 @@ double ControllerEngine::getParameterForValue(QString group, QString name, doubl Input: Control group, Key name, new value Output: - -------- ------------------------------------------------------ */ -void ControllerEngine::reset(QString group, QString name) { +void ControllerEngine::reset(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript != nullptr) { coScript->reset(); @@ -788,7 +797,7 @@ void ControllerEngine::reset(QString group, QString name) { Input: Control group, Key name, new value Output: - -------- ------------------------------------------------------ */ -double ControllerEngine::getDefaultValue(QString group, QString name) { +double ControllerEngine::getDefaultValue(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript == nullptr) { @@ -804,7 +813,7 @@ double ControllerEngine::getDefaultValue(QString group, QString name) { Input: Control group, Key name, new value Output: - -------- ------------------------------------------------------ */ -double ControllerEngine::getDefaultParameter(QString group, QString name) { +double ControllerEngine::getDefaultParameter(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript == nullptr) { @@ -820,7 +829,7 @@ double ControllerEngine::getDefaultParameter(QString group, QString name) { Input: String to log Output: - -------- ------------------------------------------------------ */ -void ControllerEngine::log(QString message) { +void ControllerEngine::log(const QString& message) { controllerDebug(message); } @@ -830,8 +839,9 @@ void ControllerEngine::log(QString message) { // The script should store this object to call its // 'disconnect' and 'trigger' methods as needed. // If unsuccessful, returns undefined. -QScriptValue ControllerEngine::makeConnection(QString group, QString name, - const QScriptValue callback) { +QScriptValue ControllerEngine::makeConnection(const QString& group, + const QString& name, + const QScriptValue& callback) { VERIFY_OR_DEBUG_ASSERT(m_pEngine != nullptr) { qWarning() << "Tried to connect script callback, but there is no script engine!"; return QScriptValue(); @@ -889,7 +899,7 @@ void ScriptConnection::executeCallback(double value) const { Purpose: (Dis)connects a ScriptConnection Input: the ScriptConnection to disconnect -------- ------------------------------------------------------ */ -bool ControllerEngine::removeScriptConnection(const ScriptConnection connection) { +bool ControllerEngine::removeScriptConnection(const ScriptConnection& connection) { ControlObjectScript* coScript = getControlObjectScript(connection.key.group, connection.key.item); @@ -911,7 +921,7 @@ bool ScriptConnectionInvokableWrapper::disconnect() { Purpose: Triggers the callback function of a ScriptConnection Input: the ScriptConnection to trigger -------- ------------------------------------------------------ */ -void ControllerEngine::triggerScriptConnection(const ScriptConnection connection) { +void ControllerEngine::triggerScriptConnection(const ScriptConnection& connection) { if (m_pEngine == nullptr) { return; } @@ -937,8 +947,10 @@ void ScriptConnectionInvokableWrapper::trigger() { // it is disconnected. // WARNING: These behaviors are quirky and confusing, so if you change this function, // be sure to run the ControllerEngineTest suite to make sure you do not break old scripts. -QScriptValue ControllerEngine::connectControl( - QString group, QString name, const QScriptValue passedCallback, bool disconnect) { +QScriptValue ControllerEngine::connectControl(const QString& group, + const QString& name, + const QScriptValue& 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. QScriptValue actualCallbackFunction; @@ -1044,7 +1056,7 @@ QScriptValue ControllerEngine::connectControl( Input: - Output: - -------- ------------------------------------------------------ */ -void ControllerEngine::trigger(QString group, QString name) { +void ControllerEngine::trigger(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript != nullptr) { coScript->emitValueChanged(); @@ -1130,8 +1142,7 @@ bool ControllerEngine::hasErrors(const QString& filename) { whether it should fire just once Output: The timer's ID, 0 if starting it failed -------- ------------------------------------------------------ */ -int ControllerEngine::beginTimer(int interval, QScriptValue timerCallback, - bool oneShot) { +int ControllerEngine::beginTimer(int interval, const QScriptValue& timerCallback, bool oneShot) { if (!timerCallback.isFunction() && !timerCallback.isString()) { qWarning() << "Invalid timer callback provided to beginTimer." << "Valid callbacks are strings and functions."; @@ -1468,7 +1479,7 @@ bool ControllerEngine::isScratching(int deck) { whether to set the soft-takeover status or not Output: - -------- ------------------------------------------------------ */ -void ControllerEngine::softTakeover(QString group, QString name, bool set) { +void ControllerEngine::softTakeover(const QString& group, const QString& name, bool set) { ConfigKey key = ConfigKey(group, name); ControlObject* pControl = ControlObject::getControl(key, onlyAssertOnControllerDebug()); if (!pControl) { @@ -1493,7 +1504,7 @@ void ControllerEngine::softTakeover(QString group, QString name, bool set) { Output: - -------- ------------------------------------------------------ */ void ControllerEngine::softTakeoverIgnoreNextValue( - QString group, const QString name) { + const QString& group, const QString& name) { ConfigKey key = ConfigKey(group, name); ControlObject* pControl = ControlObject::getControl(key, onlyAssertOnControllerDebug()); if (!pControl) { diff --git a/src/controllers/controllerengine.h b/src/controllers/controllerengine.h index dad8c785bc..9caab019b7 100644 --- a/src/controllers/controllerengine.h +++ b/src/controllers/controllerengine.h @@ -60,7 +60,7 @@ class ScriptConnectionInvokableWrapper : public QObject { //Q_PROPERTY(QScriptValue function READ function) Q_PROPERTY(bool isConnected READ readIsConnected) public: - ScriptConnectionInvokableWrapper(ScriptConnection conn) { + ScriptConnectionInvokableWrapper(const ScriptConnection& conn) { m_scriptConnection = conn; m_idString = conn.id.toString(); m_isConnected = true; @@ -99,36 +99,39 @@ class ControllerEngine : public QObject { const QList<QString>& getScriptFunctionPrefixes() { return m_scriptFunctionPrefixes; }; // Disconnect a ScriptConnection - bool removeScriptConnection(const ScriptConnection conn); - void triggerScriptConnection(const ScriptConnection conn); + bool removeScriptConnection(const ScriptConnection& conn); + void triggerScriptConnection(const ScriptConnection& conn); protected: - 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 QScriptValue makeConnection(QString group, QString name, - const QScriptValue 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 QScriptValue makeConnection(const QString& group, + const QString& name, + const QScriptValue& callback); // DEPRECATED: Use makeConnection instead. - Q_INVOKABLE QScriptValue connectControl(QString group, QString name, - const QScriptValue passedCallback, - bool disconnect = false); + Q_INVOKABLE QScriptValue connectControl(const QString& group, + const QString& name, + const QScriptValue& passedCallback, + bool disconnect = false); // Called indirectly by the objects returned by connectControl |