2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-05-19 18:48:18 +00:00
|
|
|
*
|
2021-12-26 18:47:58 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 02:34:17 +01:00
|
|
|
*
|
2003-05-19 18:48:18 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:17 +01:00
|
|
|
*
|
2003-05-19 18:48:18 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-05-19 18:48:18 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/midiparser.h"
|
|
|
|
#include "audio/mididrv.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "common/textconsole.h"
|
2003-05-19 18:48:18 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// MidiParser implementation
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
2022-04-19 22:22:07 +02:00
|
|
|
MidiParser::MidiParser(int8 source) :
|
|
|
|
_source(source),
|
2012-09-07 22:57:14 +02:00
|
|
|
_hangingNotesCount(0),
|
2021-11-13 21:23:55 +02:00
|
|
|
_driver(nullptr),
|
2012-09-07 22:57:14 +02:00
|
|
|
_timerRate(0x4A0000),
|
2005-05-27 12:43:19 +00:00
|
|
|
_ppqn(96),
|
|
|
|
_tempo(500000),
|
2012-09-07 22:57:14 +02:00
|
|
|
_psecPerTick(5208), // 500000 / 96
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
_sysExDelay(0),
|
2005-05-27 12:43:19 +00:00
|
|
|
_autoLoop(false),
|
|
|
|
_smartJump(false),
|
2005-10-12 06:57:25 +00:00
|
|
|
_centerPitchWheelOnUnload(false),
|
2011-02-02 23:27:59 +00:00
|
|
|
_sendSustainOffOnNotesOff(false),
|
2020-05-29 17:50:14 +02:00
|
|
|
_disableAllNotesOffMidiEvents(false),
|
2020-06-12 20:07:55 +02:00
|
|
|
_disableAutoStartPlayback(false),
|
2012-09-07 22:57:14 +02:00
|
|
|
_numTracks(0),
|
|
|
|
_activeTrack(255),
|
2013-09-21 09:30:42 +02:00
|
|
|
_abortParse(false),
|
2020-05-28 20:45:43 +02:00
|
|
|
_jumpingToTick(false),
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
_doParse(true),
|
|
|
|
_pause(false) {
|
2012-09-07 22:57:14 +02:00
|
|
|
memset(_activeNotes, 0, sizeof(_activeNotes));
|
2013-05-02 14:01:13 +03:00
|
|
|
memset(_tracks, 0, sizeof(_tracks));
|
2021-11-13 21:23:55 +02:00
|
|
|
_nextEvent.start = nullptr;
|
2012-09-07 22:57:14 +02:00
|
|
|
_nextEvent.delta = 0;
|
|
|
|
_nextEvent.event = 0;
|
|
|
|
_nextEvent.length = 0;
|
2003-05-22 15:34:30 +00:00
|
|
|
}
|
2003-05-19 18:48:18 +00:00
|
|
|
|
2005-05-27 12:43:19 +00:00
|
|
|
void MidiParser::property(int prop, int value) {
|
2003-05-19 18:48:18 +00:00
|
|
|
switch (prop) {
|
|
|
|
case mpAutoLoop:
|
|
|
|
_autoLoop = (value != 0);
|
2005-10-12 06:57:25 +00:00
|
|
|
break;
|
2003-05-22 15:34:30 +00:00
|
|
|
case mpSmartJump:
|
|
|
|
_smartJump = (value != 0);
|
2005-10-12 06:57:25 +00:00
|
|
|
break;
|
|
|
|
case mpCenterPitchWheelOnUnload:
|
|
|
|
_centerPitchWheelOnUnload = (value != 0);
|
|
|
|
break;
|
2011-02-02 23:27:59 +00:00
|
|
|
case mpSendSustainOffOnNotesOff:
|
|
|
|
_sendSustainOffOnNotesOff = (value != 0);
|
|
|
|
break;
|
2020-05-29 17:50:14 +02:00
|
|
|
case mpDisableAllNotesOffMidiEvents:
|
|
|
|
_disableAllNotesOffMidiEvents = (value != 0);
|
|
|
|
break;
|
2020-06-12 20:07:55 +02:00
|
|
|
case mpDisableAutoStartPlayback:
|
|
|
|
_disableAutoStartPlayback = (value != 0);
|
2020-05-28 20:45:43 +02:00
|
|
|
break;
|
2019-11-17 08:20:01 +00:00
|
|
|
default:
|
|
|
|
break;
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-16 21:02:58 +00:00
|
|
|
void MidiParser::sendToDriver(uint32 b) {
|
2022-04-19 22:22:07 +02:00
|
|
|
if (_source < 0) {
|
|
|
|
_driver->send(b);
|
|
|
|
} else {
|
|
|
|
_driver->send(_source, b);
|
|
|
|
}
|
2010-06-16 21:02:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 17:50:14 +02:00
|
|
|
void MidiParser::sendMetaEventToDriver(byte type, byte *data, uint16 length) {
|
2022-04-19 22:22:07 +02:00
|
|
|
if (_source < 0) {
|
|
|
|
_driver->metaEvent(type, data, length);
|
|
|
|
} else {
|
|
|
|
_driver->metaEvent(_source, type, data, length);
|
|
|
|
}
|
2020-05-29 17:50:14 +02:00
|
|
|
}
|
|
|
|
|
2005-05-27 12:43:19 +00:00
|
|
|
void MidiParser::setTempo(uint32 tempo) {
|
2003-05-23 04:19:47 +00:00
|
|
|
_tempo = tempo;
|
|
|
|
if (_ppqn)
|
2012-09-07 22:57:14 +02:00
|
|
|
_psecPerTick = (tempo + (_ppqn >> 2)) / _ppqn;
|
2003-05-23 04:19:47 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 18:48:18 +00:00
|
|
|
// This is the conventional (i.e. SMF) variable length quantity
|
2005-05-27 12:43:19 +00:00
|
|
|
uint32 MidiParser::readVLQ(byte * &data) {
|
2003-05-19 18:48:18 +00:00
|
|
|
byte str;
|
|
|
|
uint32 value = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; ++i) {
|
|
|
|
str = data[0];
|
|
|
|
++data;
|
|
|
|
value = (value << 7) | (str & 0x7F);
|
|
|
|
if (!(str & 0x80))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2005-05-27 12:43:19 +00:00
|
|
|
void MidiParser::activeNote(byte channel, byte note, bool active) {
|
2003-05-22 15:34:30 +00:00
|
|
|
if (note >= 128 || channel >= 16)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (active)
|
2012-09-07 22:57:14 +02:00
|
|
|
_activeNotes[note] |= (1 << channel);
|
2003-05-22 15:34:30 +00:00
|
|
|
else
|
2012-09-07 22:57:14 +02:00
|
|
|
_activeNotes[note] &= ~(1 << channel);
|
2003-05-22 15:34:30 +00:00
|
|
|
|
|
|
|
// See if there are hanging notes that we can cancel
|
2012-09-07 22:57:14 +02:00
|
|
|
NoteTimer *ptr = _hangingNotes;
|
2003-05-22 15:34:30 +00:00
|
|
|
int i;
|
2012-09-07 22:57:14 +02:00
|
|
|
for (i = ARRAYSIZE(_hangingNotes); i; --i, ++ptr) {
|
|
|
|
if (ptr->channel == channel && ptr->note == note && ptr->timeLeft) {
|
|
|
|
ptr->timeLeft = 0;
|
|
|
|
--_hangingNotesCount;
|
2003-05-22 15:34:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
void MidiParser::hangingNote(byte channel, byte note, uint32 timeLeft, bool recycle) {
|
2021-11-13 21:23:55 +02:00
|
|
|
NoteTimer *best = nullptr;
|
2012-09-07 22:57:14 +02:00
|
|
|
NoteTimer *ptr = _hangingNotes;
|
2003-05-22 15:34:30 +00:00
|
|
|
int i;
|
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
if (_hangingNotesCount >= ARRAYSIZE(_hangingNotes)) {
|
2004-04-29 11:57:25 +00:00
|
|
|
warning("MidiParser::hangingNote(): Exceeded polyphony");
|
2003-05-22 15:34:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
for (i = ARRAYSIZE(_hangingNotes); i; --i, ++ptr) {
|
2003-05-22 15:34:30 +00:00
|
|
|
if (ptr->channel == channel && ptr->note == note) {
|
2012-09-07 22:57:14 +02:00
|
|
|
if (ptr->timeLeft && ptr->timeLeft < timeLeft && recycle)
|
2003-05-22 15:34:30 +00:00
|
|
|
return;
|
|
|
|
best = ptr;
|
2012-09-07 22:57:14 +02:00
|
|
|
if (ptr->timeLeft) {
|
2005-05-27 12:43:19 +00:00
|
|
|
if (recycle)
|
2010-06-16 21:02:58 +00:00
|
|
|
sendToDriver(0x80 | channel, note, 0);
|
2012-09-07 22:57:14 +02:00
|
|
|
--_hangingNotesCount;
|
2003-05-23 15:04:41 +00:00
|
|
|
}
|
2003-05-22 15:34:30 +00:00
|
|
|
break;
|
2012-09-07 22:57:14 +02:00
|
|
|
} else if (!best && ptr->timeLeft == 0) {
|
2003-05-22 15:34:30 +00:00
|
|
|
best = ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-07 14:42:32 +01:00
|
|
|
// Occasionally we might get a zero or negative note
|
2003-05-23 15:04:41 +00:00
|
|
|
// length, if the note should be turned on and off in
|
|
|
|
// the same iteration. For now just set it to 1 and
|
|
|
|
// we'll turn it off in the next cycle.
|
2012-09-07 22:57:14 +02:00
|
|
|
if (!timeLeft || timeLeft & 0x80000000)
|
|
|
|
timeLeft = 1;
|
2003-05-23 15:04:41 +00:00
|
|
|
|
2003-05-22 15:34:30 +00:00
|
|
|
if (best) {
|
|
|
|
best->channel = channel;
|
|
|
|
best->note = note;
|
2012-09-07 22:57:14 +02:00
|
|
|
best->timeLeft = timeLeft;
|
|
|
|
++_hangingNotesCount;
|
2003-05-22 15:34:30 +00:00
|
|
|
} else {
|
|
|
|
// We checked this up top. We should never get here!
|
2004-04-29 11:57:25 +00:00
|
|
|
warning("MidiParser::hangingNote(): Internal error");
|
2003-05-22 15:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-19 18:48:18 +00:00
|
|
|
void MidiParser::onTimer() {
|
2012-09-07 22:57:14 +02:00
|
|
|
uint32 endTime;
|
|
|
|
uint32 eventTime;
|
2003-05-19 18:48:18 +00:00
|
|
|
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
// The SysEx delay can be decreased whenever time passes,
|
|
|
|
// even if the parser does not parse events.
|
|
|
|
_sysExDelay -= (_sysExDelay > _timerRate) ? _timerRate : _sysExDelay;
|
|
|
|
|
2022-04-19 22:22:07 +02:00
|
|
|
if (!_position._playPos || !_driver || !_doParse || _pause || !_driver->isReady(_source))
|
2003-05-19 18:48:18 +00:00
|
|
|
return;
|
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
_abortParse = false;
|
|
|
|
endTime = _position._playTime + _timerRate;
|
2003-05-19 18:48:18 +00:00
|
|
|
|
2003-05-22 15:34:30 +00:00
|
|
|
// Scan our hanging notes for any
|
|
|
|
// that should be turned off.
|
2012-09-07 22:57:14 +02:00
|
|
|
if (_hangingNotesCount) {
|
|
|
|
NoteTimer *ptr = &_hangingNotes[0];
|
2003-05-22 15:34:30 +00:00
|
|
|
int i;
|
2012-09-07 22:57:14 +02:00
|
|
|
for (i = ARRAYSIZE(_hangingNotes); i; --i, ++ptr) {
|
|
|
|
if (ptr->timeLeft) {
|
|
|
|
if (ptr->timeLeft <= _timerRate) {
|
2010-06-16 21:02:58 +00:00
|
|
|
sendToDriver(0x80 | ptr->channel, ptr->note, 0);
|
2012-09-07 22:57:14 +02:00
|
|
|
ptr->timeLeft = 0;
|
|
|
|
--_hangingNotesCount;
|
2003-05-22 15:34:30 +00:00
|
|
|
} else {
|
2012-09-07 22:57:14 +02:00
|
|
|
ptr->timeLeft -= _timerRate;
|
2003-05-22 15:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 22:34:24 +02:00
|
|
|
bool loopEvent = false;
|
2012-09-07 22:57:14 +02:00
|
|
|
while (!_abortParse) {
|
|
|
|
EventInfo &info = _nextEvent;
|
2003-05-19 18:48:18 +00:00
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
eventTime = _position._lastEventTime + info.delta * _psecPerTick;
|
|
|
|
if (eventTime > endTime)
|
2003-05-19 18:48:18 +00:00
|
|
|
break;
|
|
|
|
|
2022-01-24 22:28:20 +01:00
|
|
|
if (!info.noop) {
|
|
|
|
// Process the next info.
|
|
|
|
if (info.event < 0x80) {
|
|
|
|
warning("Bad command or running status %02X", info.event);
|
|
|
|
_position._playPos = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
2003-05-19 18:48:18 +00:00
|
|
|
|
2022-01-24 22:28:20 +01:00
|
|
|
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);
|
|
|
|
}
|
2003-05-19 18:48:18 +00:00
|
|
|
|
2022-01-24 22:28:20 +01:00
|
|
|
// Player::metaEvent() in SCUMM will delete the parser object,
|
|
|
|
// so return immediately if that might have happened.
|
|
|
|
bool ret = processEvent(info);
|
|
|
|
if (!ret)
|
|
|
|
return;
|
|
|
|
}
|
2013-09-21 01:08:02 +02:00
|
|
|
|
2020-06-29 22:34:24 +02:00
|
|
|
loopEvent |= info.loop;
|
|
|
|
|
2014-01-27 00:13:58 +01:00
|
|
|
if (!_abortParse) {
|
|
|
|
_position._lastEventTime = eventTime;
|
2020-06-29 22:34:24 +02:00
|
|
|
_position._lastEventTick += info.delta;
|
2014-01-27 00:13:58 +01:00
|
|
|
parseNextEvent(_nextEvent);
|
|
|
|
}
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
if (!_abortParse) {
|
|
|
|
_position._playTime = endTime;
|
|
|
|
_position._playTick = (_position._playTime - _position._lastEventTime) / _psecPerTick + _position._lastEventTick;
|
2020-06-29 22:34:24 +02:00
|
|
|
if (loopEvent) {
|
|
|
|
// One of the processed events has looped (part of) the MIDI data.
|
|
|
|
// Infinite looping will cause the tracker to overflow eventually.
|
|
|
|
// Reset the tracker positions to prevent this from happening.
|
|
|
|
_position._playTime -= _position._lastEventTime;
|
|
|
|
_position._lastEventTime = 0;
|
|
|
|
_position._playTick -= _position._lastEventTick;
|
|
|
|
_position._lastEventTick = 0;
|
|
|
|
}
|
2003-05-23 04:19:47 +00:00
|
|
|
}
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 00:13:58 +01:00
|
|
|
bool MidiParser::processEvent(const EventInfo &info, bool fireEvents) {
|
2013-09-20 23:05:37 +02:00
|
|
|
if (info.event == 0xF0) {
|
|
|
|
// SysEx event
|
|
|
|
// Check for trailing 0xF7 -- if present, remove it.
|
2013-09-21 00:21:08 +02:00
|
|
|
if (fireEvents) {
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
if (_sysExDelay > 0)
|
|
|
|
// Don't process this event if the delay from
|
|
|
|
// the previous SysEx hasn't passed yet.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
uint16 delay;
|
2013-09-21 00:21:08 +02:00
|
|
|
if (info.ext.data[info.length-1] == 0xF7)
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
delay = _driver->sysExNoDelay(info.ext.data, (uint16)info.length-1);
|
2013-09-21 00:21:08 +02:00
|
|
|
else
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
delay = _driver->sysExNoDelay(info.ext.data, (uint16)info.length);
|
|
|
|
|
|
|
|
// Set the delay in microseconds so the next
|
|
|
|
// SysEx event will be delayed if necessary.
|
|
|
|
_sysExDelay = delay * 1000;
|
2013-09-21 00:21:08 +02:00
|
|
|
}
|
2013-09-20 23:05:37 +02:00
|
|
|
} else if (info.event == 0xFF) {
|
2014-01-27 00:08:57 +01:00
|
|
|
// 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);
|
|
|
|
} else {
|
|
|
|
stopPlaying();
|
|
|
|
if (fireEvents)
|
2020-05-29 17:50:14 +02:00
|
|
|
sendMetaEventToDriver(info.ext.type, info.ext.data, (uint16)info.length);
|
2014-01-27 00:08:57 +01:00
|
|
|
}
|
2014-01-27 00:13:58 +01:00
|
|
|
return false;
|
2014-01-27 00:08:57 +01:00
|
|
|
} else if (info.ext.type == 0x51) {
|
2013-09-20 23:05:37 +02:00
|
|
|
if (info.length >= 3) {
|
|
|
|
setTempo(info.ext.data[0] << 16 | info.ext.data[1] << 8 | info.ext.data[2]);
|
|
|
|
}
|
|
|
|
}
|
2013-09-21 00:21:08 +02:00
|
|
|
if (fireEvents)
|
2020-05-29 17:50:14 +02:00
|
|
|
sendMetaEventToDriver(info.ext.type, info.ext.data, (uint16)info.length);
|
2013-09-20 23:05:37 +02:00
|
|
|
} else {
|
2013-09-21 00:21:08 +02:00
|
|
|
if (fireEvents)
|
|
|
|
sendToDriver(info.event, info.basic.param1, info.basic.param2);
|
2013-09-20 23:05:37 +02:00
|
|
|
}
|
2014-01-27 00:13:58 +01:00
|
|
|
|
|
|
|
return true;
|
2013-09-20 23:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-19 18:48:18 +00:00
|
|
|
void MidiParser::allNotesOff() {
|
|
|
|
if (!_driver)
|
|
|
|
return;
|
|
|
|
|
2003-12-24 12:54:33 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
// Turn off all active notes
|
|
|
|
for (i = 0; i < 128; ++i) {
|
|
|
|
for (j = 0; j < 16; ++j) {
|
2012-09-07 22:57:14 +02:00
|
|
|
if (_activeNotes[i] & (1 << j)) {
|
2010-06-16 21:02:58 +00:00
|
|
|
sendToDriver(0x80 | j, i, 0);
|
2003-12-24 12:54:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-31 08:51:10 +00:00
|
|
|
// Turn off all hanging notes
|
2012-09-07 22:57:14 +02:00
|
|
|
for (i = 0; i < ARRAYSIZE(_hangingNotes); i++) {
|
|
|
|
if (_hangingNotes[i].timeLeft) {
|
|
|
|
sendToDriver(0x80 | _hangingNotes[i].channel, _hangingNotes[i].note, 0);
|
|
|
|
_hangingNotes[i].timeLeft = 0;
|
2004-05-31 08:51:10 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-07 22:57:14 +02:00
|
|
|
_hangingNotesCount = 0;
|
2004-05-31 08:51:10 +00:00
|
|
|
|
2020-05-29 17:50:14 +02:00
|
|
|
if (!_disableAllNotesOffMidiEvents) {
|
|
|
|
// To be sure, send an "All Note Off" event (but not all MIDI devices
|
|
|
|
// support this...).
|
2020-06-27 16:02:20 +02:00
|
|
|
_driver->stopAllNotes(_sendSustainOffOnNotesOff);
|
2005-10-10 07:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
memset(_activeNotes, 0, sizeof(_activeNotes));
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MidiParser::resetTracking() {
|
2003-05-23 04:19:47 +00:00
|
|
|
_position.clear();
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
2005-05-27 12:43:19 +00:00
|
|
|
bool MidiParser::setTrack(int track) {
|
2012-09-07 22:57:14 +02:00
|
|
|
if (track < 0 || track >= _numTracks)
|
2003-05-21 06:14:14 +00:00
|
|
|
return false;
|
2008-12-13 12:45:53 +00:00
|
|
|
// We allow restarting the track via setTrack when
|
|
|
|
// it isn't playing anymore. This allows us to reuse
|
2008-12-13 12:56:53 +00:00
|
|
|
// a MidiParser when a track has finished and will
|
2008-12-13 12:45:53 +00:00
|
|
|
// be restarted via setTrack by the client again.
|
|
|
|
// This isn't exactly how setTrack behaved before though,
|
|
|
|
// the old MidiParser code did not allow setTrack to be
|
|
|
|
// used to restart a track, which was already finished.
|
|
|
|
//
|
|
|
|
// TODO: Check if any engine has problem with this
|
|
|
|
// handling, if so we need to find a better way to handle
|
|
|
|
// track restarts. (KYRA relies on this working)
|
2012-09-07 22:57:14 +02:00
|
|
|
else if (track == _activeTrack && isPlaying())
|
2003-05-21 06:14:14 +00:00
|
|
|
return true;
|
|
|
|
|
2003-05-23 04:19:47 +00:00
|
|
|
if (_smartJump)
|
|
|
|
hangAllActiveNotes();
|
2020-06-27 22:16:43 +02:00
|
|
|
else if (isPlaying())
|
2003-05-23 04:19:47 +00:00
|
|
|
allNotesOff();
|
|
|
|
|
2003-05-19 18:48:18 +00:00
|
|
|
resetTracking();
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
_pause = false;
|
2012-09-07 22:57:14 +02:00
|
|
|
memset(_activeNotes, 0, sizeof(_activeNotes));
|
2020-06-12 20:07:55 +02:00
|
|
|
if (_disableAutoStartPlayback)
|
2020-05-28 20:45:43 +02:00
|
|
|
_doParse = false;
|
2020-06-04 18:19:40 +02:00
|
|
|
|
|
|
|
onTrackStart(track);
|
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
_activeTrack = track;
|
|
|
|
_position._playPos = _tracks[track];
|
|
|
|
parseNextEvent(_nextEvent);
|
2003-05-21 06:14:14 +00:00
|
|
|
return true;
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
2008-11-30 01:53:32 +00:00
|
|
|
void MidiParser::stopPlaying() {
|
2020-06-27 22:16:43 +02:00
|
|
|
if (isPlaying())
|
|
|
|
allNotesOff();
|
2008-11-30 01:53:32 +00:00
|
|
|
resetTracking();
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
_pause = false;
|
2008-11-30 01:53:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 20:45:43 +02:00
|
|
|
bool MidiParser::startPlaying() {
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
if (_activeTrack >= _numTracks || _pause)
|
2020-05-28 20:45:43 +02:00
|
|
|
return false;
|
|
|
|
if (!_position._playPos) {
|
|
|
|
_position._playPos = _tracks[_activeTrack];
|
|
|
|
parseNextEvent(_nextEvent);
|
|
|
|
}
|
|
|
|
_doParse = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
void MidiParser::pausePlaying() {
|
|
|
|
if (isPlaying() && !_pause) {
|
|
|
|
_pause = true;
|
|
|
|
allNotesOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MidiParser::resumePlaying() {
|
|
|
|
_pause = false;
|
|
|
|
}
|
|
|
|
|
2003-05-23 04:19:47 +00:00
|
|
|
void MidiParser::hangAllActiveNotes() {
|
|
|
|
// Search for note off events until we have
|
|
|
|
// accounted for every active note.
|
2012-09-07 22:57:14 +02:00
|
|
|
uint16 tempActive[128];
|
|
|
|
memcpy(tempActive, _activeNotes, sizeof (tempActive));
|
2003-07-10 04:34:44 +00:00
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
uint32 advanceTick = _position._lastEventTick;
|
2003-05-23 04:19:47 +00:00
|
|
|
while (true) {
|
2010-07-16 03:31:45 +00:00
|
|
|
int i;
|
2003-05-23 04:19:47 +00:00
|
|
|
for (i = 0; i < 128; ++i)
|
2012-09-07 22:57:14 +02:00
|
|
|
if (tempActive[i] != 0)
|
2005-05-27 12:43:19 +00:00
|
|
|
break;
|
|
|
|
if (i == 128)
|
|
|
|
break;
|
2012-09-07 22:57:14 +02:00
|
|
|
parseNextEvent(_nextEvent);
|
|
|
|
advanceTick += _nextEvent.delta;
|
|
|
|
if (_nextEvent.command() == 0x8) {
|
|
|
|
if (tempActive[_nextEvent.basic.param1] & (1 << _nextEvent.channel())) {
|
|
|
|
hangingNote(_nextEvent.channel(), _nextEvent.basic.param1, (advanceTick - _position._lastEventTick) * _psecPerTick, false);
|
|
|
|
tempActive[_nextEvent.basic.param1] &= ~(1 << _nextEvent.channel());
|
2003-05-22 15:34:30 +00:00
|
|
|
}
|
2012-09-07 22:57:14 +02:00
|
|
|
} else if (_nextEvent.event == 0xFF && _nextEvent.ext.type == 0x2F) {
|
2004-04-29 11:57:25 +00:00
|
|
|
// warning("MidiParser::hangAllActiveNotes(): Hit End of Track with active notes left");
|
2003-06-01 18:24:10 +00:00
|
|
|
for (i = 0; i < 128; ++i) {
|
2010-07-16 03:31:45 +00:00
|
|
|
for (int j = 0; j < 16; ++j) {
|
2012-09-07 22:57:14 +02:00
|
|
|
if (tempActive[i] & (1 << j)) {
|
2005-05-27 12:43:19 +00:00
|
|
|
activeNote(j, i, false);
|
2010-06-16 21:02:58 +00:00
|
|
|
sendToDriver(0x80 | j, i, 0);
|
2003-07-10 04:34:44 +00:00
|
|
|
}
|
2003-06-01 18:24:10 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-23 04:19:47 +00:00
|
|
|
break;
|
2003-05-22 15:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-23 04:19:47 +00:00
|
|
|
}
|
2003-05-22 15:34:30 +00:00
|
|
|
|
2010-11-24 15:12:43 +00:00
|
|
|
bool MidiParser::jumpToTick(uint32 tick, bool fireEvents, bool stopNotes, bool dontSendNoteOn) {
|
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore
The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.
ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.
I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.
* MIDI: Delay parser after handling SysEx events
This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.
SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.
I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.
I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.
This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.
* MIDI: Add instrument bank fallback
Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.
Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.
This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).
* KYRA: Start MIDI playback after selecting track
The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.
* KYRA: Improve stopping MIDI playback
In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).
* MIDI/KYRA: Add pausing playback to MIDI parser
* KYRA: Fix invalid track selection
If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
|
|
|
if (_activeTrack >= _numTracks || _pause)
|
2003-05-23 04:19:47 +00:00
|
|
|
return false;
|
2003-05-19 18:48:18 +00:00
|
|
|
|
2013-09-21 09:30:42 +02:00
|
|
|
assert(!_jumpingToTick); // This function is not re-entrant
|
|
|
|
_jumpingToTick = true;
|
|
|
|
|
2005-05-27 12:43:19 +00:00
|
|
|
Tracker currentPos(_position);
|
2012-09-07 22:57:14 +02:00
|
|
|
EventInfo currentEvent(_nextEvent);
|
2003-05-19 18:48:18 +00:00
|
|
|
|
2003-05-23 04:19:47 +00:00
|
|
|
resetTracking();
|
2012-09-07 22:57:14 +02:00
|
|
|
_position._playPos = _tracks[_activeTrack];
|
|
|
|
parseNextEvent(_nextEvent);
|
2003-05-23 04:19:47 +00:00
|
|
|
if (tick > 0) {
|
|
|
|
while (true) {
|
2012-09-07 22:57:14 +02:00
|
|
|
EventInfo &info = _nextEvent;
|
|
|
|
if (_position._lastEventTick + info.delta >= tick) {
|
|
|
|
_position._playTime += (tick - _position._lastEventTick) * _psecPerTick;
|
|
|
|
_position._playTick = tick;
|
2003-05-19 18:48:18 +00:00
|
|
|
break;
|
2003-05-23 04:19:47 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
_position._lastEventTick += info.delta;
|
|
|
|
_position._lastEventTime += info.delta * _psecPerTick;
|
|
|
|
_position._playTick = _position._lastEventTick;
|
|
|
|
_position._playTime = _position._lastEventTime;
|
2003-05-23 04:19:47 +00:00
|
|
|
|
2013-09-21 00:21:08 +02:00
|
|
|
// Some special processing for the fast-forward case
|
|
|
|
if (info.command() == 0x9 && dontSendNoteOn) {
|
|
|
|
// Don't send note on; doing so creates a "warble" with
|
2021-02-28 01:28:23 -08:00
|
|
|
// some instruments on the MT-32. Refer to bug #9262
|
2013-09-21 00:21:08 +02:00
|
|
|
} 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;
|
2013-09-21 09:30:42 +02:00
|
|
|
_jumpingToTick = false;
|
2013-09-21 00:21:08 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
processEvent(info, fireEvents);
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
2003-05-23 04:19:47 +00:00
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
parseNextEvent(_nextEvent);
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
2003-05-23 04:19:47 +00:00
|
|
|
}
|
2003-05-19 18:48:18 +00:00
|
|
|
|
2010-01-02 20:20:36 +00:00
|
|
|
if (stopNotes) {
|
2012-09-07 22:57:14 +02:00
|
|
|
if (!_smartJump || !currentPos._playPos) {
|
2010-01-02 20:20:36 +00:00
|
|
|
allNotesOff();
|
|
|
|
} else {
|
2012-09-07 22:57:14 +02:00
|
|
|
EventInfo targetEvent(_nextEvent);
|
2010-01-02 20:20:36 +00:00
|
|
|
Tracker targetPosition(_position);
|
2003-05-23 04:19:47 +00:00
|
|
|
|
2010-01-02 20:20:36 +00:00
|
|
|
_position = currentPos;
|
2012-09-07 22:57:14 +02:00
|
|
|
_nextEvent = currentEvent;
|
2010-01-02 20:20:36 +00:00
|
|
|
hangAllActiveNotes();
|
2003-05-23 04:19:47 +00:00
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
_nextEvent = targetEvent;
|
2010-01-02 20:20:36 +00:00
|
|
|
_position = targetPosition;
|
|
|
|
}
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
2003-05-23 04:19:47 +00:00
|
|
|
|
2012-09-07 22:57:14 +02:00
|
|
|
_abortParse = true;
|
2013-09-21 09:30:42 +02:00
|
|
|
_jumpingToTick = false;
|
2003-05-23 04:19:47 +00:00
|
|
|
return true;
|
2003-05-19 18:48:18 +00:00
|
|
|
}
|
2003-05-25 15:47:06 +00:00
|
|
|
|
|
|
|
void MidiParser::unloadMusic() {
|
2020-06-27 22:16:43 +02:00
|
|
|
if (_numTracks == 0)
|
|
|
|
// No music data loaded
|
|
|
|
return;
|
|
|
|
|
|
|
|
stopPlaying();
|
2012-09-07 22:57:14 +02:00
|
|
|
_numTracks = 0;
|
|
|
|
_activeTrack = 255;
|
|
|
|
_abortParse = true;
|
2005-10-11 17:48:16 +00:00
|
|
|
|
2005-10-12 06:57:25 +00:00
|
|
|
if (_centerPitchWheelOnUnload) {
|
|
|
|
// Center the pitch wheels in preparation for the next piece of
|
|
|
|
// music. It's not safe to do this from within allNotesOff(),
|
|
|
|
// and might not even be safe here, so we only do it if the
|
|
|
|
// client has explicitly asked for it.
|
2005-10-11 17:48:16 +00:00
|
|
|
|
2005-10-12 06:57:25 +00:00
|
|
|
if (_driver) {
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
2010-06-16 21:02:58 +00:00
|
|
|
sendToDriver(0xE0 | i, 0, 0x40);
|
2005-10-12 06:57:25 +00:00
|
|
|
}
|
2005-10-11 17:48:16 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-25 15:47:06 +00:00
|
|
|
}
|