Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: [Win32] Select MIDI device by port name #7666

Merged
merged 1 commit into from
Aug 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/music/win32_m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a particular need for {} ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably not strictly required, mainly for being 110% sure nobody complains about passing pointers to uninitialised memory.

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) {
Expand Down