From c3a82ec9cccbe3f8ada472a0afa798566934108c Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sun, 2 Jul 2023 17:58:56 -0700 Subject: [PATCH] Move all remaining config items out of MainApp. --- src/config/FreeDVConfiguration.cpp | 51 ++++++++++++++++++++++++ src/config/FreeDVConfiguration.h | 17 ++++++++ src/dlg_options.cpp | 60 +++++++++++------------------ src/main.cpp | 62 ++++++++---------------------- src/main.h | 18 --------- src/ongui.cpp | 6 +-- src/pipeline/TxRxThread.cpp | 2 +- 7 files changed, 111 insertions(+), 105 deletions(-) diff --git a/src/config/FreeDVConfiguration.cpp b/src/config/FreeDVConfiguration.cpp index 962abb67f..9cbc78225 100644 --- a/src/config/FreeDVConfiguration.cpp +++ b/src/config/FreeDVConfiguration.cpp @@ -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 } @@ -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); @@ -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(); } \ No newline at end of file diff --git a/src/config/FreeDVConfiguration.h b/src/config/FreeDVConfiguration.h index f23618bb6..618a38209 100644 --- a/src/config/FreeDVConfiguration.h +++ b/src/config/FreeDVConfiguration.h @@ -76,6 +76,23 @@ class FreeDVConfiguration : public WxWidgetsConfigStore ConfigurationDataElement quickRecordPath; + ConfigurationDataElement freedv700Clip; + ConfigurationDataElement freedv700TxBPF; + + ConfigurationDataElement noiseSNR; + + ConfigurationDataElement debugConsoleEnabled; // note: Windows only + + ConfigurationDataElement snrSlow; + + ConfigurationDataElement debugVerbose; + ConfigurationDataElement apiVerbose; + + ConfigurationDataElement waterfallColor; + ConfigurationDataElement statsResetTimeSecs; + + ConfigurationDataElement currentFreeDVMode; + virtual void load(wxConfigBase* config) override; virtual void save(wxConfigBase* config) override; }; diff --git a/src/dlg_options.cpp b/src/dlg_options.cpp index 97aba61b8..dfe214778 100644 --- a/src/dlg_options.cpp +++ b/src/dlg_options.cpp @@ -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)); @@ -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 @@ -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); @@ -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. @@ -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(); @@ -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 @@ -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); } } @@ -979,7 +965,7 @@ 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) { @@ -987,14 +973,14 @@ void OptionsDlg::OnFreeDV700Combine(wxScrollEvent& event) { } 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 } diff --git a/src/main.cpp b/src/main.cpp index 4cb67869f..ec3f309f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; @@ -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); @@ -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); @@ -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 @@ -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()) @@ -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); @@ -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(); } @@ -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_(); @@ -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; } @@ -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 ------------------------------------ diff --git a/src/main.h b/src/main.h index cd6774f4e..a92efd8b9 100644 --- a/src/main.h +++ b/src/main.h @@ -181,17 +181,10 @@ class MainApp : public wxApp // PTT Input Serialport *m_pttInSerialPort; - // Options dialog - bool m_snrSlow; - unsigned int m_statsResetTimeSec; - wxRect m_rTopWindow; std::vector m_reporters; - // Waterfall display - int m_waterfallColor; - bool loadConfig(); bool saveConfig(); @@ -205,15 +198,8 @@ class MainApp : public wxApp MainFrame *frame; // 700 options - - bool m_FreeDV700txClip; - bool m_FreeDV700txBPF; bool m_FreeDV700Combine; - // Noise simulation - - int m_noise_snr; - // carrier attenuation bool m_attn_carrier_en; @@ -225,10 +211,6 @@ class MainApp : public wxApp int m_tone_freq_hz; int m_tone_amplitude; - // Windows debug console - - bool m_debug_console; - // debugging 700D audio break up bool m_txRxThreadHighPriority; diff --git a/src/ongui.cpp b/src/ongui.cpp index d8b4a338a..6eb3275b5 100644 --- a/src/ongui.cpp +++ b/src/ongui.cpp @@ -401,9 +401,9 @@ void MainFrame::setsnrBeta(bool snrSlow) //------------------------------------------------------------------------- void MainFrame::OnCheckSNRClick(wxCommandEvent& event) { - wxGetApp().m_snrSlow = m_ckboxSNR->GetValue(); - setsnrBeta(wxGetApp().m_snrSlow); - //printf("m_snrSlow: %d\n", (int)wxGetApp().m_snrSlow); + wxGetApp().appConfiguration.snrSlow = m_ckboxSNR->GetValue(); + setsnrBeta(wxGetApp().appConfiguration.snrSlow); + //printf("m_snrSlow: %d\n", (int)wxGetApp().appConfiguration.snrSlow); } // check for space bar press (only when running) diff --git a/src/pipeline/TxRxThread.cpp b/src/pipeline/TxRxThread.cpp index c277d4663..56af10584 100644 --- a/src/pipeline/TxRxThread.cpp +++ b/src/pipeline/TxRxThread.cpp @@ -338,7 +338,7 @@ void TxRxThread::initializePipeline_() inputSampleRate_, outputSampleRate_, []() { return &g_State; }, []() { return g_channel_noise; }, - []() { return wxGetApp().m_noise_snr; }, + []() { return wxGetApp().appConfiguration.noiseSNR; }, []() { return g_RxFreqOffsetHz; }, []() { return &g_sig_pwr_av; } );