ScummVM API documentation
MidiDriver_ADLIB_Multisource Class Reference

#include <adlib_ms.h>

Inheritance diagram for MidiDriver_ADLIB_Multisource:
MidiDriver_Multisource MidiDriver MidiDriver_BASE AGOS::MidiDriver_Accolade_AdLib AGOS::MidiDriver_Simon1_AdLib Lure::MidiDriver_ADLIB_Lure Made::MidiDriver_ADLIB_MADE Ultima::Nuvie::MidiDriver_M_AdLib

Classes

struct  ActiveNote
 
struct  InstrumentInfo
 
struct  MidiChannelControlData
 

Public Types

enum  AccuracyMode { ACCURACY_MODE_SB16_WIN95, ACCURACY_MODE_GM }
 
enum  ChannelAllocationMode { ALLOCATION_MODE_DYNAMIC, ALLOCATION_MODE_STATIC }
 
enum  InstrumentWriteMode { INSTRUMENT_WRITE_MODE_NOTE_ON, INSTRUMENT_WRITE_MODE_PROGRAM_CHANGE }
 
enum  NoteSelectMode { NOTE_SELECT_MODE_0, NOTE_SELECT_MODE_1 }
 
enum  ModulationDepth { MODULATION_DEPTH_LOW, MODULATION_DEPTH_HIGH }
 
enum  VibratoDepth { VIBRATO_DEPTH_LOW, VIBRATO_DEPTH_HIGH }
 
- 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
 

Public Member Functions

 MidiDriver_ADLIB_Multisource (OPL::Config::OplType oplType, int timerFrequency=OPL::OPL::kDefaultCallbackFrequency)
 
int open () override
 
bool isOpen () const override
 
void close () override
 
uint32 property (int prop, uint32 param) override
 
uint32 getBaseTempo () override
 
MidiChannelallocateChannel () override
 
MidiChannelgetPercussionChannel () override
 
void send (int8 source, uint32 b) override
 
void sysEx (const byte *msg, uint16 length) override
 
void metaEvent (int8 source, byte type, byte *data, uint16 length) override
 
void stopAllNotes (bool stopSustainedNotes=false) override
 
void stopAllNotes (uint8 source, uint8 channel) override
 
void deinitSource (uint8 source) override
 
- Public Member Functions inherited from MidiDriver_Multisource
void send (uint32 b) override
 
uint32 property (int prop, uint32 param) override
 
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 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 bool detectOplType (OPL::Config::OplType oplType)
 
- 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 uint8 OPL2_NUM_CHANNELS = 9
 
static const uint8 OPL3_NUM_CHANNELS = 18
 
static const uint8 MELODIC_CHANNELS_OPL2 [9]
 
static const uint8 MELODIC_CHANNELS_OPL2_RHYTHM [6]
 
static const uint8 MELODIC_CHANNELS_OPL3 [18]
 
static const uint8 MELODIC_CHANNELS_OPL3_RHYTHM [15]
 
static const uint8 OPL_NUM_RHYTHM_INSTRUMENTS = 5
 
static const uint8 OPL_RHYTHM_INSTRUMENT_CHANNELS [OPL_NUM_RHYTHM_INSTRUMENTS]
 
static const uint8 OPL_REGISTER_TEST = 0x01
 
static const uint8 OPL_REGISTER_TIMER1 = 0x02
 
static const uint8 OPL_REGISTER_TIMER2 = 0x03
 
static const uint8 OPL_REGISTER_TIMERCONTROL = 0x04
 
static const uint8 OPL_REGISTER_NOTESELECT_CSM = 0x08
 
static const uint8 OPL_REGISTER_RHYTHM = 0xBD
 
static const uint8 OPL_REGISTER_BASE_FREQMULT_MISC = 0x20
 
static const uint8 OPL_REGISTER_BASE_LEVEL = 0x40
 
static const uint8 OPL_REGISTER_BASE_DECAY_ATTACK = 0x60
 
static const uint8 OPL_REGISTER_BASE_RELEASE_SUSTAIN = 0x80
 
static const uint8 OPL_REGISTER_BASE_WAVEFORMSELECT = 0xE0
 
static const uint8 OPL_REGISTER_BASE_FNUMLOW = 0xA0
 
static const uint8 OPL_REGISTER_BASE_FNUMHIGH_BLOCK_KEYON = 0xB0
 
static const uint8 OPL_REGISTER_BASE_CONNECTION_FEEDBACK_PANNING = 0xC0
 
static const uint16 OPL3_REGISTER_CONNECTIONSELECT = 0x104
 
static const uint16 OPL3_REGISTER_NEW = 0x105
 
static const uint16 OPL_REGISTER_SET_2_OFFSET = 0x100
 
static const uint8 OPL_REGISTER_RHYTHM_OFFSETS []
 
static const uint8 OPL_MASK_LEVEL = 0x3F
 
static const uint8 OPL_MASK_FNUMHIGH_BLOCK = 0x1F
 
static const uint8 OPL_MASK_KEYON = 0x20
 
static const uint8 OPL_MASK_PANNING = 0x30
 
static const uint8 OPL_PANNING_CENTER = 0x30
 
static const uint8 OPL_PANNING_LEFT = 0x10
 
static const uint8 OPL_PANNING_RIGHT = 0x20
 
static OplInstrumentDefinition OPL_INSTRUMENT_BANK []
 
static OplInstrumentDefinition OPL_RHYTHM_BANK []
 
- 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

void applySourceVolume (uint8 source) override
 
virtual void initOpl ()
 
virtual void noteOff (uint8 channel, uint8 note, uint8 velocity, uint8 source)
 
virtual void noteOn (uint8 channel, uint8 note, uint8 velocity, uint8 source)
 
virtual void polyAftertouch (uint8 channel, uint8 note, uint8 pressure, uint8 source)
 
virtual void controlChange (uint8 channel, uint8 controller, uint8 value, uint8 source)
 
