Skip to content

Commit

Permalink
Move all remaining config items out of MainApp.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Jul 3, 2023
1 parent d6bde8a commit c3a82ec
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 105 deletions.
51 changes: 51 additions & 0 deletions src/config/FreeDVConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ FreeDVConfiguration::FreeDVConfiguration()
, multipleReceiveOnSingleThread("/Rig/SingleRxThread", true)

, quickRecordPath("/QuickRecord/SavePath", _(""))

, freedv700Clip("/FreeDV700/txClip", true)
, freedv700TxBPF("/FreeDV700/txBPF", true)

, noiseSNR("/Noise/noise_snr", 2)

, debugConsoleEnabled("/Debug/console", false)

, snrSlow("/Audio/snrSlow", false)

, debugVerbose("/Debug/verbose", false)
, apiVerbose("/Debug/APIverbose", false)

, waterfallColor("/Waterfall/Color", 0)
, statsResetTimeSecs("/Stats/ResetTime", 10)

, currentFreeDVMode("/Audio/mode", 4)
{
// empty
}
Expand Down Expand Up @@ -111,6 +128,23 @@ void FreeDVConfiguration::load(wxConfigBase* config)
load_(config, multipleReceiveEnabled);
load_(config, multipleReceiveOnSingleThread);

load_(config, freedv700Clip);
load_(config, freedv700TxBPF);

load_(config, noiseSNR);

load_(config, debugConsoleEnabled);

load_(config, snrSlow);

load_(config, debugVerbose);
load_(config, apiVerbose);

load_(config, waterfallColor);

load_(config, statsResetTimeSecs);
load_(config, currentFreeDVMode);

auto wxStandardPathObj = wxStandardPaths::Get();
auto documentsDir = wxStandardPathObj.GetDocumentsDir();
quickRecordPath.setDefaultVal(documentsDir);
Expand Down Expand Up @@ -160,5 +194,22 @@ void FreeDVConfiguration::save(wxConfigBase* config)

save_(config, quickRecordPath);

save_(config, freedv700Clip);
save_(config, freedv700TxBPF);

save_(config, noiseSNR);

save_(config, debugConsoleEnabled);

save_(config, snrSlow);

save_(config, debugVerbose);
save_(config, apiVerbose);

save_(config, waterfallColor);

save_(config, statsResetTimeSecs);
save_(config, currentFreeDVMode);

config->Flush();
}
17 changes: 17 additions & 0 deletions src/config/FreeDVConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ class FreeDVConfiguration : public WxWidgetsConfigStore

ConfigurationDataElement<wxString> quickRecordPath;

ConfigurationDataElement<bool> freedv700Clip;
ConfigurationDataElement<bool> freedv700TxBPF;

ConfigurationDataElement<int> noiseSNR;

ConfigurationDataElement<bool> debugConsoleEnabled; // note: Windows only

ConfigurationDataElement<bool> snrSlow;

ConfigurationDataElement<bool> debugVerbose;
ConfigurationDataElement<bool> apiVerbose;

ConfigurationDataElement<int> waterfallColor;
ConfigurationDataElement<unsigned int> statsResetTimeSecs;

ConfigurationDataElement<int> currentFreeDVMode;

virtual void load(wxConfigBase* config) override;
virtual void save(wxConfigBase* config) override;
};
Expand Down
60 changes: 23 additions & 37 deletions src/dlg_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
m_ckboxTestFrame->SetValue(wxGetApp().m_testFrames);

m_ckboxChannelNoise->SetValue(wxGetApp().m_channel_noise);
m_txtNoiseSNR->SetValue(wxString::Format(wxT("%i"),wxGetApp().m_noise_snr));
m_txtNoiseSNR->SetValue(wxString::Format(wxT("%i"),wxGetApp().appConfiguration.noiseSNR.get()));

m_ckboxTone->SetValue(wxGetApp().m_tone);
m_txtToneFreqHz->SetValue(wxString::Format(wxT("%i"),wxGetApp().m_tone_freq_hz));
Expand All @@ -675,12 +675,12 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
m_ckboxVerbose->SetValue(g_verbose);
m_ckboxFreeDVAPIVerbose->SetValue(g_freedv_verbose);

m_ckboxFreeDV700txClip->SetValue(wxGetApp().m_FreeDV700txClip);
m_ckboxFreeDV700txBPF->SetValue(wxGetApp().m_FreeDV700txBPF);
m_ckboxFreeDV700txClip->SetValue(wxGetApp().appConfiguration.freedv700Clip);
m_ckboxFreeDV700txBPF->SetValue(wxGetApp().appConfiguration.freedv700TxBPF);
m_ckboxFreeDV700Combine->SetValue(wxGetApp().m_FreeDV700Combine);

