Cleanup: scope, meter, spectrum and waterfall panels

This commit is contained in:
Charles J. Cliffe 2021-04-04 22:17:30 -04:00
parent 9e22a1314c
commit 0b9bcc5a46
8 changed files with 95 additions and 98 deletions

View File

@ -5,7 +5,7 @@
#include "ColorTheme.h" #include "ColorTheme.h"
MeterPanel::MeterPanel(std::string name, float low, float high, float current) { MeterPanel::MeterPanel(const std::string& name, float low, float high, float current) {
this->name = name; this->name = name;
this->low = low; this->low = low;
this->high = high; this->high = high;
@ -35,7 +35,7 @@ MeterPanel::MeterPanel(std::string name, float low, float high, float current) {
highlightPanel.setBlend(GL_ONE, GL_ONE); highlightPanel.setBlend(GL_ONE, GL_ONE);
highlightPanel.visible = false; highlightPanel.visible = false;
c1 = RGBA4f(0.3f,0.3f,0.3f,1.0f); c1 = RGBA4f(0.3f,0.3f,0.3f,1.0f);
c2 = RGBA4f(0.65f,0.65f,0.65f,1.0f);; c2 = RGBA4f(0.65f,0.65f,0.65f,1.0f);
highlightPanel.setFillColor(c1, c2); highlightPanel.setFillColor(c1, c2);
bgPanel.addChild(&highlightPanel); bgPanel.addChild(&highlightPanel);
@ -58,9 +58,7 @@ MeterPanel::MeterPanel(std::string name, float low, float high, float current) {
addChild(&valuePanel); addChild(&valuePanel);
} }
MeterPanel::~MeterPanel() { MeterPanel::~MeterPanel() = default;
}
void MeterPanel::setName(std::string name_in) { void MeterPanel::setName(std::string name_in) {
@ -71,17 +69,17 @@ std::string MeterPanel::getName() {
return name; return name;
} }
void MeterPanel::setRange(float low, float high) { void MeterPanel::setRange(float low_in, float high_in) {
this->low = low; low = low_in;
this->high = high; high = high_in;
} }
float MeterPanel::getLow() { float MeterPanel::getLow() const {
return this->low; return low;
} }
float MeterPanel::getHigh() { float MeterPanel::getHigh() const {
return this->high; return high;
} }
void MeterPanel::setValue(float value) { void MeterPanel::setValue(float value) {
@ -112,7 +110,7 @@ void MeterPanel::setHighlightVisible(bool vis) {
highlightPanel.visible = vis; highlightPanel.visible = vis;
} }
float MeterPanel::getValue() { float MeterPanel::getValue() const {
return current; return current;
} }
@ -196,16 +194,16 @@ void MeterPanel::setValueLabel(std::string label) {
} }
void MeterPanel::setPanelLevel(float setValue, GLPanel &panel) { void MeterPanel::setPanelLevel(float setValue, GLPanel &panel) const {
float valueNorm = (setValue - low) / (high - low); float valueNorm = (setValue - low) / (high - low);
panel.setSize(1.0, valueNorm); panel.setSize(1.0, valueNorm);
panel.setPosition(0.0, (-1.0+(valueNorm))); panel.setPosition(0.0, (-1.0+(valueNorm)));
} }
bool MeterPanel::getChanged() { bool MeterPanel::getChanged() const {
return changed; return changed;
} }
void MeterPanel::setChanged(bool changed) { void MeterPanel::setChanged(bool changed_in) {
this->changed = changed; changed = changed_in;
} }

View File

@ -8,26 +8,26 @@
class MeterPanel : public GLPanel { class MeterPanel : public GLPanel {
public: public:
MeterPanel(std::string name, float low, float high, float current); MeterPanel(const std::string& name, float low, float high, float current);
~MeterPanel(); ~MeterPanel() override;
void setName(std::string name_in); void setName(std::string name_in);
std::string getName(); std::string getName();
void setRange(float low, float high); void setRange(float low_in, float high_in);
float getLow(); float getLow() const;
float getHigh(); float getHigh() const;
void setValue(float value); void setValue(float value);
void setHighlight(float value); void setHighlight(float value);
void setHighlightVisible(bool vis); void setHighlightVisible(bool vis);
float getValue(); float getValue() const;
bool isMeterHit(CubicVR::vec2 mousePoint); bool isMeterHit(CubicVR::vec2 mousePoint);
float getMeterHitValue(CubicVR::vec2 mousePoint); float getMeterHitValue(CubicVR::vec2 mousePoint);
void setChanged(bool changed); void setChanged(bool changed_in);
bool getChanged(); bool getChanged() const;
protected: protected:
void drawPanelContents(); void drawPanelContents() override;
void setValueLabel(std::string label); void setValueLabel(std::string label);
void setPanelLevel(float setValue, GLPanel &panel); void setPanelLevel(float setValue, GLPanel &panel) const;
private: private:
std::string name; std::string name;

View File

@ -15,16 +15,16 @@ ScopePanel::ScopePanel() : GLPanel(), scopeMode(SCOPE_MODE_Y) {
bgPanelStereo[1].setSize(1, 0.5); bgPanelStereo[1].setSize(1, 0.5);
} }
void ScopePanel::setMode(ScopeMode scopeMode) { void ScopePanel::setMode(ScopeMode scopeMode_in) {
this->scopeMode = scopeMode; scopeMode = scopeMode_in;
} }
ScopePanel::ScopeMode ScopePanel::getMode() { ScopePanel::ScopeMode ScopePanel::getMode() {
return this->scopeMode; return this->scopeMode;
} }
void ScopePanel::setPoints(std::vector<float> &points) { void ScopePanel::setPoints(std::vector<float> &points_in) {
this->points.assign(points.begin(),points.end()); points.assign(points_in.begin(), points_in.end());
} }
void ScopePanel::drawPanelContents() { void ScopePanel::drawPanelContents() {
@ -81,7 +81,7 @@ void ScopePanel::drawPanelContents() {
ThemeMgr::mgr.currentTheme->scopeLine.b * 0.15); ThemeMgr::mgr.currentTheme->scopeLine.b * 0.15);
} }
if (points.size()) { if (!points.empty()) {
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);

View File

@ -12,12 +12,12 @@ public:
ScopePanel(); ScopePanel();
void setMode(ScopeMode scopeMode); void setMode(ScopeMode scopeMode_in);
ScopeMode getMode(); ScopeMode getMode();
void setPoints(std::vector<float> &points); void setPoints(std::vector<float> &points_in);
protected: protected:
void drawPanelContents(); void drawPanelContents() override;
private: private:
std::vector<float> points; std::vector<float> points;

View File

@ -3,7 +3,6 @@
#include "SpectrumPanel.h" #include "SpectrumPanel.h"
#include <sstream>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include "CubicSDR.h" #include "CubicSDR.h"
@ -32,35 +31,35 @@ SpectrumPanel::SpectrumPanel() {
} }
float SpectrumPanel::getFloorValue() { float SpectrumPanel::getFloorValue() const {
return floorValue; return floorValue;
} }
void SpectrumPanel::setFloorValue(float floorValue) { void SpectrumPanel::setFloorValue(float floorValue_in) {
this->floorValue = floorValue; floorValue = floorValue_in;
} }
float SpectrumPanel::getCeilValue() { float SpectrumPanel::getCeilValue() const {
return ceilValue; return ceilValue;
} }
void SpectrumPanel::setCeilValue(float ceilValue) { void SpectrumPanel::setCeilValue(float ceilValue_in) {
this->ceilValue = ceilValue; ceilValue = ceilValue_in;
} }
void SpectrumPanel::setFreq(long long freq) { void SpectrumPanel::setFreq(long long freq_in) {
this->freq = freq; freq = freq_in;
} }
long long SpectrumPanel::getFreq() { long long SpectrumPanel::getFreq() const {
return freq; return freq;
} }
void SpectrumPanel::setBandwidth(long long bandwidth) { void SpectrumPanel::setBandwidth(long long bandwidth_in) {
this->bandwidth = bandwidth; bandwidth = bandwidth_in;
} }
long long SpectrumPanel::getBandwidth() { long long SpectrumPanel::getBandwidth() const {
return bandwidth; return bandwidth;
} }
@ -68,13 +67,13 @@ void SpectrumPanel::setFFTSize(int fftSize_in) {
this->fftSize = fftSize_in; this->fftSize = fftSize_in;
} }
int SpectrumPanel::getFFTSize() { int SpectrumPanel::getFFTSize() const {
return fftSize; return fftSize;
} }
void SpectrumPanel::setShowDb(bool showDb) { void SpectrumPanel::setShowDb(bool showDb_in) {
this->showDb = showDb; showDb = showDb_in;
if (showDb) { if (showDb_in) {
addChild(&dbPanelCeil); addChild(&dbPanelCeil);
addChild(&dbPanelFloor); addChild(&dbPanelFloor);
} else { } else {
@ -84,7 +83,7 @@ void SpectrumPanel::setShowDb(bool showDb) {
} }
bool SpectrumPanel::getShowDb() { bool SpectrumPanel::getShowDb() const {
return showDb; return showDb;
} }
@ -92,17 +91,17 @@ void SpectrumPanel::setUseDBOffset(bool useOfs) {
this->useDbOfs = useOfs; this->useDbOfs = useOfs;
} }
bool SpectrumPanel::getUseDBOffset() { bool SpectrumPanel::getUseDBOffset() const {
return useDbOfs; return useDbOfs;
} }
void SpectrumPanel::setPoints(std::vector<float> &points) { void SpectrumPanel::setPoints(std::vector<float> &points_in) {
this->points.assign(points.begin(), points.end()); points.assign(points_in.begin(), points_in.end());
} }
void SpectrumPanel::setPeakPoints(std::vector<float> &points) { void SpectrumPanel::setPeakPoints(std::vector<float> &points_in) {
this->peak_points.assign(points.begin(), points.end()); peak_points.assign(points_in.begin(), points_in.end());
} }
@ -115,17 +114,17 @@ void SpectrumPanel::drawPanelContents() {
glLoadMatrixf((transform * (CubicVR::mat4::translate(-1.0f, -0.75f, 0.0f) * CubicVR::mat4::scale(2.0f, 1.5f, 1.0f))).to_ptr()); glLoadMatrixf((transform * (CubicVR::mat4::translate(-1.0f, -0.75f, 0.0f) * CubicVR::mat4::scale(2.0f, 1.5f, 1.0f))).to_ptr());
if (points.size()) { if (!points.empty()) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
double range = ceilValue-floorValue; double range = ceilValue-floorValue;
double 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 } }; double 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 (auto & i : ranges) {
double p = 0; double p = 0;
double rangeMin = ranges[i][0]; double rangeMin = i[0];
double rangeMax = ranges[i][1]; double rangeMax = i[1];
double rangeTrans = ranges[i][2]; double rangeTrans = i[2];
double rangeStep = ranges[i][3]; double rangeStep = i[3];
if (range >= rangeMin && range <= rangeMax) { if (range >= rangeMin && range <= rangeMax) {
double a = 1.0; double a = 1.0;
@ -152,7 +151,7 @@ void SpectrumPanel::drawPanelContents() {
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);
if (peak_points.size()) { if (!peak_points.empty()) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0, 1.0, 0, 0.5); glColor4f(0, 1.0, 0, 0.5);
glVertexPointer(2, GL_FLOAT, 0, &peak_points[0]); glVertexPointer(2, GL_FLOAT, 0, &peak_points[0]);

View File

@ -9,32 +9,32 @@ class SpectrumPanel : public GLPanel {
public: public:
SpectrumPanel(); SpectrumPanel();
void setPoints(std::vector<float> &points); void setPoints(std::vector<float> &points_in);
void setPeakPoints(std::vector<float> &points); void setPeakPoints(std::vector<float> &points_in);
float getFloorValue(); float getFloorValue() const;
void setFloorValue(float floorValue); void setFloorValue(float floorValue_in);
float getCeilValue(); float getCeilValue() const;
void setCeilValue(float ceilValue); void setCeilValue(float ceilValue_in);
void setFreq(long long freq); void setFreq(long long freq_in);
long long getFreq(); long long getFreq() const;
void setBandwidth(long long bandwidth); void setBandwidth(long long bandwidth_in);
long long getBandwidth(); long long getBandwidth() const;
void setFFTSize(int fftSize_in); void setFFTSize(int fftSize_in);
int getFFTSize(); int getFFTSize() const;
void setShowDb(bool showDb); void setShowDb(bool showDb_in);
bool getShowDb(); bool getShowDb() const;
void setUseDBOffset(bool useOfs); void setUseDBOffset(bool useOfs);
bool getUseDBOffset(); bool getUseDBOffset() const;
protected: protected:
void drawPanelContents(); void drawPanelContents() override;
private: private:
float floorValue, ceilValue; float floorValue, ceilValue;

View File

@ -3,10 +3,10 @@
#include "WaterfallPanel.h" #include "WaterfallPanel.h"
WaterfallPanel::WaterfallPanel() : GLPanel(), fft_size(0), waterfall_lines(0), waterfall_slice(NULL), activeTheme(NULL) { WaterfallPanel::WaterfallPanel() : GLPanel(), fft_size(0), waterfall_lines(0), waterfall_slice(nullptr), activeTheme(nullptr) {
setFillColor(RGBA4f(0,0,0)); setFillColor(RGBA4f(0,0,0));
for (int i = 0; i < 2; i++) { for (unsigned int & i : waterfall) {
waterfall[i] = 0; i = 0;
} }
} }
@ -26,8 +26,8 @@ void WaterfallPanel::setup(unsigned int fft_size_in, int num_waterfall_lines_in)
void WaterfallPanel::refreshTheme() { void WaterfallPanel::refreshTheme() {
glEnable (GL_TEXTURE_2D); glEnable (GL_TEXTURE_2D);
for (int i = 0; i < 2; i++) { for (unsigned int i : waterfall) {
glBindTexture(GL_TEXTURE_2D, waterfall[i]); glBindTexture(GL_TEXTURE_2D, 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]);
@ -36,15 +36,15 @@ void WaterfallPanel::refreshTheme() {
} }
} }
void WaterfallPanel::setPoints(std::vector<float> &points) { void WaterfallPanel::setPoints(std::vector<float> &points_in) {
size_t halfPts = points.size()/2; size_t halfPts = points_in.size() / 2;
if (halfPts == fft_size) { if (halfPts == fft_size) {
for (unsigned int i = 0; i < fft_size; i++) { for (unsigned int i = 0; i < fft_size; i++) {
this->points[i] = points[i*2+1]; points[i] = points_in[i * 2 + 1];
} }
} else { } else {
this->points.assign(points.begin(), points.end()); points.assign(points_in.begin(), points_in.end());
} }
} }
@ -61,9 +61,9 @@ void WaterfallPanel::step() {
return; return;
} }
if (points.size() && points.size() == fft_size) { if (!points.empty() && points.size() == fft_size) {
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
for (int i = 0, iMax = half_fft_size; i < iMax; i++) { for (unsigned int i = 0, iMax = half_fft_size; i < iMax; i++) {
float v = points[j * half_fft_size + i]; float v = points[j * half_fft_size + i];
float wv = v < 0 ? 0 : (v > 0.99 ? 0.99 : v); float wv = v < 0 ? 0 : (v > 0.99 ? 0.99 : v);
@ -83,7 +83,7 @@ void WaterfallPanel::step() {
} }
void WaterfallPanel::update() { void WaterfallPanel::update() {
int half_fft_size = fft_size / 2; unsigned int half_fft_size = fft_size / 2;
if (!bufferInitialized.load()) { if (!bufferInitialized.load()) {
return; return;
@ -110,8 +110,8 @@ void WaterfallPanel::update() {
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 (unsigned int i : waterfall) {
glBindTexture(GL_TEXTURE_2D, waterfall[i]); glBindTexture(GL_TEXTURE_2D, i);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@ -136,7 +136,7 @@ void WaterfallPanel::update() {
} }
} }
int run_ofs = 0; unsigned int run_ofs = 0;
while (lines_buffered.load()) { while (lines_buffered.load()) {
int run_lines = lines_buffered.load(); int run_lines = lines_buffered.load();
if (run_lines > waterfall_ofs[0]) { if (run_lines > waterfall_ofs[0]) {
@ -163,7 +163,7 @@ void WaterfallPanel::drawPanelContents() {
return; return;
} }
int half_fft_size = fft_size / 2; unsigned int half_fft_size = fft_size / 2;
glLoadMatrixf(transform.to_ptr()); glLoadMatrixf(transform.to_ptr());

View File

@ -11,12 +11,12 @@ public:
WaterfallPanel(); WaterfallPanel();
void setup(unsigned int fft_size_in, int num_waterfall_lines_in); void setup(unsigned int fft_size_in, int num_waterfall_lines_in);
void refreshTheme(); void refreshTheme();
void setPoints(std::vector<float> &points); void setPoints(std::vector<float> &points_in);
void step(); void step();
void update(); void update();
protected: protected:
void drawPanelContents(); void drawPanelContents() override;
private: private:
std::vector<float> points; std::vector<float> points;