2017-01-02 21:07:43 -05:00
|
|
|
// Copyright (c) Charles J. Cliffe
|
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
2014-10-27 21:22:29 -04:00
|
|
|
#include "PrimaryGLContext.h"
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "CubicSDR.h"
|
2014-10-30 22:51:33 -04:00
|
|
|
#include "CubicSDRDefs.h"
|
2014-11-04 19:52:11 -05:00
|
|
|
#include "AppFrame.h"
|
2014-10-30 22:51:33 -04:00
|
|
|
#include <algorithm>
|
2014-11-09 04:38:33 -05:00
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
wxString PrimaryGLContext::glGetwxString(GLenum name) {
|
2014-10-27 21:22:29 -04:00
|
|
|
const GLubyte *v = glGetString(name);
|
|
|
|
if (v == 0) {
|
|
|
|
// The error is not important. It is GL_INVALID_ENUM.
|
|
|
|
// We just want to clear the error stack.
|
|
|
|
glGetError();
|
|
|
|
|
|
|
|
return wxString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxString((const char*) v);
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
void PrimaryGLContext::CheckGLError() {
|
2014-10-27 21:22:29 -04:00
|
|
|
GLenum errLast = GL_NO_ERROR;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
GLenum err = glGetError();
|
|
|
|
if (err == GL_NO_ERROR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (err == errLast) {
|
2015-02-17 21:26:14 -05:00
|
|
|
std::cout << "OpenGL error state couldn't be reset." << std::endl;
|
2014-10-27 21:22:29 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errLast = err;
|
|
|
|
|
2015-02-17 21:26:14 -05:00
|
|
|
std::cout << "OpenGL Error " << err << std::endl;
|
2014-10-27 21:22:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
PrimaryGLContext::PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContext) :
|
2015-03-06 21:11:14 -05:00
|
|
|
wxGLContext(canvas, sharedContext), hoverAlpha(1.0) {
|
2015-01-20 19:13:49 -05:00
|
|
|
//#ifndef __linux__
|
|
|
|
// SetCurrent(*canvas);
|
|
|
|
// // Pre-load fonts
|
|
|
|
// for (int i = 0; i < GLFONT_MAX; i++) {
|
|
|
|
// getFont((GLFontSize) i);
|
|
|
|
// }
|
|
|
|
// CheckGLError();
|
|
|
|
//#endif
|
2014-10-27 21:22:29 -04:00
|
|
|
}
|
|
|
|
|
2017-08-27 05:11:30 -04:00
|
|
|
void PrimaryGLContext::DrawDemodInfo(DemodulatorInstancePtr demod, RGBA4f color, long long center_freq, long long srate, bool centerline) {
|
2014-12-09 21:28:08 -05:00
|
|
|
if (!demod) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-11 17:08:16 -05:00
|
|
|
if (!srate) {
|
|
|
|
srate = wxGetApp().getSampleRate();
|
|
|
|
}
|
2014-12-09 21:28:08 -05:00
|
|
|
|
2014-12-10 00:34:27 -05:00
|
|
|
GLint vp[4];
|
|
|
|
glGetIntegerv( GL_VIEWPORT, vp);
|
|
|
|
|
|
|
|
float viewHeight = (float) vp[3];
|
|
|
|
float viewWidth = (float) vp[2];
|
|
|
|
|
2014-12-28 05:13:46 -05:00
|
|
|
if (center_freq == -1) {
|
|
|
|
center_freq = wxGetApp().getFrequency();
|
|
|
|
}
|
2016-02-17 20:45:56 -05:00
|
|
|
|
|
|
|
long long demodFreq = demod->getFrequency();
|
2014-12-28 05:13:46 -05:00
|
|
|
|
2016-02-17 20:45:56 -05:00
|
|
|
if (demod->isDeltaLock()) {
|
2016-02-17 23:01:42 -05:00
|
|
|
demodFreq = wxGetApp().getFrequency() + demod->getDeltaLockOfs();
|
2016-02-17 20:45:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
float uxPos = (float) (demodFreq - (center_freq - srate / 2)) / (float) srate;
|
2014-12-10 00:34:27 -05:00
|
|
|
uxPos = (uxPos - 0.5) * 2.0;
|
2014-12-09 21:28:08 -05:00
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
2015-01-15 20:37:51 -05:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(color.r, color.g, color.b, 0.6f);
|
2014-12-09 21:28:08 -05:00
|
|
|
|
2015-01-04 13:20:31 -05:00
|
|
|
float ofs = ((float) demod->getBandwidth()) / (float) srate;
|
2015-11-17 18:57:42 -05:00
|
|
|
float ofsLeft = (demod->getDemodulatorType()!="USB")?ofs:0, ofsRight = (demod->getDemodulatorType()!="LSB")?ofs:0;
|
2015-01-06 19:15:27 -05:00
|
|
|
|
|
|
|
float labelHeight = 20.0 / viewHeight;
|
|
|
|
float hPos = -1.0 + labelHeight;
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2016-02-11 01:09:15 -05:00
|
|
|
bool soloMode = wxGetApp().getSoloMode();
|
2017-10-12 00:07:05 -04:00
|
|
|
bool isRecording = demod->isRecording();
|
2016-02-11 01:09:15 -05:00
|
|
|
bool isSolo = soloMode && demod == wxGetApp().getDemodMgr().getLastActiveDemodulator();
|
|
|
|
|
2017-10-12 00:07:05 -04:00
|
|
|
RGBA4f labelBg(0, 0, 0, 0.35f);
|
|
|
|
|
2016-02-11 01:09:15 -05:00
|
|
|
if (isSolo) {
|
2017-10-12 00:07:05 -04:00
|
|
|
labelBg.r = labelBg.g = 0.8f;
|
2016-02-11 01:09:15 -05:00
|
|
|
} else if (demod->isMuted()) {
|
2017-10-12 00:07:05 -04:00
|
|
|
labelBg.r = 0.8f;
|
2016-02-11 01:09:15 -05:00
|
|
|
} else if (soloMode) {
|
2017-10-12 00:07:05 -04:00
|
|
|
labelBg.r = 0.2f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Better recording indicator... pulsating red circle?
|
|
|
|
if (isRecording) {
|
2017-12-29 22:46:39 -05:00
|
|
|
auto t = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
|
|
|
labelBg.g = sinf(2.0f * M_PI * (float(t) / 1000.0f)) * 0.25f + 0.75f;
|
2015-08-17 00:59:38 -04:00
|
|
|
}
|
2017-10-12 00:07:05 -04:00
|
|
|
|
|
|
|
glColor4f(labelBg.r, labelBg.g, labelBg.b, labelBg.a);
|
2015-08-17 00:59:38 -04:00
|
|
|
|
2015-01-06 19:15:27 -05:00
|
|
|
glBegin(GL_QUADS);
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f(uxPos - ofsLeft, hPos + labelHeight, 0.0);
|
|
|
|
glVertex3f(uxPos - ofsLeft, -1.0, 0.0);
|
2015-01-06 19:15:27 -05:00
|
|
|
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f(uxPos + ofsRight, -1.0, 0.0);
|
|
|
|
glVertex3f(uxPos + ofsRight, hPos + labelHeight, 0.0);
|
2015-01-06 19:15:27 -05:00
|
|
|
glEnd();
|
|
|
|
|
2015-01-20 22:26:34 -05:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
2015-01-06 19:15:27 -05:00
|
|
|
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(color.r, color.g, color.b, 0.2f);
|
2014-12-09 21:28:08 -05:00
|
|
|
glBegin(GL_QUADS);
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f(uxPos - ofsLeft, 1.0, 0.0);
|
|
|
|
glVertex3f(uxPos - ofsLeft, -1.0, 0.0);
|
2014-12-09 21:28:08 -05:00
|
|
|
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f(uxPos + ofsRight, -1.0, 0.0);
|
|
|
|
glVertex3f(uxPos + ofsRight, 1.0, 0.0);
|
2014-12-09 21:28:08 -05:00
|
|
|
glEnd();
|
|
|
|
|
2014-12-10 00:34:27 -05:00
|
|
|
if (ofs * 2.0 < 16.0 / viewWidth) {
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(color.r, color.g, color.b, 0.2f);
|
2014-12-10 00:34:27 -05:00
|
|
|
glBegin(GL_QUADS);
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f(uxPos - ofsLeft, hPos + labelHeight, 0.0);
|
|
|
|
glVertex3f(uxPos - ofsLeft, -1.0, 0.0);
|
2014-12-10 00:34:27 -05:00
|
|
|
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f(uxPos + ofsRight, -1.0, 0.0);
|
|
|
|
glVertex3f(uxPos + ofsRight, hPos + labelHeight, 0.0);
|
2014-12-10 00:34:27 -05:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2016-03-07 19:25:12 -05:00
|
|
|
if (centerline) {
|
|
|
|
glColor4f(color.r, color.g, color.b, 0.5);
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3f(uxPos, 1.0, 0.0);
|
|
|
|
glVertex3f(uxPos, -1.0, 0.0);
|
|
|
|
glEnd();
|
|
|
|
}
|
2015-02-16 02:15:04 -05:00
|
|
|
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(1.0, 1.0, 1.0, 0.8f);
|
2014-12-10 00:34:27 -05:00
|
|
|
|
2018-01-02 23:51:32 -05:00
|
|
|
std::string demodLabel, demodPrefix;
|
|
|
|
|
2016-02-15 17:43:10 -05:00
|
|
|
if (demod->isDeltaLock()) {
|
2018-01-02 23:51:32 -05:00
|
|
|
demodPrefix.append("V");
|
2016-02-15 17:43:10 -05:00
|
|
|
}
|
2017-10-12 00:07:05 -04:00
|
|
|
|
|
|
|
if (isRecording) {
|
2018-01-02 23:51:32 -05:00
|
|
|
demodPrefix.append("R");
|
2017-10-12 00:07:05 -04:00
|
|
|
}
|
|
|
|
|
2018-01-02 23:51:32 -05:00
|
|
|
if (demod->isMuted()) {
|
|
|
|
demodPrefix.append("M");
|
|
|
|
} else if (isSolo) {
|
|
|
|
demodPrefix.append("S");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the prefix
|
|
|
|
if (!demodPrefix.empty()) {
|
|
|
|
demodLabel = "[" + demodPrefix + "] ";
|
|
|
|
}
|
|
|
|
// Append the default label
|
|
|
|
demodLabel.append(demod->getLabel());
|
|
|
|
|
2015-11-17 18:57:42 -05:00
|
|
|
if (demod->getDemodulatorType() == "USB") {
|
2016-06-23 15:17:02 -04:00
|
|
|
GLFont::getFont(16, GLFont::getScaleFactor()).drawString(demodLabel, uxPos, hPos, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER, 0, 0, true);
|
2015-11-17 18:57:42 -05:00
|
|
|
} else if (demod->getDemodulatorType() == "LSB") {
|
2016-06-23 15:17:02 -04:00
|
|
|
GLFont::getFont(16, GLFont::getScaleFactor()).drawString(demodLabel, uxPos, hPos, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER, 0, 0, true);
|
2015-02-16 02:15:04 -05:00
|
|
|
} else {
|
2016-06-23 15:17:02 -04:00
|
|
|
GLFont::getFont(16, GLFont::getScaleFactor()).drawString(demodLabel, uxPos, hPos, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, 0, 0, true);
|
2015-02-16 02:15:04 -05:00
|
|
|
}
|
2014-12-10 00:34:27 -05:00
|
|
|
|
2014-12-09 21:28:08 -05:00
|
|
|
glDisable(GL_BLEND);
|
2014-12-10 00:34:27 -05:00
|
|
|
|
2014-12-09 21:28:08 -05:00
|
|
|
}
|
2014-12-08 21:08:03 -05:00
|
|
|
|
2016-03-07 19:25:12 -05:00
|
|
|
void PrimaryGLContext::DrawFreqBwInfo(long long freq, int bw, RGBA4f color, long long center_freq, long long srate, bool stack, bool centerline) {
|
2016-01-13 00:07:42 -05:00
|
|
|
if (!srate) {
|
|
|
|
srate = wxGetApp().getSampleRate();
|
|
|
|
}
|
|
|
|
|
|
|
|
GLint vp[4];
|
|
|
|
glGetIntegerv( GL_VIEWPORT, vp);
|
|
|
|
|
|
|
|
float viewHeight = (float) vp[3];
|
|
|
|
float viewWidth = (float) vp[2];
|
|
|
|
|
|
|
|
if (center_freq == -1) {
|
|
|
|
center_freq = wxGetApp().getFrequency();
|
|
|
|
}
|
|
|
|
|
|
|
|
float uxPos = (float) (freq - (center_freq - srate / 2)) / (float) srate;
|
|
|
|
uxPos = (uxPos - 0.5) * 2.0;
|
|
|
|
|
|
|
|
std::string lastType = wxGetApp().getDemodMgr().getLastDemodulatorType();
|
|
|
|
|
|
|
|
float ofs = (float) bw / (float) srate;
|
|
|
|
float ofsLeft = (lastType!="USB")?ofs:0, ofsRight = (lastType!="LSB")?ofs:0;
|
2016-01-13 21:29:26 -05:00
|
|
|
|
2016-01-13 00:07:42 -05:00
|
|
|
float labelHeight = 20.0 / viewHeight;
|
2016-01-13 21:29:26 -05:00
|
|
|
float hPos = -1.0 + (stack?(labelHeight*3.0):labelHeight);
|
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(0, 0, 0, 0.35f);
|
2016-01-13 00:07:42 -05:00
|
|
|
|
2016-01-13 21:29:26 -05:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glVertex3f(uxPos - ofsLeft, hPos + labelHeight, 0.0);
|
|
|
|
glVertex3f(uxPos - ofsLeft, -1.0, 0.0);
|
2016-01-13 00:07:42 -05:00
|
|
|
|
2016-01-13 21:29:26 -05:00
|
|
|
glVertex3f(uxPos + ofsRight, -1.0, 0.0);
|
|
|
|
glVertex3f(uxPos + ofsRight, hPos + labelHeight, 0.0);
|
|
|
|
glEnd();
|
|
|
|
|
2016-01-13 00:07:42 -05:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(color.r, color.g, color.b, 0.1f);
|
2016-01-13 00:07:42 -05:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glVertex3f(uxPos - ofsLeft, 1.0, 0.0);
|
|
|
|
glVertex3f(uxPos - ofsLeft, -1.0, 0.0);
|
|
|
|
|
|
|
|
glVertex3f(uxPos + ofsRight, -1.0, 0.0);
|
|
|
|
glVertex3f(uxPos + ofsRight, 1.0, 0.0);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
if (ofs * 2.0 < 16.0 / viewWidth) {
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(color.r, color.g, color.b, 0.1f);
|
2016-01-13 00:07:42 -05:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glVertex3f(uxPos - ofsLeft, hPos + labelHeight, 0.0);
|
|
|
|
glVertex3f(uxPos - ofsLeft, -1.0, 0.0);
|
|
|
|
|
|
|
|
glVertex3f(uxPos + ofsRight, -1.0, 0.0);
|
|
|
|
glVertex3f(uxPos + ofsRight, hPos + labelHeight, 0.0);
|
|
|
|
glEnd();
|
|
|
|
}
|
2016-03-07 19:25:12 -05:00
|
|
|
|
|
|
|
if (centerline) {
|
|
|
|
glColor4f(color.r, color.g, color.b, 0.5);
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3f(uxPos, 1.0, 0.0);
|
|
|
|
glVertex3f(uxPos, -1.0, 0.0);
|
|
|
|
glEnd();
|
|
|
|
}
|
2016-01-13 00:07:42 -05:00
|
|
|
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(1.0, 1.0, 1.0, 0.8f);
|
2016-01-13 00:07:42 -05:00
|
|
|
|
|
|
|
std::string demodLabel = std::to_string((double)freq/1000000.0);
|
|
|
|
|
2016-01-13 23:25:16 -05:00
|
|
|
double shadowOfsX = 4.0 / viewWidth, shadowOfsY = 2.0 / viewHeight;
|
2016-06-21 13:40:02 -04:00
|
|
|
|
2016-06-23 15:17:02 -04:00
|
|
|
GLFont::Drawer refDrawingFont = GLFont::getFont(16, GLFont::getScaleFactor());
|
2016-01-13 21:29:26 -05:00
|
|
|
|
2016-01-13 00:07:42 -05:00
|
|
|
if (lastType == "USB") {
|
2016-01-13 21:29:26 -05:00
|
|
|
glColor4f(0,0,0, 1.0);
|
2016-01-13 22:39:39 -05:00
|
|
|
glBlendFunc(GL_ONE, GL_ZERO);
|
2016-06-21 13:40:02 -04:00
|
|
|
refDrawingFont.drawString(demodLabel, uxPos+shadowOfsX, hPos+shadowOfsY, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER);
|
|
|
|
refDrawingFont.drawString(demodLabel, uxPos-shadowOfsX, hPos-shadowOfsY, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER);
|
2016-01-13 21:29:26 -05:00
|
|
|
glColor4f(color.r, color.g, color.b, 1.0);
|
2016-01-13 22:39:39 -05:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
2016-06-21 13:40:02 -04:00
|
|
|
refDrawingFont.drawString(demodLabel, uxPos, hPos, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER);
|
2016-01-13 00:07:42 -05:00
|
|
|
} else if (lastType == "LSB") {
|
2016-01-13 22:39:39 -05:00
|
|
|
glBlendFunc(GL_ONE, GL_ZERO);
|
2016-01-13 21:29:26 -05:00
|
|
|
glColor4f(0,0,0, 1.0);
|
2016-06-21 13:40:02 -04:00
|
|
|
refDrawingFont.drawString(demodLabel, uxPos+shadowOfsX, hPos+shadowOfsY, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
|
|
|
|
refDrawingFont.drawString(demodLabel, uxPos-shadowOfsX, hPos-shadowOfsY, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
|
2016-01-13 21:29:26 -05:00
|
|
|
glColor4f(color.r, color.g, color.b, 1.0);
|
2016-01-13 22:39:39 -05:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
2016-06-21 13:40:02 -04:00
|
|
|
refDrawingFont.drawString(demodLabel, uxPos, hPos, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
|
2016-01-13 00:07:42 -05:00
|
|
|
} else {
|
2016-01-13 22:39:39 -05:00
|
|
|
glBlendFunc(GL_ONE, GL_ZERO);
|
2016-01-13 21:29:26 -05:00
|
|
|
glColor4f(0,0,0, 1.0);
|
2016-01-13 22:39:39 -05:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
2016-06-21 13:40:02 -04:00
|
|
|
refDrawingFont.drawString(demodLabel, uxPos+shadowOfsX, hPos+shadowOfsY, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
|
|
|
refDrawingFont.drawString(demodLabel, uxPos-shadowOfsX, hPos-shadowOfsY, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
2016-01-13 21:29:26 -05:00
|
|
|
glColor4f(color.r, color.g, color.b, 1.0);
|
2016-06-21 13:40:02 -04:00
|
|
|
refDrawingFont.drawString(demodLabel, uxPos, hPos, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
2016-01-13 00:07:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2017-08-27 05:11:30 -04:00
|
|
|
void PrimaryGLContext::DrawDemod(DemodulatorInstancePtr demod, RGBA4f color, long long center_freq, long long srate) {
|
2014-12-08 21:08:03 -05:00
|
|
|
if (!demod) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-11 17:08:16 -05:00
|
|
|
if (!srate) {
|
|
|
|
srate = wxGetApp().getSampleRate();
|
|
|
|
}
|
2014-12-08 21:08:03 -05:00
|
|
|
|
2014-12-28 05:13:46 -05:00
|
|
|
if (center_freq == -1) {
|
|
|
|
center_freq = wxGetApp().getFrequency();
|
|
|
|
}
|
|
|
|
|
2016-02-17 20:45:56 -05:00
|
|
|
long long demodFreq = demod->getFrequency();
|
|
|
|
|
|
|
|
if (demod->isDeltaLock()) {
|
2016-02-17 23:01:42 -05:00
|
|
|
demodFreq = wxGetApp().getFrequency() + demod->getDeltaLockOfs();
|
2016-02-17 20:45:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
float uxPos = (float) (demodFreq - (center_freq - srate / 2)) / (float) srate;
|
2014-12-08 21:08:03 -05:00
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
2015-01-20 22:26:34 -05:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(color.r, color.g, color.b, 0.6f);
|
2014-12-08 21:08:03 -05:00
|
|
|
|
2015-02-16 02:15:04 -05:00
|
|
|
float ofs = ((float) demod->getBandwidth()) / (float) srate;
|
2015-11-17 18:57:42 -05:00
|
|
|
float ofsLeft = (demod->getDemodulatorType()!="USB")?ofs:0, ofsRight = (demod->getDemodulatorType()!="LSB")?ofs:0;
|
2014-12-08 21:08:03 -05:00
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0);
|
|
|
|
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 - ofsLeft, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 - ofsLeft, -1.0, 0.0);
|
2014-12-08 21:08:03 -05:00
|
|
|
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 + ofsRight, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 + ofsRight, -1.0, 0.0);
|
2014-12-08 21:08:03 -05:00
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
2015-01-20 22:26:34 -05:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
2015-03-06 21:11:14 -05:00
|
|
|
glColor4f(color.r, color.g, color.b, 0.2*hoverAlpha);
|
2014-12-08 21:08:03 -05:00
|
|
|
glBegin(GL_QUADS);
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 - ofsLeft, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 - ofsLeft, -1.0, 0.0);
|
2014-12-08 21:08:03 -05:00
|
|
|
|
2015-02-16 02:15:04 -05:00
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 + ofsRight, -1.0, 0.0);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 + ofsRight, 1.0, 0.0);
|
2014-12-08 21:08:03 -05:00
|
|
|
glEnd();
|
|
|
|
|
2015-01-03 18:45:34 -05:00
|
|
|
GLint vp[4];
|
|
|
|
glGetIntegerv( GL_VIEWPORT, vp);
|
|
|
|
|
|
|
|
float viewHeight = (float) vp[3];
|
|
|
|
float viewWidth = (float) vp[2];
|
|
|
|
|
|
|
|
float labelHeight = 20.0 / viewHeight;
|
|
|
|
float xOfs = (2.0 / viewWidth);
|
|
|
|
float yOfs = (2.0 / viewHeight);
|
|
|
|
float hPos = labelHeight;
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glDisable(GL_COLOR_MATERIAL);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
2016-06-14 13:41:19 -04:00
|
|
|
//Displayed string is wstring, so use wxString to do the heavy lifting of converting getDemodulatorType()...
|
|
|
|
wxString demodStr;
|
2017-04-05 13:28:18 -04:00
|
|
|
|
2016-06-14 13:41:19 -04:00
|
|
|
demodStr.assign(demod->getDemodulatorType());
|
2016-06-12 09:31:55 -04:00
|
|
|
|
2015-11-17 18:57:42 -05:00
|
|
|
if (demodStr == "LSB") {
|
2015-02-16 02:15:04 -05:00
|
|
|
uxPos -= xOfs;
|
2015-11-17 18:57:42 -05:00
|
|
|
} else if (demodStr == "USB") {
|
2015-02-16 02:15:04 -05:00
|
|
|
uxPos += xOfs;
|
2015-01-03 18:45:34 -05:00
|
|
|
}
|
2015-11-17 18:57:42 -05:00
|
|
|
// advanced demodulators start here
|
2015-01-03 18:45:34 -05:00
|
|
|
|
2015-11-23 20:03:47 -05:00
|
|
|
// if (demod->getDemodulatorCons() > 0) {
|
|
|
|
// demodStr = demodStr + std::to_string(demod->getDemodulatorCons());
|
|
|
|
// }
|
2015-06-05 03:51:46 -04:00
|
|
|
|
|
|
|
// add lock to string if we have an lock
|
|
|
|
if(demod->getDemodulatorLock()) {
|
2016-06-11 01:46:07 -04:00
|
|
|
demodStr += " Lock";
|
|
|
|
}
|
|
|
|
|
2015-06-10 04:50:14 -04:00
|
|
|
// else {
|
|
|
|
// demodStr = demodStr + " UnLock";
|
|
|
|
// }
|
2015-01-03 18:45:34 -05:00
|
|
|
|
2017-02-12 16:26:40 -05:00
|
|
|
//Shift the user label from the modem label more for the bigger
|
|
|
|
//font sizes so they do not step on each other...
|
2017-02-13 12:37:40 -05:00
|
|
|
double heightShift = GLFont::getScaleFactor();
|
2017-02-12 16:26:40 -05:00
|
|
|
|
2016-06-11 01:46:07 -04:00
|
|
|
//demodulator user label if present: type is displayed above the label, which is at the bottom of the screen.
|
|
|
|
if (!demod->getDemodulatorUserLabel().empty()) {
|
2017-02-13 12:37:40 -05:00
|
|
|
drawSingleDemodLabel(demodStr.ToStdWstring(), uxPos, hPos * 1.2 + hPos * 1.2 * heightShift, xOfs, yOfs, GLFont::GLFONT_ALIGN_CENTER);
|
|
|
|
drawSingleDemodLabel(demod->getDemodulatorUserLabel(), uxPos, hPos * 1.2, xOfs, yOfs, GLFont::GLFONT_ALIGN_CENTER);
|
2016-06-11 01:46:07 -04:00
|
|
|
}
|
2017-02-13 12:37:40 -05:00
|
|
|
else {
|
|
|
|
drawSingleDemodLabel(demodStr.ToStdWstring(), uxPos, hPos * 1.2, xOfs, yOfs, GLFont::GLFONT_ALIGN_CENTER);
|
2016-06-11 01:46:07 -04:00
|
|
|
}
|
2015-01-03 18:45:34 -05:00
|
|
|
|
2014-12-08 21:08:03 -05:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2016-06-14 13:41:19 -04:00
|
|
|
void PrimaryGLContext::drawSingleDemodLabel(const std::wstring& demodStr, float uxPos, float hPos, float xOfs, float yOfs, GLFont::Align demodAlign) {
|
2016-06-11 01:46:07 -04:00
|
|
|
|
2016-06-23 15:17:02 -04:00
|
|
|
GLFont::Drawer refDrawingFont = GLFont::getFont(16, GLFont::getScaleFactor());
|
2016-06-21 13:40:02 -04:00
|
|
|
|
2016-06-11 01:46:07 -04:00
|
|
|
glColor3f(0, 0, 0);
|
2017-02-13 12:37:40 -05:00
|
|
|
refDrawingFont.drawString(demodStr, 2.0 * (uxPos - 0.5) + xOfs, -1.0 + hPos - yOfs, demodAlign, GLFont::GLFONT_ALIGN_CENTER, 0, 0, true);
|
2016-06-14 13:41:19 -04:00
|
|
|
|
2016-06-11 01:46:07 -04:00
|
|
|
glColor3f(1, 1, 1);
|
2017-02-13 12:37:40 -05:00
|
|
|
refDrawingFont.drawString(demodStr, 2.0 * (uxPos - 0.5), -1.0 + hPos, demodAlign, GLFont::GLFONT_ALIGN_CENTER, 0, 0, true);
|
2016-06-11 01:46:07 -04:00
|
|
|
}
|
|
|
|
|
2016-01-26 19:20:14 -05:00
|
|
|
void PrimaryGLContext::DrawFreqSelector(float uxPos, RGBA4f color, float w, long long /* center_freq */, long long srate) {
|
2017-08-27 05:11:30 -04:00
|
|
|
|
|
|
|
DemodulatorInstancePtr demod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
|
2014-12-10 18:52:24 -05:00
|
|
|
|
2015-01-04 17:11:20 -05:00
|
|
|
long long bw = 0;
|
2014-12-08 21:08:03 -05:00
|
|
|
|
2015-11-17 18:57:42 -05:00
|
|
|
std::string last_type = wxGetApp().getDemodMgr().getLastDemodulatorType();
|
2015-02-16 20:47:58 -05:00
|
|
|
|
2014-12-08 21:08:03 -05:00
|
|
|
if (!demod) {
|
2015-02-02 20:10:55 -05:00
|
|
|
bw = wxGetApp().getDemodMgr().getLastBandwidth();
|
2014-12-10 18:52:24 -05:00
|
|
|
} else {
|
2015-01-04 13:20:31 -05:00
|
|
|
bw = demod->getBandwidth();
|
2014-12-08 21:08:03 -05:00
|
|
|
}
|
|
|
|
|
2015-01-11 17:08:16 -05:00
|
|
|
if (!srate) {
|
|
|
|
srate = wxGetApp().getSampleRate();
|
|
|
|
}
|
|
|
|
|
2014-12-08 21:08:03 -05:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
2015-01-20 22:26:34 -05:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(color.r, color.g, color.b, 0.6f);
|
2014-12-08 21:08:03 -05:00
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
2015-02-16 20:47:58 -05:00
|
|
|
|
2014-12-08 21:08:03 -05:00
|
|
|
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0);
|
|
|
|
|
2014-12-11 20:50:58 -05:00
|
|
|
float ofs;
|
|
|
|
|
|
|
|
if (w) {
|
|
|
|
ofs = w;
|
|
|
|
} else {
|
2014-12-28 05:13:46 -05:00
|
|
|
ofs = ((float) bw) / (float) srate;
|
2014-12-11 20:50:58 -05:00
|
|
|
}
|
2014-12-08 21:08:03 -05:00
|
|
|
|
2015-11-17 18:57:42 -05:00
|
|
|
if (last_type != "USB") {
|
2015-02-16 20:47:58 -05:00
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
|
|
|
|
}
|
2014-12-08 21:08:03 -05:00
|
|
|
|
2015-11-17 18:57:42 -05:00
|
|
|
if (last_type != "LSB") {
|
2015-02-16 20:47:58 -05:00
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
|
|
|
|
}
|
2014-12-08 21:08:03 -05:00
|
|
|
|
|
|
|
glEnd();
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
void PrimaryGLContext::DrawRangeSelector(float uxPos1, float uxPos2, RGBA4f color) {
|
2015-02-16 20:47:58 -05:00
|
|
|
if (uxPos2 < uxPos1) {
|
|
|
|
float temp = uxPos2;
|
|
|
|
uxPos2=uxPos1;
|
|
|
|
uxPos1=temp;
|
|
|
|
}
|
|
|
|
|
2015-11-17 18:57:42 -05:00
|
|
|
std::string last_type = wxGetApp().getDemodMgr().getLastDemodulatorType();
|
2015-02-16 20:47:58 -05:00
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
2016-06-01 19:42:34 -04:00
|
|
|
glColor4f(color.r, color.g, color.b, 0.6f);
|
2015-02-16 20:47:58 -05:00
|
|
|
|
2015-11-17 18:57:42 -05:00
|
|
|
glLineWidth((last_type == "USB")?2.0:1.0);
|
2015-02-16 20:47:58 -05:00
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3f((uxPos1 - 0.5) * 2.0, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos1 - 0.5) * 2.0, -1.0, 0.0);
|
|
|
|
glEnd();
|
|
|
|
|
2015-11-17 18:57:42 -05:00
|
|
|
glLineWidth((last_type == "LSB")?2.0:1.0);
|
2015-02-16 20:47:58 -05:00
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3f((uxPos2 - 0.5) * 2.0, 1.0, 0.0);
|
|
|
|
glVertex3f((uxPos2 - 0.5) * 2.0, -1.0, 0.0);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glLineWidth(1.0);
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2015-01-15 00:59:33 -05:00
|
|
|
void PrimaryGLContext::BeginDraw(float r, float g, float b) {
|
|
|
|
glClearColor(r,g,b, 1);
|
2014-12-08 21:08:03 -05:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrimaryGLContext::EndDraw() {
|
2016-03-31 20:24:38 -04:00
|
|
|
// glFlush();
|
2014-12-08 21:08:03 -05:00
|
|
|
|
2016-03-31 20:24:38 -04:00
|
|
|
// CheckGLError();
|
2014-12-08 21:08:03 -05:00
|
|
|
}
|
|
|
|
|
2015-03-06 21:11:14 -05:00
|
|
|
void PrimaryGLContext::setHoverAlpha(float hoverAlpha) {
|
|
|
|
this->hoverAlpha = hoverAlpha;
|
|
|
|
}
|