ScummVM API documentation
MidiDriver_MT32GM Class Reference

#include <mt32gm.h>

Inheritance diagram for MidiDriver_MT32GM:
MidiDriver_Multisource MidiDriver MidiDriver_BASE AGOS::MidiDriver_Accolade_MT32 Audio::MidiDriver_Miles_Midi Ultima::Nuvie::MidiDriver_M_MT32

Classes

struct  ActiveNote
 
struct  MidiChannelControlData
 
struct  MidiSource
 
struct  SysExData
 

Public Member Functions

 MidiDriver_MT32GM (MusicType midiType)
 
int open () override
 
virtual int open (MidiDriver *driver, bool nativeMT32)
 
void close () override
 
bool isOpen () const override
 
bool isReady (int8 source=-1) override
 
uint32 property (int prop, uint32 param) override
 
void send (uint32 b) override
 
void send (int8 source, uint32 b) override
 
void sysEx (const byte *msg, uint16 length) override
 
uint16 sysExNoDelay (const byte *msg, uint16 length) override
 
void sysExQueue (const byte *msg, uint16 length, int8 source=-1)
 
uint16 sysExMT32 (const byte *msg, uint16 length, const uint32 targetAddress, bool queue=false, bool delay=true, int8 source=-1)
 
void metaEvent (int8 source, byte type, byte *data, uint16 length) override
 
void stopAllNotes (bool stopSustainedNotes=false) override
 
void clearSysExQueue ()
 
MidiChannelallocateChannel () override
 
MidiChannelgetPercussionChannel () override
 
uint32 getBaseTempo () override
 
virtual bool allocateSourceChannels (uint8 source, uint8 numChannels)
 
void deinitSource (uint8 source) override
 
- Public Member Functions inherited from MidiDriver_Multisource
void setSourceType (SourceType type)
 
void setSourceType (uint8 source, SourceType type)
 
void setSourceVolume (uint16 volume)
 
void setSourceVolume (uint8 source, uint16 volume)
 
void resetSourceVolume ()
 
void resetSourceVolume (uint8 source)
 
void setSourceNeutralVolume (uint16 volume)
 
void setSourceNeutralVolume (uint8 source, uint16 volume)
 
void startFade (uint16 duration, uint16 targetVolume)
 
void startFade (uint8 source, uint16 duration, uint16 targetVolume)
 
void abortFade (FadeAbortType abortType=FADE_ABORT_TYPE_END_VOLUME)
 
void abortFade (uint8 source, FadeAbortType abortType=FADE_ABORT_TYPE_END_VOLUME)
 
bool isFading ()
 
bool isFading (uint8 source)
 
void setControllerDefault (ControllerDefaultType type)
 
void setControllerDefault (ControllerDefaultType type, int16 value)
 
void setControllerDefaults (ControllerDefaultType type, int16 *values)
 
void clearControllerDefault (ControllerDefaultType type)
 
void setInstrumentRemapping (const byte *instrumentRemapping)
 
void syncSoundSettings ()
 
void setTimerCallback (void *timer_param, Common::TimerManager::TimerProc timer_proc) override
 
- Public Member Functions inherited from MidiDriver
void midiDriverCommonSend (uint32 b)
 
void midiDriverCommonSysEx (const byte *msg, uint16 length)
 
virtual void setPitchBendRange (byte channel, uint range)
 
void sendMT32Reset ()
 
void sendGMReset ()
 
virtual void setEngineSoundFont (Common::SeekableReadStream *soundFontData)
 
virtual bool acceptsSoundFontData ()
 
- Public Member Functions inherited from MidiDriver_BASE
void send (byte status, byte firstOp, byte secondOp)
 
void send (int8 source, byte status, byte firstOp, byte secondOp)
 
virtual void metaEvent (byte type, byte *data, uint16 length)
 

Static Public Member Functions

static void timerCallback (void *data)
 
- Static Public Member Functions inherited from MidiDriver
static Common::String musicType2GUIO (uint32 musicType)
 
static MidiDrivercreateMidi (DeviceHandle handle)
 
static DeviceHandle detectDevice (int flags)
 
static DeviceHandle getDeviceHandle (const Common::String &identifier)
 
