summaryrefslogtreecommitdiff
path: root/src/music
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2019-07-04 21:14:41 +0200
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-07-04 22:27:34 +0200
commit27384486e486ea2ced69b48f5174577317108731 (patch)
tree99a63f13ce4450bded86b245e9518faacbdfd222 /src/music
parent9d8a83bf8d6f1753ea7dc99faa94695c050d818c (diff)
downloadopenttd-27384486e486ea2ced69b48f5174577317108731.tar.xz
Codechange: Use common source for well-known SysEx messages in Windows music drivers
Diffstat (limited to 'src/music')
-rw-r--r--src/music/dmusic.cpp12
-rw-r--r--src/music/midi.h15
-rw-r--r--src/music/midifile.cpp31
-rw-r--r--src/music/win32_m.cpp12
4 files changed, 58 insertions, 12 deletions
diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp
index f160b3f08..65e2d4c83 100644
--- a/src/music/dmusic.cpp
+++ b/src/music/dmusic.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();
diff --git a/src/music/midi.h b/src/music/midi.h
index 473f7f18b..90f04435e 100644
--- a/src/music/midi.h
+++ b/src/music/midi.h
@@ -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 */
diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp
index 0259181b3..33d09c80b 100644
--- a/src/music/midifile.cpp
+++ b/src/music/midifile.cpp
@@ -27,6 +27,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.
*/
diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp
index 7cdf72729..f5360df11 100644
--- a/src/music/win32_m.cpp
+++ b/src/music/win32_m.cpp
@@ -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;