virtual void programChange (uint8 channel, uint8 program, uint8 source)
 
virtual void channelAftertouch (uint8 channel, uint8 pressure, uint8 source)
 
virtual void pitchBend (uint8 channel, uint8 pitchBendLsb, uint8 pitchBendMsb, uint8 source)
 
virtual void modulation (uint8 channel, uint8 modulation, uint8 source)
 
virtual void dataEntry (uint8 channel, uint8 dataMsb, uint8 dataLsb, uint8 source)
 
virtual void volume (uint8 channel, uint8 volume, uint8 source)
 
virtual void panning (uint8 channel, uint8 panning, uint8 source)
 
virtual void expression (uint8 channel, uint8 expression, uint8 source)
 
virtual void sustain (uint8 channel, uint8 sustain, uint8 source)
 
virtual void registeredParameterNumber (uint8 channel, uint8 rpnMsb, uint8 rpnLsb, uint8 source)
 
virtual void allSoundOff (uint8 channel, uint8 source)
 
virtual void resetAllControllers (uint8 channel, uint8 source)
 
virtual void allNotesOff (uint8 channel, uint8 source)
 
virtual void applyControllerDefaults (uint8 source)
 
virtual void recalculateFrequencies (uint8 channel, uint8 source)
 
virtual void recalculateVolumes (uint8 channel, uint8 source)
 
virtual InstrumentInfo determineInstrument (uint8 channel, uint8 source, uint8 note)
 
virtual uint8 allocateOplChannel (uint8 channel, uint8 source, uint8 instrumentId)
 
void determineMelodicChannels ()
 
virtual uint16 calculateFrequency (uint8 channel, uint8 source, uint8 note)
 
virtual int32 calculatePitchBend (uint8 channel, uint8 source, uint16 oplFrequency)
 
virtual uint8 calculateVolume (uint8 channel, uint8 source, uint8 velocity, OplInstrumentDefinition &instrumentDef, uint8 operatorNum)
 
virtual uint8 calculateUnscaledVolume (uint8 channel, uint8 source, uint8 velocity, OplInstrumentDefinition &instrumentDef, uint8 operatorNum)
 
virtual uint8 calculatePanning (uint8 channel, uint8 source)
 
virtual void setRhythmMode (bool rhythmMode)
 
uint16 determineOperatorRegisterOffset (uint8 oplChannel, uint8 operatorNum, OplInstrumentRhythmType rhythmType=RHYTHM_TYPE_UNDEFINED, bool fourOperator=false)
 
uint16 determineChannelRegisterOffset (uint8 oplChannel, bool fourOperator=false)
 
void writeInstrument (uint8 oplChannel, InstrumentInfo instrument)
 
void writeKeyOff (uint8 oplChannel, OplInstrumentRhythmType rhythmType=RHYTHM_TYPE_UNDEFINED, bool forceWrite=false)
 
void writeRhythm (bool forceWrite=false)
 
virtual void writeVolume (uint8 oplChannel, uint8 operatorNum, OplInstrumentRhythmType rhythmType=RHYTHM_TYPE_UNDEFINED)
 
virtual void writePanning (uint8 oplChannel, OplInstrumentRhythmType rhythmType=RHYTHM_TYPE_UNDEFINED)
 
virtual void writeFrequency (uint8 oplChannel, OplInstrumentRhythmType rhythmType=RHYTHM_TYPE_UNDEFINED)
 
void writeRegister (uint16 reg, uint8 value, bool forceWrite=false)
 
- 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

OPL::Config::OplType _oplType
 
OPL::OPL_opl
 
bool _isOpen
 
int _timerFrequency
 
AccuracyMode _accuracyMode
 
ChannelAllocationMode _allocationMode
 
InstrumentWriteMode _instrumentWriteMode
 
bool _rhythmModeIgnoreNoteOffs
 
uint8 _defaultChannelVolume
 
NoteSelectMode _noteSelect
 
ModulationDepth _modulationDepth
 
VibratoDepth _vibratoDepth
 
bool _rhythmMode
 
OplInstrumentDefinition_instrumentBank
 
OplInstrumentDefinition_rhythmBank
 
uint8 _rhythmBankFirstNote
 
uint8 _rhythmBankLastNote
 
MidiChannelControlData _controlData [MAXIMUM_SOURCES][MIDI_CHANNEL_COUNT]
 
ActiveNote _activeNotes [OPL3_NUM_CHANNELS]
 
ActiveNote _activeRhythmNotes [5]
 
uint8 _channelAllocations [MAXIMUM_SOURCES][MIDI_CHANNEL_COUNT]
 
const uint8 * _melodicChannels
 
uint8 _numMelodicChannels
 
uint32 _noteCounter
 
float _oplFrequencyConversionFactor
 
uint8 _shadowRegisters [0x200]
 
Common::Mutex _allocationMutex
 
Common::Mutex _activeNotesMutex
 
- 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 OPL_LEVEL_DEFAULT = 0x3F
 
static const uint8 OPL_MIDI_PANNING_LEFT_LIMIT = 0x2F
 
static const uint8 OPL_MIDI_PANNING_RIGHT_LIMIT = 0x51
 
static const uint16 OPL_NOTE_FREQUENCIES []
 
static const uint8 OPL_VOLUME_LOOKUP []
 
- Static Protected Attributes inherited from MidiDriver_Multisource
static const uint16 FADING_DELAY = 25 * 1000
 

Detailed Description

MIDI driver for AdLib / OPL2 and OPL3 emulators and devices with support for multiple simultaneous sources of MIDI data.

This driver converts MIDI events to OPL chip register writes. When opened it will initialize an OPL emulator or device using the specified OPL type. It tracks the MIDI state of each source separately to avoid conflicts. The default behavior of the driver plays General MIDI data with the same output as the SoudBlaster 16 Windows 95 driver. It can be subclassed and customized to match the specific behavior of a game.

Customization