static bool checkDevice (DeviceHandle handle)
 
static MusicType getMusicType (DeviceHandle handle)
 
static Common::String getDeviceString (DeviceHandle handle, DeviceStringType type)
 
static const char * getErrorName (int error_code)
 

Static Public Attributes

static const byte MT32_DEFAULT_INSTRUMENTS [8]
 
static const byte MT32_DEFAULT_PANNING [8]
 
static const uint8 MT32_DEFAULT_CHANNEL_VOLUME = 102
 
static const uint8 GM_DEFAULT_CHANNEL_VOLUME = 100
 
static const uint8 GS_DRUMKIT_FALLBACK_MAP [128]
 
static const uint8 MT32_DISPLAY_NUM_CHARS = 20
 
static const uint32 MT32_DISPLAY_MEMORY_ADDRESS = 0x20 << 14
 
- Static Public Attributes inherited from MidiDriver_Multisource
static const uint8 MAXIMUM_SOURCES = 10
 
static const uint16 DEFAULT_SOURCE_NEUTRAL_VOLUME = 255
 
- Static Public Attributes inherited from MidiDriver
static const byte _mt32ToGm [128]
 
static const byte _gmToMt32 [128]
 
- Static Public Attributes inherited from MidiDriver_BASE
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_BALANCE = 0x08
 
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_PORTAMENTO = 0x41
 
static const byte MIDI_CONTROLLER_SOSTENUTO = 0x42
 
static const byte MIDI_CONTROLLER_SOFT = 0x43
 
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_ALL_SOUND_OFF = 0x78
 
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 uint16 MIDI_RPN_PITCH_BEND_SENSITIVITY = 0x0000
 
static const uint16 MIDI_RPN_MASTER_TUNING_FINE = 0x0001
 
static const uint16 MIDI_RPN_MASTER_TUNING_COARSE = 0x0002
 
static const uint16 MIDI_RPN_NULL = 0x7F7F
 
static const uint8 MIDI_META_END_OF_TRACK = 0x2F
 
static const uint8 MIDI_META_SEQUENCER = 0x7F
 
static const uint16 MIDI_PITCH_BEND_DEFAULT = 0x2000
 
static const uint8 MIDI_PANNING_DEFAULT = 0x40
 
static const uint8 MIDI_EXPRESSION_DEFAULT = 0x7F
 
static const uint16 MIDI_MASTER_TUNING_FINE_DEFAULT = 0x2000
 
static const uint8 MIDI_MASTER_TUNING_COARSE_DEFAULT = 0x40
 
static const uint8 MT32_PITCH_BEND_SENSITIVITY_DEFAULT = 0x0C
 
static const uint8 GM_PITCH_BEND_SENSITIVITY_DEFAULT = 0x02
 
static const uint8 GS_RHYTHM_FIRST_NOTE = 0x1B
 
static const uint8 GS_RHYTHM_LAST_NOTE = 0x58
 

Protected Member Functions

virtual void initControlData ()
 
virtual void initMidiDevice ()
 
virtual void initMT32 (bool initForGM)
 
virtual void initGM (bool initForMT32, bool enableGS)
 
virtual void processEvent (int8 source, uint32 b, uint8 outputChannel, MidiChannelControlData &controlData, bool channelLockedByOtherSource=false)
 
virtual void applyControllerDefaults (uint8 source, MidiChannelControlData &controlData, uint8 outputChannel, bool channelLockedByOtherSource)
 
virtual void noteOnOff (byte outputChannel, byte command, byte note, byte velocity, int8 source, MidiChannelControlData &controlData)
 
virtual void polyAftertouch (byte outputChannel, byte note, byte pressure, int8 source, MidiChannelControlData &controlData, bool channelLockedByOtherSource=false)
 
virtual void controlChange (byte outputChannel, byte controllerNumber, byte controllerValue, int8 source, MidiChannelControlData &controlData, bool channelLockedByOtherSource=false)
 
virtual void programChange (byte outputChannel, byte patchId, int8 source, MidiChannelControlData &controlData, bool channelLockedByOtherSource=false)
 
virtual void channelAftertouch (byte outputChannel, byte pressure, int8 source, MidiChannelControlData &controlData, bool channelLockedByOtherSource=false)
 
