AppFrame.h 8.63 KB
Newer Older
1 2 3
// Copyright (c) Charles J. Cliffe
// SPDX-License-Identifier: GPL-2.0+

4 5 6 7 8 9
#pragma once

#include <wx/frame.h>
#include <wx/panel.h>
#include <wx/splitter.h>
#include <wx/sizer.h>
10 11
#include <wx/bitmap.h>
#include <wx/statbmp.h>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

#include "PrimaryGLContext.h"

#include "ScopeCanvas.h"
#include "SpectrumCanvas.h"
#include "WaterfallCanvas.h"
#include "MeterCanvas.h"
#include "TuningCanvas.h"
#include "ModeSelectorCanvas.h"
#include "GainCanvas.h"
#include "FFTVisualDataThread.h"
#include "SDRDeviceInfo.h"
#include "ModemProperties.h"
//#include "UITestCanvas.h"
#include "FrequencyDialog.h"
27 28
#include "BookmarkView.h"
#include "AboutDialog.h"
29 30
#include "DemodulatorInstance.h"
#include "DemodulatorThread.h"
31 32 33 34 35 36 37 38 39 40 41 42
#include <map>

#define wxID_RT_AUDIO_DEVICE 1000
#define wxID_SET_FREQ_OFFSET 2001
#define wxID_RESET 2002
#define wxID_SET_PPM 2003
#define wxID_SET_TIPS 2004
#define wxID_SET_IQSWAP 2005
#define wxID_SDR_DEVICES 2008
#define wxID_AGC_CONTROL 2009
#define wxID_SDR_START_STOP 2010
#define wxID_LOW_PERF 2011
43 44
#define wxID_SET_DB_OFFSET 2012
#define wxID_ABOUT_CUBICSDR 2013
45

46 47 48 49 50
#define wxID_OPEN_BOOKMARKS 2020
#define wxID_SAVE_BOOKMARKS 2021
#define wxID_SAVEAS_BOOKMARKS 2022
#define wxID_RESET_BOOKMARKS 2023

51 52
#define wxID_MAIN_SPLITTER 2050
#define wxID_VIS_SPLITTER 2051
53
#define wxID_BM_SPLITTER 2052
54 55 56 57 58 59 60 61 62

#define wxID_THEME_DEFAULT 2100
#define wxID_THEME_SHARP 2101
#define wxID_THEME_BW 2102
#define wxID_THEME_RAD 2103
#define wxID_THEME_TOUCH 2104
#define wxID_THEME_HD 2105
#define wxID_THEME_RADAR 2106

63 64
#define wxID_DISPLAY_BOOKMARKS 2107

65
#define wxID_BANDWIDTH_BASE 2150
66
#define wxID_BANDWIDTH_MANUAL_DIALOG 2199
67 68 69 70 71 72
#define wxID_BANDWIDTH_MANUAL 2200

#define wxID_DISPLAY_BASE 2250

#define wxID_SETTINGS_BASE 2300

73 74 75 76
#define wxID_ANTENNA_CURRENT 2500
#define wxID_ANTENNA_CURRENT_TX 2501
#define wxID_ANTENNAS_BASE 2502

77 78
#define wxID_DEVICE_ID 3500

79 80 81 82 83 84 85
#define  wxID_RECORDING_PATH 8500
#define  wxID_RECORDING_SQUELCH_BASE 8501
#define  wxID_RECORDING_SQUELCH_SILENCE 8502
#define  wxID_RECORDING_SQUELCH_SKIP 8503
#define  wxID_RECORDING_SQUELCH_ALWAYS 8504
#define  wxID_RECORDING_FILE_TIME_LIMIT 8505

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#define wxID_AUDIO_BANDWIDTH_BASE 9000
#define wxID_AUDIO_DEVICE_MULTIPLIER 50

#ifdef USE_HAMLIB
#define wxID_RIG_TOGGLE 11900
#define wxID_RIG_PORT 11901
#define wxID_RIG_SDR_IF 11902
#define wxID_RIG_CONTROL 11903
#define wxID_RIG_FOLLOW 11904
#define wxID_RIG_CENTERLOCK 11905
#define wxID_RIG_FOLLOW_MODEM 11906
#define wxID_RIG_SERIAL_BASE 11950
#define wxID_RIG_MODEL_BASE 12000
#endif

101 102 103 104
#ifdef USE_HAMLIB
class PortSelectorDialog;
#endif

105 106 107 108 109
// Define a new frame type
class AppFrame: public wxFrame {
public:
    AppFrame();
    ~AppFrame();
110

111 112 113 114 115
    wxMenu *makeFileMenu();
   
	wxMenu *makeRecordingMenu();
	void updateRecordingMenu();

116 117 118 119 120 121 122 123 124 125 126 127
    void initDeviceParams(SDRDeviceInfo *devInfo);
    void updateDeviceParams();

    void saveSession(std::string fileName);
    bool loadSession(std::string fileName);

    FFTVisualDataThread *getWaterfallDataThread();

    void notifyUpdateModemProperties();
    void setMainWaterfallFFTSize(int fftSize);
    void setScopeDeviceName(std::string deviceName);

128 129
    void gkNudgeLeft(DemodulatorInstancePtr demod, int snap);
    void gkNudgeRight(DemodulatorInstancePtr demod, int snap);
130 131 132 133

