Merge pull request #127 from cjcliffe/master

Digital lab update
This commit is contained in:
Charles J. Cliffe
2015-08-10 19:11:18 -04:00
36 changed files with 534 additions and 411 deletions
+3
View File
@@ -35,6 +35,9 @@ public:
b = other.b;
return *this;
}
RGB3f operator*(float v) { return RGB3f(r*v, g*v, b*v); }
};
class ColorTheme {
+2 -4
View File
@@ -60,9 +60,6 @@ float MeterCanvas::getInputValue() {
void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize();
glContext->SetCurrent(*this);
@@ -82,7 +79,7 @@ void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
}
void MeterCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false);
event.Skip();
}
void MeterCanvas::OnMouseMoved(wxMouseEvent& event) {
@@ -115,6 +112,7 @@ void MeterCanvas::OnMouseReleased(wxMouseEvent& event) {
void MeterCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseLeftWindow(event);
SetCursor(wxCURSOR_CROSS);
Refresh();
}
void MeterCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
+3 -5
View File
@@ -47,10 +47,7 @@ int ModeSelectorCanvas::getHoveredSelection() {
void ModeSelectorCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize();
const wxSize ClientSize = GetClientSize();
glContext->SetCurrent(*this);
initGLExtensions();
@@ -75,7 +72,7 @@ void ModeSelectorCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
}
void ModeSelectorCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false);
event.Skip();
}
void ModeSelectorCanvas::OnMouseMoved(wxMouseEvent& event) {
@@ -109,6 +106,7 @@ void ModeSelectorCanvas::OnMouseReleased(wxMouseEvent& event) {
void ModeSelectorCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseLeftWindow(event);
SetCursor (wxCURSOR_CROSS);
Refresh();
}
void ModeSelectorCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
+12 -19
View File
@@ -15,6 +15,7 @@
#include "AppFrame.h"
#include <algorithm>
wxBEGIN_EVENT_TABLE(ScopeCanvas, wxGLCanvas) EVT_PAINT(ScopeCanvas::OnPaint)
EVT_IDLE(ScopeCanvas::OnIdle)
wxEND_EVENT_TABLE()
@@ -50,31 +51,20 @@ bool ScopeCanvas::getPPMMode() {
void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize();
wxGetApp().getScopeProcessor()->run();
if (!inputData.empty()) {
ScopeRenderData *avData;
inputData.pop(avData);
if (!avData) {
return;
}
int iMax = avData->waveform_points.size();
if (!iMax) {
if (avData) {
if (avData->waveform_points.size()) {
scopePanel.setPoints(avData->waveform_points);
setStereo(avData->channels == 2);
}
avData->decRefCount();
return;
}
waveform_points.assign(avData->waveform_points.begin(),avData->waveform_points.end());
setStereo(avData->channels == 2);
avData->decRefCount();
}
glContext->SetCurrent(*this);
@@ -83,7 +73,10 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
glViewport(0, 0, ClientSize.x, ClientSize.y);
glContext->DrawBegin();
glContext->Plot(waveform_points, stereo, ppmMode);
scopePanel.setMode(stereo?ScopePanel::SCOPE_MODE_2Y:ScopePanel::SCOPE_MODE_Y);
scopePanel.calcTransform(CubicVR::mat4::identity());
scopePanel.draw();
glContext->DrawTunerTitles(ppmMode);
if (!deviceName.empty()) {
glContext->DrawDeviceName(deviceName);
}
@@ -94,7 +87,7 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
}
void ScopeCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false);
event.Skip();
}
ScopeRenderDataQueue *ScopeCanvas::getInputQueue() {
+2 -2
View File
@@ -8,12 +8,11 @@
#include "ScopeContext.h"
#include "ScopeVisualProcessor.h"
#include "ScopePanel.h"
#include "fftw3.h"
class ScopeCanvas: public wxGLCanvas {
public:
std::vector<float> waveform_points;
ScopeCanvas(wxWindow *parent, int *attribList = NULL);
~ScopeCanvas();
@@ -29,6 +28,7 @@ private:
void OnIdle(wxIdleEvent &event);
ScopeRenderDataQueue inputData;
ScopePanel scopePanel;
ScopeContext *glContext;
std::string deviceName;
bool stereo;
+2 -108
View File
@@ -23,56 +23,8 @@ void ScopeContext::DrawBegin() {
glDisable (GL_TEXTURE_2D);
}
void ScopeContext::Plot(std::vector<float> &points, bool stereo, bool ppmMode) {
if (stereo) {
glBegin(GL_QUADS);
glColor3f(ThemeMgr::mgr.currentTheme->scopeBackground.r, ThemeMgr::mgr.currentTheme->scopeBackground.g, ThemeMgr::mgr.currentTheme->scopeBackground.b);
glVertex2f(1, 1);
glVertex2f(-1, 1);
glColor3f(ThemeMgr::mgr.currentTheme->scopeBackground.r*2.0, ThemeMgr::mgr.currentTheme->scopeBackground.g*2.0, ThemeMgr::mgr.currentTheme->scopeBackground.b*2.0);
glVertex2f(-1, 0.5);
glVertex2f(1, 0.5);
glVertex2f(-1, 0.5);
glVertex2f(1, 0.5);
glColor3f(ThemeMgr::mgr.currentTheme->scopeBackground.r, ThemeMgr::mgr.currentTheme->scopeBackground.g, ThemeMgr::mgr.currentTheme->scopeBackground.b);
glVertex2f(1, 0.0);
glVertex2f(-1, 0.0);
glColor3f(ThemeMgr::mgr.currentTheme->scopeBackground.r, ThemeMgr::mgr.currentTheme->scopeBackground.g, ThemeMgr::mgr.currentTheme->scopeBackground.b);
glVertex2f(1, 0);
glVertex2f(-1, 0);
glColor3f(ThemeMgr::mgr.currentTheme->scopeBackground.r*2.0, ThemeMgr::mgr.currentTheme->scopeBackground.g*2.0, ThemeMgr::mgr.currentTheme->scopeBackground.b*2.0);
glVertex2f(-1, -0.5);
glVertex2f(1, -0.5);
glVertex2f(-1, -0.5);
glVertex2f(1, -0.5);
glColor3f(ThemeMgr::mgr.currentTheme->scopeBackground.r, ThemeMgr::mgr.currentTheme->scopeBackground.g, ThemeMgr::mgr.currentTheme->scopeBackground.b);
glVertex2f(1, -1.0);
glVertex2f(-1, -1.0);
glEnd();
} else {
glBegin (GL_QUADS);
glColor3f(ThemeMgr::mgr.currentTheme->scopeBackground.r, ThemeMgr::mgr.currentTheme->scopeBackground.g,
ThemeMgr::mgr.currentTheme->scopeBackground.b);
glVertex2f(1, 1);
glVertex2f(-1, 1);
glColor3f(ThemeMgr::mgr.currentTheme->scopeBackground.r * 2.0, ThemeMgr::mgr.currentTheme->scopeBackground.g * 2.0,
ThemeMgr::mgr.currentTheme->scopeBackground.b * 2.0);
glVertex2f(-1, 0);
glVertex2f(1, 0);
glVertex2f(-1, 0);
glVertex2f(1, 0);
glColor3f(ThemeMgr::mgr.currentTheme->scopeBackground.r, ThemeMgr::mgr.currentTheme->scopeBackground.g,
ThemeMgr::mgr.currentTheme->scopeBackground.b);
glVertex2f(1, -1);
glVertex2f(-1, -1);
glEnd();
}
glLineWidth(1.0);
void ScopeContext::DrawTunerTitles(bool ppmMode) {
glLoadIdentity();
GLint vp[4];
glGetIntegerv(GL_VIEWPORT, vp);
@@ -84,64 +36,6 @@ void ScopeContext::Plot(std::vector<float> &points, bool stereo, bool ppmMode) {
GLFont::getFont(GLFont::GLFONT_SIZE12).drawString(ppmMode?"Device PPM":"Frequency", -0.66, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
GLFont::getFont(GLFont::GLFONT_SIZE12).drawString("Bandwidth", 0.0, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
GLFont::getFont(GLFont::GLFONT_SIZE12).drawString("Center Frequency", 0.66, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
if (stereo) {
glColor3f(ThemeMgr::mgr.currentTheme->scopeLine.r, ThemeMgr::mgr.currentTheme->scopeLine.g, ThemeMgr::mgr.currentTheme->scopeLine.b);
glBegin (GL_LINES);
glVertex2f(-1.0, 0.0);
glVertex2f(1.0, 0.0);
glColor3f(ThemeMgr::mgr.currentTheme->scopeLine.r * 0.35, ThemeMgr::mgr.currentTheme->scopeLine.g * 0.35,
ThemeMgr::mgr.currentTheme->scopeLine.b * 0.35);
glVertex2f(-1.0, 0.5);
glVertex2f(1.0, 0.5);
glVertex2f(-1.0, -0.5);
glVertex2f(1.0, -0.5);
glEnd();
} else {
glColor3f(ThemeMgr::mgr.currentTheme->scopeLine.r * 0.35, ThemeMgr::mgr.currentTheme->scopeLine.g * 0.35,
ThemeMgr::mgr.currentTheme->scopeLine.b * 0.35);
glBegin (GL_LINES);
glVertex2f(-1.0, 0.0);
glVertex2f(1.0, 0.0);
glEnd();
}
if (points.size()) {
glEnable (GL_BLEND);
glEnable (GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(ThemeMgr::mgr.currentTheme->scopeLine.r, ThemeMgr::mgr.currentTheme->scopeLine.g, ThemeMgr::mgr.currentTheme->scopeLine.b, 1.0);
glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, &points[0]);
if (stereo) {
glLineWidth(1.5);
glPushMatrix();
glTranslatef(-1.0f, 0.5f, 0.0f);
glScalef(4.0f, 0.92f, 1.0f);
glDrawArrays(GL_LINE_STRIP, 0, points.size() / 4);
glPopMatrix();
glPushMatrix();
glTranslatef(-3.0f, -0.5f, 0.0f);
glPushMatrix();
glScalef(4.0f, 0.92f, 1.0f);
glDrawArrays(GL_LINE_STRIP, points.size() / 4, points.size() / 4);
glPopMatrix();
glPopMatrix();
} else {
glLineWidth(1.5);
glPushMatrix();
glTranslatef(-1.0f, 0.0f, 0.0f);
glScalef(2.0f, 2.0f, 1.0f);
glDrawArrays(GL_LINE_STRIP, 0, points.size() / 2);
glPopMatrix();
}
glLineWidth(1.0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisable(GL_BLEND);
}
}
void ScopeContext::DrawDeviceName(std::string deviceName) {
+1 -1
View File
@@ -12,7 +12,7 @@ public:
ScopeContext(ScopeCanvas *canvas, wxGLContext *sharedContext);
void DrawBegin();
void Plot(std::vector<float> &points, bool stereo=false, bool ppmMode=false);
void DrawTunerTitles(bool ppmMode=false);
void DrawDeviceName(std::string deviceName);
void DrawDivider();
void DrawEnd();
+20 -24
View File
@@ -29,7 +29,7 @@ wxEND_EVENT_TABLE()
SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), waterfallCanvas(NULL) {
glContext = new SpectrumContext(this, &wxGetApp().GetContext(this));
glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));
mouseTracker.setVertDragLock(true);
@@ -42,35 +42,35 @@ SpectrumCanvas::~SpectrumCanvas() {
void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize();
if (visualDataQueue.empty()) {
return;
if (!visualDataQueue.empty()) {
SpectrumVisualData *vData;
visualDataQueue.pop(vData);
if (vData) {
spectrumPanel.setPoints(vData->spectrum_points);
spectrumPanel.setFloorValue(vData->fft_floor);
spectrumPanel.setCeilValue(vData->fft_ceiling);
vData->decRefCount();
}
}
SpectrumVisualData *vData;
visualDataQueue.pop(vData);
if (!vData) {
return;
}
spectrum_points.assign(vData->spectrum_points.begin(),vData->spectrum_points.end());
vData->decRefCount();
glContext->SetCurrent(*this);
initGLExtensions();
glViewport(0, 0, ClientSize.x, ClientSize.y);
glContext->BeginDraw(ThemeMgr::mgr.currentTheme->fftBackground.r, ThemeMgr::mgr.currentTheme->fftBackground.g, ThemeMgr::mgr.currentTheme->fftBackground.b);
glContext->Draw(spectrum_points, getCenterFrequency(), getBandwidth());
glContext->BeginDraw(0,0,0);
spectrumPanel.setFreq(getCenterFrequency());
spectrumPanel.setBandwidth(getBandwidth());
spectrumPanel.calcTransform(CubicVR::mat4::identity());
spectrumPanel.draw();
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
@@ -84,7 +84,7 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
void SpectrumCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false);
event.Skip();
}
@@ -159,10 +159,6 @@ void SpectrumCanvas::attachWaterfallCanvas(WaterfallCanvas* canvas_in) {
waterfallCanvas = canvas_in;
}
SpectrumContext* SpectrumCanvas::getSpectrumContext() {
return glContext;
}
SpectrumVisualDataQueue *SpectrumCanvas::getVisualDataQueue() {
return &visualDataQueue;
}
+4 -10
View File
@@ -1,31 +1,24 @@
#pragma once
#include "wx/glcanvas.h"
#include "wx/timer.h"
#include <vector>
#include <queue>
#include "InteractiveCanvas.h"
#include "SpectrumContext.h"
#include "fftw3.h"
#include "PrimaryGLContext.h"
#include "MouseTracker.h"
#include "SpectrumVisualProcessor.h"
#include "SpectrumPanel.h"
class WaterfallCanvas;
class SpectrumCanvas: public InteractiveCanvas {
public:
std::vector<float> spectrum_points;
SpectrumCanvas(wxWindow *parent, int *attribList = NULL);
~SpectrumCanvas();
void attachWaterfallCanvas(WaterfallCanvas *canvas_in);
void moveCenterFrequency(long long freqChange);
SpectrumContext* getSpectrumContext();
SpectrumVisualDataQueue *getVisualDataQueue();
private:
@@ -39,8 +32,9 @@ private:
void OnMouseReleased(wxMouseEvent& event);
void OnMouseLeftWindow(wxMouseEvent& event);
SpectrumContext *glContext;
PrimaryGLContext *glContext;
WaterfallCanvas *waterfallCanvas;
SpectrumPanel spectrumPanel;
SpectrumVisualDataQueue visualDataQueue;
-161
View File
@@ -1,161 +0,0 @@
#include "SpectrumContext.h"
#include "SpectrumCanvas.h"
#include "CubicSDR.h"
#include <sstream>
#include <iostream>
#include "ColorTheme.h"
SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedContext) :
PrimaryGLContext(canvas, sharedContext), floorValue(0), ceilValue(1) {
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
float SpectrumContext::getFloorValue() const {
return floorValue;
}
void SpectrumContext::setFloorValue(float floorValue) {
this->floorValue = floorValue;
}
float SpectrumContext::getCeilValue() const {
return ceilValue;
}
void SpectrumContext::setCeilValue(float ceilValue) {
this->ceilValue = ceilValue;
}
void SpectrumContext::Draw(std::vector<float> &points, long long freq, int bandwidth) {
glBegin(GL_QUADS);
glColor3f(ThemeMgr::mgr.currentTheme->fftBackground.r, ThemeMgr::mgr.currentTheme->fftBackground.g, ThemeMgr::mgr.currentTheme->fftBackground.b);
glVertex2f(1, 0.5);
glVertex2f(-1, 0.5);
glColor3f(ThemeMgr::mgr.currentTheme->fftBackground.r*2.0, ThemeMgr::mgr.currentTheme->fftBackground.g*2.0, ThemeMgr::mgr.currentTheme->fftBackground.b*2.0);
glVertex2f(-1, -1);
glVertex2f(1, -1);
glEnd();
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
if (points.size()) {
glPushMatrix();
glTranslatef(-1.0f, -0.75f, 0.0f);
glScalef(2.0f, 1.5f, 1.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
float range = ceilValue-floorValue;
float ranges[3][4] = { { 90.0, 5000.0, 10.0, 100.0 }, { 20.0, 150.0, 10.0, 10.0 }, { -20.0, 30.0, 10.0, 1.0 } };
for (int i = 0; i < 3; i++) {
float p = 0;
float rangeMin = ranges[i][0];
float rangeMax = ranges[i][1];
float rangeTrans = ranges[i][2];
float rangeStep = ranges[i][3];
if (range >= rangeMin && range <= rangeMax) {
float a = 1.0;
if (range <= rangeMin+rangeTrans) {
a *= (range-rangeMin)/rangeTrans;
}
if (range >= rangeMax-rangeTrans) {
a *= (rangeTrans-(range-(rangeMax-rangeTrans)))/rangeTrans;
}
glColor4f(0.12, 0.12, 0.12, a);
glBegin(GL_LINES);
for (float l = floorValue; l<=ceilValue+rangeStep; l+=rangeStep) {
p += rangeStep/range;
glVertex2f(0,p); glVertex2f(1,p);
}
glEnd();
}
}
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor3f(ThemeMgr::mgr.currentTheme->fftLine.r, ThemeMgr::mgr.currentTheme->fftLine.g, ThemeMgr::mgr.currentTheme->fftLine.b);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, &points[0]);
glDrawArrays(GL_LINE_STRIP, 0, points.size() / 2);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
GLint vp[4];
glGetIntegerv( GL_VIEWPORT, vp);
float viewHeight = (float) vp[3];
float viewWidth = (float) vp[2];
long long leftFreq = (float) freq - ((float) bandwidth / 2.0);
long long rightFreq = leftFreq + (float) bandwidth;
long long firstMhz = (leftFreq / 1000000) * 1000000;
long double mhzStart = ((long double) (firstMhz - leftFreq) / (long double) (rightFreq - leftFreq)) * 2.0;
long double mhzStep = (100000.0 / (long double) (rightFreq - leftFreq)) * 2.0;
float mhzVisualStep = 0.1f;
if (mhzStep * 0.5 * viewWidth > 400) {
mhzStep = (10000.0 / (long double) (rightFreq - leftFreq)) * 2.0;
mhzVisualStep = 0.01f;
}
long double currentMhz = trunc(floor(firstMhz / 1000000.0));
std::stringstream label;
label.precision(2);
float hPos = 1.0 - (16.0 / viewHeight);
float lMhzPos = 1.0 - (5.0 / viewHeight);
for (float m = -1.0 + mhzStart, mMax = 1.0 + fabs(mhzStart); m <= mMax; m += mhzStep) {
label << std::fixed << currentMhz;
double fractpart, intpart;
fractpart = modf(currentMhz, &intpart);
if (fractpart < 0.001) {
glLineWidth(4.0);
glColor3f(ThemeMgr::mgr.currentTheme->freqLine.r, ThemeMgr::mgr.currentTheme->freqLine.g, ThemeMgr::mgr.currentTheme->freqLine.b);
} else {
glLineWidth(1.0);
glColor3f(ThemeMgr::mgr.currentTheme->freqLine.r * 0.65, ThemeMgr::mgr.currentTheme->freqLine.g * 0.65,
ThemeMgr::mgr.currentTheme->freqLine.b * 0.65);
}
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glVertex2f(m, lMhzPos);
glVertex2f(m, 1);
glEnd();
glColor4f(ThemeMgr::mgr.currentTheme->text.r, ThemeMgr::mgr.currentTheme->text.g, ThemeMgr::mgr.currentTheme->text.b,1.0);
GLFont::getFont(GLFont::GLFONT_SIZE12).drawString(label.str(), m, hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
label.str(std::string());
currentMhz += mhzVisualStep;
}
glLineWidth(1.0);
// getFont(PrimaryGLContext::GLFONT_SIZE16).drawString("Welcome to CubicSDR -- This is a test string. 01234567890!@#$%^&*()_[]",0.0,0.0,16,GLFont::GLFONT_ALIGN_CENTER,GLFont::GLFONT_ALIGN_CENTER);
CheckGLError();
}
-23
View File
@@ -1,23 +0,0 @@
#pragma once
#include "PrimaryGLContext.h"
#include "Gradient.h"
#define NUM_WATERFALL_LINES 512
class SpectrumCanvas;
class SpectrumContext: public PrimaryGLContext {
public:
SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedContext);
void Draw(std::vector<float> &points, long long freq, int bandwidth);
float getFloorValue() const;
void setFloorValue(float floorValue);
float getCeilValue() const;
void setCeilValue(float ceilValue);
private:
float floorValue, ceilValue;
};
+24 -11
View File
@@ -31,7 +31,7 @@ EVT_KEY_UP(TuningCanvas::OnKeyUp)
wxEND_EVENT_TABLE()
TuningCanvas::TuningCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), dragAccum(0), uxDown(0), top(false), bottom(false) {
InteractiveCanvas(parent, attribList), dragAccum(0), uxDown(0), top(false), bottom(false), freq(-1), bw(-1), center(-1) {
glContext = new TuningContext(this, &wxGetApp().GetContext(this));
@@ -57,13 +57,27 @@ TuningCanvas::~TuningCanvas() {
}
bool TuningCanvas::changed() {
DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
long long current_freq = 0;
if (activeDemod != NULL) {
freq = activeDemod->getFrequency();
}
long long current_bw = wxGetApp().getDemodMgr().getLastBandwidth();
long long current_center = wxGetApp().getFrequency();
if (current_freq != freq || current_bw != bw || current_center != center) {
return true;
}
return false;
}
void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize();
glContext->SetCurrent(*this);
initGLExtensions();
glViewport(0, 0, ClientSize.x, ClientSize.y);
@@ -71,13 +85,13 @@ void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
glContext->DrawBegin();
DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
long long freq = 0;
freq = 0;
if (activeDemod != NULL) {
freq = activeDemod->getFrequency();
}
long long bw = wxGetApp().getDemodMgr().getLastBandwidth();
long long center = wxGetApp().getFrequency();
bw = wxGetApp().getDemodMgr().getLastBandwidth();
center = wxGetApp().getFrequency();
if (mouseTracker.mouseDown()) {
glContext->Draw(ThemeMgr::mgr.currentTheme->tuningBarDark.r, ThemeMgr::mgr.currentTheme->tuningBarDark.g, ThemeMgr::mgr.currentTheme->tuningBarDark.b,
@@ -238,8 +252,6 @@ void TuningCanvas::OnIdle(wxIdleEvent &event) {
dragging = false;
}
}
Refresh(false);
}
void TuningCanvas::OnMouseMoved(wxMouseEvent& event) {
@@ -373,6 +385,7 @@ void TuningCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
if (currentPPM != lastPPM) {
wxGetApp().saveConfig();
}
Refresh();
}
void TuningCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
+3 -1
View File
@@ -22,7 +22,8 @@ public:
~TuningCanvas();
void setHelpTip(std::string tip);
bool changed();
private:
void OnPaint(wxPaintEvent& event);
void OnIdle(wxIdleEvent &event);
@@ -66,6 +67,7 @@ private:
int currentPPM;
int lastPPM;
long long freq, bw, center;
//
wxDECLARE_EVENT_TABLE();
};
+21 -26
View File
@@ -35,10 +35,10 @@ EVT_MOUSEWHEEL(WaterfallCanvas::OnMouseWheelMoved)
wxEND_EVENT_TABLE()
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines(
0), mouseZoom(1), zoom(1), hoverAlpha(1.0), dragOfs(0) {
InteractiveCanvas(parent, attribList), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines(0),
dragOfs(0), mouseZoom(1), zoom(1), hoverAlpha(1.0) {
glContext = new WaterfallContext(this, &wxGetApp().GetContext(this));
glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));
SetCursor(wxCURSOR_CROSS);
}
@@ -53,7 +53,7 @@ void WaterfallCanvas::setup(int fft_size_in, int waterfall_lines_in) {
fft_size = fft_size_in;
waterfall_lines = waterfall_lines_in;
glContext->Setup(fft_size, waterfall_lines);
waterfallPanel.setup(fft_size, waterfall_lines);
}
WaterfallCanvas::DragState WaterfallCanvas::getDragState() {
@@ -70,9 +70,6 @@ void WaterfallCanvas::attachSpectrumCanvas(SpectrumCanvas *canvas_in) {
void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize();
long double currentZoom = zoom;
@@ -138,29 +135,27 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2;
}
}
if (visualDataQueue.empty()) {
return;
}
SpectrumVisualData *vData;
visualDataQueue.pop(vData);
if (!vData) {
return;
}
spectrum_points.assign(vData->spectrum_points.begin(),vData->spectrum_points.end());
vData->decRefCount();
glContext->SetCurrent(*this);
initGLExtensions();
glViewport(0, 0, ClientSize.x, ClientSize.y);
if (!visualDataQueue.empty()) {
SpectrumVisualData *vData;
visualDataQueue.pop(vData);
if (vData) {
waterfallPanel.setPoints(vData->spectrum_points);
waterfallPanel.step();
vData->decRefCount();
}
}
glContext->BeginDraw(0,0,0);
glContext->Draw(spectrum_points);
waterfallPanel.calcTransform(CubicVR::mat4::identity());
waterfallPanel.draw();
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
@@ -352,7 +347,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
}
}
void WaterfallCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false);
event.Skip();
}
void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) {
@@ -715,4 +710,4 @@ void WaterfallCanvas::OnMouseRightReleased(wxMouseEvent& event) {
SpectrumVisualDataQueue *WaterfallCanvas::getVisualDataQueue() {
return &visualDataQueue;
}
}
+3 -3
View File
@@ -7,9 +7,9 @@
#include <queue>
#include "InteractiveCanvas.h"
#include "WaterfallContext.h"
#include "MouseTracker.h"
#include "SpectrumCanvas.h"
#include "WaterfallPanel.h"
class WaterfallCanvas: public InteractiveCanvas {
@@ -47,8 +47,8 @@ private:
std::vector<float> spectrum_points;
SpectrumCanvas *spectrumCanvas;
WaterfallContext *glContext;
PrimaryGLContext *glContext;
WaterfallPanel waterfallPanel;
DragState dragState;
DragState nextDragState;
-143
View File
@@ -1,143 +0,0 @@
#include "WaterfallContext.h"
#include "WaterfallCanvas.h"
#include "CubicSDR.h"
WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext) :
PrimaryGLContext(canvas, sharedContext), fft_size(0), waterfall_lines(0), waterfall_slice(NULL), activeTheme(NULL) {
for (int i = 0; i < 2; i++) {
waterfall[i] = 0;
}
}
void WaterfallContext::Setup(int fft_size_in, int num_waterfall_lines_in) {
waterfall_lines = num_waterfall_lines_in;
fft_size = fft_size_in;
for (int i = 0; i < 2; i++) {
if (waterfall[i]) {
glDeleteTextures(1, &waterfall[i]);
waterfall[i] = 0;
}
waterfall_ofs[i] = waterfall_lines - 1;
}
}
void WaterfallContext::refreshTheme() {
glEnable (GL_TEXTURE_2D);
for (int i = 0; i < 2; i++) {
glBindTexture(GL_TEXTURE_2D, waterfall[i]);
glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getRed())[0]);
glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getGreen())[0]);
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getBlue())[0]);
}
}
void WaterfallContext::Draw(std::vector<float> &points) {
int half_fft_size = fft_size / 2;
glEnable (GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
if (!waterfall[0]) {
glGenTextures(2, waterfall);
unsigned char *waterfall_tex;
waterfall_tex = new unsigned char[half_fft_size * waterfall_lines];
memset(waterfall_tex, 0, half_fft_size * waterfall_lines);
for (int i = 0; i < 2; i++) {
glBindTexture(GL_TEXTURE_2D, waterfall[i]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, waterfall[i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, half_fft_size, waterfall_lines, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, (GLvoid *) waterfall_tex);
}
if (waterfall_slice != NULL) {
delete waterfall_slice;
}
waterfall_slice = new unsigned char[half_fft_size];
delete[] waterfall_tex;
}
if (activeTheme != ThemeMgr::mgr.currentTheme) {
refreshTheme();
activeTheme = ThemeMgr::mgr.currentTheme;
}
if (points.size()) {
for (int j = 0; j < 2; j++) {
for (int i = 0, iMax = half_fft_size; i < iMax; i++) {
float v = points[(j * half_fft_size + i) * 2 + 1];
float wv = v < 0 ? 0 : (v > 0.99 ? 0.99 : v);
waterfall_slice[i] = (unsigned char) floor(wv * 255.0);
}
glBindTexture(GL_TEXTURE_2D, waterfall[j]);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, waterfall_ofs[j], half_fft_size, 1, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, (GLvoid *) waterfall_slice);
if (waterfall_ofs[j] == 0) {
waterfall_ofs[j] = waterfall_lines;
}
waterfall_ofs[j]--;
}
}
glColor3f(1.0, 1.0, 1.0);
GLint vp[4];
glGetIntegerv(GL_VIEWPORT, vp);
float viewWidth = (float) vp[2];
// some bias to prevent seams at odd scales
float half_pixel = 1.0 / viewWidth;
float half_texel = 1.0 / (float) half_fft_size;
float vtexel = 1.0 / (float) waterfall_lines;
float vofs = (float) (waterfall_ofs[0] + 1) * vtexel;
glBindTexture(GL_TEXTURE_2D, waterfall[0]);
glBegin (GL_QUADS);
glTexCoord2f(0.0 + half_texel, 1.0 + vofs);
glVertex3f(-1.0, -1.0, 0.0);
glTexCoord2f(1.0 - half_texel, 1.0 + vofs);
glVertex3f(0.0 + half_pixel, -1.0, 0.0);
glTexCoord2f(1.0 - half_texel, 0.0 + vofs);
glVertex3f(0.0 + half_pixel, 1.0, 0.0);
glTexCoord2f(0.0 + half_texel, 0.0 + vofs);
glVertex3f(-1.0, 1.0, 0.0);
glEnd();
vofs = (float) (waterfall_ofs[1] + 1) * vtexel;
glBindTexture(GL_TEXTURE_2D, waterfall[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0 + half_texel, 1.0 + vofs);
glVertex3f(0.0 - half_pixel, -1.0, 0.0);
glTexCoord2f(1.0 - half_texel, 1.0 + vofs);
glVertex3f(1.0, -1.0, 0.0);
glTexCoord2f(1.0 - half_texel, 0.0 + vofs);
glVertex3f(1.0, 1.0, 0.0);
glTexCoord2f(0.0 + half_texel, 0.0 + vofs);
glVertex3f(0.0 - half_pixel, 1.0, 0.0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDisable(GL_TEXTURE_2D);
}
-25
View File
@@ -1,25 +0,0 @@
#pragma once
#include "PrimaryGLContext.h"
#include "Gradient.h"
#include "ColorTheme.h"
class WaterfallCanvas;
class WaterfallContext: public PrimaryGLContext {
public:
WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext);
void Draw(std::vector<float> &points);
void Setup(int fft_size_in, int num_waterfall_lines_in);
void refreshTheme();
private:
GLuint waterfall[2];
int waterfall_ofs[2];
int fft_size;
int waterfall_lines;
unsigned char *waterfall_slice;
ColorTheme *activeTheme;
};