Depending on the platform and the type of music data the game uses, you can customize the driver to match this behavior:

  • Windows: If the game uses the standard Windows APIs to play General MIDI data, the default behavior of the driver should give identical output.
  • DOS, General MIDI: The default behavior of the driver should give you a decent starting point, but because there is no standard way to handle GM on OPL chips in DOS, it is probably not accurate. The instruments used by the game can be set in the _instrumentBank and _rhythmBank fields. You can subclass the driver to override more behavior, such as the calculateFrequency, calculatePitchBend, calculateUnscaledVolume and allocateOplChannel functions.
  • DOS, other type of MIDI: Additionally, you will need to override the functions that handle the various MIDI events and controllers when they do not match the General MIDI standard. You can override determineInstrument if the game uses some other way than instrument banks to set instruments.
  • DOS, does not use MIDI: Write new code to access the OPL registers directly instead of using this driver.

TODO Dual OPL2 and 4 operator instrument support is unfinished.

Member Enumeration Documentation

◆ AccuracyMode

The available accuracy modes for frequency and volume calculation.

Enumerator
ACCURACY_MODE_SB16_WIN95 

Accurate to the behavior of the Windows 95 SB16 driver.

ACCURACY_MODE_GM 

Accurate to the General MIDI and MIDI specifications.

◆ ChannelAllocationMode

The available modes for OPL channel allocation.

Enumerator
ALLOCATION_MODE_DYNAMIC 

Dynamic channel allocation (new OPL channel allocated to each note played).

ALLOCATION_MODE_STATIC 

Static channel allocation (fixed OPL channel allocated to each MIDI channel).

◆ InstrumentWriteMode

The available modes for writing the instrument definition to a channel.

Enumerator
INSTRUMENT_WRITE_MODE_NOTE_ON 

Will write the instrument definition before each note on event. Works with both dynamic and static channel allocation modes, but is less efficient and resets all parameters of the instrument when a note is played.

INSTRUMENT_WRITE_MODE_PROGRAM_CHANGE 

Will write the instrument definition after a program change event. This will only work with a static channel allocation mode. It will write the instrument only once for many notes and allows parameters of the instrument to be changed for the following notes.

◆ NoteSelectMode

The available modes for the OPL note select setting.

◆ ModulationDepth

The available modes for the OPL modulation depth setting.

Enumerator
MODULATION_DEPTH_LOW 

Low modulation depth (1 dB).

MODULATION_DEPTH_HIGH 

High modulation depth (4.8 dB).

◆ VibratoDepth

The available modes for the OPL vibrato depth setting.

Enumerator
VIBRATO_DEPTH_LOW 

Low vibrato depth (7 %).

VIBRATO_DEPTH_HIGH 

High vibrato depth (14 %).

Constructor & Destructor Documentation

◆ MidiDriver_ADLIB_Multisource()

MidiDriver_ADLIB_Multisource::MidiDriver_ADLIB_Multisource ( OPL::Config::OplType  oplType,
int  timerFrequency = OPL::OPL::kDefaultCallbackFrequency 
)

Constructs a new AdLib multisource MIDI driver using the specified type of OPL chip.

Parameters
oplTypeThe type of OPL chip that should be used.
timerFrequencyThe number of timer callbacks per second that should be generated.

Member Function Documentation

◆ detectOplType()

static bool MidiDriver_ADLIB_Multisource::detectOplType ( OPL::Config::OplType  oplType)
static

Checks if the specified type of OPL chip is supported by the OPL emulator or hardware that is used.

Parameters
oplTypeThe type of OPL chip that should be detected.
Returns
True if the specified type of OPL chip is supported by the OPL emulator/hardware; false otherwise.

◆ open()

int MidiDriver_ADLIB_Multisource::open ( )
overridevirtual

Prepares the driver for processing MIDI data and initializes the OPL emulator or hardware.

Returns
0 if the driver was opened successfully; a MidiDriver error code otherwise.

Implements MidiDriver.

Reimplemented in AGOS::MidiDriver_Simon1_AdLib, and AGOS::MidiDriver_Accolade_AdLib.

◆ isOpen()

bool MidiDriver_ADLIB_Multisource::isOpen ( ) const
overridevirtual

Check whether the midi driver has already been opened.

Implements MidiDriver.

◆ close()

void MidiDriver_ADLIB_Multisource::close ( )
overridevirtual

Close the midi driver.

Implements MidiDriver.

◆ property()

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

Get or set a property.

Reimplemented from MidiDriver.

◆ getBaseTempo()

uint32 MidiDriver_ADLIB_Multisource::getBaseTempo ( )
overridevirtual

The time in microseconds between invocations of the timer callback.

Implements MidiDriver.

◆ allocateChannel()

MidiChannel* MidiDriver_ADLIB_Multisource::allocateChannel ( )
overridevirtual

This driver does not use MidiChannel objects, so this function returns nullptr.

Returns
nullptr

Implements MidiDriver.

◆ getPercussionChannel()

MidiChannel* MidiDriver_ADLIB_Multisource::getPercussionChannel ( )
overridevirtual

This driver does not use MidiChannel objects, so this function returns nullptr.

Returns
nullptr

Implements MidiDriver.

◆ send()

void MidiDriver_ADLIB_Multisource::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_AdLib, and AGOS::MidiDriver_Accolade_AdLib.

◆ sysEx()

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

◆ metaEvent()

void MidiDriver_ADLIB_Multisource::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 Lure::MidiDriver_ADLIB_Lure, and Ultima::Nuvie::MidiDriver_M_AdLib.

◆ stopAllNotes() [1/2]

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

◆ stopAllNotes() [2/2]

void MidiDriver_ADLIB_Multisource::stopAllNotes ( uint8  source,
uint8  channel 
)
overridevirtual

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.

◆ deinitSource()

void MidiDriver_ADLIB_Multisource::deinitSource ( uint8  source)
overridevirtual

Deinitializes a source. This will abort active fades and stop any active notes.

