Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,25 @@ void CClient::SetAudioChannels ( const EAudChanConf eNAudChanConf )
}
}

QString CClient::HandleDeviceChange ( bool bWasRunning, const QString& strError )
{
strDriverLoadErrors = strError;
// init again because the sound card actual buffer size might
// be changed on new device
Init();

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

// inform the GUI about change in state
emit SoundDeviceChanged ( strError );

return strError;
}

QString CClient::SetSndCrdDev ( const QString strNewDev )
{
// if client was running then first
Expand All @@ -482,23 +501,22 @@ 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();
return HandleDeviceChange ( bWasRunning, strError );
}

QString CClient::TryLoadAnyDev()
{
// if client was running then first
// stop it and restart again after new initialization
const bool bWasRunning = Sound.IsRunning();
if ( bWasRunning )
{
// restart client
Sound.Start();
Sound.Stop();
}

// in case of an error inform the GUI about it
if ( !strError.isEmpty() )
{
emit SoundDeviceChanged ( strError );
}
const QString strError = Sound.LoadAndInitializeFirstValidDriver();

return strError;
return HandleDeviceChange ( bWasRunning, strError );
}

void CClient::SetSndCrdLeftInputChannel ( const int iNewChan )
Expand Down Expand Up @@ -608,15 +626,16 @@ void CClient::OnSndCrdReinitRequest ( int iSndCrdResetType )
{
// reinit the driver if requested
// (we use the currently selected driver)
strError = Sound.SetDev ( Sound.GetDev() );
strError = Sound.SetDev ( Sound.GetDev() );
strDriverLoadErrors = strError;
}

// init client object (must always be performed if the driver
// was changed)
Init();
}

if ( bWasRunning )
if ( bWasRunning && strDriverLoadErrors.isEmpty() )
{
// restart client
Sound.Start();
Expand Down Expand Up @@ -719,6 +738,11 @@ void CClient::OnClientIDReceived ( int iChanID )

void CClient::Start()
{
if ( !strDriverLoadErrors.isEmpty() )
{
throw CGenErr ( tr ( "You can't connect because your current audio device configuration isn't working:\n" ) + strDriverLoadErrors );
}

// init object
Init();

Expand Down Expand Up @@ -770,6 +794,14 @@ void CClient::Init()
const int iFraSizeDefault = SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_DEFAULT;
const int iFraSizeSafe = SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_SAFE;

if ( !strDriverLoadErrors.isEmpty() )
{
bFraSiFactPrefSupported = false;
bFraSiFactDefSupported = false;
bFraSiFactSafeSupported = false;
return;
}

#if defined( Q_OS_IOS )
bFraSiFactPrefSupported = true; // to reduce sound init time, because we know it's supported in iOS
bFraSiFactDefSupported = true;
Expand Down
11 changes: 10 additions & 1 deletion src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,14 @@ class CClient : public QObject
// sound card device selection
QStringList GetSndCrdDevNames() { return Sound.GetDevNames(); }

QString TryLoadAnyDev();
QString SetSndCrdDev ( const QString strNewDev );
QString GetSndCrdDev() { return Sound.GetDev(); }
void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); }
void OpenSndCrdDriverSetup()
{
if ( !GetSndCrdDev().isEmpty() )
Sound.OpenDriverSetup();
}

// sound card channel selection
int GetSndCrdNumInputChannels() { return Sound.GetNumInputChannels(); }
Expand Down Expand Up @@ -281,6 +286,8 @@ class CClient : public QObject
// callback function must be static, otherwise it does not work
static void AudioCallback ( CVector<short>& psData, void* arg );

QString HandleDeviceChange ( bool bWasRunning, const QString& strError );

void Init();
void ProcessSndCrdAudioData ( CVector<short>& vecsStereoSndCrd );
void ProcessAudioDataIntern ( CVector<short>& vecsStereoSndCrd );
Expand Down Expand Up @@ -344,6 +351,8 @@ class CClient : public QObject
bool bFraSiFactDefSupported;
bool bFraSiFactSafeSupported;

QString strDriverLoadErrors;

int iMonoBlockSizeSam;
int iStereoBlockSizeSam;

Expand Down
37 changes: 32 additions & 5 deletions src/clientdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
lblGlobalInfoLabel->setStyleSheet ( ".QLabel { background: red; }" );
lblGlobalInfoLabel->hide();

