From 40bd300bafcea779a0c94fa659270a3821338224 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 7 Oct 2020 21:28:32 +0200 Subject: [PATCH] Channel Analyzer: set GUI sample rate at construction time. Fixes #649 --- plugins/channelrx/chanalyzer/chanalyzer.cpp | 3 +++ .../channelrx/chanalyzer/chanalyzergui.cpp | 12 +++++++--- sdrgui/gui/glscope.cpp | 13 +++++++++++ sdrgui/gui/glscope.h | 2 ++ sdrgui/gui/glspectrum.cpp | 23 +++++++++++++++---- sdrgui/gui/glspectrum.h | 2 ++ 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/plugins/channelrx/chanalyzer/chanalyzer.cpp b/plugins/channelrx/chanalyzer/chanalyzer.cpp index ac3752165..de83c2adf 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzer.cpp @@ -51,6 +51,7 @@ ChannelAnalyzer::ChannelAnalyzer(DeviceAPI *deviceAPI) : ChannelAnalyzer::~ChannelAnalyzer() { + qDebug("ChannelAnalyzer::~ChannelAnalyzer"); m_deviceAPI->removeChannelSinkAPI(this); m_deviceAPI->removeChannelSink(this); @@ -59,6 +60,7 @@ ChannelAnalyzer::~ChannelAnalyzer() } delete m_basebandSink; + qDebug("ChannelAnalyzer::~ChannelAnalyzer: done"); } void ChannelAnalyzer::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) @@ -106,6 +108,7 @@ bool ChannelAnalyzer::handleMessage(const Message& cmd) { DSPSignalNotification& cfg = (DSPSignalNotification&) cmd; m_basebandSampleRate = cfg.getSampleRate(); + qDebug("ChannelAnalyzer::handleMessage: DSPSignalNotification: %d", m_basebandSampleRate); m_centerFrequency = cfg.getCenterFrequency(); DSPSignalNotification *notif = new DSPSignalNotification(cfg); m_basebandSink->getInputMessageQueue()->push(notif); diff --git a/plugins/channelrx/chanalyzer/chanalyzergui.cpp b/plugins/channelrx/chanalyzer/chanalyzergui.cpp index 14f1b8208..dbb6c9e6d 100644 --- a/plugins/channelrx/chanalyzer/chanalyzergui.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzergui.cpp @@ -367,13 +367,15 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceUISet *device ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); + m_scopeVis = new ScopeVis(ui->glScope); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); m_channelAnalyzer = (ChannelAnalyzer*) rxChannel; //new ChannelAnalyzer(m_deviceUISet->m_deviceSourceAPI); m_spectrumVis = m_channelAnalyzer->getSpectrumVis(); m_spectrumVis->setGLSpectrum(ui->glSpectrum); - m_scopeVis = new ScopeVis(ui->glScope); m_spectrumScopeComboVis = new SpectrumScopeComboVis(m_spectrumVis, m_scopeVis); + m_basebandSampleRate = m_channelAnalyzer->getChannelSampleRate(); m_channelAnalyzer->setSampleSink(m_spectrumScopeComboVis); m_channelAnalyzer->setMessageQueueToGUI(getInputMessageQueue()); @@ -424,9 +426,13 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceUISet *device ChannelAnalyzerGUI::~ChannelAnalyzerGUI() { - delete m_scopeVis; - delete m_spectrumScopeComboVis; + qDebug("ChannelAnalyzerGUI::~ChannelAnalyzerGUI"); + ui->glSpectrum->disconnectTimer(); + ui->glScope->disconnectTimer(); delete ui; + delete m_spectrumScopeComboVis; + delete m_scopeVis; + qDebug("ChannelAnalyzerGUI::~ChannelAnalyzerGUI: done"); } int ChannelAnalyzerGUI::getSinkSampleRate() diff --git a/sdrgui/gui/glscope.cpp b/sdrgui/gui/glscope.cpp index d0b81a3df..3050b1d16 100644 --- a/sdrgui/gui/glscope.cpp +++ b/sdrgui/gui/glscope.cpp @@ -46,6 +46,7 @@ GLScope::GLScope(QWidget *parent) : QGLWidget(parent), m_bufferIndex(0), m_displayMode(DisplayX), m_displayPolGrid(false), + m_masterTimer(nullptr), m_dataChanged(0), m_configChanged(false), m_sampleRate(0), @@ -2022,6 +2023,18 @@ void GLScope::connectTimer(const QTimer &timer) disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(tick())); connect(&timer, SIGNAL(timeout()), this, SLOT(tick())); m_timer.stop(); + m_masterTimer = &timer; +} + +void GLScope::disconnectTimer() +{ + qDebug() << "GLScope::disconnectTimer"; + + if (m_masterTimer) { + disconnect(m_masterTimer, SIGNAL(timeout()), this, SLOT(tick())); + } + + m_masterTimer = nullptr; } void GLScope::cleanup() diff --git a/sdrgui/gui/glscope.h b/sdrgui/gui/glscope.h index 928d3047a..598419f44 100644 --- a/sdrgui/gui/glscope.h +++ b/sdrgui/gui/glscope.h @@ -55,6 +55,7 @@ public: virtual ~GLScope(); void connectTimer(const QTimer& timer); + void disconnectTimer(); void setTraces(std::vector* tracesData, std::vector* traces); void newTraces(std::vector* traces, int traceIndex, std::vector* projectionTypes); @@ -145,6 +146,7 @@ private: DisplayMode m_displayMode; bool m_displayPolGrid; QTimer m_timer; + const QTimer *m_masterTimer; QMutex m_mutex; QAtomicInt m_dataChanged; bool m_configChanged; diff --git a/sdrgui/gui/glspectrum.cpp b/sdrgui/gui/glspectrum.cpp index e0df70ed1..d539265d0 100644 --- a/sdrgui/gui/glspectrum.cpp +++ b/sdrgui/gui/glspectrum.cpp @@ -37,6 +37,7 @@ GLSpectrum::GLSpectrum(QWidget* parent) : QGLWidget(parent), m_cursorState(CSNormal), m_cursorChannel(0), + m_masterTimer(nullptr), m_mouseInside(false), m_changesPending(true), m_centerFrequency(100000000), @@ -52,7 +53,7 @@ GLSpectrum::GLSpectrum(QWidget* parent) : m_displayTraceIntensity(50), m_invertedWaterfall(false), m_displayMaxHold(false), - m_currentSpectrum(0), + m_currentSpectrum(nullptr), m_displayCurrent(false), m_leftMargin(0), m_rightMargin(0), @@ -61,22 +62,22 @@ GLSpectrum::GLSpectrum(QWidget* parent) : m_waterfallHeight(0), m_frequencyScaleHeight(0), m_bottomMargin(0), - m_waterfallBuffer(0), + m_waterfallBuffer(nullptr), m_waterfallBufferPos(0), m_waterfallTextureHeight(-1), m_waterfallTexturePos(0), m_displayWaterfall(true), m_ssbSpectrum(false), m_lsbDisplay(false), - m_histogramBuffer(0), - m_histogram(0), + m_histogramBuffer(nullptr), + m_histogram(nullptr), m_displayHistogram(true), m_displayChanged(false), m_displaySourceOrSink(true), m_displayStreamIndex(0), m_matrixLoc(0), m_colorLoc(0), - m_messageQueueToGUI(0) + m_messageQueueToGUI(nullptr) { setAutoFillBackground(false); setAttribute(Qt::WA_OpaquePaintEvent, true); @@ -2281,9 +2282,21 @@ void GLSpectrum::connectTimer(const QTimer& timer) qDebug() << "GLSpectrum::connectTimer"; disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(tick())); connect(&timer, SIGNAL(timeout()), this, SLOT(tick())); + m_masterTimer = &timer; m_timer.stop(); } +void GLSpectrum::disconnectTimer() +{ + qDebug() << "GLScope::disconnectTimer"; + + if (m_masterTimer) { + disconnect(m_masterTimer, SIGNAL(timeout()), this, SLOT(tick())); + } + + m_masterTimer = nullptr; +} + void GLSpectrum::cleanup() { //makeCurrent(); diff --git a/sdrgui/gui/glspectrum.h b/sdrgui/gui/glspectrum.h index 2d6369ccc..d9e31ce67 100644 --- a/sdrgui/gui/glspectrum.h +++ b/sdrgui/gui/glspectrum.h @@ -108,6 +108,7 @@ public: Real getWaterfallShare() const { return m_waterfallShare; } void setWaterfallShare(Real waterfallShare); void connectTimer(const QTimer& timer); + void disconnectTimer(); void setDisplayedStream(bool sourceOrSink, int streamIndex) { @@ -235,6 +236,7 @@ private: int m_cursorChannel; QTimer m_timer; + const QTimer *m_masterTimer; QMutex m_mutex; bool m_mouseInside; bool m_changesPending;