[Scummvm-cvs-logs] scummvm master -> 535a55e47a2ef433c4daa88068a6defab801942b
athrxx
athrxx at scummvm.org
Sat Feb 25 14:33:29 CET 2012
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
535a55e47a AUDIO: (Windows) fix issue with non-unique MIDI device names
Commit: 535a55e47a2ef433c4daa88068a6defab801942b
https://github.com/scummvm/scummvm/commit/535a55e47a2ef433c4daa88068a6defab801942b
Author: athrxx (athrxx at scummvm.org)
Date: 2012-02-25T05:15:49-08:00
Commit Message:
AUDIO: (Windows) fix issue with non-unique MIDI device names
This should fix the issue mentioned here: http://forums.scummvm.org/viewtopic.php?t=11255
Apparently Windows doesn't generate unique names for MIDI devices of the exact same type.
I do not know whether this could be a problem on other backends, too.
Changed paths:
backends/midi/windows.cpp
diff --git a/backends/midi/windows.cpp b/backends/midi/windows.cpp
index 828411c..f4c5431 100644
--- a/backends/midi/windows.cpp
+++ b/backends/midi/windows.cpp
@@ -177,13 +177,49 @@ MusicDevices WindowsMusicPlugin::getDevices() const {
int numDevs = midiOutGetNumDevs();
MIDIOUTCAPS tmp;
+ Common::StringArray deviceNames;
for (int i = 0; i < numDevs; i++) {
if (midiOutGetDevCaps(i, &tmp, sizeof(MIDIOUTCAPS)) != MMSYSERR_NOERROR)
break;
+ deviceNames.push_back(tmp.szPname);
+ }
+
+ // Check for non-unique device names. This may happen if someone has devices with identical
+ // names (e. g. more than one USB device of the exact same hardware type). It seems that this
+ // does happen in reality sometimes. We generate index numbers for these devices.
+ // This is not an ideal solution, since this index could change whenever another USB
+ // device gets plugged in or removed, switched off or just plugged into a different port.
+ // Unfortunately midiOutGetDevCaps() does not generate any other unique information
+ // that could be used. Our index numbers which match the device order should at least be
+ // a little more stable than just using the midiOutGetDevCaps() device ID, since a missing
+ // device (e.g. switched off) should actually not be harmful to our indices (as it would be
+ // when using the device IDs). The cases where users have devices with identical names should
+ // be rare enough anyway.
+ Common::Array<int> nonUniqueIndex;
+ for (int i = 0; i < numDevs; i++) {
+ int match = -1;
+ for (int ii = 0; ii < i; ii++) {
+ if (deviceNames[i] == deviceNames[ii]) {
+ if (nonUniqueIndex[ii] == -1)
+ nonUniqueIndex[ii] = 0;
+ if (++match == 0)
+ ++match;
+ }
+ }
+ nonUniqueIndex.push_back(match);
+ }
+
+ // We now add the index number to the non-unique device names to make them unique.
+ for (int i = 0; i < numDevs; i++) {
+ if (nonUniqueIndex[i] != -1)
+ deviceNames[i] = Common::String::format("%s - #%.02d", deviceNames[i].c_str(), nonUniqueIndex[i]);
+ }
+
+ for (Common::StringArray::iterator i = deviceNames.begin(); i != deviceNames.end(); ++i)
// There is no way to detect the "MusicType" so I just set it to MT_GM
// The user will have to manually select his MT32 type device and his GM type device.
- devices.push_back(MusicDevice(this, tmp.szPname, MT_GM));
- }
+ devices.push_back(MusicDevice(this, *i, MT_GM));
+
return devices;
}
More information about the Scummvm-git-logs
mailing list