Add split-view controls; tweak spectrum scale control

This commit is contained in:
Charles J. Cliffe 2015-10-25 14:09:59 -04:00
parent 11aa8e9b05
commit a6201ad3b5
5 changed files with 109 additions and 28 deletions

View File

@ -34,8 +34,11 @@ EVT_CLOSE(AppFrame::OnClose)
EVT_MENU(wxID_ANY, AppFrame::OnMenu)
EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread)
EVT_IDLE(AppFrame::OnIdle)
EVT_SPLITTER_DCLICK(wxID_ANY, AppFrame::OnDoubleClickSash)
EVT_SPLITTER_UNSPLIT(wxID_ANY, AppFrame::OnUnSplit)
wxEND_EVENT_TABLE()
AppFrame::AppFrame() :
wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) {
@ -50,7 +53,13 @@ AppFrame::AppFrame() :
int attribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
demodModeSelector = new ModeSelectorCanvas(this, attribList);
mainSplitter = new wxSplitterWindow( this, wxID_MAIN_SPLITTER, wxDefaultPosition, wxDefaultSize, wxSP_3DSASH | wxSP_LIVE_UPDATE );
mainSplitter->SetSashGravity(12.0/37.0);
mainSplitter->SetMinimumPaneSize(1);
wxPanel *demodPanel = new wxPanel(mainSplitter, wxID_ANY);
demodModeSelector = new ModeSelectorCanvas(demodPanel, attribList);
demodModeSelector->addChoice(DEMOD_TYPE_FM, "FM");
demodModeSelector->addChoice(DEMOD_TYPE_AM, "AM");
demodModeSelector->addChoice(DEMOD_TYPE_LSB, "LSB");
@ -62,14 +71,14 @@ AppFrame::AppFrame() :
demodTray->Add(demodModeSelector, 2, wxEXPAND | wxALL, 0);
wxGetApp().getDemodSpectrumProcessor()->setup(1024);
demodSpectrumCanvas = new SpectrumCanvas(this, attribList);
demodSpectrumCanvas = new SpectrumCanvas(demodPanel, attribList);
demodSpectrumCanvas->setView(wxGetApp().getConfig()->getCenterFreq(), 300000);
demodVisuals->Add(demodSpectrumCanvas, 3, wxEXPAND | wxALL, 0);
wxGetApp().getDemodSpectrumProcessor()->attachOutput(demodSpectrumCanvas->getVisualDataQueue());
demodVisuals->AddSpacer(1);
demodWaterfallCanvas = new WaterfallCanvas(this, attribList);
demodWaterfallCanvas = new WaterfallCanvas(demodPanel, attribList);
demodWaterfallCanvas->setup(1024, 128);
demodWaterfallCanvas->setView(wxGetApp().getConfig()->getCenterFreq(), 300000);
demodWaterfallCanvas->attachSpectrumCanvas(demodSpectrumCanvas);
@ -82,14 +91,14 @@ AppFrame::AppFrame() :
demodTray->AddSpacer(1);
demodSignalMeter = new MeterCanvas(this, attribList);
demodSignalMeter = new MeterCanvas(demodPanel, attribList);
demodSignalMeter->setMax(0.5);
demodSignalMeter->setHelpTip("Current Signal Level. Click / Drag to set Squelch level.");
demodTray->Add(demodSignalMeter, 1, wxEXPAND | wxALL, 0);
demodTray->AddSpacer(1);
scopeCanvas = new ScopeCanvas(this, attribList);
scopeCanvas = new ScopeCanvas(demodPanel, attribList);
scopeCanvas->setHelpTip("Audio Visuals, drag left/right to toggle Scope or Spectrum.");
demodScopeTray->Add(scopeCanvas, 8, wxEXPAND | wxALL, 0);
wxGetApp().getScopeProcessor()->setup(2048);
@ -97,7 +106,7 @@ AppFrame::AppFrame() :
demodScopeTray->AddSpacer(1);
demodTuner = new TuningCanvas(this, attribList);
demodTuner = new TuningCanvas(demodPanel, attribList);
demodTuner->setHelpTip("Testing tuner");
demodScopeTray->Add(demodTuner, 1, wxEXPAND | wxALL, 0);
@ -107,7 +116,7 @@ AppFrame::AppFrame() :
wxBoxSizer *demodGainTray = new wxBoxSizer(wxVERTICAL);
demodGainMeter = new MeterCanvas(this, attribList);
demodGainMeter = new MeterCanvas(demodPanel, attribList);
demodGainMeter->setMax(2.0);
demodGainMeter->setHelpTip("Current Demodulator Gain Level. Click / Drag to set Gain level.");
demodGainMeter->setShowUserInput(false);
@ -115,7 +124,7 @@ AppFrame::AppFrame() :
demodGainTray->AddSpacer(1);
demodMuteButton = new ModeSelectorCanvas(this, attribList);
demodMuteButton = new ModeSelectorCanvas(demodPanel, attribList);
demodMuteButton->addChoice(1, "M");
demodMuteButton->setPadding(-1,-1);
demodMuteButton->setHighlightColor(RGBA4f(0.8,0.2,0.2));
@ -127,16 +136,27 @@ AppFrame::AppFrame() :
demodTray->Add(demodGainTray, 1, wxEXPAND | wxALL, 0);
vbox->Add(demodTray, 12, wxEXPAND | wxALL, 0);
vbox->AddSpacer(1);
demodPanel->SetSizer(demodTray);
// vbox->Add(demodTray, 12, wxEXPAND | wxALL, 0);
// vbox->AddSpacer(1);
mainVisSplitter = new wxSplitterWindow( mainSplitter, wxID_VIS_SPLITTER, wxDefaultPosition, wxDefaultSize, wxSP_3DSASH | wxSP_LIVE_UPDATE );
mainVisSplitter->SetSashGravity(5.0/25.0);
mainVisSplitter->SetMinimumPaneSize(1);
// mainVisSplitter->Connect( wxEVT_IDLE, wxIdleEventHandler( AppFrame::mainVisSplitterIdle ), NULL, this );
wxPanel *spectrumPanel = new wxPanel(mainVisSplitter, wxID_ANY);
wxBoxSizer *spectrumSizer = new wxBoxSizer(wxHORIZONTAL);
wxGetApp().getSpectrumProcessor()->setup(2048);
spectrumCanvas = new SpectrumCanvas(this, attribList);
spectrumCanvas = new SpectrumCanvas(spectrumPanel, attribList);
spectrumCanvas->setShowDb(true);
spectrumCanvas->setScaleFactorEnabled(true);
wxGetApp().getSpectrumProcessor()->attachOutput(spectrumCanvas->getVisualDataQueue());
spectrumAvgMeter = new MeterCanvas(this, attribList);
spectrumAvgMeter = new MeterCanvas(spectrumPanel, attribList);
spectrumAvgMeter->setHelpTip("Spectrum averaging speed, click or drag to adjust.");
spectrumAvgMeter->setMax(1.0);
spectrumAvgMeter->setLevel(0.65);
@ -145,14 +165,16 @@ AppFrame::AppFrame() :
spectrumSizer->Add(spectrumCanvas, 63, wxEXPAND | wxALL, 0);
spectrumSizer->AddSpacer(1);
spectrumSizer->Add(spectrumAvgMeter, 1, wxEXPAND | wxALL, 0);
spectrumPanel->SetSizer(spectrumSizer);
vbox->Add(spectrumSizer, 5, wxEXPAND | wxALL, 0);
// vbox->Add(spectrumSizer, 5, wxEXPAND | wxALL, 0);
vbox->AddSpacer(1);
// vbox->AddSpacer(1);
wxPanel *waterfallPanel = new wxPanel(mainVisSplitter, wxID_ANY);
wxBoxSizer *wfSizer = new wxBoxSizer(wxHORIZONTAL);
waterfallCanvas = new WaterfallCanvas(this, attribList);
waterfallCanvas = new WaterfallCanvas(waterfallPanel, attribList);
waterfallCanvas->setup(2048, 512);
waterfallDataThread = new FFTVisualDataThread();
@ -162,7 +184,7 @@ AppFrame::AppFrame() :
t_FFTData = new std::thread(&FFTVisualDataThread::threadMain, waterfallDataThread);
waterfallSpeedMeter = new MeterCanvas(this, attribList);
waterfallSpeedMeter = new MeterCanvas(waterfallPanel, attribList);
waterfallSpeedMeter->setHelpTip("Waterfall speed, click or drag to adjust (max 1024 lines per second)");
waterfallSpeedMeter->setMax(sqrt(1024));
waterfallSpeedMeter->setLevel(sqrt(DEFAULT_WATERFALL_LPS));
@ -171,8 +193,14 @@ AppFrame::AppFrame() :
wfSizer->Add(waterfallCanvas, 63, wxEXPAND | wxALL, 0);
wfSizer->AddSpacer(1);
wfSizer->Add(waterfallSpeedMeter, 1, wxEXPAND | wxALL, 0);
waterfallPanel->SetSizer(wfSizer);
vbox->Add(wfSizer, 20, wxEXPAND | wxALL, 0);
// vbox->Add(wfSizer, 20, wxEXPAND | wxALL, 0);
mainVisSplitter->SplitHorizontally( spectrumPanel, waterfallPanel, 0 );
mainSplitter->SplitHorizontally( demodPanel, mainVisSplitter );
vbox->Add(mainSplitter, 1, wxEXPAND | wxALL, 0);
// TODO: refactor these..
waterfallCanvas->attachSpectrumCanvas(spectrumCanvas);
@ -382,7 +410,6 @@ AppFrame::~AppFrame() {
t_FFTData->join();
}
void AppFrame::initDeviceParams(SDRDeviceInfo *devInfo) {
std::string deviceId = devInfo->getName();
@ -840,6 +867,39 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
event.RequestMore();
}
void AppFrame::OnDoubleClickSash(wxSplitterEvent& event)
{
wxWindow *a, *b;
wxSplitterWindow *w = NULL;
float g = 0.5;
if (event.GetId() == wxID_MAIN_SPLITTER) {
w = mainSplitter;
g = 12.0/37.0;
} else if (event.GetId() == wxID_VIS_SPLITTER) {
w = mainVisSplitter;
g = 7.4/37.0;
}
if (w != NULL) {
a = w->GetWindow1();
b = w->GetWindow2();
w->Unsplit();
w->SetSashGravity(g);
wxSize s = w->GetSize();
w->SplitHorizontally(a, b, int(float(s.GetHeight()) * g));
}
event.Veto();
}
void AppFrame::OnUnSplit(wxSplitterEvent& event)
{
event.Veto();
}
void AppFrame::saveSession(std::string fileName) {
DataTree s("cubicsdr_session");
DataNode *header = s.rootNode()->newChild("header");

View File

@ -1,6 +1,9 @@
#pragma once
#include "wx/frame.h"
#include <wx/frame.h>
#include <wx/panel.h>
#include <wx/splitter.h>
#include "PrimaryGLContext.h"
#include "ScopeCanvas.h"
@ -25,6 +28,9 @@
#define wxID_SET_SWAP_IQ 2007
#define wxID_SDR_DEVICES 2008
#define wxID_MAIN_SPLITTER 2050
#define wxID_VIS_SPLITTER 2051
#define wxID_THEME_DEFAULT 2100
#define wxID_THEME_SHARP 2101
#define wxID_THEME_BW 2102
@ -61,6 +67,8 @@ private:
void OnClose(wxCloseEvent& event);
void OnNewWindow(wxCommandEvent& event);
void OnIdle(wxIdleEvent& event);
void OnDoubleClickSash(wxSplitterEvent& event);
void OnUnSplit(wxSplitterEvent& event);
ScopeCanvas *scopeCanvas;
SpectrumCanvas *spectrumCanvas;
@ -75,6 +83,7 @@ private:
MeterCanvas *spectrumAvgMeter;
MeterCanvas *waterfallSpeedMeter;
ModeSelectorCanvas *demodMuteButton;
wxSplitterWindow *mainVisSplitter, *mainSplitter;
DemodulatorInstance *activeDemodulator;

View File

@ -150,11 +150,11 @@ void InteractiveCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
}
void InteractiveCanvas::setStatusText(std::string statusText) {
((wxFrame*) parent)->GetStatusBar()->SetStatusText(statusText);
wxGetApp().getAppFrame()->GetStatusBar()->SetStatusText(statusText);
}
void InteractiveCanvas::setStatusText(std::string statusText, int value) {
((wxFrame*) parent)->GetStatusBar()->SetStatusText(
wxGetApp().getAppFrame()->GetStatusBar()->SetStatusText(
wxString::Format(statusText.c_str(), wxNumberFormatter::ToString((long) value, wxNumberFormatter::Style_WithThousandsSep)));
}

View File

@ -40,6 +40,7 @@ SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
SetCursor(wxCURSOR_SIZEWE);
scaleFactor = 1.0;
resetScaleFactor = false;
scaleFactorEnabled = false;
bwChange = 0.0;
}
@ -165,6 +166,11 @@ void SpectrumCanvas::disableView() {
InteractiveCanvas::disableView();
}
void SpectrumCanvas::setScaleFactorEnabled(bool en) {
scaleFactorEnabled = en;
}
void SpectrumCanvas::updateScaleFactor(float factor) {
SpectrumVisualProcessor *sp = wxGetApp().getSpectrumProcessor();
FFTVisualDataThread *wdt = wxGetApp().getAppFrame()->getWaterfallDataThread();
@ -184,7 +190,7 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) {
moveCenterFrequency(freqChange);
}
}
else if (mouseTracker.mouseRightDown()) {
else if (scaleFactorEnabled && mouseTracker.mouseRightDown()) {
float yDelta = mouseTracker.getDeltaMouseY();
@ -199,7 +205,11 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) {
resetScaleFactor = false;
updateScaleFactor(scaleFactor);
} else {
if (scaleFactorEnabled) {
setStatusText("Drag horitontal to adjust center frequency. Right-drag to adjust vertical scale, click to reset. 'B' to toggle decibels display.");
} else {
setStatusText("Displaying spectrum of active demodulator.");
}
}
}

View File

@ -25,6 +25,8 @@ public:
void setView(long long center_freq_in, int bandwidth_in);
void disableView();
void setScaleFactorEnabled(bool en);
SpectrumVisualDataQueue *getVisualDataQueue();
private:
@ -48,7 +50,7 @@ private:
SpectrumPanel spectrumPanel;
float scaleFactor;
int bwChange;
bool resetScaleFactor;
bool resetScaleFactor, scaleFactorEnabled;
SpectrumVisualDataQueue visualDataQueue;