Skip to content

Commit

Permalink
Add setSoundLooped and isSoundLooped functions (#657)
Browse files Browse the repository at this point in the history
* setSoundLooped & isSoundLooped

* Remove whitespaces

* Fix isSoundLooped return nil instead false if bad argument

* Update Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp

Co-Authored-By: FileEX <alkom@t.pl>

* Update Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp

Co-Authored-By: FileEX <alkom@t.pl>

* Update Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp

Co-Authored-By: FileEX <alkom@t.pl>

* Update SetLooped function

Added more sound properties e.g volume,playback speed etc.

* Refactored setLooped function

* Add SetLooped into header

* Added SetLooped function

* Update Client/mods/deathmatch/logic/CClientSound.cpp

Co-Authored-By: FileEX <alkom@t.pl>

* Fix

* Update CBassAudio.cpp

* Update Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp

Co-Authored-By: FileEX <alkom@t.pl>

* Update Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp

Co-Authored-By: FileEX <alkom@t.pl>

* Update Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp

Co-Authored-By: FileEX <alkom@t.pl>

* Update CBassAudio.cpp

* Fix typo

* Update CClientSound.h

* Update CLuaAudioDefs.cpp

* Update CLuaAudioDefs.cpp

* Update CClientSound.h

* Update CClientSound.cpp

* Update CBassAudio.cpp

* Update CBassAudio.h

* Update CStaticFunctionDefinitions.cpp

* Update CLuaAudioDefs.cpp

* fix compile

* Fix return

* return lua error

* Fix SetPlayPosition return value

* Remove Set/IsSoundLooped from CStaticFunctionDefinitions

* Update Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp

* Fix CClientSound::SetLooped return value

Co-Authored-By: Qais Patankar <qaisjp@gmail.com>

* Don't check pSound and return error

* Return false in CBassAudio::SetLooped

* Use new Lua argument parser

* Fix indentation

Co-authored-by: Qais Patankar <qaisjp@gmail.com>
Co-authored-by: Marek Kulik <mk.botder@gmail.com>
Co-authored-by: Patrik Juvonen <patrik@scope.studio>
Co-authored-by: Nikita Obrekht <obrekht@gmail.com>
Co-authored-by: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com>
  • Loading branch information
6 people committed Jan 2, 2021
1 parent 6ace45e commit 9588301
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Client/mods/deathmatch/logic/CBassAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,16 @@ void CBassAudio::SetPlaybackSpeed(float fSpeed)
BASS_ChannelSetAttribute(m_pSound, BASS_ATTRIB_FREQ, fSpeed * m_fDefaultFrequency);
}

bool CBassAudio::SetLooped(bool bLoop)
{
if (!m_pSound)
return false;

m_bLoop = bLoop;

return BASS_ChannelFlags(m_pSound, bLoop ? BASS_SAMPLE_LOOP : 0, BASS_SAMPLE_LOOP);
}

void CBassAudio::SetPosition(const CVector& vecPosition)
{
m_vecPosition = vecPosition;
Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CBassAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CBassAudio
bool IsFreed();
float GetPan();
void SetPan(float fPan);
bool SetLooped(bool bLoop);

void DoPulse(const CVector& vecPlayerPosition, const CVector& vecCameraPosition, const CVector& vecLookAt);
void AddQueuedEvent(eSoundEventType type, const SString& strString, double dNumber = 0.0, bool bBool = false, const SString& strError = "");
Expand Down Expand Up @@ -111,7 +112,6 @@ class CBassAudio
const bool m_bStream;
const SString m_strPath;
const bool m_b3D;
const bool m_bLoop;
const bool m_bThrottle;
void* m_pBuffer;
unsigned int m_uiBufferLength;
Expand All @@ -120,6 +120,7 @@ class CBassAudio
DWORD m_pSound;

// Playback state
bool m_bLoop;
bool m_bPaused;
bool m_bReversed;
bool m_bPan;
Expand Down
20 changes: 20 additions & 0 deletions Client/mods/deathmatch/logic/CClientSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,26 @@ void CClientSound::GetVelocity(CVector& vecVelocity)
vecVelocity = m_vecVelocity;
}

