Skip to content

Commit

Permalink
Don't insist that selected audio device is working
Browse files Browse the repository at this point in the history
That is, don't immediately try to select a different working device if
the current one fails to work.
  • Loading branch information
npostavs committed Mar 28, 2021
1 parent d5d4691 commit 52eaec6
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 123 deletions.
22 changes: 14 additions & 8 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,21 +526,27 @@ QString CClient::SetSndCrdDev ( const QString strNewDev )

const QString strError = Sound.SetDev ( strNewDev );

// init again because the sound card actual buffer size might
// be changed on new device
Init();
if ( strError.isEmpty() )
{
// init again because the sound card actual buffer size might
// be changed on new device
Init();
}
else
{
bFraSiFactPrefSupported = false;
bFraSiFactDefSupported = false;
bFraSiFactSafeSupported = false;
}

if ( bWasRunning )
{
// restart client
Sound.Start();
}

// in case of an error inform the GUI about it
if ( !strError.isEmpty() )
{
emit SoundDeviceChanged ( strError );
}
// inform the GUI about change in state
emit SoundDeviceChanged ( strError );

return strError;
}
Expand Down
1 change: 1 addition & 0 deletions src/clientdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ void CClientDlg::OnSoundDeviceChanged ( QString strError )
}

// update the settings dialog
ClientSettingsDlg.SetDeviceErrors ( strError );
ClientSettingsDlg.UpdateSoundDeviceChannelSelectionFrame();
}

Expand Down
8 changes: 8 additions & 0 deletions src/clientsettingsdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP,
"panel." ) + TOOLTIP_COM_END_TEXT );
#endif

lblErrors->setText ( pSettings->strLoadErrors );
lblErrors->setWordWrap ( true );

