diff --git a/mainwindow.cpp b/mainwindow.cpp index 3e2680b..fad642e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3280,6 +3280,10 @@ void MainWindow::on_monitorButton_clicked (bool checked) void MainWindow::monitor (bool state) { ui->monitorButton->setChecked (state); + + // make sure widegraph is running if we are monitoring, otherwise pause it. + m_wideGraph->setPaused(!state); + if (state) { m_diskData = false; // no longer reading WAV files if (!m_monitoring) Q_EMIT resumeAudioInputStream (); diff --git a/plotter.cpp b/plotter.cpp index 785f580..cb7a6b7 100644 --- a/plotter.cpp +++ b/plotter.cpp @@ -172,12 +172,13 @@ void CPlotter::draw(float swide[], bool bScroll, bool bRed) if(bScroll and swide[0]<1.e29) { flat4_(swide,&iz,&m_Flatten); - if(!m_bReplot) flat4_(&dec_data.savg[j0],&jz,&m_Flatten); + //if(!m_bReplot) flat4_(&dec_data.savg[j0],&jz,&m_Flatten); } ymin=1.e30; if(swide[0]>1.e29 and swide[0]< 1.5e30) painter1.setPen(Qt::green); // horizontal line if(swide[0]>1.4e30) painter1.setPen(Qt::yellow); + if(!m_bReplot) { m_j=0; int irow=-1; diff --git a/widegraph.cpp b/widegraph.cpp index 376ff76..a8752c8 100644 --- a/widegraph.cpp +++ b/widegraph.cpp @@ -1,5 +1,6 @@ #include "widegraph.h" + #include #include #include @@ -31,7 +32,8 @@ WideGraph::WideGraph(QSettings * settings, QWidget *parent) : m_filterMinimum {0}, m_filterMaximum {5000}, m_filterEnabled {false}, - m_bHaveTransmitted {false} + m_bHaveTransmitted {false}, + m_dist { 0.0, 0.1 } { ui->setupUi(this); @@ -164,6 +166,7 @@ WideGraph::WideGraph(QSettings * settings, QWidget *parent) : setRxRange (); ui->controls_widget->setVisible(!m_settings->value("HideControls", false).toBool()); ui->cbControls->setChecked(!m_settings->value("HideControls", false).toBool()); + ui->fpsSpinBox->setValue(m_settings->value ("WaterfallFPS", 4).toInt()); auto splitState = m_settings->value("SplitState").toByteArray(); if(!splitState.isEmpty()){ @@ -189,6 +192,10 @@ WideGraph::WideGraph(QSettings * settings, QWidget *parent) : ui->paletteComboBox->addItem (user_defined); if (user_defined == m_waterfallPalette) ui->paletteComboBox->setCurrentIndex(index); readPalette (); + + connect(&m_drawTimer, &QTimer::timeout, this, &WideGraph::draw); + m_drawTimer.setSingleShot(true); + m_drawTimer.start(100); //### Don't change the 100 ms! ### } WideGraph::~WideGraph () @@ -234,6 +241,7 @@ void WideGraph::saveSettings() //saveS m_settings->setValue ("FilterEnabled", m_filterEnabled); m_settings->setValue ("FilterOpacityPercent", ui->filterOpacitySpinBox->value()); m_settings->setValue ("SplitState", ui->splitter->saveState()); + m_settings->setValue ("WaterfallFPS", ui->fpsSpinBox->value()); } void WideGraph::drawRed(int ia, int ib) @@ -244,9 +252,12 @@ void WideGraph::drawRed(int ia, int ib) void WideGraph::dataSink2(float s[], float df3, int ihsym, int ndiskdata) //dataSink2 { static float splot[NSMAX]; + + QMutexLocker lock(&m_drawLock); + int nbpp = ui->widePlot->binsPerPixel(); -//Average spectra over specified number, m_waterfallAvg + //Average spectra over specified number, m_waterfallAvg if (m_n==0) { for (int i=0; i=m_waterfallAvg) { - for (int i=0; iwidePlot->startFreq()/df3 + 0.5); - int jz=5000.0/(nbpp*df3); - if(jz>MAX_SCREENSIZE) jz=MAX_SCREENSIZE; - m_jz=jz; - for (int j=0; jwidePlot->startFreq()/df3 + 0.5); + int jz=5000.0/(nbpp*df3); + if(jz>MAX_SCREENSIZE) jz=MAX_SCREENSIZE; + m_jz=jz; + for (int j=0; jwidePlot->draw(swide,true,false); + // swide[j]=nbpp*smax; + swide[j]=nbpp*ss; } + + // Time according to this computer + qint64 ms = DriftingDateTime::currentMSecsSinceEpoch() % 86400000; + int ntr = (ms/1000) % m_TRperiod; + if((ndiskdata && ihsym <= m_waterfallAvg) || (!ndiskdata && ntrwidePlot->draw(swide,true,false); + + // copy swide around + // { + // memcpy(swide2, swide, sizeof(swide[0])*MAX_SCREENSIZE); + // } +} + +void WideGraph::draw(){ + static const quint64 buf = 10; + static quint64 lastLoop; + + quint64 fps = qMax(1, qMin(ui->fpsSpinBox->value(), 100)); + quint64 loopMs = 1000/fps * m_waterfallAvg; + quint64 thisLoop = QDateTime::currentMSecsSinceEpoch(); + if(lastLoop == 0){ + lastLoop = thisLoop; + } + quint64 delta = thisLoop - lastLoop; + if(delta > (loopMs + buf)){ + qDebug() << "widegraph overrun" << (delta-loopMs); + } + lastLoop = thisLoop; + + // do the drawing + drawSwide(); + + // compute the processing time and adjust loop to hit the next 100ms + auto endLoop = QDateTime::currentMSecsSinceEpoch(); + auto processingTime = endLoop - thisLoop; + auto nextLoopMs = 0; + if(processingTime < loopMs){ + nextLoopMs = loopMs - processingTime; + } + m_drawTimer.start(nextLoopMs); +} + +void WideGraph::drawSwide(){ + static bool lastSwideGreen = false; + + if(m_paused){ + return; + } + + QMutexLocker lock(&m_drawLock); + + float swideLocal[MAX_SCREENSIZE]; + memcpy(swideLocal, swide, sizeof(swide[0])*MAX_SCREENSIZE); + + bool thisSwideGreen = swideLocal[0] >1.e29; + for(int i = 0; i < MAX_SCREENSIZE; i++){ + if(swideLocal[i] == 0.0){ + swideLocal[i] += m_dist(m_gen); + } +#if 0 + else if (lastSwideGreen && thisSwideGreen){ + swideLocal[i] = m_dist(m_gen); + } +#endif + } + + ui->widePlot->draw(swideLocal,true,false); + lastSwideGreen = thisSwideGreen; } void WideGraph::on_bppSpinBox_valueChanged(int n) //bpp @@ -695,7 +775,6 @@ void WideGraph::on_gain2dSlider_valueChanged(int value) //Gain2 ui->widePlot->setPlot2dGain(value); if(ui->widePlot->scaleOK ()) { ui->widePlot->draw(swide,false,false); - if(m_mode=="QRA64") ui->widePlot->draw(swide,false,true); } } @@ -704,7 +783,6 @@ void WideGraph::on_zero2dSlider_valueChanged(int value) //Zero2 ui->widePlot->setPlot2dZero(value); if(ui->widePlot->scaleOK ()) { ui->widePlot->draw(swide,false,false); - if(m_mode=="QRA64") ui->widePlot->draw(swide,false,true); } } diff --git a/widegraph.h b/widegraph.h index 7596b77..1f2eed9 100644 --- a/widegraph.h +++ b/widegraph.h @@ -2,10 +2,18 @@ #ifndef WIDEGRAPH_H #define WIDEGRAPH_H + +#include +#include +#include + #include #include #include #include +#include +#include +#include #include #include "WFPalette.hpp" @@ -75,12 +83,16 @@ public slots: bool controlsVisible(); void setDrift(int n); void setQSYEnabled(bool enabled); + void setPaused(bool paused){ m_paused = paused; } protected: void keyPressEvent (QKeyEvent *e) override; void closeEvent (QCloseEvent *) override; private slots: + void draw(); + void drawSwide(); + void on_qsyPushButton_clicked(); void on_offsetSpinBox_valueChanged(int n); void on_waterfallAvgSpinBox_valueChanged(int arg1); @@ -141,14 +153,21 @@ private: qint32 m_jz=MAX_SCREENSIZE; qint32 m_n; + bool m_paused; bool m_bFlatten; bool m_bRef; bool m_bHaveTransmitted; //Set true at end of a WSPR transmission + QTimer m_drawTimer; + QMutex m_drawLock; + QString m_rxBand; QString m_mode; QString m_modeTx; QString m_waterfallPalette; + + std::default_random_engine m_gen; + std::normal_distribution m_dist; }; #endif // WIDEGRAPH_H diff --git a/widegraph.ui b/widegraph.ui index e25fb1b..0e0774e 100644 --- a/widegraph.ui +++ b/widegraph.ui @@ -177,8 +177,8 @@ - -3 - -163 + 0 + 0 270 372 @@ -427,9 +427,9 @@ 0 - 0 + -193 267 - 691 + 723 @@ -527,9 +527,28 @@ - Averaging + Scrolling && Averaging + + + + fps + + + Scroll Speed: + + + 1 + + + 100 + + + 10 + + +