22 #ifndef AUDIO_MIDIDRV_H 23 #define AUDIO_MIDIDRV_H 25 #include "common/scummsys.h" 26 #include "common/str.h" 27 #include "common/stream.h" 28 #include "common/timer.h" 29 #include "common/array.h" 89 MDT_APPLEIIGS = 1 << 6,
94 MDT_PREFER_MT32 = 1 << 11,
95 MDT_PREFER_GM = 1 << 12,
96 MDT_PREFER_FLUID = 1 << 13,
97 MDT_MACINTOSH = 1 << 14,
99 MDT_SUPPLIED_SOUND_FONT = 1 << 15,
102 enum MidiDriverCheckFlags {
105 MDCK_SUPPLIED_SOUND_FONT = 1 << 0,
114 static const uint8 MIDI_CHANNEL_COUNT = 16;
115 static const uint8 MIDI_RHYTHM_CHANNEL = 9;
117 static const byte MIDI_COMMAND_NOTE_OFF = 0x80;
118 static const byte MIDI_COMMAND_NOTE_ON = 0x90;
119 static const byte MIDI_COMMAND_POLYPHONIC_AFTERTOUCH = 0xA0;
120 static const byte MIDI_COMMAND_CONTROL_CHANGE = 0xB0;
121 static const byte MIDI_COMMAND_PROGRAM_CHANGE = 0xC0;
122 static const byte MIDI_COMMAND_CHANNEL_AFTERTOUCH = 0xD0;
123 static const byte MIDI_COMMAND_PITCH_BEND = 0xE0;
124 static const byte MIDI_COMMAND_SYSTEM = 0xF0;
126 static const byte MIDI_CONTROLLER_BANK_SELECT_MSB = 0x00;
127 static const byte MIDI_CONTROLLER_MODULATION = 0x01;
128 static const byte MIDI_CONTROLLER_DATA_ENTRY_MSB = 0x06;
129 static const byte MIDI_CONTROLLER_VOLUME = 0x07;
130 static const byte MIDI_CONTROLLER_BALANCE = 0x08;
131 static const byte MIDI_CONTROLLER_PANNING = 0x0A;
132 static const byte MIDI_CONTROLLER_EXPRESSION = 0x0B;
133 static const byte MIDI_CONTROLLER_BANK_SELECT_LSB = 0x20;
134 static const byte MIDI_CONTROLLER_DATA_ENTRY_LSB = 0x26;
135 static const byte MIDI_CONTROLLER_SUSTAIN = 0x40;
136 static const byte MIDI_CONTROLLER_PORTAMENTO = 0x41;
137 static const byte MIDI_CONTROLLER_SOSTENUTO = 0x42;
138 static const byte MIDI_CONTROLLER_SOFT = 0x43;
139 static const byte MIDI_CONTROLLER_REVERB = 0x5B;
140 static const byte MIDI_CONTROLLER_CHORUS = 0x5D;
141 static const byte MIDI_CONTROLLER_RPN_LSB = 0x64;
142 static const byte MIDI_CONTROLLER_RPN_MSB = 0x65;
143 static const byte MIDI_CONTROLLER_ALL_SOUND_OFF = 0x78;
144 static const byte MIDI_CONTROLLER_RESET_ALL_CONTROLLERS = 0x79;
145 static const byte MIDI_CONTROLLER_ALL_NOTES_OFF = 0x7B;
146 static const byte MIDI_CONTROLLER_OMNI_ON = 0x7C;
147 static const byte MIDI_CONTROLLER_OMNI_OFF = 0x7D;
148 static const byte MIDI_CONTROLLER_MONO_ON = 0x7E;
149 static const byte MIDI_CONTROLLER_POLY_ON = 0x7F;
151 static const uint16 MIDI_RPN_PITCH_BEND_SENSITIVITY = 0x0000;
152 static const uint16 MIDI_RPN_MASTER_TUNING_FINE = 0x0001;
153 static const uint16 MIDI_RPN_MASTER_TUNING_COARSE = 0x0002;
154 static const uint16 MIDI_RPN_NULL = 0x7F7F;
156 static const uint8 MIDI_META_END_OF_TRACK = 0x2F;
157 static const uint8 MIDI_META_SEQUENCER = 0x7F;
159 static const uint16 MIDI_PITCH_BEND_DEFAULT = 0x2000;
160 static const uint8 MIDI_PANNING_DEFAULT = 0x40;
161 static const uint8 MIDI_EXPRESSION_DEFAULT = 0x7F;
162 static const uint16 MIDI_MASTER_TUNING_FINE_DEFAULT = 0x2000;
163 static const uint8 MIDI_MASTER_TUNING_COARSE_DEFAULT = 0x40;
165 static const uint8 MT32_PITCH_BEND_SENSITIVITY_DEFAULT = 0x0C;
166 static const uint8 GM_PITCH_BEND_SENSITIVITY_DEFAULT = 0x02;
168 static const uint8 GS_RHYTHM_FIRST_NOTE = 0x1B;
169 static const uint8 GS_RHYTHM_LAST_NOTE = 0x58;
181 virtual void send(uint32 b) = 0;
188 virtual void send(int8 source, uint32 b) {
send(b); }
197 void send(byte status, byte firstOp, byte secondOp);
204 void send(int8 source, byte status, byte firstOp, byte secondOp);
216 virtual void sysEx(
const byte *msg, uint16 length) { }
233 virtual void metaEvent(byte type, byte *data, uint16 length) { }
240 virtual void metaEvent(int8 source, byte type, byte *data, uint16 length) {
metaEvent(type, data, length); }
258 virtual void stopAllNotes(
bool stopSustainedNotes =
false);
268 virtual bool isReady(int8 source = -1) {
return true; }
320 enum DeviceStringType {
330 static MidiDriver *createMidi(DeviceHandle handle);
333 static DeviceHandle detectDevice(
int flags);
336 static DeviceHandle getDeviceHandle(
const Common::String &identifier);
347 static bool checkDevice(DeviceHandle handle,
int flags,
bool quiet);
350 static MusicType getMusicType(DeviceHandle handle);
353 static Common::String getDeviceString(DeviceHandle handle, DeviceStringType type);
356 void midiDriverCommonSend(uint32 b);
359 void midiDriverCommonSysEx(
const byte *msg, uint16 length);
367 static bool _forceTypeMT32;
372 static const byte _mt32ToGm[128];
373 static const byte _gmToMt32[128];
380 MERR_CANNOT_CONNECT = 1,
382 MERR_DEVICE_NOT_AVAILABLE = 3,
383 MERR_ALREADY_OPEN = 4
389 PROP_CHANNEL_MASK = 3,
401 PROP_USER_VOLUME_SCALING = 5,
420 PROP_MIDI_DATA_REVERSE_PANNING = 6,
432 PROP_OPL_ACCURACY_MODE = 7,
452 PROP_OPL_CHANNEL_ALLOCATION_MODE = 8,
463 PROP_MILES_VERSION = 9,
477 PROP_OPL_RHYTHM_MODE_IGNORE_NOTE_OFF = 10
484 virtual int open() = 0;
489 virtual bool isOpen()
const = 0;
492 virtual void close() = 0;
495 virtual uint32
property(
int prop, uint32 param) {
return 0; }
498 static const char *getErrorName(
int error_code);
501 virtual void setPitchBendRange(byte channel, uint range) {
502 send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_RPN_MSB, MIDI_RPN_PITCH_BEND_SENSITIVITY >> 8);
503 send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_RPN_LSB, MIDI_RPN_PITCH_BEND_SENSITIVITY & 0xFF);
504 send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_DATA_ENTRY_MSB, range);
505 send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_DATA_ENTRY_LSB, 0);
506 send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_RPN_MSB, MIDI_RPN_NULL >> 8);
507 send(MIDI_COMMAND_CONTROL_CHANGE | channel, MIDI_CONTROLLER_RPN_LSB, MIDI_RPN_NULL & 0xFF);
513 void sendMT32Reset();
524 virtual uint32 getBaseTempo() = 0;
534 virtual bool acceptsSoundFontData() {
return false; }
542 virtual byte getNumber() = 0;
543 virtual void release() = 0;
545 virtual void send(uint32 b) = 0;
548 virtual void noteOff(byte note) = 0;
549 virtual void noteOn(byte note, byte velocity) = 0;
550 virtual void programChange(byte program) = 0;
551 virtual void pitchBend(int16 bend) = 0;
554 virtual void controlChange(byte control, byte value) = 0;
555 virtual void modulationWheel(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_MODULATION, value); }
556 virtual void volume(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_VOLUME, value); }
557 virtual void panPosition(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_PANNING, value); }
558 virtual void pitchBendFactor(byte value) = 0;
559 virtual void transpose(int8 value) {}
560 virtual void detune(int16 value) { controlChange(17, value & 0xff); }
561 virtual void priority(byte value) { }
562 virtual void sustain(
bool value) { controlChange(MidiDriver::MIDI_CONTROLLER_SUSTAIN, value ? 1 : 0); }
563 virtual void effectLevel(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_REVERB, value); }
564 virtual void chorusLevel(byte value) { controlChange(MidiDriver::MIDI_CONTROLLER_CHORUS, value); }
565 virtual void bankSelect(byte bank) {}
566 virtual void allNotesOff() { controlChange(MidiDriver::MIDI_CONTROLLER_ALL_NOTES_OFF, 0); }
569 virtual void sysEx_customInstrument(uint32 type,
const byte *instr, uint32 dataSize) = 0;
virtual uint32 property(int prop, uint32 param)
Definition: mididrv.h:495
void midiDumpDo(uint32 b)
int midiDumpVarLength(const uint32 &delta)
virtual void metaEvent(int8 source, byte type, byte *data, uint16 length)
Definition: mididrv.h:240
bool _midiDumpEnable
Definition: mididrv.h:276
uint32 DeviceHandle
Definition: mididrv.h:318
MusicType
Definition: mididrv.h:44
void(* TimerProc)(void *refCon)
Definition: timer.h:42
MidiDriverFlags
Definition: mididrv.h:81
virtual void stopAllNotes(bool stopSustainedNotes=false)
Definition: mididrv.h:309
virtual bool isReady(int8 source=-1)
Definition: mididrv.h:268
virtual void send(int8 source, uint32 b)
Definition: mididrv.h:188
Common::Array< byte > _midiDumpCache
Definition: mididrv.h:282
Definition: mididrv.h:112
void midiDumpSysEx(const byte *msg, uint16 length)
Definition: mididrv.h:537
uint32 _prevMillis
Definition: mididrv.h:279
virtual void sysEx(const byte *msg, uint16 length)
Definition: mididrv.h:216
virtual void send(uint32 b)=0
virtual uint16 sysExNoDelay(const byte *msg, uint16 length)
Definition: mididrv.h:230