- 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.
This commit is contained in:
Christoph Oelckers 2018-03-03 08:52:25 +01:00
parent 4c0f68bcd4
commit e1bb14803e
3 changed files with 58 additions and 44 deletions

View file

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

View file

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

View file

@ -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;
}
//==========================================================================