mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-01 21:54:39 -04:00
Update digital_lab
This commit is contained in:
@@ -0,0 +1,305 @@
|
||||
#include "GainCanvas.h"
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
#if !wxUSE_GLCANVAS
|
||||
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
|
||||
#endif
|
||||
|
||||
#include "CubicSDR.h"
|
||||
#include "CubicSDRDefs.h"
|
||||
#include "AppFrame.h"
|
||||
#include <algorithm>
|
||||
|
||||
wxBEGIN_EVENT_TABLE(GainCanvas, wxGLCanvas) EVT_PAINT(GainCanvas::OnPaint)
|
||||
EVT_IDLE(GainCanvas::OnIdle)
|
||||
EVT_MOTION(GainCanvas::OnMouseMoved)
|
||||
EVT_LEFT_DOWN(GainCanvas::OnMouseDown)
|
||||
EVT_LEFT_UP(GainCanvas::OnMouseReleased)
|
||||
EVT_LEAVE_WINDOW(GainCanvas::OnMouseLeftWindow)
|
||||
EVT_ENTER_WINDOW(GainCanvas::OnMouseEnterWindow)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
GainCanvas::GainCanvas(wxWindow *parent, int *attribList) :
|
||||
InteractiveCanvas(parent, attribList) {
|
||||
|
||||
glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));
|
||||
bgPanel.setCoordinateSystem(GLPanel::GLPANEL_Y_UP);
|
||||
bgPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_X);
|
||||
|
||||
numGains = 1;
|
||||
spacing = 2.0/numGains;
|
||||
barWidth = (1.0/numGains)*0.8;
|
||||
startPos = spacing/2.0;
|
||||
barHeight = 0.8;
|
||||
}
|
||||
|
||||
GainCanvas::~GainCanvas() {
|
||||
|
||||
}
|
||||
|
||||
void GainCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
wxPaintDC dc(this);
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
|
||||
glContext->SetCurrent(*this);
|
||||
initGLExtensions();
|
||||
|
||||
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
||||
|
||||
float i = 0;
|
||||
for (std::vector<GainInfo *>::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) {
|
||||
GainInfo *gInfo = (*gi);
|
||||
float midPos = -1.0+startPos+spacing*i;
|
||||
|
||||
gInfo->labelPanel.setSize(spacing/2.0,(15.0/float(ClientSize.y)));
|
||||
gInfo->labelPanel.setPosition(midPos, -barHeight-(20.0/float(ClientSize.y)));
|
||||
|
||||
gInfo->valuePanel.setSize(spacing/2.0,(15.0/float(ClientSize.y)));
|
||||
gInfo->valuePanel.setPosition(midPos, barHeight+(20.0/float(ClientSize.y)));
|
||||
|
||||
i+=1.0;
|
||||
}
|
||||
|
||||
bgPanel.draw();
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
void GainCanvas::OnIdle(wxIdleEvent &event) {
|
||||
if (mouseTracker.mouseInView()) {
|
||||
Refresh();
|
||||
} else {
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
for (std::vector<GainInfo *>::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) {
|
||||
GainInfo *gInfo = (*gi);
|
||||
if (gInfo->changed) {
|
||||
wxGetApp().setGain(gInfo->name, gInfo->current);
|
||||
gInfo->changed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GainCanvas::GetPanelHit(CubicVR::vec2 &result) {
|
||||
std::vector<GainInfo *>::iterator gi;
|
||||
|
||||
int i = 0;
|
||||
for (gi = gainInfo.begin(); gi != gainInfo.end(); gi++) {
|
||||
GainInfo *gInfo = (*gi);
|
||||
|
||||
CubicVR::vec2 hitResult;
|
||||
if (gInfo->panel.hitTest(CubicVR::vec2((mouseTracker.getMouseX()-0.5)*2.0, (mouseTracker.getMouseY()-0.5)*2.0), hitResult)) {
|
||||
// std::cout << "Hit #" << i << " result: " << hitResult << std::endl;
|
||||
result = (hitResult + CubicVR::vec2(1.0,1.0)) * 0.5;
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void GainCanvas::SetLevel() {
|
||||
CubicVR::vec2 hitResult;
|
||||
int panelHit = GetPanelHit(hitResult);
|
||||
|
||||
if (panelHit >= 0) {
|
||||
gainInfo[panelHit]->levelPanel.setSize(1.0, hitResult.y);
|
||||
gainInfo[panelHit]->levelPanel.setPosition(0.0, (-1.0+(hitResult.y)));
|
||||
gainInfo[panelHit]->current = gainInfo[panelHit]->low+(hitResult.y * (gainInfo[panelHit]->high-gainInfo[panelHit]->low));
|
||||
gainInfo[panelHit]->changed = true;
|
||||
gainInfo[panelHit]->valuePanel.setText(std::to_string(int(gainInfo[panelHit]->current)));
|
||||
}
|
||||
}
|
||||
|
||||
void GainCanvas::OnMouseMoved(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseMoved(event);
|
||||
|
||||
CubicVR::vec2 hitResult;
|
||||
int panelHit = GetPanelHit(hitResult);
|
||||
|
||||
if (panelHit >= 0) {
|
||||
gainInfo[panelHit]->highlightPanel.setSize(1.0, hitResult.y);
|
||||
gainInfo[panelHit]->highlightPanel.setPosition(0.0, (-1.0+(hitResult.y)));
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (std::vector<GainInfo *>::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) {
|
||||
(*gi)->highlightPanel.visible = (i==panelHit);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (mouseTracker.mouseDown()) {
|
||||
SetLevel();
|
||||
}
|
||||
}
|
||||
|
||||
void GainCanvas::OnMouseDown(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseDown(event);
|
||||
SetLevel();
|
||||
}
|
||||
|
||||
void GainCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseWheelMoved(event);
|
||||
// Refresh();
|
||||
}
|
||||
|
||||
void GainCanvas::OnMouseReleased(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseReleased(event);
|
||||
// Refresh();
|
||||
}
|
||||
|
||||
void GainCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseLeftWindow(event);
|
||||
SetCursor(wxCURSOR_CROSS);
|
||||
|
||||
int i = 0;
|
||||
for (std::vector<GainInfo *>::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) {
|
||||
(*gi)->highlightPanel.visible = false;
|
||||
i++;
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void GainCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
|
||||
InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event);
|
||||
SetCursor(wxCURSOR_CROSS);
|
||||
// Refresh();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GainCanvas::setHelpTip(std::string tip) {
|
||||
helpTip = tip;
|
||||
}
|
||||
|
||||
void GainCanvas::updateGainUI() {
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
|
||||
SDRDeviceInfo *devInfo = wxGetApp().getDevice();
|
||||
|
||||
std::vector<SDRDeviceRange> &gains = devInfo->getRxChannel()->getGains();
|
||||
std::vector<SDRDeviceRange>::iterator gi;
|
||||
|
||||
numGains = gains.size();
|
||||
float i = 0;
|
||||
|
||||
if (!numGains) {
|
||||
return;
|
||||
}
|
||||
|
||||
spacing = 2.0/numGains;
|
||||
barWidth = (1.0/numGains)*0.7;
|
||||
startPos = spacing/2.0;
|
||||
barHeight = 0.8;
|
||||
|
||||
RGBA4f c1, c2;
|
||||
|
||||
while (gainInfo.size()) {
|
||||
GainInfo *giDel;
|
||||
giDel = gainInfo.back();
|
||||
gainInfo.pop_back();
|
||||
|
||||
giDel->panel.removeChild(&giDel->levelPanel);
|
||||
bgPanel.removeChild(&(giDel->labelPanel));
|
||||
bgPanel.removeChild(&(giDel->valuePanel));
|
||||
bgPanel.removeChild(&(giDel->panel));
|
||||
delete giDel;
|
||||
}
|
||||
|
||||
for (gi = gains.begin(); gi != gains.end(); gi++) {
|
||||
GainInfo *gInfo = new GainInfo;
|
||||
float midPos = -1.0+startPos+spacing*i;
|
||||
|
||||
gInfo->name = (*gi).getName();
|
||||
gInfo->low = (*gi).getLow();
|
||||
gInfo->high = (*gi).getHigh();
|
||||
gInfo->current = wxGetApp().getGain(gInfo->name);
|
||||
|
||||
gInfo->panel.setBorderPx(1);
|
||||
gInfo->panel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X);
|
||||
gInfo->panel.setPosition(midPos, 0);
|
||||
gInfo->panel.setSize(barWidth, barHeight);
|
||||
gInfo->panel.setBlend(GL_ONE, GL_ONE);
|
||||
|
||||
gInfo->levelPanel.setBorderPx(0);
|
||||
gInfo->levelPanel.setMarginPx(1);
|
||||
gInfo->levelPanel.setSize(1.0,0.8);
|
||||
float levelVal = float(gInfo->current-gInfo->low)/float(gInfo->high-gInfo->low);
|
||||
gInfo->levelPanel.setSize(1.0, levelVal);
|
||||
gInfo->levelPanel.setPosition(0.0, (-1.0+(levelVal)));
|
||||
gInfo->levelPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X);
|
||||
gInfo->levelPanel.setBlend(GL_ONE, GL_ONE);
|
||||
|
||||
gInfo->panel.addChild(&gInfo->levelPanel);
|
||||
|
||||
gInfo->highlightPanel.setBorderPx(0);
|
||||
gInfo->highlightPanel.setMarginPx(1);
|
||||
gInfo->highlightPanel.setSize(1.0,0.8);
|
||||
gInfo->highlightPanel.setPosition(0.0,-0.2);
|
||||
gInfo->highlightPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X);
|
||||
gInfo->highlightPanel.setBlend(GL_ONE, GL_ONE);
|
||||
gInfo->highlightPanel.visible = false;
|
||||
|
||||
gInfo->panel.addChild(&gInfo->highlightPanel);
|
||||
|
||||
gInfo->labelPanel.setSize(spacing/2.0,(15.0/float(ClientSize.y)));
|
||||
gInfo->labelPanel.setPosition(midPos, -barHeight-(20.0/float(ClientSize.y)));
|
||||
gInfo->labelPanel.setText((*gi).getName());
|
||||
gInfo->labelPanel.setFill(GLPanel::GLPANEL_FILL_NONE);
|
||||
|
||||
bgPanel.addChild(&(gInfo->labelPanel));
|
||||
|
||||
gInfo->valuePanel.setSize(spacing/2.0,(15.0/float(ClientSize.y)));
|
||||
gInfo->valuePanel.setPosition(midPos, barHeight+(20.0/float(ClientSize.y)));
|
||||
gInfo->valuePanel.setText(std::to_string(int(gInfo->current)));
|
||||
gInfo->valuePanel.setFill(GLPanel::GLPANEL_FILL_NONE);
|
||||
|
||||
bgPanel.addChild(&(gInfo->valuePanel));
|
||||
|
||||
bgPanel.addChild(&(gInfo->panel));
|
||||
gainInfo.push_back(gInfo);
|
||||
i++;
|
||||
}
|
||||
|
||||
setThemeColors();
|
||||
}
|
||||
|
||||
void GainCanvas::setThemeColors() {
|
||||
std::vector<GainInfo *>::iterator gi;
|
||||
|
||||
RGBA4f c1, c2;
|
||||
|
||||
c1 = ThemeMgr::mgr.currentTheme->generalBackground;
|
||||
c2 = ThemeMgr::mgr.currentTheme->generalBackground * 0.5;
|
||||
|
||||
bgPanel.setFillColor(c1, c2);
|
||||
|
||||
for (gi = gainInfo.begin(); gi != gainInfo.end(); gi++) {
|
||||
GainInfo *gInfo = (*gi);
|
||||
|
||||
c1 = ThemeMgr::mgr.currentTheme->generalBackground;
|
||||
c2 = ThemeMgr::mgr.currentTheme->generalBackground * 0.5;
|
||||
c1.a = 1.0;
|
||||
c2.a = 1.0;
|
||||
gInfo->panel.setFillColor(c1, c2);
|
||||
|
||||
c1 = ThemeMgr::mgr.currentTheme->meterLevel * 0.5;
|
||||
c2 = ThemeMgr::mgr.currentTheme->meterLevel;
|
||||
c1.a = 1.0;
|
||||
c2.a = 1.0;
|
||||
gInfo->levelPanel.setFillColor(c1, c2);
|
||||
|
||||
c1 = RGBA4f(0.3,0.3,0.3,1.0);
|
||||
c2 = RGBA4f(0.65,0.65,0.65,1.0);;
|
||||
gInfo->highlightPanel.setFillColor(c1, c2);
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "wx/glcanvas.h"
|
||||
#include "wx/timer.h"
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
#include "InteractiveCanvas.h"
|
||||
#include "MouseTracker.h"
|
||||
#include "GLPanel.h"
|
||||
#include "PrimaryGLContext.h"
|
||||
|
||||
#include "fftw3.h"
|
||||
#include "Timer.h"
|
||||
|
||||
class GainInfo {
|
||||
public:
|
||||
std::string name;
|
||||
float low, high, current;
|
||||
bool changed;
|
||||
GLPanel panel;
|
||||
GLPanel levelPanel;
|
||||
GLPanel highlightPanel;
|
||||
GLTextPanel labelPanel;
|
||||
GLTextPanel valuePanel;
|
||||
};
|
||||
|
||||
class GainCanvas: public InteractiveCanvas {
|
||||
public:
|
||||
GainCanvas(wxWindow *parent, int *attribList = NULL);
|
||||
~GainCanvas();
|
||||
|
||||
void setHelpTip(std::string tip);
|
||||
void updateGainUI();
|
||||
void setThemeColors();
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnIdle(wxIdleEvent &event);
|
||||
|
||||
int GetPanelHit(CubicVR::vec2 &result);
|
||||
void SetLevel();
|
||||
|
||||
void OnShow(wxShowEvent& event);
|
||||
void OnMouseMoved(wxMouseEvent& event);
|
||||
void OnMouseDown(wxMouseEvent& event);
|
||||
void OnMouseWheelMoved(wxMouseEvent& event);
|
||||
void OnMouseReleased(wxMouseEvent& event);
|
||||
void OnMouseEnterWindow(wxMouseEvent& event);
|
||||
void OnMouseLeftWindow(wxMouseEvent& event);
|
||||
|
||||
PrimaryGLContext *glContext;
|
||||
std::string helpTip;
|
||||
std::vector<GainInfo *> gainInfo;
|
||||
GLPanel bgPanel;
|
||||
|
||||
float spacing, barWidth, startPos, barHeight, numGains;
|
||||
wxSize clientSize;
|
||||
//
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
InteractiveCanvas::InteractiveCanvas(wxWindow *parent, int *attribList) :
|
||||
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
|
||||
wxFULL_REPAINT_ON_RESIZE), parent(parent), shiftDown(false), altDown(false), ctrlDown(false), centerFreq(0), bandwidth(0), lastBandwidth(0), isView(
|
||||
wxFULL_REPAINT_ON_RESIZE| wxWANTS_CHARS), parent(parent), shiftDown(false), altDown(false), ctrlDown(false), centerFreq(0), bandwidth(0), lastBandwidth(0), isView(
|
||||
false) {
|
||||
mouseTracker.setTarget(this);
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ public:
|
||||
|
||||
long long getFrequencyAt(float x);
|
||||
|
||||
void setView(long long center_freq_in, int bandwidth_in);
|
||||
void disableView();
|
||||
virtual void setView(long long center_freq_in, int bandwidth_in);
|
||||
virtual void disableView();
|
||||
bool getViewState();
|
||||
|
||||
void setCenterFrequency(long long center_freq_in);
|
||||
|
||||
@@ -25,6 +25,8 @@ EVT_LEFT_UP(SpectrumCanvas::OnMouseReleased)
|
||||
EVT_ENTER_WINDOW(SpectrumCanvas::OnMouseEnterWindow)
|
||||
EVT_LEAVE_WINDOW(SpectrumCanvas::OnMouseLeftWindow)
|
||||
EVT_MOUSEWHEEL(SpectrumCanvas::OnMouseWheelMoved)
|
||||
EVT_RIGHT_DOWN(SpectrumCanvas::OnMouseRightDown)
|
||||
EVT_RIGHT_UP(SpectrumCanvas::OnMouseRightReleased)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
|
||||
@@ -32,10 +34,13 @@ SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
|
||||
|
||||
glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));
|
||||
|
||||
mouseTracker.setVertDragLock(true);
|
||||
visualDataQueue.set_max_num_items(1);
|
||||
|
||||
SetCursor(wxCURSOR_SIZEWE);
|
||||
scaleFactor = 1.0;
|
||||
resetScaleFactor = false;
|
||||
scaleFactorEnabled = false;
|
||||
bwChange = 0.0;
|
||||
}
|
||||
|
||||
SpectrumCanvas::~SpectrumCanvas() {
|
||||
@@ -59,6 +64,15 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (resetScaleFactor) {
|
||||
scaleFactor += (1.0-scaleFactor)*0.05;
|
||||
if (fabs(scaleFactor-1.0) < 0.01) {
|
||||
scaleFactor = 1.0;
|
||||
resetScaleFactor = false;
|
||||
}
|
||||
updateScaleFactor(scaleFactor);
|
||||
}
|
||||
|
||||
|
||||
glContext->SetCurrent(*this);
|
||||
initGLExtensions();
|
||||
@@ -137,6 +151,34 @@ bool SpectrumCanvas::getShowDb() {
|
||||
return spectrumPanel.getShowDb();
|
||||
}
|
||||
|
||||
void SpectrumCanvas::setView(long long center_freq_in, int bandwidth_in) {
|
||||
bwChange += bandwidth_in-bandwidth;
|
||||
#define BW_RESET_TH 400000
|
||||
if (bwChange > BW_RESET_TH || bwChange < -BW_RESET_TH) {
|
||||
resetScaleFactor = true;
|
||||
bwChange = 0;
|
||||
}
|
||||
InteractiveCanvas::setView(center_freq_in, bandwidth_in);
|
||||
}
|
||||
|
||||
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();
|
||||
SpectrumVisualProcessor *wp = wdt->getProcessor();
|
||||
|
||||
scaleFactor = factor;
|
||||
sp->setScaleFactor(factor);
|
||||
wp->setScaleFactor(factor);
|
||||
}
|
||||
|
||||
void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseMoved(event);
|
||||
@@ -146,12 +188,32 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) {
|
||||
if (freqChange != 0) {
|
||||
moveCenterFrequency(freqChange);
|
||||
}
|
||||
}
|
||||
else if (scaleFactorEnabled && mouseTracker.mouseRightDown()) {
|
||||
|
||||
float yDelta = mouseTracker.getDeltaMouseY();
|
||||
|
||||
scaleFactor += yDelta*2.0;
|
||||
if (scaleFactor < 0.25) {
|
||||
scaleFactor = 0.25;
|
||||
}
|
||||
if (scaleFactor > 10.0) {
|
||||
scaleFactor = 10.0;
|
||||
}
|
||||
|
||||
resetScaleFactor = false;
|
||||
updateScaleFactor(scaleFactor);
|
||||
} else {
|
||||
setStatusText("Click and drag to adjust center frequency. 'B' to toggle decibels display.");
|
||||
if (scaleFactorEnabled) {
|
||||
setStatusText("Drag horizontal to adjust center frequency. Right-drag or SHIFT+UP/DOWN to adjust vertical scale; right-click to reset. 'B' to toggle decibels display.");
|
||||
} else {
|
||||
setStatusText("Displaying spectrum of active demodulator.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpectrumCanvas::OnMouseDown(wxMouseEvent& event) {
|
||||
mouseTracker.setVertDragLock(true);
|
||||
InteractiveCanvas::OnMouseDown(event);
|
||||
SetCursor(wxCURSOR_CROSS);
|
||||
}
|
||||
@@ -161,7 +223,8 @@ void SpectrumCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
|
||||
}
|
||||
|
||||
void SpectrumCanvas::OnMouseReleased(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseReleased(event);
|
||||
mouseTracker.setVertDragLock(false);
|
||||
InteractiveCanvas::OnMouseReleased(event);
|
||||
SetCursor(wxCURSOR_SIZEWE);
|
||||
}
|
||||
|
||||
@@ -182,3 +245,17 @@ void SpectrumCanvas::attachWaterfallCanvas(WaterfallCanvas* canvas_in) {
|
||||
SpectrumVisualDataQueue *SpectrumCanvas::getVisualDataQueue() {
|
||||
return &visualDataQueue;
|
||||
}
|
||||
|
||||
void SpectrumCanvas::OnMouseRightDown(wxMouseEvent& event) {
|
||||
mouseTracker.setHorizDragLock(true);
|
||||
mouseTracker.OnMouseRightDown(event);
|
||||
scaleFactor = wxGetApp().getSpectrumProcessor()->getScaleFactor();
|
||||
}
|
||||
|
||||
void SpectrumCanvas::OnMouseRightReleased(wxMouseEvent& event) {
|
||||
mouseTracker.setHorizDragLock(false);
|
||||
if (!mouseTracker.getOriginDeltaMouseY()) {
|
||||
resetScaleFactor = true;
|
||||
}
|
||||
mouseTracker.OnMouseRightReleased(event);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@ public:
|
||||
void setShowDb(bool showDb);
|
||||
bool getShowDb();
|
||||
|
||||
void setView(long long center_freq_in, int bandwidth_in);
|
||||
void disableView();
|
||||
|
||||
void setScaleFactorEnabled(bool en);
|
||||
|
||||
SpectrumVisualDataQueue *getVisualDataQueue();
|
||||
|
||||
private:
|
||||
@@ -35,10 +40,17 @@ private:
|
||||
void OnMouseReleased(wxMouseEvent& event);
|
||||
void OnMouseEnterWindow(wxMouseEvent& event);
|
||||
void OnMouseLeftWindow(wxMouseEvent& event);
|
||||
void OnMouseRightDown(wxMouseEvent& event);
|
||||
void OnMouseRightReleased(wxMouseEvent& event);
|
||||
|
||||
void updateScaleFactor(float factor);
|
||||
|
||||
PrimaryGLContext *glContext;
|
||||
WaterfallCanvas *waterfallCanvas;
|
||||
SpectrumPanel spectrumPanel;
|
||||
float scaleFactor;
|
||||
int bwChange;
|
||||
bool resetScaleFactor, scaleFactorEnabled;
|
||||
|
||||
SpectrumVisualDataQueue visualDataQueue;
|
||||
|
||||
|
||||
@@ -190,8 +190,8 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) {
|
||||
bw += amount;
|
||||
}
|
||||
|
||||
if (bw > wxGetApp().getSampleRate()) {
|
||||
bw = wxGetApp().getSampleRate();
|
||||
if (bw > CHANNELIZER_RATE_MAX) {
|
||||
bw = CHANNELIZER_RATE_MAX;
|
||||
}
|
||||
|
||||
wxGetApp().getDemodMgr().setLastBandwidth(bw);
|
||||
|
||||
@@ -43,6 +43,7 @@ WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
|
||||
lpsIndex = 0;
|
||||
preBuf = false;
|
||||
SetCursor(wxCURSOR_CROSS);
|
||||
scaleMove = 0;
|
||||
}
|
||||
|
||||
WaterfallCanvas::~WaterfallCanvas() {
|
||||
@@ -72,19 +73,16 @@ void WaterfallCanvas::attachSpectrumCanvas(SpectrumCanvas *canvas_in) {
|
||||
}
|
||||
|
||||
void WaterfallCanvas::processInputQueue() {
|
||||
if (!glContext) {
|
||||
return;
|
||||
}
|
||||
glContext->SetCurrent(*this);
|
||||
tex_update.lock();
|
||||
|
||||
gTimer.update();
|
||||
|
||||
double targetVis = 1.0 / (double)linesPerSecond;
|
||||
lpsIndex += gTimer.lastUpdateSeconds();
|
||||
|
||||
bool updated = false;
|
||||
if (linesPerSecond) {
|
||||
if (lpsIndex >= targetVis) {
|
||||
tex_update.lock();
|
||||
while (lpsIndex >= targetVis) {
|
||||
SpectrumVisualData *vData;
|
||||
if (!visualDataQueue.empty()) {
|
||||
@@ -94,21 +92,27 @@ void WaterfallCanvas::processInputQueue() {
|
||||
waterfallPanel.setPoints(vData->spectrum_points);
|
||||
waterfallPanel.step();
|
||||
vData->decRefCount();
|
||||
updated = true;
|
||||
}
|
||||
lpsIndex-=targetVis;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
tex_update.unlock();
|
||||
}
|
||||
}}
|
||||
}
|
||||
if (updated) {
|
||||
wxClientDC(this);
|
||||
glContext->SetCurrent(*this);
|
||||
waterfallPanel.update();
|
||||
}
|
||||
tex_update.unlock();
|
||||
}
|
||||
|
||||
void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
tex_update.lock();
|
||||
wxPaintDC dc(this);
|
||||
|
||||
processInputQueue();
|
||||
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
long double currentZoom = zoom;
|
||||
|
||||
@@ -120,9 +124,33 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (scaleMove != 0) {
|
||||
SpectrumVisualProcessor *sp = wxGetApp().getSpectrumProcessor();
|
||||
FFTVisualDataThread *wdt = wxGetApp().getAppFrame()->getWaterfallDataThread();
|
||||
SpectrumVisualProcessor *wp = wdt->getProcessor();
|
||||
float factor = sp->getScaleFactor();
|
||||
|
||||
factor += scaleMove * 0.02;
|
||||
|
||||
if (factor < 0.25) {
|
||||
factor = 0.25;
|
||||
}
|
||||
if (factor > 10.0) {
|
||||
factor = 10.0;
|
||||
}
|
||||
|
||||
sp->setScaleFactor(factor);
|
||||
wp->setScaleFactor(factor);
|
||||
}
|
||||
|
||||
if (freqMove != 0.0) {
|
||||
long long newFreq = getCenterFrequency() + (long long)((long double)getBandwidth()*freqMove) * 0.01;
|
||||
|
||||
long long minFreq = bandwidth/2;
|
||||
if (newFreq < minFreq) {
|
||||
newFreq = minFreq;
|
||||
}
|
||||
|
||||
updateCenterFrequency(newFreq);
|
||||
|
||||
if (!freqMoving) {
|
||||
@@ -211,9 +239,7 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
glContext->BeginDraw(0,0,0);
|
||||
|
||||
waterfallPanel.calcTransform(CubicVR::mat4::identity());
|
||||
tex_update.lock();
|
||||
waterfallPanel.draw();
|
||||
tex_update.unlock();
|
||||
|
||||
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
|
||||
|
||||
@@ -293,6 +319,7 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
glContext->EndDraw();
|
||||
|
||||
SwapBuffers();
|
||||
tex_update.unlock();
|
||||
}
|
||||
|
||||
void WaterfallCanvas::OnKeyUp(wxKeyEvent& event) {
|
||||
@@ -304,14 +331,20 @@ void WaterfallCanvas::OnKeyUp(wxKeyEvent& event) {
|
||||
case 'A':
|
||||
case WXK_UP:
|
||||
case WXK_NUMPAD_UP:
|
||||
scaleMove = 0.0;
|
||||
zoom = 1.0;
|
||||
mouseZoom = 0.95;
|
||||
if (mouseZoom != 1.0) {
|
||||
mouseZoom = 0.95;
|
||||
}
|
||||
break;
|
||||
case 'Z':
|
||||
case WXK_DOWN:
|
||||
case WXK_NUMPAD_DOWN:
|
||||
scaleMove = 0.0;
|
||||
zoom = 1.0;
|
||||
mouseZoom = 1.05;
|
||||
if (mouseZoom != 1.0) {
|
||||
mouseZoom = 1.05;
|
||||
}
|
||||
break;
|
||||
case WXK_LEFT:
|
||||
case WXK_NUMPAD_LEFT:
|
||||
@@ -334,14 +367,22 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
|
||||
case 'A':
|
||||
case WXK_UP:
|
||||
case WXK_NUMPAD_UP:
|
||||
mouseZoom = 1.0;
|
||||
zoom = 0.95;
|
||||
if (!shiftDown) {
|
||||
mouseZoom = 1.0;
|
||||
zoom = 0.95;
|
||||
} else {
|
||||
scaleMove = 1.0;
|
||||
}
|
||||
break;
|
||||
case 'Z':
|
||||
case WXK_DOWN:
|
||||
case WXK_NUMPAD_DOWN:
|
||||
mouseZoom = 1.0;
|
||||
zoom = 1.05;
|
||||
if (!shiftDown) {
|
||||
mouseZoom = 1.0;
|
||||
zoom = 1.05;
|
||||
} else {
|
||||
scaleMove = -1.0;
|
||||
}
|
||||
break;
|
||||
case WXK_RIGHT:
|
||||
case WXK_NUMPAD_RIGHT:
|
||||
@@ -398,7 +439,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
|
||||
return;
|
||||
}
|
||||
|
||||
long long minFreq = wxGetApp().getSampleRate()/2;
|
||||
long long minFreq = bandwidth/2;
|
||||
if (freq < minFreq) {
|
||||
freq = minFreq;
|
||||
}
|
||||
@@ -409,11 +450,9 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
|
||||
|
||||
}
|
||||
void WaterfallCanvas::OnIdle(wxIdleEvent &event) {
|
||||
processInputQueue();
|
||||
Refresh();
|
||||
event.RequestMore();
|
||||
if (visualDataQueue.size() > linesPerSecond) {
|
||||
processInputQueue();
|
||||
}
|
||||
}
|
||||
|
||||
void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) {
|
||||
@@ -435,8 +474,8 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) {
|
||||
int currentBW = demod->getBandwidth();
|
||||
|
||||
currentBW = currentBW + bwDiff;
|
||||
if (currentBW > wxGetApp().getSampleRate()) {
|
||||
currentBW = wxGetApp().getSampleRate();
|
||||
if (currentBW > CHANNELIZER_RATE_MAX) {
|
||||
currentBW = CHANNELIZER_RATE_MAX;
|
||||
}
|
||||
if (currentBW < MIN_BANDWIDTH) {
|
||||
currentBW = MIN_BANDWIDTH;
|
||||
@@ -802,6 +841,7 @@ void WaterfallCanvas::updateCenterFrequency(long long freq) {
|
||||
}
|
||||
|
||||
void WaterfallCanvas::setLinesPerSecond(int lps) {
|
||||
tex_update.lock();
|
||||
linesPerSecond = lps;
|
||||
while (!visualDataQueue.empty()) {
|
||||
SpectrumVisualData *vData;
|
||||
@@ -811,7 +851,7 @@ void WaterfallCanvas::setLinesPerSecond(int lps) {
|
||||
vData->decRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
tex_update.unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ private:
|
||||
long double freqMove;
|
||||
float hoverAlpha;
|
||||
int linesPerSecond;
|
||||
float scaleMove;
|
||||
|
||||
SpectrumVisualDataQueue visualDataQueue;
|
||||
Timer gTimer;
|
||||
|
||||
Reference in New Issue
Block a user