Skip to content

Commit

Permalink
Move sound device config to new config class.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Jul 2, 2023
1 parent 221e30e commit 4253b4f
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 205 deletions.
16 changes: 16 additions & 0 deletions src/config/ConfigurationDataElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ class ConfigurationDataElement
virtual ~ConfigurationDataElement() = default;

const char* getElementName() const;

void setDefaultVal(UnderlyingDataType& val); // useful for migration
UnderlyingDataType& getDefaultVal();

// Allows usage of class as though it were defined directly as UnderlyingDataType.
ConfigurationDataElement<UnderlyingDataType>& operator=(UnderlyingDataType val);
operator UnderlyingDataType();

UnderlyingDataType& get();

private:
const char* elementName_;
UnderlyingDataType data_;
Expand Down Expand Up @@ -63,6 +67,12 @@ UnderlyingDataType& ConfigurationDataElement<UnderlyingDataType>::getDefaultVal(
return default_;
}

template<typename UnderlyingDataType>
void ConfigurationDataElement<UnderlyingDataType>::setDefaultVal(UnderlyingDataType& val)
{
default_ = val;
}

template<typename UnderlyingDataType>
ConfigurationDataElement<UnderlyingDataType>& ConfigurationDataElement<UnderlyingDataType>::operator=(UnderlyingDataType val)
{
Expand All @@ -76,4 +86,10 @@ ConfigurationDataElement<UnderlyingDataType>::operator UnderlyingDataType()
return data_;
}

template<typename UnderlyingDataType>
UnderlyingDataType& ConfigurationDataElement<UnderlyingDataType>::get()
{
return data_;
}

#endif // CONFIGURATION_DATA_ELEMENT_H
36 changes: 36 additions & 0 deletions src/config/FreeDVConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ FreeDVConfiguration::FreeDVConfiguration()
/* Squelch configuration */
, squelchActive("/Audio/SquelchActive", 1)
, squelchLevel("/Audio/SquelchLevel", (int)(SQ_DEFAULT_SNR*2))

/* Sound device configuration */
, soundCard1InDeviceName("/Audio/soundCard1InDeviceName", "none")
, soundCard1InSampleRate("/Audio/soundCard1InSampleRate", -1)
, soundCard1OutDeviceName("/Audio/soundCard1OutDeviceName", "none")
, soundCard1OutSampleRate("/Audio/soundCard1OutSampleRate", -1)
, soundCard2InDeviceName("/Audio/soundCard2InDeviceName", "none")
, soundCard2InSampleRate("/Audio/soundCard2InSampleRate", -1)
, soundCard2OutDeviceName("/Audio/soundCard2OutDeviceName", "none")
, soundCard2OutSampleRate("/Audio/soundCard2OutSampleRate", -1)
{
// empty
}
Expand All @@ -57,6 +67,23 @@ void FreeDVConfiguration::load(wxConfigBase* config)

load_(config, squelchActive);
load_(config, squelchLevel);

// Migration -- grab old sample rates from older FreeDV configuration
int oldSoundCard1SampleRate = config->Read(wxT("/Audio/soundCard1SampleRate"), -1);
int oldSoundCard2SampleRate = config->Read(wxT("/Audio/soundCard2SampleRate"), -1);
soundCard1InSampleRate.setDefaultVal(oldSoundCard1SampleRate);
soundCard1OutSampleRate.setDefaultVal(oldSoundCard1SampleRate);
soundCard2InSampleRate.setDefaultVal(oldSoundCard2SampleRate);
soundCard2OutSampleRate.setDefaultVal(oldSoundCard2SampleRate);

load_(config, soundCard1InDeviceName);
load_(config, soundCard1InSampleRate);
load_(config, soundCard1OutDeviceName);
load_(config, soundCard1OutSampleRate);
load_(config, soundCard2InDeviceName);
load_(config, soundCard2InSampleRate);
load_(config, soundCard2OutDeviceName);
load_(config, soundCard2OutSampleRate);
}

