Play the opposite type music (Digital/MIDI) when toggling between them in menu

* S_MusicInfo method to retrieve name, flags, and looping

(cherry picked from commit f6ec93198f0dcfa1d053cca88172c3e3c7ba310c)
This commit is contained in:
mazmazz 2018-08-23 16:46:40 -04:00
parent 7e7899ae83
commit 8c78d86c36
3 changed files with 54 additions and 5 deletions

View file

@ -6992,7 +6992,24 @@ static void M_ToggleDigital(void)
{
digital_disabled = true;
if (S_MusicType() != MU_MID)
S_StopMusic();
{
if (midi_disabled)
S_StopMusic();
else
{
char mmusic[7];
UINT16 mflags;
boolean looping;
if (S_MusicInfo(mmusic, &mflags, &looping) && S_MIDIExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
else
S_StopMusic();
}
}
M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING);
}
}
@ -7014,7 +7031,24 @@ static void M_ToggleMIDI(void)
{
midi_disabled = true;
if (S_MusicType() == MU_MID)
S_StopMusic();
{
if (digital_disabled)
S_StopMusic();
else
{
char mmusic[7];
UINT16 mflags;
boolean looping;
if (S_MusicInfo(mmusic, &mflags, &looping) && S_DigExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
else
S_StopMusic();
}
}
M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING);
}
}

View file

@ -1215,6 +1215,8 @@ const char *compat_special_music_slots[16] =
#endif
static char music_name[7]; // up to 6-character name
static UINT16 music_flags;
static boolean music_looping;
/// ------------------------
/// Music Status
@ -1250,9 +1252,17 @@ musictype_t S_MusicType(void)
return I_GetMusicType();
}
const char *S_MusicName(void)
boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping)
{
return music_name;
if (!I_MusicPlaying())
return false;
strncpy(mname, music_name, 7);
mname[6] = 0;
*mflags = music_flags;
*looping = music_looping;
return (boolean)mname[0];
}
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi)
@ -1333,6 +1343,8 @@ static void S_UnloadMusic(void)
{
I_UnloadSong();
music_name[0] = 0;
music_flags = 0;
music_looping = false;
}
static boolean S_PlayMusic(boolean looping)
@ -1373,6 +1385,9 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
if (!S_LoadMusic(mmusic))
return;
music_flags = mflags;
music_looping = looping;
if (!S_PlayMusic(looping))
{
CONS_Alert(CONS_ERROR, "Music cannot be played!\n");

View file

@ -108,7 +108,7 @@ boolean S_MusicDisabled(void);
boolean S_MusicPlaying(void);
boolean S_MusicPaused(void);
musictype_t S_MusicType(void);
const char *S_MusicName(void);
boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping);
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi);
#define S_DigExists(a) S_MusicExists(a, false, true)
#define S_MIDIExists(a) S_MusicExists(a, true, false)