    int OnGlobalKeyDown(wxKeyEvent &event);
    int OnGlobalKeyUp(wxKeyEvent &event);
    
134 135 136
    void toggleActiveDemodRecording();
    void toggleAllActiveDemodRecording();
    
137 138 139 140 141 142
    void setWaterfallLinesPerSecond(int lps);
    void setSpectrumAvgSpeed(double avg);
    
    FrequencyDialog::FrequencyDialogTarget getFrequencyDialogTarget();
    void refreshGainUI();
    void setViewState(long long center_freq, int bandwidth);
143
    void setViewState();
144 145 146

    long long getViewCenterFreq();
    int getViewBandwidth();
147
    bool isUserDemodBusy();
148 149 150 151 152 153 154 155 156 157
    
    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();
    
158 159 160
#ifdef _WIN32
	bool canFocus();
#endif
161 162 163
    //set tooltip to window
    void setStatusText(wxWindow* window, std::string statusText);
    void setStatusText(std::string statusText, int value);
164
    
165 166 167 168 169
#ifdef USE_HAMLIB
    void setRigControlPort(std::string portName);
    void dismissRigControlPortDialog();
#endif
    
170 171 172 173 174 175 176
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);
177
    void OnAboutDialogClose(wxCommandEvent& event);
178
   
179 180 181 182 183 184 185 186 187 188
    //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);
189
	bool actionOnMenuRecording(wxCommandEvent& event);
190 191
    bool actionOnMenuRig(wxCommandEvent& event);

192 193 194 195
    wxString getSettingsLabel(const std::string& settingsName, 
                              const std::string& settingsValue, 
                              const std::string& settingsSuffix = "");

196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
    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;
214
    wxSplitterWindow *mainVisSplitter, *mainSplitter, *bookmarkSplitter;
215
    wxBoxSizer *demodTray;
216
    BookmarkView *bookmarkView;
217
    
218 219
    //Use a raw pointer here to prevent a dangling reference
    DemodulatorInstance* activeDemodulator;
220 221 222 223

    std::vector<RtAudio::DeviceInfo> devices;
    std::map<int,RtAudio::DeviceInfo> inputDevices;
    std::map<int,RtAudio::DeviceInfo> outputDevices;
224

225 226
    std::map<int, wxMenuItem *> outputDeviceMenuItems;
    std::map<int, wxMenuItem *> sampleRateMenuItems;
227 228 229 230 231 232
    std::map<int, wxMenuItem *> antennaMenuItems;
    
    //depending on context, maps the item id to wxMenuItem*,
    //OR the submenu item id to its parent  wxMenuItem*.
    std::map<int, wxMenuItem *> settingsMenuItems;
    
233
    std::map<int, wxMenuItem *> audioSampleRateMenuItems;
234 235 236 237

	//
	std::map<int, wxMenuItem *> recordingMenuItems;

238 239 240
    std::map<int, wxMenuItem *> directSamplingMenuItems;
    wxMenuBar *menuBar;
    
241 242 243 244 245
    wxMenu *sampleRateMenu = nullptr;
    wxMenu *displayMenu = nullptr;
    wxMenuItem *agcMenuItem = nullptr;
    wxMenuItem *iqSwapMenuItem = nullptr;
    wxMenuItem *lowPerfMenuItem = nullptr;
246
    wxMenu *fileMenu = nullptr;
247
    wxMenu *settingsMenu = nullptr;
248
	wxMenu *recordingMenu = nullptr;
249 250 251 252
    
    SoapySDR::ArgInfoList settingArgs;
    int settingsIdMax;
    std::vector<long> sampleRates;
253
    long manualSampleRate = -1;
254 255 256 257

    std::vector<std::string> antennaNames;

   std::string currentTXantennaName;
258 259
    
    std::string currentSessionFile;
260
	std::string currentBookmarkFile;
261 262 263 264 265 266 267 268 269 270 271 272
    
    FFTVisualDataThread *waterfallDataThread;
    
    std::thread *t_FFTData;
    SDRDeviceInfo *devInfo;
    std::atomic_bool deviceChanged;
    
    ModemProperties *modemProps;
    std::atomic_bool modemPropertiesUpdated;
	wxMenuItem *showTipMenuItem;

    bool lowPerfMode;
273 274 275

    wxMenuItem *hideBookmarksItem;
    bool saveDisabled;
276
    
277 278 279 280
    AboutDialog *aboutDlg;

    std::string lastToolTip;

281 282 283 284 285 286 287 288 289 290 291
#ifdef USE_HAMLIB
    void enableRig();
    void disableRig();
    
    wxMenu *rigMenu;
    wxMenuItem *rigEnableMenuItem;
    wxMenuItem *rigPortMenuItem;
    wxMenuItem *rigControlMenuItem;
    wxMenuItem *rigFollowMenuItem;
    wxMenuItem *rigCenterLockMenuItem;
    wxMenuItem *rigFollowModemMenuItem;
292
    
293 294 295 296 297 298 299 300
    std::map<int, wxMenuItem *> rigSerialMenuItems;
    std::map<int, wxMenuItem *> rigModelMenuItems;
    int rigModel;
    int rigSerialRate;
    long long rigSDRIF;
    std::vector<int> rigSerialRates;
    std::string rigPort;
    int numRigs;
301
    PortSelectorDialog *rigPortDialog;
302 303 304 305
#endif

    wxDECLARE_EVENT_TABLE();
};