Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 70 additions & 24 deletions src/game/client/mp3player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ vgui::Panel *GetSDKRootPanel();
#define SOUND_ROOT "sound"

#ifdef NEO
#define MUTED_VOLUME 4
#else
#define MUTED_VOLUME 0.02f
// NEO NOTE lowest value accepted if snd_musicvolume isn't used is 0.015686274506151678
#endif // NEO
#define MUTED_VOLUME 0.02f

#define TREE_TEXT_COLOR Color( 200, 255, 200, 255 )
#define LIST_TEXT_COLOR TREE_TEXT_COLOR
Expand Down Expand Up @@ -788,8 +787,16 @@ class CMP3SongProgress : public Slider
ConVar cl_neo_radio_shuffle("cl_neo_radio_shuffle", "0", FCVAR_CLIENTDLL| FCVAR_ARCHIVE | FCVAR_DONTRECORD | FCVAR_HIDDEN, "Randomize song order", true, 0, true, 1);
ConVar cl_neo_radio_mute("cl_neo_radio_mute", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_DONTRECORD | FCVAR_HIDDEN, "Turn down sound volume as far as possible", true, 0, true, 1);
ConVar cl_neo_radio_game_pause("cl_neo_radio_game_pause", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_DONTRECORD | FCVAR_HIDDEN, "Pause NEO Radio song when loading into a game", true, 0, true, 1);
ConVar cl_neo_radio_volume("cl_neo_radio_volume", "80", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_DONTRECORD | FCVAR_HIDDEN, "NEO Radio song volume", true, MUTED_VOLUME, true, 100);
ConVar cl_neo_radio_volume_ingame("cl_neo_radio_volume_ingame", "20", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_DONTRECORD | FCVAR_HIDDEN, "NEO Radio song volume in game", true, MUTED_VOLUME, true, 100);
ConVar cl_neo_radio_volume("cl_neo_radio_volume", "0.8", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_DONTRECORD | FCVAR_HIDDEN, "NEO Radio song volume", true, MUTED_VOLUME, true, 1,
[](IConVar* var [[maybe_unused]], const char* pOldValue [[maybe_unused]], float flOldValue [[maybe_unused]] )
{
if (auto pPlayer = GetMP3Player()) {pPlayer->SetVolumeSlider(cl_neo_radio_volume.GetFloat() * 100);}
});
ConVar cl_neo_radio_volume_ingame("cl_neo_radio_volume_ingame", "0.2", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_DONTRECORD | FCVAR_HIDDEN, "NEO Radio song volume in game", true, MUTED_VOLUME, true, 1,
[](IConVar* var [[maybe_unused]], const char* pOldValue [[maybe_unused]], float flOldValue [[maybe_unused]] )
{
if (auto pPlayer = GetMP3Player()) {pPlayer->SetInGameVolumeSlider(cl_neo_radio_volume_ingame.GetFloat() * 100);}
});
#endif // NEO
CMP3Player::CMP3Player( VPANEL parent, char const *panelName ) :
BaseClass( NULL, panelName ),
Expand Down Expand Up @@ -846,13 +853,13 @@ CMP3Player::CMP3Player( VPANEL parent, char const *panelName ) :

m_pVolume = new Slider( this, "Volume" );
#ifdef NEO
m_pVolume->SetRange( MUTED_VOLUME, 100 );
m_pVolume->SetRange((int)ceil(MUTED_VOLUME * 100.f), 100 );
#else
m_pVolume->SetRange( (int)( MUTED_VOLUME * 100.0f ), 100 );
#endif // NEO
#ifdef NEO
m_pVolumeInGame = new Slider(this, "VolumeInGame");
m_pVolumeInGame->SetRange( MUTED_VOLUME, 100);
m_pVolumeInGame->SetRange((int)ceil(MUTED_VOLUME * 100.f), 100);

m_pGamePause = new CheckButton(this, "GamePause", "#GamePause");
#else
Expand Down Expand Up @@ -1632,12 +1639,24 @@ void CMP3Player::PlaySong( int songIndex, float skipTime /*= 0.0f */ )
char drymix[ 512 ];
Q_snprintf( drymix, sizeof( drymix ), "#%s", soundname );

#ifdef NEO
// NEO NOTE (Adam) As per https://developer.valvesoftware.com/wiki/Soundscripts the # symbol above makes the sound skip dsp (whatever) and makes the sound respect snd_musicvolume (big sad).
// We can remove the # and then the sound will use dsp (whatever) and ignore snd_musicvolume (yay). Unfortunately setting the volume of the sound to 0 stops the sound from playing as opposed
// to pausing it (big sad). The wiki above states that, for snd_musicvolume to be respected the sound also needs to be non-directional (sound level of 0). So we use EmitSound instead with
// SNDLVL_NORM, the result sounding exactly the same as before far as I can tell, being pausable, and still ignoring the value of snd_musicvolume. This only took me the entire day to figure out
CLocalPlayerFilter filter;
enginesound->EmitSound( filter, SOUND_FROM_UI_PANEL, CHAN_MP3_PLAYER, drymix, volume,
SNDLVL_NORM, 0, PITCH_NORM, 0, NULL, NULL, NULL, true,
skipTime == 0.0f ? 0.0f : (gpGlobals->curtime + skipTime), -1
);
#else
enginesound->EmitAmbientSound(
drymix,
volume,
PITCH_NORM,
0,
skipTime == 0.0f ? 0.0f : ( gpGlobals->curtime + skipTime ) );
#endif // NEO

m_nSongGuid = enginesound->GetGuidForLastSoundEmitted();

Expand Down Expand Up @@ -1665,6 +1684,18 @@ void CMP3Player::PlaySong( int songIndex, float skipTime /*= 0.0f */ )
m_pSongProgress->SetProgress( 0.0f );
}

