summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Schürmann <daschuer@mixxx.org>2015-12-20 18:58:52 +0100
committerDaniel Schürmann <daschuer@mixxx.org>2015-12-20 18:58:52 +0100
commit2d4ac9a7ca89ef1b671e5d4ec57084563a9cc45c (patch)
tree03929130dc5b685dd8f9ebf49892720c3923139a /src
parent03852d92ae82a8ae8e6e6fbc2d895601ae71ec78 (diff)
parentb59ddd31f05c259577e02eb732182d129e9b0442 (diff)
Merge remote-tracking branch 'upstream/1.12' into controllerpoll
Conflicts: src/controllers/midi/portmidicontroller.cpp src/controllers/midi/portmidicontroller.h
Diffstat (limited to 'src')
-rw-r--r--src/controllers/bulk/bulkcontroller.cpp4
-rw-r--r--src/controllers/hid/hidcontroller.cpp4
-rw-r--r--src/controllers/midi/hss1394controller.cpp4
-rw-r--r--src/controllers/midi/portmidicontroller.cpp33
-rw-r--r--src/controllers/midi/portmidicontroller.h5
5 files changed, 37 insertions, 13 deletions
diff --git a/src/controllers/bulk/bulkcontroller.cpp b/src/controllers/bulk/bulkcontroller.cpp
index 4d038961c5..5b6b446e8a 100644
--- a/src/controllers/bulk/bulkcontroller.cpp
+++ b/src/controllers/bulk/bulkcontroller.cpp
@@ -94,7 +94,9 @@ BulkController::BulkController(libusb_context* context,
}
BulkController::~BulkController() {
- close();
+ if (isOpen()) {
+ close();
+ }
}
QString BulkController::presetExtension() {
diff --git a/src/controllers/hid/hidcontroller.cpp b/src/controllers/hid/hidcontroller.cpp
index 7175d85b93..e8d6940006 100644
--- a/src/controllers/hid/hidcontroller.cpp
+++ b/src/controllers/hid/hidcontroller.cpp
@@ -109,7 +109,9 @@ HidController::HidController(const hid_device_info deviceInfo)
}
HidController::~HidController() {
- close();
+ if (isOpen()) {
+ close();
+ }
delete [] hid_path;
delete [] hid_serial_raw;
}
diff --git a/src/controllers/midi/hss1394controller.cpp b/src/controllers/midi/hss1394controller.cpp
index b1bc533459..688ede11e2 100644
--- a/src/controllers/midi/hss1394controller.cpp
+++ b/src/controllers/midi/hss1394controller.cpp
@@ -76,7 +76,9 @@ Hss1394Controller::Hss1394Controller(const hss1394::TNodeInfo deviceInfo,
}
Hss1394Controller::~Hss1394Controller() {
- close();
+ if (isOpen()) {
+ close();
+ }
}
int Hss1394Controller::open() {
diff --git a/src/controllers/midi/portmidicontroller.cpp b/src/controllers/midi/portmidicontroller.cpp
index 2369d0c167..e82edc4091 100644
--- a/src/controllers/midi/portmidicontroller.cpp
+++ b/src/controllers/midi/portmidicontroller.cpp
@@ -32,18 +32,24 @@ PortMidiController::PortMidiController(const PmDeviceInfo* inputDeviceInfo,
// Note: We prepend the input stream's index to the device's name to prevent
// duplicate devices from causing mayhem.
//setDeviceName(QString("%1. %2").arg(QString::number(m_iInputDeviceIndex), inputDeviceInfo->name));
- setDeviceName(QString("%1").arg(inputDeviceInfo->name));
if (m_pInputDeviceInfo) {
+ setDeviceName(QString("%1").arg(m_pInputDeviceInfo->name));
setInputDevice(m_pInputDeviceInfo->input);
}
if (m_pOutputDeviceInfo) {
+ // In the event of an output-only device, use the output device name.
+ if (m_pInputDeviceInfo == NULL) {
+ setDeviceName(QString("%1").arg(m_pOutputDeviceInfo->name));
+ }
setOutputDevice(m_pOutputDeviceInfo->output);
}
}
PortMidiController::~PortMidiController() {
- close();
+ if (isOpen()) {
+ close();
+ }
}
int PortMidiController::open() {
@@ -202,14 +208,14 @@ bool PortMidiController::poll() {
}
// Collect bytes from PmMessage
- int data = 0;
+ unsigned char data = 0;
for (int shift = 0; shift < 32 && (data != MIDI_EOX); shift += 8) {
- if ((data & 0xF8) == 0xF8) {
- // Handle real-time messages at any time
- receive(data, 0, 0, m_midiBuffer[i].timestamp);
- } else {
- m_cReceiveMsg[m_cReceiveMsg_index++] = data =
- (m_midiBuffer[i].message >> shift) & 0xFF;
+ // TODO(rryan): This prevents buffer overflow if the sysex is
+ // larger than 1024 bytes. I don't want to radically change
+ // anything before the 2.0 release so this will do for now.
+ data = (m_midiBuffer[i].message >> shift) & 0xFF;
+ if (m_cReceiveMsg_index < MIXXX_SYSEX_BUFFER_LEN) {
+ m_cReceiveMsg[m_cReceiveMsg_index++] = data;
}
}
@@ -236,6 +242,15 @@ void PortMidiController::sendWord(unsigned int word) {
}
void PortMidiController::send(QByteArray data) {
+ // PortMidi does not receive a length argument for the buffer we provide to
+ // Pm_WriteSysEx. Instead, it scans for a MIDI_EOX byte to know when the
+ // message is over. If one is not provided, it will overflow the buffer and
+ // cause a segfault.
+ if (!data.endsWith(MIDI_EOX)) {
+ controllerDebug("SysEx message does not end with 0xF7 -- ignoring.");
+ return;
+ }
+
if (m_pOutputStream) {
PmError err = Pm_WriteSysEx(m_pOutputStream, 0, (unsigned char*)data.constData());
if (err != pmNoError) {
diff --git a/src/controllers/midi/portmidicontroller.h b/src/controllers/midi/portmidicontroller.h
index 37fd02b2e4..c3fa462678 100644
--- a/src/controllers/midi/portmidicontroller.h
+++ b/src/controllers/midi/portmidicontroller.h
@@ -29,6 +29,9 @@
// a 1024 messages buffer will buffer ~327 ms Midi-Stream
#define MIXXX_PORTMIDI_BUFFER_LEN 1024
+// Length of SysEx buffer in byte
+#define MIXXX_SYSEX_BUFFER_LEN 1024
+
// String to display for no MIDI devices present
#define MIXXX_PORTMIDI_NO_DEVICE_STRING "None"
@@ -66,7 +69,7 @@ class PortMidiController : public MidiController {
PmEvent m_midiBuffer[MIXXX_PORTMIDI_BUFFER_LEN];
// Storage for SysEx messages
- unsigned char m_cReceiveMsg[1024];
+ unsigned char m_cReceiveMsg[MIXXX_SYSEX_BUFFER_LEN];
int m_cReceiveMsg_index;
bool m_bInSysex;
};