ScummVM API documentation
Audio::MidiPlayer Class Reference

#include <midiplayer.h>

Inheritance diagram for Audio::MidiPlayer:
MidiDriver_BASE Access::MusicManager Agi::SoundGenMIDI AGS::Music Bagel::MusicPlayer CGE2::MusicPlayer CGE::MusicPlayer Draci::MusicPlayer Dragons::MidiMusicPlayer Gnap::MusicPlayer Hugo::MidiPlayer Illusions::MidiPlayer Lilliput::LilliputSound Prince::MusicPlayer Tinsel::MidiMusicPlayer Toltecs::MusicPlayer Touche::MidiPlayer TwinE::TwinEMidiPlayer Ultima::Ultima4::Music

Public Member Functions

virtual void stop ()
 
virtual void pause ()
 
virtual void resume ()
 
bool isPlaying () const
 
int getVolume () const
 
virtual void setVolume (int volume)
 
void syncVolume ()
 
bool hasNativeMT32 () const
 
void send (uint32 b) override
 
void metaEvent (byte type, byte *data, uint16 length) override
 
- Public Member Functions inherited from MidiDriver_BASE
virtual void send (int8 source, uint32 b)
 
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 (int8 source, byte type, byte *data, uint16 length)
 
virtual void stopAllNotes (bool stopSustainedNotes=false)
 
virtual bool isReady (int8 source=-1)
 

Protected Types

enum  { kNumChannels = 16 }
 

Protected Member Functions

virtual void sendToChannel (byte ch, uint32 b)
 
virtual void endOfTrack ()
 
virtual void onTimer ()
 
void createDriver (int flags=MDT_MIDI|MDT_ADLIB|MDT_PREFER_GM)
 
- 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 ()
 

Static Protected Member Functions

static void timerCallback (void *data)
 

Protected Attributes

Common::Mutex _mutex
 
MidiDriver_driver
 
MidiParser_parser
 
byte * _midiData
 
MidiChannel_channelsTable [kNumChannels]
 
uint8 _channelsVolume [kNumChannels]
 
bool _isLooping
 
bool _isPlaying
 
int _masterVolume
 
bool _nativeMT32
 
- Protected Attributes inherited from MidiDriver_BASE
bool _midiDumpEnable
 
uint32 _prevMillis
 
Common::Array< byte > _midiDumpCache
 

Additional Inherited Members

- 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
 

Detailed Description

Simple MIDI playback class.

Note
Currently incomplete, as it lacks play() methods. This is just a start of the real thing, which tries to include code replicated between several of our engines.

Eventually, this should offer ways to start playback of SMF and XMIDI data (and possibly make it easy to add further playback methods), should be able to automatically instantiate _driver as needed, should perform memory management on the MidiParser object(s) being used, and possibly more.

Also, pause/resume handling should be unified (we provide an implementation, but several subclasses use different ones).

Also, care should be taken to ensure that mutex locking is done right.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
kNumChannels 

The number of MIDI channels supported.

Member Function Documentation

◆ isPlaying()

bool Audio::MidiPlayer::isPlaying ( ) const
inline

Return whether there is currently any MIDI music playing.

◆ getVolume()

int Audio::MidiPlayer::getVolume ( ) const
inline

Return the currently active master volume, in the range 0-255.

◆ setVolume()

virtual void Audio::MidiPlayer::setVolume ( int  volume)
virtual

Set the master volume to the specified value in the range 0-255. (values outside this range are automatically clipped). This may cause suitable MIDI events to be sent to active channels.

Reimplemented in Tinsel::MidiMusicPlayer, Touche::MidiPlayer, and Dragons::MidiMusicPlayer.

◆ syncVolume()

void Audio::MidiPlayer::syncVolume ( )

Update the volume according to the ConfMan's 'music_volume' setting. also respects the 'mute' setting.

◆ send()

void Audio::MidiPlayer::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.

Implements MidiDriver_BASE.

Reimplemented in CGE::MusicPlayer, CGE2::MusicPlayer, Tinsel::MidiMusicPlayer, Illusions::MidiPlayer, Prince::MusicPlayer, Touche::MidiPlayer, Agi::SoundGenMIDI, and Toltecs::MusicPlayer.

◆ sendToChannel()

virtual void Audio::MidiPlayer::sendToChannel ( byte  ch,
uint32  b 
)
protectedvirtual

This method is invoked by the default send() implementation, after suitably filtering the message b.

Reimplemented in CGE::MusicPlayer, CGE2::MusicPlayer, Illusions::MidiPlayer, Ultima::Ultima4::Music, Hugo::MidiPlayer, Prince::MusicPlayer, Agi::SoundGenMIDI, Dragons::MidiMusicPlayer, Draci::MusicPlayer, Gnap::MusicPlayer, and AGS::Music.

◆ endOfTrack()

virtual void Audio::MidiPlayer::endOfTrack ( )
protectedvirtual

This method is invoked by metaEvent when an end-of-track event arrives. By default, this tells the parser to jump to the start (if looping is enabled) resp. invokes stope(): Overload this to customize behavior.

Reimplemented in Illusions::MidiPlayer, and Agi::SoundGenMIDI.

Member Data Documentation

◆ _parser

MidiParser* Audio::MidiPlayer::_parser
protected

A MidiParser instances, to be created by methods of a MidiPlayer subclass.

Note
The stop() method (and hence the destructor) invoke the unloadMusic() method of _parser and then delete it.

◆ _midiData

byte* Audio::MidiPlayer::_midiData
protected

This is an (optional) pointer to a malloc'ed buffer containing MIDI data used by _parser. The stop() method (and hence the destructor) will free this if set. Subclasses of this class may use _midiData, but don't have to

◆ _masterVolume

int Audio::MidiPlayer::_masterVolume
protected

The master volume, in the range 0-255.


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