From a933afabfda2986f88e27ea512253227cc629252 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Mon, 22 Jul 2019 19:03:40 +0200 Subject: Add: [Win32] Select MIDI device by port name --- src/music/win32_m.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/music') 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) { -- cgit v1.2.3-70-g09d2