From 2483c11cc411e9c8a7b0d9b74511a32d2a2abcac Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 15 Aug 2018 01:55:03 -0400 Subject: [PATCH] Implement I_MusicPaused in SDL2, SDL1.2, and FMOD; console and lua commands # Conflicts: # src/sdl12/mixer_sound.c --- src/i_sound.h | 6 ++++++ src/lua_baselib.c | 16 ++++++++++++++++ src/s_sound.c | 5 +++++ src/s_sound.h | 3 +++ src/sdl/mixer_sound.c | 15 +++++++++++++-- src/win32/win_snd.c | 8 ++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 59d9c4382..248da3d82 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -144,6 +144,12 @@ boolean I_MIDIPlaying(void); */ boolean I_MusicPlaying(void); +/** \brief Get music pause status + + \return boolean +*/ +boolean I_MusicPaused(void); + // // MIDI I/O // diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 08672b824..c9f4efd6d 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2324,6 +2324,21 @@ static int lib_sMusicPlaying(lua_State *L) return 1; } +static int lib_sMusicPaused(lua_State *L) +{ + player_t *player = NULL; + NOHUD + if (!lua_isnone(L, 1) && lua_isuserdata(L, 1)) + { + player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + if (!player) + return LUA_ErrInvalid(L, "player_t"); + } + if (!player || P_IsLocalPlayer(player)) + lua_pushboolean(L, S_MusicPaused()); + return 1; +} + static int lib_sOriginPlaying(lua_State *L) { void *origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); @@ -2706,6 +2721,7 @@ static luaL_Reg lib[] = { {"S_StopMusic",lib_sStopMusic}, {"S_MidiPlaying",lib_sMidiPlaying}, {"S_MusicPlaying",lib_sMusicPlaying}, + {"S_MusicPaused",lib_sMusicPaused}, {"S_OriginPlaying",lib_sOriginPlaying}, {"S_IdPlaying",lib_sIdPlaying}, {"S_SoundPlaying",lib_sSoundPlaying}, diff --git a/src/s_sound.c b/src/s_sound.c index 092f1c779..98198a9f7 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1585,3 +1585,8 @@ boolean S_MusicPlaying(void) { return I_MusicPlaying(); } + +boolean S_MusicPaused(void) +{ + return I_MusicPaused(); +} diff --git a/src/s_sound.h b/src/s_sound.h index a463b8581..fa2fb638e 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -154,6 +154,9 @@ boolean S_MIDIPlaying(void); // Gets general music status boolean S_MusicPlaying(void); +// Gets music pause status +boolean S_MusicPaused(void); + // // Updates music & sounds // diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 8bfd1b8a2..ecb95d646 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -62,7 +62,7 @@ UINT8 sound_started = false; -static boolean midimode; +static boolean midimode, music_paused; static Mix_Music *music; static UINT8 music_volume, midi_volume, sfx_volume; static float loop_point; @@ -88,7 +88,7 @@ void I_StartupSound(void) return; } - midimode = false; + midimode = music_paused = false; music = NULL; music_volume = midi_volume = sfx_volume = 0; @@ -488,6 +488,9 @@ void I_PauseSong(INT32 handle) (void)handle; if(!midimode) Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); + if(music) + // music is not paused if there's no music to begin with, see win_snd.c:I_PauseSong + music_paused = true; Mix_PauseMusic(); songpaused = true; } @@ -503,6 +506,7 @@ void I_ResumeSong(INT32 handle) // midimode and music must be checked in case nothing is actually playing CONS_Alert(CONS_WARNING, "Error registering SDL music position counter: %s\n", Mix_GetError()); } + music_paused = false; Mix_ResumeMusic(); songpaused = false; } @@ -527,6 +531,11 @@ boolean I_MusicPlaying(void) return (boolean)music; } +boolean I_MusicPaused(void) +{ + return music_paused; +} + // // Digital Music // @@ -574,6 +583,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) if (lumpnum == LUMPERROR) return false; midimode = false; + music_paused = false; data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); len = W_LumpLength(lumpnum); @@ -883,6 +893,7 @@ boolean I_PlaySong(INT32 handle, boolean looping) (void)handle; midimode = true; + music_paused = false; if (Mix_PlayMusic(music, looping ? -1 : 0) == -1) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 7b220f12b..1fa112307 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -478,6 +478,14 @@ boolean I_MusicPlaying(void) return (boolean)music_stream; } +boolean I_MusicPaused(void) +{ + boolean fmpaused = false; + if (music_stream) + FMOD_Channel_GetPaused(music_channel, &fmpaused); + return fmpaused; +} + void I_InitDigMusic(void) { }