From 951d2a69259c2bd6e803b7f3b8388582fdf61652 Mon Sep 17 00:00:00 2001 From: Frank Buss Date: Mon, 15 Dec 2014 23:16:03 +0100 Subject: [PATCH] running status bugfix Some MIDI interfaces send a "running status" (omitting the first message byte, if it is the same for consecutive MIDI messages, even if the application doesn't send it. The current menu doesn't support this, so as a workaround it alternates bewteen note-on/off messages, because after the first note-off message it is not tested if it is a note-on for the rest of the transfer. --- qt/mainwindow.cpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp index 03ea641..e89007b 100644 --- a/qt/mainwindow.cpp +++ b/qt/mainwindow.cpp @@ -27,6 +27,7 @@ MainWindow* g_mainWindow; extern bool g_debugging; +bool g_sendNoteOff = true; bool g_midiTransferInProgress = false; bool g_testSequenceRunning = false; @@ -192,19 +193,35 @@ uint8_t ascii2petscii(uint8_t ascii) // second byte: length // last byte in the next data messages: CRC8 checksum -static void sendNoteOff(uint8_t channelBits, uint8_t note, uint8_t velocity) +static void sendNoteOnOff(uint8_t msg, uint8_t note, uint8_t velocity) { try { ByteArray message; - message.push_back(0x80 | channelBits); + message.push_back(msg); message.push_back(note); message.push_back(velocity); g_midiOut.sendMessage(&message); +/* + printf("%02x\n", message[0]); + printf("%02x\n", message[1]); + printf("%02x\n", message[2]); + fflush(stdout); + */ } catch (RtError& err) { //qWarning() << QString::fromStdString(err.getMessage()); } } +static void sendNoteOff(uint8_t channelBits, uint8_t note, uint8_t velocity) +{ + sendNoteOnOff(channelBits | 0x80, note, velocity); +} + +static void sendNoteOn(uint8_t channelBits, uint8_t note, uint8_t velocity) +{ + sendNoteOnOff(channelBits | 0x90, note, velocity); +} + static void midiSendBytesWithFlags(int b1, int b2, int flags) { int channel = 0; @@ -221,7 +238,14 @@ static void midiSendBytesWithFlags(int b1, int b2, int flags) } else { b2 = 0; } - sendNoteOff(channel | flags, b1, b2); + + // alternate between note off and note on to avoid "running status" translation of some MIDI devices + if (g_sendNoteOff) { + sendNoteOff(channel | flags, b1, b2); + } else { + sendNoteOn(channel | flags, b1, b2); + } + g_sendNoteOff = !g_sendNoteOff; } static void midiStartTransfer(uint8_t tag, uint8_t length) @@ -254,6 +278,9 @@ static void midiEndTransfer() static void midiSendCommand(uint8_t tag, ByteArray data) { + // init alternate note-on/off sending + g_sendNoteOff = true; + // start file transfer size_t length = data.size(); if (length <= 1) { @@ -506,7 +533,7 @@ MainWindow::MainWindow(QWidget *parent) : if (!g_debugging) { debuggingGroupBox->setVisible(false); } - setWindowTitle(QCoreApplication::applicationName() + " V1.0"); + setWindowTitle(QCoreApplication::applicationName() + " V1.1"); startTimer(100); QSettings settings;