virtual void pitchBend (byte outputChannel, uint8 pitchBendLsb, uint8 pitchBendMsb, int8 source, MidiChannelControlData &controlData, bool channelLockedByOtherSource=false)
 
virtual bool addActiveNote (uint8 outputChannel, uint8 note, int8 source)
 
virtual bool removeActiveNote (uint8 outputChannel, uint8 note, int8 source)
 
virtual void removeActiveNotes (uint8 outputChannel, bool sustainedNotes)
 
bool isOutputChannelUsed (int8 outputChannel)
 
virtual byte mapMT32InstrumentToGM (byte mt32Instrument)
 
virtual byte mapGMInstrumentToMT32 (byte gmInstrument)
 
byte correctInstrumentBank (byte outputChannel, byte patchId)
 
virtual int8 mapSourceChannel (uint8 source, uint8 dataChannel)
 
void applySourceVolume (uint8 source) override
 
void stopAllNotes (uint8 source, uint8 channel) override
 
void onTimer () override
 
- Protected Member Functions inherited from MidiDriver_Multisource
void updateFading ()
 
- Protected Member Functions inherited from MidiDriver_BASE
void midiDumpInit ()
 
int midiDumpVarLength (const uint32 &delta)
 
void midiDumpDelta ()
 
void midiDumpDo (uint32 b)
 
void midiDumpSysEx (const byte *msg, uint16 length)
 
void midiDumpFinish ()
 

Protected Attributes

Common::Mutex _allocationMutex
 
Common::Mutex _activeNotesMutex
 
MidiDriver_driver
 
MusicType _midiType
 
bool _nativeMT32
 
bool _enableGS
 
bool _midiDataReversePanning
 
bool _midiDeviceReversePanning
 
bool _scaleGSPercussionVolumeToMT32
 
bool _isOpen
 
uint16 _outputChannelMask
 
int _baseFreq
 
MidiChannelControlData_controlData [MIDI_CHANNEL_COUNT]
 
int8 _channelMap [MAXIMUM_SOURCES][MIDI_CHANNEL_COUNT]
 
uint16 _availableChannels [MAXIMUM_SOURCES]
 
const byte * _mt32ToGMInstrumentMap
 
const byte * _gmToMT32InstrumentMap
 
uint8 _maximumActiveNotes
 
ActiveNote_activeNotes
 
uint32 _sysExDelay
 
Common::List< SysExData_sysExQueue
 
Common::Mutex _sysExQueueMutex
 
- Protected Attributes inherited from MidiDriver_Multisource
MidiSource _sources [MAXIMUM_SOURCES]
 
ControllerDefaults _controllerDefaults
 
const byte * _instrumentRemapping
 
bool _userVolumeScaling
 
uint16 _userMusicVolume
 
uint16 _userSfxVolume
 
bool _userMute
 
Common::Mutex _fadingMutex
 
uint16 _fadeDelay
 
uint32 _timerRate
 
void * _timer_param
 
Common::TimerManager::TimerProc _timer_proc
 
- Protected Attributes inherited from MidiDriver_BASE
bool _midiDumpEnable
 
uint32 _prevMillis
 
Common::Array< byte > _midiDumpCache
 

Static Protected Attributes

static const uint8 MAXIMUM_MT32_ACTIVE_NOTES = 48
 
static const uint8 MAXIMUM_GM_ACTIVE_NOTES = 96
 
- Static Protected Attributes inherited from MidiDriver_Multisource
static const uint16 FADING_DELAY = 25 * 1000
 

Additional Inherited Members

- Public Types inherited from MidiDriver_Multisource
enum  SourceType { SOURCE_TYPE_UNDEFINED, SOURCE_TYPE_MUSIC, SOURCE_TYPE_SFX }
 
enum  FadeAbortType { FADE_ABORT_TYPE_END_VOLUME, FADE_ABORT_TYPE_CURRENT_VOLUME, FADE_ABORT_TYPE_START_VOLUME }
 
