From c753089ac7b56f5af67f23e758555e213d636aad Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 15:10:07 -0700 Subject: [PATCH 01/11] Added spectrum plasma metering. --- wfmain.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- wfmain.h | 5 +++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/wfmain.cpp b/wfmain.cpp index d2f5b4c..c0ec779 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -2035,6 +2035,15 @@ void wfmain::prepareWf(unsigned int wfLength) QByteArray empty((int)spectWidth, '\x01'); spectrumPeaks = QByteArray( (int)spectWidth, '\x01' ); + if(spectrumPlasmaSize == 0) + spectrumPlasmaSize = 128; + + //spectrumPlasma.resize(spectrumPlasmaSize); + for(unsigned int p=0; p < spectrumPlasmaSize; p++) + { + spectrumPlasma.append(empty); + } + //wfimage.resize(wfLengthMax); if((unsigned int)wfimage.size() < wfLengthMax) @@ -3522,6 +3531,12 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e } } + spectrumPlasma.push_front(spectrum); + spectrumPlasma.resize(spectrumPlasmaSize); + + // HACK DO NOT CHECK IN: + drawPeaks = false; + drawPlasma = true; if(!spectrumDrawLock) { @@ -3535,6 +3550,9 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e if(drawPeaks) { plot->graph(1)->setData(x,y2); // peaks + } else if (drawPlasma) { + computePlasma(); + plot->graph(1)->setData(x,spectrumPlasmaLine); // peaks } plot->yAxis->setRange(0, rigCaps.spectAmpMax+1); plot->xAxis->setRange(startFreq, endFreq); @@ -3562,6 +3580,35 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e } } +void wfmain::computePlasma() +{ + spectrumPlasmaLine.clear(); + spectrumPlasmaLine.resize(spectWidth); + bool averageMode = true; + if(averageMode) + { + for(int col=0; col < spectWidth; col++) + { + for(int pos=0; pos < spectrumPlasma.size(); pos++) + { + spectrumPlasmaLine[col] += spectrumPlasma[pos][col]; + + } + spectrumPlasmaLine[col] = spectrumPlasmaLine[col] / spectrumPlasma.size(); + } + } else { + // peak mode, running peak display + for(int col=0; col < spectWidth; col++) + { + for(int pos=0; pos < spectrumPlasma.size(); pos++) + { + if((double)(spectrumPlasma[pos][col]) > spectrumPlasmaLine[col]) + spectrumPlasmaLine[col] = spectrumPlasma[pos][col]; + } + } + } +} + void wfmain::receiveSpectrumMode(spectrumMode spectMode) { for (int i = 0; i < ui->spectrumModeCombo->count(); i++) @@ -6000,4 +6047,4 @@ void wfmain::on_audioSystemCombo_currentIndexChanged(int value) { prefs.audioSystem = static_cast(value); setAudioDevicesUI(); // Force all audio devices to update -} \ No newline at end of file +} diff --git a/wfmain.h b/wfmain.h index e691258..c283a94 100644 --- a/wfmain.h +++ b/wfmain.h @@ -557,6 +557,7 @@ private: void setPlotTheme(QCustomPlot *plot, bool isDark); void prepareWf(); void prepareWf(unsigned int wfLength); + void computePlasma(); void showHideSpectrum(bool show); void getInitialRigState(); void setBandButtons(); @@ -648,6 +649,10 @@ private: bool spectrumDrawLock; QByteArray spectrumPeaks; + QVector spectrumPlasmaLine; + QVector spectrumPlasma; + unsigned int spectrumPlasmaSize = 64; + bool drawPlasma = true; QVector wfimage; unsigned int wfLengthMax; From 02e6733cddebcde2d478e7179053a902db68f1dc Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 15:51:26 -0700 Subject: [PATCH 02/11] Fixed ancient issue with layering of the plot data --- wfmain.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/wfmain.cpp b/wfmain.cpp index c0ec779..1236813 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -617,20 +617,21 @@ void wfmain::receiveStatusUpdate(networkStatus status) void wfmain::setupPlots() { - -// Line 290-- spectrumDrawLock = true; - plot = ui->plot; // rename it waterfall. + plot = ui->plot; wf = ui->waterfall; freqIndicatorLine = new QCPItemLine(plot); freqIndicatorLine->setAntialiased(true); freqIndicatorLine->setPen(QPen(Qt::blue)); -// ui->plot->addGraph(); // primary - ui->plot->addGraph(0, 0); // secondary, peaks, same axis as first? + ui->plot->addGraph(0, 0); // secondary, peaks, same axis as first. + ui->plot->addLayer( "Top Layer", ui->plot->layer("main")); + ui->plot->graph(0)->setLayer("Top Layer"); + + ui->waterfall->addGraph(); colorMap = new QCPColorMap(wf->xAxis, wf->yAxis); From 53bed16b45782c978bea99b40a8b5f6f0ba1c446 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 16:21:33 -0700 Subject: [PATCH 03/11] Added floor and ceiling adjustments for the plots. --- wfmain.cpp | 75 ++++++++++++++++++++++------------- wfmain.h | 9 +++++ wfmain.ui | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 168 insertions(+), 30 deletions(-) diff --git a/wfmain.cpp b/wfmain.cpp index 1236813..157f843 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -3192,6 +3192,11 @@ void wfmain::receiveRigID(rigCapabilities rigCaps) } setWindowTitle(rigCaps.modelName); this->spectWidth = rigCaps.spectLenMax; // used once haveRigCaps is true. + wfCeiling = rigCaps.spectAmpMax; + plotCeiling = rigCaps.spectAmpMax; + ui->topLevelSlider->setMaximum(rigCaps.spectAmpMax); + wfFloor = 0; + plotFloor = 0; haveRigCaps = true; // Added so that server receives rig capabilities. emit sendRigCaps(rigCaps); @@ -3555,7 +3560,7 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e computePlasma(); plot->graph(1)->setData(x,spectrumPlasmaLine); // peaks } - plot->yAxis->setRange(0, rigCaps.spectAmpMax+1); + plot->yAxis->setRange(plotFloor, plotCeiling); plot->xAxis->setRange(startFreq, endFreq); plot->replot(); @@ -5792,32 +5797,6 @@ void wfmain::on_radioStatusBtn_clicked() } } -// --- DEBUG FUNCTION --- -void wfmain::on_debugBtn_clicked() -{ - qInfo(logSystem()) << "Debug button pressed."; - // issueDelayedCommand(cmdGetRigID); - //emit getRigCIV(); - //trxadj->show(); - //setRadioTimeDatePrep(); - //wf->setInteraction(QCP::iRangeZoom, true); - //wf->setInteraction(QCP::iRangeDrag, true); - bool ok; - int height = QInputDialog::getInt(this, "wfview Radio Polling Setup", "Poll Timing Interval (ms)", 350, 1, 500, 1, &ok ); - - this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - this->setMaximumSize(QSize(1025,height)); - this->setMinimumSize(QSize(1025,height)); - //this->setMaximumSize(QSize(929, 270)); - //this->setMinimumSize(QSize(929, 270)); - - resize(minimumSize()); - adjustSize(); // main window - adjustSize(); - -} - - void wfmain::setAudioDevicesUI() { @@ -6049,3 +6028,45 @@ void wfmain::on_audioSystemCombo_currentIndexChanged(int value) prefs.audioSystem = static_cast(value); setAudioDevicesUI(); // Force all audio devices to update } + +void wfmain::on_topLevelSlider_valueChanged(int value) +{ + wfCeiling = value; + plotCeiling = value; + plot->yAxis->setRange(QCPRange(plotFloor, plotCeiling)); + colorMap->setDataRange(QCPRange(wfFloor, wfCeiling)); +} + +void wfmain::on_botLevelSlider_valueChanged(int value) +{ + wfFloor = value; + plotFloor = value; + plot->yAxis->setRange(QCPRange(plotFloor, plotCeiling)); + colorMap->setDataRange(QCPRange(wfFloor, wfCeiling)); +} + + +// --- DEBUG FUNCTION --- +void wfmain::on_debugBtn_clicked() +{ + qInfo(logSystem()) << "Debug button pressed."; + // issueDelayedCommand(cmdGetRigID); + //emit getRigCIV(); + //trxadj->show(); + //setRadioTimeDatePrep(); + //wf->setInteraction(QCP::iRangeZoom, true); + //wf->setInteraction(QCP::iRangeDrag, true); + bool ok; + int height = QInputDialog::getInt(this, "wfview window fixed height", "number: ", 350, 1, 500, 1, &ok ); + + this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + this->setMaximumSize(QSize(1025,height)); + this->setMinimumSize(QSize(1025,height)); + //this->setMaximumSize(QSize(929, 270)); + //this->setMinimumSize(QSize(929, 270)); + + resize(minimumSize()); + adjustSize(); // main window + adjustSize(); + +} diff --git a/wfmain.h b/wfmain.h index c283a94..5f202b5 100644 --- a/wfmain.h +++ b/wfmain.h @@ -539,6 +539,10 @@ private slots: void on_audioSystemCombo_currentIndexChanged(int value); + void on_topLevelSlider_valueChanged(int value); + + void on_botLevelSlider_valueChanged(int value); + private: Ui::wfmain *ui; void closeEvent(QCloseEvent *event); @@ -654,6 +658,11 @@ private: unsigned int spectrumPlasmaSize = 64; bool drawPlasma = true; + double plotFloor = 0; + double plotCeiling = 160; + double wfFloor = 0; + double wfCeiling = 160; + QVector wfimage; unsigned int wfLengthMax; diff --git a/wfmain.ui b/wfmain.ui index 124a54b..67732e6 100644 --- a/wfmain.ui +++ b/wfmain.ui @@ -6,7 +6,7 @@ 0 0 - 940 + 1002 569 @@ -18,7 +18,7 @@ - 3 + 0 @@ -846,6 +846,114 @@ + + + + 0 + + + 0 + + + + + + 0 + 70 + + + + + 16777215 + 80 + + + + Sets the ceiling for the waterfall and spectrum displays + + + Ceiling for waterfall and spectrum display + + + 1 + + + 160 + + + 160 + + + Qt::Vertical + + + + + + + + 16777215 + 15 + + + + Top + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 70 + + + + + 16777215 + 80 + + + + 160 + + + Qt::Vertical + + + + + + + + 16777215 + 15 + + + + Bot + + + + + @@ -3790,7 +3898,7 @@ 0 0 - 940 + 1002 21 From 32d55ef490ed99296b21137ebc4d48f55dbdf2bb Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 16:34:26 -0700 Subject: [PATCH 04/11] Fixed spectrum line length --- wfmain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wfmain.cpp b/wfmain.cpp index 157f843..58891aa 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -3551,7 +3551,7 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e if((freq.MHzDouble < endFreq) && (freq.MHzDouble > startFreq)) { freqIndicatorLine->start->setCoords(freq.MHzDouble,0); - freqIndicatorLine->end->setCoords(freq.MHzDouble,160); + freqIndicatorLine->end->setCoords(freq.MHzDouble,rigCaps.spectAmpMax); } if(drawPeaks) { From 6ebb3b7680161275f8bd7e02acf686e566e0ad04 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 18:41:35 -0700 Subject: [PATCH 05/11] Added some preferences for the plasma. --- wfmain.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++-------- wfmain.h | 18 +++++++- wfmain.ui | 113 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 241 insertions(+), 22 deletions(-) diff --git a/wfmain.cpp b/wfmain.cpp index 58891aa..5a2f477 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -1050,6 +1050,25 @@ void wfmain::setUIToPrefs() on_drawPeakChk_clicked(prefs.drawPeaks); drawPeaks = prefs.drawPeaks; + underlayMode = prefs.underlayMode; + switch(underlayMode) + { + case underlayNone: + ui->underlayNone->setChecked(true); + break; + case underlayPeakHold: + ui->underlayPeakHold->setChecked(true); + break; + case underlayPeakBuffer: + ui->underlayPeakBuffer->setChecked(true); + break; + case underlayAverageBuffer: + ui->underlayAverageBuffer->setChecked(true); + break; + default: + break; + } + ui->wfAntiAliasChk->setChecked(prefs.wfAntiAlias); on_wfAntiAliasChk_clicked(prefs.wfAntiAlias); @@ -1059,6 +1078,12 @@ void wfmain::setUIToPrefs() ui->wfLengthSlider->setValue(prefs.wflength); prepareWf(prefs.wflength); + ui->topLevelSlider->setValue(prefs.plotCeiling); + ui->botLevelSlider->setValue(prefs.plotFloor); + + plot->yAxis->setRange(QCPRange(prefs.plotFloor, prefs.plotCeiling)); + colorMap->setDataRange(QCPRange(prefs.plotFloor, prefs.plotCeiling)); + ui->wfthemeCombo->setCurrentIndex(ui->wfthemeCombo->findData(prefs.wftheme)); colorMap->setGradient(static_cast(prefs.wftheme)); @@ -1250,6 +1275,7 @@ void wfmain::setDefPrefs() defPrefs.useDarkMode = true; defPrefs.useSystemTheme = false; defPrefs.drawPeaks = true; + defPrefs.underlayMode = underlayNone; defPrefs.wfAntiAlias = false; defPrefs.wfInterpolate = true; defPrefs.stylesheetPath = QString("qdarkstyle/style.qss"); @@ -1266,6 +1292,8 @@ void wfmain::setDefPrefs() defPrefs.localAFgain = 255; defPrefs.wflength = 160; defPrefs.wftheme = static_cast(QCPColorGradient::gpJet); + defPrefs.plotFloor = 0; + defPrefs.plotCeiling = 160; defPrefs.confirmExit = true; defPrefs.confirmPowerOff = true; defPrefs.meter2Type = meterNone; @@ -1293,7 +1321,14 @@ void wfmain::loadSettings() prefs.useDarkMode = settings->value("UseDarkMode", defPrefs.useDarkMode).toBool(); prefs.useSystemTheme = settings->value("UseSystemTheme", defPrefs.useSystemTheme).toBool(); prefs.wftheme = settings->value("WFTheme", defPrefs.wftheme).toInt(); + prefs.plotFloor = settings->value("plotFloor", defPrefs.plotFloor).toInt(); + prefs.plotCeiling = settings->value("plotCeiling", defPrefs.plotCeiling).toInt(); + plotFloor = prefs.plotFloor; + plotCeiling = prefs.plotCeiling; + wfFloor = prefs.plotFloor; + wfCeiling = prefs.plotCeiling; prefs.drawPeaks = settings->value("DrawPeaks", defPrefs.drawPeaks).toBool(); + prefs.underlayMode = static_cast(settings->value("underlayMode", defPrefs.underlayMode).toInt()); prefs.wfAntiAlias = settings->value("WFAntiAlias", defPrefs.wfAntiAlias).toBool(); prefs.wfInterpolate = settings->value("WFInterpolate", defPrefs.wfInterpolate).toBool(); prefs.wflength = (unsigned int)settings->value("WFLength", defPrefs.wflength).toInt(); @@ -1801,9 +1836,12 @@ void wfmain::saveSettings() settings->setValue("UseSystemTheme", prefs.useSystemTheme); settings->setValue("UseDarkMode", prefs.useDarkMode); settings->setValue("DrawPeaks", prefs.drawPeaks); + settings->setValue("underlayMode", prefs.underlayMode); settings->setValue("WFAntiAlias", prefs.wfAntiAlias); settings->setValue("WFInterpolate", prefs.wfInterpolate); settings->setValue("WFTheme", prefs.wftheme); + settings->setValue("plotFloor", prefs.plotFloor); + settings->setValue("plotCeiling", prefs.plotCeiling); settings->setValue("StylesheetPath", prefs.stylesheetPath); settings->setValue("splitter", ui->splitter->saveState()); settings->setValue("windowGeometry", saveGeometry()); @@ -3195,8 +3233,7 @@ void wfmain::receiveRigID(rigCapabilities rigCaps) wfCeiling = rigCaps.spectAmpMax; plotCeiling = rigCaps.spectAmpMax; ui->topLevelSlider->setMaximum(rigCaps.spectAmpMax); - wfFloor = 0; - plotFloor = 0; + haveRigCaps = true; // Added so that server receives rig capabilities. emit sendRigCaps(rigCaps); @@ -3316,6 +3353,8 @@ void wfmain::receiveRigID(rigCapabilities rigCaps) { ui->scopeBWCombo->addItem(rigCaps.scopeCenterSpans.at(i).name, (int)rigCaps.scopeCenterSpans.at(i).cstype); } + plot->yAxis->setRange(QCPRange(prefs.plotFloor, prefs.plotCeiling)); + colorMap->setDataRange(QCPRange(prefs.plotFloor, prefs.plotCeiling)); } else { ui->scopeBWCombo->setHidden(true); } @@ -3527,7 +3566,7 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e { //x[i] = (i * (endFreq-startFreq)/specLen) + startFreq; y[i] = (unsigned char)spectrum.at(i); - if(drawPeaks) + if(underlayMode == underlayPeakHold) { if((unsigned char)spectrum.at(i) > (unsigned char)spectrumPeaks.at(i)) { @@ -3553,13 +3592,16 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e freqIndicatorLine->start->setCoords(freq.MHzDouble,0); freqIndicatorLine->end->setCoords(freq.MHzDouble,rigCaps.spectAmpMax); } - if(drawPeaks) + if(underlayMode == underlayPeakHold) { plot->graph(1)->setData(x,y2); // peaks - } else if (drawPlasma) { + } else if (underlayMode != underlayNone) { computePlasma(); - plot->graph(1)->setData(x,spectrumPlasmaLine); // peaks + plot->graph(1)->setData(x,spectrumPlasmaLine); + } else { + plot->graph(1)->setData(x,y2); // peaks, but probably cleared out } + plot->yAxis->setRange(plotFloor, plotCeiling); plot->xAxis->setRange(startFreq, endFreq); plot->replot(); @@ -3590,8 +3632,7 @@ void wfmain::computePlasma() { spectrumPlasmaLine.clear(); spectrumPlasmaLine.resize(spectWidth); - bool averageMode = true; - if(averageMode) + if(underlayMode == underlayAverageBuffer) { for(int col=0; col < spectWidth; col++) { @@ -3602,7 +3643,7 @@ void wfmain::computePlasma() } spectrumPlasmaLine[col] = spectrumPlasmaLine[col] / spectrumPlasma.size(); } - } else { + } else if (underlayMode == underlayPeakBuffer){ // peak mode, running peak display for(int col=0; col < spectWidth; col++) { @@ -6033,6 +6074,7 @@ void wfmain::on_topLevelSlider_valueChanged(int value) { wfCeiling = value; plotCeiling = value; + prefs.plotCeiling = value; plot->yAxis->setRange(QCPRange(plotFloor, plotCeiling)); colorMap->setDataRange(QCPRange(wfFloor, wfCeiling)); } @@ -6041,10 +6083,59 @@ void wfmain::on_botLevelSlider_valueChanged(int value) { wfFloor = value; plotFloor = value; + prefs.plotFloor = value; plot->yAxis->setRange(QCPRange(plotFloor, plotCeiling)); colorMap->setDataRange(QCPRange(wfFloor, wfCeiling)); } +void wfmain::on_underlayBufferSlider_valueChanged(int value) +{ + // TODO: lock first... + spectrumPlasma.resize(value); +} + +void wfmain::on_underlayNone_toggled(bool checked) +{ + ui->underlayBufferSlider->setDisabled(checked); + if(checked) + { + underlayMode = underlayNone; + prefs.underlayMode = underlayMode; + on_clearPeakBtn_clicked(); + } +} + +void wfmain::on_underlayPeakHold_toggled(bool checked) +{ + ui->underlayBufferSlider->setDisabled(checked); + if(checked) + { + underlayMode = underlayPeakHold; + prefs.underlayMode = underlayMode; + on_clearPeakBtn_clicked(); + } + +} + +void wfmain::on_underlayPeakBuffer_toggled(bool checked) +{ + ui->underlayBufferSlider->setDisabled(!checked); + if(checked) + { + underlayMode = underlayPeakBuffer; + prefs.underlayMode = underlayMode; + } +} + +void wfmain::on_underlayAverageBuffer_toggled(bool checked) +{ + ui->underlayBufferSlider->setDisabled(!checked); + if(checked) + { + underlayMode = underlayAverageBuffer; + prefs.underlayMode = underlayMode; + } +} // --- DEBUG FUNCTION --- void wfmain::on_debugBtn_clicked() @@ -6056,17 +6147,20 @@ void wfmain::on_debugBtn_clicked() //setRadioTimeDatePrep(); //wf->setInteraction(QCP::iRangeZoom, true); //wf->setInteraction(QCP::iRangeDrag, true); - bool ok; - int height = QInputDialog::getInt(this, "wfview window fixed height", "number: ", 350, 1, 500, 1, &ok ); + plot->yAxis->setRange(QCPRange(plotFloor, plotCeiling)); + colorMap->setDataRange(QCPRange(wfFloor, wfCeiling)); - this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - this->setMaximumSize(QSize(1025,height)); - this->setMinimumSize(QSize(1025,height)); - //this->setMaximumSize(QSize(929, 270)); - //this->setMinimumSize(QSize(929, 270)); +// bool ok; +// int height = QInputDialog::getInt(this, "wfview window fixed height", "number: ", 350, 1, 500, 1, &ok ); - resize(minimumSize()); - adjustSize(); // main window - adjustSize(); +// this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); +// this->setMaximumSize(QSize(1025,height)); +// this->setMinimumSize(QSize(1025,height)); +// //this->setMaximumSize(QSize(929, 270)); +// //this->setMinimumSize(QSize(929, 270)); + +// resize(minimumSize()); +// adjustSize(); // main window +// adjustSize(); } diff --git a/wfmain.h b/wfmain.h index 5f202b5..5d3329c 100644 --- a/wfmain.h +++ b/wfmain.h @@ -543,6 +543,16 @@ private slots: void on_botLevelSlider_valueChanged(int value); + void on_underlayBufferSlider_valueChanged(int value); + + void on_underlayNone_toggled(bool checked); + + void on_underlayPeakHold_toggled(bool checked); + + void on_underlayPeakBuffer_toggled(bool checked); + + void on_underlayAverageBuffer_toggled(bool checked); + private: Ui::wfmain *ui; void closeEvent(QCloseEvent *event); @@ -652,10 +662,14 @@ private: quint16 wfLength; bool spectrumDrawLock; + enum underlay_t { underlayNone, underlayPeakHold, underlayPeakBuffer, underlayAverageBuffer }; + + QByteArray spectrumPeaks; QVector spectrumPlasmaLine; QVector spectrumPlasma; unsigned int spectrumPlasmaSize = 64; + underlay_t underlayMode = underlayNone; bool drawPlasma = true; double plotFloor = 0; @@ -770,6 +784,7 @@ private: bool useDarkMode; bool useSystemTheme; bool drawPeaks; + underlay_t underlayMode = underlayNone; bool wfAntiAlias; bool wfInterpolate; QString stylesheetPath; @@ -788,13 +803,14 @@ private: unsigned char localAFgain; unsigned int wflength; int wftheme; + int plotFloor; + int plotCeiling; bool confirmExit; bool confirmPowerOff; meterKind meter2Type; quint16 tcpPort; quint8 waterfallFormat; audioType audioSystem; - // plot scheme } prefs; preferences defPrefs; diff --git a/wfmain.ui b/wfmain.ui index 67732e6..2e0d107 100644 --- a/wfmain.ui +++ b/wfmain.ui @@ -18,7 +18,7 @@ - 0 + 3 @@ -2174,7 +2174,7 @@ - 0 + 1 @@ -2907,6 +2907,114 @@ + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Underlay Mode + + + + + + + None + + + true + + + underlayButtonGroup + + + + + + + Peak Hold + + + underlayButtonGroup + + + + + + + Peak + + + underlayButtonGroup + + + + + + + Average + + + underlayButtonGroup + + + + + + + Uneerlay Buffer Size: + + + + + + + + 100 + 16777215 + + + + 8 + + + 128 + + + 64 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -3921,5 +4029,6 @@ + From 03a279087e2ea6c18f213f5668254c02bcac846e Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 18:46:00 -0700 Subject: [PATCH 06/11] Added underlayBufferSize to the preferences. --- wfmain.cpp | 7 +++++++ wfmain.h | 1 + 2 files changed, 8 insertions(+) diff --git a/wfmain.cpp b/wfmain.cpp index 5a2f477..3f6adb8 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -1069,6 +1069,9 @@ void wfmain::setUIToPrefs() break; } + ui->underlayBufferSlider->setValue(prefs.underlayBufferSize); + on_underlayBufferSlider_valueChanged(prefs.underlayBufferSize); + ui->wfAntiAliasChk->setChecked(prefs.wfAntiAlias); on_wfAntiAliasChk_clicked(prefs.wfAntiAlias); @@ -1276,6 +1279,7 @@ void wfmain::setDefPrefs() defPrefs.useSystemTheme = false; defPrefs.drawPeaks = true; defPrefs.underlayMode = underlayNone; + defPrefs.underlayBufferSize = 64; defPrefs.wfAntiAlias = false; defPrefs.wfInterpolate = true; defPrefs.stylesheetPath = QString("qdarkstyle/style.qss"); @@ -1328,6 +1332,7 @@ void wfmain::loadSettings() wfFloor = prefs.plotFloor; wfCeiling = prefs.plotCeiling; prefs.drawPeaks = settings->value("DrawPeaks", defPrefs.drawPeaks).toBool(); + prefs.underlayBufferSize = settings->value("underlayBufferSize", defPrefs.underlayBufferSize).toInt(); prefs.underlayMode = static_cast(settings->value("underlayMode", defPrefs.underlayMode).toInt()); prefs.wfAntiAlias = settings->value("WFAntiAlias", defPrefs.wfAntiAlias).toBool(); prefs.wfInterpolate = settings->value("WFInterpolate", defPrefs.wfInterpolate).toBool(); @@ -1837,6 +1842,7 @@ void wfmain::saveSettings() settings->setValue("UseDarkMode", prefs.useDarkMode); settings->setValue("DrawPeaks", prefs.drawPeaks); settings->setValue("underlayMode", prefs.underlayMode); + settings->setValue("underlayBufferSize", prefs.underlayBufferSize); settings->setValue("WFAntiAlias", prefs.wfAntiAlias); settings->setValue("WFInterpolate", prefs.wfInterpolate); settings->setValue("WFTheme", prefs.wftheme); @@ -6092,6 +6098,7 @@ void wfmain::on_underlayBufferSlider_valueChanged(int value) { // TODO: lock first... spectrumPlasma.resize(value); + prefs.underlayBufferSize = value; } void wfmain::on_underlayNone_toggled(bool checked) diff --git a/wfmain.h b/wfmain.h index 5d3329c..d514950 100644 --- a/wfmain.h +++ b/wfmain.h @@ -785,6 +785,7 @@ private: bool useSystemTheme; bool drawPeaks; underlay_t underlayMode = underlayNone; + int underlayBufferSize = 64; bool wfAntiAlias; bool wfInterpolate; QString stylesheetPath; From 123084c7794000049413b07858c279ded7bbefb9 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 19:58:04 -0700 Subject: [PATCH 07/11] Slightly faster plotting due to data being already sorted. --- wfmain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wfmain.cpp b/wfmain.cpp index 3f6adb8..6020a39 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -3592,7 +3592,7 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e if(!spectrumDrawLock) { //ui->qcp->addGraph(); - plot->graph(0)->setData(x,y); + plot->graph(0)->setData(x,y, true); if((freq.MHzDouble < endFreq) && (freq.MHzDouble > startFreq)) { freqIndicatorLine->start->setCoords(freq.MHzDouble,0); @@ -3600,12 +3600,12 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e } if(underlayMode == underlayPeakHold) { - plot->graph(1)->setData(x,y2); // peaks + plot->graph(1)->setData(x,y2, true); // peaks } else if (underlayMode != underlayNone) { computePlasma(); plot->graph(1)->setData(x,spectrumPlasmaLine); } else { - plot->graph(1)->setData(x,y2); // peaks, but probably cleared out + plot->graph(1)->setData(x,y2, true); // peaks, but probably cleared out } plot->yAxis->setRange(plotFloor, plotCeiling); From 5215984de82e912d7b6f6997752c63498f5a7596 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 21:46:47 -0700 Subject: [PATCH 08/11] Minor change for slightly faster averages. --- wfmain.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/wfmain.cpp b/wfmain.cpp index 6020a39..94652c7 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -3536,12 +3536,13 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e if((startFreq != oldLowerFreq) || (endFreq != oldUpperFreq)) { // If the frequency changed and we were drawing peaks, now is the time to clearn them - if(drawPeaks) + if(underlayMode == underlayPeakHold) { // TODO: create non-button function to do this // This will break if the button is ever moved or renamed. on_clearPeakBtn_clicked(); } + // TODO: Add clear-out for the buffer } oldLowerFreq = startFreq; @@ -3638,22 +3639,22 @@ void wfmain::computePlasma() { spectrumPlasmaLine.clear(); spectrumPlasmaLine.resize(spectWidth); + int specPlasmaSize = spectrumPlasma.size(); if(underlayMode == underlayAverageBuffer) { for(int col=0; col < spectWidth; col++) { - for(int pos=0; pos < spectrumPlasma.size(); pos++) + for(int pos=0; pos < specPlasmaSize; pos++) { spectrumPlasmaLine[col] += spectrumPlasma[pos][col]; - } - spectrumPlasmaLine[col] = spectrumPlasmaLine[col] / spectrumPlasma.size(); + spectrumPlasmaLine[col] = spectrumPlasmaLine[col] / specPlasmaSize; } } else if (underlayMode == underlayPeakBuffer){ // peak mode, running peak display for(int col=0; col < spectWidth; col++) { - for(int pos=0; pos < spectrumPlasma.size(); pos++) + for(int pos=0; pos < specPlasmaSize; pos++) { if((double)(spectrumPlasma[pos][col]) > spectrumPlasmaLine[col]) spectrumPlasmaLine[col] = spectrumPlasma[pos][col]; From b2204b35193f45685491a70d44ddfe7479f935f1 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 22:38:44 -0700 Subject: [PATCH 09/11] Fixed resize; added mutex. --- wfmain.cpp | 38 ++++++++++++++++++++++++++++++++++---- wfmain.h | 4 ++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/wfmain.cpp b/wfmain.cpp index 94652c7..45c6454 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -3581,10 +3581,12 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e } y2[i] = (unsigned char)spectrumPeaks.at(i); } - } + plasmaMutex.lock(); spectrumPlasma.push_front(spectrum); - spectrumPlasma.resize(spectrumPlasmaSize); + spectrumPlasma.pop_back(); + //spectrumPlasma.resize(spectrumPlasmaSize); + plasmaMutex.unlock(); // HACK DO NOT CHECK IN: drawPeaks = false; @@ -3637,6 +3639,7 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e void wfmain::computePlasma() { + plasmaMutex.lock(); spectrumPlasmaLine.clear(); spectrumPlasmaLine.resize(spectWidth); int specPlasmaSize = spectrumPlasma.size(); @@ -3661,6 +3664,8 @@ void wfmain::computePlasma() } } } + plasmaMutex.unlock(); + } void wfmain::receiveSpectrumMode(spectrumMode spectMode) @@ -6097,11 +6102,36 @@ void wfmain::on_botLevelSlider_valueChanged(int value) void wfmain::on_underlayBufferSlider_valueChanged(int value) { - // TODO: lock first... - spectrumPlasma.resize(value); + resizePlasmaBuffer(value); prefs.underlayBufferSize = value; } +void wfmain::resizePlasmaBuffer(int newSize) +{ + + QByteArray empty((int)spectWidth, '\x01'); + plasmaMutex.lock(); + + int oldSize = spectrumPlasma.size(); + + if(oldSize < newSize) + { + spectrumPlasma.resize(newSize); + for(int p=oldSize; p < newSize; p++) + { + spectrumPlasma.append(empty); + } + } else if (oldSize > newSize){ + for(int p = oldSize; p > newSize; p--) + { + spectrumPlasma.pop_back(); + } + } + + spectrumPlasma.squeeze(); + plasmaMutex.unlock(); +} + void wfmain::on_underlayNone_toggled(bool checked) { ui->underlayBufferSlider->setDisabled(checked); diff --git a/wfmain.h b/wfmain.h index d514950..6bafd06 100644 --- a/wfmain.h +++ b/wfmain.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include "logcategories.h" #include "commhandler.h" @@ -671,6 +673,8 @@ private: unsigned int spectrumPlasmaSize = 64; underlay_t underlayMode = underlayNone; bool drawPlasma = true; + QMutex plasmaMutex; + void resizePlasmaBuffer(int newSize); double plotFloor = 0; double plotCeiling = 160; From 76398808612b7e77822d277b8c20c2fae8c749f4 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 17 Aug 2022 23:30:02 -0700 Subject: [PATCH 10/11] Fixed issue with the floor and ceiling not updating initially. The waterfall is now ranged prior to replot each time. --- wfmain.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wfmain.cpp b/wfmain.cpp index 45c6454..bbdfe7d 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -3236,8 +3236,8 @@ void wfmain::receiveRigID(rigCapabilities rigCaps) } setWindowTitle(rigCaps.modelName); this->spectWidth = rigCaps.spectLenMax; // used once haveRigCaps is true. - wfCeiling = rigCaps.spectAmpMax; - plotCeiling = rigCaps.spectAmpMax; + //wfCeiling = rigCaps.spectAmpMax; + //plotCeiling = rigCaps.spectAmpMax; ui->topLevelSlider->setMaximum(rigCaps.spectAmpMax); haveRigCaps = true; @@ -3611,7 +3611,7 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e plot->graph(1)->setData(x,y2, true); // peaks, but probably cleared out } - plot->yAxis->setRange(plotFloor, plotCeiling); + plot->yAxis->setRange(prefs.plotFloor, prefs.plotCeiling); plot->xAxis->setRange(startFreq, endFreq); plot->replot(); @@ -3629,10 +3629,10 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e colorMap->data()->setCell( col, row, wfimage.at(row).at(col)); } } - - wf->yAxis->setRange(0,wfLength - 1); - wf->xAxis->setRange(0, spectWidth-1); - wf->replot(); + colorMap->setDataRange(QCPRange(wfFloor, wfCeiling)); + wf->yAxis->setRange(0,wfLength - 1); + wf->xAxis->setRange(0, spectWidth-1); + wf->replot(); } } } From f1f58a10cf602f87e94dce703f1b1a38f6c883e6 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Thu, 18 Aug 2022 09:56:06 -0700 Subject: [PATCH 11/11] Slight reduction in CPU usage with regards to wf, more to come. --- wfmain.cpp | 25 +++++++++++++++++++------ wfmain.h | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/wfmain.cpp b/wfmain.cpp index bbdfe7d..c55d6cc 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -3533,6 +3533,9 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e return; } + QElapsedTimer performanceTimer; + bool updateRange = false; + if((startFreq != oldLowerFreq) || (endFreq != oldUpperFreq)) { // If the frequency changed and we were drawing peaks, now is the time to clearn them @@ -3594,6 +3597,9 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e if(!spectrumDrawLock) { + if((plotFloor != oldPlotFloor) || (plotCeiling != oldPlotCeiling)) + updateRange = true; + //ui->qcp->addGraph(); plot->graph(0)->setData(x,y, true); if((freq.MHzDouble < endFreq) && (freq.MHzDouble > startFreq)) @@ -3611,29 +3617,36 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e plot->graph(1)->setData(x,y2, true); // peaks, but probably cleared out } - plot->yAxis->setRange(prefs.plotFloor, prefs.plotCeiling); + if(updateRange) + plot->yAxis->setRange(prefs.plotFloor, prefs.plotCeiling); + plot->xAxis->setRange(startFreq, endFreq); plot->replot(); if(specLen == spectWidth) { wfimage.prepend(spectrum); - wfimage.resize(wfLengthMax); - wfimage.squeeze(); - + wfimage.pop_back(); + QByteArray wfRow; // Waterfall: for(int row = 0; row < wfLength; row++) { + wfRow = wfimage.at(row); for(int col = 0; col < spectWidth; col++) { - colorMap->data()->setCell( col, row, wfimage.at(row).at(col)); + colorMap->data()->setCell( col, row, wfRow.at(col)); } } - colorMap->setDataRange(QCPRange(wfFloor, wfCeiling)); + if(updateRange) + { + colorMap->setDataRange(QCPRange(wfFloor, wfCeiling)); + } wf->yAxis->setRange(0,wfLength - 1); wf->xAxis->setRange(0, spectWidth-1); wf->replot(); } + oldPlotFloor = plotFloor; + oldPlotCeiling = plotCeiling; } } diff --git a/wfmain.h b/wfmain.h index 6bafd06..55fc8d2 100644 --- a/wfmain.h +++ b/wfmain.h @@ -680,6 +680,8 @@ private: double plotCeiling = 160; double wfFloor = 0; double wfCeiling = 160; + double oldPlotFloor = -1; + double oldPlotCeiling = 999; QVector wfimage; unsigned int wfLengthMax;