Loose ends from previous work

* Pause/ResumeSong remove handle argument
* LoadSong declare char *data argument
* Variable weirdness
This commit is contained in:
mazmazz 2018-08-23 09:36:51 -04:00
parent 3ec1a122e0
commit e89eccf78e
4 changed files with 49 additions and 59 deletions

View file

@ -122,7 +122,7 @@ void I_ShutdownMusic(void);
\return void \return void
*/ */
void I_PauseSong(INT32 handle); void I_PauseSong(void);
/** \brief RESUME game handling /** \brief RESUME game handling
@ -130,7 +130,7 @@ void I_PauseSong(INT32 handle);
\return void \return void
*/ */
void I_ResumeSong(INT32 handle); void I_ResumeSong(void);
// //
// MIDI I/O // MIDI I/O
@ -153,7 +153,7 @@ void I_SetMIDIMusicVolume(UINT8 volume);
\todo Remove this \todo Remove this
*/ */
boolean I_LoadSong(void *data, size_t len); boolean I_LoadSong(char *data, size_t len);
/** \brief Called by anything that wishes to start music /** \brief Called by anything that wishes to start music
@ -164,7 +164,7 @@ boolean I_LoadSong(void *data, size_t len);
\todo pass music name, not handle \todo pass music name, not handle
*/ */
boolean I_PlaySong(void); boolean I_PlaySong(boolean looping);
/** \brief Stops a song over 3 seconds /** \brief Stops a song over 3 seconds

View file

@ -1316,11 +1316,10 @@ static char music_name[7]; // up to 6-character name
static boolean mus_forcemidi = 0; // force midi even when digital exists static boolean mus_forcemidi = 0; // force midi even when digital exists
static boolean mus_paused = 0; // whether songs are mus_paused static boolean mus_paused = 0; // whether songs are mus_paused
static boolean S_LoadMusic(const char *mname, boolean looping) static boolean S_LoadMusic(const char *mname)
{ {
lumpnum_t mlumpnum; lumpnum_t mlumpnum;
void *mdata; void *mdata;
INT32 mhandle;
if (nomidimusic || music_disabled) if (nomidimusic || music_disabled)
return false; // didn't search. return false; // didn't search.
@ -1354,7 +1353,7 @@ static boolean S_LoadMusic(const char *mname, boolean looping)
return false; return false;
} }
static void S_UnloadSong(void) static void S_UnloadMusic(void)
{ {
I_UnloadSong(); I_UnloadSong();
music_name[0] = 0; music_name[0] = 0;
@ -1365,12 +1364,9 @@ static boolean S_PlayMusic(const char *mname, boolean looping)
if (nodigimusic || digital_disabled) if (nodigimusic || digital_disabled)
return false; // try midi return false; // try midi
if (!S_LoadSong(mname, looping)) if (!I_PlaySong(looping))
return false;
if (!I_PlaySong())
{ {
S_UnloadSong(); S_UnloadMusic();
return false; return false;
} }
@ -1394,7 +1390,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
if (strncmp(music_name, mmusic, 6)) if (strncmp(music_name, mmusic, 6))
{ {
S_StopMusic(); // shutdown old music S_StopMusic(); // shutdown old music
if (!S_LoadMusic(mmusic, looping) && !S_PlayMusic(mmusic, looping)) if (!S_LoadMusic(mmusic) && !S_PlayMusic(mmusic, looping))
{ {
CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic);
return; return;
@ -1414,7 +1410,7 @@ void S_StopMusic(void)
return; return;
if (mus_paused) if (mus_paused)
I_ResumeSong(music_handle); I_ResumeSong();
S_SpeedMusic(1.0f); S_SpeedMusic(1.0f);
I_StopSong(); I_StopSong();
@ -1424,7 +1420,6 @@ void S_StopMusic(void)
Z_ChangeTag(music_data, PU_CACHE); Z_ChangeTag(music_data, PU_CACHE);
#endif #endif
music_data = NULL;
music_name[0] = 0; music_name[0] = 0;
if (cv_closedcaptioning.value) if (cv_closedcaptioning.value)
@ -1434,7 +1429,7 @@ void S_StopMusic(void)
} }
} }
void S_SetMusicVolume(INT32 volume) void S_SetDigMusicVolume(INT32 volume)
{ {
if (volume < 0 || volume > 31) if (volume < 0 || volume > 31)
CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n");
@ -1536,11 +1531,11 @@ void S_Start(void)
void S_PauseAudio(void) void S_PauseAudio(void)
{ {
if (!nodigimusic) if (!nodigimusic)
I_PauseSong(0); I_PauseSong();
if (music_playing && !mus_paused) if (music_playing && !mus_paused)
{ {
I_PauseSong(music_handle); I_PauseSong();
mus_paused = true; mus_paused = true;
} }
@ -1555,11 +1550,11 @@ void S_PauseAudio(void)
void S_ResumeAudio(void) void S_ResumeAudio(void)
{ {
if (!nodigimusic) if (!nodigimusic)
I_ResumeSong(0); I_ResumeSong();
else else
if (music_playing && mus_paused) if (music_playing && mus_paused)
{ {
I_ResumeSong(music_handle); I_ResumeSong();
mus_paused = false; mus_paused = false;
} }

View file

@ -566,7 +566,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
// Tell game we got focus back, resume music if necessary // Tell game we got focus back, resume music if necessary
window_notinfocus = false; window_notinfocus = false;
if (!paused) if (!paused)
I_ResumeSong(0); //resume it I_ResumeSong(); //resume it
if (!firsttimeonmouse) if (!firsttimeonmouse)
{ {
@ -578,7 +578,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
{ {
// Tell game we lost focus, pause music // Tell game we lost focus, pause music
window_notinfocus = true; window_notinfocus = true;
I_PauseSong(0); I_PauseSong();
if (!disable_mouse) if (!disable_mouse)
{ {

View file

@ -491,16 +491,14 @@ void I_ShutdownMusic(void)
music = NULL; music = NULL;
} }
void I_PauseSong(INT32 handle) void I_PauseSong(void)
{ {
(void)handle;
Mix_PauseMusic(); Mix_PauseMusic();
songpaused = true; songpaused = true;
} }
void I_ResumeSong(INT32 handle) void I_ResumeSong(void)
{ {
(void)handle;
Mix_ResumeMusic(); Mix_ResumeMusic();
songpaused = false; songpaused = false;
} }
@ -570,7 +568,7 @@ boolean I_SetSongTrack(int track)
// MIDI Music // MIDI Music
// //
boolean I_LoadSong(void *data, size_t len) boolean I_LoadSong(char *data, size_t len)
{ {
I_Assert(!music); I_Assert(!music);
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
@ -667,6 +665,8 @@ boolean I_LoadSong(void *data, size_t len)
else if (!gme_open_data(data, len, &gme, 44100)) else if (!gme_open_data(data, len, &gme, 44100))
{ {
gme_equalizer_t eq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; gme_equalizer_t eq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0};
gme_set_equalizer(gme, &eq);
Mix_HookMusic(mix_gme, gme);
return true; return true;
} }
#endif #endif
@ -680,8 +680,7 @@ boolean I_LoadSong(void *data, size_t len)
// Find the OGG loop point. // Find the OGG loop point.
loop_point = 0.0f; loop_point = 0.0f;
if (looping)
{
const char *key1 = "LOOP"; const char *key1 = "LOOP";
const char *key2 = "POINT="; const char *key2 = "POINT=";
const char *key3 = "MS="; const char *key3 = "MS=";
@ -711,12 +710,11 @@ boolean I_LoadSong(void *data, size_t len)
} }
// Neither?! Continue searching. // Neither?! Continue searching.
} }
}
return true; return true;
} }
boolean I_PlaySong(void) boolean I_PlaySong(boolean looping)
{ {
if (!music) if (!music)
return false; return false;
@ -725,8 +723,6 @@ boolean I_PlaySong(void)
{ {
gme_start_track(gme, 0); gme_start_track(gme, 0);
current_track = 0; current_track = 0;
gme_set_equalizer(gme, &eq);
Mix_HookMusic(mix_gme, gme);
return true; return true;
} }
#endif #endif
@ -782,7 +778,6 @@ void I_UnloadSong(void)
if (!midimode || !music) if (!midimode || !music)
return; return;
(void)handle;
Mix_FreeMusic(music); Mix_FreeMusic(music);
music = NULL; music = NULL;
} }