enum  ControllerDefaultType {
  CONTROLLER_DEFAULT_PROGRAM, CONTROLLER_DEFAULT_INSTRUMENT_BANK, CONTROLLER_DEFAULT_DRUMKIT, CONTROLLER_DEFAULT_CHANNEL_PRESSURE,
  CONTROLLER_DEFAULT_PITCH_BEND, CONTROLLER_DEFAULT_MODULATION, CONTROLLER_DEFAULT_VOLUME, CONTROLLER_DEFAULT_PANNING,
  CONTROLLER_DEFAULT_EXPRESSION, CONTROLLER_DEFAULT_SUSTAIN, CONTROLLER_DEFAULT_RPN, CONTROLLER_DEFAULT_PITCH_BEND_SENSITIVITY
}
 
- Public Types inherited from MidiDriver
enum  DeviceStringType { kDriverName, kDriverId, kDeviceName, kDeviceId }
 
enum  { MERR_CANNOT_CONNECT = 1, MERR_DEVICE_NOT_AVAILABLE = 3, MERR_ALREADY_OPEN = 4 }
 
enum  {
  PROP_OLD_ADLIB = 2, PROP_CHANNEL_MASK = 3, PROP_SCUMM_OPL3 = 4, PROP_USER_VOLUME_SCALING = 5,
  PROP_MIDI_DATA_REVERSE_PANNING = 6, PROP_OPL_ACCURACY_MODE = 7, PROP_OPL_CHANNEL_ALLOCATION_MODE = 8, PROP_MILES_VERSION = 9,
  PROP_OPL_RHYTHM_MODE_IGNORE_NOTE_OFF = 10
}
 
typedef uint32 DeviceHandle
 

Detailed Description

MIDI driver for MT-32 and GM compatible emulators and devices.

This class contains some commonly needed functionality for these devices and the MIDI data that targets them. It wraps the MidiDriver instance that does the actual communication with the MT-32 or GM device.

This driver has the following features:

  • MIDI device initialization Construct the driver with the type of MIDI data that will be sent to it. When the driver is opened, it will create an output MIDI driver appropriate for the user configuration settings and the type of MIDI data. You can also create the output MIDI driver yourself and pass it to the open function. The driver will take care of initializing the MIDI device and setting up for playback of MT-32 data on a GM/GS device or the other way around.
  • MT-32 <> GM conversion If the incoming MIDI data has been set to MT-32 and the output device is GM, the driver will map MT-32 instruments to GM equivalents. GM playback on an MT-32 device is also supported. Set the _mt32ToGMInstrumentMap and _gmToMT32InstrumentMap variables to override the standard instrument maps, or override the mapMT32InstrumentToGM and mapGMInstrumentToMT32 functions for more advanced mapping algorithms.
  • Reverse stereo If the game has MIDI data with reversed stereo compared to the targeted output device, set the MIDI_DATA_REVERSE_PANNING property to reverse stereo. The driver wil automatically reverse stereo when MT-32 data is sent to a GM/GS device or the other way around.
  • Correct Roland GS bank and drumkit selects Some games' MIDI data relies on a feature of the Roland SC-55 MIDI module which automatically corrects invalid bank selects and drumkit program changes. The driver replicates this feature to ensure correct instrument banks and drumkits on other hardware or softsynths.
  • SysEx queue The sysExQueue function will queue a SysEx message and return immediately. You can send more messages to the queue while the driver sends the messages asynchronously with the necessary delays to the MIDI device. Use the isReady function to check if the device has received all messages and is ready to start playback. Use this instead of the sysEx function to prevent the main game loop from being blocked while the driver waits the necessary amount of time for the MIDI device to process the message. Use clearSysExQueue to remove all messages from the queue, in case device initialization has to be aborted.
  • Multiple MIDI sources If the game plays multiple streams of MIDI data at the same time, each stream can be marked with a source number. This enables the following feature:
    • Channel mapping If multiple sources use the same MIDI channels, the driver can map the data channels to different output channels to avoid conflicts. Use allocateSourceChannels to allocate output channels to a source. The data channels are automatically mapped to the allocated output channels during playback. The allocated channels are freed when the source is deinitialized. If you only have one source of MIDI data or the sources do not use conflicting channels, you do not need to allocate channels - the channels in the MIDI data will be used directly. If you do use this feature, you have to use it for all MIDI sources to avoid channel conflicts. The standard channel allocation scheme will allocate the available output channels with the lowest numbers and will fail if not enough channels are available. You can override the allocateSourceChannels and mapSourceChannel functions to customize the allocation and mapping algorithms. Note that you can also use the "standard" way of allocating channels using the allocateChannel function and MidiChannel objects. These two methods are not coordinated in any way, so don't use both at the same time.

