summaryrefslogtreecommitdiff
path: root/src/music
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2019-07-22 19:03:40 +0200
committerCharles Pigott <charlespigott@googlemail.com>2019-08-31 21:13:25 +0100
commita933afabfda2986f88e27ea512253227cc629252 (patch)
tree7588cea958d3afc8890c6e2097cca9b354c48c10 /src/music
parent28e11623bd22fcf933350aae980b28008f113286 (diff)
downloadopenttd-a933afabfda2986f88e27ea512253227cc629252.tar.xz
Add: [Win32] Select MIDI device by port name
Diffstat (limited to 'src/music')
-rw-r--r--src/music/win32_m.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp
index 21ffe1ed3..cb6301a57 100644
--- a/src/music/win32_m.cpp
+++ b/src/music/win32_m.cpp
@@ -370,6 +370,26 @@ const char *MusicDriver_Win32::Start(const char * const *parm)
int resolution = GetDriverParamInt(parm, "resolution", 5);
int port = GetDriverParamInt(parm, "port", -1);
+ const char *portname = GetDriverParam(parm, "portname");
+
+ /* Enumerate ports either for selecting port by name, or for debug output */
+ if (portname != nullptr || _debug_driver_level > 0) {
+ uint numports = midiOutGetNumDevs();
+ DEBUG(driver, 1, "Win32-MIDI: Found %d output devices:", numports);
+ for (uint tryport = 0; tryport < numports; tryport++) {
+ MIDIOUTCAPS moc{};
+ if (midiOutGetDevCaps(tryport, &moc, sizeof(moc)) == MMSYSERR_NOERROR) {
+ char tryportname[128];
+ convert_from_fs(moc.szPname, tryportname, lengthof(tryportname));
+
+ /* Compare requested and detected port name.
+ * If multiple ports have the same name, this will select the last matching port, and the debug output will be confusing. */
+ if (portname != nullptr && strncmp(tryportname, portname, lengthof(tryportname)) == 0) port = tryport;
+
+ DEBUG(driver, 1, "MIDI port %2d: %s%s", tryport, tryportname, (tryport == port) ? " [selected]" : "");
+ }
+ }
+ }
UINT devid;
if (port < 0) {