Skip to content

Commit

Permalink
AUDIO: improved warnings in detectDevice()
Browse files Browse the repository at this point in the history
Silent fallback would occur if the user expressly selected a formerly available audio device which now has become unavailable (switched off, disconnected, no longer compiled in, etc.). A warning dialogue will now be displayed, before the fallback takes place.
  • Loading branch information
athrxx committed Jun 14, 2011
1 parent e6b671e commit 6efc829
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions audio/mididrv.cpp
Expand Up @@ -190,20 +190,30 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {

case MT_NULL:
reslt = hdl;
break;

default:
break;
}

Common::String failedDevStr;
if (getMusicType(hdl) == MT_INVALID) {
// If the expressly selected driver or device cannot be found (no longer compiled in, turned off, etc.)
// we display a warning and continue.
failedDevStr = ConfMan.get("music_driver");
Common::String warningMsg = Common::String::format(_("The selected audio device '%s' was not found (e.g. might be turned off or disconnected). Attempting to fall back to the next available device..."), failedDevStr.c_str());
GUI::MessageDialog dialog(warningMsg);
dialog.runModal();
}

MusicType tp = getMusicType(reslt);
if (tp != MT_INVALID && tp != MT_AUTO) {
if (checkDevice(reslt)) {
return reslt;
} else {
// If the expressly selected device is unavailable we display a warning and continue.
// If the expressly selected device cannot be used we display a warning and continue.
failedDevStr = getDeviceString(hdl, MidiDriver::kDeviceName);
Common::String warningMsg = Common::String::format(_("Failed to detect the selected audio device '%s'. See log file for more information. Attempting to fall back to the next available device..."), failedDevStr.c_str());
Common::String warningMsg = Common::String::format(_("The selected audio device '%s' cannot be used. See log file for more information. Attempting to fall back to the next available device..."), failedDevStr.c_str());
GUI::MessageDialog dialog(warningMsg);
dialog.runModal();
}
Expand All @@ -220,30 +230,41 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
while (flags != MDT_NONE) {
if ((flags & MDT_MIDI) && !skipMidi) {
// If a preferred MT32 or GM device has been selected that device gets returned if available.
if (flags & MDT_PREFER_MT32)
hdl = getDeviceHandle(ConfMan.get("mt32_device"));
Common::String devStr;
if (flags & MDT_PREFER_MT32)
devStr = ConfMan.get("mt32_device");
else if (flags & MDT_PREFER_GM)
hdl = getDeviceHandle(ConfMan.get("gm_device"));
devStr = ConfMan.get("gm_device");
else
hdl = getDeviceHandle("auto");
devStr = "auto";

hdl = getDeviceHandle(devStr);
const MusicType type = getMusicType(hdl);

// If have a "Don't use GM/MT-32" setting we skip this part and jump
// to AdLib, PC Speaker etc. detection right away.
if (type != MT_NULL) {
if (type != MT_AUTO && type != MT_INVALID) {
if (type == MT_INVALID) {
// If the preferred (expressly requested) selected driver or device cannot be found (no longer compiled in, turned off, etc.)
// we display a warning and continue. Don't warn about the missing device if we did already (this becomes relevant if the
// missing device is selected as preferred device and also as GM or MT-32 device).
if (failedDevStr != devStr) {
Common::String warningMsg = Common::String::format(_("The preferred audio device '%s' was not found (e.g. might be turned off or disconnected). Attempting to fall back to the next available device..."), devStr.c_str());
GUI::MessageDialog dialog(warningMsg);
dialog.runModal();
}
} else if (type != MT_AUTO) {
if (checkDevice(hdl)) {
if (flags & MDT_PREFER_MT32)
// If we have a preferred MT32 device we disable the gm/mt32 mapping (more about this in mididrv.h).
_forceTypeMT32 = true;
return hdl;
} else {
// If the preferred (expressly requested) device is unavailable we display a warning and continue.
// Don't warn about the missing device if we did already (this becomes relevant if the failing
// If the preferred (expressly requested) device cannot be used we display a warning and continue.
// Don't warn about the failing device if we did already (this becomes relevant if the failing
// device is selected as preferred device and also as GM or MT-32 device).
if (failedDevStr != getDeviceString(hdl, MidiDriver::kDeviceName)) {
Common::String warningMsg = Common::String::format(_("Failed to detect the preferred device '%s'. See log file for more information. Attempting to fall back to the next available device..."), getDeviceString(hdl, MidiDriver::kDeviceName).c_str());
Common::String warningMsg = Common::String::format(_("The preferred audio device '%s' cannot be used. See log file for more information. Attempting to fall back to the next available device..."), getDeviceString(hdl, MidiDriver::kDeviceName).c_str());
GUI::MessageDialog dialog(warningMsg);
dialog.runModal();
}
Expand Down

0 comments on commit 6efc829

Please sign in to comment.