Member Function Documentation

◆ open()

int MidiDriver_MT32GM::open ( )
overridevirtual

Open the midi driver.

Returns
0 if successful, otherwise an error code.

Implements MidiDriver.

◆ close()

void MidiDriver_MT32GM::close ( )
overridevirtual

Close the midi driver.

Implements MidiDriver.

◆ isOpen()

bool MidiDriver_MT32GM::isOpen ( ) const
inlineoverridevirtual

Check whether the midi driver has already been opened.

Implements MidiDriver.

◆ isReady()

bool MidiDriver_MT32GM::isReady ( int8  source = -1)
overridevirtual

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.

Parameters
sourceCheck if the driver is ready to receive events from this specific source. Specify -1 to check readiness regardless of source.

Reimplemented from MidiDriver_BASE.

◆ property()

uint32 MidiDriver_MT32GM::property ( int  prop,
uint32  param 
)
overridevirtual

Get or set a property.

Reimplemented from MidiDriver_Multisource.

◆ send() [1/2]

void MidiDriver_MT32GM::send ( uint32  b)
overridevirtual

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.

Reimplemented from MidiDriver_Multisource.

◆ send() [2/2]

void MidiDriver_MT32GM::send ( int8  source,
uint32  b 
)
overridevirtual

Send a MIDI command from a specific source. If the MIDI driver does not support multiple sources, the source parameter is ignored.

Implements MidiDriver_Multisource.

Reimplemented in Ultima::Nuvie::MidiDriver_M_MT32, and AGOS::MidiDriver_Accolade_MT32.

◆ sysEx()

void MidiDriver_MT32GM::sysEx ( const byte *  msg,
uint16  length 
)
overridevirtual

Transmit a SysEx to the MIDI device.

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 268 bytes. Passing longer buffers can lead to undefined behavior (most likely, a crash).

Reimplemented from MidiDriver_BASE.

◆ sysExNoDelay()

uint16 MidiDriver_MT32GM::sysExNoDelay ( const byte *  msg,
uint16  length 
)
overridevirtual

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. In this case, 0 is returned and the driver itself will do a delay if necessary.

For information on the SysEx data requirements, see the sysEx method.

Reimplemented from MidiDriver_BASE.

◆ sysExQueue()

void MidiDriver_MT32GM::sysExQueue ( const byte *  msg,
uint16  length,
int8  source = -1 
)

Puts a SysEx message on the SysEx queue. The message will be sent when the device is ready to receive it, without blocking the thread. Use the isReady function to determine if the SysEx has been sent. Other MIDI messages (not using the queue) should not be sent until the queue is empty.

◆ sysExMT32()

uint16 MidiDriver_MT32GM::sysExMT32 ( const byte *  msg,
uint16  length,
const uint32  targetAddress,
bool  queue = false,
bool  delay = true,
int8  source = -1 
)

Write data to an MT-32 memory location using a SysEx message. This function will add the necessary header and checksum bytes.

Parameters
msgPointer to the data to write to a memory location
lengthThe data length
targetAddressThe start memory address in 8 bit format. Note that MT-32 memory addresses are sometimes specified in 7 bit format; these must be converted (f.e. System Area: 10 00 00 -> 04 00 00).
queueSpecify this parameter to use the SysEx queue to send the message (see sysExQueue for more information).
delaySet this to false to disable the delay to ensure that the MT-32 has enough time to process the message. This parameter has no effect if queue is true.
Returns
The delay in ms that must pass before the next SysEx message is sent to the MT-32. If delay or queue is true this will be 0; otherwise it is the caller's responsibility to make sure that the next SysEx is not sent before this time has passed.

◆ metaEvent()

void MidiDriver_MT32GM::metaEvent ( int8  source,
byte  type,
byte *  data,
uint16  length 
)
overridevirtual

