commit a5b01f3b6a0c3ec22d9b23b60923e9d2d73a54b5
Author: Michael Day <contact@michaelcday.com>
AuthorDate: Sun Jun 26 22:03:31 2022 -0400
Commit: Michael Day <contact@michaelcday.com>
CommitDate: Tue Jun 28 14:33:02 2022 -0400
Check for functioning FluidSynth before using
Check that FluidSynth shows up in SDL Mixer's list of valid decoders.
This ensures that FluidSynth is actually available and the soundfont
file is good.
---
src/i_sdlmusic.c | 55 +++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 43 insertions(+), 12 deletions(-)
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index 064004d3..f4428955 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -186,6 +186,7 @@ static boolean SDLIsInitialized(void)
static boolean I_SDL_InitMusic(void)
{
boolean fluidsynth_sf_is_set = false;
+ boolean fluidsynth_requested;
// If SDL_mixer is not initialized, we have to initialize it
// and have the responsibility to shut it down later on.
@@ -215,6 +216,28 @@ static boolean I_SDL_InitMusic(void)
}
}
+ // When using FluidSynth, proceed to set the soundfont path via
+ // Mix_SetSoundFonts if necessary. We need to do this before calling
+ // Mix_Init() in order for FluidSynth to be registered as a valid decoder
+ // in the Mix_GetMusicDecoder() list.
+
+ fluidsynth_requested =
+ ((strlen(fluidsynth_sf_path) > 0) && (strlen(timidity_cfg_path) == 0));
+
+ if (fluidsynth_requested)
+ {
+ if (M_FileExists(fluidsynth_sf_path))
+ {
+ Mix_SetSoundFonts(fluidsynth_sf_path);
+ }
+ else
+ {
+ fprintf(stderr,
+ "I_SDL_InitMusic: Can't find FluidSynth soundfont.\n");
+ fluidsynth_requested = false;
+ }
+ }
+
// Initialize SDL_Mixer for MIDI music playback
Mix_Init(MIX_INIT_MID);
@@ -223,26 +246,34 @@ static boolean I_SDL_InitMusic(void)
RemoveTimidityConfig();
- // When using FluidSynth, proceed to set the soundfont path via
- // Mix_SetSoundFonts if necessary.
-
- if (strlen(fluidsynth_sf_path) > 0 && strlen(timidity_cfg_path) == 0)
+ // Confirm that FluidSynth is actually available.
+ if (fluidsynth_requested)
{
- if (M_FileExists(fluidsynth_sf_path))
+ int total;
+
+ total = Mix_GetNumMusicDecoders();
+
+ // If FluidSynth is present and has a valid soundfont, it will be in
+ // the list of available music decoders.
+ for (int i = 0; i < total; ++i)
{
- fluidsynth_sf_is_set = true;
+ if (!strcmp(Mix_GetMusicDecoder(i), "FLUIDSYNTH"))
+ {
+ fluidsynth_sf_is_set = true;
+ break;
+ }
+ }
+
+ if (fluidsynth_sf_is_set)
+ {
+ printf("I_SDL_InitMusic: Using FluidSynth.\n");
}
else
{
- fprintf(stderr, "Can't find Fluidsynth soundfont.\n");
+ fprintf(stderr, "I_SDL_InitMusic: FluidSynth unavailable.\n");
}
}
- if (fluidsynth_sf_is_set)
- {
- Mix_SetSoundFonts(fluidsynth_sf_path);
- }
-
// If snd_musiccmd is set, we need to call Mix_SetMusicCMD to
// configure an external music playback program.