diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 2f42956..703985d 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -77,15 +77,9 @@ AppFrame::AppFrame() : initIcon(); - devInfo = NULL; - deviceChanged.store(false); modemPropertiesUpdated.store(false); - saveDisabled = false; - aboutDlg = nullptr; - - demodTray = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *demodScopeTray = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodTunerTray = new wxBoxSizer(wxHORIZONTAL); @@ -958,7 +952,7 @@ void AppFrame::notifyDeviceChanged() { deviceChanged.store(true); } -void AppFrame::updateDeviceParams() { +void AppFrame::handleUpdateDeviceParams() { if (!deviceChanged.load() || devInfo == nullptr) { return; @@ -2107,9 +2101,7 @@ void AppFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) { void AppFrame::OnIdle(wxIdleEvent& event) { - if (deviceChanged.load()) { - updateDeviceParams(); - } + handleUpdateDeviceParams(); handleTXAntennaChange(); @@ -3057,37 +3049,6 @@ int AppFrame::getViewBandwidth() { } -/* split a string by 'seperator' into a vector of string */ -std::vector str_explode(const std::string &seperator, const std::string &in_str) -{ - std::vector vect_out; - - size_t i = 0, j = 0; - size_t seperator_len = seperator.length(); - size_t str_len = in_str.length(); - - while(i < str_len) - { - j = in_str.find_first_of(seperator,i); - - if (j == std::string::npos && i < str_len) { - j = str_len; - } - - if (j == std::string::npos) { - break; - } - - vect_out.push_back(in_str.substr(i,j-i)); - - i = j; - - i+=seperator_len; - } - - return vect_out; -} - void AppFrame::setStatusText(wxWindow* window, std::string statusText) { GetStatusBar()->SetStatusText(statusText); if (wxGetApp().getConfig()->getShowTips()) { diff --git a/src/AppFrame.h b/src/AppFrame.h index 8f0ed13..5e8c187 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -30,6 +30,283 @@ #include "DemodulatorThread.h" #include + +#ifdef USE_HAMLIB +class PortSelectorDialog; +#endif + +// Define a new frame type +class AppFrame: public wxFrame { +public: + AppFrame(); + ~AppFrame(); + + void initDeviceParams(SDRDeviceInfo *devInfo); + + FFTVisualDataThread *getWaterfallDataThread(); + WaterfallCanvas *getWaterfallCanvas(); + SpectrumCanvas *getSpectrumCanvas(); + + void notifyUpdateModemProperties(); + void setMainWaterfallFFTSize(int fftSize); + void setScopeDeviceName(std::string deviceName); + + int OnGlobalKeyDown(wxKeyEvent &event); + int OnGlobalKeyUp(wxKeyEvent &event); + + void setWaterfallLinesPerSecond(int lps); + void setSpectrumAvgSpeed(double avg); + + FrequencyDialog::FrequencyDialogTarget getFrequencyDialogTarget(); + void refreshGainUI(); + void setViewState(long long center_freq, int bandwidth); + void setViewState(); + + long long getViewCenterFreq(); + int getViewBandwidth(); + bool isUserDemodBusy(); + + BookmarkView *getBookmarkView(); + void disableSave(bool state); + + //call this in case the main UI is not + //the origin of device changes / sample rate by operator, + //and must be notified back to update its UI elements + //(ex: SDR Devices dialog changing the configuration) + void notifyDeviceChanged(); + +#ifdef _WIN32 + bool canFocus(); +#endif + //set tooltip to window + void setStatusText(wxWindow* window, std::string statusText); + void setStatusText(std::string statusText, int value); + + +#ifdef USE_HAMLIB + void setRigControlPort(std::string portName); + void dismissRigControlPortDialog(); +#endif + + +private: + /*** + * UI Elements + */ + ScopeCanvas *scopeCanvas; + SpectrumCanvas *spectrumCanvas, *demodSpectrumCanvas; + WaterfallCanvas *waterfallCanvas, *demodWaterfallCanvas; + TuningCanvas *demodTuner; + MeterCanvas *demodSignalMeter, *demodGainMeter, *spectrumAvgMeter, *waterfallSpeedMeter; + ModeSelectorCanvas *demodModeSelector, *demodMuteButton, *peakHoldButton, *soloModeButton, *deltaLockButton; + GainCanvas *gainCanvas; + BookmarkView *bookmarkView; + + wxSizerItem *gainSizerItem, *gainSpacerItem; + wxSplitterWindow *mainVisSplitter, *mainSplitter, *bookmarkSplitter; + + wxBoxSizer *demodTray; + + //Use a raw pointer here to prevent a dangling reference + DemodulatorInstance* activeDemodulator; + + /*** + * Menus + */ + wxMenuBar *menuBar = nullptr; + + wxMenu *fileMenu = nullptr; + + wxMenu *settingsMenu = nullptr; + wxMenuItem *showTipMenuItem; + wxMenuItem *iqSwapMenuItem = nullptr; + wxMenuItem *agcMenuItem = nullptr; + + wxMenu *sampleRateMenu = nullptr; + + wxMenu *displayMenu = nullptr; + wxMenuItem *hideBookmarksItem; + + wxMenu *recordingMenu = nullptr; + + //depending on context, maps the item id to wxMenuItem*, + //OR the submenu item id to its parent wxMenuItem*. + std::map sampleRateMenuItems; + std::map antennaMenuItems; + std::map settingsMenuItems; + std::map performanceMenuItems; + std::map audioSampleRateMenuItems; + std::map recordingMenuItems; + + + /*** + * Waterfall Data Thread + */ + FFTVisualDataThread *waterfallDataThread; + std::thread *t_FFTData; + + + /*** + * Active Settings + */ + bool saveDisabled = false; + + std::string currentSessionFile; + std::string currentBookmarkFile; + + SoapySDR::ArgInfoList settingArgs; + int settingsIdMax; + + std::vector sampleRates; + long manualSampleRate = -1; + + SDRDeviceInfo *devInfo = nullptr; + std::atomic_bool deviceChanged; + + ModemProperties *modemProps; + std::atomic_bool modemPropertiesUpdated; + + std::vector antennaNames; + std::string currentTXantennaName; + + AboutDialog *aboutDlg = nullptr; + std::string lastToolTip; + +#ifdef ENABLE_DIGITAL_LAB + ModeSelectorCanvas *demodModeSelectorAdv; +#endif + + + /*** + * wx Events + */ + void OnMenu(wxCommandEvent& event); + void OnClose(wxCloseEvent& event); + void OnIdle(wxIdleEvent& event); + void OnDoubleClickSash(wxSplitterEvent& event); + void OnUnSplit(wxSplitterEvent& event); + void OnAboutDialogClose(wxCommandEvent& event); + void OnNewWindow(wxCommandEvent& event); + + /** + * Session Management + */ + void saveSession(std::string fileName); + bool loadSession(std::string fileName); + + /** + * Keyboard handlers + */ + void gkNudgeLeft(DemodulatorInstancePtr demod, int snap); + void gkNudgeRight(DemodulatorInstancePtr demod, int snap); + + void toggleActiveDemodRecording(); + void toggleAllActiveDemodRecording(); + + /** + * UI init functions + */ + ModeSelectorCanvas *makeModemSelectorPanel(wxWindow *parent, const wxGLAttributes &attribList); + WaterfallCanvas *makeWaterfallCanvas(wxWindow *parent, const wxGLAttributes &attribList); + SpectrumCanvas *makeDemodSpectrumCanvas(wxWindow *parent, const wxGLAttributes &attribList); + MeterCanvas *makeSignalMeter(wxWindow *parent, const wxGLAttributes &attribList); + ModeSelectorCanvas *makeDeltaLockButton(wxWindow *parent, const wxGLAttributes &attribList); + TuningCanvas *makeModemTuner(wxWindow *parent, const wxGLAttributes &attribList); + MeterCanvas *makeModemGainMeter(wxWindow *parent, const wxGLAttributes &attribList); + ModeSelectorCanvas *makeSoloModeButton(wxWindow *parent, const wxGLAttributes &attribList); + ModeSelectorCanvas *makeModemMuteButton(wxWindow *parent, const wxGLAttributes &attribList); + ModeSelectorCanvas *makePeakHoldButton(wxWindow *parent, const wxGLAttributes &attribList); + SpectrumCanvas *makeSpectrumCanvas(wxWindow *parent, const wxGLAttributes &attribList); + MeterCanvas *makeSpectrumAvgMeter(wxWindow *parent, const wxGLAttributes &attribList); + WaterfallCanvas *makeWaterfall(wxWindow *parent, const wxGLAttributes &attribList); + MeterCanvas *makeWaterfallSpeedMeter(wxWindow *parent, const wxGLAttributes &attribList); + ScopeCanvas *makeScopeCanvas(wxPanel *parent, const wxGLAttributes &attribList); + ModeSelectorCanvas *makeModemAdvSelectorPanel(wxPanel *parent, const wxGLAttributes &attribList); + ModemProperties *makeModemProperties(wxPanel *parent); + + void initConfigurationSettings(); + void initMenuBar(); + void initIcon(); + + wxMenu *makeFileMenu(); + wxMenu *makeAudioSampleRateMenu(); + wxMenu *makeDisplayMenu(); + wxMenu *makeRecordingMenu(); + void updateRecordingMenu(); + + wxString getSettingsLabel(const std::string& settingsName, + const std::string& settingsValue, + const std::string& settingsSuffix = ""); + + + /** + * Menu Action Handlers + */ + //actionXXXX manage menu actions, return true if the event has been + //treated. + bool actionOnMenuAbout(wxCommandEvent& event); + bool actionOnMenuReset(wxCommandEvent& event); + bool actionOnMenuSettings(wxCommandEvent& event); + bool actionOnMenuAGC(wxCommandEvent& event); + bool actionOnMenuSampleRate(wxCommandEvent& event); + bool actionOnMenuAudioSampleRate(wxCommandEvent& event); + bool actionOnMenuDisplay(wxCommandEvent& event); + bool actionOnMenuLoadSave(wxCommandEvent& event); + bool actionOnMenuRecording(wxCommandEvent& event); + bool actionOnMenuRig(wxCommandEvent& event); + + /** + * UI Action Handlers + */ + void handleUpdateDeviceParams(); + void handleTXAntennaChange(); + void handleCurrentModem(); + void handleModeSelector(); + void handleGainMeter(); + void handleDemodWaterfallSpectrum(); + void handleSpectrumWaterfall(); + void handleMuteButton(); + void handleScopeProcessor(); + void handleScopeSpectrumProcessors(); + void handleModemProperties(); + void handlePeakHold(); + + + /** + * Hamlib/Rig specific + */ +#ifdef USE_HAMLIB + wxMenu *rigMenu; + wxMenuItem *rigEnableMenuItem; + wxMenuItem *rigPortMenuItem; + wxMenuItem *rigControlMenuItem; + wxMenuItem *rigFollowMenuItem; + wxMenuItem *rigCenterLockMenuItem; + wxMenuItem *rigFollowModemMenuItem; + + std::map rigSerialMenuItems; + std::map rigModelMenuItems; + int rigModel; + int rigSerialRate; + long long rigSDRIF; + std::vector rigSerialRates; + std::string rigPort; + int numRigs; + PortSelectorDialog *rigPortDialog; + + void enableRig(); + void disableRig(); + + wxMenu *makeRigMenu(); + void handleRigMenu(); +#endif + + wxDECLARE_EVENT_TABLE(); + +}; + + + #define wxID_RT_AUDIO_DEVICE 1000 #define wxID_SET_FREQ_OFFSET 2001 #define wxID_RESET 2002 @@ -98,243 +375,4 @@ #define wxID_RIG_FOLLOW_MODEM 11906 #define wxID_RIG_SERIAL_BASE 11950 #define wxID_RIG_MODEL_BASE 12000 -#endif - -#ifdef USE_HAMLIB -class PortSelectorDialog; -#endif - -// Define a new frame type -class AppFrame: public wxFrame { -public: - AppFrame(); - ~AppFrame(); - - wxMenu *makeFileMenu(); - - wxMenu *makeRecordingMenu(); - void updateRecordingMenu(); - - void initDeviceParams(SDRDeviceInfo *devInfo); - void updateDeviceParams(); - - void saveSession(std::string fileName); - bool loadSession(std::string fileName); - - FFTVisualDataThread *getWaterfallDataThread(); - WaterfallCanvas *getWaterfallCanvas(); - SpectrumCanvas *getSpectrumCanvas(); - - void notifyUpdateModemProperties(); - void setMainWaterfallFFTSize(int fftSize); - void setScopeDeviceName(std::string deviceName); - - void gkNudgeLeft(DemodulatorInstancePtr demod, int snap); - void gkNudgeRight(DemodulatorInstancePtr demod, int snap); - - int OnGlobalKeyDown(wxKeyEvent &event); - int OnGlobalKeyUp(wxKeyEvent &event); - - void toggleActiveDemodRecording(); - void toggleAllActiveDemodRecording(); - - void setWaterfallLinesPerSecond(int lps); - void setSpectrumAvgSpeed(double avg); - - FrequencyDialog::FrequencyDialogTarget getFrequencyDialogTarget(); - void refreshGainUI(); - void setViewState(long long center_freq, int bandwidth); - void setViewState(); - - long long getViewCenterFreq(); - int getViewBandwidth(); - bool isUserDemodBusy(); - - BookmarkView *getBookmarkView(); - void disableSave(bool state); - - //call this in case the main UI is not - //the origin of device changes / sample rate by operator, - //and must be notified back to update its UI elements - //(ex: SDR Devices dialog changing the configuration) - void notifyDeviceChanged(); - -#ifdef _WIN32 - bool canFocus(); -#endif - //set tooltip to window - void setStatusText(wxWindow* window, std::string statusText); - void setStatusText(std::string statusText, int value); - -#ifdef USE_HAMLIB - void setRigControlPort(std::string portName); - void dismissRigControlPortDialog(); -#endif - -private: - void OnMenu(wxCommandEvent& event); - void OnClose(wxCloseEvent& event); - void OnNewWindow(wxCommandEvent& event); - void OnIdle(wxIdleEvent& event); - void OnDoubleClickSash(wxSplitterEvent& event); - void OnUnSplit(wxSplitterEvent& event); - void OnAboutDialogClose(wxCommandEvent& event); - - //actionXXXX manage menu actions, return true if the event has been - //treated. - bool actionOnMenuAbout(wxCommandEvent& event); - bool actionOnMenuReset(wxCommandEvent& event); - bool actionOnMenuSettings(wxCommandEvent& event); - bool actionOnMenuAGC(wxCommandEvent& event); - bool actionOnMenuSampleRate(wxCommandEvent& event); - bool actionOnMenuAudioSampleRate(wxCommandEvent& event); - bool actionOnMenuDisplay(wxCommandEvent& event); - bool actionOnMenuLoadSave(wxCommandEvent& event); - bool actionOnMenuRecording(wxCommandEvent& event); - bool actionOnMenuRig(wxCommandEvent& event); - - wxString getSettingsLabel(const std::string& settingsName, - const std::string& settingsValue, - const std::string& settingsSuffix = ""); - - ScopeCanvas *scopeCanvas; - SpectrumCanvas *spectrumCanvas; - WaterfallCanvas *waterfallCanvas; - ModeSelectorCanvas *demodModeSelector; -#ifdef ENABLE_DIGITAL_LAB - ModeSelectorCanvas *demodModeSelectorAdv; -#endif - SpectrumCanvas *demodSpectrumCanvas; - WaterfallCanvas *demodWaterfallCanvas; - MeterCanvas *demodSignalMeter; - MeterCanvas *demodGainMeter; - TuningCanvas *demodTuner; -// UITestCanvas *testCanvas; - MeterCanvas *spectrumAvgMeter; - MeterCanvas *waterfallSpeedMeter; - ModeSelectorCanvas *demodMuteButton, *peakHoldButton, *soloModeButton, *deltaLockButton; - GainCanvas *gainCanvas; - wxSizerItem *gainSizerItem, *gainSpacerItem; - wxSplitterWindow *mainVisSplitter, *mainSplitter, *bookmarkSplitter; - wxBoxSizer *demodTray; - BookmarkView *bookmarkView; - - //Use a raw pointer here to prevent a dangling reference - DemodulatorInstance* activeDemodulator; - - std::map sampleRateMenuItems; - std::map antennaMenuItems; - - //depending on context, maps the item id to wxMenuItem*, - //OR the submenu item id to its parent wxMenuItem*. - std::map settingsMenuItems; - std::map performanceMenuItems; - std::map audioSampleRateMenuItems; - std::map recordingMenuItems; - - wxMenuBar *menuBar; - - wxMenu *sampleRateMenu = nullptr; - wxMenu *displayMenu = nullptr; - wxMenuItem *agcMenuItem = nullptr; - wxMenuItem *iqSwapMenuItem = nullptr; - - wxMenu *fileMenu = nullptr; - wxMenu *settingsMenu = nullptr; - wxMenu *recordingMenu = nullptr; - - SoapySDR::ArgInfoList settingArgs; - int settingsIdMax; - std::vector sampleRates; - long manualSampleRate = -1; - - std::vector antennaNames; - - std::string currentTXantennaName; - - std::string currentSessionFile; - std::string currentBookmarkFile; - - FFTVisualDataThread *waterfallDataThread; - - std::thread *t_FFTData; - SDRDeviceInfo *devInfo; - std::atomic_bool deviceChanged; - - ModemProperties *modemProps; - std::atomic_bool modemPropertiesUpdated; - wxMenuItem *showTipMenuItem; - - wxMenuItem *hideBookmarksItem; - bool saveDisabled; - - AboutDialog *aboutDlg; - std::string lastToolTip; - - ModeSelectorCanvas *makeModemSelectorPanel(wxWindow *parent, const wxGLAttributes &attribList); - WaterfallCanvas *makeWaterfallCanvas(wxWindow *parent, const wxGLAttributes &attribList); - SpectrumCanvas *makeDemodSpectrumCanvas(wxWindow *parent, const wxGLAttributes &attribList); - MeterCanvas *makeSignalMeter(wxWindow *parent, const wxGLAttributes &attribList); - ModeSelectorCanvas *makeDeltaLockButton(wxWindow *parent, const wxGLAttributes &attribList); - TuningCanvas *makeModemTuner(wxWindow *parent, const wxGLAttributes &attribList); - MeterCanvas *makeModemGainMeter(wxWindow *parent, const wxGLAttributes &attribList); - ModeSelectorCanvas *makeSoloModeButton(wxWindow *parent, const wxGLAttributes &attribList); - ModeSelectorCanvas *makeModemMuteButton(wxWindow *parent, const wxGLAttributes &attribList); - ModeSelectorCanvas *makePeakHoldButton(wxWindow *parent, const wxGLAttributes &attribList); - SpectrumCanvas *makeSpectrumCanvas(wxWindow *parent, const wxGLAttributes &attribList); - MeterCanvas *makeSpectrumAvgMeter(wxWindow *parent, const wxGLAttributes &attribList); - WaterfallCanvas *makeWaterfall(wxWindow *parent, const wxGLAttributes &attribList); - MeterCanvas *makeWaterfallSpeedMeter(wxWindow *parent, const wxGLAttributes &attribList); - ScopeCanvas *makeScopeCanvas(wxPanel *parent, const wxGLAttributes &attribList); - ModeSelectorCanvas *makeModemAdvSelectorPanel(wxPanel *parent, const wxGLAttributes &attribList); - ModemProperties *makeModemProperties(wxPanel *parent); - - void initConfigurationSettings(); - void initMenuBar(); - void initIcon(); - - wxMenu *makeAudioSampleRateMenu(); - wxMenu *makeDisplayMenu(); - - void handleTXAntennaChange(); - void handleCurrentModem(); - void handleModeSelector(); - void handleGainMeter(); - void handleDemodWaterfallSpectrum(); - void handleSpectrumWaterfall(); - void handleMuteButton(); - void handleScopeProcessor(); - void handleScopeSpectrumProcessors(); - void handleModemProperties(); - void handlePeakHold(); - - -#ifdef USE_HAMLIB - void enableRig(); - void disableRig(); - - wxMenu *rigMenu; - wxMenuItem *rigEnableMenuItem; - wxMenuItem *rigPortMenuItem; - wxMenuItem *rigControlMenuItem; - wxMenuItem *rigFollowMenuItem; - wxMenuItem *rigCenterLockMenuItem; - wxMenuItem *rigFollowModemMenuItem; - - std::map rigSerialMenuItems; - std::map rigModelMenuItems; - int rigModel; - int rigSerialRate; - long long rigSDRIF; - std::vector rigSerialRates; - std::string rigPort; - int numRigs; - PortSelectorDialog *rigPortDialog; - - wxMenu *makeRigMenu(); - void handleRigMenu(); -#endif - - wxDECLARE_EVENT_TABLE(); - -}; +#endif \ No newline at end of file