diff options
author | Diegoisawesome <Diegoisawesome@users.noreply.github.com> | 2018-09-15 16:12:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-15 16:12:25 -0500 |
commit | b183b99694cb3706f8fc36ff5aa981be1b3da5ad (patch) | |
tree | 823a062f16b609b46dec6845555b32db7003326c /tools/mid2agb/midi.cpp | |
parent | b8c9d9a980303d4bcd1cfd9400926736363d1df9 (diff) | |
parent | 3028fdc353447be5b36a5bee526ffe3ee696a62a (diff) |
Merge pull request #327 from Diegoisawesome/master
Update mid2agb source
Diffstat (limited to 'tools/mid2agb/midi.cpp')
-rw-r--r-- | tools/mid2agb/midi.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/mid2agb/midi.cpp b/tools/mid2agb/midi.cpp index ba5dd654a..09480e139 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) |