- some cleanup on music code.

* change the license of the main file because there is no more id-based code here licensed under the GPL.
* moved VM interface definition out of the implementation.
* moved idmus CCMD out of implementation because it is dependent on Doom level definitions.
* moved s_music.cpp into the music folder with the rest of the music code.
This commit is contained in:
Christoph Oelckers 2020-04-11 18:23:15 +02:00
parent 56f2b2ac56
commit 4af96bab47
15 changed files with 196 additions and 225 deletions

View file

@ -884,7 +884,6 @@ set (PCH_SOURCES
sound/s_sndseq.cpp
sound/s_doomsound.cpp
sound/s_sound.cpp
sound/s_music.cpp
serializer.cpp
scriptutil.cpp
st_stuff.cpp
@ -1097,6 +1096,7 @@ set (PCH_SOURCES
scripting/zscript/ast.cpp
scripting/zscript/zcc_compile.cpp
scripting/zscript/zcc_parser.cpp
sound/music/music.cpp
sound/music/i_music.cpp
sound/music/i_soundfont.cpp
sound/backend/i_sound.cpp

View file

@ -65,6 +65,8 @@
#include "v_video.h"
#include "md5.h"
#include "findfile.h"
#include "i_music.h"
#include "s_music.h"
extern FILE *Logfile;
extern bool insave;
@ -1084,3 +1086,57 @@ CCMD(r_showcaps)
}
//==========================================================================
//
// CCMD idmus
//
//==========================================================================
CCMD(idmus)
{
level_info_t* info;
FString map;
int l;
if (!nomusic)
{
if (argv.argc() > 1)
{
if (gameinfo.flags & GI_MAPxx)
{
l = atoi(argv[1]);
if (l <= 99)
{
map = CalcMapName(0, l);
}
else
{
Printf("%s\n", GStrings("STSTR_NOMUS"));
return;
}
}
else
{
map = CalcMapName(argv[1][0] - '0', argv[1][1] - '0');
}
if ((info = FindLevelInfo(map)))
{
if (info->Music.IsNotEmpty())
{
S_ChangeMusic(info->Music, info->musicorder);
Printf("%s\n", GStrings("STSTR_MUS"));
}
}
else
{
Printf("%s\n", GStrings("STSTR_NOMUS"));
}
}
}
else
{
Printf("Music is disabled\n");
}
}

View file

@ -1280,7 +1280,7 @@ void C_FullConsole ()
gamestate = GS_FULLCONSOLE;
primaryLevel->Music = "";
S_Start ();
S_StartMusic();
S_StopMusic(true);
P_FreeLevelData ();
}
else

View file

@ -148,6 +148,7 @@ void DrawFullscreenSubtitle(const char *text);
void D_Cleanup();
void FreeSBarInfoScript();
void I_UpdateWindowTitle();
void S_ParseMusInfo();
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------

View file

@ -415,7 +415,14 @@ void P_SetupLevel(FLevelLocals *Level, int position, bool newGame)
// Make sure all sounds are stopped before Z_FreeTags.
S_Start();
S_StartMusic();
S_ResetMusic();
// Don't start the music if loading a savegame, because the music is stored there.
// Don't start the music if revisiting a level in a hub for the same reason.
if (!primaryLevel->IsReentering())
{
primaryLevel->SetMusic();
}
// [RH] clear out the mid-screen message
C_MidPrint(nullptr, nullptr);

View file

@ -56,6 +56,7 @@
#include "c_cvars.h"
#include "c_bind.h"
#include "c_dispatch.h"
#include "s_music.h"
DVector2 AM_GetPosition();
int Net_GetLatency(int *ld, int *ad);
@ -3435,6 +3436,16 @@ DEFINE_ACTION_FUNCTION(_Console, Printf)
}
DEFINE_ACTION_FUNCTION(DObject, S_ChangeMusic)
{
PARAM_PROLOGUE;
PARAM_STRING(music);
PARAM_INT(order);
PARAM_BOOL(looping);
PARAM_BOOL(force);
ACTION_RETURN_BOOL(S_ChangeMusic(music, order, looping, force));
}
//==========================================================================
@ -3619,3 +3630,8 @@ DEFINE_GLOBAL(StatusBar);
DEFINE_GLOBAL(Bindings)
DEFINE_GLOBAL(AutomapBindings)
DEFINE_GLOBAL_NAMED(mus_playing, musplaying);
DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, name);
DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, baseorder);
DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, loop);

