Merge pull request #133 from cjcliffe/processor_threads

Move visual processors to threads
This commit is contained in:
Charles J. Cliffe 2015-08-16 20:30:10 -04:00
commit 36fe309c6e
12 changed files with 142 additions and 54 deletions

View File

@ -264,6 +264,7 @@ SET (cubicsdr_sources
src/process/ScopeVisualProcessor.cpp src/process/ScopeVisualProcessor.cpp
src/process/SpectrumVisualProcessor.cpp src/process/SpectrumVisualProcessor.cpp
src/process/FFTVisualDataThread.cpp src/process/FFTVisualDataThread.cpp
src/process/SpectrumVisualDataThread.cpp
src/ui/GLPanel.cpp src/ui/GLPanel.cpp
external/rtaudio/RtAudio.cpp external/rtaudio/RtAudio.cpp
external/lodepng/lodepng.cpp external/lodepng/lodepng.cpp
@ -318,6 +319,7 @@ SET (cubicsdr_headers
src/process/ScopeVisualProcessor.h src/process/ScopeVisualProcessor.h
src/process/SpectrumVisualProcessor.h src/process/SpectrumVisualProcessor.h
src/process/FFTVisualDataThread.h src/process/FFTVisualDataThread.h
src/process/SpectrumVisualDataThread.h
src/ui/GLPanel.h src/ui/GLPanel.h
src/ui/UITestCanvas.cpp src/ui/UITestCanvas.cpp
src/ui/UITestCanvas.h src/ui/UITestCanvas.h

View File

@ -62,11 +62,11 @@ AppFrame::AppFrame() :
demodModeSelector->setHelpTip("Choose modulation type: Frequency Modulation, Amplitude Modulation and Lower, Upper or Double Side-Band."); demodModeSelector->setHelpTip("Choose modulation type: Frequency Modulation, Amplitude Modulation and Lower, Upper or Double Side-Band.");
demodTray->Add(demodModeSelector, 2, wxEXPAND | wxALL, 0); demodTray->Add(demodModeSelector, 2, wxEXPAND | wxALL, 0);
wxGetApp().getDemodSpectrumProcesor()->setup(1024); wxGetApp().getDemodSpectrumProcessor()->setup(1024);
demodSpectrumCanvas = new SpectrumCanvas(this, attribList); demodSpectrumCanvas = new SpectrumCanvas(this, attribList);
demodSpectrumCanvas->setView(wxGetApp().getConfig()->getCenterFreq(), 300000); demodSpectrumCanvas->setView(wxGetApp().getConfig()->getCenterFreq(), 300000);
demodVisuals->Add(demodSpectrumCanvas, 3, wxEXPAND | wxALL, 0); demodVisuals->Add(demodSpectrumCanvas, 3, wxEXPAND | wxALL, 0);
wxGetApp().getDemodSpectrumProcesor()->attachOutput(demodSpectrumCanvas->getVisualDataQueue()); wxGetApp().getDemodSpectrumProcessor()->attachOutput(demodSpectrumCanvas->getVisualDataQueue());
demodVisuals->AddSpacer(1); demodVisuals->AddSpacer(1);
@ -76,7 +76,7 @@ AppFrame::AppFrame() :
demodWaterfallCanvas->attachSpectrumCanvas(demodSpectrumCanvas); demodWaterfallCanvas->attachSpectrumCanvas(demodSpectrumCanvas);
demodSpectrumCanvas->attachWaterfallCanvas(demodWaterfallCanvas); demodSpectrumCanvas->attachWaterfallCanvas(demodWaterfallCanvas);
demodVisuals->Add(demodWaterfallCanvas, 6, wxEXPAND | wxALL, 0); demodVisuals->Add(demodWaterfallCanvas, 6, wxEXPAND | wxALL, 0);
wxGetApp().getDemodSpectrumProcesor()->attachOutput(demodWaterfallCanvas->getVisualDataQueue()); wxGetApp().getDemodSpectrumProcessor()->attachOutput(demodWaterfallCanvas->getVisualDataQueue());
demodTray->Add(demodVisuals, 30, wxEXPAND | wxALL, 0); demodTray->Add(demodVisuals, 30, wxEXPAND | wxALL, 0);
@ -113,9 +113,9 @@ AppFrame::AppFrame() :
vbox->AddSpacer(1); vbox->AddSpacer(1);
wxBoxSizer *spectrumSizer = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *spectrumSizer = new wxBoxSizer(wxHORIZONTAL);
wxGetApp().getSpectrumProcesor()->setup(2048); wxGetApp().getSpectrumProcessor()->setup(2048);
spectrumCanvas = new SpectrumCanvas(this, attribList); spectrumCanvas = new SpectrumCanvas(this, attribList);
wxGetApp().getSpectrumProcesor()->attachOutput(spectrumCanvas->getVisualDataQueue()); wxGetApp().getSpectrumProcessor()->attachOutput(spectrumCanvas->getVisualDataQueue());
spectrumAvgMeter = new MeterCanvas(this, attribList); spectrumAvgMeter = new MeterCanvas(this, attribList);
spectrumAvgMeter->setHelpTip("Spectrum averaging speed, click or drag to adjust."); spectrumAvgMeter->setHelpTip("Spectrum averaging speed, click or drag to adjust.");
@ -370,7 +370,7 @@ AppFrame::AppFrame() :
float spectrumAvg = wxGetApp().getConfig()->getSpectrumAvgSpeed(); float spectrumAvg = wxGetApp().getConfig()->getSpectrumAvgSpeed();
spectrumAvgMeter->setLevel(spectrumAvg); spectrumAvgMeter->setLevel(spectrumAvg);
wxGetApp().getSpectrumProcesor()->setFFTAverageRate(spectrumAvg); wxGetApp().getSpectrumProcessor()->setFFTAverageRate(spectrumAvg);
int wflps =wxGetApp().getConfig()->getWaterfallLinesPerSec(); int wflps =wxGetApp().getConfig()->getWaterfallLinesPerSec();
@ -488,7 +488,7 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
spectrumCanvas->setCenterFrequency(wxGetApp().getFrequency()); spectrumCanvas->setCenterFrequency(wxGetApp().getFrequency());
waterfallDataThread->setLinesPerSecond(DEFAULT_WATERFALL_LPS); waterfallDataThread->setLinesPerSecond(DEFAULT_WATERFALL_LPS);
waterfallSpeedMeter->setLevel(sqrt(DEFAULT_WATERFALL_LPS)); waterfallSpeedMeter->setLevel(sqrt(DEFAULT_WATERFALL_LPS));
wxGetApp().getSpectrumProcesor()->setFFTAverageRate(0.65); wxGetApp().getSpectrumProcessor()->setFFTAverageRate(0.65);
spectrumAvgMeter->setLevel(0.65); spectrumAvgMeter->setLevel(0.65);
demodModeSelector->Refresh(); demodModeSelector->Refresh();
demodTuner->Refresh(); demodTuner->Refresh();
@ -607,12 +607,16 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
} }
void AppFrame::OnClose(wxCloseEvent& event) { void AppFrame::OnClose(wxCloseEvent& event) {
wxGetApp().getDemodSpectrumProcessor()->removeOutput(demodSpectrumCanvas->getVisualDataQueue());
wxGetApp().getDemodSpectrumProcessor()->removeOutput(demodWaterfallCanvas->getVisualDataQueue());
wxGetApp().getSpectrumProcessor()->removeOutput(spectrumCanvas->getVisualDataQueue());
wxGetApp().getConfig()->setWindow(this->GetPosition(), this->GetClientSize()); wxGetApp().getConfig()->setWindow(this->GetPosition(), this->GetClientSize());
wxGetApp().getConfig()->setWindowMaximized(this->IsMaximized()); wxGetApp().getConfig()->setWindowMaximized(this->IsMaximized());
wxGetApp().getConfig()->setTheme(ThemeMgr::mgr.getTheme()); wxGetApp().getConfig()->setTheme(ThemeMgr::mgr.getTheme());
wxGetApp().getConfig()->setSnap(wxGetApp().getFrequencySnap()); wxGetApp().getConfig()->setSnap(wxGetApp().getFrequencySnap());
wxGetApp().getConfig()->setCenterFreq(wxGetApp().getFrequency()); wxGetApp().getConfig()->setCenterFreq(wxGetApp().getFrequency());
wxGetApp().getConfig()->setSpectrumAvgSpeed(wxGetApp().getSpectrumProcesor()->getFFTAverageRate()); wxGetApp().getConfig()->setSpectrumAvgSpeed(wxGetApp().getSpectrumProcessor()->getFFTAverageRate());
wxGetApp().getConfig()->setWaterfallLinesPerSec(waterfallDataThread->getLinesPerSecond()); wxGetApp().getConfig()->setWaterfallLinesPerSec(waterfallDataThread->getLinesPerSecond());
wxGetApp().getConfig()->save(); wxGetApp().getConfig()->save();
event.Skip(); event.Skip();
@ -742,7 +746,7 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
wxGetApp().getScopeProcessor()->run(); wxGetApp().getScopeProcessor()->run();
wxGetApp().getSpectrumDistributor()->run(); wxGetApp().getSpectrumDistributor()->run();
SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcesor(); SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcessor();
if (spectrumAvgMeter->inputChanged()) { if (spectrumAvgMeter->inputChanged()) {
float val = spectrumAvgMeter->getInputValue(); float val = spectrumAvgMeter->getInputValue();
@ -755,20 +759,16 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
GetStatusBar()->SetStatusText(wxString::Format(wxT("Spectrum averaging speed changed to %0.2f%%."),val*100.0)); GetStatusBar()->SetStatusText(wxString::Format(wxT("Spectrum averaging speed changed to %0.2f%%."),val*100.0));
} }
proc->setView(spectrumCanvas->getViewState()); proc->setView(waterfallCanvas->getViewState());
proc->setBandwidth(spectrumCanvas->getBandwidth()); proc->setBandwidth(waterfallCanvas->getBandwidth());
proc->setCenterFrequency(spectrumCanvas->getCenterFrequency()); proc->setCenterFrequency(waterfallCanvas->getCenterFrequency());
proc->run(); SpectrumVisualProcessor *dproc = wxGetApp().getDemodSpectrumProcessor();
SpectrumVisualProcessor *dproc = wxGetApp().getDemodSpectrumProcesor();
dproc->setView(demodWaterfallCanvas->getViewState()); dproc->setView(demodWaterfallCanvas->getViewState());
dproc->setBandwidth(demodWaterfallCanvas->getBandwidth()); dproc->setBandwidth(demodWaterfallCanvas->getBandwidth());
dproc->setCenterFrequency(demodWaterfallCanvas->getCenterFrequency()); dproc->setCenterFrequency(demodWaterfallCanvas->getCenterFrequency());
dproc->run();
SpectrumVisualProcessor *wproc = waterfallDataThread->getProcessor(); SpectrumVisualProcessor *wproc = waterfallDataThread->getProcessor();
if (waterfallSpeedMeter->inputChanged()) { if (waterfallSpeedMeter->inputChanged()) {

View File

@ -21,7 +21,7 @@
IMPLEMENT_APP(CubicSDR) IMPLEMENT_APP(CubicSDR)
CubicSDR::CubicSDR() : appframe(NULL), m_glContext(NULL), frequency(0), offset(0), ppm(0), snap(1), sampleRate(DEFAULT_SAMPLE_RATE), directSamplingMode(0), CubicSDR::CubicSDR() : appframe(NULL), m_glContext(NULL), frequency(0), offset(0), ppm(0), snap(1), sampleRate(DEFAULT_SAMPLE_RATE), directSamplingMode(0),
sdrThread(NULL), sdrPostThread(NULL), pipeSDRCommand(NULL), pipeSDRIQData(NULL), pipeIQVisualData(NULL), pipeAudioVisualData(NULL), t_SDR(NULL), t_PostSDR(NULL) { sdrThread(NULL), sdrPostThread(NULL), spectrumVisualThread(NULL), demodVisualThread(NULL), pipeSDRCommand(NULL), pipeSDRIQData(NULL), pipeIQVisualData(NULL), pipeAudioVisualData(NULL), t_SDR(NULL), t_PostSDR(NULL) {
} }
@ -51,6 +51,9 @@ bool CubicSDR::OnInit() {
directSamplingMode = 0; directSamplingMode = 0;
// Visual Data // Visual Data
spectrumVisualThread = new SpectrumVisualDataThread();
demodVisualThread = new SpectrumVisualDataThread();
pipeIQVisualData = new DemodulatorThreadInputQueue(); pipeIQVisualData = new DemodulatorThreadInputQueue();
pipeIQVisualData->set_max_num_items(1); pipeIQVisualData->set_max_num_items(1);
@ -68,8 +71,8 @@ bool CubicSDR::OnInit() {
spectrumDistributor.attachOutput(pipeDemodIQVisualData); spectrumDistributor.attachOutput(pipeDemodIQVisualData);
spectrumDistributor.attachOutput(pipeSpectrumIQVisualData); spectrumDistributor.attachOutput(pipeSpectrumIQVisualData);
demodSpectrumProcessor.setInput(pipeDemodIQVisualData); getDemodSpectrumProcessor()->setInput(pipeDemodIQVisualData);
spectrumProcessor.setInput(pipeSpectrumIQVisualData); getSpectrumProcessor()->setInput(pipeSpectrumIQVisualData);
pipeAudioVisualData = new DemodulatorThreadOutputQueue(); pipeAudioVisualData = new DemodulatorThreadOutputQueue();
pipeAudioVisualData->set_max_num_items(1); pipeAudioVisualData->set_max_num_items(1);
@ -80,7 +83,7 @@ bool CubicSDR::OnInit() {
pipeSDRIQData = new SDRThreadIQDataQueue(); pipeSDRIQData = new SDRThreadIQDataQueue();
pipeSDRCommand = new SDRThreadCommandQueue(); pipeSDRCommand = new SDRThreadCommandQueue();
pipeSDRIQData->set_max_num_items(1); pipeSDRIQData->set_max_num_items(100);
sdrThread = new SDRThread(); sdrThread = new SDRThread();
sdrThread->setInputQueue("SDRCommandQueue",pipeSDRCommand); sdrThread->setInputQueue("SDRCommandQueue",pipeSDRCommand);
@ -134,6 +137,8 @@ bool CubicSDR::OnInit() {
t_PostSDR = new std::thread(&SDRPostThread::threadMain, sdrPostThread); t_PostSDR = new std::thread(&SDRPostThread::threadMain, sdrPostThread);
t_SDR = new std::thread(&SDRThread::threadMain, sdrThread); t_SDR = new std::thread(&SDRThread::threadMain, sdrThread);
t_SpectrumVisual = new std::thread(&SpectrumVisualDataThread::threadMain, spectrumVisualThread);
t_DemodVisual = new std::thread(&SpectrumVisualDataThread::threadMain, demodVisualThread);
appframe = new AppFrame(); appframe = new AppFrame();
if (dev != NULL) { if (dev != NULL) {
@ -168,12 +173,24 @@ int CubicSDR::OnExit() {
sdrPostThread->terminate(); sdrPostThread->terminate();
t_PostSDR->join(); t_PostSDR->join();
std::cout << "Terminating Visual Processor threads.." << std::endl;
spectrumVisualThread->terminate();
t_SpectrumVisual->join();
demodVisualThread->terminate();
t_DemodVisual->join();
delete sdrThread; delete sdrThread;
delete t_SDR; delete t_SDR;
delete sdrPostThread; delete sdrPostThread;
delete t_PostSDR; delete t_PostSDR;
delete t_SpectrumVisual;
delete spectrumVisualThread;
delete t_DemodVisual;
delete demodVisualThread;
delete pipeSDRCommand; delete pipeSDRCommand;
delete pipeIQVisualData; delete pipeIQVisualData;
@ -273,12 +290,12 @@ ScopeVisualProcessor *CubicSDR::getScopeProcessor() {
return &scopeProcessor; return &scopeProcessor;
} }
SpectrumVisualProcessor *CubicSDR::getSpectrumProcesor() { SpectrumVisualProcessor *CubicSDR::getSpectrumProcessor() {
return &spectrumProcessor; return spectrumVisualThread->getProcessor();
} }
SpectrumVisualProcessor *CubicSDR::getDemodSpectrumProcesor() { SpectrumVisualProcessor *CubicSDR::getDemodSpectrumProcessor() {
return &demodSpectrumProcessor; return demodVisualThread->getProcessor();
} }
VisualDataDistributor<DemodulatorThreadIQData> *CubicSDR::getSpectrumDistributor() { VisualDataDistributor<DemodulatorThreadIQData> *CubicSDR::getSpectrumDistributor() {

View File

@ -20,6 +20,7 @@
#include "ScopeVisualProcessor.h" #include "ScopeVisualProcessor.h"
#include "SpectrumVisualProcessor.h" #include "SpectrumVisualProcessor.h"
#include "SpectrumVisualDataThread.h"
#include <wx/cmdline.h> #include <wx/cmdline.h>
@ -57,8 +58,8 @@ public:
int getDevice(); int getDevice();
ScopeVisualProcessor *getScopeProcessor(); ScopeVisualProcessor *getScopeProcessor();
SpectrumVisualProcessor *getSpectrumProcesor(); SpectrumVisualProcessor *getSpectrumProcessor();
SpectrumVisualProcessor *getDemodSpectrumProcesor(); SpectrumVisualProcessor *getDemodSpectrumProcessor();
VisualDataDistributor<DemodulatorThreadIQData> *getSpectrumDistributor(); VisualDataDistributor<DemodulatorThreadIQData> *getSpectrumDistributor();
DemodulatorThreadOutputQueue* getAudioVisualQueue(); DemodulatorThreadOutputQueue* getAudioVisualQueue();
@ -96,6 +97,8 @@ private:
SDRThread *sdrThread; SDRThread *sdrThread;
SDRPostThread *sdrPostThread; SDRPostThread *sdrPostThread;
SpectrumVisualDataThread *spectrumVisualThread;
SpectrumVisualDataThread *demodVisualThread;
SDRThreadCommandQueue* pipeSDRCommand; SDRThreadCommandQueue* pipeSDRCommand;
SDRThreadIQDataQueue* pipeSDRIQData; SDRThreadIQDataQueue* pipeSDRIQData;
@ -106,13 +109,13 @@ private:
DemodulatorThreadInputQueue* pipeWaterfallIQVisualData; DemodulatorThreadInputQueue* pipeWaterfallIQVisualData;
ScopeVisualProcessor scopeProcessor; ScopeVisualProcessor scopeProcessor;
SpectrumVisualProcessor spectrumProcessor;
SpectrumVisualProcessor demodSpectrumProcessor;
VisualDataDistributor<DemodulatorThreadIQData> spectrumDistributor; VisualDataDistributor<DemodulatorThreadIQData> spectrumDistributor;
std::thread *t_SDR; std::thread *t_SDR;
std::thread *t_PostSDR; std::thread *t_PostSDR;
std::thread *t_SpectrumVisual;
std::thread *t_DemodVisual;
}; };
static const wxCmdLineEntryDesc commandLineInfo [] = static const wxCmdLineEntryDesc commandLineInfo [] =

View File

@ -59,6 +59,6 @@ void FFTVisualDataThread::run() {
} }
} }
std::cout << "FFT visual data thread terminated." << std::endl; std::cout << "FFT visual data thread done." << std::endl;
} }

View File

@ -0,0 +1,25 @@
#include "SpectrumVisualDataThread.h"
#include "CubicSDR.h"
SpectrumVisualDataThread::SpectrumVisualDataThread() {
}
SpectrumVisualDataThread::~SpectrumVisualDataThread() {
}
SpectrumVisualProcessor *SpectrumVisualDataThread::getProcessor() {
return &sproc;
}
void SpectrumVisualDataThread::run() {
std::cout << "Spectrum visual data thread started." << std::endl;
while(!terminated) {
std::this_thread::sleep_for(std::chrono::milliseconds(12));
sproc.run();
}
std::cout << "Spectrum visual data thread done." << std::endl;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "IOThread.h"
#include "SpectrumVisualProcessor.h"
class SpectrumVisualDataThread : public IOThread {
public:
SpectrumVisualDataThread();
~SpectrumVisualDataThread();
SpectrumVisualProcessor *getProcessor();
void run();
protected:
SpectrumVisualProcessor sproc;
};

View File

@ -221,14 +221,14 @@ void SDRPostThread::run() {
data_in->decRefCount(); data_in->decRefCount();
} }
buffers.purge(); // buffers.purge();
if (iqVisualQueue && !iqVisualQueue->empty()) { if (iqVisualQueue && !iqVisualQueue->empty()) {
DemodulatorThreadIQData *visualDataDummy; DemodulatorThreadIQData *visualDataDummy;
iqVisualQueue->pop(visualDataDummy); iqVisualQueue->pop(visualDataDummy);
} }
visualDataBuffers.purge(); // visualDataBuffers.purge();
std::cout << "SDR post-processing thread done." << std::endl; std::cout << "SDR post-processing thread done." << std::endl;
} }

View File

@ -295,7 +295,7 @@ void SDRThread::run() {
} }
} }
buffers.purge(); // buffers.purge();
std::cout << "SDR thread done." << std::endl; std::cout << "SDR thread done." << std::endl;
} }

