From 57d5e549832741e74f542309b15145b83b5bd28b Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 10 Mar 2024 12:19:31 +0000 Subject: [PATCH] Stereo Mode: Fix multi-Track musicdefs not having their first part loop under non-Seq conditions Had to introduce a hacky Music_SetFadeOut func, but I didn't want to rework this section of code/menu too heavily for how little time we have left --- src/music.cpp | 17 +++++++++++++++++ src/music.h | 4 ++++ src/s_sound.c | 25 ++++++++++++++++++------- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/music.cpp b/src/music.cpp index caa77e51c..9b0de56e9 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -218,6 +218,23 @@ void Music_Play(const char* id) } } +void Music_SetFadeOut(const char* id, int fade_out) +{ + Tune* tune = g_tunes.find(id); + + if (tune) + { + tune->fade_out = fade_out; + + if (tune->time_remaining() <= detail::msec_to_tics(tune->fade_out)) + { + // If this action would cause a fade out, start + // fading immediately. + g_tunes.tick(); + } + } +} + void Music_DelayEnd(const char* id, tic_t duration) { Tune* tune = g_tunes.find(id); diff --git a/src/music.h b/src/music.h index 2265639ea..61f6c4976 100644 --- a/src/music.h +++ b/src/music.h @@ -59,6 +59,10 @@ const char *Music_CurrentId(void); // back to the start.) void Music_Play(const char *id); +// Set fade out duration. Mostly to fix a last minute bug +// with Stereo Mode. +void Music_SetFadeOut(const char* id, int fade_out); + // Postpone the end of this tune until N tics from now. The // tune should already be playing before calling this. void Music_DelayEnd(const char *id, tic_t duration); diff --git a/src/s_sound.c b/src/s_sound.c index a26ad51ef..6daecbb26 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1690,10 +1690,7 @@ const char *S_SoundTestTune(UINT8 invert) boolean S_SoundTestCanSequenceFade(void) { - return - soundtest.current->basenoloop[soundtest.currenttrack] == false && - // Only fade out if we're the last track for this song. - soundtest.currenttrack == soundtest.current->numtracks-1; + return soundtest.current->basenoloop[soundtest.currenttrack] == false; } static void S_SoundTestReconfigure(const char *tune) @@ -1728,12 +1725,16 @@ void S_SoundTestPlay(void) } // Does song have default loop? - if (soundtest.current->basenoloop[soundtest.currenttrack] == false) + if (S_SoundTestCanSequenceFade() == true) { + // I'd personally like songs in sequence to last between 3 and 6 minutes. if (sequencemaxtime < 3*60*1000) { - // I'd personally like songs in sequence to last between 3 and 6 minutes. - const UINT32 loopduration = (sequencemaxtime - I_GetSongLoopPoint()); + const UINT32 looppoint = I_GetSongLoopPoint(); + const UINT32 loopduration = + (looppoint < sequencemaxtime) + ? sequencemaxtime - looppoint + : 0; if (!loopduration) ; @@ -1745,6 +1746,16 @@ void S_SoundTestPlay(void) } } + // Only the last track fades out... but we still use stereo_fade to handle stopping. + if (soundtest.currenttrack == soundtest.current->numtracks-1) + { + Music_SetFadeOut("stereo_fade", 5000); + } + else + { + Music_SetFadeOut("stereo_fade", 0); + } + Music_DelayEnd( S_SoundTestCanSequenceFade() ? "stereo_fade" : "stereo", (TICRATE*sequencemaxtime)/1000 // ms to TICRATE conversion