SetErrorMessage ( pNSetP->strLoadErrors );

// prepare update check info label (invisible by default)
lblUpdateCheck->setOpenExternalLinks ( true ); // enables opening a web browser if one clicks on a html link
lblUpdateCheck->setText ( "<font color=\"red\"><b>" + APP_UPGRADE_AVAILABLE_MSG_TEXT.arg ( APP_NAME ).arg ( VERSION ) + "</b></font>" );
Expand Down Expand Up @@ -1041,6 +1043,12 @@ void CClientDlg::OnLocalMuteStateChanged ( int value )
}
}

void CClientDlg::SetErrorMessage ( const QString& message )
{
lblGlobalErrorMessage->setText ( message );
lblGlobalErrorMessage->setVisible ( !message.isEmpty() );
}

void CClientDlg::OnTimerSigMet()
{
// show current level
Expand Down Expand Up @@ -1155,10 +1163,7 @@ void CClientDlg::OnSoundDeviceChanged ( QString strError )
if ( !strError.isEmpty() )
{
// the sound device setup has a problem, disconnect any active connection
if ( pClient->IsRunning() )
{
Disconnect();
}
Disconnect();

// show the error message of the device setup
QMessageBox::critical ( this, APP_NAME, strError, tr ( "Ok" ), nullptr );
Expand All @@ -1176,7 +1181,10 @@ void CClientDlg::OnSoundDeviceChanged ( QString strError )
bDetectFeedback = true;
}

SetErrorMessage ( strError );

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

Expand Down Expand Up @@ -1204,7 +1212,26 @@ void CClientDlg::Connect ( const QString& strSelectedAddress, const QString& str
catch ( const CGenErr& generr )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linux/sound.cpp, android/sound.cpp, ios/sound.mm, src/soundbase.cpp, mac/sound.cpp, windows/sound.cpp - these all throw CGenErr from multiple places.

src/socket.cpp throws the error, too - and it's caught here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you think we should add a subtype of error to distinguish the audio error case?

{
// show error message and return the function
QMessageBox::critical ( this, APP_NAME, generr.GetErrorText(), "Close", nullptr );
QMessageBox msgBox ( QMessageBox::Critical, APP_NAME, generr.GetErrorText(), QMessageBox::NoButton, this );
QPushButton* openSettingsButton = msgBox.addButton ( tr ( "Open Settings" ), QMessageBox::ActionRole );
// See also CClientSettingsDlg::UpdateSoundDeviceChannelSelectionFrame()
QPushButton* autoSelectButton =
( pClient->GetSndCrdDevNames().count() > 1 ) ? msgBox.addButton ( tr ( "Auto Select Device" ), QMessageBox::ActionRole ) : nullptr;
QPushButton* closeButton = msgBox.addButton ( tr ( "Close" ), QMessageBox::AcceptRole );

msgBox.setTextFormat ( Qt::RichText ); // Some error messages are HTML formatted
msgBox.setDefaultButton ( openSettingsButton );
msgBox.setEscapeButton ( closeButton );

msgBox.exec();
if ( msgBox.clickedButton() == openSettingsButton )
{
ShowGeneralSettings ( SETTING_TAB_AUDIONET );
}
else if ( msgBox.clickedButton() == autoSelectButton )
{
ClientSettingsDlg.OnTryLoadAnyDriverClicked();
}
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/clientdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class CClientDlg : public CBaseDlg, private Ui_CClientDlgBase
virtual void dropEvent ( QDropEvent* Event ) { ManageDragNDrop ( Event, false ); }
void UpdateDisplay();

void SetErrorMessage ( const QString& message );

CClientSettingsDlg ClientSettingsDlg;
CChatDlg ChatDlg;
CConnectDlg ConnectDlg;
Expand Down
13 changes: 13 additions & 0 deletions src/clientdlgbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,19 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblGlobalErrorMessage">
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="visible">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>.QLabel { background: red; }</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="sizeConstraint">
Expand Down
26 changes: 25 additions & 1 deletion src/clientsettingsdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet
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 @@ -261,6 +264,8 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet
butDriverSetup->setToolTip ( strSndCardDriverSetupTT );
#endif

butDriverReset->setIcon ( butDriverReset->style()->standardIcon ( QStyle::SP_BrowserReload ) );

// fancy skin
lblSkin->setWhatsThis ( "<b>" + tr ( "Skin" ) + ":</b> " + tr ( "Select the skin to be used for the main window." ) );

Expand Down Expand Up @@ -691,6 +696,8 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet
// Driver Setup button is only available for Windows when JACK is not used
QObject::connect ( butDriverSetup, &QPushButton::clicked, this, &CClientSettingsDlg::OnDriverSetupClicked );
#endif
QObject::connect ( butTryLoadAnyDriver, &QPushButton::clicked, this, &CClientSettingsDlg::OnTryLoadAnyDriverClicked );
QObject::connect ( butDriverReset, &QPushButton::clicked, this, &CClientSettingsDlg::OnDriverResetClicked );

// misc
// sliders
Expand Down Expand Up @@ -785,6 +792,8 @@ QString CClientSettingsDlg::GenSndCrdBufferDelayString ( const int iFrameSize, c
QString().setNum ( iFrameSize ) + strAddText + ")";
}

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

void CClientSettingsDlg::UpdateSoundCardFrame()
{
// get current actual buffer size value
Expand Down Expand Up @@ -837,8 +846,13 @@ void CClientSettingsDlg::UpdateSoundDeviceChannelSelectionFrame()
{
cbxSoundcard->addItem ( strDevName );
}
// Selecting devices automatically only makes sense if there is more than
// one to choose from.
butTryLoadAnyDriver->setVisible ( slSndCrdDevNames.count() > 1 );

cbxSoundcard->setCurrentText ( pClient->GetSndCrdDev() );
const QString& sSndCrdName = pClient->GetSndCrdDev();
cbxSoundcard->setCurrentText ( sSndCrdName );
butDriverSetup->setEnabled ( !sSndCrdName.isEmpty() );

// update input/output channel selection
#if defined( _WIN32 ) || defined( __APPLE__ ) || defined( __MACOSX )
Expand Down Expand Up @@ -903,6 +917,8 @@ void CClientSettingsDlg::SetEnableFeedbackDetection ( bool enable )
void CClientSettingsDlg::OnDriverSetupClicked() { pClient->OpenSndCrdDriverSetup(); }
#endif

void CClientSettingsDlg::OnDriverResetClicked() { pClient->SetSndCrdDev ( pClient->GetSndCrdDev() ); }

void CClientSettingsDlg::OnNetBufValueChanged ( int value )
{
pClient->SetSockBufNumFrames ( value, true );
Expand All @@ -915,6 +931,14 @@ void CClientSettingsDlg::OnNetBufServerValueChanged ( int value )
UpdateJitterBufferFrame();
}

void CClientSettingsDlg::OnTryLoadAnyDriverClicked()
{
pClient->TryLoadAnyDev();

UpdateSoundDeviceChannelSelectionFrame();
UpdateDisplay();
}

void CClientSettingsDlg::OnSoundcardActivated ( int iSndDevIdx )
{
pClient->SetSndCrdDev ( cbxSoundcard->itemText ( iSndDevIdx ) );
Expand Down
3 changes: 3 additions & 0 deletions src/clientsettingsdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class CClientSettingsDlg : public CBaseDlg, private Ui_CClientSettingsDlgBase

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

void SetEnableFeedbackDetection ( bool enable );
Expand Down Expand Up @@ -96,6 +97,8 @@ public slots:
void OnAudioQualityActivated ( int iQualityIdx );
void OnGUIDesignActivated ( int iDesignIdx );
void OnMeterStyleActivated ( int iMeterStyleIdx );
void OnDriverResetClicked();
void OnTryLoadAnyDriverClicked();
void OnLanguageChanged ( QString strLanguage ) { pSettings->strLanguage = strLanguage; }
void OnAliasTextChanged ( const QString& strNewName );
void OnInstrumentActivated ( int iCntryListItem );
Expand Down
50 changes: 36 additions & 14 deletions src/clientsettingsdlgbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,31 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="cbxSoundcard">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_Soundcard">
<item>
<widget class="QComboBox" name="cbxSoundcard">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="butDriverReset">
<property name="toolTip">
<string>Reset Driver</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
Expand All @@ -368,6 +379,17 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblErrors">
</widget>
</item>
<item>
<widget class="QPushButton" name="butTryLoadAnyDriver">
<property name="text">
<string>Auto Select Device</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="butDriverSetup">
<property name="sizePolicy">
Expand Down
Loading