From 70e53c4383fd11565e05115ee8d04228a5b6d21f Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 1 Dec 2009 20:08:21 +0000 Subject: [PATCH] fixes for error messages, removed std::string -> replaced by QString --- linux/sound.cpp | 26 +++++------ linux/sound.h | 16 +++---- src/client.cpp | 2 +- src/client.h | 10 ++--- src/clientsettingsdlg.cpp | 2 +- windows/sound.cpp | 90 ++++++++++++++++++++++++++------------- windows/sound.h | 13 +++--- 7 files changed, 95 insertions(+), 64 deletions(-) diff --git a/linux/sound.cpp b/linux/sound.cpp index 6a01135b..586c21e5 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -18,7 +18,7 @@ void CSound::OpenJack() pJackClient = jack_client_open ( "llcon", JackNullOption, &JackStatus ); if ( pJackClient == NULL ) { - throw CGenErr ( "Jack server not running" ); + throw CGenErr ( tr ( "Jack server not running" ) ); } // tell the JACK server to call "process()" whenever @@ -34,8 +34,8 @@ void CSound::OpenJack() // TEST check sample rate, if not correct, just fire error if ( jack_get_sample_rate ( pJackClient ) != SYSTEM_SAMPLE_RATE ) { - throw CGenErr ( "Jack server sample rate is different from " - "required one" ); + throw CGenErr ( tr ( "Jack server sample rate is different from " + "required one" ) ); } // create four ports (two for input, two for output -> stereo) @@ -56,7 +56,7 @@ if ( jack_get_sample_rate ( pJackClient ) != SYSTEM_SAMPLE_RATE ) // tell the JACK server that we are ready to roll if ( jack_activate ( pJackClient ) ) { - throw CGenErr ( "Cannot activate client" ); + throw CGenErr ( tr ( "Cannot activate client" ) ); } // connect the ports, note: you cannot do this before @@ -66,21 +66,21 @@ if ( jack_get_sample_rate ( pJackClient ) != SYSTEM_SAMPLE_RATE ) if ( ( ports = jack_get_ports ( pJackClient, NULL, NULL, JackPortIsPhysical | JackPortIsOutput ) ) == NULL ) { - throw CGenErr ( "Cannot find any physical capture ports" ); + throw CGenErr ( tr ( "Cannot find any physical capture ports" ) ); } if ( !ports[1] ) { - throw CGenErr ( "Cannot find enough physical capture ports" ); + throw CGenErr ( tr ( "Cannot find enough physical capture ports" ) ); } if ( jack_connect ( pJackClient, ports[0], jack_port_name ( input_port_left ) ) ) { - throw CGenErr ( "Cannot connect input ports" ); + throw CGenErr ( tr ( "Cannot connect input ports" ) ); } if ( jack_connect ( pJackClient, ports[1], jack_port_name ( input_port_right ) ) ) { - throw CGenErr ( "Cannot connect input ports" ); + throw CGenErr ( tr ( "Cannot connect input ports" ) ); } free ( ports ); @@ -88,21 +88,21 @@ if ( jack_get_sample_rate ( pJackClient ) != SYSTEM_SAMPLE_RATE ) if ( ( ports = jack_get_ports ( pJackClient, NULL, NULL, JackPortIsPhysical | JackPortIsInput ) ) == NULL ) { - throw CGenErr ( "Cannot find any physical playback ports" ); + throw CGenErr ( tr ( "Cannot find any physical playback ports" ) ); } if ( !ports[1] ) { - throw CGenErr ( "Cannot find enough physical playback ports" ); + throw CGenErr ( tr ( "Cannot find enough physical playback ports" ) ); } if ( jack_connect ( pJackClient, jack_port_name ( output_port_left ), ports[0] ) ) { - throw CGenErr ( "Cannot connect output ports" ); + throw CGenErr ( tr ( "Cannot connect output ports" ) ); } if ( jack_connect ( pJackClient, jack_port_name ( output_port_right ), ports[1] ) ) { - throw CGenErr ( "Cannot connect output ports" ); + throw CGenErr ( tr ( "Cannot connect output ports" ) ); } free ( ports ); @@ -238,6 +238,6 @@ void CSound::shutdownCallback ( void *arg ) { // without a Jack server, our software makes no sense to run, throw // error message - throw CGenErr ( "Jack server was shut down" ); + throw CGenErr ( tr ( "Jack server was shut down" ) ); } #endif // WITH_SOUND diff --git a/linux/sound.h b/linux/sound.h index 02342da5..f0f2b057 100755 --- a/linux/sound.h +++ b/linux/sound.h @@ -50,10 +50,10 @@ public: virtual void Stop(); // not implemented yet, always return one device and default string - int GetNumDev() { return 1; } - std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; } - std::string SetDev ( const int iNewDev ) { return ""; } // dummy - int GetDev() { return 0; } + int GetNumDev() { return 1; } + QString GetDeviceName ( const int iDiD ) { return "wave mapper"; } + QString SetDev ( const int iNewDev ) { return ""; } // dummy + int GetDev() { return 0; } // these variables should be protected but cannot since we want // to access them from the callback function @@ -86,10 +86,10 @@ public: virtual ~CSound() { Close(); } // not used - int GetNumDev() { return 1; } - std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; } - std::string SetDev ( const int iNewDev ) { return ""; } // dummy - int GetDev() { return 0; } + int GetNumDev() { return 1; } + QString GetDeviceName ( const int iDiD ) { return "wave mapper"; } + QString SetDev ( const int iNewDev ) { return ""; } // dummy + int GetDev() { return 0; } // dummy definitions virtual int Init ( const int iNewPrefMonoBufferSize ) { CSoundBase::Init ( iNewPrefMonoBufferSize ); } diff --git a/src/client.cpp b/src/client.cpp index 103b206c..ce50b621 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -241,7 +241,7 @@ QString CClient::SetSndCrdDev ( const int iNewDev ) Sound.Stop(); } - const QString strReturn = Sound.SetDev ( iNewDev ).c_str(); + const QString strReturn = Sound.SetDev ( iNewDev ); // init again because the sound card actual buffer size might // be changed on new device diff --git a/src/client.h b/src/client.h index 44bb2079..c3f627f4 100755 --- a/src/client.h +++ b/src/client.h @@ -123,13 +123,13 @@ public: int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); } - int GetSndCrdNumDev() { return Sound.GetNumDev(); } - std::string GetSndCrdDeviceName ( const int iDiD ) + int GetSndCrdNumDev() { return Sound.GetNumDev(); } + QString GetSndCrdDeviceName ( const int iDiD ) { return Sound.GetDeviceName ( iDiD ); } - QString SetSndCrdDev ( const int iNewDev ); - int GetSndCrdDev() { return Sound.GetDev(); } - void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); } + QString SetSndCrdDev ( const int iNewDev ); + int GetSndCrdDev() { return Sound.GetDev(); } + void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); } void SetSndCrdPrefFrameSizeFactor ( const int iNewFactor ); int GetSndCrdPrefFrameSizeFactor() diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 4db4633f..8f25492a 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -169,7 +169,7 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, cbSoundcard->clear(); for ( int iSndDevIdx = 0; iSndDevIdx < pClient->GetSndCrdNumDev(); iSndDevIdx++ ) { - cbSoundcard->addItem ( pClient->GetSndCrdDeviceName ( iSndDevIdx ).c_str() ); + cbSoundcard->addItem ( pClient->GetSndCrdDeviceName ( iSndDevIdx ) ); } cbSoundcard->setCurrentIndex ( pClient->GetSndCrdDev() ); diff --git a/windows/sound.cpp b/windows/sound.cpp index 8ce84f32..74b4e58c 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -57,9 +57,10 @@ CSound* pSound; /******************************************************************************\ * Common * \******************************************************************************/ -std::string CSound::SetDev ( const int iNewDev ) +QString CSound::SetDev ( const int iNewDev ) { - std::string strReturn = ""; // init with no error + QString strReturn = ""; // init with no error + bool bTryLoadAnyDriver = false; // check if an ASIO driver was already initialized if ( lCurDev >= 0 ) @@ -72,9 +73,9 @@ std::string CSound::SetDev ( const int iNewDev ) ASIOExit(); asioDrivers->removeCurrentDriver(); - const std::string strErrorMessage = LoadAndInitializeDriver ( iNewDev ); + const QString strErrorMessage = LoadAndInitializeDriver ( iNewDev ); - if ( !strErrorMessage.empty() ) + if ( !strErrorMessage.isEmpty() ) { if ( iNewDev != lCurDev ) { @@ -92,7 +93,7 @@ std::string CSound::SetDev ( const int iNewDev ) "have changed to a state which is incompatible to this " "software. The selected audio device could not be used " "because of the following error: " ) ) + - strErrorMessage.c_str() + + strErrorMessage + QString ( tr ( "

Please restart the software." ) ), "Close", 0 ); @@ -115,32 +116,52 @@ std::string CSound::SetDev ( const int iNewDev ) // throw an error that no driver is available -> it does not make // sense to start the llcon software if no audio hardware is // available - if ( !LoadAndInitializeDriver ( iNewDev ).empty() ) + if ( !LoadAndInitializeDriver ( iNewDev ).isEmpty() ) { // loading and initializing the new driver failed, try to find // at least one usable driver - if ( !LoadAndInitializeFirstValidDriver() ) - { - throw CGenErr ( "No usable ASIO audio device " - "(driver) found." ); - } + bTryLoadAnyDriver = true; } } else { // try to find one usable driver (select the first valid driver) - if ( !LoadAndInitializeFirstValidDriver() ) + bTryLoadAnyDriver = true; + } + } + + if ( bTryLoadAnyDriver ) + { + // try to load and initialize any valid driver + QVector vsErrorList = + LoadAndInitializeFirstValidDriver(); + + if ( !vsErrorList.isEmpty() ) + { + // create error message with all details + QString sErrorMessage = tr ( "No usable ASIO audio device " + "(driver) found.

" + "In the following there is a list of all available drivers " + "with the associated error message:"; + + throw CGenErr ( sErrorMessage ); } } return strReturn; } -bool CSound::LoadAndInitializeFirstValidDriver() +QVector CSound::LoadAndInitializeFirstValidDriver() { + QVector vsErrorList; + // load and initialize first valid ASIO driver bool bValidDriverDetected = false; int iCurDriverIdx = 0; @@ -148,23 +169,32 @@ bool CSound::LoadAndInitializeFirstValidDriver() // try all available drivers in the system ("lNumDevs" devices) while ( !bValidDriverDetected && ( iCurDriverIdx < lNumDevs ) ) { - if ( LoadAndInitializeDriver ( iCurDriverIdx ).empty() ) + // try to load and initialize current driver, store error message + const QString strCurError = + LoadAndInitializeDriver ( iCurDriverIdx ); + + vsErrorList.append ( strCurError ); + + if ( strCurError.isEmpty() ) { // initialization was successful bValidDriverDetected = true; // store ID of selected driver lCurDev = iCurDriverIdx; + + // empty error list shows that init was successful + vsErrorList.clear(); } // try next driver iCurDriverIdx++; } - return bValidDriverDetected; + return vsErrorList; } -std::string CSound::LoadAndInitializeDriver ( int iDriverIdx ) +QString CSound::LoadAndInitializeDriver ( int iDriverIdx ) { // first check and correct input parameter if ( iDriverIdx >= lNumDevs ) @@ -179,14 +209,14 @@ std::string CSound::LoadAndInitializeDriver ( int iDriverIdx ) { // clean up and return error string asioDrivers->removeCurrentDriver(); - return "The audio driver could not be initialized."; + return tr ( "The audio driver could not be initialized." ); } // check device capabilities if it fullfills our requirements - const std::string strStat = CheckDeviceCapabilities(); + const QString strStat = CheckDeviceCapabilities(); // store ID of selected driver if initialization was successful - if ( strStat.empty() ) + if ( strStat.isEmpty() ) { lCurDev = iDriverIdx; } @@ -199,7 +229,7 @@ std::string CSound::LoadAndInitializeDriver ( int iDriverIdx ) return strStat; } -std::string CSound::CheckDeviceCapabilities() +QString CSound::CheckDeviceCapabilities() { // This function checks if our required input/output channel // properties are supported by the selected device. If the return @@ -212,8 +242,9 @@ std::string CSound::CheckDeviceCapabilities() ( CanSaRateReturn == ASE_NotPresent ) ) { // return error string - return "The audio device does not support the " - "required sample rate."; + return tr ( "The audio device does not support the " + "required sample rate. The required sample rate is: " ) + + QString().setNum ( SYSTEM_SAMPLE_RATE ) + " Hz"; } // check the number of available channels @@ -224,8 +255,9 @@ std::string CSound::CheckDeviceCapabilities() ( lNumOutChan < NUM_IN_OUT_CHANNELS ) ) { // return error string - return "The audio device does not support the " - "required number of channels."; + return tr ( "The audio device does not support the " + "required number of channels. The required number of channels " + "is: " ) + QString().setNum ( NUM_IN_OUT_CHANNELS ); } // check sample format @@ -249,8 +281,8 @@ std::string CSound::CheckDeviceCapabilities() ( channelInfos[i].type != ASIOSTInt32LSB ) ) { // return error string - return "Required audio sample format not " - "available (16/24/32 bit LSB)."; + return tr ( "Required audio sample format not " + "available (16/24/32 bit LSB)." ); } } @@ -417,7 +449,7 @@ pSound = this; // in case we do not have a driver available, throw error if ( lNumDevs == 0 ) { - throw CGenErr ( "No ASIO audio device (driver) found." ); + throw CGenErr ( tr ( "No ASIO audio device (driver) found." ) ); } asioDrivers->removeCurrentDriver(); @@ -578,7 +610,7 @@ void CSound::bufferSwitch ( long index, ASIOBool processNow ) long CSound::asioMessages ( long selector, long value, void* message, double* opt ) { long ret = 0; - switch(selector) + switch ( selector ) { case kAsioEngineVersion: // return the supported ASIO version of the host application diff --git a/windows/sound.h b/windows/sound.h index cc2feaa0..d6bd2eb4 100755 --- a/windows/sound.h +++ b/windows/sound.h @@ -26,7 +26,6 @@ #define _SOUNDIN_H__9518A621_7F78_11D3_8C0D_EEBF182CF549__INCLUDED_ #include -#include #include #include #include "../src/util.h" @@ -65,16 +64,16 @@ public: virtual void OpenDriverSetup() { ASIOControlPanel(); } int GetNumDev() { return lNumDevs; } - std::string GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; } + QString GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; } - std::string SetDev ( const int iNewDev ); + QString SetDev ( const int iNewDev ); int GetDev() { return lCurDev; } protected: - bool LoadAndInitializeFirstValidDriver(); - std::string LoadAndInitializeDriver ( int iIdx ); - int GetActualBufferSize ( const int iDesiredBufferSizeMono ); - std::string CheckDeviceCapabilities(); + QVector LoadAndInitializeFirstValidDriver(); + QString LoadAndInitializeDriver ( int iIdx ); + int GetActualBufferSize ( const int iDesiredBufferSizeMono ); + QString CheckDeviceCapabilities(); // audio hardware buffer info struct sHWBufferInfo