summaryrefslogtreecommitdiff
path: root/tools/mid2agb/midi.cpp
diff options
context:
space:
mode:
authorKermalis <29823718+Kermalis@users.noreply.github.com>2018-09-15 00:40:55 -0400
committerKermalis <29823718+Kermalis@users.noreply.github.com>2018-09-15 00:40:55 -0400
commit5d56632d032a4a908d4bfe2d9ddd648020364716 (patch)
treee1e557e2d004f6a8a58934c90dab275645989827 /tools/mid2agb/midi.cpp
parent918c7ca3b5a44bc4dc14a4d3c59cc64305516cfe (diff)
mid2agb changes from #380
https://github.com/pret/pokeruby/pull/380
Diffstat (limited to 'tools/mid2agb/midi.cpp')
-rw-r--r--tools/mid2agb/midi.cpp16
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)