Added I_GetMusicType and removed midimode variable

* Revised S_PlayMusic arguments
* Now music plays again!

(cherry picked from commit 55f3803e4b)
This commit is contained in:
mazmazz 2018-08-23 10:18:38 -04:00
parent b59aa27104
commit 06b7367941
3 changed files with 69 additions and 19 deletions

View file

@ -18,6 +18,21 @@
#include "sounds.h"
#include "command.h"
// copied from SDL mixer, plus GME
typedef enum {
MU_NONE,
MU_CMD,
MU_WAV,
MU_MOD,
MU_MID,
MU_OGG,
MU_MP3,
MU_MP3_MAD_UNUSED, // use MU_MP3 instead
MU_FLAC,
MU_MODPLUG_UNUSED, // use MU_MOD instead
MU_GME
} musictype_t;
/** \brief Sound subsystem runing and waiting
*/
extern UINT8 sound_started;
@ -108,6 +123,9 @@ void I_SetSfxVolume(UINT8 volume);
//
// MUSIC I/O
//
musictype_t I_GetMusicType(void);
/** \brief Init the music systems
*/
void I_InitMusic(void);

View file

@ -1227,7 +1227,7 @@ static boolean S_MIDIMusic(const char *mname, boolean looping)
return true;
}
static boolean S_DigMusic(const char *mname, boolean looping)
static boolean S_PlayMusic(boolean looping)
{
if (nodigimusic || digital_disabled)
return false; // try midi
@ -1235,11 +1235,6 @@ static boolean S_DigMusic(const char *mname, boolean looping)
if (!I_StartDigSong(mname, looping))
return false;
strncpy(music_name, mname, 7);
music_name[6] = 0;
music_lumpnum = LUMPERROR;
music_data = NULL;
music_handle = 0;
return true;
}
@ -1262,11 +1257,18 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
if (strncmp(music_name, mmusic, 6))
{
S_StopMusic(); // shutdown old music
if (!S_DigMusic(mmusic, looping) && !S_MIDIMusic(mmusic, looping))
if (!S_LoadMusic(mmusic))
{
CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic);
return;
}
if (!S_PlayMusic(looping))
{
CONS_Alert(CONS_ERROR, "Music cannot be played!\n");
return;
}
}
I_SetSongTrack(mflags & MUSIC_TRACKMASK);
}

View file

@ -62,7 +62,6 @@
UINT8 sound_started = false;
static boolean midimode;
static Mix_Music *music;
static UINT8 music_volume, midi_volume, sfx_volume;
static float loop_point;
@ -87,7 +86,6 @@ void I_StartupSound(void)
return;
}
midimode = false;
music = NULL;
music_volume = midi_volume = sfx_volume = 0;
@ -436,6 +434,25 @@ void I_SetSfxVolume(UINT8 volume)
// Music
//
musictype_t I_GetMusicType(void)
{
#ifdef HAVE_LIBGME
if (gme)
return MU_GME;
else
#endif
if (!music)
return MU_NONE;
else if (Mix_GetMusicType(music) == MUS_MID)
return MU_MID;
else if (Mix_GetMusicType(music) == MUS_MOD || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED)
return MU_MOD;
else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED)
return MU_MP3;
else
return (musictype_t)Mix_GetMusicType(music);
}
// Music hooks
static void music_loop(void)
{
@ -470,8 +487,19 @@ FUNCMATH void I_InitMusic(void)
void I_ShutdownMusic(void)
{
I_ShutdownDigMusic();
I_ShutdownMIDIMusic();
#ifdef HAVE_LIBGME
if (gme)
{
Mix_HookMusic(NULL, NULL);
gme_delete(gme);
gme = NULL;
}
#endif
if (!music)
return;
Mix_HookMusicFinished(NULL);
Mix_FreeMusic(music);
music = NULL;
}
void I_PauseSong(INT32 handle)
@ -492,7 +520,15 @@ void I_ResumeSong(INT32 handle)
// Digital Music
//
void I_InitDigMusic(void)
void I_SetDigMusicVolume(UINT8 volume)
{
music_volume = volume;
if (I_GetMusicType() == MU_MID || !music)
return;
Mix_VolumeMusic((UINT32)volume*128/31);
}
boolean I_SetSongSpeed(float speed)
{
#ifdef HAVE_LIBGME
gme = NULL;
@ -691,8 +727,6 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
void I_StopDigSong(void)
{
if (midimode)
return;
#ifdef HAVE_LIBGME
if (gme)
{
@ -791,7 +825,7 @@ void I_SetMIDIMusicVolume(UINT8 volume)
midi_volume = 31;
//midi_volume = volume;
if (!midimode || !music)
if (I_GetMusicType() != MU_MID || !music)
return;
Mix_VolumeMusic((UINT32)midi_volume*128/31);
}
@ -834,10 +868,6 @@ void I_StopSong(INT32 handle)
void I_UnRegisterSong(INT32 handle)
{
if (!midimode || !music)
return;
(void)handle;
Mix_FreeMusic(music);
music = NULL;
}