Add streamersafemusic cvar

Don't play music that is marked contentidunsafe in its MUSICDEF (if
it exists).
This commit is contained in:
Eidolon 2024-04-30 18:03:19 -05:00
parent 6a9fd1bf5f
commit ab854ab545
5 changed files with 23 additions and 2 deletions

View file

@ -318,6 +318,7 @@ void Captioning_OnChange(void);
consvar_t cv_closedcaptioning = Player("closedcaptioning", "Off").on_off().onchange(Captioning_OnChange); consvar_t cv_closedcaptioning = Player("closedcaptioning", "Off").on_off().onchange(Captioning_OnChange);
consvar_t cv_continuousmusic = Player("continuousmusic", "On").on_off(); consvar_t cv_continuousmusic = Player("continuousmusic", "On").on_off();
consvar_t cv_streamersafemusic = Player("streamersafemusic", "Off").on_off();
consvar_t cv_controlperkey = Player("controlperkey", "One").values({{1, "One"}, {2, "Several"}}); consvar_t cv_controlperkey = Player("controlperkey", "One").values({{1, "One"}, {2, "Several"}});
// actual general (maximum) sound & music volume, saved into the config // actual general (maximum) sound & music volume, saved into the config

View file

@ -292,6 +292,9 @@ menuitem_t OPTIONS_Sound[] =
{IT_STRING | IT_CVAR, "Continuous Attack Music", "Keep music playing seamlessly when retrying in Attack modes.", {IT_STRING | IT_CVAR, "Continuous Attack Music", "Keep music playing seamlessly when retrying in Attack modes.",
NULL, {.cvar = &cv_continuousmusic}, 0, 0}, NULL, {.cvar = &cv_continuousmusic}, 0, 0},
{IT_STRING | IT_CVAR, "Streamer-Safe Music", "Only play music safe for video platforms.",
NULL, {.cvar = &cv_streamersafemusic}, 0, 0},
{IT_SPACE | IT_DYBIGSPACE, NULL, NULL, {IT_SPACE | IT_DYBIGSPACE, NULL, NULL,
NULL, {NULL}, 0, 0}, NULL, {NULL}, 0, 0},

View file

@ -80,8 +80,13 @@ void TuneManager::tick()
if (changed) if (changed)
{ {
if (load()) if (load())
{
musicdef_t* def = find_musicdef();
if (!cv_streamersafemusic.value || (def != nullptr && !def->contentidunsafe))
{ {
I_PlaySong(tune->loop); I_PlaySong(tune->loop);
}
I_FadeSongFromVolume( I_FadeSongFromVolume(
tune->use_level_volume ? level_volume_ : 100, tune->use_level_volume ? level_volume_ : 100,
0, 0,
@ -150,10 +155,14 @@ void TuneManager::pause_unpause() const
I_PauseSong(); I_PauseSong();
} }
else else
{
musicdef_t* def = find_musicdef();
if (!cv_streamersafemusic.value || (def != nullptr && !def->contentidunsafe))
{ {
I_ResumeSong(); I_ResumeSong();
} }
} }
}
} }
bool TuneManager::load() const bool TuneManager::load() const
@ -168,6 +177,12 @@ bool TuneManager::load() const
return I_LoadSong(static_cast<char*>(W_CacheLumpNum(lumpnum, PU_MUSIC)), W_LumpLength(lumpnum)); return I_LoadSong(static_cast<char*>(W_CacheLumpNum(lumpnum, PU_MUSIC)), W_LumpLength(lumpnum));
} }
musicdef_t* TuneManager::find_musicdef() const
{
uint8_t index = 0;
return S_FindMusicDef(current_song_.c_str(), &index);
}
void TuneManager::adjust_volume() const void TuneManager::adjust_volume() const
{ {
UINT8 i; UINT8 i;

View file

@ -121,6 +121,7 @@ private:
} }
bool load() const; bool load() const;
musicdef_t* find_musicdef() const;
void adjust_volume() const; void adjust_volume() const;
bool resync(); bool resync();

View file

@ -43,6 +43,7 @@ extern consvar_t cv_gamedigimusic;
extern consvar_t cv_gamesounds; extern consvar_t cv_gamesounds;
extern consvar_t cv_bgaudio; extern consvar_t cv_bgaudio;
extern consvar_t cv_streamersafemusic;
typedef enum typedef enum
{ {