#ifdef __WXMSW__
m_ckboxDebugConsole->SetValue(wxGetApp().m_debug_console);
m_ckboxDebugConsole->SetValue(wxGetApp().appConfiguration.debugConsoleEnabled);
#endif

// General reporting config
Expand All @@ -699,10 +699,10 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
m_ckbox_use_utc_time->SetValue(wxGetApp().appConfiguration.reportingConfiguration.useUTCForReporting);

// Stats reset time
m_statsResetTime->SetValue(wxString::Format(wxT("%i"), wxGetApp().m_statsResetTimeSec));
m_statsResetTime->SetValue(wxString::Format(wxT("%i"), wxGetApp().appConfiguration.statsResetTimeSecs.get()));

// Waterfall color
switch (wxGetApp().m_waterfallColor)
switch (wxGetApp().appConfiguration.waterfallColor)
{
case 1:
m_waterfallColorScheme1->SetValue(false);
Expand All @@ -724,15 +724,15 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)

if (m_waterfallColorScheme1->GetValue())
{
wxGetApp().m_waterfallColor = 0;
wxGetApp().appConfiguration.waterfallColor = 0;
}
else if (m_waterfallColorScheme2->GetValue())
{
wxGetApp().m_waterfallColor = 1;
wxGetApp().appConfiguration.waterfallColor = 1;
}
else if (m_waterfallColorScheme3->GetValue())
{
wxGetApp().m_waterfallColor = 2;
wxGetApp().appConfiguration.waterfallColor = 2;
}

// Update control state based on checkbox state.
Expand Down Expand Up @@ -775,7 +775,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
wxGetApp().m_channel_noise = m_ckboxChannelNoise->GetValue();
long noise_snr;
m_txtNoiseSNR->GetValue().ToLong(&noise_snr);
wxGetApp().m_noise_snr = (int)noise_snr;
wxGetApp().appConfiguration.noiseSNR = (int)noise_snr;
//fprintf(stderr, "noise_snr: %d\n", (int)noise_snr);

wxGetApp().m_tone = m_ckboxTone->GetValue();
Expand All @@ -800,12 +800,12 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
g_verbose = m_ckboxVerbose->GetValue();
g_freedv_verbose = m_ckboxFreeDVAPIVerbose->GetValue();

wxGetApp().m_FreeDV700txClip = m_ckboxFreeDV700txClip->GetValue();
wxGetApp().m_FreeDV700txBPF = m_ckboxFreeDV700txBPF->GetValue();
wxGetApp().appConfiguration.freedv700Clip = m_ckboxFreeDV700txClip->GetValue();
wxGetApp().appConfiguration.freedv700TxBPF = m_ckboxFreeDV700txBPF->GetValue();
wxGetApp().m_FreeDV700Combine = m_ckboxFreeDV700Combine->GetValue();

#ifdef __WXMSW__
wxGetApp().m_debug_console = m_ckboxDebugConsole->GetValue();
wxGetApp().appConfiguration.debugConsoleEnabled = m_ckboxDebugConsole->GetValue();
#endif

// General reporting config
Expand All @@ -826,39 +826,25 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
// Waterfall color
if (m_waterfallColorScheme1->GetValue())
{
wxGetApp().m_waterfallColor = 0;
wxGetApp().appConfiguration.waterfallColor = 0;
}
else if (m_waterfallColorScheme2->GetValue())
{
wxGetApp().m_waterfallColor = 1;
wxGetApp().appConfiguration.waterfallColor = 1;
}
else if (m_waterfallColorScheme3->GetValue())
{
wxGetApp().m_waterfallColor = 2;
wxGetApp().appConfiguration.waterfallColor = 2;
}

// Stats reset time
long resetTime;
m_statsResetTime->GetValue().ToLong(&resetTime);
wxGetApp().m_statsResetTimeSec = resetTime;
wxGetApp().appConfiguration.statsResetTimeSecs = resetTime;

if (storePersistent) {
pConfig->Write(wxT("/FreeDV700/txClip"), wxGetApp().m_FreeDV700txClip);
pConfig->Write(wxT("/FreeDV700/txBPF"), wxGetApp().m_FreeDV700txBPF);

pConfig->Write(wxT("/Noise/noise_snr"), wxGetApp().m_noise_snr);

#ifdef __WXMSW__
pConfig->Write(wxT("/Debug/console"), wxGetApp().m_debug_console);
#endif
pConfig->Write(wxT("/Debug/verbose"), g_verbose);
pConfig->Write(wxT("/Debug/APIverbose"), g_freedv_verbose);

pConfig->Write(wxT("/Stats/ResetTime"), wxGetApp().m_statsResetTimeSec);

// Waterfall configuration
pConfig->Write(wxT("/Waterfall/Color"), wxGetApp().m_waterfallColor);

wxGetApp().appConfiguration.debugVerbose = g_verbose;
wxGetApp().appConfiguration.apiVerbose = g_freedv_verbose;
wxGetApp().appConfiguration.save(pConfig);
}
}
Expand Down Expand Up @@ -979,22 +965,22 @@ void OptionsDlg::OnAttnCarrierEn(wxScrollEvent& event) {
}