Parameters
sourceThe source to deinitialize.

Reimplemented from MidiDriver_Multisource.

Reimplemented in Ultima::Nuvie::MidiDriver_M_AdLib, AGOS::MidiDriver_Simon1_AdLib, and AGOS::MidiDriver_Accolade_AdLib.

◆ applySourceVolume()

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

◆ initOpl()

virtual void MidiDriver_ADLIB_Multisource::initOpl ( )
protectedvirtual

Initializes the OPL registers to their default values.

◆ noteOff()

virtual void MidiDriver_ADLIB_Multisource::noteOff ( uint8  channel,
uint8  note,
uint8  velocity,
uint8  source 
)
protectedvirtual

Processes a MIDI note off event.

Parameters
channelThe MIDI channel on which the note is active.
noteThe MIDI note that should be turned off.
velocityThe release velocity (not implemented).
sourceThe source sending the note off event.

◆ noteOn()

virtual void MidiDriver_ADLIB_Multisource::noteOn ( uint8  channel,
uint8  note,
uint8  velocity,
uint8  source 
)
protectedvirtual

Processes a MIDI note on event.

Parameters
channelThe MIDI channel on which the note is played.
noteThe MIDI note that should be turned on.
velocityThe MIDI velocity of the played note.
sourceThe source sending the note on event.

Reimplemented in AGOS::MidiDriver_Simon1_AdLib.

◆ polyAftertouch()

virtual void MidiDriver_ADLIB_Multisource::polyAftertouch ( uint8  channel,
uint8  note,
uint8  pressure,
uint8  source 
)
protectedvirtual

Processes a MIDI polyphonic aftertouch event. Note: this event has no default implementation because it is not implemented in the Win95 SB16 driver.

Parameters
channelThe MIDI channel on which the event is sent.
noteThe MIDI note on which aftertouch should be applied.
pressureThe aftertouch amount that should be applied.
sourceThe source sending the aftertouch event.

◆ controlChange()

virtual void MidiDriver_ADLIB_Multisource::controlChange ( uint8  channel,
uint8  controller,
uint8  value,
uint8  source 
)
protectedvirtual

Processes a MIDI control change event. The individual controllers are handled by separate functions (

See also
modulation etc.).
Parameters
channelThe MIDI channel on which the event is sent.
controllerThe MIDI controller whose value should be changed.
valueThe value that should be applied to the controller.
sourceThe source sending the conrol change event.

◆ programChange()

virtual void MidiDriver_ADLIB_Multisource::programChange ( uint8  channel,
uint8  program,
uint8  source 
)
protectedvirtual

Processes a MIDI program (instrument) change event.

Parameters
channelThe MIDI channel on which the instrument should be set.
programThe instrument that should be set on the channel.
sourceThe source sending the program change event.

Reimplemented in Ultima::Nuvie::MidiDriver_M_AdLib, and AGOS::MidiDriver_Simon1_AdLib.

◆ channelAftertouch()

virtual void MidiDriver_ADLIB_Multisource::channelAftertouch ( uint8  channel,
uint8  pressure,
uint8  source 
)
protectedvirtual

Processes a MIDI channel aftertouch event. Note: this event has no default implementation because it is not implemented in the Win95 SB16 driver.

Parameters
channelThe MIDI channel on which aftertouch should be applied.
pressureThe aftertouch amount that should be applied.
sourceThe source sending the aftertouch event.

Reimplemented in Lure::MidiDriver_ADLIB_Lure.

◆ pitchBend()

virtual void MidiDriver_ADLIB_Multisource::pitchBend ( uint8  channel,
uint8  pitchBendLsb,
uint8  pitchBendMsb,
uint8  source 
)
protectedvirtual

Processes a MIDI pitch bend event. Note that MIDI pitch bend is a 14 bit value sent as 2 7 bit values, with the LSB sent first.

Parameters
channelThe MIDI channel on which pitch bend should be applied.
pitchBendLsbThe LSB of the pitch bend value.
pitchBendMsbThe MSB of the pitch bend value.
sourceThe source sending the pitch bend event.

◆ modulation()

virtual void MidiDriver_ADLIB_Multisource::modulation ( uint8  channel,
uint8  modulation,
uint8  source 
)
protectedvirtual

Processes a MIDI modulation control change event. Note: this event has no default implementation because it is not implemented in the Win95 SB16 driver.

Parameters
channelThe MIDI channel on which modulation should be applied.
modulationThe modulation amount that should be applied.
sourceThe source sending the control change event.

Reimplemented in Ultima::Nuvie::MidiDriver_M_AdLib.

◆ dataEntry()

virtual void MidiDriver_ADLIB_Multisource::dataEntry ( uint8  channel,
uint8  dataMsb,
uint8  dataLsb,
uint8  source 
)
protectedvirtual

Processes a MIDI data entry control change event. This sets the MSB and/or LSB of the currently selected registered parameter number. Note that a MIDI data entry event contains either the MSB or LSB; specify 0xFF for the other data byte to leave it unchanged. RPNs pitch bend sensitivity, master tuning fine and coarse are supported in accuracy mode GM only.

Parameters
channelThe MIDI channel on which the RPN data byte should be set.
dataMsbThe MSB of the RPN data value; 0xFF to not set the MSB.
dataLsbThe LSB of the RPN data value; 0xFF to not set the LSB.
sourceThe source sending the control change event.

◆ volume()

virtual void MidiDriver_ADLIB_Multisource::volume ( uint8  channel,
uint8  volume,
uint8  source 
)
protectedvirtual

Process a MIDI volume control change event.

Parameters
channelThe MIDI channel on which volume should be set.
volumeThe volume level that should be set.
sourceThe source sending the control change event.

◆ panning()

virtual void MidiDriver_ADLIB_Multisource::panning ( uint8  channel,
uint8  panning,
uint8  source 
)
protectedvirtual

Process a MIDI panning control change event. Note that panning is not supported on an OPL2 chip because it has mono output.

