From ca88c5206401943fc542707ff35fcb571f6c0669 Mon Sep 17 00:00:00 2001 From: elasota <1137273+elasota@users.noreply.github.com> Date: Mon, 4 Mar 2024 19:36:37 -0500 Subject: [PATCH] AUDIO: Split MIDI check flags out, fail checkDevice by default for "auto" --- audio/mididrv.cpp | 12 ++++++++---- audio/mididrv.h | 7 +++++++ audio/musicplugin.h | 10 ++++++++-- audio/softsynth/fluidsynth.cpp | 2 +- backends/midi/seq.cpp | 5 +++++ backends/midi/windows.cpp | 5 +++++ 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/audio/mididrv.cpp b/audio/mididrv.cpp index 5d2ad58ba22..e4efdc0220e 100644 --- a/audio/mididrv.cpp +++ b/audio/mididrv.cpp @@ -216,8 +216,12 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) { break; } - int checkFlags = (flags & (MDT_SUPPLIED_SOUND_FONT)); - flags ^= checkFlags; + int checkFlags = MDCK_NONE; + + if (flags & MDT_SUPPLIED_SOUND_FONT) { + checkFlags |= MDCK_SUPPLIED_SOUND_FONT; + flags ^= MDT_SUPPLIED_SOUND_FONT; + } Common::String failedDevStr; if (getMusicType(hdl) == MT_INVALID) { @@ -311,7 +315,7 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { if (d->getMusicType() == MT_MT32) { hdl = d->getHandle(); - if (checkDevice(hdl, checkFlags, true)) + if (checkDevice(hdl, checkFlags | MDCK_AUTO, true)) return hdl; } } @@ -326,7 +330,7 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { if (d->getMusicType() == MT_GM || d->getMusicType() == MT_GS) { hdl = d->getHandle(); - if (checkDevice(hdl, checkFlags, true)) + if (checkDevice(hdl, checkFlags | MDCK_AUTO, true)) return hdl; } } diff --git a/audio/mididrv.h b/audio/mididrv.h index 290031c9c29..57b89da37e2 100644 --- a/audio/mididrv.h +++ b/audio/mididrv.h @@ -99,6 +99,13 @@ enum MidiDriverFlags { MDT_SUPPLIED_SOUND_FONT = 1 << 15, // Engine will supply sound font (allows checkDevice to pass if it would fail due to missing sound font) }; +enum MidiDriverCheckFlags { + MDCK_NONE = 0, + + MDCK_SUPPLIED_SOUND_FONT = 1 << 0, // Sound font will be supplied by the engine + MDCK_AUTO = 1 << 1, // Driver is being checked for automatic selection (i.e. MIDI device is set to "auto") +}; + /** * TODO: Document this, give it a better name. */ diff --git a/audio/musicplugin.h b/audio/musicplugin.h index 80e2f9fe159..bfa3e805ff4 100644 --- a/audio/musicplugin.h +++ b/audio/musicplugin.h @@ -100,9 +100,15 @@ public: /** * Checks whether a device can actually be used. Currently this is only * implemented for the MT-32 emulator to check whether the required rom - * files are present. + * files are present. In the default implementation, the device is not + * available as an auto-selected device. + * + * @param hdl MIDI device handle + * @param checkFlags Bitwise OR mask of MidiDriverCheckFlags + * @param quiet If true, suppress and error messages on check failure. + * */ - virtual bool checkDevice(MidiDriver::DeviceHandle hdl, int flags, bool quiet) const { return true; } + virtual bool checkDevice(MidiDriver::DeviceHandle hdl, int checkFlags, bool quiet) const { return (checkFlags & MDCK_AUTO) == 0; } /** * Tries to instantiate a MIDI Driver instance based on the device diff --git a/audio/softsynth/fluidsynth.cpp b/audio/softsynth/fluidsynth.cpp index a1d93e0eac6..10496983d11 100644 --- a/audio/softsynth/fluidsynth.cpp +++ b/audio/softsynth/fluidsynth.cpp @@ -604,7 +604,7 @@ MusicDevices FluidSynthMusicPlugin::getDevices() const { bool FluidSynthMusicPlugin::checkDevice(MidiDriver::DeviceHandle, int flags, bool quiet) const { #ifdef FS_HAS_STREAM_SUPPORT - if (flags & MDT_SUPPLIED_SOUND_FONT) + if (flags & MDCK_SUPPLIED_SOUND_FONT) return true; #endif diff --git a/backends/midi/seq.cpp b/backends/midi/seq.cpp index 9181d8bbdc7..8f6d174fb17 100644 --- a/backends/midi/seq.cpp +++ b/backends/midi/seq.cpp @@ -282,6 +282,7 @@ public: MusicDevices getDevices() const; Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const; + bool checkDevice(MidiDriver::DeviceHandle hdl, int checkFlags, bool quiet) const; private: void addMidiDevices(int deviceFD, MusicDevices &devices, Common::Array *portIDs) const; @@ -381,6 +382,10 @@ Common::Error SeqMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver return Common::kAudioDeviceInitFailed; } +bool SeqMusicPlugin::checkDevice(MidiDriver::DeviceHandle hdl, int checkFlags, bool quiet) const { + return true; +} + //#if PLUGIN_ENABLED_DYNAMIC(SEQ) //REGISTER_PLUGIN_DYNAMIC(SEQ, PLUGIN_TYPE_MUSIC, SeqMusicPlugin); //#else diff --git a/backends/midi/windows.cpp b/backends/midi/windows.cpp index 43e01c80b1e..efdee259c81 100644 --- a/backends/midi/windows.cpp +++ b/backends/midi/windows.cpp @@ -174,6 +174,7 @@ public: MusicDevices getDevices() const override; Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const override; + bool checkDevice(MidiDriver::DeviceHandle hdl, int checkFlags, bool quiet) const override; }; MusicDevices WindowsMusicPlugin::getDevices() const { @@ -252,6 +253,10 @@ Common::Error WindowsMusicPlugin::createInstance(MidiDriver **mididriver, MidiDr return Common::kNoError; } +bool WindowsMusicPlugin::checkDevice(MidiDriver::DeviceHandle hdl, int checkFlags, bool quiet) const { + return true; +} + //#if PLUGIN_ENABLED_DYNAMIC(WINDOWS) //REGISTER_PLUGIN_DYNAMIC(WINDOWS, PLUGIN_TYPE_MUSIC, WindowsMusicPlugin); //#else