#ifdef NEO
void CMP3Player::SetVolumeSlider(int value)
{
m_pVolume->SetValue(value);
}

void CMP3Player::SetInGameVolumeSlider(int value)
{
m_pVolumeInGame->SetValue(value);
}

#endif // NEO
void CMP3Player::OnStop()
{
if ( m_bPlaying )
Expand Down Expand Up @@ -1777,8 +1808,8 @@ void CMP3Player::OnTick()
m_pMute->SetSelected(cl_neo_radio_mute.GetBool());
m_pShuffle->SetSelected(cl_neo_radio_shuffle.GetBool());
m_pGamePause->SetSelected(cl_neo_radio_game_pause.GetBool());
m_pVolume->SetValue(cl_neo_radio_volume.GetInt());
m_pVolumeInGame->SetValue(cl_neo_radio_volume_ingame.GetInt());
m_pVolume->SetValue(cl_neo_radio_volume.GetFloat() * 100);
m_pVolumeInGame->SetValue(cl_neo_radio_volume_ingame.GetFloat() * 100);
m_flCurrentVolume = m_pVolume->GetValue();
m_bMuted = m_pMute->IsSelected();
m_bShuffle = m_pShuffle->IsSelected();
Expand All @@ -1803,10 +1834,6 @@ void CMP3Player::OnTick()
if ( volumeChanged )
{
m_flCurrentVolume = newVol;
#ifdef NEO
cl_neo_radio_volume.SetValue(m_pVolume->GetValue());
cl_neo_radio_volume_ingame.SetValue(m_pVolumeInGame->GetValue());
#endif // NEO
}
bool muteChanged = m_bMuted != m_pMute->IsSelected();
if ( muteChanged )
Expand Down Expand Up @@ -1939,17 +1966,9 @@ float CMP3Player::GetIdealVolume()
{
return 0;
}
if (m_bMuted)
{
constexpr float LOWEST_POSSIBLE_VOLUME = MUTED_VOLUME / 100.f;
return LOWEST_POSSIBLE_VOLUME;
}
if (engine->IsInGame() && !engine->IsLevelMainMenuBackground())
{
return (float)m_pVolumeInGame->GetValue() / 100.0f;
}
// player is in the menu
return (float)m_pVolume->GetValue() / 100.0f;

float volume = m_bMuted ? MUTED_VOLUME : (engine->IsInGame() && !engine->IsLevelMainMenuBackground()) ? ((float)m_pVolumeInGame->GetValue() * 0.01f) : ((float)m_pVolume->GetValue() * 0.01f);
return volume;
}

#endif // NEO
Expand Down Expand Up @@ -2467,6 +2486,33 @@ void CMP3Player::OnSliderMoved()
#endif
}

#ifdef NEO
void CMP3Player::OnSliderDragEnd(KeyValues* data)
{
KeyValues* pData = data->GetFirstSubKey();
if (!pData)
{
return;
}
const float newValue = pData->GetInt() * 0.01f;

pData = pData->GetNextKey();
if (!pData)
{
return;
}

if (m_pVolume == pData->GetPtr())
{
cl_neo_radio_volume.SetValue(newValue);
}
else if (m_pVolumeInGame == pData->GetPtr())
{
cl_neo_radio_volume_ingame.SetValue(newValue);
}
}
#endif // NEO

void CMP3Player::LoadPlayList( char const *filename )
{
KeyValues *kv = new KeyValues( "playlist" );
Expand Down
5 changes: 5 additions & 0 deletions src/game/client/mp3player.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ class CMP3Player : public vgui::Frame

MESSAGE_FUNC( OnTreeViewItemSelected, "TreeViewItemSelected" );
MESSAGE_FUNC( OnSliderMoved, "SliderMoved" );
#ifdef NEO
MESSAGE_FUNC_PARAMS(OnSliderDragEnd, "SliderDragEnd", data);
#endif // NEO

void PopulateTree();
void PopulateLists();
Expand All @@ -274,6 +277,8 @@ class CMP3Player : public vgui::Frame
int FindSong( char const *relative );
#ifdef NEO
public:
void SetVolumeSlider(int value);
void SetInGameVolumeSlider(int value);
#endif // NEO
void PlaySong( int songIndex, float skipTime = 0.0f );
#ifdef NEO
Expand Down
2 changes: 1 addition & 1 deletion src/game/shared/neo/weapons/weapon_ghost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void CWeaponGhost::OnPickedUp(CBaseCombatCharacter *pNewOwner)
#ifdef GAME_DLL // NEO NOTE (Adam) Fairly sure the above will never run client side and this whole thing could be surrounded by ifdef GAME_DLL, but I don't want weapons falling through the floor again if im wrong, so just leaving this comment here
EmitSound_t soundParams;
soundParams.m_pSoundName = "HUD.GhostPickUp";
soundParams.m_nChannel = CHAN_USER_BASE;
soundParams.m_nChannel = CHAN_GHOST_PICKUP;
soundParams.m_bWarnOnDirectWaveReference = false;
soundParams.m_bEmitCloseCaption = false;
soundParams.m_SoundLevel = ATTN_TO_SNDLVL(ATTN_NONE);
Expand Down
5 changes: 5 additions & 0 deletions src/public/soundflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ enum
CHAN_VOICE2 = 7,
CHAN_VOICE_BASE = 8, // allocate channel for network voice data
CHAN_USER_BASE = (CHAN_VOICE_BASE+128) // Anything >= this number is allocated to game code.
#ifdef NEO

,CHAN_MP3_PLAYER = CHAN_USER_BASE,
CHAN_GHOST_PICKUP = CHAN_USER_BASE + 1,
#endif // NEO
};

//-----------------------------------------------------------------------------
Expand Down
Loading