Skip to content

Commit 4502734

Browse files
committed
bass: expose these two & move GetChannelCount
1 parent 8502434 commit 4502734

5 files changed

Lines changed: 65 additions & 13 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,6 +3545,9 @@ See https://www.un4seen.com/doc/#bass/BASS_ChannelGetData.html<br>
35453545
> [!NOTE]
35463546
> The nSize is limited to 64kb!
35473547
3548+
#### number(channelCount|nil on failure), string(errMsg - nil) IGModAudioChannel:GetChannelCount()
3549+
Returns the number of channels this channel has.<br>
3550+
35483551
#### bool(success), string(errMsg - nil) IGModAudioChannel:SetFX(string fxName, number fxType, number priority, table fxParams)
35493552
fxName - A unique name used for FX so that you can have multiple of the same fx type with unique names you assigned<br>
35503553

@@ -3599,6 +3602,9 @@ See https://www.un4seen.com/doc/#bassmix/BASS_Mixer_ChannelIsActive.html for mor
35993602
Sets the channel's mixer matrix.
36003603
See https://www.un4seen.com/doc/#bassmix/BASS_Mixer_ChannelIsActive.html for more details<br>
36013604

3605+
#### number(channelCount|nil on failure), string(errMsg - nil) IGModAudioChannel:GetMixerChannelCount()
3606+
Returns the number of channels the mixer channel that this channel is attached to has.<br>
3607+
36023608
#### bool IGModAudioChannel:IsSplitter()
36033609
Returns `true` if the channel was created using `bass.CreateSplitChannel`<br>
36043610

source/modules/bass.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,23 @@ LUA_FUNCTION_STATIC(IGModAudioChannel_GetChannelData)
548548
return 2;
549549
}
550550

551+
LUA_FUNCTION_STATIC(IGModAudioChannel_GetChannelCount)
552+
{
553+
IGModAudioChannel* channel = Get_IGModAudioChannel(LUA, 1, true);
554+
555+
const char* pError = nullptr;
556+
int nChannelCount = channel->GetChannelCount(&pError);
557+
if (pError)
558+
{
559+
LUA->PushNil();
560+
LUA->PushString(pError);
561+
} else {
562+
LUA->PushNumber(nChannelCount);
563+
LUA->PushNil();
564+
}
565+
return 2;
566+
}
567+
551568
LUA_FUNCTION_STATIC(IGModAudioChannel_SetFX)
552569
{
553570
IGModAudioChannel* channel = Get_IGModAudioChannel(LUA, 1, true);
@@ -895,6 +912,23 @@ LUA_FUNCTION_STATIC(IGModAudioChannel_SetMixerMatrix)
895912
return 2;
896913
}
897914