void OptionsDlg::OnFreeDV700txClip(wxScrollEvent& event) {
wxGetApp().m_FreeDV700txClip = m_ckboxFreeDV700txClip->GetValue();
wxGetApp().appConfiguration.freedv700Clip = m_ckboxFreeDV700txClip->GetValue();
}

void OptionsDlg::OnFreeDV700Combine(wxScrollEvent& event) {
wxGetApp().m_FreeDV700Combine = m_ckboxFreeDV700Combine->GetValue();
}

void OptionsDlg::OnDebugConsole(wxScrollEvent& event) {
wxGetApp().m_debug_console = m_ckboxDebugConsole->GetValue();
wxGetApp().appConfiguration.debugConsoleEnabled = m_ckboxDebugConsole->GetValue();
#ifdef __WXMSW__
// somewhere to send printfs while developing, causes conmsole to pop up on Windows
if (wxGetApp().m_debug_console) {
if (wxGetApp().appConfiguration.debugConsoleEnabled) {
int ret = AllocConsole();
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
if (g_verbose) fprintf(stderr, "AllocConsole: %d m_debug_console: %d\n", ret, wxGetApp().m_debug_console);
if (g_verbose) fprintf(stderr, "AllocConsole: %d m_debug_console: %d\n", ret, wxGetApp().appConfiguration.debugConsoleEnabled);
}
#endif
}
Expand Down
62 changes: 16 additions & 46 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,21 +414,10 @@ void MainFrame::loadConfiguration_()

// -----------------------------------------------------------------------

bool slow = false; // prevents compile error when using default bool
wxGetApp().m_snrSlow = pConfig->Read("/Audio/snrSlow", slow);

bool t = true; // prevents compile error when using default bool
bool f = false;

wxGetApp().m_FreeDV700txClip = (float)pConfig->Read(wxT("/FreeDV700/txClip"), t);
wxGetApp().m_FreeDV700txBPF = (float)pConfig->Read(wxT("/FreeDV700/txBPF"), t);
wxGetApp().m_FreeDV700Combine = 1;

wxGetApp().m_noise_snr = (float)pConfig->Read(wxT("/Noise/noise_snr"), 2);

wxGetApp().m_debug_console = (float)pConfig->Read(wxT("/Debug/console"), f);
g_verbose = pConfig->Read(wxT("/Debug/verbose"), (long)0);
g_freedv_verbose = pConfig->Read(wxT("/Debug/APIverbose"), (long)0);
g_verbose = wxGetApp().appConfiguration.debugVerbose;
g_freedv_verbose = wxGetApp().appConfiguration.apiVerbose;

wxGetApp().m_attn_carrier_en = 0;
wxGetApp().m_attn_carrier = 0;
Expand All @@ -439,15 +428,9 @@ void MainFrame::loadConfiguration_()

// General reporting parameters
m_cboReportFrequency->SetValue(wxString::Format("%.4f", ((double)wxGetApp().appConfiguration.reportingConfiguration.reportingFrequency)/1000.0/1000.0));

// Waterfall configuration
wxGetApp().m_waterfallColor = (int)pConfig->Read(wxT("/Waterfall/Color"), (int)0); // 0-2

// Time in seconds after losing sync before we reset the stats area
wxGetApp().m_statsResetTimeSec = (int)pConfig->Read(wxT("/Stats/ResetTime"), (int)10);

int defaultMode = 4;
int mode = pConfig->Read(wxT("/Audio/mode"), (long)defaultMode);
int defaultMode = wxGetApp().appConfiguration.currentFreeDVMode.getDefaultVal();
int mode = wxGetApp().appConfiguration.currentFreeDVMode;
setDefaultMode:
if (mode == 0)
m_rb1600->SetValue(1);
Expand Down Expand Up @@ -510,8 +493,8 @@ void MainFrame::loadConfiguration_()

// SNR settings

m_ckboxSNR->SetValue(wxGetApp().m_snrSlow);
setsnrBeta(wxGetApp().m_snrSlow);
m_ckboxSNR->SetValue(wxGetApp().appConfiguration.snrSlow);
setsnrBeta(wxGetApp().appConfiguration.snrSlow);

// Show/hide frequency box based on reporting enablement
m_freqBox->Show(wxGetApp().appConfiguration.reportingConfiguration.reportingEnabled);
Expand Down Expand Up @@ -706,12 +689,12 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent, wxID_ANY, _("FreeDV ")
// Init optional Windows debug console so we can see all those printfs

#ifdef __WXMSW__
if (wxGetApp().m_debug_console || wxGetApp().appConfiguration.firstTimeUse) {
if (wxGetApp().appConfiguration.debugConsoleEnabled || wxGetApp().appConfiguration.firstTimeUse) {
// somewhere to send printfs while developing
int ret = AllocConsole();
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
fprintf(stderr, "AllocConsole: %d m_debug_console: %d\n", ret, wxGetApp().m_debug_console);
fprintf(stderr, "AllocConsole: %d m_debug_console: %d\n", ret, wxGetApp().appConfiguration.debugConsoleEnabled);
}
#endif

Expand Down Expand Up @@ -812,19 +795,6 @@ MainFrame::~MainFrame()
wxGetApp().appConfiguration.squelchLevel = (int)(g_SquelchLevel*2.0);

wxGetApp().appConfiguration.transmitLevel = g_txLevel;

pConfig->Write(wxT("/Audio/snrSlow"), wxGetApp().m_snrSlow);

pConfig->Write(wxT("/FreeDV700/txClip"), wxGetApp().m_FreeDV700txClip);
pConfig->Write(wxT("/Noise/noise_snr"), wxGetApp().m_noise_snr);

pConfig->Write(wxT("/Debug/console"), wxGetApp().m_debug_console);

// Waterfall configuration
pConfig->Write(wxT("/Waterfall/Color"), wxGetApp().m_waterfallColor);

// Time in seconds after losing sync before we reset the stats area
pConfig->Write(wxT("/Stats/ResetTime"), wxGetApp().m_statsResetTimeSec);

int mode;
if (m_rb1600->GetValue())
Expand All @@ -845,9 +815,9 @@ MainFrame::~MainFrame()
if (m_rb2020b->GetValue())
mode = 10;
#endif // defined(FREEDV_MODE_2020B)
pConfig->Write(wxT("/Audio/mode"), mode);

wxGetApp().appConfiguration.save(pConfig);
wxGetApp().appConfiguration.currentFreeDVMode = mode;
wxGetApp().appConfiguration.save(pConfig);

m_togBtnOnOff->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnOnOffUI), NULL, this);
m_togBtnAnalog->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnAnalogClickUI), NULL, this);
Expand Down Expand Up @@ -955,7 +925,7 @@ void MainFrame::OnTimer(wxTimerEvent &evt)
if (m_panelWaterfall->checkDT()) {
m_panelWaterfall->setRxFreq(FDMDV_FCENTRE - g_RxFreqOffsetHz);
m_panelWaterfall->m_newdata = true;
m_panelWaterfall->setColor(wxGetApp().m_waterfallColor);
m_panelWaterfall->setColor(wxGetApp().appConfiguration.waterfallColor);
m_panelWaterfall->Refresh();
}

