Add: [Win32] Select MIDI device by port name

This commit is contained in:
Niels Martin Hansen 2019-07-22 19:03:40 +02:00 committed by Charles Pigott
parent 28e11623bd
commit a933afabfd
1 changed files with 20 additions and 0 deletions

View File

@ -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) {