From 8bbc9adaa3cd9550f49a0b15248545c131c4a4ef Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 7 Dec 2011 20:18:56 +0000 Subject: [PATCH] moved a check from the sound class in the sound base class --- src/soundbase.cpp | 56 ++++++++++++++++++++++++++++------------------- windows/sound.cpp | 13 +++-------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/soundbase.cpp b/src/soundbase.cpp index e309891d..46a099fa 100755 --- a/src/soundbase.cpp +++ b/src/soundbase.cpp @@ -132,11 +132,18 @@ void CSoundBase::run() \******************************************************************************/ QString CSoundBase::SetDev ( const int iNewDev ) { - QString strReturn = ""; // init with no error - bool bTryLoadAnyDriver = false; + // init return parameter with "no error" + QString strReturn = ""; + + // first check if valid input parameter + if ( iNewDev >= lNumDevs ) + { + // we should actually never get here... + return tr ( "Invalid device selection." ); + } // check if an ASIO driver was already initialized - if ( lCurDev >= 0 ) + if ( lCurDev != INVALID_SNC_CARD_DEVICE ) { // a device was already been initialized and is used, first clean up // driver @@ -175,6 +182,9 @@ QString CSoundBase::SetDev ( const int iNewDev ) } else { + // init flag for "load any driver" + bool bTryLoadAnyDriver = false; + if ( iNewDev != INVALID_SNC_CARD_DEVICE ) { // This is the first time a driver is to be initialized, we first @@ -195,31 +205,31 @@ QString CSoundBase::SetDev ( const int iNewDev ) // try to find one usable driver (select the first valid driver) bTryLoadAnyDriver = true; } - } - if ( bTryLoadAnyDriver ) - { - // try to load and initialize any valid driver - QVector vsErrorList = - LoadAndInitializeFirstValidDriver(); - - if ( !vsErrorList.isEmpty() ) + if ( bTryLoadAnyDriver ) { - // create error message with all details - QString sErrorMessage = tr ( "No usable " ) + - strSystemDriverTechniqueName + tr ( " audio device " - "(driver) found.

" - "In the following there is a list of all available drivers " - "with the associated error message:"; + // create error message with all details + QString sErrorMessage = tr ( "No usable " ) + + strSystemDriverTechniqueName + tr ( " audio device " + "(driver) found.

" + "In the following there is a list of all available drivers " + "with the associated error message:"; + + throw CGenErr ( sErrorMessage ); + } } } diff --git a/windows/sound.cpp b/windows/sound.cpp index 0fced374..5e2e00df 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -42,13 +42,6 @@ CSound* pSound; \******************************************************************************/ QString CSound::LoadAndInitializeDriver ( int iDriverIdx ) { - // first check and correct input parameter - if ( iDriverIdx >= lNumDevs ) - { - // we assume here that at least one driver is in the system - iDriverIdx = 0; - } - // load driver loadAsioDriver ( cDriverNames[iDriverIdx] ); if ( ASIOInit ( &driverInfo ) != ASE_OK ) @@ -82,7 +75,7 @@ QString CSound::LoadAndInitializeDriver ( int iDriverIdx ) void CSound::UnloadCurrentDriver() { - // cleanup ASIO stuff + // clean up ASIO stuff ASIOStop(); ASIODisposeBuffers(); ASIOExit(); @@ -439,8 +432,8 @@ CSound::CSound ( void (*fpNewCallback) ( CVector& psData, void* arg ), strDriverNames[i] = cDriverNames[i]; } - // init device index with illegal value to show that driver is not initialized - lCurDev = -1; + // init device index as not initialized (invalid) + lCurDev = INVALID_SNC_CARD_DEVICE; // init channel mapping ResetChannelMapping();