Parameters
channelThe MIDI channel on which panning should be set.
panningThe panning value that should be set.
sourceThe source sending the control change event.

◆ expression()

virtual void MidiDriver_ADLIB_Multisource::expression ( uint8  channel,
uint8  expression,
uint8  source 
)
protectedvirtual

Process a MIDI expression control change event.

Parameters
channelThe MIDI channel on which expression should be set.
expressionThe expression value that should be set.
sourceThe source sending the control change event.

◆ sustain()

virtual void MidiDriver_ADLIB_Multisource::sustain ( uint8  channel,
uint8  sustain,
uint8  source 
)
protectedvirtual

Process a MIDI sustain control change event.

Parameters
channelThe MIDI channel on which sustain should be set.
sustainThe sustain value that should be set.
sourceThe source sending the control change event.

◆ registeredParameterNumber()

virtual void MidiDriver_ADLIB_Multisource::registeredParameterNumber ( uint8  channel,
uint8  rpnMsb,
uint8  rpnLsb,
uint8  source 
)
protectedvirtual

Process a MIDI registered parameter number control change event. This sets the currently active RPN; subsequent data entry control change events will set the value for the selected RPN. Note that a MIDI PRN event contains either the MSB or LSB; specify 0xFF for the other rpn byte to leave it unchanged. RPNs pitch bend sensitivity, master tuning fine and coarse are supported in accuracy mode GM only.

Parameters
channelThe MIDI channel on which the active PRN should be set.
rpnMsbThe MSB of the RPN number; 0xFF to not set the MSB.
rpnLsbThe LSB of the RPN number; 0xFF to not set the LSB.
sourceThe source sending the control change event.

◆ allSoundOff()

virtual void MidiDriver_ADLIB_Multisource::allSoundOff ( uint8  channel,
uint8  source 
)
protectedvirtual

Process a MIDI all sound off channel mode event. Note that this should immediately stop all sound, but it is not possible to abort the "release" phase of a note on an OPL chip. So this will function like an all notes off event, except it will also stop sustained notes.

Parameters
channelThe MIDI channel on which the all sound off channel mode event is sent.
sourceThe source sending the control change event.

◆ resetAllControllers()

virtual void MidiDriver_ADLIB_Multisource::resetAllControllers ( uint8  channel,
uint8  source 
)
protectedvirtual

Process a MIDI reset all controllers channel mode event. This will reset the following controllers to their default values:

  • modulation
  • expression
  • sustain
  • active RPN
  • pitch bend
  • channel aftertouch It should also reset polyphonic aftertouch, but this is not implemented.
Parameters
channelThe MIDI channel on which the reset all controllers channel mode event is sent.
sourceThe source sending the control change event.

◆ allNotesOff()

virtual void MidiDriver_ADLIB_Multisource::allNotesOff ( uint8  channel,
uint8  source 
)
protectedvirtual

Process a MIDI all notes off channel mode event. This will turn off all non-sustained notes or sustain all notes if the sustain controller is on.

Parameters
channelThe MIDI channel on which the all notes off channel mode event is sent.
sourceThe source sending the control change event.

◆ applyControllerDefaults()

virtual void MidiDriver_ADLIB_Multisource::applyControllerDefaults ( uint8  source)
protectedvirtual

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

Parameters
sourceThe source triggering the default settings, or 0xFF to apply controller defaults for all sources.

◆ recalculateFrequencies()

virtual void MidiDriver_ADLIB_Multisource::recalculateFrequencies ( uint8  channel,
uint8  source 
)
protectedvirtual

Recalculates and writes the frequencies of the active notes on the specified MIDI channel and source.

Parameters
channelThe MIDI channel on which the note frequencies should be recalculated.
sourceThe source for which the note frequencies should be recalculated.

◆ recalculateVolumes()

virtual void MidiDriver_ADLIB_Multisource::recalculateVolumes ( uint8  channel,
uint8  source 
)
protectedvirtual

Recalculates and writes the volumes of the active notes on the specified MIDI channel and source. 0xFF can be specified to recalculate volumes of notes on all MIDI channels and/or sources.

Parameters
channelThe MIDI channel on which the note volumes should be recalculated; 0xFF to recalculate volumes for all channels.
sourceThe source for which the note volumes should be recalculated; 0xFF to recalculate volumes for all sources.

◆ determineInstrument()

virtual InstrumentInfo MidiDriver_ADLIB_Multisource::determineInstrument ( uint8  channel,
uint8  source,
uint8  note 
)
protectedvirtual

Determines the instrument data necessary to play the specified note on the specified MIDI channel and source. This will determine the instrument definition to use, the note that should be played and an instrument ID for use by the dynamic channel allocation algorithm.

Parameters
channelThe MIDI channel on which the note is played.
sourceThe source playing the note.
noteThe MIDI note which is played.
Returns
The instrument data for playing the note, or an empty struct if the note cannot be played.

Reimplemented in Lure::MidiDriver_ADLIB_Lure, and AGOS::MidiDriver_Accolade_AdLib.

◆ allocateOplChannel()

virtual uint8 MidiDriver_ADLIB_Multisource::allocateOplChannel ( uint8  channel,
uint8  source,
uint8  instrumentId 
)
protectedvirtual

Allocates an OPL channel to play a note on the specified MIDI channel and source with the specified instrument ID. Allocation behavior depends on the active channel allocation mode:

  • Dynamic: allocates an unused channel, a channel playing a note using the same instrument or the channel playing the oldest note. This will always allocate a channel to play the note. This is the same behavior as the Win95 SB16 driver.
  • Static: allocates an unused OPL channel and assigns it to the MIDI channel playing the note. All subsequent notes on this MIDI channel will be played using this OPL channel. If there are no free channels, it will fail to allocate a channel. The MIDI data must play one note at a time on each channel and not use more MIDI channels than there are OPL channels for this algorithm to work properly.
