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
commit 6ac4661e2e
36 changed files with 534 additions and 411 deletions

View File

@ -244,6 +244,9 @@ SET (cubicsdr_sources
src/util/GLExt.cpp src/util/GLExt.cpp
src/util/GLFont.cpp src/util/GLFont.cpp
src/util/DataTree.cpp src/util/DataTree.cpp
src/panel/ScopePanel.cpp
src/panel/SpectrumPanel.cpp
src/panel/WaterfallPanel.cpp
src/visual/ColorTheme.cpp src/visual/ColorTheme.cpp
src/visual/PrimaryGLContext.cpp src/visual/PrimaryGLContext.cpp
src/visual/InteractiveCanvas.cpp src/visual/InteractiveCanvas.cpp
@ -256,9 +259,7 @@ SET (cubicsdr_sources
src/visual/ScopeCanvas.cpp src/visual/ScopeCanvas.cpp
src/visual/ScopeContext.cpp src/visual/ScopeContext.cpp
src/visual/SpectrumCanvas.cpp src/visual/SpectrumCanvas.cpp
src/visual/SpectrumContext.cpp
src/visual/WaterfallCanvas.cpp src/visual/WaterfallCanvas.cpp
src/visual/WaterfallContext.cpp
src/process/VisualProcessor.cpp src/process/VisualProcessor.cpp
src/process/ScopeVisualProcessor.cpp src/process/ScopeVisualProcessor.cpp
src/process/SpectrumVisualProcessor.cpp src/process/SpectrumVisualProcessor.cpp
@ -296,6 +297,9 @@ SET (cubicsdr_headers
src/util/GLExt.h src/util/GLExt.h
src/util/GLFont.h src/util/GLFont.h
src/util/DataTree.h src/util/DataTree.h
src/panel/ScopePanel.h
src/panel/SpectrumPanel.h
src/panel/WaterfallPanel.h
src/visual/ColorTheme.h src/visual/ColorTheme.h
src/visual/PrimaryGLContext.h src/visual/PrimaryGLContext.h
src/visual/InteractiveCanvas.h src/visual/InteractiveCanvas.h
@ -308,9 +312,7 @@ SET (cubicsdr_headers
src/visual/ScopeCanvas.h src/visual/ScopeCanvas.h
src/visual/ScopeContext.h src/visual/ScopeContext.h
src/visual/SpectrumCanvas.h src/visual/SpectrumCanvas.h
src/visual/SpectrumContext.h
src/visual/WaterfallCanvas.h src/visual/WaterfallCanvas.h
src/visual/WaterfallContext.h
src/process/VisualProcessor.h src/process/VisualProcessor.h
src/process/ScopeVisualProcessor.h src/process/ScopeVisualProcessor.h
src/process/SpectrumVisualProcessor.h src/process/SpectrumVisualProcessor.h
@ -339,11 +341,28 @@ SET (cubicsdr_headers
external/cubicvr2/math/vec4.h external/cubicvr2/math/vec4.h
) )
set(REG_EXT "[^/]*([.]cpp|[.]c|[.]h|[.]hpp)$")
SOURCE_GROUP("Base" REGULAR_EXPRESSION src/${REG_EXT})
SOURCE_GROUP("SDR" REGULAR_EXPRESSION src/sdr/${REG_EXT})
SOURCE_GROUP("Demodulator" REGULAR_EXPRESSION src/demod/${REG_EXT})
SOURCE_GROUP("Audio" REGULAR_EXPRESSION src/audio/${REG_EXT})
SOURCE_GROUP("Utility" REGULAR_EXPRESSION src/util/${REG_EXT})
SOURCE_GROUP("Panel" REGULAR_EXPRESSION src/panel/${REG_EXT})
SOURCE_GROUP("Visual" REGULAR_EXPRESSION src/visual/${REG_EXT})
SOURCE_GROUP("Process" REGULAR_EXPRESSION src/process/${REG_EXT})
SOURCE_GROUP("UI" REGULAR_EXPRESSION src/ui/${REG_EXT})
SOURCE_GROUP("_ext-RTAudio" REGULAR_EXPRESSION external/rtaudio/.*${REG_EXT})
SOURCE_GROUP("_ext-LodePNG" REGULAR_EXPRESSION external/lodepng/.*${REG_EXT})
SOURCE_GROUP("_ext-TinyXML" REGULAR_EXPRESSION external/tinyxml/.*${REG_EXT})
SOURCE_GROUP("_ext-CubicVR2" REGULAR_EXPRESSION external/cubicvr2/.*${REG_EXT})
include_directories ( include_directories (
${PROJECT_SOURCE_DIR}/src/sdr ${PROJECT_SOURCE_DIR}/src/sdr
${PROJECT_SOURCE_DIR}/src/demod ${PROJECT_SOURCE_DIR}/src/demod
${PROJECT_SOURCE_DIR}/src/audio ${PROJECT_SOURCE_DIR}/src/audio
${PROJECT_SOURCE_DIR}/src/util ${PROJECT_SOURCE_DIR}/src/util
${PROJECT_SOURCE_DIR}/src/panel
${PROJECT_SOURCE_DIR}/src/visual ${PROJECT_SOURCE_DIR}/src/visual
${PROJECT_SOURCE_DIR}/src/process ${PROJECT_SOURCE_DIR}/src/process
${PROJECT_SOURCE_DIR}/src/ui ${PROJECT_SOURCE_DIR}/src/ui
@ -586,7 +605,9 @@ IF (UNIX AND BUILD_DEB)
${PROJECT_SOURCE_DIR}/font/vera_sans_mono24_0.png ${PROJECT_SOURCE_DIR}/font/vera_sans_mono24_0.png
${PROJECT_SOURCE_DIR}/font/vera_sans_mono32_0.png ${PROJECT_SOURCE_DIR}/font/vera_sans_mono32_0.png
${PROJECT_SOURCE_DIR}/font/vera_sans_mono48_0.png ${PROJECT_SOURCE_DIR}/font/vera_sans_mono48_0.png
${PROJECT_SOURCE_DIR}/src/CubicSDR.png
DESTINATION share/cubicsdr) DESTINATION share/cubicsdr)
INSTALL(FILES CubicSDR.desktop
DESTINATION share/applications)
INCLUDE(CPack) INCLUDE(CPack)
ENDIF (UNIX AND BUILD_DEB) ENDIF (UNIX AND BUILD_DEB)

9
CubicSDR.desktop Normal file
View File

@ -0,0 +1,9 @@
[Desktop Entry]
Type=Application
Exec=CubicSDR %u
Icon=/usr/share/cubicsdr/CubicSDR.png
Terminal=false
Name=CubicSDR
GenericName=CubicSDR
Comment=Software-Defined Radio Application
Categories=Science;HamRadio;DataVisualization;

View File

@ -21,9 +21,8 @@ Features and Status:
- Simple UI - Simple UI
- Devices - Devices
- [x] RTL-SDR - [x] RTL-SDR
- [ ] rtl_tcp - [ ] rtl_tcp client
- [ ] HackRF - [ ] gr-osmosdr
- [ ] Whatever else I can get my hands on
- Basic Features - Basic Features
- [x] Device Selection - [x] Device Selection
- [x] Bandwidth - [x] Bandwidth
@ -33,18 +32,21 @@ Features and Status:
- [x] Device PPM - [x] Device PPM
- [ ] Default preferences - [ ] Default preferences
- [ ] Audio defaults - [ ] Audio defaults
- [ ] Device defaults - [x] Device defaults
- [ ] Bookmarks - [ ] Bookmarks
- [ ] History - [ ] History
- [ ] Run as rtl_tcp server and visualize control
- Neat Visuals - Neat Visuals
- [x] Scope - [ ] 2D visuals
- [x] Spectrum - [x] Y Scope
- [x] Waterfall - [x] Spectrum
- [ ] Audio Spectrum - [x] Waterfall
- [ ] More 2D visuals
- [x] Add faint grid for sense of scale - [x] Add faint grid for sense of scale
- [ ] Audio Spectrum
- [ ] X/Y Scope
- [ ] Indicate outer spectrum edges when zoomed - [ ] Indicate outer spectrum edges when zoomed
- [ ] 3D visuals - [ ] 3D visuals
- [ ] I/Q helix
- Demodulation: - Demodulation:
- [ ] Basic modular expansion - [ ] Basic modular expansion
- [x] Multiple demodulators per IQ stream - [x] Multiple demodulators per IQ stream
@ -56,7 +58,7 @@ Features and Status:
- [x] LSB - [x] LSB
- [x] USB - [x] USB
- [x] DSB - [x] DSB
- [ ] RAW - [x] I/Q
- [ ] Controls - [ ] Controls
- [x] Display Frequency and allow manual adjustments - [x] Display Frequency and allow manual adjustments
- [x] Allow selection of demodulation type - [x] Allow selection of demodulation type
@ -64,8 +66,10 @@ Features and Status:
- [x] Display signal level and allow squelch control - [x] Display signal level and allow squelch control
- [x] Display audio output selection - [x] Display audio output selection
- [x] Volume control - [x] Volume control
- [ ] Demodulator input filtering - [x] Direct frequency input
- [ ] Audio filtering - [ ] Mute
- [ ] Waterfall speed
- [ ] RTL-SDR Gain
- Basic Input Controls - Basic Input Controls
- [x] Drag spectrum to change center frequency - [x] Drag spectrum to change center frequency
- [x] Hold shift and click on waterfall to create a new demodulator - [x] Hold shift and click on waterfall to create a new demodulator
@ -88,6 +92,8 @@ Features and Status:
- [ ] Recording - [ ] Recording
- Implement digital demodulation supported by liquid-dsp: (http://liquidsdr.org/doc/modem.html) - Implement digital demodulation supported by liquid-dsp: (http://liquidsdr.org/doc/modem.html)
- [ ] Demodulator Lab - [ ] Demodulator Lab
- [ ] Demodulator I/Q input filtering
- [ ] Audio output filtering
- [ ] Toggle current demodulator exclusively into "Lab" mode - [ ] Toggle current demodulator exclusively into "Lab" mode
- [ ] Additional visualizations for audio and I/Q stream - [ ] Additional visualizations for audio and I/Q stream
- [ ] Audio Spectrum - [ ] Audio Spectrum
@ -115,9 +121,9 @@ Features and Status:
- [ ] CPFSK - [ ] CPFSK
- Optimization - Optimization
- [x] Eliminate large waterfall texture uploads - [x] Eliminate large waterfall texture uploads
- [ ] Update visuals to OpenGL 3.x - [ ] Update visuals to OpenGL 3.x / OpenGL ES
- [ ] Resolve constant refresh on visuals that don't change often - [ ] Resolve constant refresh on visuals that don't change often
- [ ] Resolve driver/platform vertical sync issues - [ ] Resolve all driver/platform vertical sync issues
- [ ] Group and divide IQ data distribution workload instead of 100% distribution per instance - [ ] Group and divide IQ data distribution workload instead of 100% distribution per instance
@ -140,6 +146,7 @@ Advanced Goals and ideas:
* Take control of additional devices and spawning new demodulators (i.e. trunkers) * Take control of additional devices and spawning new demodulators (i.e. trunkers)
* Script manager / live editor * Script manager / live editor
* Provide scriptable liquid-dsp modulation for trancievers? * Provide scriptable liquid-dsp modulation for trancievers?
* Allow scripts to launch/run headless (no UI)
- "PVR" like mode with waterfall time shifting - "PVR" like mode with waterfall time shifting
- L/R and surround-sound balance settings for separating and listening to mono streams - L/R and surround-sound balance settings for separating and listening to mono streams
- Add tool for converting decimated I/Q recording to video - Add tool for converting decimated I/Q recording to video

View File

@ -23,7 +23,9 @@ namespace CubicVR {
__float a,b,c,d,e,f,g,h,i; __float a,b,c,d,e,f,g,h,i;
// __float operator [] (unsigned i) const { return ((__float *)this)[i]; } // __float operator [] (unsigned i) const { return ((__float *)this)[i]; }
#ifndef _WIN32
__float& operator [] (unsigned i) { return ((__float *)this)[i]; } __float& operator [] (unsigned i) { return ((__float *)this)[i]; }
#endif
operator __float*() const { return (__float *)this; } operator __float*() const { return (__float *)this; }
mat3(__float ai,__float bi,__float ci,__float di,__float ei,__float fi,__float gi,__float hi,__float ii) { mat3(__float ai,__float bi,__float ci,__float di,__float ei,__float fi,__float gi,__float hi,__float ii) {

View File

@ -25,7 +25,10 @@ namespace CubicVR {
__float a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p; __float a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;
// __float operator [] (unsigned i) const { return ((__float *)this)[i]; } // __float operator [] (unsigned i) const { return ((__float *)this)[i]; }
#ifndef _WIN32
__float& operator [] (unsigned i) { return ((__float *)this)[i]; } __float& operator [] (unsigned i) { return ((__float *)this)[i]; }
#endif
operator __float*() const { return (__float *)this; } operator __float*() const { return (__float *)this; }
mat4(__float ai,__float bi,__float ci,__float di,__float ei,__float fi,__float gi,__float hi,__float ii,__float ji,__float ki,__float li,__float mi,__float ni,__float oi,__float pi) { mat4(__float ai,__float bi,__float ci,__float di,__float ei,__float fi,__float gi,__float hi,__float ii,__float ji,__float ki,__float li,__float mi,__float ni,__float oi,__float pi) {
a = ai; b = bi; c = ci; d = di; e = ei; f = fi; g = gi; h = hi; i = ii; j = ji; k = ki; l = li; m = mi; n = ni; o = oi; p = pi; a = ai; b = bi; c = ci; d = di; e = ei; f = fi; g = gi; h = hi; i = ii; j = ji; k = ki; l = li; m = mi; n = ni; o = oi; p = pi;

View File

@ -25,8 +25,9 @@ namespace CubicVR {
__float& v() { return y; } __float& v() { return y; }
// __float operator [] (unsigned i) const { return ((__float *)this)[i]; } // __float operator [] (unsigned i) const { return ((__float *)this)[i]; }
__float& operator [] (unsigned i) { return ((__float *)this)[i]; } #ifndef _WIN32
__float& operator [] (unsigned i) { return ((__float *)this)[i]; }
#endif
vec2 (__float xi,__float yi) { x = xi; y = yi; } vec2 (__float xi,__float yi) { x = xi; y = yi; }
vec2 () { x = y = 0.0f; } vec2 () { x = y = 0.0f; }

View File

@ -29,7 +29,9 @@ namespace CubicVR {
__float& g() { return y; } __float& g() { return y; }
__float& b() { return z; } __float& b() { return z; }
#ifndef _WIN32
__float& operator [] (unsigned i) { return ((__float *)this)[i]; } __float& operator [] (unsigned i) { return ((__float *)this)[i]; }
#endif
vec3 (__float xi,__float yi,__float zi) { x = xi; y = yi; z = zi; } vec3 (__float xi,__float yi,__float zi) { x = xi; y = yi; z = zi; }
vec3 () { x = y = z = 0.0f; } vec3 () { x = y = z = 0.0f; }

View File

@ -28,8 +28,10 @@ namespace CubicVR {
__float& a() { return w; } __float& a() { return w; }
// __float operator [] (unsigned i) const { return ((__float *)this)[i]; } // __float operator [] (unsigned i) const { return ((__float *)this)[i]; }
#ifndef _WIN32
__float& operator [] (unsigned i) { return ((__float *)this)[i]; } __float& operator [] (unsigned i) { return ((__float *)this)[i]; }
#endif
vec4 (__float xi,__float yi,__float zi,__float wi) { x = xi; y = yi; z = zi; w = wi; } vec4 (__float xi,__float yi,__float zi,__float wi) { x = xi; y = yi; z = zi; w = wi; }
vec4 () { x = y = z = w = 0.0f; } vec4 () { x = y = z = w = 0.0f; }

View File

@ -35,10 +35,11 @@ EVT_CLOSE(AppFrame::OnClose)
EVT_MENU(wxID_ANY, AppFrame::OnMenu) EVT_MENU(wxID_ANY, AppFrame::OnMenu)
EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread) EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread)
EVT_IDLE(AppFrame::OnIdle) EVT_IDLE(AppFrame::OnIdle)
EVT_TIMER(FRAME_TIMER_ID, AppFrame::OnTimer)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
AppFrame::AppFrame() : AppFrame::AppFrame() :
wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) { wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL), frame_timer(this, FRAME_TIMER_ID) {
#ifdef __linux__ #ifdef __linux__
SetIcon(wxICON(cubicsdr)); SetIcon(wxICON(cubicsdr));
@ -377,6 +378,8 @@ AppFrame::AppFrame() :
wxAcceleratorTable accel(3, entries); wxAcceleratorTable accel(3, entries);
SetAcceleratorTable(accel); SetAcceleratorTable(accel);
// frame rate = 1000 / 30 = 33ms
frame_timer.Start(33);
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 }; // static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not"); // wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
// ShowFullScreen(true); // ShowFullScreen(true);
@ -479,6 +482,11 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
ThemeMgr::mgr.setTheme(COLOR_THEME_RADAR); ThemeMgr::mgr.setTheme(COLOR_THEME_RADAR);
} }
if (event.GetId() >= wxID_THEME_DEFAULT && event.GetId() <= wxID_THEME_RADAR) {
demodTuner->Refresh();
demodModeSelector->Refresh();
}
switch (event.GetId()) { switch (event.GetId()) {
case wxID_BANDWIDTH_250K: case wxID_BANDWIDTH_250K:
wxGetApp().setSampleRate(250000); wxGetApp().setSampleRate(250000);
@ -587,6 +595,10 @@ void AppFrame::OnThread(wxCommandEvent& event) {
} }
void AppFrame::OnIdle(wxIdleEvent& event) { void AppFrame::OnIdle(wxIdleEvent& event) {
event.Skip();
}
void AppFrame::OnTimer(wxTimerEvent& event) {
DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
@ -733,7 +745,7 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
scopeCanvas->setPPMMode(demodTuner->isAltDown()); scopeCanvas->setPPMMode(demodTuner->isAltDown());
wxGetApp().getScopeProcessor()->run();
wxGetApp().getSpectrumDistributor()->run(); wxGetApp().getSpectrumDistributor()->run();
SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcesor(); SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcesor();
@ -751,6 +763,24 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
dproc->setCenterFrequency(demodWaterfallCanvas->getCenterFrequency()); dproc->setCenterFrequency(demodWaterfallCanvas->getCenterFrequency());
dproc->run(); dproc->run();
scopeCanvas->Refresh();
waterfallCanvas->Refresh();
spectrumCanvas->Refresh();
demodWaterfallCanvas->Refresh();
demodSpectrumCanvas->Refresh();
demodSignalMeter->Refresh();
demodGainMeter->Refresh();
if (demodTuner->getMouseTracker()->mouseInView() || demodTuner->changed()) {
demodTuner->Refresh();
}
if (demodModeSelector->getMouseTracker()->mouseInView()) {
demodModeSelector->Refresh();
}
event.Skip(); event.Skip();
} }

View File

@ -50,7 +50,7 @@
#define wxID_AUDIO_BANDWIDTH_BASE 9000 #define wxID_AUDIO_BANDWIDTH_BASE 9000
#define wxID_AUDIO_DEVICE_MULTIPLIER 50 #define wxID_AUDIO_DEVICE_MULTIPLIER 50
#define FRAME_TIMER_ID 1000
// Define a new frame type // Define a new frame type
class AppFrame: public wxFrame { class AppFrame: public wxFrame {
@ -69,6 +69,7 @@ private:
void OnClose(wxCloseEvent& event); void OnClose(wxCloseEvent& event);
void OnNewWindow(wxCommandEvent& event); void OnNewWindow(wxCommandEvent& event);
void OnIdle(wxIdleEvent& event); void OnIdle(wxIdleEvent& event);
void OnTimer(wxTimerEvent& event);
ScopeCanvas *scopeCanvas; ScopeCanvas *scopeCanvas;
@ -96,6 +97,7 @@ private:
wxMenuItem *iqSwapMenuItem; wxMenuItem *iqSwapMenuItem;
std::string currentSessionFile; std::string currentSessionFile;
wxTimer frame_timer;
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };

BIN
src/CubicSDR.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

91
src/panel/ScopePanel.cpp Normal file
View File

@ -0,0 +1,91 @@
#include "ScopePanel.h"
#include "ColorTheme.h"
ScopePanel::ScopePanel() : GLPanel(), scopeMode(SCOPE_MODE_Y) {
bgPanel.setFill(GLPanelFillType::GLPANEL_FILL_GRAD_BAR_Y);
bgPanelStereo[0].setFill(GLPanelFillType::GLPANEL_FILL_GRAD_BAR_Y);
bgPanelStereo[0].setPosition(0, 0.5);
bgPanelStereo[0].setSize(1, 0.5);
bgPanelStereo[1].setFill(GLPanelFillType::GLPANEL_FILL_GRAD_BAR_Y);
bgPanelStereo[1].setPosition(0, -0.5);
bgPanelStereo[1].setSize(1, 0.5);
}
void ScopePanel::setMode(ScopeMode scopeMode) {
this->scopeMode = scopeMode;
}
void ScopePanel::setPoints(std::vector<float> &points) {
this->points.assign(points.begin(),points.end());
}
void ScopePanel::drawPanelContents() {
glLineWidth(1.0);
if (scopeMode == SCOPE_MODE_Y) {
bgPanel.setFillColor(ThemeMgr::mgr.currentTheme->scopeBackground, ThemeMgr::mgr.currentTheme->scopeBackground * 2.0);
bgPanel.calcTransform(transform);
bgPanel.draw();
glLoadMatrixf(transform);
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();
} else if (scopeMode == SCOPE_MODE_2Y) {
bgPanelStereo[0].setFillColor(ThemeMgr::mgr.currentTheme->scopeBackground, ThemeMgr::mgr.currentTheme->scopeBackground * 2.0);
bgPanelStereo[1].setFillColor(ThemeMgr::mgr.currentTheme->scopeBackground, ThemeMgr::mgr.currentTheme->scopeBackground * 2.0);
bgPanelStereo[0].calcTransform(transform);
bgPanelStereo[0].draw();
bgPanelStereo[1].calcTransform(transform);
bgPanelStereo[1].draw();
glLoadMatrixf(transform);
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 if (scopeMode == SCOPE_MODE_XY) {
// ...
}
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]);
glLineWidth(1.5);
if (scopeMode == SCOPE_MODE_Y) {
glLoadMatrixf(bgPanel.transform);
glDrawArrays(GL_LINE_STRIP, 0, points.size() / 2);
} else if (scopeMode == SCOPE_MODE_2Y) {
glLoadMatrixf(bgPanelStereo[0].transform);
glDrawArrays(GL_LINE_STRIP, 0, points.size() / 4);
glLoadMatrixf(bgPanelStereo[1].transform);
glDrawArrays(GL_LINE_STRIP, points.size() / 4, points.size() / 4);
} else if (scopeMode == SCOPE_MODE_XY) {
// ...
}
glLineWidth(1.0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisable(GL_BLEND);
}
}

23
src/panel/ScopePanel.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include "GLPanel.h"
class ScopePanel : public GLPanel {
public:
typedef enum ScopeMode { SCOPE_MODE_Y, SCOPE_MODE_2Y, SCOPE_MODE_XY } ScopeMode;
ScopePanel();
void setMode(ScopeMode scopeMode);
void setPoints(std::vector<float> &points);
protected:
void drawPanelContents();
private:
std::vector<float> points;
ScopeMode scopeMode;
GLPanel bgPanel;
GLPanel bgPanelStereo[2];
};

View File

@ -1,82 +1,83 @@
#include "SpectrumContext.h" #include "SpectrumPanel.h"
#include "SpectrumCanvas.h"
#include "CubicSDR.h"
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include "ColorTheme.h" #include "ColorTheme.h"
SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedContext) : SpectrumPanel::SpectrumPanel() : floorValue(0), ceilValue(1) {
PrimaryGLContext(canvas, sharedContext), floorValue(0), ceilValue(1) { setFill(GLPANEL_FILL_GRAD_Y);
glDisable(GL_CULL_FACE); setFillColor(ThemeMgr::mgr.currentTheme->fftBackground * 2.0, ThemeMgr::mgr.currentTheme->fftBackground);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
} }
float SpectrumContext::getFloorValue() const { float SpectrumPanel::getFloorValue() const {
return floorValue; return floorValue;
} }
void SpectrumContext::setFloorValue(float floorValue) { void SpectrumPanel::setFloorValue(float floorValue) {
this->floorValue = floorValue; this->floorValue = floorValue;
} }
float SpectrumContext::getCeilValue() const { float SpectrumPanel::getCeilValue() const {
return ceilValue; return ceilValue;
} }
void SpectrumContext::setCeilValue(float ceilValue) { void SpectrumPanel::setCeilValue(float ceilValue) {
this->ceilValue = ceilValue; this->ceilValue = ceilValue;
} }
void SpectrumContext::Draw(std::vector<float> &points, long long freq, int bandwidth) { void SpectrumPanel::setFreq(long long freq) {
this->freq = freq;
}
glBegin(GL_QUADS); long long SpectrumPanel::getFreq() {
glColor3f(ThemeMgr::mgr.currentTheme->fftBackground.r, ThemeMgr::mgr.currentTheme->fftBackground.g, ThemeMgr::mgr.currentTheme->fftBackground.b); return freq;
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); void SpectrumPanel::setBandwidth(long long bandwidth) {
glVertex2f(-1, -1); this->bandwidth = bandwidth;
glVertex2f(1, -1); }
glEnd();
long long SpectrumPanel::getBandwidth() {
return bandwidth;
}
void SpectrumPanel::setPoints(std::vector<float> &points) {
this->points.assign(points.begin(), points.end());
}
void SpectrumPanel::drawPanelContents() {
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
glLoadMatrixf(transform * (CubicVR::mat4::translate(-1.0f, -0.75f, 0.0f) * CubicVR::mat4::scale(2.0f, 1.5f, 1.0f)));
if (points.size()) { if (points.size()) {
glPushMatrix();
glTranslatef(-1.0f, -0.75f, 0.0f);
glScalef(2.0f, 1.5f, 1.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
float range = ceilValue-floorValue; 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 } }; 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++) { for (int i = 0; i < 3; i++) {
float p = 0; float p = 0;
float rangeMin = ranges[i][0]; float rangeMin = ranges[i][0];
float rangeMax = ranges[i][1]; float rangeMax = ranges[i][1];
float rangeTrans = ranges[i][2]; float rangeTrans = ranges[i][2];
float rangeStep = ranges[i][3]; float rangeStep = ranges[i][3];
if (range >= rangeMin && range <= rangeMax) { if (range >= rangeMin && range <= rangeMax) {
float a = 1.0; float a = 1.0;
if (range <= rangeMin+rangeTrans) { if (range <= rangeMin+rangeTrans) {
a *= (range-rangeMin)/rangeTrans; a *= (range-rangeMin)/rangeTrans;
} }
if (range >= rangeMax-rangeTrans) { if (range >= rangeMax-rangeTrans) {
a *= (rangeTrans-(range-(rangeMax-rangeTrans)))/rangeTrans; a *= (rangeTrans-(range-(rangeMax-rangeTrans)))/rangeTrans;
} }
glColor4f(0.12, 0.12, 0.12, a); glColor4f(0.12, 0.12, 0.12, a);
glBegin(GL_LINES); glBegin(GL_LINES);
for (float l = floorValue; l<=ceilValue+rangeStep; l+=rangeStep) { for (float l = floorValue; l<=ceilValue+rangeStep; l+=rangeStep) {
@ -86,76 +87,74 @@ void SpectrumContext::Draw(std::vector<float> &points, long long freq, int bandw
glEnd(); glEnd();
} }
} }
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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); glColor3f(ThemeMgr::mgr.currentTheme->fftLine.r, ThemeMgr::mgr.currentTheme->fftLine.g, ThemeMgr::mgr.currentTheme->fftLine.b);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, &points[0]); glVertexPointer(2, GL_FLOAT, 0, &points[0]);
glDrawArrays(GL_LINE_STRIP, 0, points.size() / 2); glDrawArrays(GL_LINE_STRIP, 0, points.size() / 2);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
} }
glLoadMatrixf(transform);
GLint vp[4]; GLint vp[4];
glGetIntegerv( GL_VIEWPORT, vp); glGetIntegerv( GL_VIEWPORT, vp);
float viewHeight = (float) vp[3]; float viewHeight = (float) vp[3];
float viewWidth = (float) vp[2]; float viewWidth = (float) vp[2];
long long leftFreq = (float) freq - ((float) bandwidth / 2.0); long long leftFreq = (float) freq - ((float) bandwidth / 2.0);
long long rightFreq = leftFreq + (float) bandwidth; long long rightFreq = leftFreq + (float) bandwidth;
long long firstMhz = (leftFreq / 1000000) * 1000000; long long firstMhz = (leftFreq / 1000000) * 1000000;
long double mhzStart = ((long double) (firstMhz - leftFreq) / (long double) (rightFreq - leftFreq)) * 2.0; long double mhzStart = ((long double) (firstMhz - leftFreq) / (long double) (rightFreq - leftFreq)) * 2.0;
long double mhzStep = (100000.0 / (long double) (rightFreq - leftFreq)) * 2.0; long double mhzStep = (100000.0 / (long double) (rightFreq - leftFreq)) * 2.0;
float mhzVisualStep = 0.1f; float mhzVisualStep = 0.1f;
if (mhzStep * 0.5 * viewWidth > 400) { if (mhzStep * 0.5 * viewWidth > 400) {
mhzStep = (10000.0 / (long double) (rightFreq - leftFreq)) * 2.0; mhzStep = (10000.0 / (long double) (rightFreq - leftFreq)) * 2.0;
mhzVisualStep = 0.01f; mhzVisualStep = 0.01f;
} }
long double currentMhz = trunc(floor(firstMhz / 1000000.0)); long double currentMhz = trunc(floor(firstMhz / 1000000.0));
std::stringstream label; std::stringstream label;
label.precision(2); label.precision(2);
float hPos = 1.0 - (16.0 / viewHeight); float hPos = 1.0 - (16.0 / viewHeight);
float lMhzPos = 1.0 - (5.0 / viewHeight); float lMhzPos = 1.0 - (5.0 / viewHeight);
for (float m = -1.0 + mhzStart, mMax = 1.0 + fabs(mhzStart); m <= mMax; m += mhzStep) { for (float m = -1.0 + mhzStart, mMax = 1.0 + ((mhzStart>0)?mhzStart:-mhzStart); m <= mMax; m += mhzStep) {
label << std::fixed << currentMhz; label << std::fixed << currentMhz;
double fractpart, intpart; double fractpart, intpart;
fractpart = modf(currentMhz, &intpart); fractpart = modf(currentMhz, &intpart);
if (fractpart < 0.001) { if (fractpart < 0.001) {
glLineWidth(4.0); glLineWidth(4.0);
glColor3f(ThemeMgr::mgr.currentTheme->freqLine.r, ThemeMgr::mgr.currentTheme->freqLine.g, ThemeMgr::mgr.currentTheme->freqLine.b); glColor3f(ThemeMgr::mgr.currentTheme->freqLine.r, ThemeMgr::mgr.currentTheme->freqLine.g, ThemeMgr::mgr.currentTheme->freqLine.b);
} else { } else {
glLineWidth(1.0); glLineWidth(1.0);
glColor3f(ThemeMgr::mgr.currentTheme->freqLine.r * 0.65, ThemeMgr::mgr.currentTheme->freqLine.g * 0.65, glColor3f(ThemeMgr::mgr.currentTheme->freqLine.r * 0.65, ThemeMgr::mgr.currentTheme->freqLine.g * 0.65,
ThemeMgr::mgr.currentTheme->freqLine.b * 0.65); ThemeMgr::mgr.currentTheme->freqLine.b * 0.65);
} }
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex2f(m, lMhzPos); glVertex2f(m, lMhzPos);
glVertex2f(m, 1); glVertex2f(m, 1);
glEnd(); glEnd();
glColor4f(ThemeMgr::mgr.currentTheme->text.r, ThemeMgr::mgr.currentTheme->text.g, ThemeMgr::mgr.currentTheme->text.b,1.0); 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); GLFont::getFont(GLFont::GLFONT_SIZE12).drawString(label.str(), m, hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
label.str(std::string()); label.str(std::string());
currentMhz += mhzVisualStep; currentMhz += mhzVisualStep;
} }
glLineWidth(1.0); 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();
} }

31
src/panel/SpectrumPanel.h Normal file
View File

@ -0,0 +1,31 @@
#pragma once
#include "GLPanel.h"
class SpectrumPanel : public GLPanel {
public:
SpectrumPanel();
void setPoints(std::vector<float> &points);
float getFloorValue() const;
void setFloorValue(float floorValue);
float getCeilValue() const;
void setCeilValue(float ceilValue);
void setFreq(long long freq);
long long getFreq();
void setBandwidth(long long bandwidth);
long long getBandwidth();
protected:
void drawPanelContents();
private:
float floorValue, ceilValue;
long long freq;
long long bandwidth;
std::vector<float> points;
};

View File

@ -1,34 +1,36 @@
#include "WaterfallContext.h" #include "WaterfallPanel.h"
#include "WaterfallCanvas.h"
#include "CubicSDR.h"
WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext) : WaterfallPanel::WaterfallPanel() : GLPanel(), fft_size(0), waterfall_lines(0), waterfall_slice(NULL), activeTheme(NULL) {
PrimaryGLContext(canvas, sharedContext), fft_size(0), waterfall_lines(0), waterfall_slice(NULL), activeTheme(NULL) { setFillColor(RGB3f(0,0,0));
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
waterfall[i] = 0; waterfall[i] = 0;
} }
} }
void WaterfallContext::Setup(int fft_size_in, int num_waterfall_lines_in) { void WaterfallPanel::setup(int fft_size_in, int num_waterfall_lines_in) {
waterfall_lines = num_waterfall_lines_in; waterfall_lines = num_waterfall_lines_in;
fft_size = fft_size_in; fft_size = fft_size_in;
if (points.size() != fft_size) {
points.resize(fft_size);
}
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
if (waterfall[i]) { if (waterfall[i]) {
glDeleteTextures(1, &waterfall[i]); glDeleteTextures(1, &waterfall[i]);
waterfall[i] = 0; waterfall[i] = 0;
} }
waterfall_ofs[i] = waterfall_lines - 1; waterfall_ofs[i] = waterfall_lines - 1;
} }
} }
void WaterfallContext::refreshTheme() { void WaterfallPanel::refreshTheme() {
glEnable (GL_TEXTURE_2D); glEnable (GL_TEXTURE_2D);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
glBindTexture(GL_TEXTURE_2D, waterfall[i]); glBindTexture(GL_TEXTURE_2D, waterfall[i]);
glPixelTransferi(GL_MAP_COLOR, GL_TRUE); 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_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_G, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getGreen())[0]);
@ -36,81 +38,100 @@ void WaterfallContext::refreshTheme() {
} }
} }
void WaterfallContext::Draw(std::vector<float> &points) { void WaterfallPanel::setPoints(std::vector<float> &points) {
int halfPts = points.size()/2;
if (halfPts == fft_size) {
for (int i = 0; i < fft_size; i++) {
this->points[i] = points[i*2+1];
}
} else {
this->points.assign(points.begin(), points.end());
}
}
void WaterfallPanel::step() {
int half_fft_size = fft_size / 2; int half_fft_size = fft_size / 2;
glEnable (GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
if (!waterfall[0]) { if (!waterfall[0]) {
glGenTextures(2, waterfall); glGenTextures(2, waterfall);
unsigned char *waterfall_tex; unsigned char *waterfall_tex;
waterfall_tex = new unsigned char[half_fft_size * waterfall_lines]; waterfall_tex = new unsigned char[half_fft_size * waterfall_lines];
memset(waterfall_tex, 0, half_fft_size * waterfall_lines); memset(waterfall_tex, 0, half_fft_size * waterfall_lines);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
glBindTexture(GL_TEXTURE_2D, waterfall[i]); glBindTexture(GL_TEXTURE_2D, waterfall[i]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 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_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, waterfall[i]); 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); 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) { if (waterfall_slice != NULL) {
delete waterfall_slice; delete waterfall_slice;
} }
waterfall_slice = new unsigned char[half_fft_size]; waterfall_slice = new unsigned char[half_fft_size];
delete[] waterfall_tex; delete[] waterfall_tex;
} }
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];
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]--;
}
}
}
void WaterfallPanel::drawPanelContents() {
if (!waterfall[0]) {
return;
}
int half_fft_size = fft_size / 2;
glLoadMatrixf(transform);
glEnable (GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
if (activeTheme != ThemeMgr::mgr.currentTheme) { if (activeTheme != ThemeMgr::mgr.currentTheme) {
refreshTheme(); refreshTheme();
activeTheme = ThemeMgr::mgr.currentTheme; 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); glColor3f(1.0, 1.0, 1.0);
GLint vp[4]; GLint vp[4];
glGetIntegerv(GL_VIEWPORT, vp); glGetIntegerv(GL_VIEWPORT, vp);
float viewWidth = (float) vp[2]; float viewWidth = (float) vp[2];
// some bias to prevent seams at odd scales // some bias to prevent seams at odd scales
float half_pixel = 1.0 / viewWidth; float half_pixel = 1.0 / viewWidth;
float half_texel = 1.0 / (float) half_fft_size; float half_texel = 1.0 / (float) half_fft_size;
float vtexel = 1.0 / (float) waterfall_lines; float vtexel = 1.0 / (float) waterfall_lines;
float vofs = (float) (waterfall_ofs[0] + 1) * vtexel; float vofs = (float) (waterfall_ofs[0] + 1) * vtexel;
glBindTexture(GL_TEXTURE_2D, waterfall[0]); glBindTexture(GL_TEXTURE_2D, waterfall[0]);
glBegin (GL_QUADS); glBegin (GL_QUADS);
glTexCoord2f(0.0 + half_texel, 1.0 + vofs); glTexCoord2f(0.0 + half_texel, 1.0 + vofs);
@ -122,7 +143,7 @@ void WaterfallContext::Draw(std::vector<float> &points) {
glTexCoord2f(0.0 + half_texel, 0.0 + vofs); glTexCoord2f(0.0 + half_texel, 0.0 + vofs);
glVertex3f(-1.0, 1.0, 0.0); glVertex3f(-1.0, 1.0, 0.0);
glEnd(); glEnd();
vofs = (float) (waterfall_ofs[1] + 1) * vtexel; vofs = (float) (waterfall_ofs[1] + 1) * vtexel;
glBindTexture(GL_TEXTURE_2D, waterfall[1]); glBindTexture(GL_TEXTURE_2D, waterfall[1]);
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -135,9 +156,9 @@ void WaterfallContext::Draw(std::vector<float> &points) {
glTexCoord2f(0.0 + half_texel, 0.0 + vofs); glTexCoord2f(0.0 + half_texel, 0.0 + vofs);
glVertex3f(0.0 - half_pixel, 1.0, 0.0); glVertex3f(0.0 - half_pixel, 1.0, 0.0);
glEnd(); glEnd();
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
} }

View File

@ -0,0 +1,26 @@
#pragma once
#include "GLPanel.h"
class WaterfallPanel : public GLPanel {
public:
WaterfallPanel();
void setup(int fft_size_in, int num_waterfall_lines_in);
void refreshTheme();
void setPoints(std::vector<float> &points);
void step();
protected:
void drawPanelContents();
private:
std::vector<float> points;
GLuint waterfall[2];
int waterfall_ofs[2];
int fft_size;
int waterfall_lines;
unsigned char *waterfall_slice;
ColorTheme *activeTheme;
};

View File

@ -23,12 +23,27 @@ void ScopeVisualProcessor::process() {
if (renderData->waveform_points.size() != iMax * 2) { if (renderData->waveform_points.size() != iMax * 2) {
renderData->waveform_points.resize(iMax * 2); renderData->waveform_points.resize(iMax * 2);
} }
float peak = 1.0f;
for (int i = 0; i < iMax; i++) { for (int i = 0; i < iMax; i++) {
renderData->waveform_points[i * 2 + 1] = audioInputData->data[i] * 0.5f; float p = fabs(audioInputData->data[i]);
renderData->waveform_points[i * 2] = ((double) i / (double) iMax); if (p > peak) {
peak = p;
}
} }
if (audioInputData->channels == 2) {
for (int i = 0; i < iMax; i++) {
renderData->waveform_points[i * 2] = (((double) (i % (iMax/2)) / (double) iMax) * 2.0 - 0.5) * 2.0;
renderData->waveform_points[i * 2 + 1] = audioInputData->data[i] / peak;
}
} else {
for (int i = 0; i < iMax; i++) {
renderData->waveform_points[i * 2] = (((double) i / (double) iMax) - 0.5) * 2.0;
renderData->waveform_points[i * 2 + 1] = audioInputData->data[i] / peak;
}
}
distribute(renderData); distribute(renderData);
} }
} }

