added CVAR to select the preferred MOD player and SNDINFO option to set it per song.

This commit is contained in:
Christoph Oelckers 2024-10-05 12:36:55 +02:00
parent 6b5be653dc
commit 413aefb0ab
4 changed files with 30 additions and 2 deletions

View file

@ -151,6 +151,7 @@ typedef enum EIntConfigKey_
zmusic_snd_mididevice, zmusic_snd_mididevice,
zmusic_snd_outputrate, zmusic_snd_outputrate,
zmusic_mod_preferredplayer,
NUM_ZMUSIC_INT_CONFIGS NUM_ZMUSIC_INT_CONFIGS
} EIntConfigKey; } EIntConfigKey;

View file

@ -74,6 +74,7 @@ float relative_volume = 1.f;
float saved_relative_volume = 1.0f; // this could be used to implement an ACS FadeMusic function float saved_relative_volume = 1.0f; // this could be used to implement an ACS FadeMusic function
MusicVolumeMap MusicVolumes; MusicVolumeMap MusicVolumes;
MidiDeviceMap MidiDevices; MidiDeviceMap MidiDevices;
TMap<int, int> ModPlayers;
static int DefaultFindMusic(const char* fn) static int DefaultFindMusic(const char* fn)
{ {
@ -93,6 +94,7 @@ EXTERN_CVAR(Float, fluid_gain)
CVAR(Bool, mus_calcgain, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // changing this will only take effect for the next song. CVAR(Bool, mus_calcgain, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // changing this will only take effect for the next song.
CVAR(Bool, mus_usereplaygain, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // changing this will only take effect for the next song. CVAR(Bool, mus_usereplaygain, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // changing this will only take effect for the next song.
CVAR(Int, mod_preferred_player, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)// toggle between libXMP and Dumb. Unlike other sound CVARs this is not directly mapped to ZMusic's config.
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
@ -769,6 +771,7 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
{ {
int lumpnum = mus_cb.FindMusic(musicname); int lumpnum = mus_cb.FindMusic(musicname);
MidiDeviceSetting* devp = MidiDevices.CheckKey(lumpnum); MidiDeviceSetting* devp = MidiDevices.CheckKey(lumpnum);
int* mplay = ModPlayers.CheckKey(lumpnum);
auto volp = MusicVolumes.CheckKey(lumpnum); auto volp = MusicVolumes.CheckKey(lumpnum);
if (volp) if (volp)
@ -781,6 +784,12 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
CheckReplayGain(musicname, devp ? (EMidiDevice)devp->device : MDEV_DEFAULT, devp ? devp->args.GetChars() : ""); CheckReplayGain(musicname, devp ? (EMidiDevice)devp->device : MDEV_DEFAULT, devp ? devp->args.GetChars() : "");
} }
auto mreader = GetMusicReader(reader); // this passes the file reader to the newly created wrapper. auto mreader = GetMusicReader(reader); // this passes the file reader to the newly created wrapper.
int mod_player = mplay? *mplay : *mod_preferred_player;
int scratch;
// This config var is only effective when opening a music stream so there's no need for active synchronization. Setting it here is sufficient.
// Ideally this should have been a parameter to ZMusic_OpenSong, but that would have necessitated an API break.
ChangeMusicSettingInt(zmusic_mod_preferredplayer, mus_playing.handle, mod_player, &scratch);
mus_playing.handle = ZMusic_OpenSong(mreader, devp ? (EMidiDevice)devp->device : MDEV_DEFAULT, devp ? devp->args.GetChars() : ""); mus_playing.handle = ZMusic_OpenSong(mreader, devp ? (EMidiDevice)devp->device : MDEV_DEFAULT, devp ? devp->args.GetChars() : "");
if (mus_playing.handle == nullptr) if (mus_playing.handle == nullptr)
{ {

View file

@ -74,6 +74,7 @@ struct MidiDeviceSetting
typedef TMap<int, MidiDeviceSetting> MidiDeviceMap; typedef TMap<int, MidiDeviceSetting> MidiDeviceMap;
typedef TMap<int, float> MusicVolumeMap; typedef TMap<int, float> MusicVolumeMap;
extern TMap<int, int> ModPlayers;
extern MidiDeviceMap MidiDevices; extern MidiDeviceMap MidiDevices;
extern MusicVolumeMap MusicVolumes; extern MusicVolumeMap MusicVolumes;
extern MusicCallbacks mus_cb; extern MusicCallbacks mus_cb;

View file

@ -147,6 +147,7 @@ enum SICommands
SI_EDFOverride, SI_EDFOverride,
SI_Attenuation, SI_Attenuation,
SI_PitchSet, SI_PitchSet,
SI_ModPlayer,
}; };
// Blood was a cool game. If Monolith ever releases the source for it, // Blood was a cool game. If Monolith ever releases the source for it,
@ -236,7 +237,8 @@ static const char *SICommandStrings[] =
"$edfoverride", "$edfoverride",
"$attenuation", "$attenuation",
"$pitchset", "$pitchset",
NULL "$modplayer",
nullptr
}; };
static TArray<FSavedPlayerSoundInfo> SavedPlayerSounds; static TArray<FSavedPlayerSoundInfo> SavedPlayerSounds;
@ -571,6 +573,7 @@ void S_ClearSoundData()
MusicAliases.Clear(); MusicAliases.Clear();
MidiDevices.Clear(); MidiDevices.Clear();
HexenMusic.Clear(); HexenMusic.Clear();
ModPlayers.Clear();
} }
//========================================================================== //==========================================================================
@ -1109,7 +1112,21 @@ static void S_AddSNDINFO (int lump)
sc.RestorePos(save); sc.RestorePos(save);
sc.MustGetString(); sc.MustGetString();
} }
if (lumpnum >= 0) MidiDevices[lumpnum] = devset; if (lumpnum >= 0) MidiDevices.Insert(lumpnum, devset);
}
break;
case SI_ModPlayer: {
sc.MustGetString();
int lumpnum = mus_cb.FindMusic(sc.String);
int player;
FScanner::SavedPos save = sc.SavePos();
sc.MustGetString();
if (sc.Compare("XMP") || sc.Compare("libXMP")) player = 0;
else if (sc.Compare("dumb") || sc.Compare("libdumb")) player = 1;
else sc.ScriptError("Unknown Module player %s\n", sc.String);
if (lumpnum >= 0) ModPlayers.Insert(lumpnum, player);
} }
break; break;