ScummVM API documentation
MidiDriver_Casio Class Reference

#include <casio.h>

Inheritance diagram for MidiDriver_Casio:
MidiDriver_Multisource MidiDriver MidiDriver_BASE AGOS::MidiDriver_Accolade_Casio

Classes

struct  ActiveNote
 

Public Member Functions

 MidiDriver_Casio (MusicType midiType)
 
int open () override
 
virtual int open (MidiDriver *driver, MusicType deviceType)
 
void close () override
 
bool isOpen () const override
 
void send (int8 source, uint32 b) override
 
void metaEvent (int8 source, byte type, byte *data, uint16 length) override
 
void stopAllNotes (bool stopSustainedNotes=false) override
 
MidiChannelallocateChannel () override
 
MidiChannelgetPercussionChannel () override
 
uint32 getBaseTempo () override
 
- Public Member Functions inherited from MidiDriver_Multisource
void send (uint32 b) override
 
uint32 property (int prop, uint32 param) override
 
virtual void deinitSource (uint8 source)
 
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 sysEx (const byte *msg, uint16 length)
 
virtual uint16 sysExNoDelay (const byte *msg, uint16 length)
 
virtual void metaEvent (byte type, byte *data, uint16 length)
 
virtual bool isReady (int8 source=-1)
 

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 int CASIO_CHANNEL_POLYPHONY [4]
 
static const uint8 INSTRUMENT_REMAPPING_CT460_TO_MT540 [30]
 
static const uint8 INSTRUMENT_REMAPPING_MT540_TO_CT460 [30]
 
static const uint8 RHYTHM_INSTRUMENT_MT540
 
static const uint8 RHYTHM_INSTRUMENT_CT460
 
static const uint8 BASS_INSTRUMENT_MT540
 
static const uint8 BASS_INSTRUMENT_CT460
 
- 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 int8 mapSourceChannel (uint8 source, uint8 dataChannel)
 
virtual void processEvent (int8 source, uint32 b, uint8 outputChannel)
 
virtual void noteOff (byte outputChannel, byte command, byte note, byte velocity, int8 source)
 
virtual void noteOn (byte outputChannel, byte note, byte velocity, int8 source)
 
virtual void programChange (byte outputChannel, byte patchId, int8 source, bool applyRemapping=true)
 
virtual void controlChange (byte outputChannel, byte controllerNumber, byte controllerValue, int8 source)
 
virtual int8 mapNote (byte outputChannel, byte note)
 
virtual byte calculateVelocity (int8 source, byte velocity)
 
virtual byte mapInstrument (byte program, bool applyRemapping=true)
 
virtual bool isRhythmChannel (uint8 outputChannel)
 
void applySourceVolume (uint8 source) override
 
void stopAllNotes (uint8 source, uint8 channel) override
 
- Protected Member Functions inherited from MidiDriver_Multisource
void updateFading ()
 
virtual void onTimer ()
 
- 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

MidiDriver_driver
 
MusicType _deviceType
 
MusicType _midiType
 
bool _isOpen
 
byte _instruments [4]
 
bool _rhythmChannel [4]
 
ActiveNote _activeNotes [32]
 
bool _sustain [4]
 
byte * _rhythmNoteRemapping
 
bool _sendUntrackedNoteOff
 
Common::Mutex _mutex
 
- 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
 

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
 
- Static Protected Attributes inherited from MidiDriver_Multisource
static const uint16 FADING_DELAY = 25 * 1000
 

Detailed Description

MIDI driver implementation for the Casio MT-540, CT-640 and CSM-1 devices.

This driver provides source volume and user volume scaling, as well as fades (due to device limitations these are applied to note velocity instead of the volume controller). It also provides instrument mapping between the MT-540 and CT-640/CSM-1 instrument map and can map rhythm notes from the input MIDI data by specifying a remapping.

TODO This driver does not provide a full multisource functionality implementation because this was not needed for the game for which it was added (Elvira). It assumes only 1 source sends MIDI data at the same time and this source has access to all MIDI channels.