Send a meta event from a specific source. If the MIDI driver does not support multiple sources, the source parameter is ignored.

Reimplemented from MidiDriver_BASE.

Reimplemented in Ultima::Nuvie::MidiDriver_M_MT32.

◆ stopAllNotes() [1/2]

void MidiDriver_MT32GM::stopAllNotes ( bool  stopSustainedNotes = false)
overridevirtual

Stops all currently active notes. Specify stopSustainedNotes if the MIDI data makes use of the sustain controller to make sure sustained notes are also stopped.

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.

Reimplemented from MidiDriver_BASE.

Reimplemented in Ultima::Nuvie::MidiDriver_M_MT32.

◆ clearSysExQueue()

void MidiDriver_MT32GM::clearSysExQueue ( )

Removes all SysEx messages in the SysEx queue.

◆ getBaseTempo()

uint32 MidiDriver_MT32GM::getBaseTempo ( )
overridevirtual

The time in microseconds between invocations of the timer callback.

Implements MidiDriver.

◆ allocateSourceChannels()

virtual bool MidiDriver_MT32GM::allocateSourceChannels ( uint8  source,
uint8  numChannels 
)
virtual

Allocates a number of MIDI channels for use by the specified source. By default this implements a simple algorithm which allocates the unallocated channel(s) with the lowest numbers. The channel numbers in the MIDI data sent by this source will be mapped to the allocated MIDI output channels. The function can be overridden to implement more complex channel allocation algorithms. Channels are freed when the source is deinitialized. Note that sources are not required to allocate channels, so if sources use conflicting MIDI channels, make sure to use this function consistently.

Parameters
sourceThe source for which to allocate channels
numChannelsThe number of channels to allocate
Returns
True if allocation was successful, false otherwise (usually because insufficent channels were available)

◆ deinitSource()

void MidiDriver_MT32GM::deinitSource ( uint8  source)
overridevirtual

Deinitializes a source. This will abort active fades, free any output channels allocated to the source and stop active notes.

Reimplemented from MidiDriver_Multisource.

Reimplemented in AGOS::MidiDriver_Accolade_MT32.

◆ initControlData()

virtual void MidiDriver_MT32GM::initControlData ( )
protectedvirtual

This will initialize the _controlData array with the default values for MT-32 or GM (depending on the _nativeMT32 value).

Reimplemented in Audio::MidiDriver_Miles_Midi.

◆ initMidiDevice()

virtual void MidiDriver_MT32GM::initMidiDevice ( )
protectedvirtual

Initializes the MIDI device. Will call initMT32 or initGM.

Reimplemented in Audio::MidiDriver_Miles_Midi.

◆ initMT32()

virtual void MidiDriver_MT32GM::initMT32 ( bool  initForGM)
protectedvirtual

Initializes the MT-32 MIDI device. The device will be reset and, if the parameter is specified, set up for General MIDI data.

Parameters
initForGMTrue if the MT-32 should be initialized for GM mapping

◆ initGM()

virtual void MidiDriver_MT32GM::initGM ( bool  initForMT32,
bool  enableGS 
)
protectedvirtual

Initializes the General MIDI device. The device will be reset. If the initForMT32 parameter is specified, the device will be set up for MT-32 MIDI data. If the device supports Roland GS, the enableGS parameter can be specified for enhanced GS MT-32 compatiblity.

Parameters
initForMT32True if the device should be initialized for MT-32 mapping
enableGSTrue if the device should be initialized for GS MT-32 mapping

◆ processEvent()

virtual void MidiDriver_MT32GM::processEvent ( int8  source,
uint32  b,
uint8  outputChannel,
MidiChannelControlData controlData,
bool  channelLockedByOtherSource = false 
)
protectedvirtual

Processes a MIDI event. The type of event is determined and the corresponding function is called to handle the event. This function is called after mapping the MIDI data channel to an output channel, so the specified output channel is used and not the channel in the event bytes.

Parameters
sourceThe source of the event
bThe event MIDI bytes
outputChannelThe output channel for the event
controlDataThe control data set to use when processing the event
channelLockedByOtherSourceTrue if the output channel is locked by another source. This will prevent the event from actually being sent to the MIDI device, but controlData will be updated. Default is false.

