From e1bb14803e7fa63daa5a308fdadad713b3466e98 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 3 Mar 2018 08:52:25 +0100 Subject: [PATCH] - print an error message if the requested MIDI device cannot be started. This will only be done the first time a given setup fails. Repeated messages will be muted. --- src/sound/i_music.cpp | 18 +--- .../music_wavewriter_mididevice.cpp | 2 +- src/sound/musicformats/music_midistream.cpp | 82 +++++++++++++------ 3 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index 1c3ed8d287..cbea4ee2ca 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -461,7 +461,6 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) return 0; } - // fixme: device and streamer need to be handled individually. EMidiDevice devtype = device == nullptr? MDEV_DEFAULT : (EMidiDevice)device->device; #ifndef _WIN32 // non-Windows platforms don't support MDEV_MMAPI so map to MDEV_SNDSYS @@ -469,24 +468,11 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) devtype = MDEV_SNDSYS; #endif - MIDIStreamer *streamer = nullptr; -retry_as_sndsys: - streamer = CreateMIDIStreamer(devtype, device != nullptr? device->args.GetChars() : ""); - - if (streamer == nullptr && devtype != MDEV_SNDSYS && snd_mididevice < 0) - { - devtype = MDEV_SNDSYS; - goto retry_as_sndsys; - } -#ifdef _WIN32 - if (streamer == nullptr && devtype != MDEV_MMAPI && snd_mididevice >= 0) - { - streamer = CreateMIDIStreamer(MDEV_MMAPI, ""); - } -#endif + MIDIStreamer *streamer = CreateMIDIStreamer(devtype, device != nullptr? device->args.GetChars() : ""); if (streamer == nullptr) { delete reader; + delete source; return 0; } streamer->SetMIDISource(source); diff --git a/src/sound/mididevices/music_wavewriter_mididevice.cpp b/src/sound/mididevices/music_wavewriter_mididevice.cpp index 44e263bdfe..ddf5bb3bb2 100644 --- a/src/sound/mididevices/music_wavewriter_mididevice.cpp +++ b/src/sound/mididevices/music_wavewriter_mididevice.cpp @@ -1,6 +1,6 @@ /* ** music_wavewriter_mididevice.cpp -** Dumos a MIDI to a wave file by using one of the other software synths. +** Dumps a MIDI to a wave file by using one of the other software synths. ** **--------------------------------------------------------------------------- ** Copyright 2008 Randy Heit diff --git a/src/sound/musicformats/music_midistream.cpp b/src/sound/musicformats/music_midistream.cpp index 5889b0e1da..eea2049100 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -40,6 +40,7 @@ #include "doomdef.h" #include "m_swap.h" #include "doomerrors.h" +#include "v_text.h" // MACROS ------------------------------------------------------------------ @@ -179,46 +180,56 @@ EMidiDevice MIDIStreamer::SelectMIDIDevice(EMidiDevice device) // //========================================================================== +static EMidiDevice lastRequestedDevice, lastSelectedDevice; + MIDIDevice *MIDIStreamer::CreateMIDIDevice(EMidiDevice devtype) { - // fixme: This should check up front if the device can be started. - // Checks to ensure that a device finds a compatible sound font are entirely missing here. bool checked[MDEV_COUNT] = { false }; + MIDIDevice *dev = nullptr; if (devtype == MDEV_SNDSYS) devtype = MDEV_FLUIDSYNTH; - while (true) + EMidiDevice requestedDevice = devtype, selectedDevice; + while (dev == nullptr) { + selectedDevice = devtype; try { - switch (devtype) - { + switch (devtype) + { case MDEV_GUS: - return new TimidityMIDIDevice(Args); - - case MDEV_MMAPI: -#ifdef _WIN32 - return CreateWinMIDIDevice(mididevice); -#endif - // Intentional fall-through for non-Windows systems. - - case MDEV_FLUIDSYNTH: - return new FluidSynthMIDIDevice(Args); - - case MDEV_OPL: - return new OPLMIDIDevice(Args); - - case MDEV_TIMIDITY: - return CreateTimidityPPMIDIDevice(Args); - - case MDEV_WILDMIDI: - return new WildMIDIDevice(Args); - - default: + dev = new TimidityMIDIDevice(Args); break; - } + + case MDEV_MMAPI: + #ifdef _WIN32 + dev = CreateWinMIDIDevice(mididevice); + break; +#endif + // Intentional fall-through for non-Windows systems. + + case MDEV_FLUIDSYNTH: + dev = new FluidSynthMIDIDevice(Args); + break; + + case MDEV_OPL: + dev = new OPLMIDIDevice(Args); + break; + + case MDEV_TIMIDITY: + dev = CreateTimidityPPMIDIDevice(Args); + break; + + case MDEV_WILDMIDI: + dev = new WildMIDIDevice(Args); + break; + + default: + break; + } } catch (CRecoverableError &err) { + DPrintf(DMSG_WARNING, "%s\n", err.GetMessage()); checked[devtype] = true; devtype = MDEV_DEFAULT; // Opening the requested device did not work out so choose another one. @@ -238,6 +249,23 @@ MIDIDevice *MIDIStreamer::CreateMIDIDevice(EMidiDevice devtype) } } } + if (selectedDevice != requestedDevice && (selectedDevice != lastSelectedDevice || requestedDevice != lastRequestedDevice)) + { + static const char *devnames[] = { + "Windows Default", + "OPL", + "", + "Timidity++", + "FluidSynth", + "GUS", + "WildMidi" + }; + + lastRequestedDevice = requestedDevice; + lastSelectedDevice = selectedDevice; + Printf(TEXTCOLOR_RED "Unable to create " TEXTCOLOR_ORANGE "%s" TEXTCOLOR_RED " MIDI device. Falling back to " TEXTCOLOR_ORANGE "%s\n", devnames[requestedDevice], devnames[selectedDevice]); + } + return dev; } //==========================================================================