mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-02 22:14:47 -04:00
Add functional Spectrum view to demodulator visuals
- Might need to do some renaming from Scope->AVDisplay or something for ScopeCanvas to avoid confusion.
This commit is contained in:
+108
-28
@@ -28,20 +28,51 @@ EVT_LEAVE_WINDOW(ScopeCanvas::OnMouseLeftWindow)
|
||||
EVT_ENTER_WINDOW(ScopeCanvas::OnMouseEnterWindow)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
ScopeCanvas::ScopeCanvas(wxWindow *parent, int *attribList) : InteractiveCanvas(parent, attribList), stereo(false), ppmMode(false), ctr(0), ctrTarget(0), dragAccel(0) {
|
||||
ScopeCanvas::ScopeCanvas(wxWindow *parent, int *attribList) : InteractiveCanvas(parent, attribList), stereo(false), ppmMode(false), ctr(0), ctrTarget(0), dragAccel(0), helpTip("") {
|
||||
|
||||
glContext = new ScopeContext(this, &wxGetApp().GetContext(this));
|
||||
inputData.set_max_num_items(1);
|
||||
inputData.set_max_num_items(2);
|
||||
bgPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_Y);
|
||||
bgPanel.setSize(1.0, 0.5);
|
||||
bgPanel.setPosition(0.0, -0.5);
|
||||
panelSpacing = 0.2;
|
||||
panelSpacing = 0.4;
|
||||
|
||||
parentPanel.addChild(&scopePanel);
|
||||
parentPanel.addChild(&spectrumPanel);
|
||||
parentPanel.setFill(GLPanel::GLPANEL_FILL_NONE);
|
||||
scopePanel.setSize(1.0,-1.0);
|
||||
spectrumPanel.setSize(1.0,-1.0);
|
||||
spectrumPanel.setShowDb(true);
|
||||
}
|
||||
|
||||
ScopeCanvas::~ScopeCanvas() {
|
||||
|
||||
}
|
||||
|
||||
bool ScopeCanvas::scopeVisible() {
|
||||
float panelInterval = (2.0 + panelSpacing);
|
||||
|
||||
ctrTarget = abs(round(ctr / panelInterval));
|
||||
|
||||
if (ctrTarget == 0 || dragAccel || (ctr != ctrTarget)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ScopeCanvas::spectrumVisible() {
|
||||
float panelInterval = (2.0 + panelSpacing);
|
||||
|
||||
ctrTarget = abs(round(ctr / panelInterval));
|
||||
|
||||
if (ctrTarget == 1 || dragAccel || (ctr != ctrTarget)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScopeCanvas::setStereo(bool state) {
|
||||
stereo = state;
|
||||
}
|
||||
@@ -59,20 +90,40 @@ bool ScopeCanvas::getPPMMode() {
|
||||
return ppmMode;
|
||||
}
|
||||
|
||||
void ScopeCanvas::setShowDb(bool showDb) {
|
||||
this->showDb = showDb;
|
||||
}
|
||||
|
||||
bool ScopeCanvas::getShowDb() {
|
||||
return showDb;
|
||||
}
|
||||
|
||||
void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
wxPaintDC dc(this);
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
|
||||
if (!inputData.empty()) {
|
||||
while (!inputData.empty()) {
|
||||
ScopeRenderData *avData;
|
||||
inputData.pop(avData);
|
||||
|
||||
if (avData) {
|
||||
if (!avData->spectrum) {
|
||||
if (avData->waveform_points.size()) {
|
||||
scopePanel.setPoints(avData->waveform_points);
|
||||
setStereo(avData->channels == 2);
|
||||
}
|
||||
|
||||
avData->decRefCount();
|
||||
} else {
|
||||
if (avData->waveform_points.size()) {
|
||||
spectrumPanel.setPoints(avData->waveform_points);
|
||||
spectrumPanel.setFloorValue(avData->fft_floor);
|
||||
spectrumPanel.setCeilValue(avData->fft_ceil);
|
||||
spectrumPanel.setBandwidth((avData->sampleRate/2)*1000);
|
||||
spectrumPanel.setFreq((avData->sampleRate/4)*1000);
|
||||
spectrumPanel.setFFTSize(avData->fft_size);
|
||||
spectrumPanel.setShowDb(showDb);
|
||||
}
|
||||
|
||||
avData->decRefCount();
|
||||
}
|
||||
}
|
||||
@@ -96,53 +147,74 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
CubicVR::mat4 modelView = CubicVR::mat4::lookat(0, 0, -1.2, 0, 0, 0, 0, -1, 0);
|
||||
CubicVR::mat4 modelView = CubicVR::mat4::lookat(0, 0, -1.205, 0, 0, 0, 0, -1, 0);
|
||||
|
||||
float panelWidth = 1.0;
|
||||
float panelInterval = (panelWidth * 2.0 + panelSpacing);
|
||||
|
||||
if (!mouseTracker.mouseDown()) {
|
||||
ctrTarget = round(ctr / panelInterval);
|
||||
if (ctrTarget < -1.0) {
|
||||
ctrTarget = -1.0;
|
||||
} else if (ctrTarget > 0.0) {
|
||||
ctrTarget = 0.0;
|
||||
}
|
||||
ctrTarget *= panelInterval;
|
||||
if (!dragAccel) {
|
||||
ctrTarget = round(ctr / panelInterval);
|
||||
if (ctrTarget < -1.0) {
|
||||
ctrTarget = -1.0;
|
||||
} else if (ctrTarget > 0.0) {
|
||||
ctrTarget = 0.0;
|
||||
}
|
||||
ctrTarget *= panelInterval;
|
||||
if (ctr != ctrTarget) {
|
||||
ctr += (ctrTarget-ctr)*0.2;
|
||||
}
|
||||
if (abs(ctr - ctrTarget) < 0.001) {
|
||||
ctr=ctrTarget;
|
||||
}
|
||||
} else {
|
||||
dragAccel -= dragAccel * 0.01;
|
||||
if (abs(dragAccel) < 0.1 || ctr < ctrTarget-panelInterval/2.0 || ctr > ctrTarget+panelInterval/2.0 ) {
|
||||
dragAccel -= dragAccel * 0.1;
|
||||
if ((abs(dragAccel) < 0.2) || (ctr < (ctrTarget-panelInterval/2.0)) || (ctr > (ctrTarget+panelInterval/2.0)) ) {
|
||||
dragAccel = 0;
|
||||
} else {
|
||||
ctr += dragAccel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float roty = 0;
|
||||
|
||||
scopePanel.setPosition(ctr, 0);
|
||||
float roty = atan2(scopePanel.pos[0],1.2);
|
||||
scopePanel.rot[1] = -(roty * (180.0 / M_PI));
|
||||
scopePanel.calcTransform(modelView);
|
||||
scopePanel.draw();
|
||||
if (scopeVisible()) {
|
||||
scopePanel.contentsVisible = true;
|
||||
roty = atan2(scopePanel.pos[0],1.2);
|
||||
scopePanel.rot[1] = -(roty * (180.0 / M_PI));
|
||||
} else {
|
||||
scopePanel.contentsVisible = false;
|
||||
}
|
||||
|
||||
spectrumPanel.setPosition(panelInterval+ctr, 0);
|
||||
if (spectrumVisible()) {
|
||||
spectrumPanel.setFillColor(ThemeMgr::mgr.currentTheme->scopeBackground * 2.0, RGBA4f(0,0,0,0));
|
||||
spectrumPanel.contentsVisible = true;
|
||||
roty = atan2(spectrumPanel.pos[0],1.2);
|
||||
spectrumPanel.rot[1] = -(roty * (180.0 / M_PI));
|
||||
} else {
|
||||
spectrumPanel.contentsVisible = false;
|
||||
}
|
||||
|
||||
scopePanel.setPosition(panelInterval+ctr, 0);
|
||||
roty = atan2(scopePanel.pos[0],1.2);
|
||||
scopePanel.rot[1] = -(roty * (180.0 / M_PI));
|
||||
scopePanel.calcTransform(modelView);
|
||||
scopePanel.draw();
|
||||
parentPanel.calcTransform(modelView);
|
||||
parentPanel.draw();
|
||||
|
||||
if (spectrumVisible()) {
|
||||
spectrumPanel.drawChildren();
|
||||
}
|
||||
|
||||
glLoadMatrixf(scopePanel.transform);
|
||||
if (!deviceName.empty()) {
|
||||
glContext->DrawDeviceName(deviceName);
|
||||
}
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glContext->DrawTunerTitles(ppmMode);
|
||||
if (!deviceName.empty()) {
|
||||
glContext->DrawDeviceName(deviceName);
|
||||
}
|
||||
glContext->DrawEnd();
|
||||
|
||||
SwapBuffers();
|
||||
@@ -182,7 +254,10 @@ void ScopeCanvas::OnMouseReleased(wxMouseEvent& event) {
|
||||
|
||||
void ScopeCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseEnterWindow(event);
|
||||
|
||||
if (!helpTip.empty()) {
|
||||
setStatusText(helpTip);
|
||||
}
|
||||
SetCursor(wxCURSOR_SIZEWE);
|
||||
}
|
||||
|
||||
void ScopeCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
|
||||
@@ -190,3 +265,8 @@ void ScopeCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ScopeCanvas::setHelpTip(std::string tip) {
|
||||
helpTip = tip;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "ScopeContext.h"
|
||||
#include "ScopeVisualProcessor.h"
|
||||
#include "ScopePanel.h"
|
||||
#include "SpectrumPanel.h"
|
||||
#include "fftw3.h"
|
||||
#include "InteractiveCanvas.h"
|
||||
|
||||
@@ -22,6 +23,14 @@ public:
|
||||
void setPPMMode(bool ppmMode);
|
||||
bool getPPMMode();
|
||||
|
||||
void setShowDb(bool showDb);
|
||||
bool getShowDb();
|
||||
|
||||
bool scopeVisible();
|
||||
bool spectrumVisible();
|
||||
|
||||
void setHelpTip(std::string tip);
|
||||
|
||||
ScopeRenderDataQueue *getInputQueue();
|
||||
|
||||
private:
|
||||
@@ -36,15 +45,19 @@ private:
|
||||
|
||||
ScopeRenderDataQueue inputData;
|
||||
ScopePanel scopePanel;
|
||||
GLPanel parentPanel;
|
||||
SpectrumPanel spectrumPanel;
|
||||
GLPanel bgPanel;
|
||||
ScopeContext *glContext;
|
||||
std::string deviceName;
|
||||
bool stereo;
|
||||
bool ppmMode;
|
||||
bool showDb;
|
||||
float panelSpacing;
|
||||
float ctr;
|
||||
float ctrTarget;
|
||||
float dragAccel;
|
||||
std::string helpTip;
|
||||
// event table
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user