void FreeDVConfiguration::save(wxConfigBase* config)
Expand All @@ -74,5 +101,14 @@ void FreeDVConfiguration::save(wxConfigBase* config)
save_(config, squelchActive);
save_(config, squelchLevel);

save_(config, soundCard1InDeviceName);
save_(config, soundCard1InSampleRate);
save_(config, soundCard1OutDeviceName);
save_(config, soundCard1OutSampleRate);
save_(config, soundCard2InDeviceName);
save_(config, soundCard2InSampleRate);
save_(config, soundCard2OutDeviceName);
save_(config, soundCard2OutSampleRate);

config->Flush();
}
9 changes: 9 additions & 0 deletions src/config/FreeDVConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class FreeDVConfiguration
ConfigurationDataElement<long> squelchActive;
ConfigurationDataElement<long> squelchLevel;

ConfigurationDataElement<wxString> soundCard1InDeviceName;
ConfigurationDataElement<int> soundCard1InSampleRate;
ConfigurationDataElement<wxString> soundCard1OutDeviceName;
ConfigurationDataElement<int> soundCard1OutSampleRate;
ConfigurationDataElement<wxString> soundCard2InDeviceName;
ConfigurationDataElement<int> soundCard2InSampleRate;
ConfigurationDataElement<wxString> soundCard2OutDeviceName;
ConfigurationDataElement<int> soundCard2OutSampleRate;

void load(wxConfigBase* config);
void save(wxConfigBase* config);

Expand Down
111 changes: 49 additions & 62 deletions src/dlg_audiooptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,72 +402,72 @@ int AudioOptsDialog::ExchangeData(int inout)
}

if (g_nSoundCards == 1) {
if (g_verbose) fprintf(stderr," m_soundCard1InSampleRate: %d\n", wxGetApp().m_soundCard1InSampleRate);
if (g_verbose) fprintf(stderr," m_soundCard1InSampleRate: %d\n", wxGetApp().appConfiguration.soundCard1InSampleRate.get());

setTextCtrlIfDevNameValid(m_textCtrlRxIn,
m_listCtrlRxInDevices,
wxGetApp().m_soundCard1InDeviceName);
wxGetApp().appConfiguration.soundCard1InDeviceName);

if (g_verbose) fprintf(stderr," m_soundCard1OutSampleRate: %d\n", wxGetApp().m_soundCard1OutSampleRate);
if (g_verbose) fprintf(stderr," m_soundCard1OutSampleRate: %d\n", wxGetApp().appConfiguration.soundCard1OutSampleRate.get());

setTextCtrlIfDevNameValid(m_textCtrlRxOut,
m_listCtrlRxOutDevices,
wxGetApp().m_soundCard1OutDeviceName);
wxGetApp().appConfiguration.soundCard1OutDeviceName);

if ((m_textCtrlRxIn->GetValue() != "none") && (m_textCtrlRxOut->GetValue() != "none")) {
// Build sample rate dropdown lists
buildListOfSupportedSampleRates(m_cbSampleRateRxIn, wxGetApp().m_soundCard1InDeviceName, AUDIO_IN);
buildListOfSupportedSampleRates(m_cbSampleRateRxOut, wxGetApp().m_soundCard1OutDeviceName, AUDIO_OUT);
buildListOfSupportedSampleRates(m_cbSampleRateRxIn, wxGetApp().appConfiguration.soundCard1InDeviceName, AUDIO_IN);
buildListOfSupportedSampleRates(m_cbSampleRateRxOut, wxGetApp().appConfiguration.soundCard1OutDeviceName, AUDIO_OUT);

m_cbSampleRateRxIn->SetValue(wxString::Format(wxT("%i"), wxGetApp().m_soundCard1InSampleRate));
m_cbSampleRateRxOut->SetValue(wxString::Format(wxT("%i"), wxGetApp().m_soundCard1OutSampleRate));
m_cbSampleRateRxIn->SetValue(wxString::Format(wxT("%i"), wxGetApp().appConfiguration.soundCard1InSampleRate.get()));
m_cbSampleRateRxOut->SetValue(wxString::Format(wxT("%i"), wxGetApp().appConfiguration.soundCard1OutSampleRate.get()));
}

