diff options
Diffstat (limited to 'tools/mid2agb/midi.cpp')
-rw-r--r-- | tools/mid2agb/midi.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index ba5dd654a..c7a4389b9 100644 --- a/tools/mid2agb/midi.cpp +++ b/tools/mid2agb/midi.cpp @@ -52,6 +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; void Seek(long offset) { @@ -170,6 +171,7 @@ void StartTrack() { Seek(s_trackDataStart); s_absoluteTime = 0; + s_runningStatus = 0; } void SkipEventData() @@ -181,15 +183,24 @@ void DetermineEventCategory(MidiEventCategory& category, int& typeChan, int& siz { typeChan = ReadInt8(); + if (typeChan < 0x80) + { + // If data byte was found, use the running status. + ungetc(typeChan, g_inputFile); + typeChan = s_runningStatus; + } + if (typeChan == 0xFF) { category = MidiEventCategory::Meta; size = 0; + s_runningStatus = 0; } else if (typeChan >= 0xF0) { category = MidiEventCategory::SysEx; size = 0; + s_runningStatus = 0; } else if (typeChan >= 0x80) { @@ -205,6 +216,7 @@ void DetermineEventCategory(MidiEventCategory& category, int& typeChan, int& siz size = 2; break; } + s_runningStatus = typeChan; } else { @@ -421,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; @@ -429,6 +444,7 @@ void FindNoteEnd(Event& event) ; Seek(startPos); + s_runningStatus = savedRunningStatus; } bool ReadTrackEvent(Event& event) @@ -884,7 +900,7 @@ void Compress(std::vector<Event>& events) return; } - if (CalculateCompressionScore(events, i) >= 6) + if (CalculateCompressionScore(events, i) > 6) { CompressWholeNote(events, i); } |