915+
LUA_FUNCTION_STATIC(IGModAudioChannel_GetMixerChannelCount)
916+
{
917+
IGModAudioChannel* channel = Get_IGModAudioChannel(LUA, 1, true);
918+
919+
const char* pError = nullptr;
920+
int nChannelCount = channel->GetMixerChannelCount(&pError);
921+
if (pError)
922+
{
923+
LUA->PushNil();
924+
LUA->PushString(pError);
925+
} else {
926+
LUA->PushNumber(nChannelCount);
927+
LUA->PushNil();
928+
}
929+
return 2;
930+
}
931+
898932
LUA_FUNCTION_STATIC(IGModAudioChannel_IsSplitter)
899933
{
900934
IGModAudioChannel* channel = Get_IGModAudioChannel(LUA, 1, true);
@@ -1479,6 +1513,7 @@ void CBassModule::LuaInit(GarrysMod::Lua::ILuaInterface* pLua, bool bServerInit)
14791513
Util::AddFunc(pLua, IGModAudioChannel_GetAttribute, "GetAttribute");
14801514
Util::AddFunc(pLua, IGModAudioChannel_IsAttributeSliding, "IsAttributeSliding");
14811515
Util::AddFunc(pLua, IGModAudioChannel_GetChannelData, "GetChannelData");
1516+
Util::AddFunc(pLua, IGModAudioChannel_GetChannelCount, "GetChannelCount");
14821517

14831518
Util::AddFunc(pLua, IGModAudioChannel_SetFX, "SetFX");
14841519
Util::AddFunc(pLua, IGModAudioChannel_ResetFX, "ResetFX");
@@ -1495,6 +1530,7 @@ void CBassModule::LuaInit(GarrysMod::Lua::ILuaInterface* pLua, bool bServerInit)
14951530
Util::AddFunc(pLua, IGModAudioChannel_RemoveMixerChannel, "RemoveMixerChannel");
14961531
Util::AddFunc(pLua, IGModAudioChannel_GetMixerState, "GetMixerState");
14971532
Util::AddFunc(pLua, IGModAudioChannel_SetMixerMatrix, "SetMixerMatrix");
1533+
Util::AddFunc(pLua, IGModAudioChannel_GetMixerChannelCount, "GetMixerChannelCount");
14981534

14991535
Util::AddFunc(pLua, IGModAudioChannel_IsSplitter, "IsSplitter");
15001536
Util::AddFunc(pLua, IGModAudioChannel_ResetSplitStream, "ResetSplitStream");

source/sourcesdk/IGmod_Audio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class IGModAudioChannel
156156
virtual float GetAttribute( unsigned long nAttribute, const char** pErrorOut ) = 0;
157157
virtual bool IsAttributeSliding( unsigned long nAttribute ) = 0;
158158
virtual unsigned long GetChannelData( void* pBuffer, unsigned long nLength ) = 0;
159+
virtual int GetChannelCount(const char** pErrorOut) = 0;
159160

160161
// FX Stuff, formerly I wanted to expose the IGModAudioFX
161162
// though I did not like the idea of having to manage yet another independent but linked object
@@ -177,7 +178,6 @@ class IGModAudioChannel
177178
virtual void RemoveMixerChannel() = 0;
178179
virtual int GetMixerState() = 0;
179180
virtual const char* SetMatrix(float* pValues, float fTime) = 0;
180-
virtual int GetChannelCount(const char** pErrorOut) = 0;
181181
virtual int GetMixerChannelCount(const char** pErrorOut) = 0;
182182

183183
// Splitter functions

source/sourcesdk/cgmod_audio.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,21 @@ unsigned long CGModAudioChannel::GetChannelData(void* pBuffer, unsigned long nLe
11561156
return BASS_ChannelGetData(m_pHandle, pBuffer, nLength);
11571157
}
11581158

1159+
1160+
int CGModAudioChannel::GetChannelCount(const char** pErrorOut)
1161+
{
1162+
*pErrorOut = nullptr;
1163+
1164+
BASS_CHANNELINFO info;
1165+
if (!BASS_ChannelGetInfo(m_pHandle, &info))
1166+
{
1167+
*pErrorOut = BassErrorToString(BASS_ErrorGetCode());
1168+
return -1;
1169+
}
1170+
1171+
return info.chans;
1172+
}
1173+
11591174
bool CGModAudioChannel::SetFX( const char* pFXName, unsigned long nType, int nPriority, void* pParams, const char** pErrorOut )
11601175
{
11611176
*pErrorOut = nullptr;
@@ -1267,30 +1282,25 @@ int CGModAudioChannel::GetMixerState()
12671282

12681283
const char* CGModAudioChannel::SetMatrix(float* pValues, float fTime)
12691284
{
1285+
if (!func_BASS_Mixer_ChannelSetMatrixEx)
1286+
return "Missing BassMix plugin! (Install it manually!)";
1287+
12701288
if (!func_BASS_Mixer_ChannelSetMatrixEx(m_pHandle, pValues, fTime))
12711289
return BassErrorToString(BASS_ErrorGetCode());
12721290

12731291
return nullptr;
12741292
}
12751293

1276-
int CGModAudioChannel::GetChannelCount(const char** pErrorOut)
1294+
int CGModAudioChannel::GetMixerChannelCount(const char** pErrorOut)
12771295
{
12781296
*pErrorOut = nullptr;
12791297

1280-
BASS_CHANNELINFO info;
1281-
if (!BASS_ChannelGetInfo(m_pHandle, &info))
1298+
if (!func_BASS_Mixer_ChannelGetMixer)
12821299
{
1283-
*pErrorOut = BassErrorToString(BASS_ErrorGetCode());
1300+
*pErrorOut = "Missing BassMix plugin! (Install it manually!)";
12841301
return -1;
12851302
}
12861303

1287-
return info.chans;
1288-
}
1289-
1290-
int CGModAudioChannel::GetMixerChannelCount(const char** pErrorOut)
1291-
{
1292-
*pErrorOut = nullptr;
1293-
12941304
HSTREAM pMixer = func_BASS_Mixer_ChannelGetMixer(m_pHandle);
12951305
if (!pMixer)
12961306
{

source/sourcesdk/cgmod_audio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class CGModAudioChannel : public IGModAudioChannel
180180
virtual float GetAttribute( unsigned long nAttribute, const char** pErrorOut );
181181
virtual bool IsAttributeSliding( unsigned long nAttribute );
182182
virtual unsigned long GetChannelData( void* pBuffer, unsigned long nLength );
183+
virtual int GetChannelCount(const char** pErrorOut);
183184

184185
// FX
185186
virtual bool SetFX( const char* pFXName, unsigned long nType, int nPriority, void* pParams, const char** pErrorOut );
@@ -200,7 +201,6 @@ class CGModAudioChannel : public IGModAudioChannel
200201
virtual void RemoveMixerChannel();
201202
virtual int GetMixerState();
202203
virtual const char* SetMatrix(float* pValues, float fTime);
203-
virtual int GetChannelCount(const char** pErrorOut);
204204
virtual int GetMixerChannelCount(const char** pErrorOut);
205205

206206
// Splitter functions

0 commit comments

Comments
 (0)