m_textCtrlTxIn->SetValue("none");
m_textCtrlTxOut->SetValue("none");
}

if (g_nSoundCards == 2) {
if (g_verbose) fprintf(stderr," m_soundCard1InSampleRate: %d\n", wxGetApp().m_soundCard1InSampleRate);
if (g_verbose) fprintf(stderr," m_soundCard1InSampleRate: %d\n", wxGetApp().appConfiguration.soundCard1InSampleRate.get());

setTextCtrlIfDevNameValid(m_textCtrlRxIn,
m_listCtrlRxInDevices,
wxGetApp().m_soundCard1InDeviceName);
wxGetApp().appConfiguration.soundCard1InDeviceName);

if (g_verbose) fprintf(stderr," m_soundCard2OutSampleRate: %d\n", wxGetApp().m_soundCard2OutSampleRate);
if (g_verbose) fprintf(stderr," m_soundCard2OutSampleRate: %d\n", wxGetApp().appConfiguration.soundCard2OutSampleRate.get());

setTextCtrlIfDevNameValid(m_textCtrlRxOut,
m_listCtrlRxOutDevices,
wxGetApp().m_soundCard2OutDeviceName);
wxGetApp().appConfiguration.soundCard2OutDeviceName);

if (g_verbose) fprintf(stderr," m_soundCard2InDeviceName: %d\n", wxGetApp().m_soundCard2InSampleRate);
if (g_verbose) fprintf(stderr," m_soundCard2InDeviceName: %d\n", wxGetApp().appConfiguration.soundCard2InSampleRate.get());

setTextCtrlIfDevNameValid(m_textCtrlTxIn,
m_listCtrlTxInDevices,
wxGetApp().m_soundCard2InDeviceName);
wxGetApp().appConfiguration.soundCard2InDeviceName);

if (g_verbose) fprintf(stderr," m_soundCard1OutSampleRate: %d\n", wxGetApp().m_soundCard1OutSampleRate);
if (g_verbose) fprintf(stderr," m_soundCard1OutSampleRate: %d\n", wxGetApp().appConfiguration.soundCard1OutSampleRate.get());

setTextCtrlIfDevNameValid(m_textCtrlTxOut,
m_listCtrlTxOutDevices,
wxGetApp().m_soundCard1OutDeviceName);
wxGetApp().appConfiguration.soundCard1OutDeviceName);

if ((m_textCtrlRxIn->GetValue() != "none") && (m_textCtrlTxOut->GetValue() != "none")) {
// Build sample rate dropdown lists
buildListOfSupportedSampleRates(m_cbSampleRateRxIn, wxGetApp().m_soundCard1InDeviceName, AUDIO_IN);
buildListOfSupportedSampleRates(m_cbSampleRateTxOut, wxGetApp().m_soundCard1OutDeviceName, AUDIO_OUT);
buildListOfSupportedSampleRates(m_cbSampleRateRxIn, wxGetApp().appConfiguration.soundCard1InDeviceName, AUDIO_IN);
buildListOfSupportedSampleRates(m_cbSampleRateTxOut, wxGetApp().appConfiguration.soundCard1OutDeviceName, AUDIO_OUT);

m_cbSampleRateRxIn->SetValue(wxString::Format(wxT("%i"), wxGetApp().m_soundCard1InSampleRate));
m_cbSampleRateTxOut->SetValue(wxString::Format(wxT("%i"), wxGetApp().m_soundCard1OutSampleRate));
m_cbSampleRateRxIn->SetValue(wxString::Format(wxT("%i"), wxGetApp().appConfiguration.soundCard1InSampleRate.get()));
m_cbSampleRateTxOut->SetValue(wxString::Format(wxT("%i"), wxGetApp().appConfiguration.soundCard1OutSampleRate.get()));
}

