diff options
Diffstat (limited to 'src/controllers/midi/portmidicontroller.cpp')
-rw-r--r-- | src/controllers/midi/portmidicontroller.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
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) { |