View file

@ -45,9 +45,9 @@
#include "c_dispatch.h"
#include "templates.h"
#include "stats.h"
#include "cmdlib.h"
#include "c_cvars.h"
#include "c_console.h"
#include "vm.h"
#include "v_text.h"
#include "i_sound.h"
#include "i_soundfont.h"
@ -61,9 +61,7 @@ void I_InitSoundFonts();
EXTERN_CVAR (Int, snd_samplerate)
EXTERN_CVAR (Int, snd_mididevice)
static bool ungzip(uint8_t *data, int size, std::vector<uint8_t> &newdata);
EXTERN_CVAR(Float, snd_mastervolume)
int nomusic = 0;
//==========================================================================
@ -73,7 +71,7 @@ int nomusic = 0;
// Maximum volume of MOD/stream music.
//==========================================================================
CUSTOM_CVAR (Float, snd_musicvolume, 0.5f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CUSTOM_CVARD(Float, snd_musicvolume, 0.5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "controls music volume")
{
if (self < 0.f)
self = 0.f;
@ -100,6 +98,12 @@ CUSTOM_CVAR (Float, snd_musicvolume, 0.5f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
}
}
CUSTOM_CVARD(Bool, mus_enabled, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "enables/disables music")
{
if (self) S_RestartMusic();
else S_StopMusic(true);
}
//==========================================================================
//
// Callbacks for the music system.
@ -360,7 +364,7 @@ UNSAFE_CCMD (writewave)
if (source == nullptr) return;
EMidiDevice dev = MDEV_DEFAULT;
#ifndef ZMUSIC_LITE
if (argv.argc() >= 6)
{
if (!stricmp(argv[5], "WildMidi")) dev = MDEV_WILDMIDI;
@ -376,6 +380,7 @@ UNSAFE_CCMD (writewave)
return;
}
}
#endif
// We must stop the currently playing music to avoid interference between two synths.
auto savedsong = mus_playing;
S_StopMusic(true);

View file

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include "doomtype.h"
#include "zstring.h"
#include "tarray.h"
#include "filesystem.h"
#include "files.h"
#include "filereadermusicinterface.h"

View file