if ((m_textCtrlTxIn->GetValue() != "none") && (m_textCtrlRxOut->GetValue() != "none")) {
// Build sample rate dropdown lists
buildListOfSupportedSampleRates(m_cbSampleRateTxIn, wxGetApp().m_soundCard2InDeviceName, AUDIO_IN);
buildListOfSupportedSampleRates(m_cbSampleRateRxOut, wxGetApp().m_soundCard2OutDeviceName, AUDIO_OUT);
buildListOfSupportedSampleRates(m_cbSampleRateTxIn, wxGetApp().appConfiguration.soundCard2InDeviceName, AUDIO_IN);
buildListOfSupportedSampleRates(m_cbSampleRateRxOut, wxGetApp().appConfiguration.soundCard2OutDeviceName, AUDIO_OUT);

m_cbSampleRateTxIn->SetValue(wxString::Format(wxT("%i"), wxGetApp().m_soundCard2InSampleRate));
m_cbSampleRateRxOut->SetValue(wxString::Format(wxT("%i"), wxGetApp().m_soundCard2OutSampleRate));
m_cbSampleRateTxIn->SetValue(wxString::Format(wxT("%i"), wxGetApp().appConfiguration.soundCard2InSampleRate.get()));
m_cbSampleRateRxOut->SetValue(wxString::Format(wxT("%i"), wxGetApp().appConfiguration.soundCard2OutSampleRate.get()));
}
}
}
Expand Down Expand Up @@ -537,29 +537,29 @@ int AudioOptsDialog::ExchangeData(int inout)

if (valid_one_card_config) {
g_nSoundCards = 1;
wxGetApp().m_soundCard1InSampleRate = wxAtoi(sampleRate1);
wxGetApp().m_soundCard1OutSampleRate = wxAtoi(sampleRate2);
wxGetApp().appConfiguration.soundCard1InSampleRate = wxAtoi(sampleRate1);
wxGetApp().appConfiguration.soundCard1OutSampleRate = wxAtoi(sampleRate2);

if (g_verbose)
{
fprintf(stderr," m_soundCard1InSampleRate: %d\n", wxGetApp().m_soundCard1InSampleRate);
fprintf(stderr," m_soundCard1OutSampleRate: %d\n", wxGetApp().m_soundCard1OutSampleRate);
fprintf(stderr," m_soundCard1InSampleRate: %d\n", wxGetApp().appConfiguration.soundCard1InSampleRate.get());
fprintf(stderr," m_soundCard1OutSampleRate: %d\n", wxGetApp().appConfiguration.soundCard1OutSampleRate.get());
}
}

if (valid_two_card_config) {
g_nSoundCards = 2;
wxGetApp().m_soundCard1InSampleRate = wxAtoi(sampleRate1);
wxGetApp().m_soundCard2OutSampleRate = wxAtoi(sampleRate2);
wxGetApp().m_soundCard2InSampleRate = wxAtoi(sampleRate3);
wxGetApp().m_soundCard1OutSampleRate = wxAtoi(sampleRate4);
wxGetApp().appConfiguration.soundCard1InSampleRate = wxAtoi(sampleRate1);
wxGetApp().appConfiguration.soundCard2OutSampleRate = wxAtoi(sampleRate2);
wxGetApp().appConfiguration.soundCard2InSampleRate = wxAtoi(sampleRate3);
wxGetApp().appConfiguration.soundCard1OutSampleRate = wxAtoi(sampleRate4);

if (g_verbose)
{
fprintf(stderr," m_soundCard1InSampleRate: %d\n", wxGetApp().m_soundCard1InSampleRate);
fprintf(stderr," m_soundCard2OutSampleRate: %d\n", wxGetApp().m_soundCard2OutSampleRate);
fprintf(stderr," m_soundCard2InSampleRate: %d\n", wxGetApp().m_soundCard2InSampleRate);
fprintf(stderr," m_soundCard1OutSampleRate: %d\n", wxGetApp().m_soundCard1OutSampleRate);
fprintf(stderr," m_soundCard1InSampleRate: %d\n", wxGetApp().appConfiguration.soundCard1InSampleRate.get());
fprintf(stderr," m_soundCard2OutSampleRate: %d\n", wxGetApp().appConfiguration.soundCard2OutSampleRate.get());
fprintf(stderr," m_soundCard2InSampleRate: %d\n", wxGetApp().appConfiguration.soundCard2InSampleRate.get());
fprintf(stderr," m_soundCard1OutSampleRate: %d\n", wxGetApp().appConfiguration.soundCard1OutSampleRate.get());
}
}