bool CClientSound::SetLooped(bool bLoop)
{
if (m_bLoop == bLoop)
return false;

m_bLoop = bLoop;
m_SimulatedPlayPosition.SetLooped(bLoop);

if (!m_pAudio)
return false;

m_pAudio->SetLooped(m_bLoop);
return true;
}

bool CClientSound::IsLooped(void) const
{
return m_bLoop;
}

void CClientSound::SetPaused(bool bPaused)
{
if (m_bPaused != bPaused)
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientSound.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class CClientSound : public CClientEntity
void SetPaused(bool bPaused);
bool IsPaused();

bool SetLooped(bool bLoop);
bool IsLooped() const;

bool SetPlayPosition(double dPosition);
double GetPlayPosition();

Expand Down
16 changes: 16 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*****************************************************************************/

#include "StdInc.h"
#include <lua/CLuaFunctionParser.h>

void CLuaAudioDefs::LoadFunctions()
{
Expand All @@ -34,6 +35,8 @@ void CLuaAudioDefs::LoadFunctions()
{"getSoundPosition", GetSoundPosition},
{"getSoundLength", GetSoundLength},
{"getSoundBufferLength", GetSoundBufferLength},
{"setSoundLooped", ArgumentParser<SetSoundLooped>},
{"isSoundLooped", ArgumentParser<IsSoundLooped>},
{"setSoundPaused", SetSoundPaused},
{"isSoundPaused", IsSoundPaused},
{"setSoundVolume", SetSoundVolume},
Expand Down Expand Up @@ -84,12 +87,14 @@ void CLuaAudioDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "setSpeed", "setSoundSpeed");
lua_classfunction(luaVM, "setVolume", "setSoundVolume");
lua_classfunction(luaVM, "setPaused", "setSoundPaused");
lua_classfunction(luaVM, "setLooped", "setSoundLooped");
lua_classfunction(luaVM, "setPan", "setSoundPan");
lua_classfunction(luaVM, "setPanningEnabled", "setSoundPanningEnabled");
lua_classfunction(luaVM, "setProperties", "setSoundProperties");

lua_classfunction(luaVM, "getLength", "getSoundLength");
lua_classfunction(luaVM, "getBufferLength", "getSoundBufferLength");
lua_classfunction(luaVM, "isLooped", "isSoundLooped");
lua_classfunction(luaVM, "getMetaTags", "getSoundMetaTags");
lua_classfunction(luaVM, "getBPM", "getSoundBPM");
lua_classfunction(luaVM, "getFFTData", "getSoundFFTData");
Expand All @@ -106,6 +111,7 @@ void CLuaAudioDefs::AddClass(lua_State* luaVM)
lua_classvariable(luaVM, "playbackPosition", "setSoundPosition", "getSoundPosition");
lua_classvariable(luaVM, "speed", "setSoundSpeed", "getSoundSpeed");
lua_classvariable(luaVM, "volume", "setSoundVolume", "getSoundVolume");
lua_classvariable(luaVM, "looped", "setSoundLooped", "isSoundLooped");
lua_classvariable(luaVM, "paused", "setSoundPaused", "isSoundPaused");
lua_classvariable(luaVM, "pan", "setSoundPan", "getSoundPan");
lua_classvariable(luaVM, "panningEnabled", "setSoundPanningEnabled", "isSoundPanningEnabled");
Expand Down Expand Up @@ -448,6 +454,16 @@ int CLuaAudioDefs::GetSoundBufferLength(lua_State* luaVM)
return 1;
}

bool CLuaAudioDefs::SetSoundLooped(CClientSound* pSound, bool bLoop)
{
return pSound->SetLooped(bLoop);
}

bool CLuaAudioDefs::IsSoundLooped(CClientSound* pSound)
{
return pSound->IsLooped();
}

int CLuaAudioDefs::SetSoundPaused(lua_State* luaVM)
{
CClientPlayer* pPlayer = NULL;
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class CLuaAudioDefs : public CLuaDefs
LUA_DECLARE(SetSoundPan);
LUA_DECLARE(GetSoundPan);

static bool SetSoundLooped(CClientSound* pSound, bool bLoop);
static bool IsSoundLooped(CClientSound* pSound);

// Radio functions
LUA_DECLARE(SetRadioChannel);
LUA_DECLARE(GetRadioChannel);
Expand Down

0 comments on commit 9588301

Please sign in to comment.