2020-04-30 21:12:01 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2016-2020 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
|
|
|
// //
|
|
|
|
// OpenGL interface modernization. //
|
|
|
|
// See: http://doc.qt.io/qt-5/qopenglshaderprogram.html //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-06-18 18:54:19 -04:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QToolTip>
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
#include "gui/glspectrumgui.h"
|
|
|
|
#include "dsp/fftwindow.h"
|
|
|
|
#include "dsp/spectrumvis.h"
|
|
|
|
#include "gui/glspectrum.h"
|
2020-05-01 05:06:56 -04:00
|
|
|
#include "gui/crightclickenabler.h"
|
|
|
|
#include "gui/wsspectrumsettingsdialog.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
#include "util/simpleserializer.h"
|
2021-02-10 02:34:42 -05:00
|
|
|
#include "util/db.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
#include "ui_glspectrumgui.h"
|
|
|
|
|
2021-02-11 18:53:18 -05:00
|
|
|
const int GLSpectrumGUI::m_fpsMs[] = {500, 200, 100, 50, 20, 10, 5, 0};
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
GLSpectrumGUI::GLSpectrumGUI(QWidget* parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::GLSpectrumGUI),
|
2020-03-12 10:31:20 -04:00
|
|
|
m_spectrumVis(nullptr),
|
|
|
|
m_glSpectrum(nullptr),
|
2020-04-30 21:12:01 -04:00
|
|
|
m_doApplySettings(true)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2018-08-15 04:30:12 -04:00
|
|
|
on_linscale_toggled(false);
|
2020-04-30 21:12:01 -04:00
|
|
|
|
2020-06-18 18:54:19 -04:00
|
|
|
QString levelStyle = QString(
|
|
|
|
"QSpinBox {background-color: rgb(79, 79, 79);}"
|
|
|
|
"QLineEdit {color: white; background-color: rgb(79, 79, 79); border: 1px solid gray; border-radius: 4px;}"
|
|
|
|
"QTooltip {color: white; background-color: balck;}"
|
|
|
|
);
|
|
|
|
ui->refLevel->setStyleSheet(levelStyle);
|
|
|
|
ui->levelRange->setStyleSheet(levelStyle);
|
2021-02-10 02:34:42 -05:00
|
|
|
ui->fftOverlap->setStyleSheet(levelStyle);
|
2020-06-18 18:54:19 -04:00
|
|
|
// ui->refLevel->findChild<QLineEdit*>()->setStyleSheet("color: white; background-color: rgb(79, 79, 79); border: 1px solid gray; border-radius: 4px; ");
|
|
|
|
// ui->refLevel->setStyleSheet("background-color: rgb(79, 79, 79);");
|
2020-04-30 21:12:01 -04:00
|
|
|
|
2020-06-18 18:54:19 -04:00
|
|
|
// ui->levelRange->findChild<QLineEdit*>()->setStyleSheet("color: white; background-color: rgb(79, 79, 79); border: 1px solid gray; border-radius: 4px;");
|
|
|
|
// ui->levelRange->setStyleSheet("background-color: rgb(79, 79, 79);");
|
2020-04-30 21:12:01 -04:00
|
|
|
|
2018-07-01 14:48:30 -04:00
|
|
|
connect(&m_messageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
|
2020-05-01 05:06:56 -04:00
|
|
|
|
|
|
|
CRightClickEnabler *wsSpectrumRightClickEnabler = new CRightClickEnabler(ui->wsSpectrum);
|
|
|
|
connect(wsSpectrumRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openWebsocketSpectrumSettingsDialog(const QPoint &)));
|
|
|
|
|
2020-04-30 21:12:01 -04:00
|
|
|
displaySettings();
|
2020-04-30 23:33:44 -04:00
|
|
|
setAveragingCombo();
|
2020-04-30 21:12:01 -04:00
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GLSpectrumGUI::~GLSpectrumGUI()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:50 -04:00
|
|
|
void GLSpectrumGUI::setBuddies(SpectrumVis* spectrumVis, GLSpectrum* glSpectrum)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
m_spectrumVis = spectrumVis;
|
|
|
|
m_glSpectrum = glSpectrum;
|
2021-02-15 07:49:51 -05:00
|
|
|
m_glSpectrum->setSpectrumVis(spectrumVis);
|
2018-07-01 14:48:30 -04:00
|
|
|
m_glSpectrum->setMessageQueueToGUI(&m_messageQueue);
|
2020-04-30 21:12:01 -04:00
|
|
|
m_spectrumVis->setMessageQueueToGUI(&m_messageQueue);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::resetToDefaults()
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.resetToDefaults();
|
|
|
|
displaySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray GLSpectrumGUI::serialize() const
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
return m_settings.serialize();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GLSpectrumGUI::deserialize(const QByteArray& data)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
if (m_settings.deserialize(data))
|
2019-08-10 19:27:19 -04:00
|
|
|
{
|
2020-08-29 05:10:11 -04:00
|
|
|
displaySettings(); // ends with blockApplySettings(false)
|
2020-04-30 21:12:01 -04:00
|
|
|
applySettings();
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-10 19:27:19 -04:00
|
|
|
else
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2020-04-30 21:12:01 -04:00
|
|
|
void GLSpectrumGUI::displaySettings()
|
|
|
|
{
|
|
|
|
blockApplySettings(true);
|
2020-06-18 18:54:19 -04:00
|
|
|
ui->refLevel->setValue(m_settings.m_refLevel);
|
|
|
|
ui->levelRange->setValue(m_settings.m_powerRange);
|
2020-04-30 21:12:01 -04:00
|
|
|
ui->decay->setSliderPosition(m_settings.m_decay);
|
|
|
|
ui->decayDivisor->setSliderPosition(m_settings.m_decayDivisor);
|
|
|
|
ui->stroke->setSliderPosition(m_settings.m_histogramStroke);
|
|
|
|
ui->waterfall->setChecked(m_settings.m_displayWaterfall);
|
|
|
|
ui->maxHold->setChecked(m_settings.m_displayMaxHold);
|
|
|
|
ui->current->setChecked(m_settings.m_displayCurrent);
|
|
|
|
ui->histogram->setChecked(m_settings.m_displayHistogram);
|
2020-11-10 10:38:12 -05:00
|
|
|
ui->invertWaterfall->setChecked(m_settings.m_invertedWaterfall);
|
2020-04-30 21:12:01 -04:00
|
|
|
ui->grid->setChecked(m_settings.m_displayGrid);
|
|
|
|
ui->gridIntensity->setSliderPosition(m_settings.m_displayGridIntensity);
|
|
|
|
|
|
|
|
ui->decay->setToolTip(QString("Decay: %1").arg(m_settings.m_decay));
|
|
|
|
ui->decayDivisor->setToolTip(QString("Decay divisor: %1").arg(m_settings.m_decayDivisor));
|
|
|
|
ui->stroke->setToolTip(QString("Stroke: %1").arg(m_settings.m_histogramStroke));
|
|
|
|
ui->gridIntensity->setToolTip(QString("Grid intensity: %1").arg(m_settings.m_displayGridIntensity));
|
|
|
|
ui->traceIntensity->setToolTip(QString("Trace intensity: %1").arg(m_settings.m_displayTraceIntensity));
|
2020-03-12 10:31:20 -04:00
|
|
|
|
|
|
|
ui->fftWindow->blockSignals(true);
|
|
|
|
ui->averaging->blockSignals(true);
|
|
|
|
ui->averagingMode->blockSignals(true);
|
|
|
|
ui->linscale->blockSignals(true);
|
|
|
|
|
2020-04-30 21:12:01 -04:00
|
|
|
ui->fftWindow->setCurrentIndex(m_settings.m_fftWindow);
|
2020-03-12 10:31:20 -04:00
|
|
|
|
2021-02-09 01:12:32 -05:00
|
|
|
for (int i = 0; i < 6; i++)
|
2020-03-12 10:31:20 -04:00
|
|
|
{
|
2021-02-09 01:12:32 -05:00
|
|
|
if (m_settings.m_fftSize == (1 << (i + 7)))
|
2020-03-12 10:31:20 -04:00
|
|
|
{
|
|
|
|
ui->fftSize->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-11 18:53:18 -05:00
|
|
|
if (m_settings.m_fpsPeriodMs == 0)
|
|
|
|
{
|
|
|
|
ui->fps->setCurrentIndex(sizeof(m_fpsMs)/sizeof(m_fpsMs[0]) - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
for (; i < sizeof(m_fpsMs)/sizeof(m_fpsMs[0]); i++)
|
|
|
|
{
|
|
|
|
if (m_settings.m_fpsPeriodMs >= m_fpsMs[i]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->fps->setCurrentIndex(i);
|
|
|
|
}
|
|
|
|
|
2021-02-09 01:12:32 -05:00
|
|
|
ui->fftOverlap->setValue(m_settings.m_fftOverlap);
|
|
|
|
setMaximumOverlap();
|
2020-04-30 21:12:01 -04:00
|
|
|
ui->averaging->setCurrentIndex(m_settings.m_averagingIndex);
|
|
|
|
ui->averagingMode->setCurrentIndex((int) m_settings.m_averagingMode);
|
|
|
|
ui->linscale->setChecked(m_settings.m_linear);
|
|
|
|
setAveragingToolitp();
|
2018-07-01 14:48:30 -04:00
|
|
|
|
2020-03-12 10:31:20 -04:00
|
|
|
ui->fftWindow->blockSignals(false);
|
|
|
|
ui->averaging->blockSignals(false);
|
|
|
|
ui->averagingMode->blockSignals(false);
|
|
|
|
ui->linscale->blockSignals(false);
|
2020-04-30 21:12:01 -04:00
|
|
|
blockApplySettings(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::blockApplySettings(bool block)
|
|
|
|
{
|
|
|
|
m_doApplySettings = !block;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::applySettings()
|
|
|
|
{
|
|
|
|
if (!m_doApplySettings) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-05 19:38:23 -04:00
|
|
|
if (m_glSpectrum) {
|
|
|
|
applyGLSpectrumSettings();
|
2020-04-30 21:12:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_spectrumVis)
|
|
|
|
{
|
2020-05-01 05:06:56 -04:00
|
|
|
SpectrumVis::MsgConfigureSpectrumVis *msg = SpectrumVis::MsgConfigureSpectrumVis::create(m_settings, false);
|
|
|
|
m_spectrumVis->getInputMessageQueue()->push(msg);
|
2020-04-30 21:12:01 -04:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2020-05-05 19:38:23 -04:00
|
|
|
void GLSpectrumGUI::applyGLSpectrumSettings()
|
|
|
|
{
|
|
|
|
m_glSpectrum->setDisplayWaterfall(m_settings.m_displayWaterfall);
|
|
|
|
m_glSpectrum->setInvertedWaterfall(m_settings.m_invertedWaterfall);
|
|
|
|
m_glSpectrum->setDisplayMaxHold(m_settings.m_displayMaxHold);
|
|
|
|
m_glSpectrum->setDisplayCurrent(m_settings.m_displayCurrent);
|
|
|
|
m_glSpectrum->setDisplayHistogram(m_settings.m_displayHistogram);
|
|
|
|
m_glSpectrum->setDecay(m_settings.m_decay);
|
|
|
|
m_glSpectrum->setDecayDivisor(m_settings.m_decayDivisor);
|
|
|
|
m_glSpectrum->setHistoStroke(m_settings.m_histogramStroke);
|
|
|
|
m_glSpectrum->setDisplayGrid(m_settings.m_displayGrid);
|
|
|
|
m_glSpectrum->setDisplayGridIntensity(m_settings.m_displayGridIntensity);
|
|
|
|
m_glSpectrum->setDisplayTraceIntensity(m_settings.m_displayTraceIntensity);
|
2020-11-15 15:56:45 -05:00
|
|
|
m_glSpectrum->setWaterfallShare(m_settings.m_waterfallShare);
|
2020-05-05 19:38:23 -04:00
|
|
|
|
|
|
|
if ((m_settings.m_averagingMode == GLSpectrumSettings::AvgModeFixed) || (m_settings.m_averagingMode == GLSpectrumSettings::AvgModeMax)) {
|
|
|
|
m_glSpectrum->setTimingRate(getAveragingValue(m_settings.m_averagingIndex, m_settings.m_averagingMode) == 0 ?
|
|
|
|
1 :
|
|
|
|
getAveragingValue(m_settings.m_averagingIndex, m_settings.m_averagingMode));
|
|
|
|
} else {
|
|
|
|
m_glSpectrum->setTimingRate(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Real refLevel = m_settings.m_linear ? pow(10.0, m_settings.m_refLevel/10.0) : m_settings.m_refLevel;
|
|
|
|
Real powerRange = m_settings.m_linear ? pow(10.0, m_settings.m_refLevel/10.0) : m_settings.m_powerRange;
|
|
|
|
qDebug("GLSpectrumGUI::applySettings: refLevel: %e powerRange: %e", refLevel, powerRange);
|
|
|
|
m_glSpectrum->setReferenceLevel(refLevel);
|
|
|
|
m_glSpectrum->setPowerRange(powerRange);
|
2021-02-11 18:53:18 -05:00
|
|
|
m_glSpectrum->setFPSPeriodMs(m_settings.m_fpsPeriodMs);
|
2020-05-05 19:38:23 -04:00
|
|
|
m_glSpectrum->setLinear(m_settings.m_linear);
|
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
void GLSpectrumGUI::on_fftWindow_currentIndexChanged(int index)
|
|
|
|
{
|
2020-03-12 10:31:20 -04:00
|
|
|
qDebug("GLSpectrumGUI::on_fftWindow_currentIndexChanged: %d", index);
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_fftWindow = (FFTWindow::Function) index;
|
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::on_fftSize_currentIndexChanged(int index)
|
|
|
|
{
|
2020-03-12 10:31:20 -04:00
|
|
|
qDebug("GLSpectrumGUI::on_fftSize_currentIndexChanged: %d", index);
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_fftSize = 1 << (7 + index);
|
2021-02-09 01:12:32 -05:00
|
|
|
setMaximumOverlap();
|
2020-04-30 21:12:01 -04:00
|
|
|
applySettings();
|
2018-07-01 14:48:30 -04:00
|
|
|
setAveragingToolitp();
|
2018-06-30 16:30:42 -04:00
|
|
|
}
|
|
|
|
|
2021-02-09 01:12:32 -05:00
|
|
|
void GLSpectrumGUI::on_fftOverlap_valueChanged(int value)
|
|
|
|
{
|
|
|
|
qDebug("GLSpectrumGUI::on_fftOverlap_valueChanged: %d", value);
|
|
|
|
m_settings.m_fftOverlap = value;
|
|
|
|
setMaximumOverlap();
|
|
|
|
applySettings();
|
2021-02-09 01:39:03 -05:00
|
|
|
setAveragingToolitp();
|
2021-02-09 01:12:32 -05:00
|
|
|
}
|
|
|
|
|
2021-02-10 02:34:42 -05:00
|
|
|
void GLSpectrumGUI::on_autoscale_clicked(bool checked)
|
|
|
|
{
|
|
|
|
(void) checked;
|
|
|
|
|
|
|
|
if (!m_spectrumVis) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Real> psd;
|
|
|
|
m_spectrumVis->getPSDCopy(psd);
|
|
|
|
int avgRange = m_settings.m_fftSize / 32;
|
|
|
|
|
|
|
|
if (psd.size() < (unsigned int) avgRange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(psd.begin(), psd.end());
|
2021-02-10 23:13:13 -05:00
|
|
|
float max = psd[psd.size() - 1];
|
|
|
|
float minSum = 0.0f;
|
2021-02-10 02:34:42 -05:00
|
|
|
|
2021-02-10 23:13:13 -05:00
|
|
|
for (int i = 0; i < avgRange; i++) {
|
2021-02-10 02:34:42 -05:00
|
|
|
minSum += psd[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
float minAvg = minSum / avgRange;
|
|
|
|
int minLvl = CalcDb::dbPower(minAvg*2);
|
2021-02-10 23:13:13 -05:00
|
|
|
int maxLvl = CalcDb::dbPower(max*10);
|
2021-02-10 02:34:42 -05:00
|
|
|
|
|
|
|
m_settings.m_refLevel = maxLvl;
|
|
|
|
m_settings.m_powerRange = maxLvl - minLvl;
|
|
|
|
ui->refLevel->setValue(m_settings.m_refLevel);
|
|
|
|
ui->levelRange->setValue(m_settings.m_powerRange);
|
|
|
|
// qDebug("GLSpectrumGUI::on_autoscale_clicked: max: %d min %d max: %e min: %e",
|
|
|
|
// maxLvl, minLvl, maxAvg, minAvg);
|
|
|
|
|
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
|
2018-06-30 20:16:59 -04:00
|
|
|
void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index)
|
2018-06-30 16:30:42 -04:00
|
|
|
{
|
2020-03-12 10:31:20 -04:00
|
|
|
qDebug("GLSpectrumGUI::on_averagingMode_currentIndexChanged: %d", index);
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_averagingMode = index < 0 ?
|
|
|
|
GLSpectrumSettings::AvgModeNone :
|
|
|
|
index > 3 ?
|
|
|
|
GLSpectrumSettings::AvgModeMax :
|
|
|
|
(GLSpectrumSettings::AveragingMode) index;
|
2018-06-30 21:11:36 -04:00
|
|
|
|
2020-04-30 23:33:44 -04:00
|
|
|
setAveragingCombo();
|
2020-04-30 21:12:01 -04:00
|
|
|
applySettings();
|
2021-02-13 04:01:55 -05:00
|
|
|
setAveragingToolitp();
|
2018-06-30 16:30:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::on_averaging_currentIndexChanged(int index)
|
|
|
|
{
|
2020-03-12 10:31:20 -04:00
|
|
|
qDebug("GLSpectrumGUI::on_averaging_currentIndexChanged: %d", index);
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_averagingIndex = index;
|
|
|
|
applySettings();
|
2018-07-01 14:48:30 -04:00
|
|
|
setAveragingToolitp();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2018-07-04 17:11:28 -04:00
|
|
|
void GLSpectrumGUI::on_linscale_toggled(bool checked)
|
|
|
|
{
|
2020-03-12 10:31:20 -04:00
|
|
|
qDebug("GLSpectrumGUI::on_averaging_currentIndexChanged: %s", checked ? "lin" : "log");
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_linear = checked;
|
|
|
|
applySettings();
|
2018-07-04 17:11:28 -04:00
|
|
|
}
|
|
|
|
|
2020-05-01 18:35:47 -04:00
|
|
|
void GLSpectrumGUI::on_wsSpectrum_toggled(bool checked)
|
|
|
|
{
|
|
|
|
if (m_spectrumVis)
|
|
|
|
{
|
|
|
|
SpectrumVis::MsgConfigureWSpectrumOpenClose *msg = SpectrumVis::MsgConfigureWSpectrumOpenClose::create(checked);
|
|
|
|
m_spectrumVis->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:54:19 -04:00
|
|
|
void GLSpectrumGUI::on_refLevel_valueChanged(int value)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2020-06-18 18:54:19 -04:00
|
|
|
m_settings.m_refLevel = value;
|
2020-04-30 21:12:01 -04:00
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2020-06-18 18:54:19 -04:00
|
|
|
void GLSpectrumGUI::on_levelRange_valueChanged(int value)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2020-06-18 18:54:19 -04:00
|
|
|
m_settings.m_powerRange = value;
|
2020-04-30 21:12:01 -04:00
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2021-02-11 18:53:18 -05:00
|
|
|
void GLSpectrumGUI::on_fps_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
m_settings.m_fpsPeriodMs = m_fpsMs[index];
|
|
|
|
qDebug("GLSpectrumGUI::on_fps_currentIndexChanged: %d ms", m_settings.m_fpsPeriodMs);
|
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
|
2015-07-15 02:48:02 -04:00
|
|
|
void GLSpectrumGUI::on_decay_valueChanged(int index)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_decay = index;
|
|
|
|
ui->decay->setToolTip(QString("Decay: %1").arg(m_settings.m_decay));
|
|
|
|
applySettings();
|
2015-07-15 02:48:02 -04:00
|
|
|
}
|
|
|
|
|
2018-10-18 18:40:14 -04:00
|
|
|
void GLSpectrumGUI::on_decayDivisor_valueChanged(int index)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_decayDivisor = index;
|
|
|
|
ui->decayDivisor->setToolTip(QString("Decay divisor: %1").arg(m_settings.m_decayDivisor));
|
|
|
|
applySettings();
|
2015-07-15 02:48:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::on_stroke_valueChanged(int index)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_histogramStroke = index;
|
|
|
|
ui->stroke->setToolTip(QString("Stroke: %1").arg(m_settings.m_histogramStroke));
|
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::on_waterfall_toggled(bool checked)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_displayWaterfall = checked;
|
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::on_histogram_toggled(bool checked)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_displayHistogram = checked;
|
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::on_maxHold_toggled(bool checked)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_displayMaxHold = checked;
|
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-07-15 22:55:14 -04:00
|
|
|
void GLSpectrumGUI::on_current_toggled(bool checked)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_displayCurrent = checked;
|
|
|
|
applySettings();
|
2015-07-15 22:55:14 -04:00
|
|
|
}
|
|
|
|
|
2020-11-10 10:38:12 -05:00
|
|
|
void GLSpectrumGUI::on_invertWaterfall_toggled(bool checked)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2020-11-10 10:38:12 -05:00
|
|
|
m_settings.m_invertedWaterfall = checked;
|
2020-04-30 21:12:01 -04:00
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::on_grid_toggled(bool checked)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_displayGrid = checked;
|
|
|
|
applySettings();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
2015-05-12 09:49:03 -04:00
|
|
|
|
|
|
|
void GLSpectrumGUI::on_gridIntensity_valueChanged(int index)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_displayGridIntensity = index;
|
|
|
|
ui->gridIntensity->setToolTip(QString("Grid intensity: %1").arg(m_settings.m_displayGridIntensity));
|
|
|
|
applySettings();
|
2015-05-12 09:49:03 -04:00
|
|
|
}
|
2015-07-18 11:53:57 -04:00
|
|
|
|
|
|
|
void GLSpectrumGUI::on_traceIntensity_valueChanged(int index)
|
|
|
|
{
|
2020-04-30 21:12:01 -04:00
|
|
|
m_settings.m_displayTraceIntensity = index;
|
|
|
|
ui->traceIntensity->setToolTip(QString("Trace intensity: %1").arg(m_settings.m_displayTraceIntensity));
|
|
|
|
applySettings();
|
2015-07-18 11:53:57 -04:00
|
|
|
}
|
2015-07-23 19:09:03 -04:00
|
|
|
|
2018-11-12 12:36:27 -05:00
|
|
|
void GLSpectrumGUI::on_clearSpectrum_clicked(bool checked)
|
2015-07-23 19:09:03 -04:00
|
|
|
{
|
2018-11-12 12:36:27 -05:00
|
|
|
(void) checked;
|
2020-03-12 10:31:20 -04:00
|
|
|
|
|
|
|
if (m_glSpectrum) {
|
2018-06-30 16:30:42 -04:00
|
|
|
m_glSpectrum->clearSpectrumHistogram();
|
|
|
|
}
|
2015-07-23 19:09:03 -04:00
|
|
|
}
|
2018-06-30 16:30:42 -04:00
|
|
|
|
2020-07-05 04:03:41 -04:00
|
|
|
void GLSpectrumGUI::on_freeze_toggled(bool checked)
|
|
|
|
{
|
|
|
|
SpectrumVis::MsgStartStop *msg = SpectrumVis::MsgStartStop::create(!checked);
|
|
|
|
m_spectrumVis->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
2020-04-30 23:33:44 -04:00
|
|
|
int GLSpectrumGUI::getAveragingMaxScale(GLSpectrumSettings::AveragingMode averagingMode)
|
|
|
|
{
|
|
|
|
if (averagingMode == GLSpectrumSettings::AvgModeMoving) {
|
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GLSpectrumGUI::getAveragingIndex(int averagingValue, GLSpectrumSettings::AveragingMode averagingMode)
|
2018-06-30 16:30:42 -04:00
|
|
|
{
|
2018-10-13 19:16:39 -04:00
|
|
|
if (averagingValue <= 1) {
|
2018-06-30 16:30:42 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int v = averagingValue;
|
|
|
|
int j = 0;
|
|
|
|
|
2020-04-30 23:33:44 -04:00
|
|
|
for (int i = 0; i <= getAveragingMaxScale(averagingMode); i++)
|
2018-06-30 16:30:42 -04:00
|
|
|
{
|
|
|
|
if (v < 20)
|
|
|
|
{
|
|
|
|
if (v < 2) {
|
|
|
|
j = 0;
|
|
|
|
} else if (v < 5) {
|
|
|
|
j = 1;
|
|
|
|
} else if (v < 10) {
|
|
|
|
j = 2;
|
|
|
|
} else {
|
|
|
|
j = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 3*i + j;
|
|
|
|
}
|
|
|
|
|
|
|
|
v /= 10;
|
|
|
|
}
|
|
|
|
|
2020-04-30 23:33:44 -04:00
|
|
|
return 3 * getAveragingMaxScale(averagingMode) + 3;
|
2018-06-30 16:30:42 -04:00
|
|
|
}
|
|
|
|
|
2020-04-30 23:33:44 -04:00
|
|
|
int GLSpectrumGUI::getAveragingValue(int averagingIndex, GLSpectrumSettings::AveragingMode averagingMode)
|
2018-06-30 16:30:42 -04:00
|
|
|
{
|
|
|
|
if (averagingIndex <= 0) {
|
2018-10-13 19:16:39 -04:00
|
|
|
return 1;
|
2018-06-30 16:30:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int v = averagingIndex - 1;
|
2020-04-30 23:33:44 -04:00
|
|
|
int m = pow(10.0, v/3 > getAveragingMaxScale(averagingMode) ? getAveragingMaxScale(averagingMode) : v/3);
|
2018-11-18 05:06:41 -05:00
|
|
|
int x = 1;
|
2018-06-30 16:30:42 -04:00
|
|
|
|
|
|
|
if (v % 3 == 0) {
|
|
|
|
x = 2;
|
|
|
|
} else if (v % 3 == 1) {
|
|
|
|
x = 5;
|
|
|
|
} else if (v % 3 == 2) {
|
|
|
|
x = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return x * m;
|
|
|
|
}
|
|
|
|
|
2018-06-30 18:55:30 -04:00
|
|
|
void GLSpectrumGUI::setAveragingCombo()
|
|
|
|
{
|
2018-10-16 17:56:09 -04:00
|
|
|
int index = ui->averaging->currentIndex();
|
2020-03-12 10:31:20 -04:00
|
|
|
ui->averaging->blockSignals(true);
|
2018-06-30 18:55:30 -04:00
|
|
|
ui->averaging->clear();
|
2018-10-13 19:16:39 -04:00
|
|
|
ui->averaging->addItem(QString("1"));
|
2018-06-30 18:55:30 -04:00
|
|
|
|
2020-04-30 23:33:44 -04:00
|
|
|
for (int i = 0; i <= getAveragingMaxScale(m_settings.m_averagingMode); i++)
|
2018-06-30 18:55:30 -04:00
|
|
|
{
|
|
|
|
QString s;
|
|
|
|
int m = pow(10.0, i);
|
|
|
|
int x = 2*m;
|
|
|
|
setNumberStr(x, s);
|
|
|
|
ui->averaging->addItem(s);
|
|
|
|
x = 5*m;
|
|
|
|
setNumberStr(x, s);
|
|
|
|
ui->averaging->addItem(s);
|
|
|
|
x = 10*m;
|
|
|
|
setNumberStr(x, s);
|
|
|
|
ui->averaging->addItem(s);
|
|
|
|
}
|
2018-10-16 17:56:09 -04:00
|
|
|
|
|
|
|
ui->averaging->setCurrentIndex(index >= ui->averaging->count() ? ui->averaging->count() - 1 : index);
|
2020-03-12 10:31:20 -04:00
|
|
|
ui->averaging->blockSignals(false);
|
2018-06-30 18:55:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::setNumberStr(int n, QString& s)
|
|
|
|
{
|
|
|
|
if (n < 1000) {
|
|
|
|
s = tr("%1").arg(n);
|
2018-10-13 19:16:39 -04:00
|
|
|
} else if (n < 100000) {
|
2018-06-30 18:55:30 -04:00
|
|
|
s = tr("%1k").arg(n/1000);
|
2018-10-13 19:16:39 -04:00
|
|
|
} else if (n < 1000000) {
|
|
|
|
s = tr("%1e5").arg(n/100000);
|
2018-06-30 18:55:30 -04:00
|
|
|
} else if (n < 1000000000) {
|
|
|
|
s = tr("%1M").arg(n/1000000);
|
|
|
|
} else {
|
|
|
|
s = tr("%1G").arg(n/1000000000);
|
|
|
|
}
|
|
|
|
}
|
2018-07-01 14:48:30 -04:00
|
|
|
|
|
|
|
void GLSpectrumGUI::setNumberStr(float v, int decimalPlaces, QString& s)
|
|
|
|
{
|
|
|
|
if (v < 1e-6) {
|
|
|
|
s = tr("%1n").arg(v*1e9, 0, 'f', decimalPlaces);
|
|
|
|
} else if (v < 1e-3) {
|
|
|
|
s = tr("%1µ").arg(v*1e6, 0, 'f', decimalPlaces);
|
|
|
|
} else if (v < 1.0) {
|
|
|
|
s = tr("%1m").arg(v*1e3, 0, 'f', decimalPlaces);
|
|
|
|
} else if (v < 1e3) {
|
|
|
|
s = tr("%1").arg(v, 0, 'f', decimalPlaces);
|
|
|
|
} else if (v < 1e6) {
|
|
|
|
s = tr("%1k").arg(v*1e-3, 0, 'f', decimalPlaces);
|
|
|
|
} else if (v < 1e9) {
|
|
|
|
s = tr("%1M").arg(v*1e-6, 0, 'f', decimalPlaces);
|
|
|
|
} else {
|
|
|
|
s = tr("%1G").arg(v*1e-9, 0, 'f', decimalPlaces);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::setAveragingToolitp()
|
|
|
|
{
|
|
|
|
if (m_glSpectrum)
|
|
|
|
{
|
|
|
|
QString s;
|
2021-02-13 04:01:55 -05:00
|
|
|
int averagingIndex = m_settings.m_averagingMode == GLSpectrumSettings::AvgModeNone ? 0 : m_settings.m_averagingIndex;
|
2021-02-09 01:39:03 -05:00
|
|
|
float halfSize = m_settings.m_fftSize / 2;
|
|
|
|
float overlapFactor = (halfSize - m_settings.m_fftOverlap) / halfSize;
|
2021-02-13 04:01:55 -05:00
|
|
|
float averagingTime = (m_settings.m_fftSize * (getAveragingValue(averagingIndex, m_settings.m_averagingMode) == 0 ?
|
2020-04-30 21:12:01 -04:00
|
|
|
1 :
|
2021-02-13 04:01:55 -05:00
|
|
|
getAveragingValue(averagingIndex, m_settings.m_averagingMode))) / (float) m_glSpectrum->getSampleRate();
|
2021-02-09 01:39:03 -05:00
|
|
|
setNumberStr(averagingTime*overlapFactor, 2, s);
|
2018-07-01 14:48:30 -04:00
|
|
|
ui->averaging->setToolTip(QString("Number of averaging samples (avg time: %1s)").arg(s));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->averaging->setToolTip(QString("Number of averaging samples"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-09 11:14:17 -05:00
|
|
|
void GLSpectrumGUI::setFFTSize(int log2FFTSize)
|
|
|
|
{
|
|
|
|
ui->fftSize->setCurrentIndex(log2FFTSize < 7 ? 0 : log2FFTSize > 12 ? 5 : log2FFTSize - 7); // 128 to 4096 in powers of 2
|
|
|
|
}
|
|
|
|
|
2021-02-09 01:12:32 -05:00
|
|
|
void GLSpectrumGUI::setMaximumOverlap()
|
|
|
|
{
|
2021-02-10 02:34:42 -05:00
|
|
|
int halfSize = m_settings.m_fftSize/2;
|
|
|
|
ui->fftOverlap->setMaximum((halfSize)-1);
|
2021-02-09 01:12:32 -05:00
|
|
|
int value = ui->fftOverlap->value();
|
2021-02-10 02:34:42 -05:00
|
|
|
ui->fftOverlap->setValue(value);
|
|
|
|
ui->fftOverlap->setToolTip(tr("FFT overlap %1 %").arg((value/(float)halfSize)*100.0f));
|
2021-02-09 02:08:59 -05:00
|
|
|
|
|
|
|
if (m_glSpectrum) {
|
|
|
|
m_glSpectrum->setFFTOverlap(value);
|
|
|
|
}
|
2021-02-09 01:12:32 -05:00
|
|
|
}
|
|
|
|
|
2018-07-01 14:48:30 -04:00
|
|
|
bool GLSpectrumGUI::handleMessage(const Message& message)
|
|
|
|
{
|
|
|
|
if (GLSpectrum::MsgReportSampleRate::match(message))
|
|
|
|
{
|
|
|
|
setAveragingToolitp();
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-05 19:38:23 -04:00
|
|
|
else if (SpectrumVis::MsgConfigureSpectrumVis::match(message))
|
2020-08-29 05:10:11 -04:00
|
|
|
{
|
2020-05-05 19:38:23 -04:00
|
|
|
SpectrumVis::MsgConfigureSpectrumVis& cfg = (SpectrumVis::MsgConfigureSpectrumVis&) message;
|
|
|
|
m_settings = cfg.getSettings();
|
|
|
|
displaySettings();
|
|
|
|
|
|
|
|
if (m_glSpectrum) {
|
|
|
|
applyGLSpectrumSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2020-08-29 05:10:11 -04:00
|
|
|
}
|
2020-05-05 19:38:23 -04:00
|
|
|
else if (SpectrumVis::MsgConfigureWSpectrumOpenClose::match(message))
|
2020-07-09 18:08:42 -04:00
|
|
|
{
|
2020-05-05 19:38:23 -04:00
|
|
|
SpectrumVis::MsgConfigureWSpectrumOpenClose& notif = (SpectrumVis::MsgConfigureWSpectrumOpenClose&) message;
|
|
|
|
ui->wsSpectrum->blockSignals(true);
|
|
|
|
ui->wsSpectrum->doToggle(notif.getOpenClose());
|
|
|
|
ui->wsSpectrum->blockSignals(false);
|
2020-07-09 18:08:42 -04:00
|
|
|
return true;
|
|
|
|
}
|
2020-11-15 15:56:45 -05:00
|
|
|
else if (GLSpectrum::MsgReportWaterfallShare::match(message))
|
|
|
|
{
|
|
|
|
const GLSpectrum::MsgReportWaterfallShare& report = (const GLSpectrum::MsgReportWaterfallShare&) message;
|
|
|
|
m_settings.m_waterfallShare = report.getWaterfallShare();
|
|
|
|
}
|
|
|
|
else if (SpectrumVis::MsgStartStop::match(message))
|
|
|
|
{
|
|
|
|
const SpectrumVis::MsgStartStop& msg = (SpectrumVis::MsgStartStop&) message;
|
|
|
|
ui->freeze->blockSignals(true);
|
|
|
|
ui->freeze->doToggle(!msg.getStartStop()); // this is a freeze so stop is true
|
|
|
|
ui->freeze->blockSignals(false);
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-01 14:48:30 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLSpectrumGUI::handleInputMessages()
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = m_messageQueue.pop()) != 0)
|
|
|
|
{
|
|
|
|
qDebug("GLSpectrumGUI::handleInputMessages: message: %s", message->getIdentifier());
|
|
|
|
|
|
|
|
if (handleMessage(*message))
|
|
|
|
{
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-01 05:06:56 -04:00
|
|
|
|
|
|
|
void GLSpectrumGUI::openWebsocketSpectrumSettingsDialog(const QPoint& p)
|
|
|
|
{
|
|
|
|
WebsocketSpectrumSettingsDialog dialog(this);
|
|
|
|
dialog.setAddress(m_settings.m_wsSpectrumAddress);
|
|
|
|
dialog.setPort(m_settings.m_wsSpectrumPort);
|
|
|
|
|
|
|
|
dialog.move(p);
|
|
|
|
dialog.exec();
|
|
|
|
|
|
|
|
if (dialog.hasChanged())
|
|
|
|
{
|
|
|
|
m_settings.m_wsSpectrumAddress = dialog.getAddress();
|
|
|
|
m_settings.m_wsSpectrumPort = dialog.getPort();
|
|
|
|
|
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
}
|