introduce global INVALID_INDEX for more consistent code

This commit is contained in:
Volker Fischer 2020-05-26 09:56:46 +02:00
parent c740a19123
commit 8552863493
8 changed files with 22 additions and 27 deletions

View file

@ -163,7 +163,7 @@ CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData
}
// init device index as not initialized (invalid)
lCurDev = INVALID_SNC_CARD_DEVICE;
lCurDev = INVALID_INDEX;
CurrentAudioInputDeviceID = 0;
CurrentAudioOutputDeviceID = 0;
iNumInChan = 0;
@ -611,12 +611,12 @@ void CSound::UpdateChSelection()
int iSelCHRight, iSelAddCHRight;
// initialize all buffer indexes with an invalid value
iSelInBufferLeft = -1;
iSelInBufferRight = -1;
iSelAddInBufferLeft = -1; // if no additional channel used, this will stay on the invalid value
iSelAddInBufferRight = -1; // if no additional channel used, this will stay on the invalid value
iSelOutBufferLeft = -1;
iSelOutBufferRight = -1;
iSelInBufferLeft = INVALID_INDEX;
iSelInBufferRight = INVALID_INDEX;
iSelAddInBufferLeft = INVALID_INDEX; // if no additional channel used, this will stay on the invalid value
iSelAddInBufferRight = INVALID_INDEX; // if no additional channel used, this will stay on the invalid value
iSelOutBufferLeft = INVALID_INDEX;
iSelOutBufferRight = INVALID_INDEX;
// input
GetSelCHAndAddCH ( iSelInputLeftChannel, iNumInChan, iSelCHLeft, iSelAddCHLeft );

View file

@ -152,10 +152,8 @@ LED bar: lbr
#define AUD_MIX_FADER_MAX 100
#define AUD_MIX_PAN_MAX 100
// maximum number of recognized sound cards installed in the system,
// definition for "no device"
// maximum number of recognized sound cards installed in the system
#define MAX_NUMBER_SOUND_CARDS 129 // e.g. 16 inputs, 8 outputs + default entry (MacOS)
#define INVALID_SNC_CARD_DEVICE -1
// define the maximum number of audio channel for input/output we can store
// channel infos for (and therefore this is the maximum number of entries in
@ -173,7 +171,7 @@ LED bar: lbr
#define LOW_BOUND_SIG_METER ( -50.0 ) // dB
#define UPPER_BOUND_SIG_METER ( 0.0 ) // dB
// Maximum number of connected clients at the server.
// maximum number of connected clients at the server (must not be larger than 256)
#define MAX_NUM_CHANNELS 50 // max number channels for server
// actual number of used channels in the server
@ -239,8 +237,8 @@ LED bar: lbr
"</i></font></div>"
#define _MAXSHORT 32767
#define _MAXBYTE 255 // binary: 11111111
#define _MINSHORT ( -32768 )
#define INVALID_INDEX -1 // define invalid index as a negative value (a valid index must always be >= 0)
#if HAVE_STDINT_H
# include <stdint.h>

View file

@ -353,14 +353,11 @@ void CServerListManager::CentralServerRegisterServer ( const CHostAddress& In
QMutexLocker locker ( &Mutex );
const int iCurServerListSize = ServerList.size();
// define invalid index used as a flag
const int ciInvalidIdx = -1;
// Check if server is already registered.
// The very first list entry must not be checked since
// this is per definition the central server (i.e., this server)
int iSelIdx = ciInvalidIdx; // initialize with an illegal value
int iSelIdx = INVALID_INDEX; // initialize with an illegal value
for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ )
{
if ( ServerList[iIdx].HostAddr == InetAddr )
@ -374,7 +371,7 @@ void CServerListManager::CentralServerRegisterServer ( const CHostAddress& In
}
// if server is not yet registered, we have to create a new entry
if ( iSelIdx == ciInvalidIdx )
if ( iSelIdx == INVALID_INDEX )
{
// check for maximum allowed number of servers in the server list
if ( iCurServerListSize < MAX_NUM_SERVERS_IN_SERVER_LIST )
@ -401,7 +398,7 @@ void CServerListManager::CentralServerRegisterServer ( const CHostAddress& In
}
}
pConnLessProtocol->CreateCLRegisterServerResp ( InetAddr, iSelIdx == ciInvalidIdx
pConnLessProtocol->CreateCLRegisterServerResp ( InetAddr, iSelIdx == INVALID_INDEX
? ESvrRegResult::SRR_CENTRAL_SVR_FULL
: ESvrRegResult::SRR_REGISTERED );
}

View file

@ -189,9 +189,9 @@ void CSettings::Load()
}
else
{
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that
// use "INVALID_INDEX" to tell the sound card driver that
// no device selection was done previously
pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE );
pClient->SetSndCrdDev ( INVALID_INDEX );
}
// sound card channel mapping settings: make sure these settings are

View file

@ -116,7 +116,7 @@ QString CSoundBase::SetDev ( const int iNewDev )
}
// check if an ASIO driver was already initialized
if ( lCurDev != INVALID_SNC_CARD_DEVICE )
if ( lCurDev != INVALID_INDEX )
{
// a device was already been initialized and is used, first clean up
// driver
@ -158,7 +158,7 @@ QString CSoundBase::SetDev ( const int iNewDev )
// init flag for "load any driver"
bool bTryLoadAnyDriver = false;
if ( iNewDev != INVALID_SNC_CARD_DEVICE )
if ( iNewDev != INVALID_INDEX )
{
// This is the first time a driver is to be initialized, we first
// try to load the selected driver, if this fails, we try to load

View file

@ -113,7 +113,7 @@ protected:
}
else
{
iSelAddCHOut = -1; // set it to an invalid number
iSelAddCHOut = INVALID_INDEX; // set it to an invalid number
iSelCHOut = iSelCH;
}
}

View file

@ -212,7 +212,7 @@ template<class TData> int CVector<TData>::StringFiFoWithCompare ( const QString
CVector<QString> vstrTempList ( iVectorSize, "" );
// init with illegal index per definition
int iOldIndex = -1;
int iOldIndex = INVALID_INDEX;
// init temporary list count (may be overwritten later on)
int iTempListCnt = 0;
@ -1249,11 +1249,11 @@ public:
CTimingMeas ( const int iNNMeas, const QString strNFName = "" ) :
iNumMeas ( iNNMeas ), vElapsedTimes ( iNNMeas ), strFileName ( strNFName ) { Reset(); }
void Reset() { iCnt = -1; }
void Reset() { iCnt = INVALID_INDEX; }
void Measure()
{
// exclude the very first measurement (initialization phase)
if ( iCnt == -1 )
if ( iCnt == INVALID_INDEX )
{
iCnt = 0;
}

View file

@ -533,7 +533,7 @@ CSound::CSound ( void (*fpNewCallback) ( CVector<int16_t>& psData, voi
}
// init device index as not initialized (invalid)
lCurDev = INVALID_SNC_CARD_DEVICE;
lCurDev = INVALID_INDEX;
// init channel mapping
ResetChannelMapping();