Expand All @@ -569,40 +569,27 @@ int AudioOptsDialog::ExchangeData(int inout)

if (valid_one_card_config)
{
wxGetApp().m_soundCard1InDeviceName = m_textCtrlRxIn->GetValue();
wxGetApp().m_soundCard1OutDeviceName = m_textCtrlRxOut->GetValue();
wxGetApp().m_soundCard2InDeviceName = "none";
wxGetApp().m_soundCard2OutDeviceName = "none";
wxGetApp().appConfiguration.soundCard1InDeviceName = m_textCtrlRxIn->GetValue();
wxGetApp().appConfiguration.soundCard1OutDeviceName = m_textCtrlRxOut->GetValue();
wxGetApp().appConfiguration.soundCard2InDeviceName = "none";
wxGetApp().appConfiguration.soundCard2OutDeviceName = "none";
}
else if (valid_two_card_config)
{
wxGetApp().m_soundCard1InDeviceName = m_textCtrlRxIn->GetValue();
wxGetApp().m_soundCard1OutDeviceName = m_textCtrlTxOut->GetValue();
wxGetApp().m_soundCard2InDeviceName = m_textCtrlTxIn->GetValue();
wxGetApp().m_soundCard2OutDeviceName = m_textCtrlRxOut->GetValue();
wxGetApp().appConfiguration.soundCard1InDeviceName = m_textCtrlRxIn->GetValue();
wxGetApp().appConfiguration.soundCard1OutDeviceName = m_textCtrlTxOut->GetValue();
wxGetApp().appConfiguration.soundCard2InDeviceName = m_textCtrlTxIn->GetValue();
wxGetApp().appConfiguration.soundCard2OutDeviceName = m_textCtrlRxOut->GetValue();
}
else
{
wxGetApp().m_soundCard1InDeviceName = "none";
wxGetApp().m_soundCard1OutDeviceName = "none";
wxGetApp().m_soundCard2InDeviceName = "none";
wxGetApp().m_soundCard2OutDeviceName = "none";
wxGetApp().appConfiguration.soundCard1InDeviceName = "none";
wxGetApp().appConfiguration.soundCard1OutDeviceName = "none";
wxGetApp().appConfiguration.soundCard2InDeviceName = "none";
wxGetApp().appConfiguration.soundCard2OutDeviceName = "none";
}

pConfig->Write(wxT("/Audio/soundCard1InDeviceName"), wxGetApp().m_soundCard1InDeviceName);
pConfig->Write(wxT("/Audio/soundCard1InSampleRate"), wxGetApp().m_soundCard1InSampleRate);

pConfig->Write(wxT("/Audio/soundCard1OutDeviceName"), wxGetApp().m_soundCard1OutDeviceName);
pConfig->Write(wxT("/Audio/soundCard1OutSampleRate"), wxGetApp().m_soundCard1OutSampleRate);

pConfig->Write(wxT("/Audio/soundCard2InDeviceName"), wxGetApp().m_soundCard2InDeviceName);
pConfig->Write(wxT("/Audio/soundCard2InSampleRate"), wxGetApp().m_soundCard2InSampleRate);

pConfig->Write(wxT("/Audio/soundCard2OutDeviceName"), wxGetApp().m_soundCard2OutDeviceName);
pConfig->Write(wxT("/Audio/soundCard2OutSampleRate"), wxGetApp().m_soundCard2OutSampleRate);

pConfig->Flush();

wxGetApp().appConfiguration.save(pConfig);
}

return 0;
Expand Down
Loading

0 comments on commit 4253b4f

Please sign in to comment.