From 703b142bad8affc87b066b007c765d98570399f9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 7 Sep 2020 21:26:07 +0200 Subject: [PATCH] - added a CVAR to disable WT's ogg music and a fallback for when it cannot be found. Fixes #354 --- source/common/audio/music/music.cpp | 2 +- source/core/raze_music.cpp | 2 +- source/games/duke/src/sounds.cpp | 36 +++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/source/common/audio/music/music.cpp b/source/common/audio/music/music.cpp index f78c1901d..198b9975f 100644 --- a/source/common/audio/music/music.cpp +++ b/source/common/audio/music/music.cpp @@ -319,7 +319,7 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force) if (!force && PlayList.GetNumSongs()) { // Don't change if a playlist is active - return false; + return true; // do not report an error here. } // Do game specific lookup. FString musicname_; diff --git a/source/core/raze_music.cpp b/source/core/raze_music.cpp index 2a6fd69f6..9ee2d1c72 100644 --- a/source/core/raze_music.cpp +++ b/source/core/raze_music.cpp @@ -197,7 +197,7 @@ int Mus_Play(const char *mapname, const char *fn, bool loop) if (!MusicEnabled()) { - return 0; + return 1; } // Allow per level music substitution. diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index a1afcf51d..713e7eaa0 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -587,12 +587,44 @@ void S_MenuSound(void) // //========================================================================== +CVAR(Bool, wt_forcemidi, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // quick hack to disable the oggs, which are of lower quality than playing the MIDIs with a good synth and sound font. + static bool cd_disabled = false; // This is in case mus_redbook is enabled but no tracks found so that the regular music system can be switched on. +static void MusPlay(const char* label, const char* music, bool loop) +{ + if (isWorldTour()) + { + if (wt_forcemidi) + { + FString alternative = music; + alternative.Substitute(".ogg", ".mid"); + int num = fileSystem.FindFile(alternative); + if (num >= 0) + { + int file = fileSystem.GetFileContainer(num); + if (file == 1) + { + Mus_Play(label, alternative, loop); + return; + } + } + } + } + int result = Mus_Play(label, music, loop); + // do not remain silent if playing World Tour when the user has deleted the music. + if (!result && isWorldTour()) + { + FString alternative = music; + alternative.Substitute(".ogg", ".mid"); + Mus_Play(label, alternative, loop); + } +} + void S_PlayLevelMusic(MapRecord *mi) { if (isRR() && mi->music.IsEmpty() && mus_redbook && !cd_disabled) return; - Mus_Play(mi->labelName, mi->music, true); + MusPlay(mi->labelName, mi->music, true); } void S_PlaySpecialMusic(unsigned int m) @@ -601,7 +633,7 @@ void S_PlaySpecialMusic(unsigned int m) auto& musicfn = specialmusic[m]; if (musicfn.IsNotEmpty()) { - Mus_Play(nullptr, musicfn, true); + MusPlay(nullptr, musicfn, true); } }