aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2013-09-20 23:05:37 +0200
committerWillem Jan Palenstijn2013-09-21 00:22:56 +0200
commit6c5a5cd8e90fcaafae6fd6f409fde04b29fa7e7a (patch)
treecda8e7888fba18127f6eb30ffe792243174fd11a
parent995d689ef355ce465f3647270a33ccf08802754e (diff)
downloadscummvm-rg350-6c5a5cd8e90fcaafae6fd6f409fde04b29fa7e7a.tar.gz
scummvm-rg350-6c5a5cd8e90fcaafae6fd6f409fde04b29fa7e7a.tar.bz2
scummvm-rg350-6c5a5cd8e90fcaafae6fd6f409fde04b29fa7e7a.zip
AUDIO: Split event processing from MidiParser::onTimer
This is to prepare for overriding more of this functionality in SCI.
-rw-r--r--audio/midiparser.cpp79
-rw-r--r--audio/midiparser.h5
2 files changed, 47 insertions, 37 deletions
diff --git a/audio/midiparser.cpp b/audio/midiparser.cpp
index 9c144c2479..0a8183669d 100644
--- a/audio/midiparser.cpp
+++ b/audio/midiparser.cpp
@@ -204,44 +204,18 @@ void MidiParser::onTimer() {
return;
}
- if (info.event == 0xF0) {
- // SysEx event
- // Check for trailing 0xF7 -- if present, remove it.
- if (info.ext.data[info.length-1] == 0xF7)
- _driver->sysEx(info.ext.data, (uint16)info.length-1);
+ if (info.command() == 0x8) {
+ activeNote(info.channel(), info.basic.param1, false);
+ } else if (info.command() == 0x9) {
+ if (info.length > 0)
+ hangingNote(info.channel(), info.basic.param1, info.length * _psecPerTick - (endTime - eventTime));
else
- _driver->sysEx(info.ext.data, (uint16)info.length);
- } else if (info.event == 0xFF) {
- // META event
- if (info.ext.type == 0x2F) {
- // End of Track must be processed by us,
- // as well as sending it to the output device.
- if (_autoLoop) {
- jumpToTick(0);
- parseNextEvent(_nextEvent);
- } else {
- stopPlaying();
- _driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length);
- }
- return;
- } else if (info.ext.type == 0x51) {
- if (info.length >= 3) {
- setTempo(info.ext.data[0] << 16 | info.ext.data[1] << 8 | info.ext.data[2]);
- }
- }
- _driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length);
- } else {
- if (info.command() == 0x8) {
- activeNote(info.channel(), info.basic.param1, false);
- } else if (info.command() == 0x9) {
- if (info.length > 0)
- hangingNote(info.channel(), info.basic.param1, info.length * _psecPerTick - (endTime - eventTime));
- else
- activeNote(info.channel(), info.basic.param1, true);
- }
- sendToDriver(info.event, info.basic.param1, info.basic.param2);
+ activeNote(info.channel(), info.basic.param1, true);
}
+ bool ret = processEvent(info);
+ if (!ret)
+ return;
if (!_abortParse) {
_position._lastEventTime = eventTime;
@@ -255,6 +229,41 @@ void MidiParser::onTimer() {
}
}
+bool MidiParser::processEvent(const EventInfo &info) {
+ if (info.event == 0xF0) {
+ // SysEx event
+ // Check for trailing 0xF7 -- if present, remove it.
+ if (info.ext.data[info.length-1] == 0xF7)
+ _driver->sysEx(info.ext.data, (uint16)info.length-1);
+ else
+ _driver->sysEx(info.ext.data, (uint16)info.length);
+ } else if (info.event == 0xFF) {
+ // META event
+ if (info.ext.type == 0x2F) {
+ // End of Track must be processed by us,
+ // as well as sending it to the output device.
+ if (_autoLoop) {
+ jumpToTick(0);
+ parseNextEvent(_nextEvent);
+ } else {
+ stopPlaying();
+ _driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length);
+ }
+ return false;
+ } else if (info.ext.type == 0x51) {
+ if (info.length >= 3) {
+ setTempo(info.ext.data[0] << 16 | info.ext.data[1] << 8 | info.ext.data[2]);
+ }
+ }
+ _driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length);
+ } else {
+ sendToDriver(info.event, info.basic.param1, info.basic.param2);
+ }
+
+ return true;
+}
+
+
void MidiParser::allNotesOff() {
if (!_driver)
return;
diff --git a/audio/midiparser.h b/audio/midiparser.h
index bb9749b97f..4470d7d980 100644
--- a/audio/midiparser.h
+++ b/audio/midiparser.h
@@ -105,8 +105,8 @@ struct EventInfo {
///< will occur, and the MidiParser will have to generate one itself.
///< For all other events, this value should always be zero.
- byte channel() { return event & 0x0F; } ///< Separates the MIDI channel from the event.
- byte command() { return event >> 4; } ///< Separates the command code from the event.
+ byte channel() const { return event & 0x0F; } ///< Separates the MIDI channel from the event.
+ byte command() const { return event >> 4; } ///< Separates the command code from the event.
};
/**
@@ -293,6 +293,7 @@ protected:
virtual void resetTracking();
virtual void allNotesOff();
virtual void parseNextEvent(EventInfo &info) = 0;
+ virtual bool processEvent(const EventInfo &info);
void activeNote(byte channel, byte note, bool active);
void hangingNote(byte channel, byte note, uint32 ticksLeft, bool recycle = true);