// sound card input/output channel mapping
QString strSndCrdChanMapp = "<b>" + tr ( "Sound Card Channel Mapping" ) + ":</b> " +
tr ( "If the selected sound card device offers more than one "
Expand Down Expand Up @@ -481,6 +484,11 @@ QString CClientSettingsDlg::GenSndCrdBufferDelayString ( const int iFrameSiz
QString().setNum ( iFrameSize ) + strAddText + ")";
}

void CClientSettingsDlg::SetDeviceErrors ( const QString& strError )
{
lblErrors->setText ( strError );
}

void CClientSettingsDlg::UpdateSoundCardFrame()
{
// get current actual buffer size value
Expand Down
1 change: 1 addition & 0 deletions src/clientsettingsdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class CClientSettingsDlg : public CBaseDlg, private Ui_CClientSettingsDlgBase
const CMultiColorLED::ELightColor eOverallDelayLEDColor );

void UpdateDisplay();
void SetDeviceErrors ( const QString& strError );
void UpdateSoundDeviceChannelSelectionFrame();

protected:
Expand Down
4 changes: 4 additions & 0 deletions src/clientsettingsdlgbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblErrors">
</widget>
</item>
<item>
<widget class="QPushButton" name="butDriverSetup">
<property name="text">
Expand Down
9 changes: 1 addition & 8 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,7 @@ void CClientSettings::ReadSettingsFromXML ( const QDomDocument& IniXMLDocument
// sound card selection
const QString strError = pClient->SetSndCrdDev ( FromBase64ToString ( GetIniSetting ( IniXMLDocument, "client", "auddev_base64", "" ) ) );

if ( !strError.isEmpty() )
{
#ifndef HEADLESS
// special case: when settings are loaded no GUI is yet created, therefore
// we have to create a warning message box here directly
QMessageBox::warning ( nullptr, APP_NAME, strError );
#endif
}
strLoadErrors = strError;

// sound card channel mapping settings: make sure these settings are
// set AFTER the sound card device is set, otherwise the settings are
Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class CClientSettings : public CSettings
bool bWindowWasShownProfile;
bool bWindowWasShownConnect;

QString strLoadErrors;
protected:
// No CommandLineOptions used when reading Client inifile
virtual void WriteSettingsToXML ( QDomDocument& IniXMLDocument ) override;
Expand Down
117 changes: 10 additions & 107 deletions src/soundbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ QStringList CSoundBase::GetDevNames()

QStringList slDevNames;

bool currentInList = false;

// put all device names in the string list
for ( int iDev = 0; iDev < lNumDevs; iDev++ )
{
currentInList |= ( strDriverNames[iDev] == strCurDevName );
slDevNames << strDriverNames[iDev];
}

if ( !currentInList )
{
slDevNames << strCurDevName;
}

return slDevNames;
}

Expand All @@ -94,114 +102,9 @@ QString CSoundBase::SetDev ( const QString strDevName )
{
QMutexLocker locker ( &MutexDevProperties );

// init return parameter with "no error"
QString strReturn = "";

// init flag for "load any driver"
bool bTryLoadAnyDriver = false;

// check if an ASIO driver was already initialized
if ( !strCurDevName.isEmpty() )
{
// a device was already been initialized and is used, first clean up
// driver
UnloadCurrentDriver();

const QString strErrorMessage = LoadAndInitializeDriver ( strDevName, false );

if ( !strErrorMessage.isEmpty() )
{
if ( strDevName != strCurDevName )
{
// loading and initializing the new driver failed, go back to
// original driver and create error message
LoadAndInitializeDriver ( strCurDevName, false );

// store error return message
strReturn = QString ( tr ( "The selected audio device could not be used "
"because of the following error: " ) ) + strErrorMessage +
QString ( tr ( " The previous driver will be selected." ) );
}
else
{
// loading and initializing the current driver failed, try to find
// at least one usable driver
bTryLoadAnyDriver = true;
}
}
}
else
{
if ( !strDevName.isEmpty() )
{
// 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
// the first available driver in the system. If this fails, too, we
// throw an error that no driver is available -> it does not make
// sense to start the software if no audio hardware is available.
if ( !LoadAndInitializeDriver ( strDevName, false ).isEmpty() )
{
// loading and initializing the new driver failed, try to find
// at least one usable driver
bTryLoadAnyDriver = true;
}
}
else
{
// try to find one usable driver (select the first valid driver)
bTryLoadAnyDriver = true;
}
}

if ( bTryLoadAnyDriver )
{
// if a driver was previously selected, show a warning message
if ( !strDevName.isEmpty() )
{
strReturn = tr ( "The previously selected audio device "
"is no longer available or the audio driver properties have changed to a state which "
"is incompatible with this software. We now try to find a valid audio device. This new "
"audio device might cause audio feedback. So, before connecting to a server, please "
"check the audio device setting." );
}

// try to load and initialize any valid driver
QVector<QString> vsErrorList = LoadAndInitializeFirstValidDriver();

if ( !vsErrorList.isEmpty() )
{
// create error message with all details
QString sErrorMessage = "<b>" + tr ( "No usable " ) +
strSystemDriverTechniqueName + tr ( " audio device "
"(driver) found." ) + "</b><br><br>" + tr (
"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>";

#ifdef _WIN32
// to be able to access the ASIO driver setup for changing, e.g., the sample rate, we
// offer the user under Windows that we open the driver setups of all registered
// ASIO drivers
sErrorMessage = sErrorMessage + "<br/>" + tr ( "Do you want to open the ASIO driver setups?" );

if ( QMessageBox::Yes == QMessageBox::information ( nullptr, APP_NAME, sErrorMessage, QMessageBox::Yes|QMessageBox::No ) )
{
LoadAndInitializeFirstValidDriver ( true );
}

sErrorMessage = APP_NAME + tr ( " could not be started because of audio interface issues." );
#endif

throw CGenErr ( sErrorMessage );
}
}
strCurDevName = strDevName; // Update current device, even if loading fails.

return strReturn;
return LoadAndInitializeDriver ( strDevName, false );
}

QVector<QString> CSoundBase::LoadAndInitializeFirstValidDriver ( const bool bOpenDriverSetup )
Expand Down

0 comments on commit 52eaec6

Please sign in to comment.