Skip to content
Permalink
Browse files

Codechange: Use common source for well-known SysEx messages in Window…

…s music drivers
  • Loading branch information...
nielsmh committed Jul 4, 2019
1 parent 9d8a83b commit 27384486e486ea2ced69b48f5174577317108731
Showing with 58 additions and 12 deletions.
  1. +6 −6 src/music/dmusic.cpp
  2. +15 −0 src/music/midi.h
  3. +31 −0 src/music/midifile.cpp
  4. +6 −6 src/music/win32_m.cpp
@@ -559,9 +559,11 @@ static void TransmitSysex(IDirectMusicBuffer *buffer, REFERENCE_TIME rt, const b
msg_start = msg_end;
}

static void TransmitSysexConst(IDirectMusicBuffer *buffer, REFERENCE_TIME rt, const byte *msg_start, size_t length)
static void TransmitStandardSysex(IDirectMusicBuffer *buffer, REFERENCE_TIME rt, MidiSysexMessage msg)
{
TransmitSysex(buffer, rt, msg_start, length);
size_t length = 0;
const byte *data = MidiGetStandardSysexMessage(msg, length);
TransmitSysex(buffer, rt, data, length);
}

/** Transmit 'Note off' messages to all MIDI channels. */
@@ -618,11 +620,9 @@ static void MidiThreadProc()
clock->GetTime(&cur_time);

/* Standard "Enable General MIDI" message */
static byte gm_enable_sysex[] = { 0xF0, 0x7E, 0x00, 0x09, 0x01, 0xF7 };
TransmitSysexConst(_buffer, cur_time, &gm_enable_sysex[0], sizeof(gm_enable_sysex));
TransmitStandardSysex(_buffer, block_time + 20, MidiSysexMessage::ResetGM);
/* Roland-specific reverb room control, used by the original game */
static byte roland_reverb_sysex[] = { 0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x01, 0x30, 0x02, 0x04, 0x00, 0x40, 0x40, 0x00, 0x00, 0x09, 0xF7 };
TransmitSysexConst(_buffer, cur_time, &roland_reverb_sysex[0], sizeof(roland_reverb_sysex));
TransmitStandardSysex(_buffer, block_time + 30, MidiSysexMessage::RolandSetReverb);

_port->PlayBuffer(_buffer);
_buffer->Flush();
@@ -141,4 +141,19 @@ enum MidiController {
MIDICT_MODE_POLY = 127,
};


/** Well-known MIDI system exclusive message values for use with the MidiGetStandardSysexMessage function. */
enum class MidiSysexMessage {
/** Reset device to General MIDI defaults */
ResetGM,
/** Reset device to (Roland) General Standard defaults */
ResetGS,
/** Reset device to (Yamaha) XG defaults */
ResetXG,
/** Set up Roland SoundCanvas reverb room as TTD does */
RolandSetReverb,
};

const byte *MidiGetStandardSysexMessage(MidiSysexMessage msg, size_t &length);

#endif /* MUSIC_MIDI_H */
@@ -26,6 +26,37 @@

static MidiFile *_midifile_instance = nullptr;

/**
* Retrieve a well-known MIDI system exclusive message.
* @param msg Which sysex message to retrieve
* @param[out] length Receives the length of the returned buffer
* @return Pointer to byte buffer with sysex message
*/
const byte *MidiGetStandardSysexMessage(MidiSysexMessage msg, size_t &length)
{
static byte reset_gm_sysex[] = { 0xF0, 0x7E, 0x00, 0x09, 0x01, 0xF7 };
static byte reset_gs_sysex[] = { 0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7 };
static byte reset_xg_sysex[] = { 0xF0, 0x43, 0x10, 0x4C, 0x00, 0x00, 0x7E, 0x00, 0xF7 };
static byte roland_reverb_sysex[] = { 0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x01, 0x30, 0x02, 0x04, 0x00, 0x40, 0x40, 0x00, 0x00, 0x09, 0xF7 };

switch (msg) {
case MidiSysexMessage::ResetGM:
length = lengthof(reset_gm_sysex);
return reset_gm_sysex;
case MidiSysexMessage::ResetGS:
length = lengthof(reset_gs_sysex);
return reset_gs_sysex;
case MidiSysexMessage::ResetXG:
length = lengthof(reset_xg_sysex);
return reset_xg_sysex;
case MidiSysexMessage::RolandSetReverb:
length = lengthof(roland_reverb_sysex);
return roland_reverb_sysex;
default:
NOT_REACHED();
}
}

/**
* Owning byte buffer readable as a stream.
* RAII-compliant to make teardown in error situations easier.
@@ -98,9 +98,11 @@ static void TransmitSysex(const byte *&msg_start, size_t &remaining)
msg_start = msg_end;
}

static void TransmitSysexConst(const byte *msg_start, size_t length)
static void TransmitStandardSysex(MidiSysexMessage msg)
{
TransmitSysex(msg_start, length);
size_t length = 0;
const byte *data = MidiGetStandardSysexMessage(msg, length);
TransmitSysex(data, length);
}

/**
@@ -370,12 +372,10 @@ const char *MusicDriver_Win32::Start(const char * const *parm)
midiOutReset(_midi.midi_out);

/* Standard "Enable General MIDI" message */
static byte gm_enable_sysex[] = { 0xF0, 0x7E, 0x00, 0x09, 0x01, 0xF7 };
TransmitSysexConst(&gm_enable_sysex[0], sizeof(gm_enable_sysex));
TransmitStandardSysex(MidiSysexMessage::ResetGM);

/* Roland-specific reverb room control, used by the original game */
static byte roland_reverb_sysex[] = { 0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x01, 0x30, 0x02, 0x04, 0x00, 0x40, 0x40, 0x00, 0x00, 0x09, 0xF7 };
TransmitSysexConst(&roland_reverb_sysex[0], sizeof(roland_reverb_sysex));
TransmitStandardSysex(MidiSysexMessage::RolandSetReverb);

/* prepare multimedia timer */
TIMECAPS timecaps;

0 comments on commit 2738448

Please sign in to comment.
You can’t perform that action at this time.