From 8bd6c9cffb8af6696b513de4e5272d1c5ae92e15 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 29 Mar 2023 01:22:40 -0700 Subject: [PATCH] Add musicdef->debug_volume, add musicdef console command musicdef -volume changes the volume of the currently playing song. The change persists through song changes and is visible with devmode music. musicdef -show prints all changed musicdef volumes. The intention of this command is to allow editing music volumes quickly in game, without having to quit, edit music.pk3, and reopen the game. --- src/s_sound.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++- src/s_sound.h | 1 + src/st_stuff.c | 12 +++++++ 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 1fa8b1c45..ef1f58214 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -47,6 +47,7 @@ static void Command_Tunes_f(void); static void Command_RestartAudio_f(void); static void Command_PlaySound(void); static void Got_PlaySound(UINT8 **p, INT32 playernum); +static void Command_MusicDef_f(void); // Sound system toggles static void GameSounds_OnChange(void); @@ -266,6 +267,7 @@ void S_RegisterSoundStuff(void) COM_AddCommand("restartaudio", Command_RestartAudio_f); COM_AddCommand("playsound", Command_PlaySound); RegisterNetXCmd(XD_PLAYSOUND, Got_PlaySound); + COM_AddCommand("musicdef", Command_MusicDef_f); } static void SetChannelsNum(void) @@ -2289,7 +2291,7 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 if (def) { - I_SetCurrentSongVolume(def->volume); + I_SetCurrentSongVolume(def->debug_volume != 0 ? def->debug_volume : def->volume); } } @@ -2697,6 +2699,96 @@ static void Got_PlaySound(UINT8 **cp, INT32 playernum) S_StartSound(NULL, sound_id); } +static void Command_MusicDef_f(void) +{ + const char *arg1 = COM_Argv(1); + const char *arg2 = COM_Argv(2); + + enum { + CMD_VOLUME, + CMD_SHOW, + } cmd; + + musicdef_t *def; + + if (!stricmp(arg1, "-volume")) + { + cmd = CMD_VOLUME; + } + else if (!stricmp(arg1, "-show")) + { + cmd = CMD_SHOW; + } + else + { + CONS_Printf( + "\nmusicdef -volume \n" + " Change the volume for the current song.\n" + " Changes are saved while the game is open.\n" + " Hint: turn on devmode music too!\n" + "\nmusicdef -show\n" + " Print a list of changed musicdefs.\n" + ); + return; + } + + switch (cmd) + { + case CMD_VOLUME: + if (!strcmp(arg2, "")) + { + CONS_Printf("musicdef %s: missing argument\n", arg1); + return; + } + + // This command uses the current musicdef + { + UINT8 i = 0; + + def = S_FindMusicDef(music_name, &i); + def->debug_volume = atoi(arg2); + I_SetCurrentSongVolume(def->debug_volume); + + CONS_Printf("Changed %s", def->name[0]); + + for (i = 1; i < def->numtracks; ++i) + { + CONS_Printf(", %s", def->name[i]); + } + + CONS_Printf("\n"); + } + break; + + case CMD_SHOW: + for (def = musicdefstart; def; def = def->next) + { + if (def->debug_volume != 0) + { + UINT8 i; + + CONS_Printf("Lump %s", def->name[0]); + + for (i = 1; i < def->numtracks; ++i) + { + CONS_Printf(", %s", def->name[1]); + } + + CONS_Printf( + "\n" + "Volume = %d\n" + "\n", + def->debug_volume + ); + } + } + break; + + default: + I_Assert(false); + } +} + void GameSounds_OnChange(void) { if (M_CheckParm("-nosound") || M_CheckParm("-noaudio")) diff --git a/src/s_sound.h b/src/s_sound.h index c9a02f4df..dcda1751d 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -187,6 +187,7 @@ struct musicdef_t char *source; char *composers; int volume; + int debug_volume; musicdef_t *next; }; diff --git a/src/st_stuff.c b/src/st_stuff.c index 39d4d841c..a48d844d5 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -371,6 +371,12 @@ static void ST_pushDebugString(INT32 *height, const char *string) ST_pushRow(height); } +static void ST_pushDebugStringHighlighted(INT32 *height, const char *string) +{ + V_DrawRightAlignedSmallString(319, *height, V_MONOSPACE | V_YELLOWMAP, string); + ST_pushRow(height); +} + static void ST_pushDebugTimeMS(INT32 *height, const char *label, UINT32 ms) { ST_pushDebugString(height, va("%s%02d:%05.2f", label, @@ -418,6 +424,12 @@ static void ST_drawMusicDebug(INT32 *height) if (def) { ST_pushRow(height); + + if (def->debug_volume != 0) + { + ST_pushDebugStringHighlighted(height, va("Debug Volume: %4d/100", def->debug_volume)); + } + ST_pushDebugString(height, va(" Volume: %4d/100", def->volume)); } }