diff --git a/CMakeLists.txt b/CMakeLists.txt index 209f2a0..3697dfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,6 +244,9 @@ SET (cubicsdr_sources src/util/GLExt.cpp src/util/GLFont.cpp src/util/DataTree.cpp + src/panel/ScopePanel.cpp + src/panel/SpectrumPanel.cpp + src/panel/WaterfallPanel.cpp src/visual/ColorTheme.cpp src/visual/PrimaryGLContext.cpp src/visual/InteractiveCanvas.cpp @@ -256,9 +259,7 @@ SET (cubicsdr_sources src/visual/ScopeCanvas.cpp src/visual/ScopeContext.cpp src/visual/SpectrumCanvas.cpp - src/visual/SpectrumContext.cpp src/visual/WaterfallCanvas.cpp - src/visual/WaterfallContext.cpp src/process/VisualProcessor.cpp src/process/ScopeVisualProcessor.cpp src/process/SpectrumVisualProcessor.cpp @@ -296,6 +297,9 @@ SET (cubicsdr_headers src/util/GLExt.h src/util/GLFont.h src/util/DataTree.h + src/panel/ScopePanel.h + src/panel/SpectrumPanel.h + src/panel/WaterfallPanel.h src/visual/ColorTheme.h src/visual/PrimaryGLContext.h src/visual/InteractiveCanvas.h @@ -308,9 +312,7 @@ SET (cubicsdr_headers src/visual/ScopeCanvas.h src/visual/ScopeContext.h src/visual/SpectrumCanvas.h - src/visual/SpectrumContext.h src/visual/WaterfallCanvas.h - src/visual/WaterfallContext.h src/process/VisualProcessor.h src/process/ScopeVisualProcessor.h src/process/SpectrumVisualProcessor.h @@ -339,11 +341,28 @@ SET (cubicsdr_headers 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 ( ${PROJECT_SOURCE_DIR}/src/sdr ${PROJECT_SOURCE_DIR}/src/demod ${PROJECT_SOURCE_DIR}/src/audio ${PROJECT_SOURCE_DIR}/src/util + ${PROJECT_SOURCE_DIR}/src/panel ${PROJECT_SOURCE_DIR}/src/visual ${PROJECT_SOURCE_DIR}/src/process ${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_mono32_0.png ${PROJECT_SOURCE_DIR}/font/vera_sans_mono48_0.png + ${PROJECT_SOURCE_DIR}/src/CubicSDR.png DESTINATION share/cubicsdr) - + INSTALL(FILES CubicSDR.desktop + DESTINATION share/applications) INCLUDE(CPack) ENDIF (UNIX AND BUILD_DEB) diff --git a/CubicSDR.desktop b/CubicSDR.desktop new file mode 100644 index 0000000..6cb140c --- /dev/null +++ b/CubicSDR.desktop @@ -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; diff --git a/README.md b/README.md index a60e845..79a923b 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,8 @@ Features and Status: - Simple UI - Devices - [x] RTL-SDR - - [ ] rtl_tcp - - [ ] HackRF - - [ ] Whatever else I can get my hands on + - [ ] rtl_tcp client + - [ ] gr-osmosdr - Basic Features - [x] Device Selection - [x] Bandwidth @@ -33,18 +32,21 @@ Features and Status: - [x] Device PPM - [ ] Default preferences - [ ] Audio defaults - - [ ] Device defaults + - [x] Device defaults - [ ] Bookmarks - [ ] History + - [ ] Run as rtl_tcp server and visualize control - Neat Visuals - - [x] Scope - - [x] Spectrum - - [x] Waterfall - - [ ] Audio Spectrum - - [ ] More 2D visuals + - [ ] 2D visuals + - [x] Y Scope + - [x] Spectrum + - [x] Waterfall - [x] Add faint grid for sense of scale + - [ ] Audio Spectrum + - [ ] X/Y Scope - [ ] Indicate outer spectrum edges when zoomed - [ ] 3D visuals + - [ ] I/Q helix - Demodulation: - [ ] Basic modular expansion - [x] Multiple demodulators per IQ stream @@ -56,7 +58,7 @@ Features and Status: - [x] LSB - [x] USB - [x] DSB - - [ ] RAW + - [x] I/Q - [ ] Controls - [x] Display Frequency and allow manual adjustments - [x] Allow selection of demodulation type @@ -64,8 +66,10 @@ Features and Status: - [x] Display signal level and allow squelch control - [x] Display audio output selection - [x] Volume control - - [ ] Demodulator input filtering - - [ ] Audio filtering + - [x] Direct frequency input + - [ ] Mute + - [ ] Waterfall speed + - [ ] RTL-SDR Gain - Basic Input Controls - [x] Drag spectrum to change center frequency - [x] Hold shift and click on waterfall to create a new demodulator @@ -88,6 +92,8 @@ Features and Status: - [ ] Recording - Implement digital demodulation supported by liquid-dsp: (http://liquidsdr.org/doc/modem.html) - [ ] Demodulator Lab + - [ ] Demodulator I/Q input filtering + - [ ] Audio output filtering - [ ] Toggle current demodulator exclusively into "Lab" mode - [ ] Additional visualizations for audio and I/Q stream - [ ] Audio Spectrum @@ -115,9 +121,9 @@ Features and Status: - [ ] CPFSK - Optimization - [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 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 @@ -140,6 +146,7 @@ Advanced Goals and ideas: * Take control of additional devices and spawning new demodulators (i.e. trunkers) * Script manager / live editor * Provide scriptable liquid-dsp modulation for trancievers? + * Allow scripts to launch/run headless (no UI) - "PVR" like mode with waterfall time shifting - L/R and surround-sound balance settings for separating and listening to mono streams - Add tool for converting decimated I/Q recording to video diff --git a/external/cubicvr2/math/mat3.h b/external/cubicvr2/math/mat3.h index e96b0db..8f5ab22 100644 --- a/external/cubicvr2/math/mat3.h +++ b/external/cubicvr2/math/mat3.h @@ -23,7 +23,9 @@ namespace CubicVR { __float a,b,c,d,e,f,g,h,i; // __float operator [] (unsigned i) const { return ((__float *)this)[i]; } +#ifndef _WIN32 __float& operator [] (unsigned i) { return ((__float *)this)[i]; } +#endif 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) { diff --git a/external/cubicvr2/math/mat4.h b/external/cubicvr2/math/mat4.h index b46409c..0059cd8 100644 --- a/external/cubicvr2/math/mat4.h +++ b/external/cubicvr2/math/mat4.h @@ -25,7 +25,10 @@ namespace CubicVR { __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]; } +#ifndef _WIN32 __float& operator [] (unsigned i) { return ((__float *)this)[i]; } +#endif + 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) { 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; diff --git a/external/cubicvr2/math/vec2.h b/external/cubicvr2/math/vec2.h index d7a7aad..24011c7 100644 --- a/external/cubicvr2/math/vec2.h +++ b/external/cubicvr2/math/vec2.h @@ -25,8 +25,9 @@ namespace CubicVR { __float& v() { return y; } // __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 () { x = y = 0.0f; } diff --git a/external/cubicvr2/math/vec3.h b/external/cubicvr2/math/vec3.h index 9dcdca6..220bf60 100644 --- a/external/cubicvr2/math/vec3.h +++ b/external/cubicvr2/math/vec3.h @@ -29,7 +29,9 @@ namespace CubicVR { __float& g() { return y; } __float& b() { return z; } +#ifndef _WIN32 __float& operator [] (unsigned i) { return ((__float *)this)[i]; } +#endif vec3 (__float xi,__float yi,__float zi) { x = xi; y = yi; z = zi; } vec3 () { x = y = z = 0.0f; } diff --git a/external/cubicvr2/math/vec4.h b/external/cubicvr2/math/vec4.h index 5975079..ad795c1 100644 --- a/external/cubicvr2/math/vec4.h +++ b/external/cubicvr2/math/vec4.h @@ -28,8 +28,10 @@ namespace CubicVR { __float& a() { return w; } // __float operator [] (unsigned i) const { return ((__float *)this)[i]; } +#ifndef _WIN32 __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 () { x = y = z = w = 0.0f; } diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 08db73a..86d654d 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -35,10 +35,11 @@ EVT_CLOSE(AppFrame::OnClose) EVT_MENU(wxID_ANY, AppFrame::OnMenu) EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread) EVT_IDLE(AppFrame::OnIdle) +EVT_TIMER(FRAME_TIMER_ID, AppFrame::OnTimer) wxEND_EVENT_TABLE() 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__ SetIcon(wxICON(cubicsdr)); @@ -377,6 +378,8 @@ AppFrame::AppFrame() : wxAcceleratorTable accel(3, entries); SetAcceleratorTable(accel); + // frame rate = 1000 / 30 = 33ms + frame_timer.Start(33); // static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 }; // wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not"); // ShowFullScreen(true); @@ -479,6 +482,11 @@ void AppFrame::OnMenu(wxCommandEvent& event) { ThemeMgr::mgr.setTheme(COLOR_THEME_RADAR); } + if (event.GetId() >= wxID_THEME_DEFAULT && event.GetId() <= wxID_THEME_RADAR) { + demodTuner->Refresh(); + demodModeSelector->Refresh(); + } + switch (event.GetId()) { case wxID_BANDWIDTH_250K: wxGetApp().setSampleRate(250000); @@ -587,6 +595,10 @@ void AppFrame::OnThread(wxCommandEvent& event) { } void AppFrame::OnIdle(wxIdleEvent& event) { + event.Skip(); +} + +void AppFrame::OnTimer(wxTimerEvent& event) { DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); @@ -733,7 +745,7 @@ void AppFrame::OnIdle(wxIdleEvent& event) { scopeCanvas->setPPMMode(demodTuner->isAltDown()); - + wxGetApp().getScopeProcessor()->run(); wxGetApp().getSpectrumDistributor()->run(); SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcesor(); @@ -751,6 +763,24 @@ void AppFrame::OnIdle(wxIdleEvent& event) { dproc->setCenterFrequency(demodWaterfallCanvas->getCenterFrequency()); 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(); } diff --git a/src/AppFrame.h b/src/AppFrame.h index 5ccf413..9182fa6 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -50,7 +50,7 @@ #define wxID_AUDIO_BANDWIDTH_BASE 9000 #define wxID_AUDIO_DEVICE_MULTIPLIER 50 - +#define FRAME_TIMER_ID 1000 // Define a new frame type class AppFrame: public wxFrame { @@ -69,6 +69,7 @@ private: void OnClose(wxCloseEvent& event); void OnNewWindow(wxCommandEvent& event); void OnIdle(wxIdleEvent& event); + void OnTimer(wxTimerEvent& event); ScopeCanvas *scopeCanvas; @@ -96,6 +97,7 @@ private: wxMenuItem *iqSwapMenuItem; std::string currentSessionFile; - + wxTimer frame_timer; + wxDECLARE_EVENT_TABLE(); }; diff --git a/src/CubicSDR.png b/src/CubicSDR.png new file mode 100644 index 0000000..14b565c Binary files /dev/null and b/src/CubicSDR.png differ diff --git a/src/panel/ScopePanel.cpp b/src/panel/ScopePanel.cpp new file mode 100644 index 0000000..c50fa08 --- /dev/null +++ b/src/panel/ScopePanel.cpp @@ -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 &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); + } +} + diff --git a/src/panel/ScopePanel.h b/src/panel/ScopePanel.h new file mode 100644 index 0000000..7d72756 --- /dev/null +++ b/src/panel/ScopePanel.h @@ -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 &points); + +protected: + void drawPanelContents(); + +private: + std::vector points; + ScopeMode scopeMode; + GLPanel bgPanel; + GLPanel bgPanelStereo[2]; +}; \ No newline at end of file diff --git a/src/visual/SpectrumContext.cpp b/src/panel/SpectrumPanel.cpp similarity index 70% rename from src/visual/SpectrumContext.cpp rename to src/panel/SpectrumPanel.cpp index 22b78b7..4e33087 100644 --- a/src/visual/SpectrumContext.cpp +++ b/src/panel/SpectrumPanel.cpp @@ -1,82 +1,83 @@ -#include "SpectrumContext.h" +#include "SpectrumPanel.h" -#include "SpectrumCanvas.h" -#include "CubicSDR.h" #include #include #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(); - +SpectrumPanel::SpectrumPanel() : floorValue(0), ceilValue(1) { + setFill(GLPANEL_FILL_GRAD_Y); + setFillColor(ThemeMgr::mgr.currentTheme->fftBackground * 2.0, ThemeMgr::mgr.currentTheme->fftBackground); } -float SpectrumContext::getFloorValue() const { +float SpectrumPanel::getFloorValue() const { return floorValue; } -void SpectrumContext::setFloorValue(float floorValue) { +void SpectrumPanel::setFloorValue(float floorValue) { this->floorValue = floorValue; } -float SpectrumContext::getCeilValue() const { +float SpectrumPanel::getCeilValue() const { return ceilValue; } -void SpectrumContext::setCeilValue(float ceilValue) { +void SpectrumPanel::setCeilValue(float ceilValue) { this->ceilValue = ceilValue; } -void SpectrumContext::Draw(std::vector &points, long long freq, int bandwidth) { +void SpectrumPanel::setFreq(long long freq) { + this->freq = freq; +} - 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(); +long long SpectrumPanel::getFreq() { + return freq; +} + +void SpectrumPanel::setBandwidth(long long bandwidth) { + this->bandwidth = bandwidth; +} + +long long SpectrumPanel::getBandwidth() { + return bandwidth; +} + +void SpectrumPanel::setPoints(std::vector &points) { + this->points.assign(points.begin(), points.end()); +} +void SpectrumPanel::drawPanelContents() { glDisable(GL_TEXTURE_2D); - + glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); 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()) { - 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) { @@ -86,76 +87,74 @@ void SpectrumContext::Draw(std::vector &points, long long freq, int bandw 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(); } + + glLoadMatrixf(transform); 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) { + + for (float m = -1.0 + mhzStart, mMax = 1.0 + ((mhzStart>0)?mhzStart:-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); + 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(); } diff --git a/src/panel/SpectrumPanel.h b/src/panel/SpectrumPanel.h new file mode 100644 index 0000000..af2d2f7 --- /dev/null +++ b/src/panel/SpectrumPanel.h @@ -0,0 +1,31 @@ +#pragma once + +#include "GLPanel.h" + +class SpectrumPanel : public GLPanel { +public: + SpectrumPanel(); + + void setPoints(std::vector &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 points; +}; \ No newline at end of file diff --git a/src/visual/WaterfallContext.cpp b/src/panel/WaterfallPanel.cpp similarity index 76% rename from src/visual/WaterfallContext.cpp rename to src/panel/WaterfallPanel.cpp index 733cfc9..d3b0224 100644 --- a/src/visual/WaterfallContext.cpp +++ b/src/panel/WaterfallPanel.cpp @@ -1,34 +1,36 @@ -#include "WaterfallContext.h" -#include "WaterfallCanvas.h" -#include "CubicSDR.h" +#include "WaterfallPanel.h" -WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext) : - PrimaryGLContext(canvas, sharedContext), fft_size(0), waterfall_lines(0), waterfall_slice(NULL), activeTheme(NULL) { +WaterfallPanel::WaterfallPanel() : GLPanel(), fft_size(0), waterfall_lines(0), waterfall_slice(NULL), activeTheme(NULL) { + setFillColor(RGB3f(0,0,0)); for (int i = 0; i < 2; i++) { 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; fft_size = fft_size_in; - + + if (points.size() != fft_size) { + points.resize(fft_size); + } + 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() { +void WaterfallPanel::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]); @@ -36,81 +38,100 @@ void WaterfallContext::refreshTheme() { } } -void WaterfallContext::Draw(std::vector &points) { +void WaterfallPanel::setPoints(std::vector &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; - 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]; - + + if (waterfall_slice != NULL) { + delete waterfall_slice; + } + waterfall_slice = new unsigned char[half_fft_size]; + 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) { 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); @@ -122,7 +143,7 @@ void WaterfallContext::Draw(std::vector &points) { 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); @@ -135,9 +156,9 @@ void WaterfallContext::Draw(std::vector &points) { 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); } diff --git a/src/panel/WaterfallPanel.h b/src/panel/WaterfallPanel.h new file mode 100644 index 0000000..65c664a --- /dev/null +++ b/src/panel/WaterfallPanel.h @@ -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 &points); + void step(); + +protected: + void drawPanelContents(); + +private: + std::vector points; + + GLuint waterfall[2]; + int waterfall_ofs[2]; + int fft_size; + int waterfall_lines; + unsigned char *waterfall_slice; + + ColorTheme *activeTheme; +}; diff --git a/src/process/ScopeVisualProcessor.cpp b/src/process/ScopeVisualProcessor.cpp index 4eff90d..7439977 100644 --- a/src/process/ScopeVisualProcessor.cpp +++ b/src/process/ScopeVisualProcessor.cpp @@ -23,12 +23,27 @@ void ScopeVisualProcessor::process() { if (renderData->waveform_points.size() != iMax * 2) { renderData->waveform_points.resize(iMax * 2); } + + float peak = 1.0f; for (int i = 0; i < iMax; i++) { - renderData->waveform_points[i * 2 + 1] = audioInputData->data[i] * 0.5f; - renderData->waveform_points[i * 2] = ((double) i / (double) iMax); + float p = fabs(audioInputData->data[i]); + 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); } } diff --git a/src/ui/GLPanel.cpp b/src/ui/GLPanel.cpp index 5de9387..c7e2bca 100644 --- a/src/ui/GLPanel.cpp +++ b/src/ui/GLPanel.cpp @@ -13,6 +13,8 @@ GLPanel::GLPanel() : fillType(GLPANEL_FILL_SOLID), contentsVisible(true), transf fill[1] = RGB3f(0.1,0.1,0.1); borderColor = RGB3f(0.8, 0.8, 0.8); setCoordinateSystem(GLPANEL_Y_UP); + setMarginPx(0); + setBorderPx(0); } void GLPanel::genArrays() { @@ -225,7 +227,7 @@ void GLPanel::drawPanelContents() { void GLPanel::calcTransform(mat4 transform_in) { // 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 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]); 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) { - 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); } } diff --git a/src/ui/UITestCanvas.cpp b/src/ui/UITestCanvas.cpp index e94a993..e3bf7d2 100644 --- a/src/ui/UITestCanvas.cpp +++ b/src/ui/UITestCanvas.cpp @@ -36,9 +36,6 @@ UITestCanvas::~UITestCanvas() { void UITestCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); -#ifdef __APPLE__ // force half-rate? - glFinish(); -#endif const wxSize ClientSize = GetClientSize(); glContext->SetCurrent(*this); diff --git a/src/util/GLExt.cpp b/src/util/GLExt.cpp index 1de46d8..47ccfdf 100644 --- a/src/util/GLExt.cpp +++ b/src/util/GLExt.cpp @@ -36,6 +36,8 @@ void initGLExtensions() { std::cout << std::endl << "Supported GL Extensions: " << std::endl << extensions << std::endl << std::endl; + const GLint interval = 1; + #ifdef _WIN32 if (GLExtSupported("WGL_EXT_swap_control")) { std::cout << "Initializing WGL swap control extensions.." << std::endl; @@ -48,8 +50,7 @@ void initGLExtensions() { #ifdef __APPLE__ // OSX is just ON / OFF - const GLint gl_interval = 1; - CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &gl_interval); + CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &interval); #endif #ifdef __linux__ diff --git a/src/visual/ColorTheme.h b/src/visual/ColorTheme.h index 1318ac6..52b431a 100644 --- a/src/visual/ColorTheme.h +++ b/src/visual/ColorTheme.h @@ -35,6 +35,9 @@ public: b = other.b; return *this; } + + RGB3f operator*(float v) { return RGB3f(r*v, g*v, b*v); } + }; class ColorTheme { diff --git a/src/visual/MeterCanvas.cpp b/src/visual/MeterCanvas.cpp index bb3c20b..423fc20 100644 --- a/src/visual/MeterCanvas.cpp +++ b/src/visual/MeterCanvas.cpp @@ -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) { diff --git a/src/visual/ModeSelectorCanvas.cpp b/src/visual/ModeSelectorCanvas.cpp index 1b859e3..98172b5 100644 --- a/src/visual/ModeSelectorCanvas.cpp +++ b/src/visual/ModeSelectorCanvas.cpp @@ -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) { diff --git a/src/visual/ScopeCanvas.cpp b/src/visual/ScopeCanvas.cpp index 5c6bd54..1063c16 100644 --- a/src/visual/ScopeCanvas.cpp +++ b/src/visual/ScopeCanvas.cpp @@ -15,6 +15,7 @@ #include "AppFrame.h" #include + 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() { diff --git a/src/visual/ScopeCanvas.h b/src/visual/ScopeCanvas.h index 23203b7..6cdff03 100644 --- a/src/visual/ScopeCanvas.h +++ b/src/visual/ScopeCanvas.h @@ -8,12 +8,11 @@ #include "ScopeContext.h" #include "ScopeVisualProcessor.h" +#include "ScopePanel.h" #include "fftw3.h" class ScopeCanvas: public wxGLCanvas { public: - std::vector 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; diff --git a/src/visual/ScopeContext.cpp b/src/visual/ScopeContext.cpp index 267b038..8c4a889 100644 --- a/src/visual/ScopeContext.cpp +++ b/src/visual/ScopeContext.cpp @@ -23,56 +23,8 @@ void ScopeContext::DrawBegin() { glDisable (GL_TEXTURE_2D); } -void ScopeContext::Plot(std::vector &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 &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) { diff --git a/src/visual/ScopeContext.h b/src/visual/ScopeContext.h index 4afc6ad..c962429 100644 --- a/src/visual/ScopeContext.h +++ b/src/visual/ScopeContext.h @@ -12,7 +12,7 @@ public: ScopeContext(ScopeCanvas *canvas, wxGLContext *sharedContext); void DrawBegin(); - void Plot(std::vector &points, bool stereo=false, bool ppmMode=false); + void DrawTunerTitles(bool ppmMode=false); void DrawDeviceName(std::string deviceName); void DrawDivider(); void DrawEnd(); diff --git a/src/visual/SpectrumCanvas.cpp b/src/visual/SpectrumCanvas.cpp index e618cc5..c9df1f0 100644 --- a/src/visual/SpectrumCanvas.cpp +++ b/src/visual/SpectrumCanvas.cpp @@ -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 &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; } \ No newline at end of file diff --git a/src/visual/SpectrumCanvas.h b/src/visual/SpectrumCanvas.h index eb05e79..6c891ae 100644 --- a/src/visual/SpectrumCanvas.h +++ b/src/visual/SpectrumCanvas.h @@ -1,31 +1,24 @@ #pragma once -#include "wx/glcanvas.h" -#include "wx/timer.h" - #include #include #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 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; diff --git a/src/visual/SpectrumContext.h b/src/visual/SpectrumContext.h deleted file mode 100644 index 03cc82a..0000000 --- a/src/visual/SpectrumContext.h +++ /dev/null @@ -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 &points, long long freq, int bandwidth); - - float getFloorValue() const; - void setFloorValue(float floorValue); - float getCeilValue() const; - void setCeilValue(float ceilValue); - -private: - float floorValue, ceilValue; -}; diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp index daed27e..cb618f6 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -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) { diff --git a/src/visual/TuningCanvas.h b/src/visual/TuningCanvas.h index 1fea2e2..2826363 100644 --- a/src/visual/TuningCanvas.h +++ b/src/visual/TuningCanvas.h @@ -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(); }; diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 7fe2011..a5269e2 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -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 &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; -} \ No newline at end of file +} diff --git a/src/visual/WaterfallCanvas.h b/src/visual/WaterfallCanvas.h index e7f3384..b570ffb 100644 --- a/src/visual/WaterfallCanvas.h +++ b/src/visual/WaterfallCanvas.h @@ -7,9 +7,9 @@ #include #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 spectrum_points; SpectrumCanvas *spectrumCanvas; - - WaterfallContext *glContext; + PrimaryGLContext *glContext; + WaterfallPanel waterfallPanel; DragState dragState; DragState nextDragState; diff --git a/src/visual/WaterfallContext.h b/src/visual/WaterfallContext.h deleted file mode 100644 index f42b5f9..0000000 --- a/src/visual/WaterfallContext.h +++ /dev/null @@ -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 &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; -};