Parameters
channelThe MIDI channel on which the note is played.
sourceThe source playing the note.
instrumentIdThe ID of the instrument playing the note. Not used by the static channel allocation mode.
Returns
The number of the allocated OPL channel; 0xFF if allocation failed (not possible using the dynamic channel allocation mode).

Reimplemented in Ultima::Nuvie::MidiDriver_M_AdLib, and AGOS::MidiDriver_Accolade_AdLib.

◆ determineMelodicChannels()

void MidiDriver_ADLIB_Multisource::determineMelodicChannels ( )
protected

Determines which melodic channels are available based on the OPL chip type and rhythm mode setting and sets _melodicChannels and _numMelodicChannels to the determined values. This is called after constructing the driver with the OPL chip type and after calls to setRhythmMode.

◆ calculateFrequency()

virtual uint16 MidiDriver_ADLIB_Multisource::calculateFrequency ( uint8  channel,
uint8  source,
uint8  note 
)
protectedvirtual

Calculates the OPL frequency (F-num) and octave (block) to play the specified note on the specified MIDI channel and source, taking into account the MIDI controllers pitch bend and (on accuracy mode GM) pitch bend sensitivity and master tuning. The result is returned in the format of the Ax (low byte) and Bx (high byte) OPL registers. Note that the MIDI note range exceeds the frequency range of an OPL chip, so the highest MIDI notes will be shifted down one or two octaves. The SB16 Win95 accuracy mode calculates the same frequencies as the Windows 95 SB16 driver. The GM accuracy mode is more accurate, but the calculations are more CPU intensive. This mode also supports pitch bend sensitivity (which is fixed at 2 semitones in SB16 Win95 mode) and master tuning.

Parameters
channelThe MIDI channel on which the note is played.
sourceThe source playing the note.
noteThe MIDI note which is played.
Returns
The F-num and block to play the note on the OPL chip.

Reimplemented in Lure::MidiDriver_ADLIB_Lure, Ultima::Nuvie::MidiDriver_M_AdLib, and AGOS::MidiDriver_Accolade_AdLib.

◆ calculatePitchBend()

virtual int32 MidiDriver_ADLIB_Multisource::calculatePitchBend ( uint8  channel,
uint8  source,
uint16  oplFrequency 
)
protectedvirtual

Calculates the pitch bend value to apply to the specified OPL frequency (F-num) on the specified MIDI channel and source. If the accuracy mode is GM, pitch bend sensitivity and master tuning settings are also applied. The result is an adjustment which can be added to the OPL frequency to get the pitch bent note.

Parameters
channelThe MIDI channel for which pitch bend should be calculated.
sourceThe source for which pitch bend should be calculated.
oplFrequencyThe OPL frequency for which pitch bend should be calculated.
Returns
The calculated pitch bend (OPL frequency adjustment).

Reimplemented in Lure::MidiDriver_ADLIB_Lure.

◆ calculateVolume()

virtual uint8 MidiDriver_ADLIB_Multisource::calculateVolume ( uint8  channel,
uint8  source,
uint8  velocity,
OplInstrumentDefinition instrumentDef,
uint8  operatorNum 
)
protectedvirtual

Calculates the volume for the specified operator of a note on the specified MIDI channel and source, using the specified MIDI velocity and instrument definition. This function will check if the operator will need to have volume applied to it or if the operator volume from the instrument definition should be used without adjustment (this depends on the connection type). If volume should be applied, unscaled volume is calculated (

See also
calculateUnscaledVolume) and volume is scaled to source and user volume. The volume is returned as an OPL 2x register volume (level) value, i.e. 0 = maximum volume, 3F = minimum volume.
Parameters
channelThe MIDI channel on which the note is played.
sourceThe source playing the note.
velocityThe MIDI velocity of the note for which volume should be calculated.
instrumentDefThe instrument definition used to play the note.
operatorNumThe number of the operator for which volume should be calculated; 0-1 for 2 operator instruments, 0-3 for 4 operator instruments.
Returns
The calculated operator volume (level).

◆ calculateUnscaledVolume()

virtual uint8 MidiDriver_ADLIB_Multisource::calculateUnscaledVolume ( uint8  channel,
uint8  source,
uint8  velocity,
OplInstrumentDefinition instrumentDef,
uint8  operatorNum 
)
protectedvirtual

Calculates the unscaled volume for the specified operator of a note on the specified MIDI channel and source, using the specified MIDI velocity and instrument definition. The SB16 Win95 accuracy mode calculates the same values as the Windows 95 SB16 driver. The GM accuracy mode is more accurate to the volume curve in the General MIDI specification and supports the expression controller, but the calculation is more CPU intensive. The volume is returned as an OPL 2x register volume (level) value, i.e. 0 = maximum volume, 3F = minimum volume.

Parameters
channelThe MIDI channel on which the note is played.
sourceThe source playing the note.
velocityThe MIDI velocity of the note for which volume should be calculated.
instrumentDefThe instrument definition used to play the note.
operatorNumThe number of the operator for which volume should be calculated; 0-1 for 2 operator instruments, 0-3 for 4 operator instruments.
Returns
The calculated unscaled operator volume (level).

Reimplemented in Lure::MidiDriver_ADLIB_Lure, Ultima::Nuvie::MidiDriver_M_AdLib, and AGOS::MidiDriver_Accolade_AdLib.

◆ calculatePanning()

virtual uint8 MidiDriver_ADLIB_Multisource::calculatePanning ( uint8  channel,
uint8  source 
)
protectedvirtual

Determines the panning that should be applied to notes played on the specified MIDI channel and source. This will convert the MIDI panning controller value to simple left, right and center panning and return the result as a Cx register panning value (in bits 4 and 5) for an OPL3 chip.

Parameters
channelThe MIDI channel for which panning should be calculated.
sourceThe source for which panning should be calculated.
Returns
The calculated panning.

◆ setRhythmMode()