Some details of these Casio devices:

  • They seem to support only note on, note off and program change MIDI events. Because they do not support the volume controller, volume is applied to note velocity (and I'm not sure if they support even that...). All Notes Off is performed by keeping track of active notes and sending note off events for all active notes.
  • They only use MIDI channels 0-3. The MT-32 and GM devices have channel 9 as the fixed rhythm channel. The Casio devices can switch any used channel to a rhythm channel by setting a specific instrument.
  • They have only 30 instruments, 3 of which are rhythm or SFX banks.
  • All devices seem to have the same capabilities, but the instrument numbering is different between the MT-540 on the one hand and the CT-640 and CSM-1 on the other.

Constructor & Destructor Documentation

◆ MidiDriver_Casio()

MidiDriver_Casio::MidiDriver_Casio ( MusicType  midiType)

Constructs a new Casio MidiDriver instance.

Parameters
midiTypeThe type of MIDI data that will be sent to the driver (MT-540 or CT-460/CSM-1).

Member Function Documentation

◆ open() [1/2]

int MidiDriver_Casio::open ( )
overridevirtual

Open the midi driver.

Returns
0 if successful, otherwise an error code.

Implements MidiDriver.

Reimplemented in AGOS::MidiDriver_Accolade_Casio.

◆ open() [2/2]

virtual int MidiDriver_Casio::open ( MidiDriver driver,
MusicType  deviceType 
)
virtual

Opens the driver wrapping the specified MidiDriver instance.

Parameters
driverThe driver that will receive MIDI events from this driver.
deviceTypeThe type of MIDI device that will receive MIDI events from this driver (MT-540 or CT-460/CSM-1).
Returns
0 if the driver was opened successfully; >0 if an error occurred.

◆ close()

void MidiDriver_Casio::close ( )
overridevirtual

Close the midi driver.

Implements MidiDriver.

◆ isOpen()

bool MidiDriver_Casio::isOpen ( ) const
overridevirtual

Check whether the midi driver has already been opened.

Implements MidiDriver.

◆ send()

void MidiDriver_Casio::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.

◆ metaEvent()

void MidiDriver_Casio::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.

◆ stopAllNotes() [1/2]

void MidiDriver_Casio::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.

◆ getBaseTempo()

uint32 MidiDriver_Casio::getBaseTempo ( )
overridevirtual

The time in microseconds between invocations of the timer callback.

Implements MidiDriver.

◆ mapSourceChannel()

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

Maps a data MIDI channel to an output MIDI channel for the specified source. TODO This driver has no default implementation for a channel allocation scheme. It assumes only one source is active at a time and has access to all output channels. The default implementation for this method just returns the data channel.

Parameters
sourceThe source for which the MIDI channel should be mapped.
dataChannelThe data channel that should be mapped.
Returns
The output MIDI channel.

Reimplemented in AGOS::MidiDriver_Accolade_Casio.

◆ processEvent()

virtual void MidiDriver_Casio::processEvent ( int8  source,
uint32  b,
uint8  outputChannel 
)
protectedvirtual

Processes a MIDI event.

Parameters
sourceThe source sending the MIDI event.
bThe MIDI event data.
outputChannelThe MIDI channel on which the event should be sent.

◆ noteOff()

virtual void MidiDriver_Casio::noteOff ( byte  outputChannel,
byte  command,
byte  note,
byte  velocity,
int8  source 
)
protectedvirtual

Processes a MIDI note off event.

Parameters
outputChannelThe MIDI channel on which the event should be sent.
commandThe MIDI command that triggered the note off event (other than note off (0x80) this can also be note on (0x90) with velocity 0).
noteThe MIDI note that should be turned off.
velocityThe note off velocity.
sourceThe source sending the MIDI event.

◆ noteOn()

virtual void MidiDriver_Casio::noteOn ( byte  outputChannel,
byte  note,
byte  velocity,
int8  source 
)
protectedvirtual

Processes a MIDI note on event.

Parameters
outputChannelThe MIDI channel on which the event should be sent.
noteThe MIDI note that should be turned on.
velocityThe note velocity,
sourceThe source sending the MIDI event.

◆ programChange()

virtual void MidiDriver_Casio::programChange ( byte  outputChannel,
byte  patchId,
int8  source,
bool  applyRemapping = true 
)
protectedvirtual

Processes a MIDI program change event.

Parameters
outputChannelThe MIDI channel on which the event should be sent.
patchIdThe instrument that should be set.
sourceThe source sending the MIDI event.
applyRemappingTrue if the instrument remapping (_instrumentRemapping) should be applied.

◆ controlChange()

virtual void MidiDriver_Casio::controlChange ( byte  outputChannel,
byte  controllerNumber,
byte  controllerValue,
int8  source 
)
protectedvirtual

Processes a MIDI control change event.

Parameters
outputChannelThe MIDI channel on which the event should be sent.
controllerNumberThe controller for which the value should be set.
controllerValueThe controller value that should be set.
sourceThe source sending the MIDI event.

◆ mapNote()

virtual int8 MidiDriver_Casio::mapNote ( byte  outputChannel,
byte  note 
)
protectedvirtual

Maps the specified note to a different note according to the rhythm note mapping. This mapping is only applied if the note is played on a rhythm channel.

Parameters
outputChannelThe MIDI channel on which the note is/will be active.
noteThe note that should be mapped.
Returns
The mapped note, or the specified note if it was not mapped.

◆ calculateVelocity()

virtual byte MidiDriver_Casio::calculateVelocity ( int8  source,
byte  velocity 
)
protectedvirtual

Calculates the velocity for a note on event. This applies source volume and user volume settings to the specified velocity value.

Parameters
sourceThe source that sent the note on event.
velocityThe velocity specified in the note on event.
Returns
The calculated velocity.

◆ mapInstrument()

virtual byte MidiDriver_Casio::mapInstrument ( byte  program,
bool  applyRemapping = true 
)
protectedvirtual

Maps the specified instrument to the instrument value that should be sent to the MIDI device. This applies the current instrument remapping (if present and if applyRemapping is specified) and maps MT-540 instruments to CT-460/CSM-1 instruments (or the other way around) if necessary.

Parameters
programThe instrument that should be mapped.
applyRemappingTrue if the instrument remapping (_instrumentRemapping) should be applied.
Returns
The mapped instrument, or the specified instrument if no mapping was necessary.

◆ isRhythmChannel()

virtual bool MidiDriver_Casio::isRhythmChannel ( uint8  outputChannel)
protectedvirtual

Returns whether the specified MIDI channel is a rhythm channel. On the Casio devices, the rhythm channel is not fixed but is created by setting a channel to a specific instrument (see the rhythm instrument constants).

Parameters
outputChannelThe channel that should be checked.
Returns
True if the specified channel is a rhythm channel, false otherwise.

◆ applySourceVolume()

void MidiDriver_Casio::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_Casio::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.


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