From 6ea531d5847992ca586f6849ead56e5d256ed7a5 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 18 Mar 2004 01:31:34 +0000 Subject: [PATCH] give each RageSound instance a unique ID --- stepmania/src/RageSound.cpp | 15 +++++++-------- stepmania/src/RageSound.h | 5 +++++ stepmania/src/RageSoundManager.cpp | 17 +++++++++++++++++ stepmania/src/RageSoundManager.h | 2 ++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 287ed05c40..51a15d4844 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -75,8 +75,8 @@ RageSound::RageSound() playing = false; databuf.reserve(internal_buffer_size); - /* Register ourselves, so we receive Update()s. */ - SOUNDMAN->all_sounds.insert(this); + /* Register ourself, so we have a unique ID and receive Update()s. */ + ID = SOUNDMAN->RegisterSound( this ); } RageSound::~RageSound() @@ -88,10 +88,8 @@ RageSound::~RageSound() Unload(); - /* Unregister ourselves. */ - SOUNDMAN->lock.Lock(); - SOUNDMAN->all_sounds.erase(this); - SOUNDMAN->lock.Unlock(); + /* Unregister ourself. */ + SOUNDMAN->UnregisterSound( this ); } RageSound::RageSound(const RageSound &cpy): @@ -114,8 +112,9 @@ RageSound::RageSound(const RageSound &cpy): * copy this down here. */ m_sFilePath = cpy.m_sFilePath; - /* Register ourselves, so we receive Update()s. */ - SOUNDMAN->all_sounds.insert(this); + /* Register ourselves, so we receive Update()s. We have a different ID than + * our parent. */ + ID = SOUNDMAN->RegisterSound( this ); } void RageSound::Unload() diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index 0997d136fb..64073fe8d5 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -17,6 +17,7 @@ public: virtual int GetSampleRate() const = 0; virtual RageTimer GetStartTime() const { return RageZeroTimer; } virtual float GetVolume() const = 0; + virtual int GetID() const = 0; virtual CString GetLoadedFilePath() const = 0; }; @@ -106,6 +107,7 @@ public: float GetPlaybackRate() const; RageTimer GetStartTime() const; float GetVolume() const; + int GetID() const { return ID; } void SetParams( const RageSoundParams &p ); const RageSoundParams &GetParams() const { return m_Param; } @@ -152,6 +154,9 @@ private: int64_t stopped_position; bool playing; + /* Unique ID number for this instance of RageSound. */ + int ID; + CString error; int64_t GetPositionSecondsInternal( bool *approximate=NULL ) const; diff --git a/stepmania/src/RageSoundManager.cpp b/stepmania/src/RageSoundManager.cpp index 6f1dfdc325..f097574b07 100644 --- a/stepmania/src/RageSoundManager.cpp +++ b/stepmania/src/RageSoundManager.cpp @@ -88,6 +88,23 @@ void RageSoundManager::Update(float delta) driver->Update(delta); } +/* Register the given sound, and return a unique ID. */ +int RageSoundManager::RegisterSound( RageSound *p ) +{ + LockMut(lock); + + all_sounds.insert( p ); + + static int iID = 0; + return ++iID; +} + +void RageSoundManager::UnregisterSound( RageSound *p ) +{ + LockMut(lock); + all_sounds.erase( p ); +} + float RageSoundManager::GetPlayLatency() const { return driver->GetPlayLatency(); diff --git a/stepmania/src/RageSoundManager.h b/stepmania/src/RageSoundManager.h index 2725c6b5da..c859fa6fe6 100644 --- a/stepmania/src/RageSoundManager.h +++ b/stepmania/src/RageSoundManager.h @@ -38,6 +38,8 @@ public: void StartMixing( RageSoundBase *snd ); /* used by RageSound */ void StopMixing( RageSoundBase *snd ); /* used by RageSound */ int64_t GetPosition( const RageSoundBase *snd ) const; /* used by RageSound */ + int RegisterSound( RageSound *p ); /* used by RageSound */ + void UnregisterSound( RageSound *p ); /* used by RageSound */ float GetPlayLatency() const; int GetDriverSampleRate( int rate ) const; const set &GetPlayingSounds() const { return playing_sounds; }