Added I_GetMusicType and removed midimode variable

* Revised S_PlayMusic arguments
* Now music plays again!

(cherry picked from commit 55f3803e4b9f8104c90cc6c769d54121e5bac0b8)
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 "sounds.h"
#include "command.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 /** \brief Sound subsystem runing and waiting
*/ */
extern UINT8 sound_started; extern UINT8 sound_started;
@ -108,6 +123,9 @@ void I_SetSfxVolume(UINT8 volume);
// //
// MUSIC I/O // MUSIC I/O
// //
musictype_t I_GetMusicType(void);
/** \brief Init the music systems /** \brief Init the music systems
*/ */
void I_InitMusic(void); void I_InitMusic(void);

View file

@ -1227,7 +1227,7 @@ static boolean S_MIDIMusic(const char *mname, boolean looping)
return true; return true;
} }
static boolean S_DigMusic(const char *mname, boolean looping) static boolean S_PlayMusic(boolean looping)
{ {
if (nodigimusic || digital_disabled) if (nodigimusic || digital_disabled)
return false; // try midi return false; // try midi
@ -1235,11 +1235,6 @@ static boolean S_DigMusic(const char *mname, boolean looping)
if (!I_StartDigSong(mname, looping)) if (!I_StartDigSong(mname, looping))
return false; return false;
strncpy(music_name, mname, 7);
music_name[6] = 0;
music_lumpnum = LUMPERROR;
music_data = NULL;
music_handle = 0;
return true; return true;
} }
@ -1262,11 +1257,18 @@ 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_DigMusic(mmusic, looping) && !S_MIDIMusic(mmusic, looping))
if (!S_LoadMusic(mmusic))
{ {
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;
} }
if (!S_PlayMusic(looping))
{
CONS_Alert(CONS_ERROR, "Music cannot be played!\n");
return;
}
} }
I_SetSongTrack(mflags & MUSIC_TRACKMASK); I_SetSongTrack(mflags & MUSIC_TRACKMASK);
} }

View file

@ -62,7 +62,6 @@
UINT8 sound_started = false; UINT8 sound_started = false;
static boolean midimode;
static Mix_Music *music; static Mix_Music *music;
static UINT8 music_volume, midi_volume, sfx_volume; static UINT8 music_volume, midi_volume, sfx_volume;
static float loop_point; static float loop_point;
@ -87,7 +86,6 @@ void I_StartupSound(void)
return; return;
} }
midimode = false;
music = NULL; music = NULL;
music_volume = midi_volume = sfx_volume = 0; music_volume = midi_volume = sfx_volume = 0;
@ -436,6 +434,25 @@ void I_SetSfxVolume(UINT8 volume)
// Music // 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 // Music hooks
static void music_loop(void) static void music_loop(void)
{ {
@ -470,8 +487,19 @@ FUNCMATH void I_InitMusic(void)
void I_ShutdownMusic(void) void I_ShutdownMusic(void)
{ {
I_ShutdownDigMusic(); #ifdef HAVE_LIBGME
I_ShutdownMIDIMusic(); 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) void I_PauseSong(INT32 handle)
@ -492,7 +520,15 @@ void I_ResumeSong(INT32 handle)
// Digital Music // 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 #ifdef HAVE_LIBGME
gme = NULL; gme = NULL;
@ -691,8 +727,6 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
void I_StopDigSong(void) void I_StopDigSong(void)
{ {
if (midimode)
return;
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
if (gme) if (gme)
{ {
@ -791,7 +825,7 @@ void I_SetMIDIMusicVolume(UINT8 volume)
midi_volume = 31; midi_volume = 31;
//midi_volume = volume; //midi_volume = volume;
if (!midimode || !music) if (I_GetMusicType() != MU_MID || !music)
return; return;
Mix_VolumeMusic((UINT32)midi_volume*128/31); Mix_VolumeMusic((UINT32)midi_volume*128/31);
} }
@ -834,10 +868,6 @@ void I_StopSong(INT32 handle)
void I_UnRegisterSong(INT32 handle) void I_UnRegisterSong(INT32 handle)
{ {
if (!midimode || !music)
return;
(void)handle;
Mix_FreeMusic(music); Mix_FreeMusic(music);
music = NULL; music = NULL;
} }