diff options
Diffstat (limited to 'tools/mid2agb/midi.cpp')
-rw-r--r-- | tools/mid2agb/midi.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index 7c05c5237..09480e139 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -52,7 +52,7 @@ static std::int32_t s_absoluteTime; static int s_blockCount = 0; static int s_minNote; static int s_maxNote; -static int s_runningStatus = 0; +static int s_runningStatus; void Seek(long offset) { @@ -171,6 +171,7 @@ void StartTrack() { Seek(s_trackDataStart); s_absoluteTime = 0; + s_runningStatus = 0; } void SkipEventData() @@ -182,20 +183,18 @@ void DetermineEventCategory(MidiEventCategory& category, int& typeChan, int& siz { typeChan = ReadInt8(); - if (typeChan < 0x80 && s_runningStatus != 0) + if (typeChan < 0x80) { + // If data byte was found, use the running status. + ungetc(typeChan, g_inputFile); typeChan = s_runningStatus; - Skip(-1); } - + if (typeChan == 0xFF) { category = MidiEventCategory::Meta; size = 0; - } - else if (typeChan >= 0xF8) - { - category = MidiEventCategory::Invalid; + s_runningStatus = 0; } else if (typeChan >= 0xF0) { @@ -206,7 +205,6 @@ void DetermineEventCategory(MidiEventCategory& category, int& typeChan, int& siz else if (typeChan >= 0x80) { category = MidiEventCategory::Control; - s_runningStatus = typeChan; switch (typeChan >> 4) { @@ -218,6 +216,7 @@ void DetermineEventCategory(MidiEventCategory& category, int& typeChan, int& siz size = 2; break; } + s_runningStatus = typeChan; } else { @@ -434,7 +433,10 @@ bool CheckNoteEnd(Event& event) void FindNoteEnd(Event& event) { + // Save the current file position and running status + // which get modified by CheckNoteEnd. long startPos = ftell(g_inputFile); + int savedRunningStatus = s_runningStatus; event.param2 = 0; @@ -442,6 +444,7 @@ void FindNoteEnd(Event& event) ; Seek(startPos); + s_runningStatus = savedRunningStatus; } bool ReadTrackEvent(Event& event) |