View File

@ -22,6 +22,7 @@ EVT_IDLE(SpectrumCanvas::OnIdle)
EVT_MOTION(SpectrumCanvas::OnMouseMoved) EVT_MOTION(SpectrumCanvas::OnMouseMoved)
EVT_LEFT_DOWN(SpectrumCanvas::OnMouseDown) EVT_LEFT_DOWN(SpectrumCanvas::OnMouseDown)
EVT_LEFT_UP(SpectrumCanvas::OnMouseReleased) EVT_LEFT_UP(SpectrumCanvas::OnMouseReleased)
EVT_ENTER_WINDOW(SpectrumCanvas::OnMouseEnterWindow)
EVT_LEAVE_WINDOW(SpectrumCanvas::OnMouseLeftWindow) EVT_LEAVE_WINDOW(SpectrumCanvas::OnMouseLeftWindow)
EVT_MOUSEWHEEL(SpectrumCanvas::OnMouseWheelMoved) EVT_MOUSEWHEEL(SpectrumCanvas::OnMouseWheelMoved)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
@ -152,6 +153,11 @@ void SpectrumCanvas::OnMouseReleased(wxMouseEvent& event) {
SetCursor(wxCURSOR_SIZEWE); SetCursor(wxCURSOR_SIZEWE);
} }
void SpectrumCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseEnterWindow(event);
SetCursor(wxCURSOR_SIZEWE);
}
void SpectrumCanvas::OnMouseLeftWindow(wxMouseEvent& event) { void SpectrumCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseLeftWindow(event); InteractiveCanvas::OnMouseLeftWindow(event);
SetCursor(wxCURSOR_SIZEWE); SetCursor(wxCURSOR_SIZEWE);

View File

@ -30,6 +30,7 @@ private:
void OnMouseDown(wxMouseEvent& event); void OnMouseDown(wxMouseEvent& event);
void OnMouseWheelMoved(wxMouseEvent& event); void OnMouseWheelMoved(wxMouseEvent& event);
void OnMouseReleased(wxMouseEvent& event); void OnMouseReleased(wxMouseEvent& event);
void OnMouseEnterWindow(wxMouseEvent& event);
void OnMouseLeftWindow(wxMouseEvent& event); void OnMouseLeftWindow(wxMouseEvent& event);
PrimaryGLContext *glContext; PrimaryGLContext *glContext;

View File

@ -105,45 +105,49 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
long long bw; long long bw;
if (currentZoom != 1) { if (currentZoom != 1) {
long long freq = wxGetApp().getFrequency(); long long freq = wxGetApp().getFrequency();
bw = getBandwidth();
double mpos = 0;
float mouseInView = false;
if (mouseTracker.mouseInView()) {
mpos = mouseTracker.getMouseX();
mouseInView = true;
} else if (spectrumCanvas && spectrumCanvas->getMouseTracker()->mouseInView()) {
mpos = spectrumCanvas->getMouseTracker()->getMouseX();
mouseInView = true;
}
if (currentZoom < 1) { if (currentZoom < 1) {
centerFreq = getCenterFrequency();
bw = getBandwidth();
bw = (long long) ceil((long double) bw * currentZoom); bw = (long long) ceil((long double) bw * currentZoom);
if (bw < 30000) { if (bw < 30000) {
bw = 30000; bw = 30000;
} }
if (mouseTracker.mouseInView()) { if (mouseInView) {
long long mfreqA = getFrequencyAt(mouseTracker.getMouseX()); long long mfreqA = getFrequencyAt(mpos);
setBandwidth(bw); setBandwidth(bw);
long long mfreqB = getFrequencyAt(mouseTracker.getMouseX()); long long mfreqB = getFrequencyAt(mpos);
centerFreq += mfreqA - mfreqB; centerFreq += mfreqA - mfreqB;
} }
setView(centerFreq, bw); setView(centerFreq, bw);
if (spectrumCanvas) {
spectrumCanvas->setView(centerFreq, bw);
}
} else { } else {
if (isView) { if (isView) {
bw = getBandwidth();
bw = (long long) ceil((long double) bw * currentZoom); bw = (long long) ceil((long double) bw * currentZoom);
if (bw >= wxGetApp().getSampleRate()) { if (bw >= wxGetApp().getSampleRate()) {
disableView(); disableView();
if (spectrumCanvas) { if (spectrumCanvas) {
spectrumCanvas->disableView(); spectrumCanvas->disableView();
} }
} else { } else {
if (mouseTracker.mouseInView()) { if (mouseInView) {
long long mfreqA = getFrequencyAt(mouseTracker.getMouseX()); long long mfreqA = getFrequencyAt(mpos);
setBandwidth(bw); setBandwidth(bw);
long long mfreqB = getFrequencyAt(mouseTracker.getMouseX()); long long mfreqB = getFrequencyAt(mpos);
centerFreq += mfreqA - mfreqB; centerFreq += mfreqA - mfreqB;
} } else {
setBandwidth(bw);
setView(getCenterFrequency(), bw);
if (spectrumCanvas) {
spectrumCanvas->setView(centerFreq, bw);
} }
} }
} }
@ -154,7 +158,14 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
if (centerFreq > freq && (centerFreq + bandwidth / 2) > (freq + wxGetApp().getSampleRate() / 2)) { if (centerFreq > freq && (centerFreq + bandwidth / 2) > (freq + wxGetApp().getSampleRate() / 2)) {
centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2; centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2;
} }
if (spectrumCanvas) {
if ((spectrumCanvas->getCenterFrequency() != centerFreq) || (spectrumCanvas->getBandwidth() != bw)) {
spectrumCanvas->setView(centerFreq,bw);
} }
}
}
glContext->SetCurrent(*this); glContext->SetCurrent(*this);
initGLExtensions(); initGLExtensions();
@ -255,11 +266,13 @@ void WaterfallCanvas::OnKeyUp(wxKeyEvent& event) {
case WXK_UP: case WXK_UP:
case WXK_NUMPAD_UP: case WXK_NUMPAD_UP:
zoom = 1.0; zoom = 1.0;
mouseZoom = 0.95;
break; break;
case 'Z': case 'Z':
case WXK_DOWN: case WXK_DOWN:
case WXK_NUMPAD_DOWN: case WXK_NUMPAD_DOWN:
zoom = 1.0; zoom = 1.0;
mouseZoom = 1.05;
break; break;
} }
} }
@ -276,11 +289,13 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
case 'A': case 'A':
case WXK_UP: case WXK_UP:
case WXK_NUMPAD_UP: case WXK_NUMPAD_UP:
mouseZoom = 1.0;
zoom = 0.95; zoom = 0.95;
break; break;
case 'Z': case 'Z':
case WXK_DOWN: case WXK_DOWN:
case WXK_NUMPAD_DOWN: case WXK_NUMPAD_DOWN:
mouseZoom = 1.0;
zoom = 1.05; zoom = 1.05;
break; break;
case WXK_RIGHT: case WXK_RIGHT:
@ -349,6 +364,9 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
setStatusText("Set center frequency: %s", freq); setStatusText("Set center frequency: %s", freq);
} }
} else { } else {
if (spectrumCanvas) {
spectrumCanvas->setCenterFrequency(freq);
}
wxGetApp().setFrequency(freq); wxGetApp().setFrequency(freq);
setStatusText("Set center frequency: %s", freq); setStatusText("Set center frequency: %s", freq);
} }