foxygit / doom Log in
commit 3c44a45bb5f24d71ddc98627b3a1de4797b058af
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sun May 3 17:06:01 2020 -0400
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Sun May 3 17:06:01 2020 -0400

    music: Disable Fluidsynth when we want Timidity.

    When `timidity_cfg_path` is set, or we're using GUS pseudo-emulation, set the
    SDL_mixer environment variable to disable Fluidsynth, because Fluidsynth has a
    higher priority than Timidity inside SDL_mixer, and if it's configured
    properly it will circumvent Timidity entirely along with any configuration
    we've set up.

    Thanks to DagothKronk for reporting this bug on Doomworld:
    <https://www.doomworld.com/forum/topic/86366-chocolate-doom/?do=findComment&comment=2105318>
---
 src/i_sdlmusic.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index 87253b40..1ddde158 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -110,11 +110,17 @@ void I_InitTimidityConfig(void)

     // Set the TIMIDITY_CFG environment variable to point to the temporary
     // config file.
-
     if (success)
     {
         env_string = M_StringJoin("TIMIDITY_CFG=", temp_timidity_cfg, NULL);
         putenv(env_string);
+        // env_string deliberately not freed; see putenv manpage
+
+        // If we're explicitly configured to use Timidity (either through
+        // timidity_cfg_path or GUS mode), then disable Fluidsynth, because
+        // SDL_mixer considers Fluidsynth a higher priority than Timidity and
+        // therefore can end up circumventing Timidity entirely.
+        putenv("SDL_MIXER_DISABLE_FLUIDSYNTH=1");
     }
     else
     {