virtual void MidiDriver_ADLIB_Multisource::setRhythmMode ( bool  rhythmMode)
protectedvirtual

Activates or deactivates the rhythm mode setting of the OPL chip. This setting uses 3 OPL channels to make 5 preset rhythm instruments available. Rhythm mode is turned off by default. Activating rhythm mode will deallocate and end active notes on channels 6 to 8. Deactivating rhythm mode will end active rhythm notes. If the specified setting is the same as the current setting, this method does nothing.

Parameters
rhythmModeTrue if rhythm mode should be turned on; false if it should be turned off.

◆ determineOperatorRegisterOffset()

uint16 MidiDriver_ADLIB_Multisource::determineOperatorRegisterOffset ( uint8  oplChannel,
uint8  operatorNum,
OplInstrumentRhythmType  rhythmType = RHYTHM_TYPE_UNDEFINED,
bool  fourOperator = false 
)
protected

Determines the offset from a base register for the specified operator of the specified OPL channel or rhythm instrument. Add the offset to the base register to get the correct register for this operator and channel or rhythm instrument.

Parameters
oplChannelThe OPL channel for which to determine the offset. Ignored if a rhythm type is specified.
operatorNumThe operator for which to determine the offset; 0-1 for 2 operator instruments, 0-3 for 4 operator instruments. Ignored for rhythm instruments other than bass drum.
rhythmTypeThe rhythm instrument for which to determine the offset. Specify type undefined to determine the offset for a melodic instrument on the specified channel.
fourOperatorTrue if the instrument used is a 4 operator instrument; false if it is a 2 operator instrument. Ignored if a rhythm instrument type is specified.
Returns
The offset to the base register for this operator.

◆ determineChannelRegisterOffset()

uint16 MidiDriver_ADLIB_Multisource::determineChannelRegisterOffset ( uint8  oplChannel,
bool  fourOperator = false 
)
protected

Determines the offset from a base register for the specified OPL channel. Add the offset to the base register to get the correct register for this channel.

Parameters
oplChannelThe OPL channel for which to determine the offset.
fourOperatorTrue if the instrument used is a 4 operator instrument; false if it is a 2 operator instrument.
Returns
The offset to the base register for this channel.

◆ writeInstrument()

void MidiDriver_ADLIB_Multisource::writeInstrument ( uint8  oplChannel,
InstrumentInfo  instrument 
)
protected

Writes the specified instrument definition to the specified OPL channel. It will calculate volume and panning if necessary.

Parameters
oplChannelThe OPL channel on which to write the instrument.
instrumentThe data of the instrument to write.

◆ writeKeyOff()

void MidiDriver_ADLIB_Multisource::writeKeyOff ( uint8  oplChannel,
OplInstrumentRhythmType  rhythmType = RHYTHM_TYPE_UNDEFINED,
bool  forceWrite = false 
)
protected

Sets the key on bit to false for the specified OPL channel or rhythm instrument and updates _activeNotes or _activeRhythmNotes with the new status. Specify forceWrite to force the OPL register to be written, even if the key on bit is already false according to the shadow registers.

Parameters
oplChannelThe OPL channel on which the key on bit should be set to false. Ignored if a rhythm type is specified.
rhythmTypeThe rhythm instrument for which the key on bit should be set to false.
forceWriteTrue if the OPL register write should be forced; false otherwise.

◆ writeRhythm()

void MidiDriver_ADLIB_Multisource::writeRhythm ( bool  forceWrite = false)
protected

Determines the value for the rhythm register (0xBD) and writes the new value to the OPL chip. This register controls rhythm mode, the rhythm instruments and the vibrato and modulation depth settings.

◆ writeVolume()

virtual void MidiDriver_ADLIB_Multisource::writeVolume ( uint8  oplChannel,
uint8  operatorNum,
OplInstrumentRhythmType  rhythmType = RHYTHM_TYPE_UNDEFINED 
)
protectedvirtual

Calculates the volume for the specified OPL channel or rhythm instrument and operator (

See also
calculateVolume) and writes the new value to the OPL registers.
Parameters
oplChannelThe OPL channel for which volume should be calculated and written. Ignored if a rhythm type is specified.
operatorNumThe operator for which volume should be calculated and written.
rhythmTypeThe rhythm instrument for which volume should be calculated and written. Use type undefined to calculate volume for a melodic instrument.

Reimplemented in Ultima::Nuvie::MidiDriver_M_AdLib.

◆ writePanning()

virtual void MidiDriver_ADLIB_Multisource::writePanning ( uint8  oplChannel,
OplInstrumentRhythmType  rhythmType = RHYTHM_TYPE_UNDEFINED 
)
protectedvirtual

Calculates the panning for the specified OPL channel or rhythm type (

See also
calculatePanning) and writes the new value to the OPL registers.
Parameters
oplChannelThe OPL channel for which panning should be calculated and written. Ignored if a rhythm type is specified.
rhythmTypeThe rhythm instrument for which panning should be calculated and written. Use type undefined to calculate panning for a melodic instrument.

Reimplemented in AGOS::MidiDriver_Accolade_AdLib.

◆ writeFrequency()

virtual void MidiDriver_ADLIB_Multisource::writeFrequency ( uint8  oplChannel,
OplInstrumentRhythmType  rhythmType = RHYTHM_TYPE_UNDEFINED 
)
protectedvirtual

Calculates the frequency for the active note on the specified OPL channel or of the specified rhythm type (

See also
calculateFrequency) and writes the new value to the OPL registers.
Parameters
oplChannelThe OPL channel for which the frequency should be calculated and written. Ignored if a rhythm type is specified.
rhythmTypeThe rhythm instrument for which the frequency should be calculated and written. Use type undefined to calculate the frequency for a melodic instrument.

Reimplemented in AGOS::MidiDriver_Accolade_AdLib.

◆ writeRegister()

void MidiDriver_ADLIB_Multisource::writeRegister ( uint16  reg,
uint8  value,
bool  forceWrite = false 
)
protected

