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.
|
2002-04-21 17:46:42 +00: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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 01:34:17 +00:00
|
|
|
*
|
2002-04-21 17:46:42 +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 01:34:17 +00:00
|
|
|
*
|
2002-04-21 17:46:42 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-10-28 10:27:50 +00:00
|
|
|
#ifndef AUDIO_MIDIDRV_H
|
|
|
|
#define AUDIO_MIDIDRV_H
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/scummsys.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/str.h"
|
2020-05-30 04:30:40 +00:00
|
|
|
#include "common/stream.h"
|
2003-10-18 13:04:59 +00:00
|
|
|
#include "common/timer.h"
|
2020-02-19 17:51:53 +00:00
|
|
|
#include "common/array.h"
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2002-11-26 16:54:58 +00:00
|
|
|
class MidiChannel;
|
2003-10-02 22:52:57 +00:00
|
|
|
|
2020-11-30 01:54:01 +00:00
|
|
|
/**
|
|
|
|
* @defgroup audio_mididrv MIDI drivers
|
|
|
|
* @ingroup audio
|
|
|
|
*
|
|
|
|
* @brief API for managing MIDI drivers.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-06-21 21:36:36 +00:00
|
|
|
/**
|
|
|
|
* Music types that music drivers can implement and engines can rely on.
|
|
|
|
*/
|
|
|
|
enum MusicType {
|
2010-08-11 19:32:07 +00:00
|
|
|
MT_INVALID = -1, // Invalid output
|
|
|
|
MT_AUTO = 0, // Auto
|
|
|
|
MT_NULL, // Null
|
|
|
|
MT_PCSPK, // PC Speaker
|
|
|
|
MT_PCJR, // PCjr
|
|
|
|
MT_CMS, // CMS
|
|
|
|
MT_ADLIB, // AdLib
|
|
|
|
MT_C64, // C64
|
|
|
|
MT_AMIGA, // Amiga
|
|
|
|
MT_APPLEIIGS, // Apple IIGS
|
|
|
|
MT_TOWNS, // FM-TOWNS
|
|
|
|
MT_PC98, // PC98
|
2020-07-11 16:05:43 +00:00
|
|
|
MT_SEGACD, // SegaCD
|
2010-08-11 19:32:07 +00:00
|
|
|
MT_GM, // General MIDI
|
|
|
|
MT_MT32, // MT-32
|
|
|
|
MT_GS // Roland GS
|
2003-10-02 22:52:57 +00:00
|
|
|
};
|
|
|
|
|
2005-12-26 11:18:25 +00:00
|
|
|
/**
|
2010-06-21 21:36:36 +00:00
|
|
|
* A set of flags to be passed to detectDevice() which can be used to
|
2005-12-29 16:55:21 +00:00
|
|
|
* specify what kind of music driver is preferred / accepted.
|
|
|
|
*
|
2011-03-01 08:32:17 +00:00
|
|
|
* The flags (except for MDT_PREFER_MT32 and MDT_PREFER_GM) indicate whether a
|
|
|
|
* given driver type is acceptable. E.g. the TOWNS music driver could be
|
|
|
|
* returned by detectDevice if and only if MDT_TOWNS is specified.
|
|
|
|
*
|
|
|
|
* MDT_PREFER_MT32 and MDT_PREFER_GM indicate the MIDI device type to use when
|
|
|
|
* no device is selected in the music options, or when the MIDI device selected
|
|
|
|
* does not match the requirements of a game engine. With these flags, more
|
|
|
|
* priority is given to an MT-32 device, or a GM device respectively.
|
|
|
|
*
|
2005-12-29 16:55:21 +00:00
|
|
|
* @todo Rename MidiDriverFlags to MusicDriverFlags
|
2005-12-26 11:18:25 +00:00
|
|
|
*/
|
|
|
|
enum MidiDriverFlags {
|
2010-08-11 18:54:56 +00:00
|
|
|
MDT_NONE = 0,
|
2011-03-23 11:58:01 +00:00
|
|
|
MDT_PCSPK = 1 << 0, // PC Speaker: Maps to MT_PCSPK and MT_PCJR
|
|
|
|
MDT_CMS = 1 << 1, // Creative Music System / Gameblaster: Maps to MT_CMS
|
2010-08-11 19:32:07 +00:00
|
|
|
MDT_PCJR = 1 << 2, // Tandy/PC Junior driver
|
|
|
|
MDT_ADLIB = 1 << 3, // AdLib: Maps to MT_ADLIB
|
|
|
|
MDT_C64 = 1 << 4,
|
|
|
|
MDT_AMIGA = 1 << 5,
|
|
|
|
MDT_APPLEIIGS = 1 << 6,
|
|
|
|
MDT_TOWNS = 1 << 7, // FM-TOWNS: Maps to MT_TOWNS
|
2020-07-11 16:05:43 +00:00
|
|
|
MDT_PC98 = 1 << 8, // PC-98: Maps to MT_PC98
|
|
|
|
MDT_SEGACD = 1 << 9,
|
|
|
|
MDT_MIDI = 1 << 10, // Real MIDI
|
|
|
|
MDT_PREFER_MT32 = 1 << 11, // MT-32 output is preferred
|
|
|
|
MDT_PREFER_GM = 1 << 12, // GM output is preferred
|
|
|
|
MDT_PREFER_FLUID= 1 << 13 // FluidSynth driver is preferred
|
2004-12-02 00:33:42 +00:00
|
|
|
};
|
2003-10-18 00:22:46 +00:00
|
|
|
|
2011-03-23 12:04:46 +00:00
|
|
|
/**
|
|
|
|
* TODO: Document this, give it a better name.
|
|
|
|
*/
|
|
|
|
class MidiDriver_BASE {
|
|
|
|
public:
|
2020-07-27 12:43:21 +00:00
|
|
|
static const uint8 MIDI_CHANNEL_COUNT = 16;
|
|
|
|
static const uint8 MIDI_RHYTHM_CHANNEL = 9;
|
|
|
|
|
|
|
|
static const byte MIDI_COMMAND_NOTE_OFF = 0x80;
|
|
|
|
static const byte MIDI_COMMAND_NOTE_ON = 0x90;
|
|
|
|
static const byte MIDI_COMMAND_POLYPHONIC_AFTERTOUCH = 0xA0;
|
|
|
|
static const byte MIDI_COMMAND_CONTROL_CHANGE = 0xB0;
|
|
|
|
static const byte MIDI_COMMAND_PROGRAM_CHANGE = 0xC0;
|
|
|
|
static const byte MIDI_COMMAND_CHANNEL_AFTERTOUCH = 0xD0;
|
|
|
|
static const byte MIDI_COMMAND_PITCH_BEND = 0xE0;
|
|
|
|
static const byte MIDI_COMMAND_SYSTEM = 0xF0;
|
|
|
|
|
|
|
|
static const byte MIDI_CONTROLLER_BANK_SELECT_MSB = 0x00;
|
|
|
|
static const byte MIDI_CONTROLLER_MODULATION = 0x01;
|
|
|
|
static const byte MIDI_CONTROLLER_DATA_ENTRY_MSB = 0x06;
|
|
|
|
static const byte MIDI_CONTROLLER_VOLUME = 0x07;
|
|
|
|
static const byte MIDI_CONTROLLER_PANNING = 0x0A;
|
|
|
|
static const byte MIDI_CONTROLLER_EXPRESSION = 0x0B;
|
|
|
|
static const byte MIDI_CONTROLLER_BANK_SELECT_LSB = 0x20;
|
|
|
|
static const byte MIDI_CONTROLLER_DATA_ENTRY_LSB = 0x26;
|
|
|
|
static const byte MIDI_CONTROLLER_SUSTAIN = 0x40;
|
|
|
|
static const byte MIDI_CONTROLLER_REVERB = 0x5B;
|
|
|
|
static const byte MIDI_CONTROLLER_CHORUS = 0x5D;
|
|
|
|
static const byte MIDI_CONTROLLER_RPN_LSB = 0x64;
|
|
|
|
static const byte MIDI_CONTROLLER_RPN_MSB = 0x65;
|
|
|
|
static const byte MIDI_CONTROLLER_RESET_ALL_CONTROLLERS = 0x79;
|
|
|
|
static const byte MIDI_CONTROLLER_ALL_NOTES_OFF = 0x7B;
|
|
|
|
static const byte MIDI_CONTROLLER_OMNI_ON = 0x7C;
|
|
|
|
static const byte MIDI_CONTROLLER_OMNI_OFF = 0x7D;
|
|
|
|
static const byte MIDI_CONTROLLER_MONO_ON = 0x7E;
|
|
|
|
static const byte MIDI_CONTROLLER_POLY_ON = 0x7F;
|
|
|
|
|
|
|
|
static const byte MIDI_RPN_PITCH_BEND_SENSITIVITY_MSB = 0x00;
|
|
|
|
static const byte MIDI_RPN_PITCH_BEND_SENSITIVITY_LSB = 0x00;
|
|
|
|
static const byte MIDI_RPN_NULL = 0x7F;
|
|
|
|
|
|
|
|
static const uint16 MIDI_PITCH_BEND_DEFAULT = 0x2000;
|
|
|
|
|
2020-02-19 17:51:53 +00:00
|
|
|
MidiDriver_BASE();
|
|
|
|
|
|
|
|
virtual ~MidiDriver_BASE();
|
2011-03-23 12:04:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Output a packed midi command to the midi stream.
|
|
|
|
* The 'lowest' byte (i.e. b & 0xFF) is the status
|
|
|
|
* code, then come (if used) the first and second
|
|
|
|
* opcode.
|
|
|
|
*/
|
|
|
|
virtual void send(uint32 b) = 0;
|
|
|
|
|
2020-05-29 15:50:14 +00:00
|
|
|
/**
|
|
|
|
* Send a MIDI command from a specific source. If the MIDI driver
|
|
|
|
* does not support multiple sources, the source parameter is
|
|
|
|
* ignored.
|
|
|
|
*/
|
|
|
|
virtual void send(int8 source, uint32 b) { send(b); }
|
2020-02-19 17:51:53 +00:00
|
|
|
|
2011-03-23 12:04:46 +00:00
|
|
|
/**
|
|
|
|
* Output a midi command to the midi stream. Convenience wrapper
|
|
|
|
* around the usual 'packed' send method.
|
|
|
|
*
|
|
|
|
* Do NOT use this for sysEx transmission; instead, use the sysEx()
|
|
|
|
* method below.
|
|
|
|
*/
|
2020-02-19 17:51:53 +00:00
|
|
|
void send(byte status, byte firstOp, byte secondOp);
|
2021-05-04 08:45:03 +00:00
|
|
|
|
2020-05-29 15:50:14 +00:00
|
|
|
/**
|
|
|
|
* Send a MIDI command from a specific source. If the MIDI driver
|
|
|
|
* does not support multiple sources, the source parameter is
|
|
|
|
* ignored.
|
|
|
|
*/
|
|
|
|
void send(int8 source, byte status, byte firstOp, byte secondOp);
|
|
|
|
|
2011-03-23 12:04:46 +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 21:27:30 +00:00
|
|
|
* Transmit a SysEx to the MIDI device.
|
2011-03-23 12:04:46 +00:00
|
|
|
*
|
|
|
|
* The given msg MUST NOT contain the usual SysEx frame, i.e.
|
|
|
|
* do NOT include the leading 0xF0 and the trailing 0xF7.
|
|
|
|
*
|
|
|
|
* Furthermore, the maximal supported length of a SysEx
|
|
|
|
* is 264 bytes. Passing longer buffers can lead to
|
|
|
|
* undefined behavior (most likely, a crash).
|
|
|
|
*/
|
|
|
|
virtual void sysEx(const byte *msg, uint16 length) { }
|
|
|
|
|
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 21:27:30 +00:00
|
|
|
/**
|
|
|
|
* Transmit a SysEx to the MIDI device and return the necessary
|
|
|
|
* delay until the next SysEx event in milliseconds.
|
|
|
|
*
|
|
|
|
* This can be used to implement an alternate delay method than the
|
|
|
|
* OSystem::delayMillis function used by most sysEx implementations.
|
|
|
|
* Note that not every driver needs a delay, or supports this method.
|
2021-05-04 08:45:03 +00:00
|
|
|
* In this case, 0 is returned and the driver itself will do a delay
|
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 21:27:30 +00:00
|
|
|
* if necessary.
|
|
|
|
*
|
|
|
|
* For information on the SysEx data requirements, see the sysEx method.
|
|
|
|
*/
|
|
|
|
virtual uint16 sysExNoDelay(const byte *msg, uint16 length) { sysEx(msg, length); return 0; }
|
|
|
|
|
2011-03-23 12:04:46 +00:00
|
|
|
// TODO: Document this.
|
|
|
|
virtual void metaEvent(byte type, byte *data, uint16 length) { }
|
2020-02-19 17:51:53 +00:00
|
|
|
|
2020-05-29 15:50:14 +00:00
|
|
|
/**
|
|
|
|
* Send a meta event from a specific source. If the MIDI driver
|
|
|
|
* does not support multiple sources, the source parameter is
|
|
|
|
* ignored.
|
|
|
|
*/
|
|
|
|
virtual void metaEvent(int8 source, byte type, byte *data, uint16 length) { metaEvent(type, data, length); }
|
2020-06-26 14:27:33 +00:00
|
|
|
|
2020-06-27 14:02:20 +00:00
|
|
|
/**
|
|
|
|
* Stops all currently active notes. Specify stopSustainedNotes if
|
|
|
|
* the MIDI data makes use of the sustain controller to also stop
|
|
|
|
* sustained notes.
|
|
|
|
*
|
|
|
|
* Usually, the MIDI parser tracks active notes and terminates them
|
|
|
|
* when playback is stopped. This method should be used as a backup
|
|
|
|
* to silence the MIDI output in case the MIDI parser makes a
|
|
|
|
* mistake when tracking acive notes. It can also be used when
|
|
|
|
* quitting or pausing a game.
|
|
|
|
*
|
|
|
|
* By default, this method sends an All Notes Off message and, if
|
|
|
|
* stopSustainedNotes is true, a Sustain off message on all MIDI
|
|
|
|
* channels. Driver implementations can override this if they want
|
|
|
|
* to implement this functionality in a different way.
|
|
|
|
*/
|
|
|
|
virtual void stopAllNotes(bool stopSustainedNotes = false);
|
|
|
|
|
2020-06-26 14:27:33 +00:00
|
|
|
/**
|
|
|
|
* A driver implementation might need time to prepare playback of
|
|
|
|
* a track. Use this function to check if the driver is ready to
|
|
|
|
* receive MIDI events.
|
|
|
|
*/
|
|
|
|
virtual bool isReady() { return true; }
|
|
|
|
|
2020-02-19 17:51:53 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables midi dumping to a 'dump.mid' file and to debug messages on screen
|
|
|
|
* It's set by '--dump-midi' command line parameter
|
|
|
|
*/
|
|
|
|
bool _midiDumpEnable;
|
|
|
|
|
|
|
|
/** Used for MIDI dumping delta calculation */
|
|
|
|
uint32 _prevMillis;
|
|
|
|
|
|
|
|
/** Stores all MIDI events, will be written to disk after an engine quits */
|
|
|
|
Common::Array<byte> _midiDumpCache;
|
|
|
|
|
|
|
|
/** Initialize midi dumping mechanism, called only if enabled */
|
|
|
|
void midiDumpInit();
|
|
|
|
|
|
|
|
/** Handles MIDI file variable length dumping */
|
|
|
|
int midiDumpVarLength(const uint32 &delta);
|
|
|
|
|
|
|
|
/** Handles MIDI file time delta dumping */
|
|
|
|
void midiDumpDelta();
|
|
|
|
|
|
|
|
/** Performs dumping of MIDI commands, called only if enabled */
|
|
|
|
void midiDumpDo(uint32 b);
|
|
|
|
|
|
|
|
/** Performs dumping of MIDI SysEx commands, called only if enabled */
|
|
|
|
void midiDumpSysEx(const byte *msg, uint16 length);
|
|
|
|
|
|
|
|
/** Writes the captured MIDI events to disk, called only if enabled */
|
|
|
|
void midiDumpFinish();
|
|
|
|
|
2011-03-23 12:04:46 +00:00
|
|
|
};
|
|
|
|
|
2005-12-29 16:55:21 +00:00
|
|
|
/**
|
|
|
|
* Abstract MIDI Driver Class
|
|
|
|
*
|
|
|
|
* @todo Rename MidiDriver to MusicDriver
|
|
|
|
*/
|
2011-03-23 12:04:46 +00:00
|
|
|
class MidiDriver : public MidiDriver_BASE {
|
2004-12-02 00:33:42 +00:00
|
|
|
public:
|
2010-06-29 00:29:35 +00:00
|
|
|
/**
|
|
|
|
* The device handle.
|
|
|
|
*
|
|
|
|
* The value 0 is reserved for an invalid device for now.
|
|
|
|
* TODO: Maybe we should use -1 (i.e. 0xFFFFFFFF) as
|
|
|
|
* invalid device?
|
|
|
|
*/
|
2010-06-21 21:36:36 +00:00
|
|
|
typedef uint32 DeviceHandle;
|
2005-12-30 14:18:21 +00:00
|
|
|
|
2010-06-21 21:36:36 +00:00
|
|
|
enum DeviceStringType {
|
|
|
|
kDriverName,
|
|
|
|
kDriverId,
|
2011-06-05 22:17:24 +00:00
|
|
|
kDeviceName,
|
2010-06-21 21:36:36 +00:00
|
|
|
kDeviceId
|
|
|
|
};
|
2004-12-02 00:33:42 +00:00
|
|
|
|
2011-10-23 14:14:41 +00:00
|
|
|
static Common::String musicType2GUIO(uint32 musicType);
|
2010-06-15 10:56:12 +00:00
|
|
|
|
2010-06-25 22:37:19 +00:00
|
|
|
/** Create music driver matching the given device handle, or NULL if there is no match. */
|
2010-06-21 21:36:36 +00:00
|
|
|
static MidiDriver *createMidi(DeviceHandle handle);
|
|
|
|
|
2010-06-25 22:37:19 +00:00
|
|
|
/** Returns device handle based on the present devices and the flags parameter. */
|
2010-06-21 21:36:36 +00:00
|
|
|
static DeviceHandle detectDevice(int flags);
|
2010-07-21 18:17:51 +00:00
|
|
|
|
2010-06-25 22:37:19 +00:00
|
|
|
/** Find the music driver matching the given driver name/description. */
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
static DeviceHandle getDeviceHandle(const Common::String &identifier);
|
2004-12-02 00:33:42 +00:00
|
|
|
|
2011-06-05 16:26:25 +00:00
|
|
|
/** Check whether the device with the given handle is available. */
|
|
|
|
static bool checkDevice(DeviceHandle handle);
|
|
|
|
|
2010-06-21 21:36:36 +00:00
|
|
|
/** Get the music type matching the given device handle, or MT_AUTO if there is no match. */
|
|
|
|
static MusicType getMusicType(DeviceHandle handle);
|
2004-12-02 00:33:42 +00:00
|
|
|
|
2010-06-25 22:37:19 +00:00
|
|
|
/** Get the device description string matching the given device handle and the given type. */
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
static Common::String getDeviceString(DeviceHandle handle, DeviceStringType type);
|
2004-12-02 00:33:42 +00:00
|
|
|
|
2020-02-19 17:51:53 +00:00
|
|
|
/** Common operations to be done by all drivers on start of send */
|
|
|
|
void midiDriverCommonSend(uint32 b);
|
|
|
|
|
|
|
|
/** Common operations to be done by all drivers on start of sysEx */
|
|
|
|
void midiDriverCommonSysEx(const byte *msg, uint16 length);
|
|
|
|
|
2010-06-21 21:36:36 +00:00
|
|
|
private:
|
|
|
|
// If detectDevice() detects MT32 and we have a preferred MT32 device
|
|
|
|
// we use this to force getMusicType() to return MT_MT32 so that we don't
|
|
|
|
// have to rely on the 'True Roland MT-32' config manager setting (since nobody
|
|
|
|
// would possibly think about activating 'True Roland MT-32' when he has set
|
2010-06-25 22:37:19 +00:00
|
|
|
// 'Music Driver' to '<default>')
|
2010-06-21 21:36:36 +00:00
|
|
|
static bool _forceTypeMT32;
|
2004-12-02 00:33:42 +00:00
|
|
|
|
2002-04-13 18:34:11 +00:00
|
|
|
public:
|
2003-05-23 04:19:47 +00:00
|
|
|
virtual ~MidiDriver() { }
|
|
|
|
|
2005-04-03 22:01:38 +00:00
|
|
|
static const byte _mt32ToGm[128];
|
|
|
|
static const byte _gmToMt32[128];
|
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/**
|
|
|
|
* Error codes returned by open.
|
|
|
|
* Can be converted to a string with getErrorName().
|
|
|
|
*/
|
2002-04-13 18:34:11 +00:00
|
|
|
enum {
|
|
|
|
MERR_CANNOT_CONNECT = 1,
|
2002-12-11 16:09:58 +00:00
|
|
|
// MERR_STREAMING_NOT_AVAILABLE = 2,
|
2002-04-13 18:34:11 +00:00
|
|
|
MERR_DEVICE_NOT_AVAILABLE = 3,
|
2002-12-25 00:36:04 +00:00
|
|
|
MERR_ALREADY_OPEN = 4
|
2002-04-13 18:34:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2003-05-23 04:19:47 +00:00
|
|
|
// PROP_TIMEDIV = 1,
|
2003-09-25 22:32:05 +00:00
|
|
|
PROP_OLD_ADLIB = 2,
|
2012-09-30 23:51:04 +00:00
|
|
|
PROP_CHANNEL_MASK = 3,
|
|
|
|
// HACK: Not so nice, but our SCUMM AdLib code is in audio/
|
2020-07-27 12:43:21 +00:00
|
|
|
PROP_SCUMM_OPL3 = 4,
|
|
|
|
/**
|
|
|
|
* Set this to enable or disable scaling of the MIDI channel
|
|
|
|
* volume with the user volume settings (including setting it
|
|
|
|
* to 0 when Mute All is selected). This is currently
|
|
|
|
* implemented in the MT-32/GM drivers (regular and Miles AIL).
|
|
|
|
*
|
|
|
|
* Default is enabled for the regular driver, and disabled for
|
|
|
|
* the Miles AIL driver.
|
|
|
|
*/
|
|
|
|
PROP_USER_VOLUME_SCALING = 5,
|
|
|
|
/**
|
|
|
|
* Set this property to indicate that the MIDI data used by the
|
|
|
|
* game has reversed stereo panning compared to its intended
|
|
|
|
* device. The MT-32 has reversed stereo panning compared to
|
|
|
|
* the MIDI specification and some game developers chose to
|
|
|
|
* stick to the MIDI specification.
|
|
|
|
*
|
|
|
|
* Do not confuse this with the _midiDeviceReversePanning flag,
|
|
|
|
* which indicates that the output MIDI device has reversed
|
|
|
|
* stereo panning compared to the intended MIDI device targeted
|
|
|
|
* by the MIDI data. This is set by the MT-32/GM driver when
|
|
|
|
* MT-32 data is played on a GM device or the other way around.
|
|
|
|
* Both flags can be set, which results in no change to the
|
|
|
|
* panning.
|
|
|
|
*
|
|
|
|
* Set this property before opening the driver, to make sure
|
|
|
|
* that the default panning is set correctly.
|
|
|
|
*/
|
|
|
|
PROP_MIDI_DATA_REVERSE_PANNING = 6
|
2002-04-13 18:34:11 +00:00
|
|
|
};
|
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/**
|
|
|
|
* Open the midi driver.
|
|
|
|
* @return 0 if successful, otherwise an error code.
|
|
|
|
*/
|
2002-12-11 16:09:58 +00:00
|
|
|
virtual int open() = 0;
|
2002-04-13 18:34:11 +00:00
|
|
|
|
2011-03-21 14:42:17 +00:00
|
|
|
/**
|
|
|
|
* Check whether the midi driver has already been opened.
|
|
|
|
*/
|
|
|
|
virtual bool isOpen() const = 0;
|
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/** Close the midi driver. */
|
2002-04-13 18:34:11 +00:00
|
|
|
virtual void close() = 0;
|
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/** Get or set a property. */
|
2003-05-17 14:27:58 +00:00
|
|
|
virtual uint32 property(int prop, uint32 param) { return 0; }
|
2002-04-13 18:34:11 +00:00
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/** Retrieve a string representation of an error code. */
|
2002-12-11 16:09:58 +00:00
|
|
|
static const char *getErrorName(int error_code);
|
2002-10-21 09:32:38 +00:00
|
|
|
|
|
|
|
// HIGH-LEVEL SEMANTIC METHODS
|
2007-02-16 13:30:41 +00:00
|
|
|
virtual void setPitchBendRange(byte channel, uint range) {
|
2020-07-27 12:43:21 +00:00
|
|
|
send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_RPN_MSB, MIDI_RPN_PITCH_BEND_SENSITIVITY_MSB);
|
|
|
|
send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_RPN_LSB, MIDI_RPN_PITCH_BEND_SENSITIVITY_LSB);
|
|
|
|
send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_DATA_ENTRY_MSB, range); // Semi-tones
|
|
|
|
send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_DATA_ENTRY_LSB, 0); // Cents
|
|
|
|
send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_RPN_MSB, MIDI_RPN_NULL);
|
|
|
|
send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_RPN_LSB, MIDI_RPN_NULL);
|
2002-11-04 18:29:26 +00:00
|
|
|
}
|
2002-11-21 19:06:42 +00:00
|
|
|
|
MIDI: Send a reset MIDI device signal on startup.
This is currently done in the engine code. I adapted AGI, AGOS, DRACI,
GROOVIE, LURE, MADE, QUEEN, SAGA, SKY, TINSEL and TOUCHE to send a reset
device on startup. The sound output still works fine (started up a game
from every engine), so this should hopefully not introduce any regressions.
As far as I can tell it seems that SCUMM does send a proper device reset, so
I did not touch it. KYRA only sends a proper reset for MT-32 currently. I am
not sure about SCI though.
This fixes bug #3066826 "SIMON: MIDI notes off when using RTL after SCI".
svn-id: r52736
2010-09-15 22:00:20 +00:00
|
|
|
/**
|
|
|
|
* Send a Roland MT-32 reset sysEx to the midi device.
|
|
|
|
*/
|
|
|
|
void sendMT32Reset();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a General MIDI reset sysEx to the midi device.
|
|
|
|
*/
|
|
|
|
void sendGMReset();
|
|
|
|
|
2006-02-27 01:59:07 +00:00
|
|
|
virtual void sysEx_customInstrument(byte channel, uint32 type, const byte *instr) { }
|
2007-02-16 13:30:41 +00:00
|
|
|
|
2002-11-21 19:06:42 +00:00
|
|
|
// Timing functions - MidiDriver now operates timers
|
2006-06-24 09:34:49 +00:00
|
|
|
virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-10-17 19:39:54 +00:00
|
|
|
/** The time in microseconds between invocations of the timer callback. */
|
2009-11-02 21:54:57 +00:00
|
|
|
virtual uint32 getBaseTempo() = 0;
|
2002-11-26 16:54:58 +00:00
|
|
|
|
|
|
|
// Channel allocation functions
|
|
|
|
virtual MidiChannel *allocateChannel() = 0;
|
|
|
|
virtual MidiChannel *getPercussionChannel() = 0;
|
2020-05-30 04:30:40 +00:00
|
|
|
|
|
|
|
// Allow an engine to supply its own soundFont data. This stream will be destroyed after use.
|
|
|
|
virtual void setEngineSoundFont(Common::SeekableReadStream *soundFontData) { }
|
|
|
|
|
|
|
|
// Does this driver accept soundFont data?
|
|
|
|
virtual bool acceptsSoundFontData() { return false; }
|
2002-11-26 16:54:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MidiChannel {
|
|
|
|
public:
|
2005-06-20 18:27:33 +00:00
|
|
|
virtual ~MidiChannel() {}
|
|
|
|
|
2002-12-18 07:13:42 +00:00
|
|
|
virtual MidiDriver *device() = 0;
|
2002-12-18 07:48:35 +00:00
|
|
|
virtual byte getNumber() = 0;
|
2002-11-26 16:54:58 +00:00
|
|
|
virtual void release() = 0;
|
|
|
|
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void send(uint32 b) = 0; // 4-bit channel portion is ignored
|
2003-08-08 11:54:24 +00:00
|
|
|
|
2002-11-26 16:54:58 +00:00
|
|
|
// Regular messages
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void noteOff(byte note) = 0;
|
|
|
|
virtual void noteOn(byte note, byte velocity) = 0;
|
|
|
|
virtual void programChange(byte program) = 0;
|
|
|
|
virtual void pitchBend(int16 bend) = 0; // -0x2000 to +0x1FFF
|
2002-11-26 16:54:58 +00:00
|
|
|
|
|
|
|
// Control Change messages
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void controlChange(byte control, byte value) = 0;
|
2020-07-27 12:43:21 +00:00
|
|
|
virtual void modulationWheel(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_MODULATION, value); }
|
|
|
|
virtual void volume(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_VOLUME, value); }
|
|
|
|
virtual void panPosition(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_PANNING, value); }
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void pitchBendFactor(byte value) = 0;
|
2019-06-22 21:30:37 +00:00
|
|
|
virtual void transpose(int8 value) {}
|
2006-05-12 12:03:36 +00:00
|
|
|
virtual void detune(byte value) { controlChange(17, value); }
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void priority(byte value) { }
|
2020-07-27 12:43:21 +00:00
|
|
|
virtual void sustain(bool value) { controlChange(MidiDriver::MIDI_CONTROLLER_SUSTAIN, value ? 1 : 0); }
|
|
|
|
virtual void effectLevel(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_REVERB, value); }
|
|
|
|
virtual void chorusLevel(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_CHORUS, value); }
|
|
|
|
virtual void allNotesOff() { controlChange(MidiDriver::MIDI_CONTROLLER_ALL_NOTES_OFF, 0); }
|
2002-11-26 16:54:58 +00:00
|
|
|
|
|
|
|
// SysEx messages
|
2006-02-27 01:59:07 +00:00
|
|
|
virtual void sysEx_customInstrument(uint32 type, const byte *instr) = 0;
|
2002-04-13 18:34:11 +00:00
|
|
|
};
|
2020-11-30 01:54:01 +00:00
|
|
|
/** @} */
|
2004-02-06 08:35:24 +00:00
|
|
|
#endif
|