make music toggle/volume handling less of a mess

based on work in srb2 from sphere
this gets rid of all the duplicated midi stuff
since we dont really have a whole midi soundtrack like srb2, S_GetMusicLumpNum will always prefer non midi music
This commit is contained in:
Alug committed 2025-08-06 18:21:37 +02:00
1 parent c7138a96f2
commit f1748b705d
7 files changed
+72 -237

No files matched your search

+8 -33
View File
@@ -121,11 +121,8 @@ INT32 postimgparam[MAXSPLITSCREENPLAYERS];
// These variables are only true if
// whether the respective sound system is disabled
// or they're init'ed, but the player just toggled them
#ifndef NO_MIDI
boolean midi_disabled = false;
#endif
boolean sound_disabled = false;
boolean digital_disabled = false;
boolean music_disabled = false;
#ifdef DEBUGFILE
INT32 debugload = 0;
@@ -2047,45 +2044,23 @@ void D_SRB2Main(void)
if (dedicated)
{
sound_disabled = true;
digital_disabled = true;
#ifndef NO_MIDI
midi_disabled = true;
#endif
music_disabled = true;
}
if (M_CheckParm("-noaudio")) // combines -nosound and -nomusic
{
sound_disabled = true;
digital_disabled = true;
#ifndef NO_MIDI
midi_disabled = true;
#endif
music_disabled = true;
}
else
{
if (M_CheckParm("-nosound"))
sound_disabled = true;
if (M_CheckParm("-nomusic")) // combines -nomidimusic and -nodigmusic
{
digital_disabled = true;
#ifndef NO_MIDI
midi_disabled = true;
#endif
}
else
{
#ifndef NO_MIDI
if (M_CheckParm("-nomidimusic"))
midi_disabled = true; // WARNING: DOS version initmusic in I_StartupSound
#endif
if (M_CheckParm("-nodigmusic"))
digital_disabled = true; // WARNING: DOS version initmusic in I_StartupSound
}
if (M_CheckParm("-nomusic"))
music_disabled = true;
}
if (!( sound_disabled && digital_disabled
#ifndef NO_MIDI
&& midi_disabled
#endif
))
if (!(sound_disabled && music_disabled))
{
CONS_Printf("S_InitSfxChannels(): Setting up sound channels.\n");
I_StartupSound();
+1 -6
View File
@@ -102,13 +102,8 @@ extern boolean forceresetplayers, deferencoremode;
// Internal parameters for sound rendering.
// ========================================
#ifdef NO_MIDI
#define midi_disabled true
#else
extern boolean midi_disabled;
#endif
extern boolean sound_disabled;
extern boolean digital_disabled;
extern boolean music_disabled;
// =========================
// Status flags for refresh.
+6 -6
View File
@@ -5271,23 +5271,23 @@ static void M_DrawSkyRoom(void)
V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x,
currentMenu->y+currentMenu->menuitems[2].alphaKey,
(digital_disabled ? warningflags : highlightflags),
(digital_disabled ? "OFF" : "ON"));
(music_disabled ? warningflags : highlightflags),
(music_disabled ? "OFF" : "ON"));
#ifndef NO_MIDI
V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x,
currentMenu->y+currentMenu->menuitems[5].alphaKey,
(midi_disabled ? warningflags : highlightflags),
(midi_disabled ? "OFF" : "ON"));
(music_disabled ? warningflags : highlightflags),
(music_disabled ? "OFF" : "ON"));
#endif
if (itemOn == 0)
lengthstring = 8*(sound_disabled ? 3 : 2);
else if (itemOn == 2)
lengthstring = 8*(digital_disabled ? 3 : 2);
lengthstring = 8*(music_disabled ? 3 : 2);
#ifndef NO_MIDI
else if (itemOn == 5)
lengthstring = 8*(midi_disabled ? 3 : 2);
lengthstring = 8*(music_disabled ? 3 : 2);
#endif
}
+49 -173
View File
@@ -42,12 +42,10 @@ static void Command_RestartMusic_f(void); //mhhhm amiga type filters here i come
static void Command_ShowMusicCredit_f(void);
// Sound system toggles
#ifndef NO_MIDI
static void GameMIDIMusic_OnChange(void);
#endif
static void GameSounds_OnChange(void);
static void GameMusic_OnChange(void);
static void SoundPrecache_OnChange(void);
static void GameDigiMusic_OnChange(void);
static void BufferSize_OnChange(void);
#ifdef HAVE_OPENMPT
@@ -90,11 +88,8 @@ consvar_t cv_samesoundlimit = {"samesoundlimit", "0", CV_SAVE, samesoundlimit_co
//consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE|CV_NOSHOWHELP, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL};
// Sound system toggles, saved into the config
consvar_t cv_gamedigimusic = {"digimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameDigiMusic_OnChange, 0, NULL, NULL, 0, 0, NULL};
#ifndef NO_MIDI
consvar_t cv_gamemidimusic = {"midimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameMIDIMusic_OnChange, 0, NULL, NULL, 0, 0, NULL};
#endif
consvar_t cv_gamesounds = {"sounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameSounds_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_gamedigimusic = {"digimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameMusic_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_gamesounds = {"sounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameSounds_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_playmusicifunfocused = {"playmusicifunfocused", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_playsoundifunfocused = {"playsoundsifunfocused", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL};
@@ -286,9 +281,6 @@ void S_RegisterSoundStuff(void)
//CV_RegisterVar(&cv_resetmusic);
CV_RegisterVar(&cv_gamesounds);
CV_RegisterVar(&cv_gamedigimusic);
#ifndef NO_MIDI
CV_RegisterVar(&cv_gamemidimusic);
#endif
CV_RegisterVar(&cv_samesoundlimit);
@@ -367,10 +359,7 @@ lumpnum_t S_GetSfxLumpNum(sfxinfo_t *sfx)
boolean S_SoundDisabled(void)
{
return (
sound_disabled ||
( window_notinfocus && ! cv_playsoundifunfocused.value )
);
return (sound_disabled || (window_notinfocus && !cv_playsoundifunfocused.value));
}
boolean S_PrecacheSound(void)
@@ -693,10 +682,7 @@ void S_StopSound(void *origin)
// Updates music & sounds
//
static INT32 actualsfxvolume; // check for change through console
static INT32 actualdigmusicvolume;
#ifndef NO_MIDI
static INT32 actualmidimusicvolume;
#endif
static INT32 actualmusicvolume;
void S_UpdateSounds(void)
{
@@ -708,15 +694,19 @@ void S_UpdateSounds(void)
listener_t listener[MAXSPLITSCREENPLAYERS];
mobj_t *listenmobj[MAXSPLITSCREENPLAYERS];
#ifndef NO_MIDI
const boolean currentmidi = (I_SongType() == MU_MID);
#endif
// Update sound/music volumes, if changed manually at console
if (actualsfxvolume != cv_soundvolume.value)
S_SetSfxVolume(cv_soundvolume.value);
if (actualdigmusicvolume != cv_digmusicvolume.value)
S_SetDigMusicVolume(cv_digmusicvolume.value);
#ifndef NO_MIDI
if (actualmidimusicvolume != cv_midimusicvolume.value)
S_SetMIDIMusicVolume(cv_midimusicvolume.value);
if (actualmusicvolume != (currentmidi ? cv_midimusicvolume.value : cv_digmusicvolume.value))
#else
if (actualmusicvolume != cv_digmusicvolume.value)
#endif
S_SetMusicVolume(-1);
memset(listener, 0, sizeof(listener));
@@ -1516,7 +1506,8 @@ void S_ShowSpecifiedMusicCredit(const char *musname)
{
musicdef_t *def;
if (digital_disabled) return;
if (music_disabled)
return;
if (!cv_songcredits.value || demo.rewinding)
return;
@@ -1546,19 +1537,9 @@ void S_ShowMusicCredit(void)
/// Music Status
/// ------------------------
boolean S_DigMusicDisabled(void)
{
return digital_disabled;
}
boolean S_MIDIMusicDisabled(void)
{
return midi_disabled; // SRB2Kart: defined as "true" w/ NO_MIDI
}
boolean S_MusicDisabled(void)
{
return (midi_disabled && digital_disabled);
return (music_disabled);
}
boolean S_MusicPlaying(void)
@@ -1647,6 +1628,15 @@ UINT32 S_GetMusicPosition(void)
/// Music Playback
/// ------------------------
static lumpnum_t S_GetMusicLumpNum(const char *mname)
{
if (S_MusicExists(mname, false, true)) // check non midis first
return W_GetNumForName(va("o_%s", mname));
else if (S_MusicExists(mname, true, false))
return W_GetNumForName(va("d_%s", mname));
return LUMPERROR;
}
static boolean S_LoadMusic(const char *mname)
{
lumpnum_t mlumpnum;
@@ -1655,27 +1645,11 @@ static boolean S_LoadMusic(const char *mname)
if (S_MusicDisabled())
return false;
if (!S_DigMusicDisabled() && S_DigExists(mname))
mlumpnum = W_GetNumForName(va("o_%s", mname));
else if (!S_MIDIMusicDisabled() && S_MIDIExists(mname))
mlumpnum = W_GetNumForName(va("d_%s", mname));
else if (S_DigMusicDisabled() && S_DigExists(mname))
mlumpnum = S_GetMusicLumpNum(mname);
if (mlumpnum == LUMPERROR)
{
CONS_Alert(CONS_NOTICE, "Digital music is disabled!\n");
return false;
}
else if (S_MIDIMusicDisabled() && S_MIDIExists(mname))
{
#ifdef NO_MIDI
CONS_Alert(CONS_ERROR, "A MIDI music lump %.6s was found,\nbut SRB2Kart does not support MIDI output.\nWe apologise for the inconvenience.\n", mname);
#else
CONS_Alert(CONS_NOTICE, "MIDI music is disabled!\n");
#endif
return false;
}
else
{
CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mname);
CONS_Alert(CONS_ERROR, "Music %.6s could not be loaded: lump not found!\n", mname);
return false;
}
@@ -1723,7 +1697,7 @@ static boolean S_PlayMusic(boolean looping, UINT32 fadeinms)
return false;
}
S_InitMusicVolume(); // switch between digi and sequence volume
S_SetMusicVolume(-1); // initialize music volume
if (S_MusicNotInFocus())
I_SetMusicVolume(0);
@@ -1879,47 +1853,24 @@ void S_ResumeAudio(void)
I_ResumeSong();
}
void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume)
void S_SetMusicVolume(INT32 volume)
{
if (digvolume < 0)
digvolume = cv_digmusicvolume.value;
#ifdef NO_MIDI
(void)seqvolume;
consvar_t *musicvolume = &cv_digmusicvolume;
#else
if (seqvolume < 0)
seqvolume = cv_midimusicvolume.value;
consvar_t *musicvolume = (I_SongType() == MU_MID) ? &cv_midimusicvolume : &cv_digmusicvolume;
#endif
if (digvolume < 0 || digvolume > 31)
CONS_Alert(CONS_WARNING, "digmusicvolume should be between 0-31\n");
CV_SetValue(&cv_digmusicvolume, digvolume&31);
actualdigmusicvolume = cv_digmusicvolume.value; //check for change of var
if (volume < 0)
volume = musicvolume->value;
#ifndef NO_MIDI
if (seqvolume < 0 || seqvolume > 31)
CONS_Alert(CONS_WARNING, "midimusicvolume should be between 0-31\n");
CV_SetValue(&cv_midimusicvolume, seqvolume&31);
actualmidimusicvolume = cv_midimusicvolume.value; //check for change of var
#endif
if (volume < 0 || volume > 31)
CONS_Alert(CONS_WARNING, "Music volume should be between 0-31\n");
#ifndef NO_MIDI
seqvolume = 31;
#endif
CV_SetValue(musicvolume, volume&31);
actualmusicvolume = musicvolume->value; //check for change of var
switch(I_SongType())
{
#ifndef NO_MIDI
case MU_MID:
//case MU_MOD:
//case MU_GME:
I_SetMusicVolume(seqvolume&31);
break;
#endif
default:
I_SetMusicVolume(digvolume&31);
break;
}
I_SetMusicVolume(volume&31);
}
void S_SetRestoreMusicFadeInCvar(consvar_t *cv)
@@ -2165,11 +2116,7 @@ void S_RestartMusic(void)
I_ShutdownMusic();
I_InitMusic();
#ifdef NO_MIDI
S_SetMusicVolume(cv_digmusicvolume.value, -1);
#else
S_SetMusicVolume(cv_digmusicvolume.value, cv_midimusicvolume.value);
#endif
S_SetMusicVolume(-1);
S_ResetKeepAndSpecialMus();
@@ -2270,11 +2217,7 @@ static void Command_RestartAudio_f(void)
// These must be called or no sound and music until manually set.
I_SetSfxVolume(cv_soundvolume.value);
#ifdef NO_MIDI
S_SetMusicVolume(cv_digmusicvolume.value, -1);
#else
S_SetMusicVolume(cv_digmusicvolume.value, cv_midimusicvolume.value);
#endif
S_SetMusicVolume(-1);
S_StartSound(NULL, sfx_strpst);
@@ -2344,16 +2287,14 @@ static void SoundPrecache_OnChange(void)
}
}
static void GameDigiMusic_OnChange(void)
void GameMusic_OnChange(void)
{
if (M_CheckParm("-nomusic") || M_CheckParm("-noaudio"))
return;
else if (M_CheckParm("-nodigmusic"))
return;
if (digital_disabled && cv_gamedigimusic.value)
if (music_disabled && cv_gamedigimusic.value)
{
digital_disabled = false;
music_disabled = false;
I_StartupSound(); // will return early if initialised
I_InitMusic();
@@ -2364,32 +2305,13 @@ static void GameDigiMusic_OnChange(void)
else
S_ChangeMusicInternal("titles", looptitle);
}
else if (!digital_disabled && !cv_gamedigimusic.value)
else if (!music_disabled && !cv_gamedigimusic.value)
{
digital_disabled = true;
if (S_MusicType() != MU_MID)
{
if (midi_disabled)
S_StopMusic();
else
{
char mmusic[7];
UINT16 mflags;
boolean looping;
if (S_MusicInfo(mmusic, &mflags, &looping) && S_MIDIExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
else
S_StopMusic();
}
}
music_disabled = true;
S_StopMusic();
}
}
#ifdef HAVE_OPENMPT
static void ModFilter_OnChange(void)
{
@@ -2431,49 +2353,3 @@ static void BufferSize_OnChange(void)
if (sound_started)
COM_ImmedExecute("restartaudio");
}
#ifndef NO_MIDI
static void GameMIDIMusic_OnChange(void)
{
if (M_CheckParm("-nomusic") || M_CheckParm("-noaudio"))
return;
else if (M_CheckParm("-nomidimusic"))
return;
if (midi_disabled && cv_gamemidimusic.value)
{
midi_disabled = false;
I_InitMusic();
S_ResetKeepAndSpecialMus();
if (Playing())
P_RestoreMusic(&players[consoleplayer]);
else
S_ChangeMusicInternal("titles", looptitle);
}
else if (!midi_disabled && !cv_gamemidimusic.value)
{
midi_disabled = true;
if (S_MusicType() == MU_MID)
{
if (digital_disabled)
S_StopMusic();
else
{
char mmusic[7];
UINT16 mflags;
boolean looping;
if (S_MusicInfo(mmusic, &mflags, &looping) && S_DigExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
else
S_StopMusic();
}
}
}
}
#endif
+2 -9
View File
@@ -38,7 +38,7 @@ extern consvar_t cv_audbuffersize;
//extern consvar_t cv_resetmusic;
extern consvar_t cv_gamedigimusic;
#ifndef NO_MIDI
extern consvar_t cv_gamemidimusic, cv_midimusicvolume;
extern consvar_t cv_midimusicvolume;
#endif
extern consvar_t cv_gamesounds;
extern consvar_t cv_playmusicifunfocused;
@@ -150,8 +150,6 @@ void S_StopSound(void *origin);
// Music Status
//
boolean S_DigMusicDisabled(void);
boolean S_MIDIMusicDisabled(void);
boolean S_MusicDisabled(void);
boolean S_MusicPlaying(void);
boolean S_MusicPaused(void);
@@ -161,8 +159,6 @@ musictype_t S_MusicType(void);
const char *S_MusicName(void);
boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping);
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi);
#define S_DigExists(a) S_MusicExists(a, false, true)
#define S_MIDIExists(a) S_MusicExists(a, true, false)
//
// Music Effects
@@ -283,10 +279,7 @@ void S_UpdateSounds(void);
FUNCMATH fixed_t S_CalculateSoundDistance(fixed_t px1, fixed_t py1, fixed_t pz1, fixed_t px2, fixed_t py2, fixed_t pz2);
void S_SetSfxVolume(INT32 volume);
void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume);
#define S_SetDigMusicVolume(a) S_SetMusicVolume(a,-1)
#define S_SetMIDIMusicVolume(a) S_SetMusicVolume(-1,a)
#define S_InitMusicVolume() S_SetMusicVolume(-1,-1)
void S_SetMusicVolume(INT32 volume);
INT32 S_OriginPlaying(void *origin);
INT32 S_IdPlaying(sfxenum_t id);
+2 -2
View File
@@ -731,10 +731,10 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
// Tell game we got focus back, resume music if necessary
window_notinfocus = false;
S_InitMusicVolume();
S_SetMusicVolume(-1);
if (cv_gamesounds.value)
S_ResumeAudio(); //resume it
S_ResumeAudio(); // resume it
if (!firsttimeonmouse)
{
+4 -8
View File
@@ -189,7 +189,7 @@ static void Snd_LockAudio(void) //Alam: Lock audio data and uninstall audio call
{
if (Snd_Mutex) SDL_LockMutex(Snd_Mutex);
else if (sound_disabled) return;
else if (midi_disabled && digital_disabled) SDL_LockAudio();
else if (music_disabled) SDL_LockAudio();
#ifdef HAVE_MIXER
else if (musicStarted) Mix_SetPostMix(NULL, NULL);
#endif
@@ -199,7 +199,7 @@ static void Snd_UnlockAudio(void) //Alam: Unlock audio data and reinstall audio
{
if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex);
else if (sound_disabled) return;
else if (midi_disabled && digital_disabled) SDL_UnlockAudio();
else if (music_disabled) SDL_UnlockAudio();
#ifdef HAVE_MIXER
else if (musicStarted) Mix_SetPostMix(audio.callback, audio.userdata);
#endif
@@ -1061,7 +1061,7 @@ void I_ShutdownSound(void)
CONS_Printf("I_ShutdownSound: ");
if (midi_disabled && digital_disabled)
if (music_disabled)
SDL_CloseAudio();
CONS_Printf("%s", M_GetText("shut down\n"));
sound_started = false;
@@ -1078,11 +1078,7 @@ void I_UpdateSound(void)
void I_StartupSound(void)
{
#ifndef HAVE_MIXER
#ifndef NO_MIDI
midi_disabled =
#endif
digital_disabled = true;
#endif
music_disabled = true;
memset(channels, 0, sizeof (channels)); //Alam: Clean it