Skip to content

Commit

Permalink
Merge pull request #735 from drowe67/ms-audio-config-no-wipe
Browse files Browse the repository at this point in the history
Avoid modifying the audio device configuration without the user explicitly doing so.
  • Loading branch information
tmiw committed Jul 16, 2024
2 parents 0179173 + 86e9ede commit 7929986
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 76 deletions.
1 change: 1 addition & 0 deletions USER_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes
* Show green line indicating RX frequency. (PR #725)
* Update configuration of the Voice Keyer feature based on user feedback. (PR #730)
* Add monitor volume adjustment. (PR #733)
* Avoid modifying the audio device configuration without the user explicitly doing so. (PR #735)
3. Build system:
* Allow overrriding the version tag when building. (PR #727)
* Update wxWidgets to 3.2.5. (PR #731)
Expand Down
87 changes: 11 additions & 76 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3094,99 +3094,28 @@ bool MainFrame::validateSoundCardSetup()
auto soundCard2InDevice = engine->getAudioDevice(wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName, IAudioEngine::AUDIO_ENGINE_IN, wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate, 1);
auto soundCard2OutDevice = engine->getAudioDevice(wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName, IAudioEngine::AUDIO_ENGINE_OUT, wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate, 1);

wxString failedDeviceName;
if (wxGetApp().appConfiguration.audioConfiguration.soundCard1In.deviceName != "none" && !soundCard1InDevice)
{
wxMessageBox(wxString::Format(
"Your %s device cannot be found and may have been removed from your system. Please go to Tools->Audio Config... to confirm your audio setup.",
wxGetApp().appConfiguration.audioConfiguration.soundCard1In.deviceName.get()), wxT("Sound Device Removed"), wxOK, this);
failedDeviceName = wxGetApp().appConfiguration.audioConfiguration.soundCard1In.deviceName.get();
canRun = false;
}
else if (canRun && wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.deviceName != "none" && !soundCard1OutDevice)
{
wxMessageBox(wxString::Format(
"Your %s device cannot be found and may have been removed from your system. Please go to Tools->Audio Config... to confirm your audio setup.",
wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.deviceName.get()), wxT("Sound Device Removed"), wxOK, this);
failedDeviceName = wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.deviceName.get();
canRun = false;
}
else if (canRun && wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName != "none" && !soundCard2InDevice)
{
wxMessageBox(wxString::Format(
"Your %s device cannot be found and may have been removed from your system. Please go to Tools->Audio Config... to confirm your audio setup.",
wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName.get()), wxT("Sound Device Removed"), wxOK, this);
failedDeviceName = wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName.get();
canRun = false;
}
else if (canRun && wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName != "none" && !soundCard2OutDevice)
{
wxMessageBox(wxString::Format(
"Your %s device cannot be found and may have been removed from your system. Please go to Tools->Audio Config... to confirm your audio setup.",
wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName.get()), wxT("Sound Device Removed"), wxOK, this);
failedDeviceName = wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName.get();
canRun = false;
}

if (!canRun)
{
if (g_nSoundCards == 1)
{
if (!soundCard1OutDevice && defaultOutputDevice.isValid())
{
wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.deviceName = defaultOutputDevice.name;
wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.sampleRate = defaultOutputDevice.defaultSampleRate;
}
else
{
wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.deviceName = "none";
wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.sampleRate = 0;
}
}
else if (g_nSoundCards == 2)
{
if (!soundCard2InDevice && defaultInputDevice.isValid())
{
// If we're not already using the default input device as the radio input device, use that instead.
if (defaultInputDevice.name != wxGetApp().appConfiguration.audioConfiguration.soundCard1In.deviceName)
{
wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName = defaultInputDevice.name;
wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate = defaultInputDevice.defaultSampleRate;
}
else
{
wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName = "none";
wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate = 0;
}
}
else
{
wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName = "none";
wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate = 0;
}

if (!soundCard2OutDevice && defaultOutputDevice.isValid())
{
// If we're not already using the default output device as the radio input device, use that instead.
if (defaultOutputDevice.name != wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.deviceName)
{
wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName = defaultOutputDevice.name;
wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate = defaultOutputDevice.defaultSampleRate;
}
else
{
wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName = "none";
wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate = 0;
}
}
else
{
wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName = "none";
wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate = 0;
}

if (wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName == "none" && wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName == "none")
{
g_nSoundCards = 1;
}
}
}

if (canRun && g_nSoundCards == 0)
{
// Initial setup. Display Easy Setup dialog.
Expand Down Expand Up @@ -3215,6 +3144,12 @@ bool MainFrame::validateSoundCardSetup()
});
canRun = false;
}
else if (!canRun)
{
wxMessageBox(wxString::Format(
"Your %s device cannot be found and may have been removed from your system. Please reattach this device, close this message box and retry. If this fails, go to Tools->Audio Config... to check your settings.",
failedDeviceName), wxT("Sound Device Not Found"), wxOK, this);
}

engine->stop();
engine->setOnEngineError(nullptr, nullptr);
Expand Down

0 comments on commit 7929986

Please sign in to comment.