◆ applyControllerDefaults()

virtual void MidiDriver_MT32GM::applyControllerDefaults ( uint8  source,
MidiChannelControlData controlData,
uint8  outputChannel,
bool  channelLockedByOtherSource 
)
protectedvirtual

Applies the controller default settings to the specified output channel for the specified source. This will set all default values specified on _controllerDefaults on the channel except sustain, which is set by deinitSource.

Parameters
sourceThe source triggering the default settings
controlDataThe control data set to use when setting the defaults
outputChannelThe output channel on which the defaults should be set
channelLockedByOtherSourceTrue if the output channel is locked by another source. This will prevent the defaults from actually being sent to the MIDI device, but controlData will be updated. Default is false.

◆ noteOnOff()

virtual void MidiDriver_MT32GM::noteOnOff ( byte  outputChannel,
byte  command,
byte  note,
byte  velocity,
int8  source,
MidiChannelControlData controlData 
)
protectedvirtual

Processes a note on or off MIDI event. This will apply source volume if necessary, update the active note registration and send the event to the MIDI device.

Parameters
outputChannelThe MIDI output channel for the event
commandThe MIDI command byte
controlDataThe control data set that will be used for applying source volume

◆ polyAftertouch()

virtual void MidiDriver_MT32GM::polyAftertouch ( byte  outputChannel,
byte  note,
byte  pressure,
int8  source,
MidiChannelControlData controlData,
bool  channelLockedByOtherSource = false 
)
protectedvirtual

Processes a polyphonic aftertouch MIDI event. This implementation will just send the event to the MIDI device.

Parameters
outputChannelThe MIDI output channel for the event
noteThe note on which aftertouch should be applied
pressureThe amount of pressure which should be applied
sourceThe source of the event
controlDataThe control data set for the MIDI channel
channelLockedByOtherSourceTrue if the output channel is locked by another source. Default is false.

◆ controlChange()

virtual void MidiDriver_MT32GM::controlChange ( byte  outputChannel,
byte  controllerNumber,
byte  controllerValue,
int8  source,
MidiChannelControlData controlData,
bool  channelLockedByOtherSource = false 
)
protectedvirtual

Process a control change MIDI event. This will update the specified control data set and apply other processing if necessary, and then send the event to the MIDI device.

Parameters
outputChannelThe MIDI output channel for the event
controlDataThe control data set that the new controller value should be stored on
channelLockedByOtherSourceTrue if the output channel is locked by another source. Default is false.

◆ programChange()

virtual void MidiDriver_MT32GM::programChange ( byte  outputChannel,
byte  patchId,
int8  source,
MidiChannelControlData controlData,
bool  channelLockedByOtherSource = false 
)
protectedvirtual

Process a program change MIDI event. This will update the specified control data set, apply MT-32 <> GM instrument mapping and other processing, and send the event to the MIDI device.

Parameters
outputChannelThe MIDI output channel for the event
controlDataThe control data set that the new program value should be stored on
channelLockedByOtherSourceTrue if the output channel is locked by another source. Default is false.

◆ channelAftertouch()

virtual void MidiDriver_MT32GM::channelAftertouch ( byte  outputChannel,
byte  pressure,
int8  source,
MidiChannelControlData controlData,
bool  channelLockedByOtherSource = false 
)
protectedvirtual

Processes a channel aftertouch MIDI event. This whil update the specified control data set and send the event to the MIDI device.

Parameters
outputChannelThe MIDI output channel for the event
pressureThe amount of pressure which should be applied
sourceThe source of the event
controlDataThe control data set for the MIDI channel
channelLockedByOtherSourceTrue if the output channel is locked by another source. Default is false.

◆ pitchBend()

virtual void MidiDriver_MT32GM::pitchBend ( byte  outputChannel,
uint8  pitchBendLsb,
uint8  pitchBendMsb,
int8  source,
MidiChannelControlData controlData,
bool  channelLockedByOtherSource = false 
)
protectedvirtual

Processes a pitch bend MIDI event. This whil update the specified control data set and send the event to the MIDI device.

