diff --git a/src/controllers/hid/hidcontroller.cpp b/src/controllers/hid/hidcontroller.cpp index e243029fa34..5cd6117f0b9 100644 --- a/src/controllers/hid/hidcontroller.cpp +++ b/src/controllers/hid/hidcontroller.cpp @@ -162,7 +162,7 @@ void HidController::processInputReport(int bytesRead) { receive(incomingData, mixxx::Time::elapsed()); } -QList HidController::getInputReport(unsigned int reportID) { +QByteArray HidController::getInputReport(unsigned int reportID) { Trace hidRead("HidController getInputReport"); int bytesRead; @@ -185,17 +185,11 @@ QList HidController::getInputReport(unsigned int reportID) { // Otherwise minimum possible value is 1, because 1 byte is for the reportID, // the smallest report with data is therefore 2 bytes. DEBUG_ASSERT(bytesRead <= kReportIdSize); - return QList(); + return QByteArray(); } - // Convert array of bytes read in a JavaScript compatible return type - // For compatibility with the array provided by HidController::poll the reportID is contained as prefix - QList dataList; - dataList.reserve(bytesRead); - for (int i = 0; i < bytesRead; i++) { - dataList.append(m_pPollData[m_pollingBufferIndex][i]); - } - return dataList; + return QByteArray::fromRawData( + reinterpret_cast(m_pPollData[m_pollingBufferIndex]), bytesRead); } bool HidController::poll() { @@ -255,14 +249,14 @@ void HidController::sendBytesReport(QByteArray data, unsigned int reportID) { } void HidController::sendFeatureReport( - const QList& dataList, unsigned int reportID) { + const QByteArray& reportData, unsigned int reportID) { QByteArray dataArray; - dataArray.reserve(kReportIdSize + dataList.size()); + dataArray.reserve(kReportIdSize + reportData.size()); // Append the Report ID to the beginning of dataArray[] per the API.. dataArray.append(reportID); - for (const int datum : dataList) { + for (const int datum : reportData) { dataArray.append(datum); } @@ -287,7 +281,7 @@ ControllerJSProxy* HidController::jsProxy() { return new HidControllerJSProxy(this); } -QList HidController::getFeatureReport( +QByteArray HidController::getFeatureReport( unsigned int reportID) { unsigned char dataRead[kReportIdSize + kBufferSize]; dataRead[0] = reportID; @@ -318,10 +312,8 @@ QList HidController::getFeatureReport( // Convert array of bytes read in a JavaScript compatible return type // For compatibility with input array HidController::sendFeatureReport, a reportID prefix is not added here - QList dataList; - dataList.reserve(bytesRead - kReportIdSize); - for (int i = kReportIdSize; i < bytesRead; i++) { - dataList.append(dataRead[i]); - } - return dataList; + QByteArray byteArray; + byteArray.reserve(bytesRead - kReportIdSize); + auto featureReportStart = reinterpret_cast(dataRead + kReportIdSize); + return QByteArray(featureReportStart, bytesRead); } diff --git a/src/controllers/hid/hidcontroller.h b/src/controllers/hid/hidcontroller.h index f84463302b2..2e7a8f22e6e 100644 --- a/src/controllers/hid/hidcontroller.h +++ b/src/controllers/hid/hidcontroller.h @@ -46,7 +46,7 @@ class HidController final : public Controller { // 0x0. void sendBytes(const QByteArray& data) override; void sendBytesReport(QByteArray data, unsigned int reportID); - void sendFeatureReport(const QList& dataList, unsigned int reportID); + void sendFeatureReport(const QByteArray& reportData, unsigned int reportID); // getInputReport receives an input report on request. // This can be used on startup to initialize the knob positions in Mixxx @@ -55,7 +55,7 @@ class HidController final : public Controller { // as in the polling functionality (including ReportID in first byte). // The returned list can be used to call the incomingData // function of the common-hid-packet-parser. - QList getInputReport(unsigned int reportID); + QByteArray getInputReport(unsigned int reportID); // getFeatureReport receives a feature reports on request. // HID doesn't support polling feature reports, therefore this is the @@ -64,7 +64,7 @@ class HidController final : public Controller { // changing the other bits. The returned list matches the input // format of sendFeatureReport, allowing it to be read, modified // and sent it back to the controller. - QList getFeatureReport(unsigned int reportID); + QByteArray getFeatureReport(unsigned int reportID); const mixxx::hid::DeviceInfo m_deviceInfo; @@ -96,17 +96,17 @@ class HidControllerJSProxy : public ControllerJSProxy { m_pHidController->sendReport(data, length, reportID); } - Q_INVOKABLE QList getInputReport( + Q_INVOKABLE QByteArray getInputReport( unsigned int reportID) { return m_pHidController->getInputReport(reportID); } Q_INVOKABLE void sendFeatureReport( - const QList& dataList, unsigned int reportID) { - m_pHidController->sendFeatureReport(dataList, reportID); + const QByteArray& reportData, unsigned int reportID) { + m_pHidController->sendFeatureReport(reportData, reportID); } - Q_INVOKABLE QList getFeatureReport( + Q_INVOKABLE QByteArray getFeatureReport( unsigned int reportID) { return m_pHidController->getFeatureReport(reportID); }