From 7f6b421e87972904434c4551863e593fd42b49b5 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 20 Jan 2016 18:00:48 -0600 Subject: [PATCH] Make sure all unhandled delayed MIDI events generate NOPs - Looking over the code again, I see that discarded SysEx messages can cause the same issue as unhandled meta events, so generalize the returning of a NOP for everything. --- src/sound/music_smf_midiout.cpp | 38 +++++++++++++++------------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/sound/music_smf_midiout.cpp b/src/sound/music_smf_midiout.cpp index 6284c504b..918639399 100644 --- a/src/sound/music_smf_midiout.cpp +++ b/src/sound/music_smf_midiout.cpp @@ -384,6 +384,11 @@ DWORD *MIDISong2::SendCommand (DWORD *events, TrackInfo *track, DWORD delay, ptr event = track->TrackBegin[track->TrackP++]; CHECK_FINISHED + // The actual event type will be filled in below. + events[0] = delay; + events[1] = 0; + events[2] = MEVT_NOP << 24; + if (event != MIDI_SYSEX && event != MIDI_META && event != MIDI_SYSEXEND) { // Normal short message @@ -582,17 +587,10 @@ DWORD *MIDISong2::SendCommand (DWORD *events, TrackInfo *track, DWORD delay, ptr break; } } - events[0] = delay; - events[1] = 0; if (event != MIDI_META && (!track->Designated || (track->Designation & DesignationMask))) { events[2] = event | (data1<<8) | (data2<<16); } - else - { - events[2] = MEVT_NOP << 24; - } - events += 3; } else { @@ -612,8 +610,6 @@ DWORD *MIDISong2::SendCommand (DWORD *events, TrackInfo *track, DWORD delay, ptr } else { - events[0] = delay; - events[1] = 0; BYTE *msg = (BYTE *)&events[3]; if (event == MIDI_SYSEX) { // Need to add the SysEx marker to the message. @@ -631,7 +627,6 @@ DWORD *MIDISong2::SendCommand (DWORD *events, TrackInfo *track, DWORD delay, ptr { *msg++ = 0; } - events = (DWORD *)msg; track->TrackP += len; } } @@ -659,17 +654,6 @@ DWORD *MIDISong2::SendCommand (DWORD *events, TrackInfo *track, DWORD delay, ptr events[0] = delay; events[1] = 0; events[2] = (MEVT_TEMPO << 24) | Tempo; - events += 3; - break; - - default: - if (delay != 0) - { - events[0] = delay; - events[1] = 0; - events[2] = MEVT_NOP << 24; - events += 3; - } break; } track->TrackP += len; @@ -688,6 +672,18 @@ DWORD *MIDISong2::SendCommand (DWORD *events, TrackInfo *track, DWORD delay, ptr { track->Delay = track->ReadVarLen(); } + // Advance events pointer unless this is a non-delaying NOP. + if (events[0] != 0 || MEVT_EVENTTYPE(events[2]) != MEVT_NOP) + { + if (MEVT_EVENTTYPE(events[2]) == MEVT_LONGMSG) + { + events += 3 + ((MEVT_EVENTPARM(events[2]) + 3) >> 2); + } + else + { + events += 3; + } + } return events; }