Skip to content

Commit f6adbc9

Browse files
committed
use QVector<uint8_t> instead of QByteArray for controller input
Converting QByteArray to a QJSValue turns it into an ArrayBuffer in JS, which then needs to be converted to a Uint8Array to be useful. QVector<uint8_t> is converted directly to a JS Array. This temporarily disables debugging for MIDI System Exclusive messages. Fixing this will require refactoring sending controller output to also use QVector<uint8_t> instead of QByteArray, which would make this commit huge.
1 parent 9363b49 commit f6adbc9

19 files changed

+71
-70
lines changed

src/controllers/bulk/bulkcontroller.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ void BulkReader::run() {
5151
Trace timeout("BulkReader timeout");
5252
if (result >= 0) {
5353
Trace process("BulkReader process packet");
54-
//qDebug() << "Read" << result << "bytes, pointer:" << data;
55-
QByteArray outData((char*)data, transferred);
56-
emit incomingData(outData, mixxx::Time::elapsed());
54+
QVector<uint8_t> vector(transferred);
55+
for (int i = 0; i < transferred; i++) {
56+
vector.append(data[i]);
57+
}
58+
emit incomingData(vector, mixxx::Time::elapsed());
5759
}
5860
}
5961
qDebug() << "Stopped Reader";

src/controllers/bulk/bulkcontroller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class BulkReader : public QThread {
2121
void stop();
2222

2323
signals:
24-
void incomingData(QByteArray data, mixxx::Duration timestamp);
24+
void incomingData(const QVector<uint8_t>& data, mixxx::Duration timestamp);
2525

2626
protected:
2727
void run();

src/controllers/controller.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ void Controller::triggerActivity()
111111
m_userActivityInhibitTimer.start();
112112
}
113113
}
114-
void Controller::receive(const QByteArray data, mixxx::Duration timestamp) {
114+
115+
void Controller::receive(const QVector<uint8_t>& data, mixxx::Duration timestamp) {
115116
if (m_pScriptEngineLegacy == nullptr) {
116117
//qWarning() << "Controller::receive called with no active engine!";
117118
// Don't complain, since this will always show after closing a device as

src/controllers/controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Controller : public QObject, ConstControllerPresetVisitor {
8282
// Handles packets of raw bytes and passes them to an ".incomingData" script
8383
// function that is assumed to exist. (Sub-classes may want to reimplement
8484
// this if they have an alternate way of handling such data.)
85-
virtual void receive(const QByteArray data, mixxx::Duration timestamp);
85+
virtual void receive(const QVector<uint8_t>& data, mixxx::Duration timestamp);
8686

8787
/// Apply the preset to the controller.
8888
/// @brief Initializes both controller engine and static output mappings.

src/controllers/hid/hidcontroller.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,17 @@ int HidController::close() {
248248
bool HidController::poll() {
249249
Trace hidRead("HidController poll");
250250

251-
int result = hid_read(m_pHidDevice, m_pPollData, sizeof(m_pPollData) / sizeof(m_pPollData[0]));
251+
int packetLength = sizeof(m_pPollData) / sizeof(m_pPollData[0]);
252+
int result = hid_read(m_pHidDevice, m_pPollData, packetLength);
252253
if (result == -1) {
253254
return false;
254255
} else if (result > 0) {
255256
Trace process("HidController process packet");
256-
QByteArray outData(reinterpret_cast<char*>(m_pPollData), result);
257-
receive(outData, mixxx::Time::elapsed());
257+
QVector<uint8_t> data(packetLength);
258+
for (int i = 0; i < packetLength; i++) {
259+
data.append(m_pPollData[i]);
260+
}
261+
receive(data, mixxx::Time::elapsed());
258262
}
259263

260264
return true;

src/controllers/midi/hss1394controller.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,19 @@ void DeviceChannelListener::Process(const hss1394::uint8 *pBuffer, hss1394::uint
4040
if (i + 2 < uBufferSize) {
4141
note = pBuffer[i+1];
4242
velocity = pBuffer[i+2];
43-
emit incomingData(status, note, velocity, timestamp);
43+
emit receiveShortMessage(status, note, velocity, timestamp);
4444
} else {
4545
qWarning() << "Buffer underflow in DeviceChannelListener::Process()";
4646
}
4747
i += 3;
4848
break;
4949
default:
5050
// Handle platter messages and any others that are not 3 bytes
51-
QByteArray outArray((char*)pBuffer,uBufferSize);
52-
emit incomingData(outArray, timestamp);
51+
QVector<uint8_t> vector(uBufferSize);
52+
for (uint i = 0; i < uBufferSize; i++) {
53+
vector.append(pBuffer[i]);
54+
}
55+
emit receiveSysex(vector, timestamp);
5356
i = uBufferSize;
5457
break;
5558
}
@@ -110,10 +113,12 @@ int Hss1394Controller::open() {
110113
}
111114

112115
m_pChannelListener = new DeviceChannelListener(this, getName());
113-
connect(m_pChannelListener, SIGNAL(incomingData(QByteArray, mixxx::Duration)),
114-
this, SLOT(receive(QByteArray, mixxx::Duration)));
115116
connect(m_pChannelListener,
116-
&DeviceChannelListener::incomingData,
117+
&DeviceChannelListener::receiveSysex,
118+
this,
119+
&Hss1394Controller::receive);
120+
connect(m_pChannelListener,
121+
&DeviceChannelListener::receiveShortMessage,
117122
this,
118123
&Hss1394Controller::receiveShortMessage);
119124

@@ -150,10 +155,14 @@ int Hss1394Controller::close() {
150155
return -1;
151156
}
152157

153-
disconnect(m_pChannelListener, SIGNAL(incomingData(QByteArray, mixxx::Duration)),
154-
this, SLOT(receive(QByteArray, mixxx::Duration)));
155-
disconnect(m_pChannelListener, SIGNAL(incomingData(unsigned char, unsigned char, unsigned char, mixxx::Duration)),
156-
this, SLOT(receive(unsigned char, unsigned char, unsigned char, mixxx::Duration)));
158+
disconnect(m_pChannelListener,
159+
&DeviceChannelListener::receiveSysex,
160+
this,
161+
&Hss1394Controller::receive);
162+
disconnect(m_pChannelListener,
163+
&DeviceChannelListener::receiveShortMessage,
164+
this,
165+
&Hss1394Controller::receiveShortMessage);
157166

158167
stopEngine();
159168
MidiController::close();
@@ -193,7 +202,8 @@ void Hss1394Controller::send(QByteArray data) {
193202
int bytesSent = m_pChannel->SendChannelBytes(
194203
(unsigned char*)data.constData(), data.size());
195204

196-
controllerDebug(MidiUtils::formatSysexMessage(getName(), data));
205+
// TODO: re-enable debug output when switching to QVector<uint8_t> instead of QByteArray
206+
//controllerDebug(MidiUtils::formatSysexMessage(getName(), data));
197207
//if (bytesSent != length) {
198208
// qDebug()<<"ERROR: Sent" << bytesSent << "of" << length << "bytes (SysEx)";
199209
// //m_pChannel->Flush();

src/controllers/midi/hss1394controller.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ class DeviceChannelListener : public QObject, public hss1394::ChannelListener {
3333
void Disconnected();
3434
void Reconnected();
3535
signals:
36-
void incomingData(unsigned char status, unsigned char control, unsigned char value,
37-
mixxx::Duration timestamp);
38-
void incomingData(QByteArray data, mixxx::Duration timestamp);
36+
void receiveShortMessage(unsigned char status,
37+
unsigned char control,
38+
unsigned char value,
39+
mixxx::Duration timestamp);
40+
void receiveSysex(QVector<uint8_t> data, mixxx::Duration timestamp);
41+
3942
private:
4043
QString m_sName;
4144
};

src/controllers/midi/midicontroller.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ double MidiController::computeValue(
470470
return newmidivalue;
471471
}
472472

473-
void MidiController::receive(QByteArray data, mixxx::Duration timestamp) {
473+
void MidiController::receive(const QVector<uint8_t>& data, mixxx::Duration timestamp) {
474474
controllerDebug(MidiUtils::formatSysexMessage(getName(), data, timestamp));
475475

476476
MidiKey mappingKey(data.at(0), 0xFF);
@@ -498,8 +498,8 @@ void MidiController::receive(QByteArray data, mixxx::Duration timestamp) {
498498
}
499499

500500
void MidiController::processInputMapping(const MidiInputMapping& mapping,
501-
const QByteArray& data,
502-
mixxx::Duration timestamp) {
501+
const QVector<uint8_t>& data,
502+
mixxx::Duration timestamp) {
503503
// Custom script handler
504504
if (mapping.options.script) {
505505
ControllerScriptEngineLegacy* pEngine = getScriptEngine();

src/controllers/midi/midicontroller.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class MidiController : public Controller {
7474
unsigned char value,
7575
mixxx::Duration timestamp);
7676
// For receiving System Exclusive messages
77-
void receive(const QByteArray data, mixxx::Duration timestamp) override;
77+
void receive(const QVector<uint8_t>& data, mixxx::Duration timestamp) override;
7878
int close() override;
7979

8080
private slots:
@@ -97,8 +97,8 @@ class MidiController : public Controller {
9797
unsigned char value,
9898
mixxx::Duration timestamp);
9999
void processInputMapping(const MidiInputMapping& mapping,
100-
const QByteArray& data,
101-
mixxx::Duration timestamp);
100+
const QVector<uint8_t>& data,
101+
mixxx::Duration timestamp);
102102

103103
double computeValue(MidiOptions options, double _prevmidivalue, double _newmidivalue);
104104
void createOutputHandlers();

src/controllers/midi/midiutils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ QString MidiUtils::formatMidiMessage(const QString& controllerName,
121121
}
122122

123123
// static
124-
QString MidiUtils::formatSysexMessage(const QString& controllerName, const QByteArray& data,
125-
mixxx::Duration timestamp) {
124+
QString MidiUtils::formatSysexMessage(const QString& controllerName,
125+
const QVector<uint8_t>& data,
126+
mixxx::Duration timestamp) {
126127
QString msg2;
127128
if (timestamp == mixxx::Duration::fromMillis(0)) {
128129
msg2 = "outgoing:";

0 commit comments

Comments
 (0)