Parameters
outputChannelThe MIDI output channel for the event
pitchBendLsbThe pitch bend LSB
pitchBendMsbThe pitch bend MSB
sourceThe source of the event
controlDataThe control data set for the MIDI channel
channelLockedByOtherSourceTrue if the output channel is locked by another source. Default is false.

◆ addActiveNote()

virtual bool MidiDriver_MT32GM::addActiveNote ( uint8  outputChannel,
uint8  note,
int8  source 
)
protectedvirtual

Adds a note to the active note registration.

◆ removeActiveNote()

virtual bool MidiDriver_MT32GM::removeActiveNote ( uint8  outputChannel,
uint8  note,
int8  source 
)
protectedvirtual

Removes a note from the active note registration.

◆ removeActiveNotes()

virtual void MidiDriver_MT32GM::removeActiveNotes ( uint8  outputChannel,
bool  sustainedNotes 
)
protectedvirtual

Removes all sustained or all non-sustained notes on the specified MIDI channel from the active note registration.

◆ isOutputChannelUsed()

bool MidiDriver_MT32GM::isOutputChannelUsed ( int8  outputChannel)
protected

Returns true if the MIDI device uses the specified MIDI channel.

◆ mapMT32InstrumentToGM()

virtual byte MidiDriver_MT32GM::mapMT32InstrumentToGM ( byte  mt32Instrument)
protectedvirtual

Maps the specified MT-32 instrument to an equivalent GM instrument. This implementation looks up the instrument in the _mt32ToGMInstrumentMap array. Override this function to implement more complex mapping schemes.

◆ mapGMInstrumentToMT32()

virtual byte MidiDriver_MT32GM::mapGMInstrumentToMT32 ( byte  gmInstrument)
protectedvirtual

Maps the specified GM instrument to an equivalent MT-32 instrument. This implementation looks up the instrument in the _gmToMT32InstrumentMap array. Override this function to implement more complex mapping schemes.

◆ correctInstrumentBank()

byte MidiDriver_MT32GM::correctInstrumentBank ( byte  outputChannel,
byte  patchId 
)
protected

Checks if the currently selected GS bank / instrument variation on the specified channel is valid for the specified patch. If this is not the case, the correct bank will be returned which can be set by sending a bank select message. If no correction is needed, 0xFF will be returned. This emulates the fallback functionality of the Roland SC-55 v1.2x, on which some games rely to correct wrong bank selects.

◆ mapSourceChannel()

virtual int8 MidiDriver_MT32GM::mapSourceChannel ( uint8  source,
uint8  dataChannel 
)
protectedvirtual

Returns the MIDI output channel mapped to the specified data channel. If the data channel has not been mapped yet, a new mapping to one of the output channels available to the source will be created.

Parameters
sourceThe source using the data channel
dataChannelThe data channel to map
Returns
The mapped output channel, or -1 if no mapping is possible

Reimplemented in AGOS::MidiDriver_Accolade_MT32.

◆ applySourceVolume()

void MidiDriver_MT32GM::applySourceVolume ( uint8  source)
overrideprotectedvirtual

Applies the current source volume to the active notes and/or MIDI channels of the specified source. 0xFF can be specified to apply the source volume for all sources.

Parameters
sourceThe source for which the source volume should be applied, or all sources if 0xFF is specified.

Implements MidiDriver_Multisource.

◆ stopAllNotes() [2/2]

void MidiDriver_MT32GM::stopAllNotes ( uint8  source,
uint8  channel 
)
overrideprotectedvirtual

Stops all active notes (including sustained notes) for the specified source and MIDI channel. For both source and channel the value 0xFF can be specified, in which case active notes will be stopped for all sources and/or MIDI channels.

Parameters
sourceThe source for which all notes should be stopped, or all sources if 0xFF is specified.
channelThe MIDI channel on which all notes should be stopped, or all channels if 0xFF is specified.

Implements MidiDriver_Multisource.

◆ onTimer()

void MidiDriver_MT32GM::onTimer ( )
overrideprotectedvirtual

Runs the MIDI driver's timer related functionality. Will update volume fades and sends messages from the SysEx queue if necessary.

Reimplemented from MidiDriver_Multisource.

Reimplemented in Ultima::Nuvie::MidiDriver_M_MT32.


The documentation for this class was generated from the following file: