fixes for error messages, removed std::string -> replaced by QString

This commit is contained in:
Volker Fischer 2009-12-01 20:08:21 +00:00
parent e9820ddcb0
commit 70e53c4383
7 changed files with 95 additions and 64 deletions

View File

@ -18,7 +18,7 @@ void CSound::OpenJack()
pJackClient = jack_client_open ( "llcon", JackNullOption, &JackStatus ); pJackClient = jack_client_open ( "llcon", JackNullOption, &JackStatus );
if ( pJackClient == NULL ) if ( pJackClient == NULL )
{ {
throw CGenErr ( "Jack server not running" ); throw CGenErr ( tr ( "Jack server not running" ) );
} }
// tell the JACK server to call "process()" whenever // 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 // TEST check sample rate, if not correct, just fire error
if ( jack_get_sample_rate ( pJackClient ) != SYSTEM_SAMPLE_RATE ) if ( jack_get_sample_rate ( pJackClient ) != SYSTEM_SAMPLE_RATE )
{ {
throw CGenErr ( "Jack server sample rate is different from " throw CGenErr ( tr ( "Jack server sample rate is different from "
"required one" ); "required one" ) );
} }
// create four ports (two for input, two for output -> stereo) // 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 // tell the JACK server that we are ready to roll
if ( jack_activate ( pJackClient ) ) if ( jack_activate ( pJackClient ) )
{ {
throw CGenErr ( "Cannot activate client" ); throw CGenErr ( tr ( "Cannot activate client" ) );
} }
// connect the ports, note: you cannot do this before // 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, if ( ( ports = jack_get_ports ( pJackClient, NULL, NULL,
JackPortIsPhysical | JackPortIsOutput ) ) == NULL ) JackPortIsPhysical | JackPortIsOutput ) ) == NULL )
{ {
throw CGenErr ( "Cannot find any physical capture ports" ); throw CGenErr ( tr ( "Cannot find any physical capture ports" ) );
} }
if ( !ports[1] ) 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 ) ) ) 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 ) ) ) 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 ); free ( ports );
@ -88,21 +88,21 @@ if ( jack_get_sample_rate ( pJackClient ) != SYSTEM_SAMPLE_RATE )
if ( ( ports = jack_get_ports ( pJackClient, NULL, NULL, if ( ( ports = jack_get_ports ( pJackClient, NULL, NULL,
JackPortIsPhysical | JackPortIsInput ) ) == NULL ) JackPortIsPhysical | JackPortIsInput ) ) == NULL )
{ {
throw CGenErr ( "Cannot find any physical playback ports" ); throw CGenErr ( tr ( "Cannot find any physical playback ports" ) );
} }
if ( !ports[1] ) 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] ) ) 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] ) ) 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 ); free ( ports );
@ -238,6 +238,6 @@ void CSound::shutdownCallback ( void *arg )
{ {
// without a Jack server, our software makes no sense to run, throw // without a Jack server, our software makes no sense to run, throw
// error message // error message
throw CGenErr ( "Jack server was shut down" ); throw CGenErr ( tr ( "Jack server was shut down" ) );
} }
#endif // WITH_SOUND #endif // WITH_SOUND

View File

@ -51,8 +51,8 @@ public:
// not implemented yet, always return one device and default string // not implemented yet, always return one device and default string
int GetNumDev() { return 1; } int GetNumDev() { return 1; }
std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; } QString GetDeviceName ( const int iDiD ) { return "wave mapper"; }
std::string SetDev ( const int iNewDev ) { return ""; } // dummy QString SetDev ( const int iNewDev ) { return ""; } // dummy
int GetDev() { return 0; } int GetDev() { return 0; }
// these variables should be protected but cannot since we want // these variables should be protected but cannot since we want
@ -87,8 +87,8 @@ public:
// not used // not used
int GetNumDev() { return 1; } int GetNumDev() { return 1; }
std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; } QString GetDeviceName ( const int iDiD ) { return "wave mapper"; }
std::string SetDev ( const int iNewDev ) { return ""; } // dummy QString SetDev ( const int iNewDev ) { return ""; } // dummy
int GetDev() { return 0; } int GetDev() { return 0; }
// dummy definitions // dummy definitions

View File

@ -241,7 +241,7 @@ QString CClient::SetSndCrdDev ( const int iNewDev )
Sound.Stop(); 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 // init again because the sound card actual buffer size might
// be changed on new device // be changed on new device

View File

@ -124,7 +124,7 @@ public:
int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); } int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); }
int GetSndCrdNumDev() { return Sound.GetNumDev(); } int GetSndCrdNumDev() { return Sound.GetNumDev(); }
std::string GetSndCrdDeviceName ( const int iDiD ) QString GetSndCrdDeviceName ( const int iDiD )
{ return Sound.GetDeviceName ( iDiD ); } { return Sound.GetDeviceName ( iDiD ); }
QString SetSndCrdDev ( const int iNewDev ); QString SetSndCrdDev ( const int iNewDev );

View File

@ -169,7 +169,7 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent,
cbSoundcard->clear(); cbSoundcard->clear();
for ( int iSndDevIdx = 0; iSndDevIdx < pClient->GetSndCrdNumDev(); iSndDevIdx++ ) for ( int iSndDevIdx = 0; iSndDevIdx < pClient->GetSndCrdNumDev(); iSndDevIdx++ )
{ {
cbSoundcard->addItem ( pClient->GetSndCrdDeviceName ( iSndDevIdx ).c_str() ); cbSoundcard->addItem ( pClient->GetSndCrdDeviceName ( iSndDevIdx ) );
} }
cbSoundcard->setCurrentIndex ( pClient->GetSndCrdDev() ); cbSoundcard->setCurrentIndex ( pClient->GetSndCrdDev() );

View File

@ -57,9 +57,10 @@ CSound* pSound;
/******************************************************************************\ /******************************************************************************\
* Common * * 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 // check if an ASIO driver was already initialized
if ( lCurDev >= 0 ) if ( lCurDev >= 0 )
@ -72,9 +73,9 @@ std::string CSound::SetDev ( const int iNewDev )
ASIOExit(); ASIOExit();
asioDrivers->removeCurrentDriver(); asioDrivers->removeCurrentDriver();
const std::string strErrorMessage = LoadAndInitializeDriver ( iNewDev ); const QString strErrorMessage = LoadAndInitializeDriver ( iNewDev );
if ( !strErrorMessage.empty() ) if ( !strErrorMessage.isEmpty() )
{ {
if ( iNewDev != lCurDev ) if ( iNewDev != lCurDev )
{ {
@ -92,7 +93,7 @@ std::string CSound::SetDev ( const int iNewDev )
"have changed to a state which is incompatible to this " "have changed to a state which is incompatible to this "
"software. The selected audio device could not be used " "software. The selected audio device could not be used "
"because of the following error: <b>" ) ) + "because of the following error: <b>" ) ) +
strErrorMessage.c_str() + strErrorMessage +
QString ( tr ( "</b><br><br>Please restart the software." ) ), QString ( tr ( "</b><br><br>Please restart the software." ) ),
"Close", 0 ); "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 // throw an error that no driver is available -> it does not make
// sense to start the llcon software if no audio hardware is // sense to start the llcon software if no audio hardware is
// available // available
if ( !LoadAndInitializeDriver ( iNewDev ).empty() ) if ( !LoadAndInitializeDriver ( iNewDev ).isEmpty() )
{ {
// loading and initializing the new driver failed, try to find // loading and initializing the new driver failed, try to find
// at least one usable driver // at least one usable driver
if ( !LoadAndInitializeFirstValidDriver() ) bTryLoadAnyDriver = true;
{
throw CGenErr ( "No usable ASIO audio device "
"(driver) found." );
}
} }
} }
else else
{ {
// try to find one usable driver (select the first valid driver) // try to find one usable driver (select the first valid driver)
if ( !LoadAndInitializeFirstValidDriver() ) bTryLoadAnyDriver = true;
{
throw CGenErr ( "No usable ASIO audio device (driver) found." );
} }
} }
if ( bTryLoadAnyDriver )
{
// try to load and initialize any valid driver
QVector<QString> vsErrorList =
LoadAndInitializeFirstValidDriver();
if ( !vsErrorList.isEmpty() )
{
// create error message with all details
QString sErrorMessage = tr ( "<b>No usable ASIO audio device "
"(driver) found.</b><br><br>"
"In the following there is a list of all available drivers "
"with the associated error message:<ul>" );
for ( int i = 0; i < lNumDevs; i++ )
{
sErrorMessage += "<li><b>" + GetDeviceName ( i ) + "</b>: " +
vsErrorList[i] + "</li>";
}
sErrorMessage += "</ul>";
throw CGenErr ( sErrorMessage );
}
} }
return strReturn; return strReturn;
} }
bool CSound::LoadAndInitializeFirstValidDriver() QVector<QString> CSound::LoadAndInitializeFirstValidDriver()
{ {
QVector<QString> vsErrorList;
// load and initialize first valid ASIO driver // load and initialize first valid ASIO driver
bool bValidDriverDetected = false; bool bValidDriverDetected = false;
int iCurDriverIdx = 0; int iCurDriverIdx = 0;
@ -148,23 +169,32 @@ bool CSound::LoadAndInitializeFirstValidDriver()
// try all available drivers in the system ("lNumDevs" devices) // try all available drivers in the system ("lNumDevs" devices)
while ( !bValidDriverDetected && ( iCurDriverIdx < lNumDevs ) ) 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 // initialization was successful
bValidDriverDetected = true; bValidDriverDetected = true;
// store ID of selected driver // store ID of selected driver
lCurDev = iCurDriverIdx; lCurDev = iCurDriverIdx;
// empty error list shows that init was successful
vsErrorList.clear();
} }
// try next driver // try next driver
iCurDriverIdx++; iCurDriverIdx++;
} }
return bValidDriverDetected; return vsErrorList;
} }
std::string CSound::LoadAndInitializeDriver ( int iDriverIdx ) QString CSound::LoadAndInitializeDriver ( int iDriverIdx )
{ {
// first check and correct input parameter // first check and correct input parameter
if ( iDriverIdx >= lNumDevs ) if ( iDriverIdx >= lNumDevs )
@ -179,14 +209,14 @@ std::string CSound::LoadAndInitializeDriver ( int iDriverIdx )
{ {
// clean up and return error string // clean up and return error string
asioDrivers->removeCurrentDriver(); 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 // 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 // store ID of selected driver if initialization was successful
if ( strStat.empty() ) if ( strStat.isEmpty() )
{ {
lCurDev = iDriverIdx; lCurDev = iDriverIdx;
} }
@ -199,7 +229,7 @@ std::string CSound::LoadAndInitializeDriver ( int iDriverIdx )
return strStat; return strStat;
} }
std::string CSound::CheckDeviceCapabilities() QString CSound::CheckDeviceCapabilities()
{ {
// This function checks if our required input/output channel // This function checks if our required input/output channel
// properties are supported by the selected device. If the return // properties are supported by the selected device. If the return
@ -212,8 +242,9 @@ std::string CSound::CheckDeviceCapabilities()
( CanSaRateReturn == ASE_NotPresent ) ) ( CanSaRateReturn == ASE_NotPresent ) )
{ {
// return error string // return error string
return "The audio device does not support the " return tr ( "The audio device does not support the "
"required sample rate."; "required sample rate. The required sample rate is: " ) +
QString().setNum ( SYSTEM_SAMPLE_RATE ) + " Hz";
} }
// check the number of available channels // check the number of available channels
@ -224,8 +255,9 @@ std::string CSound::CheckDeviceCapabilities()
( lNumOutChan < NUM_IN_OUT_CHANNELS ) ) ( lNumOutChan < NUM_IN_OUT_CHANNELS ) )
{ {
// return error string // return error string
return "The audio device does not support the " return tr ( "The audio device does not support the "
"required number of channels."; "required number of channels. The required number of channels "
"is: " ) + QString().setNum ( NUM_IN_OUT_CHANNELS );
} }
// check sample format // check sample format
@ -249,8 +281,8 @@ std::string CSound::CheckDeviceCapabilities()
( channelInfos[i].type != ASIOSTInt32LSB ) ) ( channelInfos[i].type != ASIOSTInt32LSB ) )
{ {
// return error string // return error string
return "Required audio sample format not " return tr ( "Required audio sample format not "
"available (16/24/32 bit LSB)."; "available (16/24/32 bit LSB)." );
} }
} }
@ -417,7 +449,7 @@ pSound = this;
// in case we do not have a driver available, throw error // in case we do not have a driver available, throw error
if ( lNumDevs == 0 ) if ( lNumDevs == 0 )
{ {
throw CGenErr ( "No ASIO audio device (driver) found." ); throw CGenErr ( tr ( "No ASIO audio device (driver) found." ) );
} }
asioDrivers->removeCurrentDriver(); 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 CSound::asioMessages ( long selector, long value, void* message, double* opt )
{ {
long ret = 0; long ret = 0;
switch(selector) switch ( selector )
{ {
case kAsioEngineVersion: case kAsioEngineVersion:
// return the supported ASIO version of the host application // return the supported ASIO version of the host application

View File

@ -26,7 +26,6 @@
#define _SOUNDIN_H__9518A621_7F78_11D3_8C0D_EEBF182CF549__INCLUDED_ #define _SOUNDIN_H__9518A621_7F78_11D3_8C0D_EEBF182CF549__INCLUDED_
#include <windows.h> #include <windows.h>
#include <string>
#include <qmutex.h> #include <qmutex.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include "../src/util.h" #include "../src/util.h"
@ -65,16 +64,16 @@ public:
virtual void OpenDriverSetup() { ASIOControlPanel(); } virtual void OpenDriverSetup() { ASIOControlPanel(); }
int GetNumDev() { return lNumDevs; } 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; } int GetDev() { return lCurDev; }
protected: protected:
bool LoadAndInitializeFirstValidDriver(); QVector<QString> LoadAndInitializeFirstValidDriver();
std::string LoadAndInitializeDriver ( int iIdx ); QString LoadAndInitializeDriver ( int iIdx );
int GetActualBufferSize ( const int iDesiredBufferSizeMono ); int GetActualBufferSize ( const int iDesiredBufferSizeMono );
std::string CheckDeviceCapabilities(); QString CheckDeviceCapabilities();
// audio hardware buffer info // audio hardware buffer info
struct sHWBufferInfo struct sHWBufferInfo