Skip to content

Commit

Permalink
Allow gamesoundmanager to get/set current music playing params
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Jul 20, 2020
1 parent ca64338 commit 43d7d14
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/Etterna/Singletons/GameSoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ struct SoundPositionSetter
};
vector<SoundPositionSetter> g_PositionsToSet;

// A param to set on a sound
struct MusicParamSetter
{
RageSound* m_psound;
RageSoundParams p;
};
vector<MusicParamSetter> g_ParamsToSet;

void
GameSoundManager::StartMusic(MusicToPlay& ToPlay)
{
Expand Down Expand Up @@ -329,7 +337,8 @@ GameSoundManager::SoundWaiting()
{
return !g_SoundsToPlayOnce.empty() || !g_SoundsToPlayOnceFromDir.empty() ||
!g_SoundsToPlayOnceFromAnnouncer.empty() ||
!g_MusicsToPlay.empty() || !g_PositionsToSet.empty();
!g_MusicsToPlay.empty() || !g_PositionsToSet.empty() ||
!g_ParamsToSet.empty();
}

void
Expand Down Expand Up @@ -405,6 +414,20 @@ GameSoundManager::HandleSetPosition()
}
}

void
GameSoundManager::HandleSetParams()
{
g_Mutex->Lock();
vector<MusicParamSetter> vec = g_ParamsToSet;
g_ParamsToSet.clear();
g_Mutex->Unlock();
for (unsigned i = 0; i < vec.size(); i++) {
CHECKPOINT_M("Setting params for sound.");
// vec[i].m_psound->SetParams(vec[i].p);
g_Playing->m_Music->SetParams(vec[i].p);
}
}

void
GameSoundManager::Flush()
{
Expand Down Expand Up @@ -437,6 +460,7 @@ MusicThread_start(void* p)

soundman->StartQueuedSounds();

soundman->HandleSetParams();
soundman->HandleSetPosition();

if (bFlushing) {
Expand Down Expand Up @@ -732,6 +756,27 @@ GameSoundManager::SetSoundPosition(RageSound* s, float fSeconds)
g_Mutex->Unlock();
}

void
GameSoundManager::SetPlayingMusicParams(RageSoundParams p)
{
// This will replace the params for the music pointer
// So needs to be first filled out by the existing params
// (preferably, unless the intention is to overwrite them)
MusicParamSetter prm;
// prm.m_psound = g_Playing->m_Music;
prm.p = p;
g_Mutex->Lock();
g_ParamsToSet.push_back(prm);
g_Mutex->Broadcast();
g_Mutex->Unlock();
}

const RageSoundParams&
GameSoundManager::GetPlayingMusicParams()
{
return g_Playing->m_Music->GetParams();
}

void
GameSoundManager::PlayMusic(const std::string& sFile,
const TimingData* pTiming,
Expand Down
7 changes: 7 additions & 0 deletions src/Etterna/Singletons/GameSoundManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Etterna/Models/Misc/PlayerNumber.h"
#include "MessageManager.h"

struct RageSoundParams;
class TimingData;
class Screen;
class RageSound;
Expand Down Expand Up @@ -80,13 +81,19 @@ class GameSoundManager : MessageSubscriber
// Meant to avoid blocking the game execution (stutter)
void SetSoundPosition(RageSound* s, float fSeconds);

void SetPlayingMusicParams(RageSoundParams p);

const RageSoundParams& GetPlayingMusicParams();

void StartMusic(MusicToPlay& ToPlay);
void DoPlayOnce(std::string sPath);
void StartQueuedSounds();
void DoPlayOnceFromDir(std::string sPath);
auto SoundWaiting() -> bool;
void HandleSetPosition();

void HandleSetParams();

std::shared_ptr<LuaReference> soundPlayCallback;
unsigned int recentPCMSamplesBufferSize = 1024;
Screen* callbackOwningScreen{ nullptr };
Expand Down

0 comments on commit 43d7d14

Please sign in to comment.