Writes the specified value to the specified OPL register. If the specified value is the same as the current value according to the shadow registers, the value is not written unless forceWrite is specified.

Parameters
regThe OPL register where the value should be written (>= 0x100 for the second register set).
valueThe value to write in the register.
forceWriteTrue if the register write should be forced; false otherwise.

Member Data Documentation

◆ OPL2_NUM_CHANNELS

const uint8 MidiDriver_ADLIB_Multisource::OPL2_NUM_CHANNELS = 9
static

The number of available channels on each OPL chip.

◆ MELODIC_CHANNELS_OPL2

const uint8 MidiDriver_ADLIB_Multisource::MELODIC_CHANNELS_OPL2[9]
static

The melodic channel numbers available on an OPL2 chip with rhythm mode disabled.

◆ MELODIC_CHANNELS_OPL2_RHYTHM

const uint8 MidiDriver_ADLIB_Multisource::MELODIC_CHANNELS_OPL2_RHYTHM[6]
static

The melodic channel numbers available on an OPL2 chip with rhythm mode enabled.

◆ MELODIC_CHANNELS_OPL3

const uint8 MidiDriver_ADLIB_Multisource::MELODIC_CHANNELS_OPL3[18]
static

The melodic channel numbers available on an OPL3 chip with rhythm mode disabled.

◆ MELODIC_CHANNELS_OPL3_RHYTHM

const uint8 MidiDriver_ADLIB_Multisource::MELODIC_CHANNELS_OPL3_RHYTHM[15]
static

The melodic channel numbers available on an OPL3 chip with rhythm mode enabled.

◆ OPL_NUM_RHYTHM_INSTRUMENTS

const uint8 MidiDriver_ADLIB_Multisource::OPL_NUM_RHYTHM_INSTRUMENTS = 5
static

The number of rhythm instruments available in OPL rhythm mode.

◆ OPL_RHYTHM_INSTRUMENT_CHANNELS

const uint8 MidiDriver_ADLIB_Multisource::OPL_RHYTHM_INSTRUMENT_CHANNELS[OPL_NUM_RHYTHM_INSTRUMENTS]
static

The OPL channels used by the rhythm instruments, in order: hi-hat, cymbal, tom tom, snare drum, bass drum.

◆ OPL_REGISTER_TEST

const uint8 MidiDriver_ADLIB_Multisource::OPL_REGISTER_TEST = 0x01
static

OPL test and timer registers.

◆ OPL_REGISTER_NOTESELECT_CSM

const uint8 MidiDriver_ADLIB_Multisource::OPL_REGISTER_NOTESELECT_CSM = 0x08
static

OPL global setting registers.

◆ OPL_REGISTER_BASE_FREQMULT_MISC

const uint8 MidiDriver_ADLIB_Multisource::OPL_REGISTER_BASE_FREQMULT_MISC = 0x20
static

OPL operator base registers.

◆ OPL_REGISTER_BASE_FNUMLOW

const uint8 MidiDriver_ADLIB_Multisource::OPL_REGISTER_BASE_FNUMLOW = 0xA0
static

OPL channel base registers.

◆ OPL3_REGISTER_CONNECTIONSELECT

const uint16 MidiDriver_ADLIB_Multisource::OPL3_REGISTER_CONNECTIONSELECT = 0x104
static

OPL3-specific global setting registers.

◆ OPL_REGISTER_SET_2_OFFSET

const uint16 MidiDriver_ADLIB_Multisource::OPL_REGISTER_SET_2_OFFSET = 0x100
static

Offset to the second register set (for dual OPL2 and OPL3).

◆ OPL_REGISTER_RHYTHM_OFFSETS

const uint8 MidiDriver_ADLIB_Multisource::OPL_REGISTER_RHYTHM_OFFSETS[]
static

Offsets for the rhythm mode instrument registers.

◆ OPL_MASK_LEVEL

const uint8 MidiDriver_ADLIB_Multisource::OPL_MASK_LEVEL = 0x3F
static

Bitmasks for various parameters in the OPL registers.

◆ OPL_PANNING_CENTER

const uint8 MidiDriver_ADLIB_Multisource::OPL_PANNING_CENTER = 0x30
static

Settings for the panning bits in the OPL Cx registers.

◆ OPL_INSTRUMENT_BANK

OplInstrumentDefinition MidiDriver_ADLIB_Multisource::OPL_INSTRUMENT_BANK[]
static

The default melodic instrument definitions.

◆ OPL_RHYTHM_BANK

OplInstrumentDefinition MidiDriver_ADLIB_Multisource::OPL_RHYTHM_BANK[]
static

The default rhythm instrument definitions.

◆ OPL_LEVEL_DEFAULT

const uint8 MidiDriver_ADLIB_Multisource::OPL_LEVEL_DEFAULT = 0x3F
staticprotected

Default setting for OPL channel volume (level).

◆ OPL_MIDI_PANNING_LEFT_LIMIT

const uint8 MidiDriver_ADLIB_Multisource::OPL_MIDI_PANNING_LEFT_LIMIT = 0x2F
staticprotected

The lowest MIDI panning controller value interpreted as left panning.

◆ OPL_MIDI_PANNING_RIGHT_LIMIT

const uint8 MidiDriver_ADLIB_Multisource::OPL_MIDI_PANNING_RIGHT_LIMIT = 0x51
staticprotected

The highest MIDI panning controller value interpreted as right panning.

◆ OPL_NOTE_FREQUENCIES

const uint16 MidiDriver_ADLIB_Multisource::OPL_NOTE_FREQUENCIES[]
staticprotected

OPL frequency (F-num) value for each octave semitone. The values assume octave 5.

◆ OPL_VOLUME_LOOKUP

const uint8 MidiDriver_ADLIB_Multisource::OPL_VOLUME_LOOKUP[]
staticprotected

OPL volume lookup array for a MIDI volume value shifted from 7 to 5 bits.


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