Commit 63b15f78 by James R.

Merge branch 'musicpref-var' into 'next'

Console variable to select music preference See merge request !939
parents 005e7ce7 f541c37e
......@@ -1482,21 +1482,23 @@ static menuitem_t OP_OpenGLLightingMenu[] =
static menuitem_t OP_SoundOptionsMenu[] =
{
{IT_HEADER, NULL, "Game Audio", NULL, 0},
{IT_STRING | IT_CVAR, NULL, "Sound Effects", &cv_gamesounds, 12},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Sound Volume", &cv_soundvolume, 22},
{IT_STRING | IT_CVAR, NULL, "Sound Effects", &cv_gamesounds, 6},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Sound Volume", &cv_soundvolume, 11},
{IT_STRING | IT_CVAR, NULL, "Digital Music", &cv_gamedigimusic, 42},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Digital Music Volume", &cv_digmusicvolume, 52},
{IT_STRING | IT_CVAR, NULL, "Digital Music", &cv_gamedigimusic, 21},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Digital Music Volume", &cv_digmusicvolume, 26},
{IT_STRING | IT_CVAR, NULL, "MIDI Music", &cv_gamemidimusic, 72},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "MIDI Music Volume", &cv_midimusicvolume, 82},
{IT_STRING | IT_CVAR, NULL, "MIDI Music", &cv_gamemidimusic, 36},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "MIDI Music Volume", &cv_midimusicvolume, 41},
{IT_STRING | IT_CVAR, NULL, "Music Preference", &cv_musicpref, 51},
{IT_HEADER, NULL, "Miscellaneous", NULL, 102},
{IT_STRING | IT_CVAR, NULL, "Closed Captioning", &cv_closedcaptioning, 114},
{IT_STRING | IT_CVAR, NULL, "Reset Music Upon Dying", &cv_resetmusic, 124},
{IT_STRING | IT_CVAR, NULL, "Default 1-Up sound", &cv_1upsound, 134},
{IT_HEADER, NULL, "Miscellaneous", NULL, 61},
{IT_STRING | IT_CVAR, NULL, "Closed Captioning", &cv_closedcaptioning, 67},
{IT_STRING | IT_CVAR, NULL, "Reset Music Upon Dying", &cv_resetmusic, 72},
{IT_STRING | IT_CVAR, NULL, "Default 1-Up sound", &cv_1upsound, 77},
{IT_STRING | IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 154},
{IT_STRING | IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 87},
};
#ifdef HAVE_OPENMPT
......@@ -2195,7 +2197,7 @@ menu_t OP_ColorOptionsDef =
0,
NULL
};
menu_t OP_SoundOptionsDef = DEFAULTMENUSTYLE(
menu_t OP_SoundOptionsDef = DEFAULTSCROLLMENUSTYLE(
MTREE2(MN_OP_MAIN, MN_OP_SOUND),
"M_SOUND", OP_SoundOptionsMenu, &OP_MainDef, 30, 30);
menu_t OP_SoundAdvancedDef = DEFAULTMENUSTYLE(
......
......@@ -60,6 +60,7 @@ static void Command_RestartAudio_f(void);
static void GameMIDIMusic_OnChange(void);
static void GameSounds_OnChange(void);
static void GameDigiMusic_OnChange(void);
static void MusicPref_OnChange(void);
#ifdef HAVE_OPENMPT
static void ModFilter_OnChange(void);
......@@ -129,6 +130,14 @@ consvar_t cv_gamedigimusic = {"digimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_O
consvar_t cv_gamemidimusic = {"midimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameMIDIMusic_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_gamesounds = {"sounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameSounds_OnChange, 0, NULL, NULL, 0, 0, NULL};
// Music preference
static CV_PossibleValue_t cons_musicpref_t[] = {
{0, "Digital"},
{1, "MIDI"},
{0, NULL}
};
consvar_t cv_musicpref = {"musicpref", "Digital", CV_SAVE|CV_CALL|CV_NOINIT, cons_musicpref_t, MusicPref_OnChange, 0, NULL, NULL, 0, 0, NULL};
// Window focus sound sytem toggles
consvar_t cv_playmusicifunfocused = {"playmusicifunfocused", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_playsoundsifunfocused = {"playsoundsifunfocused", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL};
......@@ -301,6 +310,7 @@ void S_RegisterSoundStuff(void)
CV_RegisterVar(&cv_gamesounds);
CV_RegisterVar(&cv_gamedigimusic);
CV_RegisterVar(&cv_gamemidimusic);
CV_RegisterVar(&cv_musicpref);
#ifdef HAVE_OPENMPT
CV_RegisterVar(&cv_modfilter);
#endif
......@@ -1847,19 +1857,6 @@ const char *S_MusicName(void)
return music_name;
}
boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping)
{
if (!I_SongPlaying())
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)
{
return (
......@@ -2100,6 +2097,8 @@ boolean S_RecallMusic(UINT16 status, boolean fromfirst)
boolean mapmuschanged = false;
musicstack_t *result;
musicstack_t *entry = Z_Calloc(sizeof (*result), PU_MUSIC, NULL);
boolean currentmidi = (I_SongType() == MU_MID || I_SongType() == MU_MID_EX);
boolean midipref = cv_musicpref.value;
if (status)
result = S_GetMusicStackEntry(status, fromfirst, -1);
......@@ -2154,7 +2153,8 @@ boolean S_RecallMusic(UINT16 status, boolean fromfirst)
return false;
}
if (strncmp(entry->musname, S_MusicName(), 7)) // don't restart music if we're already playing it
if (strncmp(entry->musname, S_MusicName(), 7) || // don't restart music if we're already playing it
(midipref != currentmidi && S_PrefAvailable(midipref, entry->musname))) // but do if the user's preference has changed
{
if (music_stack_fadeout)
S_ChangeMusicEx(entry->musname, entry->musflags, entry->looping, 0, music_stack_fadeout, 0);
......@@ -2201,10 +2201,12 @@ boolean S_RecallMusic(UINT16 status, boolean fromfirst)
static lumpnum_t S_GetMusicLumpNum(const char *mname)
{
if (!S_DigMusicDisabled() && S_DigExists(mname))
return W_GetNumForName(va("o_%s", mname));
else if (!S_MIDIMusicDisabled() && S_MIDIExists(mname))
return W_GetNumForName(va("d_%s", mname));
boolean midipref = cv_musicpref.value;
if (S_PrefAvailable(midipref, mname))
return W_GetNumForName(va(midipref ? "d_%s":"o_%s", mname));
else if (S_PrefAvailable(!midipref, mname))
return W_GetNumForName(va(midipref ? "o_%s":"d_%s", mname));
else
return LUMPERROR;
}
......@@ -2330,6 +2332,8 @@ static void S_ChangeMusicToQueue(void)
void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 position, UINT32 prefadems, UINT32 fadeinms)
{
char newmusic[7];
boolean currentmidi = (I_SongType() == MU_MID || I_SongType() == MU_MID_EX);
boolean midipref = cv_musicpref.value;
if (S_MusicDisabled())
return;
......@@ -2359,7 +2363,8 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32
I_FadeSong(0, prefadems, S_ChangeMusicToQueue);
return;
}
else if (strnicmp(music_name, newmusic, 6) || (mflags & MUSIC_FORCERESET))
else if (strnicmp(music_name, newmusic, 6) || (mflags & MUSIC_FORCERESET) ||
(midipref != currentmidi && S_PrefAvailable(midipref, newmusic)))
{
CONS_Debug(DBG_DETAILED, "Now playing song %s\n", newmusic);
......@@ -2665,32 +2670,24 @@ void GameDigiMusic_OnChange(void)
digital_disabled = false;
I_StartupSound(); // will return early if initialised
I_InitMusic();
S_StopMusic();
if (Playing())
P_RestoreMusic(&players[consoleplayer]);
else
else if ((!cv_musicpref.value || midi_disabled) && S_DigExists("_clear"))
S_ChangeMusicInternal("_clear", false);
}
else
{
digital_disabled = true;
if (S_MusicType() != MU_MID)
if (S_MusicType() != MU_MID && S_MusicType() != MU_MID_EX)
{
if (midi_disabled)
S_StopMusic();
else
S_StopMusic();
if (!midi_disabled)
{
char mmusic[7];
UINT16 mflags;
boolean looping;
if (S_MusicInfo(mmusic, &mflags, &looping) && S_MIDIExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
if (Playing())
P_RestoreMusic(&players[consoleplayer]);
else
S_StopMusic();
S_ChangeMusicInternal("_clear", false);
}
}
}
......@@ -2708,9 +2705,10 @@ void GameMIDIMusic_OnChange(void)
midi_disabled = false;
I_StartupSound(); // will return early if initialised
I_InitMusic();
if (Playing())
P_RestoreMusic(&players[consoleplayer]);
else
else if ((cv_musicpref.value || digital_disabled) && S_MIDIExists("_clear"))
S_ChangeMusicInternal("_clear", false);
}
else
......@@ -2718,26 +2716,30 @@ void GameMIDIMusic_OnChange(void)
midi_disabled = true;
if (S_MusicType() == MU_MID || S_MusicType() == MU_MID_EX)
{
if (digital_disabled)
S_StopMusic();
else
S_StopMusic();
if (!digital_disabled)
{
char mmusic[7];
UINT16 mflags;
boolean looping;
if (S_MusicInfo(mmusic, &mflags, &looping) && S_DigExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
if (Playing())
P_RestoreMusic(&players[consoleplayer]);
else
S_StopMusic();
S_ChangeMusicInternal("_clear", false);
}
}
}
}
void MusicPref_OnChange(void)
{
if (M_CheckParm("-nomusic") || M_CheckParm("-noaudio") ||
M_CheckParm("-nomidimusic") || M_CheckParm("-nodigmusic"))
return;
if (Playing())
P_RestoreMusic(&players[consoleplayer]);
else if (S_PrefAvailable(cv_musicpref.value, "_clear"))
S_ChangeMusicInternal("_clear", false);
}
#ifdef HAVE_OPENMPT
void ModFilter_OnChange(void)
{
......
......@@ -46,6 +46,7 @@ extern consvar_t cv_1upsound;
extern consvar_t cv_gamedigimusic;
extern consvar_t cv_gamemidimusic;
extern consvar_t cv_gamesounds;
extern consvar_t cv_musicpref;
extern consvar_t cv_playmusicifunfocused;
extern consvar_t cv_playsoundsifunfocused;
......@@ -178,11 +179,16 @@ boolean S_MusicPaused(void);
boolean S_MusicNotInFocus(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)
// Returns whether the preferred format a (true = MIDI, false = Digital)
// exists and is enabled for musicname b
#define S_PrefAvailable(a, b) (a ? \
(!S_MIDIMusicDisabled() && S_MIDIExists(b)) : \
(!S_DigMusicDisabled() && S_DigExists(b)))
//
// Music Effects
//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment