Skip to content

Commit

Permalink
running status bugfix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Frank-Buss committed Dec 15, 2014
1 parent 1e4cfbf commit 951d2a6
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ MainWindow* g_mainWindow;

extern bool g_debugging;

bool g_sendNoteOff = true;
bool g_midiTransferInProgress = false;
bool g_testSequenceRunning = false;

Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 951d2a6

Please sign in to comment.