Expand Down Expand Up @@ -1186,7 +1156,7 @@ void MainFrame::OnTimer(wxTimerEvent &evt)

// Auto-reset stats if we've gone long enough since losing sync.
// NOTE: m_timeSinceSyncLoss is in milliseconds.
if (m_timeSinceSyncLoss >= wxGetApp().m_statsResetTimeSec * 1000)
if (m_timeSinceSyncLoss >= wxGetApp().appConfiguration.statsResetTimeSecs * 1000)
{
resetStats_();

Expand All @@ -1209,7 +1179,7 @@ void MainFrame::OnTimer(wxTimerEvent &evt)
else
{
// Counts the amount of time since losing sync. Once we exceed
// wxGetApp().m_statsResetTimeSec, we will reset the stats.
// wxGetApp().appConfiguration.statsResetTimeSecs, we will reset the stats.
m_timeSinceSyncLoss += _REFRESH_TIMER_PERIOD;
}

Expand Down Expand Up @@ -1378,8 +1348,8 @@ void MainFrame::OnTimer(wxTimerEvent &evt)

// set some run time options (if applicable)
freedvInterface.setRunTimeOptions(
(int)wxGetApp().m_FreeDV700txClip,
(int)wxGetApp().m_FreeDV700txBPF);
(int)wxGetApp().appConfiguration.freedv700Clip,
(int)wxGetApp().appConfiguration.freedv700TxBPF);

// Test Frame Bit Error Updates ------------------------------------

Expand Down
Loading

0 comments on commit c3a82ec

Please sign in to comment.