@ -1,29 +1,11 @@
//-----------------------------------------------------------------------------
//
// Copyright 1993-1996 id Software
// Copyright 1999-2016 Randy Heit
// Copyright 2002-2016 Christoph Oelckers
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION: none
//
//-----------------------------------------------------------------------------
/* For code that originates from ZDoom the following applies:
/*
**
** music.cpp
**
** music engine
**
** Copyright 1999-2016 Randy Heit
** Copyright 2002-2016 Christoph Oelckers
**
**---------------------------------------------------------------------------
**
@ -104,10 +86,6 @@ static FPlayList PlayList;
float relative_volume = 1.f;
float saved_relative_volume = 1.0f; // this could be used to implement an ACS FadeMusic function
DEFINE_GLOBAL_NAMED(mus_playing, musplaying);
DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, name);
DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, baseorder);
DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, loop);
// PUBLIC DATA DEFINITIONS -------------------------------------------------
@ -257,13 +235,11 @@ void S_UpdateMusic ()
//==========================================================================
//
// S_Start
// Resets the music player if music playback was paused.
//
// Per level startup code. Kills playing sounds at start of level
// and starts new music.
//==========================================================================
void S_StartMusic ()
void S_ResetMusic ()
{
// stop the old music if it has been paused.
// This ensures that the new music is started from the beginning
@ -272,13 +248,6 @@ void S_StartMusic ()
// start new music for the level
MusicPaused = false;
// Don't start the music if loading a savegame, because the music is stored there.
// Don't start the music if revisiting a level in a hub for the same reason.
if (!primaryLevel->IsReentering())
{
primaryLevel->SetMusic();
}
}
@ -361,6 +330,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
mus_playing.LastSong = "";
return true;
}
if (*musicname == '/') musicname++;
FString DEH_Music;
if (musicname[0] == '$')
@ -460,7 +430,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
// shutdown old music
S_StopMusic (true);
// Just record it if volume is 0
// Just record it if volume is 0 or music was disabled
if (snd_musicvolume <= 0)
{
mus_playing.loop = looping;
@ -505,22 +475,10 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
return false;
}
DEFINE_ACTION_FUNCTION(DObject, S_ChangeMusic)
{
PARAM_PROLOGUE;
PARAM_STRING(music);
PARAM_INT(order);
PARAM_BOOL(looping);
PARAM_BOOL(force);
ACTION_RETURN_BOOL(S_ChangeMusic(music, order, looping, force));
}
//==========================================================================
//
// S_RestartMusic
//
// Must only be called from snd_reset in i_sound.cpp!
//==========================================================================
void S_RestartMusic ()
@ -613,60 +571,6 @@ void S_StopMusic (bool force)
}
}
//==========================================================================
//
// CCMD idmus
//
//==========================================================================
CCMD (idmus)
{
level_info_t *info;
FString map;
int l;
if (!nomusic)
{
if (argv.argc() > 1)
{
if (gameinfo.flags & GI_MAPxx)
{
l = atoi (argv[1]);
if (l <= 99)
{
map = CalcMapName (0, l);
}
else
{
Printf ("%s\n", GStrings("STSTR_NOMUS"));
return;
}
}
else
{
map = CalcMapName (argv[1][0] - '0', argv[1][1] - '0');
}
if ( (info = FindLevelInfo (map)) )
{
if (info->Music.IsNotEmpty())
{
S_ChangeMusic (info->Music, info->musicorder);
Printf ("%s\n", GStrings("STSTR_MUS"));
}
}
else
{
Printf ("%s\n", GStrings("STSTR_NOMUS"));
}
}
}
else
{
Printf("Music is disabled\n");
}
}
//==========================================================================
//
// CCMD changemus

View file

@ -63,7 +63,7 @@
auto ret = ChangeMusicSetting(zmusic_##key, mus_playing.handle,*self); \
if (ret) S_MIDIDeviceChanged(-1);
#ifndef ZMUSIC_LITE
CUSTOM_CVAR(Int, adl_chips_count, 6, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
{
FORWARD_CVAR(adl_chips_count);
@ -103,7 +103,7 @@ CUSTOM_CVAR(Int, adl_volume_model, 3/*ADLMIDI_VolumeModel_DMX*/, CVAR_ARCHIVE |
{
FORWARD_CVAR(adl_bank);
}
#endif
//==========================================================================
//
// Fluidsynth MIDI device
@ -223,6 +223,7 @@ CUSTOM_CVAR(Bool, opl_fullpan, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIR
FORWARD_BOOL_CVAR(opl_fullpan);
}
#ifndef ZMUSIC_LITE
//==========================================================================
//
// OPN MIDI device
@ -382,12 +383,13 @@ CUSTOM_CVAR(Float, timidity_min_sustain_time, 5000, CVAR_ARCHIVE | CVAR_GLOBALCO
{
FORWARD_CVAR(timidity_min_sustain_time);
}
#endif
CUSTOM_CVAR(String, timidity_config, GAMENAMELOWERCASE, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
{
FORWARD_STRING_CVAR(timidity_config);
}
#ifndef ZMUSIC_LITE
//==========================================================================
//
// WildMidi
@ -408,7 +410,7 @@ CUSTOM_CVAR(Bool, wildmidi_enhanced_resampling, true, CVAR_ARCHIVE | CVAR_GLOBAL
{
FORWARD_BOOL_CVAR(wildmidi_enhanced_resampling);
}
#endif
//==========================================================================
//

View file

@ -38,6 +38,8 @@
#include "menu/menu.h"
#include <zmusic.h>
#include "s_music.h"
#include "c_cvars.h"
#include "printf.h"
#define DEF_MIDIDEV -5

72
src/sound/music/s_music.h Normal file
View file

@ -0,0 +1,72 @@
#ifndef __S_MUSIC__
#define __S_MUSIC__
#include "zstring.h"
#include "tarray.h"
#include "name.h"
#include <zmusic.h>
void S_CreateStream();
void S_PauseStream(bool pause);
void S_StopStream();
void S_SetStreamVolume(float vol);
//
void S_InitMusic ();
void S_ResetMusic ();
// Start music using <music_name>
bool S_StartMusic (const char *music_name);
// Start music using <music_name>, and set whether looping
bool S_ChangeMusic (const char *music_name, int order=0, bool looping=true, bool force=false);
void S_RestartMusic ();
void S_MIDIDeviceChanged(int newdev);
int S_GetMusic (const char **name);
// Stops the music for sure.
void S_StopMusic (bool force);
// Stop and resume music, during game PAUSE.
void S_PauseMusic ();
void S_ResumeMusic ();
//
// Updates music & sounds
//
void S_UpdateMusic ();
struct MidiDeviceSetting
{
int device;
FString args;
};
typedef TMap<FName, FName> MusicAliasMap;
typedef TMap<FName, MidiDeviceSetting> MidiDeviceMap;
typedef TMap<FName, float> MusicVolumeMap;
extern MusicAliasMap MusicAliases;
extern MidiDeviceMap MidiDevices;
extern MusicVolumeMap MusicVolumes;
struct MusPlayingInfo
{
FString name;
ZMusic_MusicStream handle;
int baseorder;
bool loop;
FString LastSong; // last music that was played
};
extern MusPlayingInfo mus_playing;
extern float relative_volume, saved_relative_volume;
#endif

View file

@ -230,7 +230,7 @@ static const char *SICommandStrings[] =
NULL
};
static FMusicVolume *MusicVolumes;
static FMusicVolume *MusicVolumes_;
static TArray<FSavedPlayerSoundInfo> SavedPlayerSounds;
static int NumPlayerReserves;
@ -256,7 +256,7 @@ static uint8_t CurrentPitchMask;
float S_GetMusicVolume (const char *music)
{
FMusicVolume *musvol = MusicVolumes;
FMusicVolume *musvol = MusicVolumes_;
while (musvol != NULL)
{
@ -744,10 +744,10 @@ void S_ClearSoundData()
soundEngine->Clear();
Ambients.Clear();
while (MusicVolumes != NULL)
while (MusicVolumes_ != NULL)
{
FMusicVolume *me = MusicVolumes;
MusicVolumes = me->Next;
FMusicVolume *me = MusicVolumes_;
MusicVolumes_ = me->Next;
M_Free(me);
}
@ -1184,8 +1184,8 @@ static void S_AddSNDINFO (int lump)
FMusicVolume *mv = (FMusicVolume *)M_Malloc (sizeof(*mv) + musname.Len());
mv->Volume = (float)sc.Float;
strcpy (mv->MusicName, musname);
mv->Next = MusicVolumes;
MusicVolumes = mv;
mv->Next = MusicVolumes_;
MusicVolumes_ = mv;
}
break;

View file

@ -1412,7 +1412,6 @@ DEFINE_ACTION_FUNCTION(DObject, S_ResumeSound)
}
CCMD (snd_status)
{
GSnd->PrintStatus ();

View file

@ -1,93 +0,0 @@
//-----------------------------------------------------------------------------
//
// Copyright 1993-1996 id Software
// Copyright 1999-2016 Randy Heit
// Copyright 2002-2016 Christoph Oelckers
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION:
// The not so system specific sound interface.
//
//-----------------------------------------------------------------------------
#ifndef __S_MUSIC__
#define __S_MUSIC__
#include <zmusic.h>
#include "doomtype.h"
#include "i_soundinternal.h"
void S_ParseMusInfo();
//
void S_InitMusic ();
void S_StartMusic ();
// Start music using <music_name>
bool S_StartMusic (const char *music_name);
// Start music using <music_name>, and set whether looping
bool S_ChangeMusic (const char *music_name, int order=0, bool looping=true, bool force=false);
void S_RestartMusic ();
void S_MIDIDeviceChanged(int newdev);
int S_GetMusic (const char **name);
// Stops the music for sure.
void S_StopMusic (bool force);
// Stop and resume music, during game PAUSE.
void S_PauseMusic ();
void S_ResumeMusic ();
//
// Updates music & sounds
//
void S_UpdateMusic ();
struct MidiDeviceSetting
{
int device;
FString args;
};
typedef TMap<FName, FName> MusicAliasMap;
typedef TMap<FName, MidiDeviceSetting> MidiDeviceMap;
extern MusicAliasMap MusicAliases;
extern MidiDeviceMap MidiDevices;
struct MusPlayingInfo
{
FString name;
ZMusic_MusicStream handle;
int baseorder;
bool loop;
FString LastSong; // last music that was played
};
extern MusPlayingInfo mus_playing;
extern float relative_volume, saved_relative_volume;
#endif