View File

@ -13,6 +13,8 @@ GLPanel::GLPanel() : fillType(GLPANEL_FILL_SOLID), contentsVisible(true), transf
fill[1] = RGB3f(0.1,0.1,0.1); fill[1] = RGB3f(0.1,0.1,0.1);
borderColor = RGB3f(0.8, 0.8, 0.8); borderColor = RGB3f(0.8, 0.8, 0.8);
setCoordinateSystem(GLPANEL_Y_UP); setCoordinateSystem(GLPANEL_Y_UP);
setMarginPx(0);
setBorderPx(0);
} }
void GLPanel::genArrays() { void GLPanel::genArrays() {
@ -225,7 +227,7 @@ void GLPanel::drawPanelContents() {
void GLPanel::calcTransform(mat4 transform_in) { void GLPanel::calcTransform(mat4 transform_in) {
// compute local transform // compute local transform
localTransform = mat4::translate(pos[0], pos[1], 0) * mat4::scale(size[0], size[1], 0); localTransform = mat4::translate(pos[0], pos[1], 0) * mat4::scale(size[0], size[1], 1);
// compute global transform // compute global transform
transform = transform_in * localTransform; transform = transform_in * localTransform;
@ -250,10 +252,10 @@ void GLPanel::calcTransform(mat4 transform_in) {
pdim = vec2((vmax.x - vmin.x) / 2.0 * view[0], (vmax.y - vmin.y) / 2.0 * view[1]); pdim = vec2((vmax.x - vmin.x) / 2.0 * view[0], (vmax.y - vmin.y) / 2.0 * view[1]);
pvec = vec2(((vmax.x - vmin.x) / 2.0) / pdim.x, ((vmax.y - vmin.y) / 2.0) / pdim.y); pvec = vec2(((vmax.x - vmin.x) / 2.0) / pdim.x, ((vmax.y - vmin.y) / 2.0) / pdim.y);
std::cout << umin << " :: " << ucenter << " :: " << pdim << " :: " << pvec << std::endl; // std::cout << umin << " :: " << ucenter << " :: " << pdim << " :: " << pvec << std::endl;
if (marginPx) { if (marginPx) {
transform *= mat4::scale(1.0 - marginPx * 2.0 * pvec.x / size[0], 1.0 - marginPx * 2.0 * pvec.y / size[1], 0); transform *= mat4::scale(1.0 - marginPx * 2.0 * pvec.x / size[0], 1.0 - marginPx * 2.0 * pvec.y / size[1], 1);
} }
} }

View File

@ -36,9 +36,6 @@ UITestCanvas::~UITestCanvas() {
void UITestCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { void UITestCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this); wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize(); const wxSize ClientSize = GetClientSize();
glContext->SetCurrent(*this); glContext->SetCurrent(*this);

View File

@ -36,6 +36,8 @@ void initGLExtensions() {
std::cout << std::endl << "Supported GL Extensions: " << std::endl << extensions << std::endl << std::endl; std::cout << std::endl << "Supported GL Extensions: " << std::endl << extensions << std::endl << std::endl;
const GLint interval = 1;
#ifdef _WIN32 #ifdef _WIN32
if (GLExtSupported("WGL_EXT_swap_control")) { if (GLExtSupported("WGL_EXT_swap_control")) {
std::cout << "Initializing WGL swap control extensions.." << std::endl; std::cout << "Initializing WGL swap control extensions.." << std::endl;
@ -48,8 +50,7 @@ void initGLExtensions() {
#ifdef __APPLE__ #ifdef __APPLE__
// OSX is just ON / OFF // OSX is just ON / OFF
const GLint gl_interval = 1; CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &interval);
CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &gl_interval);
#endif #endif
#ifdef __linux__ #ifdef __linux__

View File

@ -35,6 +35,9 @@ public:
b = other.b; b = other.b;
return *this; return *this;
} }
RGB3f operator*(float v) { return RGB3f(r*v, g*v, b*v); }
}; };
class ColorTheme { class ColorTheme {

View File

@ -60,9 +60,6 @@ float MeterCanvas::getInputValue() {
void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this); wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize(); const wxSize ClientSize = GetClientSize();
glContext->SetCurrent(*this); glContext->SetCurrent(*this);
@ -82,7 +79,7 @@ void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
} }
void MeterCanvas::OnIdle(wxIdleEvent &event) { void MeterCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false); event.Skip();
} }
void MeterCanvas::OnMouseMoved(wxMouseEvent& event) { void MeterCanvas::OnMouseMoved(wxMouseEvent& event) {
@ -115,6 +112,7 @@ void MeterCanvas::OnMouseReleased(wxMouseEvent& event) {
void MeterCanvas::OnMouseLeftWindow(wxMouseEvent& event) { void MeterCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseLeftWindow(event); InteractiveCanvas::OnMouseLeftWindow(event);
SetCursor(wxCURSOR_CROSS); SetCursor(wxCURSOR_CROSS);
Refresh();
} }
void MeterCanvas::OnMouseEnterWindow(wxMouseEvent& event) { void MeterCanvas::OnMouseEnterWindow(wxMouseEvent& event) {

View File

@ -47,10 +47,7 @@ int ModeSelectorCanvas::getHoveredSelection() {
void ModeSelectorCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { void ModeSelectorCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this); wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate? const wxSize ClientSize = GetClientSize();
glFinish();
#endif
const wxSize ClientSize = GetClientSize();
glContext->SetCurrent(*this); glContext->SetCurrent(*this);
initGLExtensions(); initGLExtensions();
@ -75,7 +72,7 @@ void ModeSelectorCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
} }
void ModeSelectorCanvas::OnIdle(wxIdleEvent &event) { void ModeSelectorCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false); event.Skip();
} }
void ModeSelectorCanvas::OnMouseMoved(wxMouseEvent& event) { void ModeSelectorCanvas::OnMouseMoved(wxMouseEvent& event) {
@ -109,6 +106,7 @@ void ModeSelectorCanvas::OnMouseReleased(wxMouseEvent& event) {
void ModeSelectorCanvas::OnMouseLeftWindow(wxMouseEvent& event) { void ModeSelectorCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseLeftWindow(event); InteractiveCanvas::OnMouseLeftWindow(event);
SetCursor (wxCURSOR_CROSS); SetCursor (wxCURSOR_CROSS);
Refresh();
} }
void ModeSelectorCanvas::OnMouseEnterWindow(wxMouseEvent& event) { void ModeSelectorCanvas::OnMouseEnterWindow(wxMouseEvent& event) {

View File

@ -15,6 +15,7 @@
#include "AppFrame.h" #include "AppFrame.h"
#include <algorithm> #include <algorithm>
wxBEGIN_EVENT_TABLE(ScopeCanvas, wxGLCanvas) EVT_PAINT(ScopeCanvas::OnPaint) wxBEGIN_EVENT_TABLE(ScopeCanvas, wxGLCanvas) EVT_PAINT(ScopeCanvas::OnPaint)
EVT_IDLE(ScopeCanvas::OnIdle) EVT_IDLE(ScopeCanvas::OnIdle)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
@ -50,31 +51,20 @@ bool ScopeCanvas::getPPMMode() {
void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this); wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize(); const wxSize ClientSize = GetClientSize();
wxGetApp().getScopeProcessor()->run();
if (!inputData.empty()) { if (!inputData.empty()) {
ScopeRenderData *avData; ScopeRenderData *avData;
inputData.pop(avData); inputData.pop(avData);
if (!avData) { if (avData) {
return; if (avData->waveform_points.size()) {
} scopePanel.setPoints(avData->waveform_points);
setStereo(avData->channels == 2);
int iMax = avData->waveform_points.size(); }
if (!iMax) {
avData->decRefCount(); avData->decRefCount();
return;
} }
waveform_points.assign(avData->waveform_points.begin(),avData->waveform_points.end());
setStereo(avData->channels == 2);
avData->decRefCount();
} }
glContext->SetCurrent(*this); glContext->SetCurrent(*this);
@ -83,7 +73,10 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
glViewport(0, 0, ClientSize.x, ClientSize.y); glViewport(0, 0, ClientSize.x, ClientSize.y);
glContext->DrawBegin(); 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()) { if (!deviceName.empty()) {
glContext->DrawDeviceName(deviceName); glContext->DrawDeviceName(deviceName);
} }
@ -94,7 +87,7 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
} }
void ScopeCanvas::OnIdle(wxIdleEvent &event) { void ScopeCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false); event.Skip();
} }
ScopeRenderDataQueue *ScopeCanvas::getInputQueue() { ScopeRenderDataQueue *ScopeCanvas::getInputQueue() {

View File

@ -8,12 +8,11 @@
#include "ScopeContext.h" #include "ScopeContext.h"
#include "ScopeVisualProcessor.h" #include "ScopeVisualProcessor.h"
#include "ScopePanel.h"
#include "fftw3.h" #include "fftw3.h"
class ScopeCanvas: public wxGLCanvas { class ScopeCanvas: public wxGLCanvas {
public: public:
std::vector<float> waveform_points;
ScopeCanvas(wxWindow *parent, int *attribList = NULL); ScopeCanvas(wxWindow *parent, int *attribList = NULL);
~ScopeCanvas(); ~ScopeCanvas();
@ -29,6 +28,7 @@ private:
void OnIdle(wxIdleEvent &event); void OnIdle(wxIdleEvent &event);
ScopeRenderDataQueue inputData; ScopeRenderDataQueue inputData;
ScopePanel scopePanel;
ScopeContext *glContext; ScopeContext *glContext;
std::string deviceName; std::string deviceName;
bool stereo; bool stereo;

View File

@ -23,56 +23,8 @@ void ScopeContext::DrawBegin() {
glDisable (GL_TEXTURE_2D); glDisable (GL_TEXTURE_2D);
} }
void ScopeContext::Plot(std::vector<float> &points, bool stereo, bool ppmMode) { void ScopeContext::DrawTunerTitles(bool ppmMode) {
if (stereo) { glLoadIdentity();
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);
GLint vp[4]; GLint vp[4];
glGetIntegerv(GL_VIEWPORT, vp); 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(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("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); 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) { void ScopeContext::DrawDeviceName(std::string deviceName) {

View File

@ -12,7 +12,7 @@ public:
ScopeContext(ScopeCanvas *canvas, wxGLContext *sharedContext); ScopeContext(ScopeCanvas *canvas, wxGLContext *sharedContext);
void DrawBegin(); 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 DrawDeviceName(std::string deviceName);
void DrawDivider(); void DrawDivider();
void DrawEnd(); void DrawEnd();

View File

@ -29,7 +29,7 @@ wxEND_EVENT_TABLE()
SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) : SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), waterfallCanvas(NULL) { InteractiveCanvas(parent, attribList), waterfallCanvas(NULL) {
glContext = new SpectrumContext(this, &wxGetApp().GetContext(this)); glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));
mouseTracker.setVertDragLock(true); mouseTracker.setVertDragLock(true);
@ -42,35 +42,35 @@ SpectrumCanvas::~SpectrumCanvas() {
void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this); wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize(); const wxSize ClientSize = GetClientSize();
if (visualDataQueue.empty()) { if (!visualDataQueue.empty()) {
return; 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); glContext->SetCurrent(*this);
initGLExtensions(); initGLExtensions();
glViewport(0, 0, ClientSize.x, ClientSize.y); 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->BeginDraw(0,0,0);
glContext->Draw(spectrum_points, getCenterFrequency(), getBandwidth());
spectrumPanel.setFreq(getCenterFrequency());
spectrumPanel.setBandwidth(getBandwidth());
spectrumPanel.calcTransform(CubicVR::mat4::identity());
spectrumPanel.draw();
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators(); std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
for (int i = 0, iMax = demods.size(); i < iMax; i++) { 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) { void SpectrumCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false); event.Skip();
} }
@ -159,10 +159,6 @@ void SpectrumCanvas::attachWaterfallCanvas(WaterfallCanvas* canvas_in) {
waterfallCanvas = canvas_in; waterfallCanvas = canvas_in;
} }
SpectrumContext* SpectrumCanvas::getSpectrumContext() {
return glContext;
}
SpectrumVisualDataQueue *SpectrumCanvas::getVisualDataQueue() { SpectrumVisualDataQueue *SpectrumCanvas::getVisualDataQueue() {
return &visualDataQueue; return &visualDataQueue;
} }

View File

@ -1,31 +1,24 @@
#pragma once #pragma once
#include "wx/glcanvas.h"
#include "wx/timer.h"
#include <vector> #include <vector>
#include <queue> #include <queue>
#include "InteractiveCanvas.h" #include "InteractiveCanvas.h"
#include "SpectrumContext.h" #include "PrimaryGLContext.h"
#include "fftw3.h"
#include "MouseTracker.h" #include "MouseTracker.h"
#include "SpectrumVisualProcessor.h" #include "SpectrumVisualProcessor.h"
#include "SpectrumPanel.h"
class WaterfallCanvas; class WaterfallCanvas;
class SpectrumCanvas: public InteractiveCanvas { class SpectrumCanvas: public InteractiveCanvas {
public: public:
std::vector<float> spectrum_points;
SpectrumCanvas(wxWindow *parent, int *attribList = NULL); SpectrumCanvas(wxWindow *parent, int *attribList = NULL);
~SpectrumCanvas(); ~SpectrumCanvas();
void attachWaterfallCanvas(WaterfallCanvas *canvas_in); void attachWaterfallCanvas(WaterfallCanvas *canvas_in);
void moveCenterFrequency(long long freqChange); void moveCenterFrequency(long long freqChange);
SpectrumContext* getSpectrumContext();
SpectrumVisualDataQueue *getVisualDataQueue(); SpectrumVisualDataQueue *getVisualDataQueue();
private: private:
@ -39,8 +32,9 @@ private:
void OnMouseReleased(wxMouseEvent& event); void OnMouseReleased(wxMouseEvent& event);
void OnMouseLeftWindow(wxMouseEvent& event); void OnMouseLeftWindow(wxMouseEvent& event);
SpectrumContext *glContext; PrimaryGLContext *glContext;
WaterfallCanvas *waterfallCanvas; WaterfallCanvas *waterfallCanvas;
SpectrumPanel spectrumPanel;
SpectrumVisualDataQueue visualDataQueue; SpectrumVisualDataQueue visualDataQueue;

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;
};

View File

@ -31,7 +31,7 @@ EVT_KEY_UP(TuningCanvas::OnKeyUp)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
TuningCanvas::TuningCanvas(wxWindow *parent, int *attribList) : 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)); 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)) { void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this); wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize(); const wxSize ClientSize = GetClientSize();
glContext->SetCurrent(*this); glContext->SetCurrent(*this);
initGLExtensions(); initGLExtensions();
glViewport(0, 0, ClientSize.x, ClientSize.y); glViewport(0, 0, ClientSize.x, ClientSize.y);
@ -71,13 +85,13 @@ void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
glContext->DrawBegin(); glContext->DrawBegin();
DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
long long freq = 0; freq = 0;
if (activeDemod != NULL) { if (activeDemod != NULL) {
freq = activeDemod->getFrequency(); freq = activeDemod->getFrequency();
} }
long long bw = wxGetApp().getDemodMgr().getLastBandwidth(); bw = wxGetApp().getDemodMgr().getLastBandwidth();
long long center = wxGetApp().getFrequency(); center = wxGetApp().getFrequency();
if (mouseTracker.mouseDown()) { if (mouseTracker.mouseDown()) {
glContext->Draw(ThemeMgr::mgr.currentTheme->tuningBarDark.r, ThemeMgr::mgr.currentTheme->tuningBarDark.g, ThemeMgr::mgr.currentTheme->tuningBarDark.b, 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; dragging = false;
} }
} }
Refresh(false);
} }
void TuningCanvas::OnMouseMoved(wxMouseEvent& event) { void TuningCanvas::OnMouseMoved(wxMouseEvent& event) {
@ -373,6 +385,7 @@ void TuningCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
if (currentPPM != lastPPM) { if (currentPPM != lastPPM) {
wxGetApp().saveConfig(); wxGetApp().saveConfig();
} }
Refresh();
} }
void TuningCanvas::OnMouseEnterWindow(wxMouseEvent& event) { void TuningCanvas::OnMouseEnterWindow(wxMouseEvent& event) {

View File

@ -22,7 +22,8 @@ public:
~TuningCanvas(); ~TuningCanvas();
void setHelpTip(std::string tip); void setHelpTip(std::string tip);
bool changed();
private: private:
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
void OnIdle(wxIdleEvent &event); void OnIdle(wxIdleEvent &event);
@ -66,6 +67,7 @@ private:
int currentPPM; int currentPPM;
int lastPPM; int lastPPM;
long long freq, bw, center;
// //
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };

View File

@ -35,10 +35,10 @@ EVT_MOUSEWHEEL(WaterfallCanvas::OnMouseWheelMoved)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) : WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines( InteractiveCanvas(parent, attribList), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines(0),
0), mouseZoom(1), zoom(1), hoverAlpha(1.0), dragOfs(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); SetCursor(wxCURSOR_CROSS);
} }
@ -53,7 +53,7 @@ void WaterfallCanvas::setup(int fft_size_in, int waterfall_lines_in) {
fft_size = fft_size_in; fft_size = fft_size_in;
waterfall_lines = waterfall_lines_in; waterfall_lines = waterfall_lines_in;
glContext->Setup(fft_size, waterfall_lines); waterfallPanel.setup(fft_size, waterfall_lines);
} }
WaterfallCanvas::DragState WaterfallCanvas::getDragState() { WaterfallCanvas::DragState WaterfallCanvas::getDragState() {
@ -70,9 +70,6 @@ void WaterfallCanvas::attachSpectrumCanvas(SpectrumCanvas *canvas_in) {
void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this); wxPaintDC dc(this);
#ifdef __APPLE__ // force half-rate?
glFinish();
#endif
const wxSize ClientSize = GetClientSize(); const wxSize ClientSize = GetClientSize();
long double currentZoom = zoom; long double currentZoom = zoom;
@ -138,29 +135,27 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2; 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); glContext->SetCurrent(*this);
initGLExtensions(); initGLExtensions();
glViewport(0, 0, ClientSize.x, ClientSize.y); 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->BeginDraw(0,0,0);
glContext->Draw(spectrum_points);
waterfallPanel.calcTransform(CubicVR::mat4::identity());
waterfallPanel.draw();
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators(); std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
@ -352,7 +347,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
} }
} }
void WaterfallCanvas::OnIdle(wxIdleEvent &event) { void WaterfallCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false); event.Skip();
} }
void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) {
@ -715,4 +710,4 @@ void WaterfallCanvas::OnMouseRightReleased(wxMouseEvent& event) {
SpectrumVisualDataQueue *WaterfallCanvas::getVisualDataQueue() { SpectrumVisualDataQueue *WaterfallCanvas::getVisualDataQueue() {
return &visualDataQueue; return &visualDataQueue;
} }

View File

@ -7,9 +7,9 @@
#include <queue> #include <queue>
#include "InteractiveCanvas.h" #include "InteractiveCanvas.h"
#include "WaterfallContext.h"
#include "MouseTracker.h" #include "MouseTracker.h"
#include "SpectrumCanvas.h" #include "SpectrumCanvas.h"
#include "WaterfallPanel.h"
class WaterfallCanvas: public InteractiveCanvas { class WaterfallCanvas: public InteractiveCanvas {
@ -47,8 +47,8 @@ private:
std::vector<float> spectrum_points; std::vector<float> spectrum_points;
SpectrumCanvas *spectrumCanvas; SpectrumCanvas *spectrumCanvas;
PrimaryGLContext *glContext;
WaterfallContext *glContext; WaterfallPanel waterfallPanel;
DragState dragState; DragState dragState;
DragState nextDragState; DragState nextDragState;

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;
};