From 6c5a5cd8e90fcaafae6fd6f409fde04b29fa7e7a Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 20 Sep 2013 23:05:37 +0200 Subject: AUDIO: Split event processing from MidiParser::onTimer This is to prepare for overriding more of this functionality in SCI. --- audio/midiparser.cpp | 79 +++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 35 deletions(-) (limited to 'audio/midiparser.cpp') 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; -- cgit v1.2.3 From da81c593081ffebb33740ada85d9c2a5084f7d0a Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sat, 21 Sep 2013 00:21:08 +0200 Subject: AUDIO: Let jumpToTick use processEvent too --- audio/midiparser.cpp | 61 +++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'audio/midiparser.cpp') diff --git a/audio/midiparser.cpp b/audio/midiparser.cpp index 0a8183669d..23da903b6d 100644 --- a/audio/midiparser.cpp +++ b/audio/midiparser.cpp @@ -229,14 +229,16 @@ void MidiParser::onTimer() { } } -bool MidiParser::processEvent(const EventInfo &info) { +bool MidiParser::processEvent(const EventInfo &info, bool fireEvents) { 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); + if (fireEvents) { + 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) { @@ -247,7 +249,8 @@ bool MidiParser::processEvent(const EventInfo &info) { parseNextEvent(_nextEvent); } else { stopPlaying(); - _driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length); + if (fireEvents) + _driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length); } return false; } else if (info.ext.type == 0x51) { @@ -255,9 +258,11 @@ bool MidiParser::processEvent(const EventInfo &info) { 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); + if (fireEvents) + _driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length); } else { - sendToDriver(info.event, info.basic.param1, info.basic.param2); + if (fireEvents) + sendToDriver(info.event, info.basic.param1, info.basic.param2); } return true; @@ -399,34 +404,18 @@ bool MidiParser::jumpToTick(uint32 tick, bool fireEvents, bool stopNotes, bool d _position._playTick = _position._lastEventTick; _position._playTime = _position._lastEventTime; - if (info.event == 0xFF) { - if (info.ext.type == 0x2F) { // End of track - _position = currentPos; - _nextEvent = currentEvent; - return false; - } else { - if (info.ext.type == 0x51 && info.length >= 3) // Tempo - setTempo(info.ext.data[0] << 16 | info.ext.data[1] << 8 | info.ext.data[2]); - if (fireEvents) - _driver->metaEvent(info.ext.type, info.ext.data, (uint16) info.length); - } - } else if (fireEvents) { - if (info.event == 0xF0) { - 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 { - // The note on sending code is used by the SCUMM engine. Other engine using this code - // (such as SCI) have issues with this, as all the notes sent can be heard when a song - // is fast-forwarded. Thus, if the engine requests it, don't send note on events. - if (info.command() == 0x9 && dontSendNoteOn) { - // Don't send note on; doing so creates a "warble" with some instruments on the MT-32. - // Refer to patch #3117577 - } else { - sendToDriver(info.event, info.basic.param1, info.basic.param2); - } - } + // Some special processing for the fast-forward case + if (info.command() == 0x9 && dontSendNoteOn) { + // Don't send note on; doing so creates a "warble" with + // some instruments on the MT-32. Refer to patch #3117577 + } else if (info.event == 0xFF && info.ext.type == 0x2F) { + // End of track + // This means that we failed to find the right tick. + _position = currentPos; + _nextEvent = currentEvent; + return false; + } else { + processEvent(info, fireEvents); } parseNextEvent(_nextEvent); -- cgit v1.2.3 From 86c2fe47e04449602e4c005fa0a9c183bc8bba39 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sat, 21 Sep 2013 01:08:02 +0200 Subject: AUDIO: Simplify MidiTracker::processEvent return value --- audio/midiparser.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'audio/midiparser.cpp') diff --git a/audio/midiparser.cpp b/audio/midiparser.cpp index 23da903b6d..dcb83bb090 100644 --- a/audio/midiparser.cpp +++ b/audio/midiparser.cpp @@ -213,14 +213,13 @@ void MidiParser::onTimer() { activeNote(info.channel(), info.basic.param1, true); } - bool ret = processEvent(info); - if (!ret) - return; + processEvent(info); - if (!_abortParse) { - _position._lastEventTime = eventTime; - parseNextEvent(_nextEvent); - } + if (_abortParse) + break; + + _position._lastEventTime = eventTime; + parseNextEvent(_nextEvent); } if (!_abortParse) { @@ -229,7 +228,7 @@ void MidiParser::onTimer() { } } -bool MidiParser::processEvent(const EventInfo &info, bool fireEvents) { +void MidiParser::processEvent(const EventInfo &info, bool fireEvents) { if (info.event == 0xF0) { // SysEx event // Check for trailing 0xF7 -- if present, remove it. @@ -252,7 +251,8 @@ bool MidiParser::processEvent(const EventInfo &info, bool fireEvents) { if (fireEvents) _driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length); } - return false; + _abortParse = true; + 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]); @@ -264,8 +264,6 @@ bool MidiParser::processEvent(const EventInfo &info, bool fireEvents) { if (fireEvents) sendToDriver(info.event, info.basic.param1, info.basic.param2); } - - return true; } -- cgit v1.2.3 From 3792af8e955bea5a07359c808361a16b15481327 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sat, 21 Sep 2013 09:30:42 +0200 Subject: AUDIO: Simplify SCI inFastForward flag by moving it to MidiParser --- audio/midiparser.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'audio/midiparser.cpp') diff --git a/audio/midiparser.cpp b/audio/midiparser.cpp index dcb83bb090..2454575413 100644 --- a/audio/midiparser.cpp +++ b/audio/midiparser.cpp @@ -44,7 +44,8 @@ _centerPitchWheelOnUnload(false), _sendSustainOffOnNotesOff(false), _numTracks(0), _activeTrack(255), -_abortParse(0) { +_abortParse(false), +_jumpingToTick(false) { memset(_activeNotes, 0, sizeof(_activeNotes)); memset(_tracks, 0, sizeof(_tracks)); _nextEvent.start = NULL; @@ -382,6 +383,9 @@ bool MidiParser::jumpToTick(uint32 tick, bool fireEvents, bool stopNotes, bool d if (_activeTrack >= _numTracks) return false; + assert(!_jumpingToTick); // This function is not re-entrant + _jumpingToTick = true; + Tracker currentPos(_position); EventInfo currentEvent(_nextEvent); @@ -411,6 +415,7 @@ bool MidiParser::jumpToTick(uint32 tick, bool fireEvents, bool stopNotes, bool d // This means that we failed to find the right tick. _position = currentPos; _nextEvent = currentEvent; + _jumpingToTick = false; return false; } else { processEvent(info, fireEvents); @@ -437,6 +442,7 @@ bool MidiParser::jumpToTick(uint32 tick, bool fireEvents, bool stopNotes, bool d } _abortParse = true; + _jumpingToTick = false; return true; } -- cgit v1.2.3