diff --git a/plugins/channelmimo/doa2/doa2.cpp b/plugins/channelmimo/doa2/doa2.cpp index 555823380..0c73faea5 100644 --- a/plugins/channelmimo/doa2/doa2.cpp +++ b/plugins/channelmimo/doa2/doa2.cpp @@ -695,3 +695,8 @@ double DOA2::normalizeAngle(double angle, double max) if (angle > max) { return angle - max; } return angle; } + +int DOA2::getChannelSampleRate() const +{ + return static_cast(m_deviceSampleRate / (1 << m_settings.m_log2Decim)); +} diff --git a/plugins/channelmimo/doa2/doa2.h b/plugins/channelmimo/doa2/doa2.h index 4685cf328..bdb40add5 100644 --- a/plugins/channelmimo/doa2/doa2.h +++ b/plugins/channelmimo/doa2/doa2.h @@ -108,6 +108,7 @@ public: QString getIdentifier() const final { return objectName(); } void getTitle(QString& title) final { title = "DOA 2 sources"; } qint64 getCenterFrequency() const final { return m_frequencyOffset; } + int getChannelSampleRate() const override; void setCenterFrequency(qint64) final { /* Not for MIMO */ } uint32_t getDeviceSampleRate() const { return m_deviceSampleRate; } diff --git a/plugins/channelrx/chanalyzer/chanalyzer.cpp b/plugins/channelrx/chanalyzer/chanalyzer.cpp index f49e656ac..bc49996c5 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzer.cpp @@ -54,8 +54,7 @@ ChannelAnalyzer::ChannelAnalyzer(DeviceAPI *deviceAPI) : qDebug("ChannelAnalyzer::ChannelAnalyzer"); setObjectName(m_channelId); m_thread.setObjectName("Channelyzer"); - - getChannelSampleRate(); + getBasebandSampleRate(); m_basebandSink = new ChannelAnalyzerBaseband(); m_basebandSink->moveToThread(&m_thread); @@ -118,7 +117,7 @@ uint32_t ChannelAnalyzer::getNumberOfDeviceStreams() const return m_deviceAPI->getNbSourceStreams(); } -int ChannelAnalyzer::getChannelSampleRate() +int ChannelAnalyzer::getBasebandSampleRate() { DeviceSampleSource *source = m_deviceAPI->getSampleSource(); @@ -726,3 +725,8 @@ void ChannelAnalyzer::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int ChannelAnalyzer::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/chanalyzer/chanalyzer.h b/plugins/channelrx/chanalyzer/chanalyzer.h index 831ec78cc..77b6ba94d 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.h +++ b/plugins/channelrx/chanalyzer/chanalyzer.h @@ -75,7 +75,7 @@ public: SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } ScopeVis *getScopeVis() { return &m_scopeVis; } void setScopeVis(ScopeVis *scopeVis) { m_basebandSink->setScopeVis(scopeVis); } - int getChannelSampleRate(); + int getBasebandSampleRate(); //!< Updates and returns the device (baseband) sample rate int getDecimation() const { return 1<getMagSq(); } double getMagSqAvg() const { return m_basebandSink->getMagSqAvg(); } @@ -95,6 +95,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = objectName(); } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const { return QByteArray(); } diff --git a/plugins/channelrx/chanalyzer/chanalyzergui.cpp b/plugins/channelrx/chanalyzer/chanalyzergui.cpp index 6c95dce83..45a7044ce 100644 --- a/plugins/channelrx/chanalyzer/chanalyzergui.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzergui.cpp @@ -313,7 +313,7 @@ void ChannelAnalyzerGUI::tick() if (ui->pll->isChecked()) { - double sampleRate = (double) m_channelAnalyzer->getChannelSampleRate(); + double sampleRate = (double) m_channelAnalyzer->getBasebandSampleRate(); int freq = (m_channelAnalyzer->getPllFrequency() * sampleRate) / (2.0*M_PI); ui->pll->setToolTip(tr("PLL lock. Freq = %1 Hz").arg(freq)); ui->pllLockFrequency->setText(tr("%1 Hz").arg(freq)); @@ -548,13 +548,13 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceUISet *device connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); m_channelAnalyzer = (ChannelAnalyzer*) rxChannel; - m_basebandSampleRate = m_channelAnalyzer->getChannelSampleRate(); + m_basebandSampleRate = m_channelAnalyzer->getBasebandSampleRate(); qDebug("ChannelAnalyzerGUI::ChannelAnalyzerGUI: m_basebandSampleRate: %d", m_basebandSampleRate); m_spectrumVis = m_channelAnalyzer->getSpectrumVis(); m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_scopeVis = m_channelAnalyzer->getScopeVis(); m_scopeVis->setGLScope(ui->glScope); - m_basebandSampleRate = m_channelAnalyzer->getChannelSampleRate(); + m_basebandSampleRate = m_channelAnalyzer->getBasebandSampleRate(); m_scopeVis->setSpectrumVis(m_spectrumVis); m_channelAnalyzer->setScopeVis(m_scopeVis); m_channelAnalyzer->setMessageQueueToGUI(getInputMessageQueue()); diff --git a/plugins/channelrx/channelpower/channelpower.cpp b/plugins/channelrx/channelpower/channelpower.cpp index 32e0579a4..d87a0c386 100644 --- a/plugins/channelrx/channelpower/channelpower.cpp +++ b/plugins/channelrx/channelpower/channelpower.cpp @@ -564,3 +564,7 @@ void ChannelPower::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); } +int ChannelPower::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/channelpower/channelpower.h b/plugins/channelrx/channelpower/channelpower.h index 07ab73e4d..b2e7307c5 100644 --- a/plugins/channelrx/channelpower/channelpower.h +++ b/plugins/channelrx/channelpower/channelpower.h @@ -86,6 +86,7 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodadsb/adsbdemod.cpp b/plugins/channelrx/demodadsb/adsbdemod.cpp index 78085f698..eb67c05d0 100644 --- a/plugins/channelrx/demodadsb/adsbdemod.cpp +++ b/plugins/channelrx/demodadsb/adsbdemod.cpp @@ -808,3 +808,8 @@ void ADSBDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int ADSBDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodadsb/adsbdemod.h b/plugins/channelrx/demodadsb/adsbdemod.h index 7820c341d..dcffce39c 100644 --- a/plugins/channelrx/demodadsb/adsbdemod.h +++ b/plugins/channelrx/demodadsb/adsbdemod.h @@ -129,6 +129,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodais/aisdemod.cpp b/plugins/channelrx/demodais/aisdemod.cpp index 156fa8d97..110193814 100644 --- a/plugins/channelrx/demodais/aisdemod.cpp +++ b/plugins/channelrx/demodais/aisdemod.cpp @@ -752,3 +752,13 @@ void AISDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int AISDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} + +int AISDemod::getAudioSampleRate() const +{ + return AISDemodSettings::AISDEMOD_CHANNEL_SAMPLE_RATE; +} diff --git a/plugins/channelrx/demodais/aisdemod.h b/plugins/channelrx/demodais/aisdemod.h index d92829531..6afdcb6c9 100644 --- a/plugins/channelrx/demodais/aisdemod.h +++ b/plugins/channelrx/demodais/aisdemod.h @@ -121,6 +121,8 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodam/amdemod.cpp b/plugins/channelrx/demodam/amdemod.cpp index feaf22aea..5fae85e75 100644 --- a/plugins/channelrx/demodam/amdemod.cpp +++ b/plugins/channelrx/demodam/amdemod.cpp @@ -158,6 +158,7 @@ void AMDemod::stop() m_running = false; m_thread->quit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool AMDemod::handleMessage(const Message& cmd) @@ -718,3 +719,8 @@ void AMDemod::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); m_basebandSink->setAudioFifoLabel(fifoLabel); } + +int AMDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodam/amdemod.h b/plugins/channelrx/demodam/amdemod.h index 99e97fd2e..c6b849535 100644 --- a/plugins/channelrx/demodam/amdemod.h +++ b/plugins/channelrx/demodam/amdemod.h @@ -84,6 +84,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -127,7 +128,7 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); - uint32_t getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } bool getSquelchOpen() const { return m_running ? m_basebandSink->getSquelchOpen() : false; } bool getPllLocked() const { return m_settings.m_pll && m_running && m_basebandSink->getPllLocked(); } diff --git a/plugins/channelrx/demodatv/atvdemod.cpp b/plugins/channelrx/demodatv/atvdemod.cpp index 6f7410631..a99e8db78 100644 --- a/plugins/channelrx/demodatv/atvdemod.cpp +++ b/plugins/channelrx/demodatv/atvdemod.cpp @@ -210,3 +210,8 @@ void ATVDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int ATVDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodatv/atvdemod.h b/plugins/channelrx/demodatv/atvdemod.h index 2f2b82aec..a2612fbb4 100644 --- a/plugins/channelrx/demodatv/atvdemod.h +++ b/plugins/channelrx/demodatv/atvdemod.h @@ -80,6 +80,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = objectName(); } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const { return QByteArray(); } diff --git a/plugins/channelrx/demodbfm/bfmdemod.cpp b/plugins/channelrx/demodbfm/bfmdemod.cpp index bd1dcbe66..f1ded1896 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.cpp +++ b/plugins/channelrx/demodbfm/bfmdemod.cpp @@ -164,6 +164,7 @@ void BFMDemod::stop() m_running = false; m_thread->quit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool BFMDemod::handleMessage(const Message& cmd) @@ -762,3 +763,8 @@ void BFMDemod::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); m_basebandSink->setAudioFifoLabel(fifoLabel); } + +int BFMDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodbfm/bfmdemod.h b/plugins/channelrx/demodbfm/bfmdemod.h index c1e0f1b7f..9efccb38f 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.h +++ b/plugins/channelrx/demodbfm/bfmdemod.h @@ -91,6 +91,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -117,7 +118,7 @@ public: Real getDemodAcc() const { return m_running ? m_basebandSink->getDemodAcc() : 0.0f; } Real getDemodQua() const { return m_running ? m_basebandSink->getDemodQua() : 0.0f; } Real getDemodFclk() const { return m_running ? m_basebandSink->getDemodFclk() : 0.0f; } - int getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } void getMagSqLevels(double& avg, double& peak, int& nbSamples) { if (m_running) { diff --git a/plugins/channelrx/demodchirpchat/chirpchatdemod.cpp b/plugins/channelrx/demodchirpchat/chirpchatdemod.cpp index d8dbf8e12..25012617a 100644 --- a/plugins/channelrx/demodchirpchat/chirpchatdemod.cpp +++ b/plugins/channelrx/demodchirpchat/chirpchatdemod.cpp @@ -185,6 +185,7 @@ void ChirpChatDemod::stop() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished m_decoderThread->exit(); m_decoderThread->wait(); m_decoderThread = nullptr; @@ -1096,3 +1097,8 @@ void ChirpChatDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int ChirpChatDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodchirpchat/chirpchatdemod.h b/plugins/channelrx/demodchirpchat/chirpchatdemod.h index cf97446e8..8020f0345 100644 --- a/plugins/channelrx/demodchirpchat/chirpchatdemod.h +++ b/plugins/channelrx/demodchirpchat/chirpchatdemod.h @@ -86,6 +86,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demoddab/dabdemod.cpp b/plugins/channelrx/demoddab/dabdemod.cpp index da489a8d8..69f37b864 100644 --- a/plugins/channelrx/demoddab/dabdemod.cpp +++ b/plugins/channelrx/demoddab/dabdemod.cpp @@ -918,3 +918,8 @@ void DABDemod::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); m_basebandSink->setAudioFifoLabel(fifoLabel); } + +int DABDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demoddab/dabdemod.h b/plugins/channelrx/demoddab/dabdemod.h index 370656760..cb18acc9d 100644 --- a/plugins/channelrx/demoddab/dabdemod.h +++ b/plugins/channelrx/demoddab/dabdemod.h @@ -353,6 +353,7 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -403,7 +404,7 @@ public: } uint32_t getNumberOfDeviceStreams() const; - int getAudioSampleRate() const { return m_basebandSink->getAudioSampleRate(); } + int getAudioSampleRate() const override { return m_basebandSink->getAudioSampleRate(); } static const char * const m_channelIdURI; static const char * const m_channelId; diff --git a/plugins/channelrx/demoddatv/datvdemod.cpp b/plugins/channelrx/demoddatv/datvdemod.cpp index 54bda4c82..8bf34b029 100644 --- a/plugins/channelrx/demoddatv/datvdemod.cpp +++ b/plugins/channelrx/demoddatv/datvdemod.cpp @@ -723,3 +723,8 @@ void DATVDemod::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); m_basebandSink->setAudioFifoLabel(fifoLabel); } + +int DATVDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demoddatv/datvdemod.h b/plugins/channelrx/demoddatv/datvdemod.h index dbe46e2b8..0b73ddaf7 100644 --- a/plugins/channelrx/demoddatv/datvdemod.h +++ b/plugins/channelrx/demoddatv/datvdemod.h @@ -51,6 +51,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = objectName(); } virtual qint64 getCenterFrequency() const { return m_settings.m_centerFrequency; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const { return QByteArray(); } diff --git a/plugins/channelrx/demoddsc/dscdemod.cpp b/plugins/channelrx/demoddsc/dscdemod.cpp index 6c0beae46..cc71264f6 100644 --- a/plugins/channelrx/demoddsc/dscdemod.cpp +++ b/plugins/channelrx/demoddsc/dscdemod.cpp @@ -761,3 +761,13 @@ void DSCDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int DSCDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} + +int DSCDemod::getAudioSampleRate() const +{ + return DSCDemodSettings::DSCDEMOD_CHANNEL_SAMPLE_RATE; +} diff --git a/plugins/channelrx/demoddsc/dscdemod.h b/plugins/channelrx/demoddsc/dscdemod.h index b374aa66c..56439c526 100644 --- a/plugins/channelrx/demoddsc/dscdemod.h +++ b/plugins/channelrx/demoddsc/dscdemod.h @@ -117,6 +117,8 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demoddsd/dsddemod.cpp b/plugins/channelrx/demoddsd/dsddemod.cpp index 9994413d4..ee579bce6 100644 --- a/plugins/channelrx/demoddsd/dsddemod.cpp +++ b/plugins/channelrx/demoddsd/dsddemod.cpp @@ -61,6 +61,7 @@ const int DSDDemod::m_udpBlockSize = 512; DSDDemod::DSDDemod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), m_deviceAPI(deviceAPI), + m_basebandSink(nullptr), m_running(false), m_basebandSampleRate(0), m_centerFrequency(0), @@ -203,6 +204,7 @@ void DSDDemod::stop() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } void DSDDemod::setScopeXYSink(BasebandSampleSink* sampleSink) @@ -921,3 +923,8 @@ void DSDDemod::handleFeatureRemoved(int featureSetIndex, Feature *feature) notifyUpdateAMBEFeatures(); } } + +int DSDDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demoddsd/dsddemod.h b/plugins/channelrx/demoddsd/dsddemod.h index a9973445e..ce995627f 100644 --- a/plugins/channelrx/demoddsd/dsddemod.h +++ b/plugins/channelrx/demoddsd/dsddemod.h @@ -117,6 +117,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -177,7 +178,7 @@ public: } const char *updateAndGetStatusText() { return m_running ? m_basebandSink->updateAndGetStatusText() : nullptr; } - int getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } bool isRunning() { return m_running; } static const char* const m_channelIdURI; diff --git a/plugins/channelrx/demodendoftrain/endoftraindemod.cpp b/plugins/channelrx/demodendoftrain/endoftraindemod.cpp index f3444cab9..86c8054c5 100644 --- a/plugins/channelrx/demodendoftrain/endoftraindemod.cpp +++ b/plugins/channelrx/demodendoftrain/endoftraindemod.cpp @@ -700,3 +700,13 @@ void EndOfTrainDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int EndOfTrainDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} + +int EndOfTrainDemod::getAudioSampleRate() const +{ + return EndOfTrainDemodSettings::CHANNEL_SAMPLE_RATE; +} diff --git a/plugins/channelrx/demodendoftrain/endoftraindemod.h b/plugins/channelrx/demodendoftrain/endoftraindemod.h index 88f2b2278..4ed9e04d2 100644 --- a/plugins/channelrx/demodendoftrain/endoftraindemod.h +++ b/plugins/channelrx/demodendoftrain/endoftraindemod.h @@ -88,6 +88,8 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodfreedv/freedvdemod.cpp b/plugins/channelrx/demodfreedv/freedvdemod.cpp index 7e1fda8d6..f4ca85a6d 100644 --- a/plugins/channelrx/demodfreedv/freedvdemod.cpp +++ b/plugins/channelrx/demodfreedv/freedvdemod.cpp @@ -656,3 +656,8 @@ void FreeDVDemod::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); m_basebandSink->setAudioFifoLabel(fifoLabel); } + +int FreeDVDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodfreedv/freedvdemod.h b/plugins/channelrx/demodfreedv/freedvdemod.h index c5678d318..e5d3299fe 100644 --- a/plugins/channelrx/demodfreedv/freedvdemod.h +++ b/plugins/channelrx/demodfreedv/freedvdemod.h @@ -98,6 +98,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -114,7 +115,7 @@ public: return m_settings.m_inputFrequencyOffset; } - int getAudioSampleRate() const { return m_basebandSink->getAudioSampleRate(); } + int getAudioSampleRate() const override { return m_basebandSink->getAudioSampleRate(); } uint32_t getModemSampleRate() const { return m_basebandSink->getModemSampleRate(); } double getMagSq() const { return m_basebandSink->getMagSq(); } bool getAudioActive() const { return m_basebandSink->getAudioActive(); } diff --git a/plugins/channelrx/demodft8/ft8demod.cpp b/plugins/channelrx/demodft8/ft8demod.cpp index 412dd26ad..e08287b1c 100644 --- a/plugins/channelrx/demodft8/ft8demod.cpp +++ b/plugins/channelrx/demodft8/ft8demod.cpp @@ -56,6 +56,7 @@ const char* const FT8Demod::m_channelId = "FT8Demod"; FT8Demod::FT8Demod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), m_deviceAPI(deviceAPI), + m_basebandSink(nullptr), m_running(false), m_spectrumVis(SDR_RX_SCALEF), m_basebandSampleRate(0), @@ -206,6 +207,7 @@ void FT8Demod::stop() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool FT8Demod::handleMessage(const Message& cmd) @@ -860,3 +862,8 @@ void FT8Demod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int FT8Demod::getAudioSampleRate() const +{ + return FT8DemodSettings::m_ft8SampleRate; +} diff --git a/plugins/channelrx/demodft8/ft8demod.h b/plugins/channelrx/demodft8/ft8demod.h index af1e27263..3079e924f 100644 --- a/plugins/channelrx/demodft8/ft8demod.h +++ b/plugins/channelrx/demodft8/ft8demod.h @@ -88,6 +88,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -106,7 +107,7 @@ public: void setDeviceCenterFrequency(qint64 centerFrequency, int index); void setMessageQueueToGUI(MessageQueue* queue) final; - uint32_t getChannelSampleRate() const { return m_running ? m_basebandSink->getChannelSampleRate() : 0; } + int getChannelSampleRate() const override { return m_running ? m_basebandSink->getChannelSampleRate() : 0; } double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } void getMagSqLevels(double& avg, double& peak, int& nbSamples) diff --git a/plugins/channelrx/demodils/ilsdemod.cpp b/plugins/channelrx/demodils/ilsdemod.cpp index 2d5f69eff..147aa8604 100644 --- a/plugins/channelrx/demodils/ilsdemod.cpp +++ b/plugins/channelrx/demodils/ilsdemod.cpp @@ -919,3 +919,8 @@ void ILSDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int ILSDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodils/ilsdemod.h b/plugins/channelrx/demodils/ilsdemod.h index 686a2dc9b..e32b418e9 100644 --- a/plugins/channelrx/demodils/ilsdemod.h +++ b/plugins/channelrx/demodils/ilsdemod.h @@ -130,6 +130,7 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -175,7 +176,7 @@ public: SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } ScopeVis *getScopeSink(); - uint32_t getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } bool getSquelchOpen() const { return m_running ? m_basebandSink->getSquelchOpen() : false; } double getMagSq() const { return m_basebandSink->getMagSq(); } diff --git a/plugins/channelrx/demodinmarsat/inmarsatdemod.cpp b/plugins/channelrx/demodinmarsat/inmarsatdemod.cpp index 845859c4c..da1b937a3 100644 --- a/plugins/channelrx/demodinmarsat/inmarsatdemod.cpp +++ b/plugins/channelrx/demodinmarsat/inmarsatdemod.cpp @@ -694,3 +694,13 @@ void InmarsatDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int InmarsatDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} + +int InmarsatDemod::getAudioSampleRate() const +{ + return InmarsatDemodSettings::CHANNEL_SAMPLE_RATE; +} diff --git a/plugins/channelrx/demodinmarsat/inmarsatdemod.h b/plugins/channelrx/demodinmarsat/inmarsatdemod.h index 6e934edec..35c2c8933 100644 --- a/plugins/channelrx/demodinmarsat/inmarsatdemod.h +++ b/plugins/channelrx/demodinmarsat/inmarsatdemod.h @@ -86,6 +86,8 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodm17/m17demod.cpp b/plugins/channelrx/demodm17/m17demod.cpp index e30f4fd46..d912ea615 100644 --- a/plugins/channelrx/demodm17/m17demod.cpp +++ b/plugins/channelrx/demodm17/m17demod.cpp @@ -166,6 +166,7 @@ void M17Demod::stop() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool M17Demod::handleMessage(const Message& cmd) @@ -762,3 +763,8 @@ void M17Demod::setScopeXYSink(BasebandSampleSink* sampleSink) m_basebandSink->setScopeXYSink(sampleSink); } } + +int M17Demod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodm17/m17demod.h b/plugins/channelrx/demodm17/m17demod.h index 7225c1791..354c5a841 100644 --- a/plugins/channelrx/demodm17/m17demod.h +++ b/plugins/channelrx/demodm17/m17demod.h @@ -170,6 +170,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -228,7 +229,7 @@ public: } } - int getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } bool isRunning() { return m_running; } void getDiagnostics( diff --git a/plugins/channelrx/demodmeshcore/meshcoredemod.cpp b/plugins/channelrx/demodmeshcore/meshcoredemod.cpp index 33f188cd8..6175f025f 100644 --- a/plugins/channelrx/demodmeshcore/meshcoredemod.cpp +++ b/plugins/channelrx/demodmeshcore/meshcoredemod.cpp @@ -1757,3 +1757,8 @@ void MeshcoreDemod::handleIndexInDeviceSetChanged(int index) runtime.basebandSink->setFifoLabel(fifoLabel); } } + +int MeshcoreDemod::getChannelSampleRate() const +{ + return m_pipelines.empty() || !m_pipelines[0].basebandSink ? 0 : m_pipelines[0].basebandSink->getChannelSampleRate(); +} diff --git a/plugins/channelrx/demodmeshcore/meshcoredemod.h b/plugins/channelrx/demodmeshcore/meshcoredemod.h index 9d64280ed..45633b368 100644 --- a/plugins/channelrx/demodmeshcore/meshcoredemod.h +++ b/plugins/channelrx/demodmeshcore/meshcoredemod.h @@ -106,6 +106,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp b/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp index 06db1daaf..e54011d6c 100644 --- a/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp +++ b/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp @@ -1687,3 +1687,8 @@ void MeshtasticDemod::handleIndexInDeviceSetChanged(int index) runtime.basebandSink->setFifoLabel(fifoLabel); } } + +int MeshtasticDemod::getChannelSampleRate() const +{ + return m_pipelines.empty() || !m_pipelines[0].basebandSink ? 0 : m_pipelines[0].basebandSink->getChannelSampleRate(); +} diff --git a/plugins/channelrx/demodmeshtastic/meshtasticdemod.h b/plugins/channelrx/demodmeshtastic/meshtasticdemod.h index 919a9b59d..1cb83e0b4 100644 --- a/plugins/channelrx/demodmeshtastic/meshtasticdemod.h +++ b/plugins/channelrx/demodmeshtastic/meshtasticdemod.h @@ -106,6 +106,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodnavtex/navtexdemod.cpp b/plugins/channelrx/demodnavtex/navtexdemod.cpp index 8594f7044..5f7fb4e37 100644 --- a/plugins/channelrx/demodnavtex/navtexdemod.cpp +++ b/plugins/channelrx/demodnavtex/navtexdemod.cpp @@ -750,3 +750,13 @@ void NavtexDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int NavtexDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} + +int NavtexDemod::getAudioSampleRate() const +{ + return NavtexDemodSettings::NAVTEXDEMOD_CHANNEL_SAMPLE_RATE; +} diff --git a/plugins/channelrx/demodnavtex/navtexdemod.h b/plugins/channelrx/demodnavtex/navtexdemod.h index 20956f09a..cba280306 100644 --- a/plugins/channelrx/demodnavtex/navtexdemod.h +++ b/plugins/channelrx/demodnavtex/navtexdemod.h @@ -137,6 +137,8 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodnfm/nfmdemod.cpp b/plugins/channelrx/demodnfm/nfmdemod.cpp index cd1814476..b9583d581 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.cpp +++ b/plugins/channelrx/demodnfm/nfmdemod.cpp @@ -174,6 +174,7 @@ void NFMDemod::stop() m_running = false; m_thread->quit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool NFMDemod::handleMessage(const Message& cmd) @@ -722,3 +723,8 @@ void NFMDemod::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); m_basebandSink->setAudioFifoLabel(fifoLabel); } + +int NFMDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodnfm/nfmdemod.h b/plugins/channelrx/demodnfm/nfmdemod.h index a88576759..7de9aa670 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.h +++ b/plugins/channelrx/demodnfm/nfmdemod.h @@ -84,6 +84,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -138,7 +139,7 @@ public: } } - int getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demodpacket/packetdemod.cpp b/plugins/channelrx/demodpacket/packetdemod.cpp index 1f1ef5ae3..f249a6d0a 100644 --- a/plugins/channelrx/demodpacket/packetdemod.cpp +++ b/plugins/channelrx/demodpacket/packetdemod.cpp @@ -716,3 +716,13 @@ void PacketDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int PacketDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} + +int PacketDemod::getAudioSampleRate() const +{ + return PacketDemodSettings::PACKETDEMOD_CHANNEL_SAMPLE_RATE; +} diff --git a/plugins/channelrx/demodpacket/packetdemod.h b/plugins/channelrx/demodpacket/packetdemod.h index 043d78da4..e078e524c 100644 --- a/plugins/channelrx/demodpacket/packetdemod.h +++ b/plugins/channelrx/demodpacket/packetdemod.h @@ -89,6 +89,8 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodpager/pagerdemod.cpp b/plugins/channelrx/demodpager/pagerdemod.cpp index a37be646d..73a0fc24c 100644 --- a/plugins/channelrx/demodpager/pagerdemod.cpp +++ b/plugins/channelrx/demodpager/pagerdemod.cpp @@ -724,3 +724,13 @@ void PagerDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int PagerDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} + +int PagerDemod::getAudioSampleRate() const +{ + return PagerDemodSettings::m_channelSampleRate; +} diff --git a/plugins/channelrx/demodpager/pagerdemod.h b/plugins/channelrx/demodpager/pagerdemod.h index 0f55c4cc2..9bd410b77 100644 --- a/plugins/channelrx/demodpager/pagerdemod.h +++ b/plugins/channelrx/demodpager/pagerdemod.h @@ -149,6 +149,8 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodradiosonde/radiosondedemod.cpp b/plugins/channelrx/demodradiosonde/radiosondedemod.cpp index b6fde1014..bb8bab047 100644 --- a/plugins/channelrx/demodradiosonde/radiosondedemod.cpp +++ b/plugins/channelrx/demodradiosonde/radiosondedemod.cpp @@ -768,3 +768,13 @@ void RadiosondeDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int RadiosondeDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} + +int RadiosondeDemod::getAudioSampleRate() const +{ + return RadiosondeDemodSettings::RADIOSONDEDEMOD_CHANNEL_SAMPLE_RATE; +} diff --git a/plugins/channelrx/demodradiosonde/radiosondedemod.h b/plugins/channelrx/demodradiosonde/radiosondedemod.h index 90daacce7..a23431d08 100644 --- a/plugins/channelrx/demodradiosonde/radiosondedemod.h +++ b/plugins/channelrx/demodradiosonde/radiosondedemod.h @@ -124,6 +124,8 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodrtty/rttydemod.cpp b/plugins/channelrx/demodrtty/rttydemod.cpp index 15b92fd84..d08906664 100644 --- a/plugins/channelrx/demodrtty/rttydemod.cpp +++ b/plugins/channelrx/demodrtty/rttydemod.cpp @@ -795,3 +795,13 @@ void RttyDemod::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int RttyDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} + +int RttyDemod::getAudioSampleRate() const +{ + return RttyDemodSettings::RTTYDEMOD_CHANNEL_SAMPLE_RATE; +} diff --git a/plugins/channelrx/demodrtty/rttydemod.h b/plugins/channelrx/demodrtty/rttydemod.h index 518566392..9ab1b0de0 100644 --- a/plugins/channelrx/demodrtty/rttydemod.h +++ b/plugins/channelrx/demodrtty/rttydemod.h @@ -131,6 +131,8 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/demodssb/ssbdemod.cpp b/plugins/channelrx/demodssb/ssbdemod.cpp index da2d99eb6..626636b1e 100644 --- a/plugins/channelrx/demodssb/ssbdemod.cpp +++ b/plugins/channelrx/demodssb/ssbdemod.cpp @@ -191,6 +191,7 @@ void SSBDemod::stop() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool SSBDemod::handleMessage(const Message& cmd) diff --git a/plugins/channelrx/demodssb/ssbdemod.h b/plugins/channelrx/demodssb/ssbdemod.h index 5da17ba36..d535d9e8c 100644 --- a/plugins/channelrx/demodssb/ssbdemod.h +++ b/plugins/channelrx/demodssb/ssbdemod.h @@ -105,8 +105,8 @@ public: } void setMessageQueueToGUI(MessageQueue* queue) final; - uint32_t getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } - uint32_t getChannelSampleRate() const { return m_running ? m_basebandSink->getChannelSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getChannelSampleRate() const override { return m_running ? m_basebandSink->getChannelSampleRate() : 0; } double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } bool getAudioActive() const { return m_running && m_basebandSink->getAudioActive(); } diff --git a/plugins/channelrx/demodvor/vordemod.cpp b/plugins/channelrx/demodvor/vordemod.cpp index 70ce88c95..774969cd7 100644 --- a/plugins/channelrx/demodvor/vordemod.cpp +++ b/plugins/channelrx/demodvor/vordemod.cpp @@ -165,6 +165,7 @@ void VORDemod::stop() m_basebandSink->stopWork(); m_thread->quit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool VORDemod::handleMessage(const Message& cmd) diff --git a/plugins/channelrx/demodvor/vordemod.h b/plugins/channelrx/demodvor/vordemod.h index d94774bfa..9b36fdbe2 100644 --- a/plugins/channelrx/demodvor/vordemod.h +++ b/plugins/channelrx/demodvor/vordemod.h @@ -129,7 +129,7 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); - uint32_t getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } bool getSquelchOpen() const { return m_running ? m_basebandSink->getSquelchOpen() : false; } diff --git a/plugins/channelrx/demodvormc/vordemodmc.h b/plugins/channelrx/demodvormc/vordemodmc.h index febc6c95e..07088b67b 100644 --- a/plugins/channelrx/demodvormc/vordemodmc.h +++ b/plugins/channelrx/demodvormc/vordemodmc.h @@ -118,7 +118,7 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); - uint32_t getAudioSampleRate() const { return m_basebandSink->getAudioSampleRate(); } + int getAudioSampleRate() const override { return m_basebandSink->getAudioSampleRate(); } double getMagSq() const { return m_basebandSink->getMagSq(); } bool getSquelchOpen() const { return m_basebandSink->getSquelchOpen(); } diff --git a/plugins/channelrx/demodwfm/wfmdemod.cpp b/plugins/channelrx/demodwfm/wfmdemod.cpp index ca2a613f0..7776642fc 100644 --- a/plugins/channelrx/demodwfm/wfmdemod.cpp +++ b/plugins/channelrx/demodwfm/wfmdemod.cpp @@ -162,6 +162,7 @@ void WFMDemod::stop() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool WFMDemod::handleMessage(const Message& cmd) @@ -663,3 +664,8 @@ void WFMDemod::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); m_basebandSink->setAudioFifoLabel(fifoLabel); } + +int WFMDemod::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/demodwfm/wfmdemod.h b/plugins/channelrx/demodwfm/wfmdemod.h index 5176a0e98..029d8f0a1 100644 --- a/plugins/channelrx/demodwfm/wfmdemod.h +++ b/plugins/channelrx/demodwfm/wfmdemod.h @@ -84,6 +84,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -102,7 +103,7 @@ public: double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } bool getSquelchOpen() const { return m_running && m_basebandSink->getSquelchOpen(); } - int getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } QDateTime getAudioFifoErrorDateTime() const { return m_running ? m_basebandSink->getAudioFifoErrorDateTime() : QDateTime(); } void getMagSqLevels(double& avg, double& peak, int& nbSamples) diff --git a/plugins/channelrx/filesink/filesink.cpp b/plugins/channelrx/filesink/filesink.cpp index f9e7d0945..87c1cd9d6 100644 --- a/plugins/channelrx/filesink/filesink.cpp +++ b/plugins/channelrx/filesink/filesink.cpp @@ -54,6 +54,7 @@ const char* const FileSink::m_channelId = "FileSink"; FileSink::FileSink(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), m_deviceAPI(deviceAPI), + m_basebandSink(nullptr), m_running(false), m_spectrumVis(SDR_RX_SCALEF), m_centerFrequency(0), @@ -207,6 +208,7 @@ void FileSink::stop() m_thread->quit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished if (getMessageQueueToGUI()) { @@ -834,3 +836,8 @@ void FileSink::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int FileSink::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/filesink/filesink.h b/plugins/channelrx/filesink/filesink.h index e1c4522cf..95712a242 100644 --- a/plugins/channelrx/filesink/filesink.h +++ b/plugins/channelrx/filesink/filesink.h @@ -103,6 +103,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = "File Sink"; } virtual qint64 getCenterFrequency() const { return m_frequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64) {} virtual QByteArray serialize() const; diff --git a/plugins/channelrx/freqscanner/freqscanner.cpp b/plugins/channelrx/freqscanner/freqscanner.cpp index fda833270..f02972633 100644 --- a/plugins/channelrx/freqscanner/freqscanner.cpp +++ b/plugins/channelrx/freqscanner/freqscanner.cpp @@ -202,6 +202,7 @@ void FreqScanner::stop() m_thread->exit(); #ifndef __EMSCRIPTEN__ m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished #endif } @@ -1456,3 +1457,8 @@ void FreqScanner::notifyUpdateChannels(const QStringList& renameFrom, const QStr getMessageQueueToGUI()->push(msgToGUI); } } + +int FreqScanner::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/freqscanner/freqscanner.h b/plugins/channelrx/freqscanner/freqscanner.h index 3ec017bcb..2d21524ab 100644 --- a/plugins/channelrx/freqscanner/freqscanner.h +++ b/plugins/channelrx/freqscanner/freqscanner.h @@ -325,6 +325,7 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/freqtracker/freqtracker.cpp b/plugins/channelrx/freqtracker/freqtracker.cpp index b614e641b..86c814578 100644 --- a/plugins/channelrx/freqtracker/freqtracker.cpp +++ b/plugins/channelrx/freqtracker/freqtracker.cpp @@ -161,6 +161,7 @@ void FreqTracker::stop() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool FreqTracker::handleMessage(const Message& cmd) @@ -709,3 +710,8 @@ void FreqTracker::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int FreqTracker::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/freqtracker/freqtracker.h b/plugins/channelrx/freqtracker/freqtracker.h index 86ad77be3..61416d618 100644 --- a/plugins/channelrx/freqtracker/freqtracker.h +++ b/plugins/channelrx/freqtracker/freqtracker.h @@ -84,6 +84,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/heatmap/heatmap.cpp b/plugins/channelrx/heatmap/heatmap.cpp index b05aa6782..78c1f7958 100644 --- a/plugins/channelrx/heatmap/heatmap.cpp +++ b/plugins/channelrx/heatmap/heatmap.cpp @@ -600,3 +600,8 @@ void HeatMap::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int HeatMap::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/heatmap/heatmap.h b/plugins/channelrx/heatmap/heatmap.h index a17dbfc32..9e5539437 100644 --- a/plugins/channelrx/heatmap/heatmap.h +++ b/plugins/channelrx/heatmap/heatmap.h @@ -91,6 +91,7 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/localsink/localsink.cpp b/plugins/channelrx/localsink/localsink.cpp index 2b95bd981..ff5036366 100644 --- a/plugins/channelrx/localsink/localsink.cpp +++ b/plugins/channelrx/localsink/localsink.cpp @@ -186,6 +186,7 @@ void LocalSink::stopProcessing() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool LocalSink::handleMessage(const Message& cmd) @@ -862,3 +863,8 @@ void LocalSink::updateDeviceSetList() m_guiMessageQueue->push(msg); } } + +int LocalSink::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/localsink/localsink.h b/plugins/channelrx/localsink/localsink.h index 663d76687..51a8f7c5c 100644 --- a/plugins/channelrx/localsink/localsink.h +++ b/plugins/channelrx/localsink/localsink.h @@ -101,6 +101,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = "Local Sink"; } virtual qint64 getCenterFrequency() const { return m_frequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64) {} virtual QByteArray serialize() const; diff --git a/plugins/channelrx/noisefigure/noisefigure.cpp b/plugins/channelrx/noisefigure/noisefigure.cpp index 780aba41c..01fd3aa92 100644 --- a/plugins/channelrx/noisefigure/noisefigure.cpp +++ b/plugins/channelrx/noisefigure/noisefigure.cpp @@ -978,3 +978,8 @@ void NoiseFigure::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int NoiseFigure::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/noisefigure/noisefigure.h b/plugins/channelrx/noisefigure/noisefigure.h index 5fa766fda..74e6f026a 100644 --- a/plugins/channelrx/noisefigure/noisefigure.h +++ b/plugins/channelrx/noisefigure/noisefigure.h @@ -194,6 +194,7 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/radioastronomy/radioastronomy.cpp b/plugins/channelrx/radioastronomy/radioastronomy.cpp index f11ecf638..0e7947eab 100644 --- a/plugins/channelrx/radioastronomy/radioastronomy.cpp +++ b/plugins/channelrx/radioastronomy/radioastronomy.cpp @@ -68,7 +68,7 @@ RadioAstronomy::RadioAstronomy(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), m_deviceAPI(deviceAPI), m_basebandSampleRate(0), - m_availableFeatureHandler({"sdrangel.feature.startracker"}, QStringList{"startracker.target"}), + m_availableFeatureHandler({"sdrangel.feature.startracker"}, QStringList{"startracker.target"}, "RTMF", this), m_availableRotatorHandler({"sdrangel.feature.gs232controller"}), m_sweeping(false) { @@ -1359,3 +1359,8 @@ void RadioAstronomy::handleFeatureMessageQueue(MessageQueue* messageQueue) } } } + +int RadioAstronomy::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/radioastronomy/radioastronomy.h b/plugins/channelrx/radioastronomy/radioastronomy.h index 01e3bd667..ae6945807 100644 --- a/plugins/channelrx/radioastronomy/radioastronomy.h +++ b/plugins/channelrx/radioastronomy/radioastronomy.h @@ -396,6 +396,7 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/radioclock/radioclock.cpp b/plugins/channelrx/radioclock/radioclock.cpp index c0f5232a0..c2b16a5ca 100644 --- a/plugins/channelrx/radioclock/radioclock.cpp +++ b/plugins/channelrx/radioclock/radioclock.cpp @@ -629,3 +629,8 @@ void RadioClock::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int RadioClock::getChannelSampleRate() const +{ + return RadioClockSettings::RADIOCLOCK_CHANNEL_SAMPLE_RATE; +} diff --git a/plugins/channelrx/radioclock/radioclock.h b/plugins/channelrx/radioclock/radioclock.h index 5ac47d83e..7600d122d 100644 --- a/plugins/channelrx/radioclock/radioclock.h +++ b/plugins/channelrx/radioclock/radioclock.h @@ -134,6 +134,7 @@ public: virtual const QString& getURI() const { return getName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/remotesink/remotesink.cpp b/plugins/channelrx/remotesink/remotesink.cpp index 313c8054f..27c52ad1e 100644 --- a/plugins/channelrx/remotesink/remotesink.cpp +++ b/plugins/channelrx/remotesink/remotesink.cpp @@ -163,6 +163,7 @@ void RemoteSink::stop() m_basebandSink->stopWork(); m_thread->quit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool RemoteSink::handleMessage(const Message& cmd) @@ -706,3 +707,8 @@ void RemoteSink::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int RemoteSink::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/remotesink/remotesink.h b/plugins/channelrx/remotesink/remotesink.h index 156634a2c..434f00543 100644 --- a/plugins/channelrx/remotesink/remotesink.h +++ b/plugins/channelrx/remotesink/remotesink.h @@ -83,6 +83,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = "Remote Sink"; } virtual qint64 getCenterFrequency() const { return m_frequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64) {} virtual QByteArray serialize() const; diff --git a/plugins/channelrx/remotetcpsink/remotetcpsink.cpp b/plugins/channelrx/remotetcpsink/remotetcpsink.cpp index f466f17f7..5cd5cf40f 100644 --- a/plugins/channelrx/remotetcpsink/remotetcpsink.cpp +++ b/plugins/channelrx/remotetcpsink/remotetcpsink.cpp @@ -765,3 +765,8 @@ void RemoteTCPSink::updatePublicListing() m_networkManager->post(request, data); } + +int RemoteTCPSink::getChannelSampleRate() const +{ + return m_settings.m_channelSampleRate; +} diff --git a/plugins/channelrx/remotetcpsink/remotetcpsink.h b/plugins/channelrx/remotetcpsink/remotetcpsink.h index ab05b9d64..38a72ce1d 100644 --- a/plugins/channelrx/remotetcpsink/remotetcpsink.h +++ b/plugins/channelrx/remotetcpsink/remotetcpsink.h @@ -221,6 +221,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = "Remote Sink"; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/sigmffilesink/sigmffilesink.cpp b/plugins/channelrx/sigmffilesink/sigmffilesink.cpp index 7469e5f6d..c11b145d0 100644 --- a/plugins/channelrx/sigmffilesink/sigmffilesink.cpp +++ b/plugins/channelrx/sigmffilesink/sigmffilesink.cpp @@ -54,6 +54,7 @@ const char* const SigMFFileSink::m_channelId = "SigMFFileSink"; SigMFFileSink::SigMFFileSink(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), m_deviceAPI(deviceAPI), + m_basebandSink(nullptr), m_running(false), m_spectrumVis(SDR_RX_SCALEF), m_centerFrequency(0), @@ -205,6 +206,7 @@ void SigMFFileSink::stop() m_running = false; m_thread->quit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished if (getMessageQueueToGUI()) { @@ -839,3 +841,8 @@ void SigMFFileSink::handleIndexInDeviceSetChanged(int index) .arg(index); m_basebandSink->setFifoLabel(fifoLabel); } + +int SigMFFileSink::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/sigmffilesink/sigmffilesink.h b/plugins/channelrx/sigmffilesink/sigmffilesink.h index a72111c30..28f5c8f11 100644 --- a/plugins/channelrx/sigmffilesink/sigmffilesink.h +++ b/plugins/channelrx/sigmffilesink/sigmffilesink.h @@ -103,6 +103,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = "SigMF File Sink"; } virtual qint64 getCenterFrequency() const { return m_frequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64) {} virtual QByteArray serialize() const; diff --git a/plugins/channelrx/udpsink/udpsink.cpp b/plugins/channelrx/udpsink/udpsink.cpp index 721b5d505..38be11b03 100644 --- a/plugins/channelrx/udpsink/udpsink.cpp +++ b/plugins/channelrx/udpsink/udpsink.cpp @@ -696,3 +696,8 @@ void UDPSink::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); m_basebandSink->setAudioFifoLabel(fifoLabel); } + +int UDPSink::getChannelSampleRate() const +{ + return m_basebandSink ? m_basebandSink->getChannelSampleRate() : 0; +} diff --git a/plugins/channelrx/udpsink/udpsink.h b/plugins/channelrx/udpsink/udpsink.h index 973466133..8dba1745f 100644 --- a/plugins/channelrx/udpsink/udpsink.h +++ b/plugins/channelrx/udpsink/udpsink.h @@ -90,6 +90,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channelrx/wdsprx/wdsprx.cpp b/plugins/channelrx/wdsprx/wdsprx.cpp index 86136645b..a0628fb62 100644 --- a/plugins/channelrx/wdsprx/wdsprx.cpp +++ b/plugins/channelrx/wdsprx/wdsprx.cpp @@ -193,6 +193,7 @@ void WDSPRx::stop() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished } bool WDSPRx::handleMessage(const Message& cmd) diff --git a/plugins/channelrx/wdsprx/wdsprx.h b/plugins/channelrx/wdsprx/wdsprx.h index 4b7128d89..6421f90c7 100644 --- a/plugins/channelrx/wdsprx/wdsprx.h +++ b/plugins/channelrx/wdsprx/wdsprx.h @@ -105,8 +105,8 @@ public: } void setMessageQueueToGUI(MessageQueue* queue) final; - uint32_t getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } - uint32_t getChannelSampleRate() const { return m_running ? m_basebandSink->getChannelSampleRate() : 0; } + int getAudioSampleRate() const override { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + int getChannelSampleRate() const override { return m_running ? m_basebandSink->getChannelSampleRate() : 0; } double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } bool getAudioActive() const { return m_running && m_basebandSink->getAudioActive(); } diff --git a/plugins/channeltx/filesource/filesource.cpp b/plugins/channeltx/filesource/filesource.cpp index 380df5bb4..0fab1982c 100644 --- a/plugins/channeltx/filesource/filesource.cpp +++ b/plugins/channeltx/filesource/filesource.cpp @@ -702,3 +702,8 @@ uint32_t FileSource::getNumberOfDeviceStreams() const { return m_deviceAPI->getNbSinkStreams(); } + +int FileSource::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/filesource/filesource.h b/plugins/channeltx/filesource/filesource.h index 2d5186b2f..989bf6ed0 100644 --- a/plugins/channeltx/filesource/filesource.h +++ b/plugins/channeltx/filesource/filesource.h @@ -166,6 +166,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return 0; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64) {} virtual int getNbSinkStreams() const { return 0; } diff --git a/plugins/channeltx/localsource/localsource.cpp b/plugins/channeltx/localsource/localsource.cpp index 1fefc231f..185a76824 100644 --- a/plugins/channeltx/localsource/localsource.cpp +++ b/plugins/channeltx/localsource/localsource.cpp @@ -628,3 +628,8 @@ uint32_t LocalSource::getNumberOfDeviceStreams() const { return m_deviceAPI->getNbSinkStreams(); } + +int LocalSource::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/localsource/localsource.h b/plugins/channeltx/localsource/localsource.h index c77b05315..bdf27ef14 100644 --- a/plugins/channeltx/localsource/localsource.h +++ b/plugins/channeltx/localsource/localsource.h @@ -80,6 +80,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = "Local Sink"; } virtual qint64 getCenterFrequency() const { return m_frequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64) {} virtual QByteArray serialize() const; diff --git a/plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.cpp b/plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.cpp index c5debfd21..fe6501ddd 100644 --- a/plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.cpp +++ b/plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.cpp @@ -814,3 +814,8 @@ ScopeVis *IEEE_802_15_4_Mod::getScopeSink() { return m_basebandSource->getScopeSink(); } + +int IEEE_802_15_4_Mod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.h b/plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.h index 1ceb0c261..8cde2f386 100644 --- a/plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.h +++ b/plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.h @@ -109,6 +109,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/modais/aismod.cpp b/plugins/channeltx/modais/aismod.cpp index 5f5649b4e..67259d112 100644 --- a/plugins/channeltx/modais/aismod.cpp +++ b/plugins/channeltx/modais/aismod.cpp @@ -997,3 +997,13 @@ void AISMod::udpRx() m_basebandSource->getInputMessageQueue()->push(msg); } } + +int AISMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} + +int AISMod::getAudioSampleRate() const +{ + return AISModSettings::AISMOD_SAMPLE_RATE; +} diff --git a/plugins/channeltx/modais/aismod.h b/plugins/channeltx/modais/aismod.h index 21e799035..143ed8a8e 100644 --- a/plugins/channeltx/modais/aismod.h +++ b/plugins/channeltx/modais/aismod.h @@ -170,6 +170,8 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/modam/ammod.cpp b/plugins/channeltx/modam/ammod.cpp index 60a8c967e..3d9984ef2 100644 --- a/plugins/channeltx/modam/ammod.cpp +++ b/plugins/channeltx/modam/ammod.cpp @@ -162,6 +162,7 @@ void AMMod::stop() m_running = false; m_thread->exit(); m_thread->wait(); + m_basebandSource = nullptr; // Freed by deleteLater when the thread finished } void AMMod::pull(SampleVector::iterator& begin, unsigned int nbSamples) @@ -837,3 +838,8 @@ int AMMod::getFeedbackAudioSampleRate() const return 0; } + +int AMMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modam/ammod.h b/plugins/channeltx/modam/ammod.h index e980914d9..94f14ff08 100644 --- a/plugins/channeltx/modam/ammod.h +++ b/plugins/channeltx/modam/ammod.h @@ -193,6 +193,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -240,7 +241,7 @@ public: double getMagSq() const; CWKeyer *getCWKeyer(); void setLevelMeter(QObject *levelMeter) { m_levelMeter = levelMeter; } - int getAudioSampleRate() const; + int getAudioSampleRate() const override; int getFeedbackAudioSampleRate() const; static const char* const m_channelIdURI; diff --git a/plugins/channeltx/modatv/atvmod.cpp b/plugins/channeltx/modatv/atvmod.cpp index 00e6055b7..5971dad98 100644 --- a/plugins/channeltx/modatv/atvmod.cpp +++ b/plugins/channeltx/modatv/atvmod.cpp @@ -801,3 +801,8 @@ void ATVMod::setMessageQueueToGUI(MessageQueue* queue) { ChannelAPI::setMessageQueueToGUI(queue); m_basebandSource->setMessageQueueToGUI(queue); } + +int ATVMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modatv/atvmod.h b/plugins/channeltx/modatv/atvmod.h index a96963d0c..1d0b0fe2d 100644 --- a/plugins/channeltx/modatv/atvmod.h +++ b/plugins/channeltx/modatv/atvmod.h @@ -263,6 +263,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/modchirpchat/chirpchatmod.cpp b/plugins/channeltx/modchirpchat/chirpchatmod.cpp index 475df317c..dd6854fe3 100644 --- a/plugins/channeltx/modchirpchat/chirpchatmod.cpp +++ b/plugins/channeltx/modchirpchat/chirpchatmod.cpp @@ -1155,3 +1155,8 @@ void ChirpChatMod::udpRx() } } } + +int ChirpChatMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modchirpchat/chirpchatmod.h b/plugins/channeltx/modchirpchat/chirpchatmod.h index 37a4615ce..42710f8fc 100644 --- a/plugins/channeltx/modchirpchat/chirpchatmod.h +++ b/plugins/channeltx/modchirpchat/chirpchatmod.h @@ -108,6 +108,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/moddatv/datvmod.cpp b/plugins/channeltx/moddatv/datvmod.cpp index 2c8088864..924974a78 100644 --- a/plugins/channeltx/moddatv/datvmod.cpp +++ b/plugins/channeltx/moddatv/datvmod.cpp @@ -791,3 +791,8 @@ void DATVMod::setMessageQueueToGUI(MessageQueue* queue) { ChannelAPI::setMessageQueueToGUI(queue); m_basebandSource->setMessageQueueToGUI(queue); } + +int DATVMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/moddatv/datvmod.h b/plugins/channeltx/moddatv/datvmod.h index e77eac989..ee0b53f43 100644 --- a/plugins/channeltx/moddatv/datvmod.h +++ b/plugins/channeltx/moddatv/datvmod.h @@ -218,6 +218,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/modfreedv/freedvmod.cpp b/plugins/channeltx/modfreedv/freedvmod.cpp index 6c6777e02..8ec927252 100644 --- a/plugins/channeltx/modfreedv/freedvmod.cpp +++ b/plugins/channeltx/modfreedv/freedvmod.cpp @@ -811,3 +811,8 @@ uint32_t FreeDVMod::getNumberOfDeviceStreams() const { return m_deviceAPI->getNbSinkStreams(); } + +int FreeDVMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modfreedv/freedvmod.h b/plugins/channeltx/modfreedv/freedvmod.h index 7350f8cdd..dc92630e1 100644 --- a/plugins/channeltx/modfreedv/freedvmod.h +++ b/plugins/channeltx/modfreedv/freedvmod.h @@ -195,6 +195,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -239,7 +240,7 @@ public: SWGSDRangel::SWGChannelSettings& response); SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } - int getAudioSampleRate() const; + int getAudioSampleRate() const override; uint32_t getModemSampleRate() const; Real getLowCutoff() const; Real getHiCutoff() const; diff --git a/plugins/channeltx/modm17/m17mod.cpp b/plugins/channeltx/modm17/m17mod.cpp index b69465e02..0d7ea0645 100644 --- a/plugins/channeltx/modm17/m17mod.cpp +++ b/plugins/channeltx/modm17/m17mod.cpp @@ -956,3 +956,8 @@ void M17Mod::sendPacket() m_basebandSource->sendPacket(); } } + +int M17Mod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modm17/m17mod.h b/plugins/channeltx/modm17/m17mod.h index aa5e0657e..6de2d998a 100644 --- a/plugins/channeltx/modm17/m17mod.h +++ b/plugins/channeltx/modm17/m17mod.h @@ -193,6 +193,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -239,7 +240,7 @@ public: double getMagSq() const; void setLevelMeter(QObject *levelMeter); uint32_t getNumberOfDeviceStreams() const; - int getAudioSampleRate() const; + int getAudioSampleRate() const override; int getFeedbackAudioSampleRate() const; void sendPacket(); diff --git a/plugins/channeltx/modmeshcore/meshcoremod.cpp b/plugins/channeltx/modmeshcore/meshcoremod.cpp index b56a2a0f7..b8f0cec08 100644 --- a/plugins/channeltx/modmeshcore/meshcoremod.cpp +++ b/plugins/channeltx/modmeshcore/meshcoremod.cpp @@ -908,3 +908,8 @@ void MeshcoreMod::udpRx() } } } + +int MeshcoreMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modmeshcore/meshcoremod.h b/plugins/channeltx/modmeshcore/meshcoremod.h index a50b1e4c8..8e56fb714 100644 --- a/plugins/channeltx/modmeshcore/meshcoremod.h +++ b/plugins/channeltx/modmeshcore/meshcoremod.h @@ -123,6 +123,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/modmeshtastic/meshtasticmod.cpp b/plugins/channeltx/modmeshtastic/meshtasticmod.cpp index 6c5304bdb..92d8aab76 100644 --- a/plugins/channeltx/modmeshtastic/meshtasticmod.cpp +++ b/plugins/channeltx/modmeshtastic/meshtasticmod.cpp @@ -871,3 +871,8 @@ void MeshtasticMod::udpRx() } } } + +int MeshtasticMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modmeshtastic/meshtasticmod.h b/plugins/channeltx/modmeshtastic/meshtasticmod.h index a6af59ed0..923f3af0d 100644 --- a/plugins/channeltx/modmeshtastic/meshtasticmod.h +++ b/plugins/channeltx/modmeshtastic/meshtasticmod.h @@ -123,6 +123,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/modnfm/nfmmod.cpp b/plugins/channeltx/modnfm/nfmmod.cpp index 951e4e419..fe0e8567a 100644 --- a/plugins/channeltx/modnfm/nfmmod.cpp +++ b/plugins/channeltx/modnfm/nfmmod.cpp @@ -159,6 +159,7 @@ void NFMMod::stop() m_running = false; m_thread->quit(); m_thread->wait(); + m_basebandSource = nullptr; // Freed by deleteLater when the thread finished } void NFMMod::pull(SampleVector::iterator& begin, unsigned int nbSamples) @@ -924,3 +925,8 @@ int NFMMod::getFeedbackAudioSampleRate() const return 0; } + +int NFMMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modnfm/nfmmod.h b/plugins/channeltx/modnfm/nfmmod.h index c308e1a8b..659fd1c76 100644 --- a/plugins/channeltx/modnfm/nfmmod.h +++ b/plugins/channeltx/modnfm/nfmmod.h @@ -193,6 +193,7 @@ public: QString getIdentifier() const final { return objectName(); } void getTitle(QString& title) final { title = m_settings.m_title; } qint64 getCenterFrequency() const final { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; void setCenterFrequency(qint64 frequency) final; QByteArray serialize() const final; @@ -240,7 +241,7 @@ public: CWKeyer *getCWKeyer() { return &m_cwKeyer; } void setLevelMeter(QObject *levelMeter) { m_levelMeter = levelMeter; } uint32_t getNumberOfDeviceStreams() const; - int getAudioSampleRate() const; + int getAudioSampleRate() const override; int getFeedbackAudioSampleRate() const; static const char* const m_channelIdURI; diff --git a/plugins/channeltx/modpacket/packetmod.cpp b/plugins/channeltx/modpacket/packetmod.cpp index f1daffecd..29be8e9f6 100644 --- a/plugins/channeltx/modpacket/packetmod.cpp +++ b/plugins/channeltx/modpacket/packetmod.cpp @@ -1017,3 +1017,13 @@ void PacketMod::udpRx() m_basebandSource->getInputMessageQueue()->push(msg); } } + +int PacketMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} + +int PacketMod::getAudioSampleRate() const +{ + return getSourceChannelSampleRate(); +} diff --git a/plugins/channeltx/modpacket/packetmod.h b/plugins/channeltx/modpacket/packetmod.h index dda22ef8b..02d7b283b 100644 --- a/plugins/channeltx/modpacket/packetmod.h +++ b/plugins/channeltx/modpacket/packetmod.h @@ -160,6 +160,8 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/modpsk31/psk31mod.cpp b/plugins/channeltx/modpsk31/psk31mod.cpp index 753c33892..5ec40541c 100644 --- a/plugins/channeltx/modpsk31/psk31mod.cpp +++ b/plugins/channeltx/modpsk31/psk31mod.cpp @@ -799,3 +799,13 @@ void PSK31::setMessageQueueToGUI(MessageQueue* queue) { ChannelAPI::setMessageQueueToGUI(queue); m_basebandSource->setMessageQueueToGUI(queue); } + +int PSK31::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} + +int PSK31::getAudioSampleRate() const +{ + return getSourceChannelSampleRate(); +} diff --git a/plugins/channeltx/modpsk31/psk31mod.h b/plugins/channeltx/modpsk31/psk31mod.h index bdfa7d67f..53e87c207 100644 --- a/plugins/channeltx/modpsk31/psk31mod.h +++ b/plugins/channeltx/modpsk31/psk31mod.h @@ -144,6 +144,8 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/modrtty/rttymod.cpp b/plugins/channeltx/modrtty/rttymod.cpp index 5e5af410d..96f404507 100644 --- a/plugins/channeltx/modrtty/rttymod.cpp +++ b/plugins/channeltx/modrtty/rttymod.cpp @@ -842,3 +842,13 @@ void RttyMod::setMessageQueueToGUI(MessageQueue* queue) { ChannelAPI::setMessageQueueToGUI(queue); m_basebandSource->setMessageQueueToGUI(queue); } + +int RttyMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} + +int RttyMod::getAudioSampleRate() const +{ + return getSourceChannelSampleRate(); +} diff --git a/plugins/channeltx/modrtty/rttymod.h b/plugins/channeltx/modrtty/rttymod.h index b8a6c9ba9..8a0e40481 100644 --- a/plugins/channeltx/modrtty/rttymod.h +++ b/plugins/channeltx/modrtty/rttymod.h @@ -144,6 +144,8 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; + int getAudioSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/channeltx/modssb/ssbmod.cpp b/plugins/channeltx/modssb/ssbmod.cpp index 649e48f3e..22835ea8c 100644 --- a/plugins/channeltx/modssb/ssbmod.cpp +++ b/plugins/channeltx/modssb/ssbmod.cpp @@ -923,3 +923,8 @@ uint32_t SSBMod::getNumberOfDeviceStreams() const { return m_deviceAPI->getNbSinkStreams(); } + +int SSBMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modssb/ssbmod.h b/plugins/channeltx/modssb/ssbmod.h index a0b8f1178..fcdc9a35e 100644 --- a/plugins/channeltx/modssb/ssbmod.h +++ b/plugins/channeltx/modssb/ssbmod.h @@ -194,6 +194,7 @@ public: QString getIdentifier() const final { return objectName(); } void getTitle(QString& title) final { title = m_settings.m_title; } qint64 getCenterFrequency() const final { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; void setCenterFrequency(qint64 frequency) final; QByteArray serialize() const final; @@ -241,7 +242,7 @@ public: double getMagSq() const; CWKeyer *getCWKeyer(); void setLevelMeter(QObject *levelMeter) { m_levelMeter = levelMeter; } - int getAudioSampleRate() const; + int getAudioSampleRate() const override; int getFeedbackAudioSampleRate() const; uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channeltx/modwfm/wfmmod.cpp b/plugins/channeltx/modwfm/wfmmod.cpp index d2065548d..5a7278d4d 100644 --- a/plugins/channeltx/modwfm/wfmmod.cpp +++ b/plugins/channeltx/modwfm/wfmmod.cpp @@ -783,3 +783,8 @@ int WFMMod::getFeedbackAudioSampleRate() const { return m_basebandSource->getFeedbackAudioSampleRate(); } + +int WFMMod::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/modwfm/wfmmod.h b/plugins/channeltx/modwfm/wfmmod.h index afb304638..259a06b58 100644 --- a/plugins/channeltx/modwfm/wfmmod.h +++ b/plugins/channeltx/modwfm/wfmmod.h @@ -192,6 +192,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; @@ -239,7 +240,7 @@ public: CWKeyer *getCWKeyer(); void setLevelMeter(QObject *levelMeter); uint32_t getNumberOfDeviceStreams() const; - int getAudioSampleRate() const; + int getAudioSampleRate() const override; int getFeedbackAudioSampleRate() const; static const char* const m_channelIdURI; diff --git a/plugins/channeltx/remotesource/remotesource.cpp b/plugins/channeltx/remotesource/remotesource.cpp index 23a161504..06227c80f 100644 --- a/plugins/channeltx/remotesource/remotesource.cpp +++ b/plugins/channeltx/remotesource/remotesource.cpp @@ -603,3 +603,8 @@ uint32_t RemoteSource::getNumberOfDeviceStreams() const { return m_deviceAPI->getNbSinkStreams(); } + +int RemoteSource::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/remotesource/remotesource.h b/plugins/channeltx/remotesource/remotesource.h index 86423f162..79db41b6e 100644 --- a/plugins/channeltx/remotesource/remotesource.h +++ b/plugins/channeltx/remotesource/remotesource.h @@ -177,6 +177,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_frequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64) {} virtual int getNbSinkStreams() const { return 0; } diff --git a/plugins/channeltx/udpsource/udpsource.cpp b/plugins/channeltx/udpsource/udpsource.cpp index 9838a3a19..7378869f3 100644 --- a/plugins/channeltx/udpsource/udpsource.cpp +++ b/plugins/channeltx/udpsource/udpsource.cpp @@ -742,3 +742,8 @@ uint32_t UDPSource::getNumberOfDeviceStreams() const { return m_deviceAPI->getNbSinkStreams(); } + +int UDPSource::getChannelSampleRate() const +{ + return m_basebandSource ? m_basebandSource->getChannelSampleRate() : 0; +} diff --git a/plugins/channeltx/udpsource/udpsource.h b/plugins/channeltx/udpsource/udpsource.h index 97d111a39..657e32f02 100644 --- a/plugins/channeltx/udpsource/udpsource.h +++ b/plugins/channeltx/udpsource/udpsource.h @@ -112,6 +112,7 @@ public: virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) { title = m_settings.m_title; } virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + int getChannelSampleRate() const override; virtual void setCenterFrequency(qint64 frequency); virtual QByteArray serialize() const; diff --git a/plugins/feature/ais/ais.cpp b/plugins/feature/ais/ais.cpp index b2816c52f..8d7e37b27 100644 --- a/plugins/feature/ais/ais.cpp +++ b/plugins/feature/ais/ais.cpp @@ -42,7 +42,7 @@ const char* const AIS::m_featureId = "AIS"; AIS::AIS(WebAPIAdapterInterface *webAPIAdapterInterface) : Feature(m_featureIdURI, webAPIAdapterInterface), - m_availableChannelHandler({"sdrangel.channel.aisdemod"}, QStringList{"ais"}) + m_availableChannelHandler({"sdrangel.channel.aisdemod"}, QStringList{"ais"}, "RTMF", this) { qDebug("AIS::AIS: webAPIAdapterInterface: %p", webAPIAdapterInterface); setObjectName(m_featureId); diff --git a/plugins/feature/aprs/aprs.cpp b/plugins/feature/aprs/aprs.cpp index fc796b027..8025960a1 100644 --- a/plugins/feature/aprs/aprs.cpp +++ b/plugins/feature/aprs/aprs.cpp @@ -45,7 +45,7 @@ APRS::APRS(WebAPIAdapterInterface *webAPIAdapterInterface) : Feature(m_featureIdURI, webAPIAdapterInterface), m_thread(nullptr), m_worker(nullptr), - m_availableChannelHandler(APRSSettings::m_pipeURIs, QStringList{"packets"}) + m_availableChannelHandler(APRSSettings::m_pipeURIs, QStringList{"packets"}, "RTMF", this) { qDebug("APRS::APRS: webAPIAdapterInterface: %p", webAPIAdapterInterface); setObjectName(m_featureId); diff --git a/plugins/feature/demodanalyzer/demodanalyzer.cpp b/plugins/feature/demodanalyzer/demodanalyzer.cpp index 847d18303..013a2cc29 100644 --- a/plugins/feature/demodanalyzer/demodanalyzer.cpp +++ b/plugins/feature/demodanalyzer/demodanalyzer.cpp @@ -692,6 +692,7 @@ void DemodAnalyzer::handleDataPipeToBeDeleted(int reason, QObject *object) } m_selectedChannel = nullptr; + m_dataPipe = nullptr; // The pipe and its FIFO are freed by the pipes GC. } } diff --git a/plugins/feature/demodanalyzer/demodanalyzerworker.cpp b/plugins/feature/demodanalyzer/demodanalyzerworker.cpp index bb55697a2..1e513d030 100644 --- a/plugins/feature/demodanalyzer/demodanalyzerworker.cpp +++ b/plugins/feature/demodanalyzer/demodanalyzerworker.cpp @@ -251,6 +251,7 @@ bool DemodAnalyzerWorker::handleMessage(const Message& cmd) this, &DemodAnalyzerWorker::handleData ); + m_dataFifo = nullptr; // It is freed by the pipes GC after being unregistered. } return true; @@ -358,6 +359,10 @@ void DemodAnalyzerWorker::handleData() { QMutexLocker mutexLocker(&m_mutex); + if (!m_dataFifo) { + return; // A queued dataReady can arrive after the FIFO was disconnected. + } + while ((m_dataFifo->fill() > 0) && (m_inputMessageQueue.size() == 0)) { QByteArray::iterator part1begin; diff --git a/plugins/feature/denoiser/denoiser.cpp b/plugins/feature/denoiser/denoiser.cpp index d185e7153..8d038083b 100644 --- a/plugins/feature/denoiser/denoiser.cpp +++ b/plugins/feature/denoiser/denoiser.cpp @@ -174,6 +174,16 @@ void Denoiser::start() m_worker->getInputMessageQueue()->push(msg); m_worker->applySampleRate(m_sampleRate); + // Subscribe only while the worker can drain the FIFO. + if (m_selectedChannel && !m_dataPipe) + { + m_dataPipe = MainCore::instance()->getDataPipes().registerProducerToConsumer(m_selectedChannel, this, "demod"); + connect(m_dataPipe, &ObjectPipe::toBeDeleted, this, &Denoiser::handleDataPipeToBeDeleted, Qt::UniqueConnection); + if (auto *fifo = qobject_cast(m_dataPipe->m_element)) { + fifo->setSize(m_sampleRate > 0 ? 2 * m_sampleRate : 96000); // Resized when the rate is reported + } + } + if (m_dataPipe) { DataFifo *fifo = qobject_cast(m_dataPipe->m_element); @@ -220,12 +230,8 @@ void Denoiser::stop() if (m_dataPipe) { - DataFifo *fifo = qobject_cast(m_dataPipe->m_element); - - if (fifo) - { - DenoiserWorker::MsgConnectFifo *msg = DenoiserWorker::MsgConnectFifo::create(fifo, false); - m_worker->getInputMessageQueue()->push(msg); + if (auto *fifo = qobject_cast(m_dataPipe->m_element)) { + disconnect(fifo, SIGNAL(dataReady()), m_worker, SLOT(handleData())); } } @@ -233,6 +239,12 @@ void Denoiser::stop() setState(StIdle); m_thread->quit(); m_thread->wait(); + + if (m_dataPipe) + { + MainCore::instance()->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod"); + m_dataPipe = nullptr; + } } double Denoiser::getMagSqAvg() const @@ -659,13 +671,16 @@ void Denoiser::setChannel(QObject *selectedChannel, bool preserveSavedSource) if (m_selectedChannel) { - ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod"); - DataFifo *fifo = pipe ? qobject_cast(pipe->m_element) : nullptr; - - if ((fifo) && m_running) + if (m_dataPipe) { - DenoiserWorker::MsgConnectFifo *msg = DenoiserWorker::MsgConnectFifo::create(fifo, false); - m_worker->getInputMessageQueue()->push(msg); + ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod"); + DataFifo *fifo = pipe ? qobject_cast(pipe->m_element) : nullptr; + + if ((fifo) && m_running) + { + DenoiserWorker::MsgConnectFifo *msg = DenoiserWorker::MsgConnectFifo::create(fifo, false); + m_worker->getInputMessageQueue()->push(msg); + } } ObjectPipe *messagePipe = mainCore->getMessagePipes().unregisterProducerToConsumer(m_selectedChannel, this, "reportdemod"); @@ -691,16 +706,15 @@ void Denoiser::setChannel(QObject *selectedChannel, bool preserveSavedSource) return; } - m_dataPipe = mainCore->getDataPipes().registerProducerToConsumer(selectedChannel, this, "demod"); - connect(m_dataPipe, SIGNAL(toBeDeleted(int, QObject*)), this, SLOT(handleDataPipeToBeDeleted(int, QObject*))); - DataFifo *fifo = qobject_cast(m_dataPipe->m_element); - - if (fifo) + if (m_running) { - fifo->setSize(96000); + m_dataPipe = mainCore->getDataPipes().registerProducerToConsumer(selectedChannel, this, "demod"); + connect(m_dataPipe, &ObjectPipe::toBeDeleted, this, &Denoiser::handleDataPipeToBeDeleted, Qt::UniqueConnection); + DataFifo *fifo = qobject_cast(m_dataPipe->m_element); - if (m_running) + if (fifo) { + fifo->setSize(96000); DenoiserWorker::MsgConnectFifo *msg = DenoiserWorker::MsgConnectFifo::create(fifo, true); m_worker->getInputMessageQueue()->push(msg); } @@ -1061,7 +1075,7 @@ void Denoiser::handleDataPipeToBeDeleted(int reason, QObject *object) } m_selectedChannel = nullptr; - m_dataPipe = nullptr; + m_dataPipe = nullptr; // The pipe and its FIFO are freed by the pipes GC. m_sampleRate = 0; if (m_running) { diff --git a/plugins/feature/denoiser/denoiserworker.cpp b/plugins/feature/denoiser/denoiserworker.cpp index 3010e7fad..20da5f2c9 100644 --- a/plugins/feature/denoiser/denoiserworker.cpp +++ b/plugins/feature/denoiser/denoiserworker.cpp @@ -247,6 +247,7 @@ bool DenoiserWorker::handleMessage(const Message& cmd) this, &DenoiserWorker::handleData ); + m_dataFifo = nullptr; // It is freed by the pipes GC after being unregistered. } return true; @@ -451,6 +452,10 @@ void DenoiserWorker::handleData() QMutexLocker mutexLocker(&m_mutex); + if (!m_dataFifo) { + return; // A queued dataReady can arrive after the FIFO was disconnected. + } + while ((m_dataFifo->fill() > 0) && (m_inputMessageQueue.size() == 0)) { QByteArray::iterator part1begin; diff --git a/plugins/feature/denoiser/vst3effect.cpp b/plugins/feature/denoiser/vst3effect.cpp index e5dc23e1f..103f98861 100644 --- a/plugins/feature/denoiser/vst3effect.cpp +++ b/plugins/feature/denoiser/vst3effect.cpp @@ -698,6 +698,11 @@ class Vst3Effect::EditorWidget : public QWidget public: EditorWidget(Vst3Effect *effect, QWidget *parent) : QWidget(parent), m_effect(effect) { + // The editor needs a native window to host the plugin's own, but its ancestors + // must not be made native: that would reach the dialog, and then the dialog's + // parent's children, spreading native windows through the whole main window + // (breaking OpenGL composition and mouse input under overlays). + setAttribute(Qt::WA_DontCreateNativeAncestors); setAttribute(Qt::WA_NativeWindow); setFocusPolicy(Qt::StrongFocus); m_frame.iface.lpVtbl = &frameVtbl; diff --git a/plugins/feature/map/map.cpp b/plugins/feature/map/map.cpp index b8573a2d1..7623c9d37 100644 --- a/plugins/feature/map/map.cpp +++ b/plugins/feature/map/map.cpp @@ -43,7 +43,7 @@ const char* const Map::m_featureId = "Map"; Map::Map(WebAPIAdapterInterface *webAPIAdapterInterface) : Feature(m_featureIdURI, webAPIAdapterInterface), - m_availableChannelOrFeatureHandler(MapSettings::m_pipeURIs, QStringList{"mapitems"}), + m_availableChannelOrFeatureHandler(MapSettings::m_pipeURIs, QStringList{"mapitems"}, "RTMF", this), m_multiplier(0.0) { qDebug("Map::Map: webAPIAdapterInterface: %p", webAPIAdapterInterface); diff --git a/plugins/feature/morsedecoder/morsedecoder.cpp b/plugins/feature/morsedecoder/morsedecoder.cpp index 5616d0b02..ba90b18aa 100644 --- a/plugins/feature/morsedecoder/morsedecoder.cpp +++ b/plugins/feature/morsedecoder/morsedecoder.cpp @@ -389,7 +389,7 @@ void MorseDecoder::setChannel(ChannelAPI *selectedChannel) if (m_selectedChannel) { ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod"); - DataFifo *fifo = qobject_cast(pipe->m_element); + DataFifo *fifo = pipe ? qobject_cast(pipe->m_element) : nullptr; if ((fifo) && m_running) { @@ -704,6 +704,7 @@ void MorseDecoder::handleDataPipeToBeDeleted(int reason, QObject *object) } m_selectedChannel = nullptr; + m_dataPipe = nullptr; // The pipe and its FIFO are freed by the pipes GC. } } diff --git a/plugins/feature/morsedecoder/morsedecoderworker.cpp b/plugins/feature/morsedecoder/morsedecoderworker.cpp index 805069b37..2b77fc6ef 100644 --- a/plugins/feature/morsedecoder/morsedecoderworker.cpp +++ b/plugins/feature/morsedecoder/morsedecoderworker.cpp @@ -303,6 +303,7 @@ bool MorseDecoderWorker::handleMessage(const Message& cmd) this, &MorseDecoderWorker::handleData ); + m_dataFifo = nullptr; // It is freed by the pipes GC after being unregistered. } return true; @@ -366,6 +367,10 @@ void MorseDecoderWorker::handleData() { QMutexLocker mutexLocker(&m_mutex); + if (!m_dataFifo) { + return; // A queued dataReady can arrive after the FIFO was disconnected. + } + while ((m_dataFifo->fill() > 0) && (m_inputMessageQueue.size() == 0)) { QByteArray::iterator part1begin; diff --git a/plugins/feature/radiosonde/radiosonde.cpp b/plugins/feature/radiosonde/radiosonde.cpp index 1c0692579..50da85d9c 100644 --- a/plugins/feature/radiosonde/radiosonde.cpp +++ b/plugins/feature/radiosonde/radiosonde.cpp @@ -40,7 +40,7 @@ const char* const Radiosonde::m_featureId = "Radiosonde"; Radiosonde::Radiosonde(WebAPIAdapterInterface *webAPIAdapterInterface) : Feature(m_featureIdURI, webAPIAdapterInterface), - m_availableChannelHandler({"sdrangel.channel.radiosondedemod"}, QStringList{"radiosonde"}) + m_availableChannelHandler({"sdrangel.channel.radiosondedemod"}, QStringList{"radiosonde"}, "RTMF", this) { qDebug("Radiosonde::Radiosonde: webAPIAdapterInterface: %p", webAPIAdapterInterface); setObjectName(m_featureId); diff --git a/plugins/feature/skymap/skymapgui.cpp b/plugins/feature/skymap/skymapgui.cpp index 070fdc053..deafde306 100644 --- a/plugins/feature/skymap/skymapgui.cpp +++ b/plugins/feature/skymap/skymapgui.cpp @@ -201,7 +201,7 @@ SkyMapGUI::SkyMapGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature * m_featureUISet(featureUISet), m_doApplySettings(true), m_source(nullptr), - m_availableChannelOrFeatureHandler(SkyMapSettings::m_pipeURIs, {"target", "skymap.target"}), + m_availableChannelOrFeatureHandler(SkyMapSettings::m_pipeURIs, {"target", "skymap.target"}, "RTMF", this), m_ready(false) { m_feature = feature; diff --git a/plugins/feature/startracker/startracker.cpp b/plugins/feature/startracker/startracker.cpp index eb601c5b2..ebf16e9ea 100644 --- a/plugins/feature/startracker/startracker.cpp +++ b/plugins/feature/startracker/startracker.cpp @@ -49,8 +49,8 @@ StarTracker::StarTracker(WebAPIAdapterInterface *webAPIAdapterInterface) : Feature(m_featureIdURI, webAPIAdapterInterface), m_thread(nullptr), m_worker(nullptr), - m_availableChannelHandler({"sdrangel.channel.radioastronomy"}, QStringList{"startracker.display"}), - m_availableFeatureHandler({"sdrangel.feature.satellitetracker", "sdrangel.feature.skymap"}) + m_availableChannelHandler({"sdrangel.channel.radioastronomy"}, QStringList{"startracker.display"}, "RTMF", this), + m_availableFeatureHandler({"sdrangel.feature.satellitetracker", "sdrangel.feature.skymap"}, "RTMF", this) { qDebug("StarTracker::StarTracker: webAPIAdapterInterface: %p", webAPIAdapterInterface); setObjectName(m_featureId); diff --git a/sdrbase/availablechannelorfeaturehandler.h b/sdrbase/availablechannelorfeaturehandler.h index fce07b430..dd4c92873 100644 --- a/sdrbase/availablechannelorfeaturehandler.h +++ b/sdrbase/availablechannelorfeaturehandler.h @@ -33,7 +33,8 @@ class SDRBASE_API AvailableChannelOrFeatureHandler : public QObject public: // Use this constructor to just keep track of available channels and features with specified URIs and kinds - AvailableChannelOrFeatureHandler(QStringList uris, const QString& kinds = "RTMF") : + AvailableChannelOrFeatureHandler(QStringList uris, const QString& kinds = "RTMF", QObject *parent = nullptr) : + QObject(parent), m_uris(uris), m_kinds(kinds) { @@ -41,7 +42,8 @@ public: } // Use this constructor to keep track of available channels and features with specified URIs and kinds and register pipes with the given names to them - AvailableChannelOrFeatureHandler(QStringList uris, QStringList pipeNames, const QString& kinds = "RTMF") : + AvailableChannelOrFeatureHandler(QStringList uris, QStringList pipeNames, const QString& kinds = "RTMF", QObject* parent = nullptr) : + QObject(parent), m_uris(uris), m_pipeNames(pipeNames), m_kinds(kinds) diff --git a/sdrbase/channel/channelapi.h b/sdrbase/channel/channelapi.h index 9be890076..ba25cfc38 100644 --- a/sdrbase/channel/channelapi.h +++ b/sdrbase/channel/channelapi.h @@ -68,6 +68,8 @@ public: virtual const QString& getName() const { return m_name; } virtual qint64 getCenterFrequency() const = 0; //!< Applies to a default stream virtual void setCenterFrequency(qint64 frequency) = 0; + virtual int getChannelSampleRate() const { return 0; } //!< Sample rate after channelization, 0 if unknown + virtual int getAudioSampleRate() const { return 0; } //!< Sample rate of the audio or demodulated output (e.g. "demod" pipe), 0 if none virtual QByteArray serialize() const = 0; virtual bool deserialize(const QByteArray& data) = 0; diff --git a/sdrbase/pipes/datapipes.cpp b/sdrbase/pipes/datapipes.cpp index c27ea3bd7..0406e9539 100644 --- a/sdrbase/pipes/datapipes.cpp +++ b/sdrbase/pipes/datapipes.cpp @@ -53,6 +53,11 @@ void DataPipes::getDataPipes(const QObject *producer, const QString& type, QList return m_registrations.getPipes(producer, type, pipes); } +QList DataPipes::getConnections() +{ + return m_registrations.getConnections(); +} + void DataPipes::startGC() { qDebug("DataPipes::startGC"); diff --git a/sdrbase/pipes/datapipes.h b/sdrbase/pipes/datapipes.h index 2b647c10e..f55968e5a 100644 --- a/sdrbase/pipes/datapipes.h +++ b/sdrbase/pipes/datapipes.h @@ -42,6 +42,7 @@ public: ObjectPipe *registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type); ObjectPipe *unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type); void getDataPipes(const QObject *producer, const QString& type, QList& pipes); + QList getConnections(); private: DataFifoStore m_dataFifoStore; diff --git a/sdrbase/pipes/messagepipes.cpp b/sdrbase/pipes/messagepipes.cpp index da3cc98a3..9a469757f 100644 --- a/sdrbase/pipes/messagepipes.cpp +++ b/sdrbase/pipes/messagepipes.cpp @@ -53,6 +53,11 @@ void MessagePipes::getMessagePipes(const QObject *producer, const QString& type, return m_registrations.getPipes(producer, type, pipes); } +QList MessagePipes::getConnections() +{ + return m_registrations.getConnections(); +} + void MessagePipes::startGC() { qDebug("MessagePipes::startGC"); diff --git a/sdrbase/pipes/messagepipes.h b/sdrbase/pipes/messagepipes.h index a1f2135fb..6995a8dc5 100644 --- a/sdrbase/pipes/messagepipes.h +++ b/sdrbase/pipes/messagepipes.h @@ -42,6 +42,7 @@ public: ObjectPipe *registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type); ObjectPipe *unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type); void getMessagePipes(const QObject *producer, const QString& type, QList& pipes); + QList getConnections(); private: MessageQueueStore m_messageQueueStore; diff --git a/sdrbase/pipes/objectpipe.cpp b/sdrbase/pipes/objectpipe.cpp index eaec8075e..ea058b312 100644 --- a/sdrbase/pipes/objectpipe.cpp +++ b/sdrbase/pipes/objectpipe.cpp @@ -47,9 +47,8 @@ int ObjectPipe::getGCCount() const { int ObjectPipe::decreaseGCCount() { if (m_gcCount > 0) { - return m_gcCount--; + return --m_gcCount; } else { return m_gcCount; } } - diff --git a/sdrbase/pipes/objectpipesregistrations.cpp b/sdrbase/pipes/objectpipesregistrations.cpp index 0b19ebfdb..451820d5d 100644 --- a/sdrbase/pipes/objectpipesregistrations.cpp +++ b/sdrbase/pipes/objectpipesregistrations.cpp @@ -71,6 +71,10 @@ ObjectPipe *ObjectPipesRegistrations::registerProducerToConsumer(const QObject * if (!m_pipeMap.contains(std::make_tuple(producer, consumer, typeId))) { m_pipeMap[std::make_tuple(producer, consumer, typeId)] = pipe; } + // A pipe revived before GC may now belong to a new object at the old + // address, so make sure that object's destruction is also tracked. + connect(producer, SIGNAL(destroyed(QObject*)), this, SLOT(removeProducer(QObject*)), Qt::UniqueConnection); + connect(consumer, SIGNAL(destroyed(QObject*)), this, SLOT(removeConsumer(QObject*)), Qt::UniqueConnection); return pipe; } } @@ -91,14 +95,15 @@ ObjectPipe *ObjectPipesRegistrations::registerProducerToConsumer(const QObject * m_producerAndTypeIdPipes[std::make_tuple(producer, typeId)].push_back(m_pipes.back()); m_pipeMap[std::make_tuple(producer, consumer, typeId)] = m_pipes.back(); - connect(producer, SIGNAL(destroyed(QObject*)), this, SLOT(removeProducer(QObject*))); - connect(consumer, SIGNAL(destroyed(QObject*)), this, SLOT(removeConsumer(QObject*))); + connect(producer, SIGNAL(destroyed(QObject*)), this, SLOT(removeProducer(QObject*)), Qt::UniqueConnection); + connect(consumer, SIGNAL(destroyed(QObject*)), this, SLOT(removeConsumer(QObject*)), Qt::UniqueConnection); return m_pipes.back(); } ObjectPipe *ObjectPipesRegistrations::unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type) { + QMutexLocker mlock(&m_mutex); ObjectPipe *pipe = nullptr; if (m_typeIds.contains(type)) @@ -159,6 +164,18 @@ void ObjectPipesRegistrations::getPipes(const QObject *producer, const QString& } } +QList ObjectPipesRegistrations::getConnections() +{ + QMutexLocker lock(&m_mutex); + QList connections; + for (const ObjectPipe *pipe : m_pipes) { + if (pipe->getGCCount() == 0) { + connections.append({pipe->m_producer, pipe->m_consumer, m_types.value(pipe->m_typeId)}); + } + } + return connections; +} + void ObjectPipesRegistrations::processGC() { QMutexLocker mlock(&m_mutex); @@ -171,6 +188,11 @@ void ObjectPipesRegistrations::processGC() { if ((*itPipe)->decreaseGCCount() == 0) // delete on this pass { + const auto key = std::make_tuple((*itPipe)->m_producer, (*itPipe)->m_consumer, + (*itPipe)->m_typeId); + if (m_pipeMap.value(key, nullptr) == *itPipe) { + m_pipeMap.remove(key); + } m_objectPipeElementsStore->deleteElement((*itPipe)->m_element); delete *itPipe; itPipe = m_pipes.erase(itPipe); @@ -216,7 +238,7 @@ void ObjectPipesRegistrations::removeProducer(QObject *producer) while (itP != m_pipeMap.end()) { - if (std::get<0>(itP.key())) { + if (std::get<0>(itP.key()) == producer) { itP = m_pipeMap.erase(itP); } else { ++itP; diff --git a/sdrbase/pipes/objectpipesregistrations.h b/sdrbase/pipes/objectpipesregistrations.h index d74d232f5..24383e0ae 100644 --- a/sdrbase/pipes/objectpipesregistrations.h +++ b/sdrbase/pipes/objectpipesregistrations.h @@ -37,6 +37,11 @@ class SDRBASE_API ObjectPipesRegistrations : public QObject { Q_OBJECT public: + struct Connection { + const QObject *producer; + const QObject *consumer; + QString type; + }; enum PipeDeletionReason { PipeProducerDeleted, @@ -50,6 +55,7 @@ public: ObjectPipe *registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type); ObjectPipe *unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type); void getPipes(const QObject *producer, const QString& type, QList& pipes); + QList getConnections(); void processGC(); private slots: diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index 65c6e42b7..93e8a5d9c 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -104,6 +104,7 @@ set(sdrgui_SOURCES gui/valuedialz.cpp gui/welcomedialog.cpp gui/workspace.cpp + gui/connectionoverlay.cpp gui/workspaceselectiondialog.cpp gui/workspacewindow.cpp gui/wsspectrumsettingsdialog.cpp @@ -243,6 +244,7 @@ set(sdrgui_HEADERS gui/workspace.h gui/workspaceselectiondialog.h gui/workspacewindow.h + gui/connectionoverlay.h gui/wsspectrumsettingsdialog.h gui/wrappingdatetimeedit.h gui/wrappingdial.h diff --git a/sdrgui/channel/channelgui.cpp b/sdrgui/channel/channelgui.cpp index b93e6466c..cc07bf45b 100644 --- a/sdrgui/channel/channelgui.cpp +++ b/sdrgui/channel/channelgui.cpp @@ -464,6 +464,7 @@ void ChannelGUI::setTitle(const QString& title) void ChannelGUI::setTitleColor(const QColor& c) { + m_indexLabelColor = c; m_indexLabel->setStyleSheet(tr("QLabel { background-color: %1; color: %2; }") .arg(c.name()) .arg(getTitleColor(c).name()) diff --git a/sdrgui/channel/channelgui.h b/sdrgui/channel/channelgui.h index 0043257c6..a0a033da0 100644 --- a/sdrgui/channel/channelgui.h +++ b/sdrgui/channel/channelgui.h @@ -22,6 +22,7 @@ #define SDRGUI_CHANNEL_CHANNELGUI_H_ #include +#include #include #include "gui/qtcompatibility.h" @@ -80,6 +81,7 @@ public: void sizeToContents(); void setTitle(const QString& title); void setTitleColor(const QColor& c); + QColor getIndexLabelColor() const { return m_indexLabelColor; } void setDeviceType(DeviceType type); void setDisplayedame(const QString& name); DeviceType getDeviceType() const { return m_deviceType; } @@ -120,6 +122,7 @@ private: DeviceType m_deviceType; int m_deviceSetIndex; int m_channelIndex; + QColor m_indexLabelColor = QColor(128, 128, 128); RollupContents* m_rollupContents; QLabel *m_indexLabel; diff --git a/sdrgui/device/devicegui.cpp b/sdrgui/device/devicegui.cpp index 43dabe01b..671ff7f8e 100644 --- a/sdrgui/device/devicegui.cpp +++ b/sdrgui/device/devicegui.cpp @@ -448,7 +448,7 @@ void DeviceGUI::setIndex(int index) void DeviceGUI::setDeviceType(DeviceType type) { m_deviceType = type; - m_indexLabel->setStyleSheet(tr("QLabel { background-color: %1; qproperty-alignment: AlignCenter; }").arg(getDeviceTypeColor())); + m_indexLabel->setStyleSheet(tr("QLabel { background-color: %1; qproperty-alignment: AlignCenter; }").arg(getDeviceTypeColor().name())); } void DeviceGUI::setToolTip(const QString& tooltip) @@ -456,18 +456,18 @@ void DeviceGUI::setToolTip(const QString& tooltip) m_titleLabel->setToolTip(tooltip); } -QString DeviceGUI::getDeviceTypeColor() +QColor DeviceGUI::getDeviceTypeColor() const { switch(m_deviceType) { case DeviceRx: - return "rgb(0, 128, 0)"; + return QColor(0, 128, 0); case DeviceTx: - return "rgb(204, 0, 0)"; + return QColor(204, 0, 0); case DeviceMIMO: - return "rgb(0, 0, 192)"; + return QColor(0, 0, 192); default: - return "rgb(128, 128, 128)"; + return QColor(128, 128, 128); } } diff --git a/sdrgui/device/devicegui.h b/sdrgui/device/devicegui.h index d1b3b2fb0..04288bd83 100644 --- a/sdrgui/device/devicegui.h +++ b/sdrgui/device/devicegui.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -73,6 +74,7 @@ public: void sizeToContents(); void setDeviceType(DeviceType type); DeviceType getDeviceType() const { return m_deviceType; } + QColor getDeviceTypeColor() const; void setTitle(const QString& title); QString getTitle() const override; void setDefaultTitle(const QString& title) { m_defaultTitle = title; } @@ -111,7 +113,6 @@ protected slots: private: bool isOnMovingPad(); - QString getDeviceTypeColor(); QString getDeviceTypeTag(); QLabel *m_indexLabel; diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index 0abbe3e40..55986e4c0 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -205,6 +205,11 @@ ChannelGUI *DeviceUISet::getChannelGUIAt(int channelIndex) return m_channelInstanceRegistrations[channelIndex].m_gui; } +int DeviceUISet::getChannelTypeAt(int channelIndex) const +{ + return m_channelInstanceRegistrations[channelIndex].m_channelType; +} + // Serialization is only used for Device and Spectrum settings in a Device preset // To include channels, use a Device Set preset via loadDeviceSetSettings/saveDeviceSetSettings diff --git a/sdrgui/device/deviceuiset.h b/sdrgui/device/deviceuiset.h index 558db2128..bd9e24b81 100644 --- a/sdrgui/device/deviceuiset.h +++ b/sdrgui/device/deviceuiset.h @@ -86,6 +86,7 @@ public: void deleteChannel(int channelIndex); ChannelAPI *getChannelAt(int channelIndex); ChannelGUI *getChannelGUIAt(int channelIndex); + int getChannelTypeAt(int channelIndex) const; // 0: Rx, 1: Tx, 2: MIMO QByteArray serialize() const override; bool deserialize(const QByteArray& data) override; diff --git a/sdrgui/gui/connectionoverlay.cpp b/sdrgui/gui/connectionoverlay.cpp new file mode 100644 index 000000000..904df470b --- /dev/null +++ b/sdrgui/gui/connectionoverlay.cpp @@ -0,0 +1,1610 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "connectionoverlay.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Opacity of links not touching the hovered window. +static constexpr qreal dimmedOpacity = 0.5; +// Channel, device, spectrum and feature title bars: a 2 px border, then a 20 px row. +static constexpr int titleBarMiddle = 12; +static constexpr int titleBarHeight = 24; +static constexpr int anchorOutset = 6; // Routes are planned from just outside a window's frame + +ConnectionOverlay::ConnectionOverlay(QMdiArea *mdi) : + QOpenGLWidget(mdi), + m_mdi(mdi) +{ + // QMdiArea scrolls its viewport children; keep the overlay fixed above the viewport. + setAttribute(Qt::WA_TransparentForMouseEvents); + // Composited last, with its alpha, over everything including OpenGL spectra. + setAttribute(Qt::WA_AlwaysStackOnTop); + QSurfaceFormat surfaceFormat = format(); + surfaceFormat.setAlphaBufferSize(8); + setFormat(surfaceFormat); + setGeometry(mdi->viewport()->geometry()); + mdi->viewport()->installEventFilter(this); + m_animationTimer.setInterval(33); + connect(&m_animationTimer, &QTimer::timeout, this, &ConnectionOverlay::animate); + m_clock.start(); + hide(); +} + +ConnectionOverlay::~ConnectionOverlay() +{ + releaseGL(); +} + +void ConnectionOverlay::initializeGL() +{ + // The context is recreated when the window changes, e.g. a workspace is floated. + connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &ConnectionOverlay::releaseGL, Qt::UniqueConnection); + m_unpremultiply = new QOpenGLShaderProgram(); + m_unpremultiply->addShaderFromSourceCode(QOpenGLShader::Vertex, + "attribute highp vec2 position;\n" + "varying highp vec2 coordinate;\n" + "void main() {\n" + " coordinate = position * 0.5 + 0.5;\n" + " gl_Position = vec4(position, 0.0, 1.0);\n" + "}\n"); + m_unpremultiply->addShaderFromSourceCode(QOpenGLShader::Fragment, + "varying highp vec2 coordinate;\n" + "uniform sampler2D source;\n" + "void main() {\n" + " highp vec4 colour = texture2D(source, coordinate);\n" + " gl_FragColor = colour.a > 0.0 ? vec4(colour.rgb / colour.a, colour.a) : vec4(0.0);\n" + "}\n"); + m_unpremultiply->link(); +} + +void ConnectionOverlay::releaseGL() +{ + if (!m_paintBuffer && !m_resolveBuffer && !m_unpremultiply) { + return; + } + makeCurrent(); + if (m_resolveBuffer != m_paintBuffer) { + delete m_resolveBuffer; + } + delete m_paintBuffer; + delete m_unpremultiply; + m_paintBuffer = nullptr; + m_resolveBuffer = nullptr; + m_unpremultiply = nullptr; + doneCurrent(); +} + +bool ConnectionOverlay::sameConnections(const QList& a, const QList& b) +{ + if (a.size() != b.size()) { + return false; + } + for (int i = 0; i < a.size(); ++i) + { + const Connection& x = a[i]; + const Connection& y = b[i]; + if (x.m_source.data() != y.m_source.data() || x.m_target.data() != y.m_target.data() || + x.m_sourceLabel != y.m_sourceLabel || x.m_targetLabel != y.m_targetLabel || + x.m_flowLabel != y.m_flowLabel || x.m_sourceWorkspace != y.m_sourceWorkspace || + x.m_targetWorkspace != y.m_targetWorkspace || x.m_kind != y.m_kind || + x.m_direction != y.m_direction || x.m_color != y.m_color) { + return false; + } + } + return true; +} + +void ConnectionOverlay::setConnections(const QList& connections) +{ + // Connections are refreshed periodically; only relayout when something changed. + if (sameConnections(connections, m_connections)) { + return; + } + m_connections = connections; + m_windows.clear(); + for (const Connection& connection : m_connections) + { + for (QMdiSubWindow *window : {connection.m_source.data(), connection.m_target.data()}) + { + if (window && !m_windows.contains(window)) { + m_windows.append(window); + } + } + } + watchWindows(); + invalidateLayout(); +} + +void ConnectionOverlay::watchWindows() +{ + // Cached routes depend on the connected windows' geometry. + for (const QPointer& object : m_watched) + { + if (object) { + object->removeEventFilter(this); + } + } + m_watched.clear(); + for (const QPointer& window : m_windows) + { + if (window) + { + window->installEventFilter(this); + m_watched.append(window.data()); + } + } +} + +void ConnectionOverlay::setOverlayVisible(bool visible) +{ + setVisible(visible); + if (visible) + { + setGeometry(m_mdi->viewport()->geometry()); + raise(); + m_layoutDirty = true; + relayout(); + m_animationTimer.start(); + } + else + { + m_animationTimer.stop(); + } +} + +bool ConnectionOverlay::eventFilter(QObject *object, QEvent *event) +{ + const QEvent::Type type = event->type(); + if (object == m_mdi->viewport()) + { + if (type == QEvent::Resize || type == QEvent::Move || type == QEvent::Show) + { + setGeometry(m_mdi->viewport()->geometry()); + if (isVisible()) { + raise(); + } + invalidateLayout(); + } + else if (type == QEvent::ChildAdded || type == QEvent::ChildRemoved) + { + invalidateLayout(); // A window joined or left this workspace. + } + } + else if (type == QEvent::Enter || type == QEvent::Leave) + { + // Qt sends Enter to a window and all its ancestors, and does not send Leave + // when the mouse moves on to a child, so this tracks the whole window. + if (QMdiSubWindow *window = qobject_cast(object)) + { + if (type == QEvent::Enter) { + setHovered(window); + } else if (m_hovered == window) { + setHovered(nullptr); + } + } + } + else if (type == QEvent::Move || type == QEvent::Resize || type == QEvent::Show || + type == QEvent::Hide || type == QEvent::WindowStateChange || type == QEvent::ParentChange) + { + if (type == QEvent::Hide && object == m_hovered) { + setHovered(nullptr); // A hidden window gets no Leave event. + } + invalidateLayout(); // A connected window moved, e.g. when scrolling. + } + return QOpenGLWidget::eventFilter(object, event); +} + +void ConnectionOverlay::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::FontChange || event->type() == QEvent::PaletteChange) { + invalidateLayout(); + } + QOpenGLWidget::changeEvent(event); +} + +void ConnectionOverlay::invalidateLayout() +{ + // Remember the cache is stale even while hidden (e.g. in a background dock tab), + // so showEvent() can relayout. Coalesce bursts (e.g. scrolling) into one relayout. + m_layoutDirty = true; + if (!isVisible() || m_relayoutPending) { + return; + } + m_relayoutPending = true; + QMetaObject::invokeMethod(this, [this]() { relayout(); }, Qt::QueuedConnection); +} + +void ConnectionOverlay::relayout() +{ + m_relayoutPending = false; + if (!isVisible() || !m_layoutDirty) { + return; + } + computeLayout(); + update(); +} + +void ConnectionOverlay::showEvent(QShowEvent *event) +{ + QOpenGLWidget::showEvent(event); + // Changes while hidden were not laid out. The viewport's own Show event arrives + // before this widget is visible, so it cannot trigger the relayout itself. + if (m_layoutDirty) + { + computeLayout(); + update(); + } +} + +static QPointF viewportEdge(const QRectF& bounds, const QPointF& outside) +{ + return QPointF(qBound(bounds.left(), outside.x(), bounds.right()), + qBound(bounds.top(), outside.y(), bounds.bottom())); +} + +static QString scrollArrow(const QRectF& bounds, const QPointF& outside) +{ + if (outside.y() < bounds.top()) { + return QString::fromUtf8("↑"); + } + if (outside.y() > bounds.bottom()) { + return QString::fromUtf8("↓"); + } + if (outside.x() < bounds.left()) { + return QString::fromUtf8("←"); + } + return QString::fromUtf8("→"); +} + +static QPainterPath roundedRoute(const QVector& points) +{ + QPainterPath path(points.first()); + for (int i = 1; i + 1 < points.size(); ++i) + { + const QPointF incoming = points[i] - points[i - 1]; + const QPointF outgoing = points[i + 1] - points[i]; + const qreal incomingLength = QLineF(points[i - 1], points[i]).length(); + const qreal outgoingLength = QLineF(points[i], points[i + 1]).length(); + if (incomingLength < 1 || outgoingLength < 1 || + qAbs(incoming.x() * outgoing.y() - incoming.y() * outgoing.x()) < 0.01) + { + path.lineTo(points[i]); + continue; + } + const qreal radius = qMin(18, qMin(incomingLength, outgoingLength) / 2); + path.lineTo(points[i] - incoming * (radius / incomingLength)); + path.quadTo(points[i], points[i] + outgoing * (radius / outgoingLength)); + } + path.lineTo(points.last()); + return path; +} + +// Evenly spaced points along a path. Flattening once is much cheaper than calling +// QPainterPath::pointAtPercent() per sample, which matters as every candidate route +// of every link is scored on each relayout, e.g. while a window is dragged. +static QVector samplePath(const QPainterPath& path, int samples, qreal& total) +{ + total = 0; + QPolygonF line; + for (const QPolygonF& subpath : path.toSubpathPolygons()) { + line += subpath; + } + QVector points; + if (line.isEmpty()) { + return points; + } + QVector cumulative(line.size(), 0.0); + for (int i = 1; i < line.size(); ++i) { + cumulative[i] = cumulative[i - 1] + QLineF(line[i - 1], line[i]).length(); + } + total = cumulative.last(); + points.reserve(samples + 1); + int segment = 1; + for (int i = 0; i <= samples; ++i) + { + if (line.size() == 1 || total <= 0) + { + points.append(line.first()); + continue; + } + const qreal distance = total * i / samples; + while (segment < line.size() - 1 && cumulative[segment] < distance) { + ++segment; + } + const qreal segmentLength = cumulative[segment] - cumulative[segment - 1]; + const qreal t = segmentLength > 0 ? (distance - cumulative[segment - 1]) / segmentLength : 0.0; + points.append(line[segment - 1] + (line[segment] - line[segment - 1]) * t); + } + return points; +} + +// Cells of a grid over the overlay covered by routes already placed, and which way those +// routes run through them, so later routes take their own lane rather than drawing on +// top of an earlier one. Crossing another route at right angles costs a little. +// Counts per cell let one route be removed and added again cheaply while links are +// rerouted, and a flat grid makes each lookup an array access. +constexpr quint8 occupancyHorizontal = 1; +constexpr quint8 occupancyVertical = 2; +constexpr qreal occupancyCell = 3; // Fine enough to tell lanes 4 px apart, as tiled windows leave narrow gaps + +// Which way a sampled route runs at a point, from its neighbouring samples. +static quint8 occupancyDirection(const QVector& points, int i) +{ + const QPointF delta = points[qMin(i + 1, points.size() - 1)] - points[qMax(i - 1, 0)]; + return qAbs(delta.x()) >= qAbs(delta.y()) ? occupancyHorizontal : occupancyVertical; +} + +class Occupancy +{ +public: + explicit Occupancy(const QSize& size) : + m_columns(qMax(1, qCeil(size.width() / occupancyCell))), + m_rows(qMax(1, qCeil(size.height() / occupancyCell))), + m_horizontal(m_columns * m_rows, 0), + m_vertical(m_columns * m_rows, 0) + {} + + // The cells a route reserves, each as (cell index << 1) | vertical. Computed once + // per route, and passed to add() to add or remove the route. + QVector cells(const QPainterPath& path) const + { + // Reserve a band either side of the route, so a parallel route keeps about + // 16 px away rather than running right beside it. A little under 16 px, so the + // bracket lanes, 16 px apart, are clear of each other's bands. A line of cells + // across the route at every cell along it fills the band. + constexpr int band = 4; + // Only the middle of a route reserves its lane. Near its ends it turns into + // its window, where other routes need to pass too. + constexpr qreal freeEnds = 40; + qreal length = path.length(); + const int samples = qMax(2, qCeil(length / occupancyCell)); + const QVector points = samplePath(path, samples, length); + const qreal step = length / qMax(1, points.size() - 1); + QVector result; + for (int i = 0; i < points.size(); ++i) + { + if (i * step < freeEnds || (points.size() - 1 - i) * step < freeEnds) { + continue; + } + const quint8 direction = occupancyDirection(points, i); + const int column = qFloor(points[i].x() / occupancyCell); + const int row = qFloor(points[i].y() / occupancyCell); + for (int k = -band; k <= band; ++k) + { + const int c = direction == occupancyVertical ? column + k : column; + const int r = direction == occupancyVertical ? row : row + k; + if (c >= 0 && c < m_columns && r >= 0 && r < m_rows) { + result.append((quint32(r * m_columns + c) << 1) | (direction == occupancyVertical ? 1 : 0)); + } + } + } + return result; + } + + // Add (delta 1) or remove (delta -1) a route's cells. + void add(const QVector& cells, int delta) + { + for (quint32 cell : cells) + { + QVector& counts = (cell & 1) ? m_vertical : m_horizontal; + counts[cell >> 1] += delta; + } + m_routes += delta; + } + + bool isEmpty() const { return m_routes <= 0; } + + // The directions of the routes whose bands cover a point. + quint8 directions(const QPointF& point) const + { + const int column = qFloor(point.x() / occupancyCell); + const int row = qFloor(point.y() / occupancyCell); + if (column < 0 || column >= m_columns || row < 0 || row >= m_rows) { + return 0; + } + const int index = row * m_columns + column; + return (m_horizontal[index] ? occupancyHorizontal : 0) | (m_vertical[index] ? occupancyVertical : 0); + } + +private: + int m_columns; + int m_rows; + QVector m_horizontal; + QVector m_vertical; + int m_routes = 0; +}; + +// How good a route is: its length, and how much of it is drawn over windows or +// outside the viewport. Measured in pixels, so a longer detour does not look +// better just because its crossing is a smaller fraction of it. +struct RouteScore +{ + qreal crossing = 0; + qreal length = 0; + int bends = 0; + // A detour is worth taking when it saves a third of its extra length in crossing. + // Each bend costs a little, so simpler shapes win when all else is equal. + qreal value() const { return 3 * crossing + length + 24 * bends; } +}; + +// A route sampled for scoring, with the part of its score that does not depend on +// other routes worked out once, so it can be scored cheaply as they move. +struct ScoredPath +{ + QPainterPath path; + QVector points; + qreal step = 0; + int fixedCount = 0; // Half samples over windows or outside the viewport + RouteScore score; // Ignoring other routes +}; + +static ScoredPath scorePath(const QPainterPath& path, const QRectF& sourceBox, const QRectF& targetBox, + const QVector& obstacles, const QRectF& bounds) +{ + // Crossing covers the two linked windows, and every other window in the + // workspace, so routes prefer gaps and open space. An endpoint can be inside a + // window, e.g. where another window overlaps the edge it is on, or when it was + // pulled onto its own title bar. The route may then leave that window at the start, or + // arrive in it at the end, for up to a short distance. Running along a window's + // border costs fully, as a line on a seam between tiled windows is drawn on top + // of their frames; running just inside an edge costs half. + constexpr int samples = 80; + constexpr qreal freeRun = 30; // Pixels a route may run inside its start or end window + ScoredPath scored; + scored.path = path; + scored.points = samplePath(path, samples, scored.score.length); + const QVector& points = scored.points; + if (points.isEmpty() || scored.score.length <= 0) { + return scored; + } + const qreal step = scored.score.length / samples; + scored.step = step; + const int last = points.size() - 1; + const int maxFree = qCeil(freeRun / step); + qreal left = points.first().x(), right = left, top = points.first().y(), bottom = top; + for (const QPointF& point : points) + { + left = qMin(left, point.x()); + right = qMax(right, point.x()); + top = qMin(top, point.y()); + bottom = qMax(bottom, point.y()); + } + const QRectF pathBounds(QPointF(left, top), QPointF(right, bottom)); + auto boxSamples = [&](const QRectF& box, bool edgeDiscount) -> int { + if (box.isEmpty()) { + return 0; + } + // The window, plus a thin strip either side of its border. + constexpr qreal border = 4; + const QRectF body = box.adjusted(-border, -border, border, border); + if (!body.intersects(pathBounds.adjusted(-1, -1, 1, 1))) { + return 0; // Most windows are nowhere near a given route + } + int first = 0; + while (first <= last && first < maxFree && body.contains(points[first])) { + ++first; // Leading run inside, leaving the start window + } + int end = last; + while (end >= first && last - end < maxFree && body.contains(points[end])) { + --end; // Trailing run inside, arriving in the end window + } + // Counted in half samples. On the border itself counts fully, so routes do + // not follow seams between windows. Running vertically just inside a left or + // right edge, where the lanes beside a column run, is much less intrusive + // than cutting across the middle, so it counts half. Along the top edge it + // would cover the title bar, so that counts fully. + constexpr qreal edgeBand = 64; // Room for four lanes 16 px apart + const QRectF inner = box.adjusted(border, border, -border, -border); + const QRectF deep = inner.adjusted(edgeBand, 0, -edgeBand, 0); + int count = 0; + for (int i = first; i <= end; ++i) + { + if (!body.contains(points[i])) { + continue; + } + const bool besideEdge = edgeDiscount && inner.contains(points[i]) && !deep.contains(points[i]) && + occupancyDirection(points, i) == occupancyVertical; + count += besideEdge ? 1 : 2; + } + return count; + }; + // Crossing the linked windows counts double, with no discount near their + // edges: a line over a linked window looks like it connects there. + int count = 2 * (boxSamples(sourceBox, false) + boxSamples(targetBox, false)); + for (const QRectF& obstacle : obstacles) { + count += boxSamples(obstacle, true); + } + // Parts outside the viewport cannot be seen, so they count as crossing too. + const QRectF visible = bounds.adjusted(-4, -4, 4, 4); + for (const QPointF& point : points) + { + if (!visible.contains(point)) { + count += 2; + } + } + scored.fixedCount = count; + scored.score.crossing = count * step / 2; // Half samples to pixels + // Corners of rounded routes, and the direct curve, are cubic segments. + for (int e = 0; e < path.elementCount(); ++e) + { + if (path.elementAt(e).type == QPainterPath::CurveToElement) { + ++scored.score.bends; + } + } + return scored; +} + +// The score of a sampled route among the routes already placed. +static RouteScore scoreAmong(const ScoredPath& scored, const Occupancy *occupied) +{ + RouteScore score = scored.score; + if (!occupied || occupied->isEmpty() || scored.points.isEmpty() || score.length <= 0) { + return score; + } + // Running alongside an earlier route, in the same direction, counts as crossing + // too; crossing it at right angles costs a little, so crossings are avoided when + // that is cheap, e.g. by nesting two links the other way round. Sharing its line costs a lot: more than running + // into the edge of a neighbouring window, so parallel links keep their spacing + // even where windows are tiled with narrow gaps. Ends are exempt, as several + // links can leave the same anchor. + constexpr qreal exemptEnds = 20; + constexpr int overlapWeight = 4; + const QVector& points = scored.points; + const qreal step = scored.step; + const int last = points.size() - 1; + int count = scored.fixedCount; + for (int i = 0; i <= last; ++i) + { + if (i * step < exemptEnds || (last - i) * step < exemptEnds) { + continue; + } + const quint8 occupiedDirections = occupied->directions(points[i]); + if (occupiedDirections & occupancyDirection(points, i)) { + count += 2 * overlapWeight; + } else if (occupiedDirections) { + count += 4; // Across the other route's band: about a 150 px detour per crossing + } + } + score.crossing = count * step / 2; // Half samples to pixels + return score; +} + +static RouteScore scoreRoute(const QPainterPath& path, const QRectF& sourceBox, const QRectF& targetBox, + const QVector& obstacles, const QRectF& bounds, const Occupancy *occupied) +{ + return scoreAmong(scorePath(path, sourceBox, targetBox, obstacles, bounds), occupied); +} + +// The simplest route: a curve, or for both ends on the same side a bracket. +static QPainterPath directPath(const QPointF& from, const QPointF& to, int fromSide, int toSide, + const QRectF& sourceBox, const QRectF& targetBox) +{ + constexpr qreal labelLead = 20; // Straight run out from the window before any turn + const QPointF curveFrom = from + QPointF(fromSide * labelLead, 0); + const QPointF curveTo = to + QPointF(toSide * labelLead, 0); + const QPointF delta = curveTo - curveFrom; + // With both ends on the same side, e.g. windows stacked in a column, a large + // handle bulges far into neighbouring windows, so keep the curve tight. + const bool sameSide = fromSide != 0 && fromSide == toSide; + const qreal handle = qBound(32, qAbs(delta.x()) * 0.35 + qAbs(delta.y()) * 0.3, sameSide ? 40 : 180); + const QPointF firstControl = fromSide == 0 ? curveFrom + delta * 0.3 : + curveFrom + QPointF(fromSide * handle, 0); + const QPointF lastControl = toSide == 0 ? curveTo - delta * 0.3 : + curveTo + QPointF(toSide * handle, 0); + QPainterPath direct(from); + if (sameSide) + { + // Both ends on the same side, e.g. windows stacked in a column: a straight + // bracket 16 px out from the windows. A curve here bulges across several + // lanes, leaving no room for the links beside it. + const qreal edge = fromSide > 0 ? qMax(qMax(from.x(), to.x()), qMax(sourceBox.right(), targetBox.right())) : + qMin(qMin(from.x(), to.x()), qMin(sourceBox.left(), targetBox.left())); + const qreal laneX = edge + fromSide * 16; + direct = roundedRoute({from, QPointF(laneX, from.y()), QPointF(laneX, to.y()), to}); + } + else + { + if (fromSide != 0) { + direct.lineTo(curveFrom); + } + direct.cubicTo(firstControl, lastControl, curveTo); + if (toSide != 0) { + direct.lineTo(to); + } + } + return direct; +} + +// Routes around windows, for when the direct route crosses them. +static QVector detourPaths(const QPointF& from, const QPointF& to, int fromSide, int toSide, + const QRectF& sourceBox, const QRectF& targetBox, const QRectF& bounds) +{ + const bool sameSide = fromSide != 0 && fromSide == toSide; + QVector detours; + auto consider = [&](const QPainterPath& candidate) { + detours.append(candidate); + }; + + // Both ends on the same side: a bracket that steps out, runs along the gap + // beside the windows, and steps back in. + if (sameSide) + { + // Measured from the outermost window edge, so both windows are cleared. At + // least 16 px out, so the link visibly steps away from the window first; then + // every 16 px for parallel lanes. + const qreal edge = fromSide > 0 ? qMax(qMax(from.x(), to.x()), qMax(sourceBox.right(), targetBox.right())) : + qMin(qMin(from.x(), to.x()), qMin(sourceBox.left(), targetBox.left())); + for (qreal out : {16.0, 32.0, 48.0, 64.0, 80.0}) + { + const qreal laneX = edge + fromSide * out; + if (laneX >= bounds.left() + 2 && laneX <= bounds.right() - 2) { + consider(roundedRoute({from, QPointF(laneX, from.y()), QPointF(laneX, to.y()), to})); + } + } + } + + // Elbow routes: out from the source, one vertical run, and into the target. The + // simplest shape after the direct curve, tried with the vertical run just past + // the source, just before the target, midway, and along either window's frame. + { + constexpr qreal elbowLead = 24; + QVector elbowXs; + // Midway, except for same-side links: their anchors share an edge, so the + // midpoint runs straight down beside the windows without stepping out. + if (!sameSide) { + elbowXs.append((from.x() + to.x()) / 2); + } + // Along the windows' frames, with room for parallel lanes 16 px apart. + for (qreal lane : {16.0, 24.0, 32.0, 40.0, 48.0, 56.0, 64.0}) { + elbowXs << sourceBox.left() - lane << sourceBox.right() + lane + << targetBox.left() - lane << targetBox.right() + lane; + } + if (fromSide != 0) { + elbowXs.append(from.x() + fromSide * elbowLead); + } + if (toSide != 0) { + elbowXs.append(to.x() + toSide * elbowLead); + } + for (qreal elbowX : elbowXs) + { + if (elbowX >= bounds.left() + 2 && elbowX <= bounds.right() - 2) { + consider(roundedRoute({from, QPointF(elbowX, from.y()), QPointF(elbowX, to.y()), to})); + } + } + } + + // Try an outer route around both windows, and nearer horizontal lanes. + constexpr qreal clearance = 24; + const bool separatedBelow = sourceBox.bottom() + 2 * clearance < targetBox.top(); + const bool separatedAbove = targetBox.bottom() + 2 * clearance < sourceBox.top(); + const qreal laneY = separatedBelow ? (sourceBox.bottom() + targetBox.top()) / 2 : + (separatedAbove ? (targetBox.bottom() + sourceBox.top()) / 2 : + qMax(sourceBox.bottom(), targetBox.bottom()) + clearance); + const qreal rightX = qMax(sourceBox.right(), + separatedBelow || separatedAbove ? sourceBox.right() : targetBox.right()) + clearance; + const qreal leftX = qMin(to.x() - 30, targetBox.left() - clearance); + QVector route; + route.append(from); + const qreal topY = qMin(sourceBox.top(), targetBox.top()) - clearance; + if (topY >= bounds.top() + 4) + { + route.append(QPointF(from.x() + clearance, from.y())); + route.append(QPointF(from.x() + clearance, topY)); + route.append(QPointF(rightX, topY)); + } + else + { + route.append(QPointF(rightX, from.y())); + } + route.append(QPointF(rightX, laneY)); + route.append(QPointF(leftX, laneY)); + route.append(QPointF(leftX, to.y())); + route.append(to); + consider(roundedRoute(route)); + const qreal exitXs[] = { + from.x() + clearance, + qMax(from.x() + clearance, targetBox.right() + clearance), + qMax(from.x() + clearance, sourceBox.right() + clearance) + }; + const qreal laneYs[] = { + topY, sourceBox.top() - clearance, targetBox.top() - clearance, + laneY, sourceBox.bottom() + clearance, targetBox.bottom() + clearance + }; + for (qreal candidateY : laneYs) + { + if (candidateY < bounds.top() + 4 || candidateY > bounds.bottom() - 4 || + qAbs(candidateY - from.y()) < 6) { + continue; + } + for (qreal exitX : exitXs) + { + // A downward exit within the source would run through its controls. + const bool insideSourceX = exitX > sourceBox.left() && exitX < sourceBox.right(); + const bool throughSourceBody = insideSourceX && + qMax(qMin(from.y(), candidateY), sourceBox.top() + 26) < + qMin(qMax(from.y(), candidateY), sourceBox.bottom()); + if (throughSourceBody) { + continue; + } + consider(roundedRoute({ + from, + QPointF(exitX, from.y()), + QPointF(exitX, candidateY), + QPointF(leftX, candidateY), + QPointF(leftX, to.y()), + to + })); + } + } + // A source directly below its target has no upper lane. Turn just below + // the source title and leave on the left, instead of circling both windows. + if (targetBox.bottom() <= sourceBox.top() + clearance) { + const qreal leftExitX = qMin(sourceBox.left(), targetBox.left()) - clearance; + const qreal turnY = qMax(from.y() + clearance, targetBox.bottom() + clearance); + if (leftExitX >= bounds.left() + 4 && turnY <= bounds.bottom() - 4) { + consider(roundedRoute({ + from, + QPointF(from.x() + clearance, from.y()), + QPointF(from.x() + clearance, turnY), + QPointF(leftExitX, turnY), + QPointF(leftExitX, to.y()), + to + })); + } + } + return detours; +} + +// Every route for a link, direct first, sampled for scoring. +static QVector routeCandidates(const QPointF& from, const QPointF& to, int fromSide, int toSide, + const QRectF& sourceBox, const QRectF& targetBox, const QRectF& bounds, + const QVector& obstacles) +{ + QVector candidates; + candidates.append(scorePath(directPath(from, to, fromSide, toSide, sourceBox, targetBox), + sourceBox, targetBox, obstacles, bounds)); + if (!sourceBox.isEmpty() && !targetBox.isEmpty()) + { + for (const QPainterPath& detour : detourPaths(from, to, fromSide, toSide, sourceBox, targetBox, bounds)) { + candidates.append(scorePath(detour, sourceBox, targetBox, obstacles, bounds)); + } + } + return candidates; +} + +// The best of a link's candidate routes among the routes already placed. Take the +// best scoring route: short, and clear of windows. Crossing can be unavoidable (e.g. +// an endpoint covered by the other window), and then the direct route is usually +// clearer than a long detour around both windows. Returns its index, and its score. +static int bestCandidate(const QVector& candidates, bool sameSide, const Occupancy *occupied, + qreal& bestScore) +{ + const RouteScore directScore = scoreAmong(candidates.first(), occupied); + bestScore = directScore.value(); + if (directScore.crossing <= 0 && !sameSide) { + return 0; // Clear, and nothing is shorter. A same-side bracket clears the + // outermost window, so a lane nearer the other may be shorter. + } + int best = 0; + for (int i = 1; i < candidates.size(); ++i) + { + const qreal score = scoreAmong(candidates[i], occupied).value(); + if (score < bestScore) + { + best = i; + bestScore = score; + } + } + return best; +} + +static QPainterPath connectionPath(const QPointF& from, const QPointF& to, + int fromSide, int toSide, const QRectF& sourceBox, + const QRectF& targetBox, const QRectF& bounds, + const QVector& obstacles, const Occupancy *occupied = nullptr) +{ + const bool sameSide = fromSide != 0 && fromSide == toSide; + const QPainterPath direct = directPath(from, to, fromSide, toSide, sourceBox, targetBox); + if (sourceBox.isEmpty() || targetBox.isEmpty()) { + return direct; + } + // The direct route alone first, as it is often clear, sparing the detours. + const RouteScore directScore = scoreRoute(direct, sourceBox, targetBox, obstacles, bounds, occupied); + if (directScore.crossing <= 0 && !sameSide) { + return direct; + } + QPainterPath bestRoute = direct; + qreal bestScore = directScore.value(); + for (const QPainterPath& detour : detourPaths(from, to, fromSide, toSide, sourceBox, targetBox, bounds)) + { + const qreal detourScore = scoreRoute(detour, sourceBox, targetBox, obstacles, bounds, occupied).value(); + if (detourScore < bestScore) + { + bestRoute = detour; + bestScore = detourScore; + } + } + return bestRoute; +} + +void ConnectionOverlay::computeLayout() +{ + m_layoutDirty = false; + m_routes.clear(); + const QList localWindows = m_mdi->subWindowList(); + const QRectF bounds = rect().adjusted(8, 8, -8, -8); + const QPoint viewportOffset = m_mdi->viewport()->pos() - pos(); + const QFontMetrics metrics(font()); + QVector labelObstacles; // Each label as it is placed + // Stubs to other workspaces that leave the same anchor fan out vertically, so + // their lines and labels do not sit on top of each other. + QHash, int> stubCounts; + const qreal stubSpacing = metrics.height() + 14; + auto fanOffset = [&](QMdiSubWindow *window, int side) -> qreal { + const int n = stubCounts[qMakePair(window, side)]++; + const int step = (n + 1) / 2; // 0, 1, 1, 2, 2, ... + return (n % 2 ? step : -step) * stubSpacing; // 0, +1, -1, +2, -2, ... + }; + // Stubs placed above (vertical < 0) or below (vertical > 0) a window stack away + // from it. Returns false, claiming nothing, if the next slot and its label would + // not fit inside the viewport, or if the space it needs is covered by another window. + auto claimVertical = [&](QMdiSubWindow *window, int side, int vertical, qreal anchorX, qreal markerWidth, qreal& tipY) -> bool { + const QPair key(window, side * (vertical < 0 ? 2 : 3)); // Separate from the level fan + const QRectF box = QRectF(window->geometry().translated(viewportOffset)); + const qreal offset = 16 + stubCounts.value(key) * stubSpacing; + const qreal y = vertical < 0 ? box.top() - offset : box.bottom() + offset; + const qreal labelHeight = metrics.height() + 4; + if (y - labelHeight / 2 < bounds.top() + 4 || y + labelHeight / 2 > bounds.bottom() - 4) { + return false; + } + // Stub and label, whichever side of the tip the label ends up on. + const qreal bandTop = vertical < 0 ? y - labelHeight / 2 : box.bottom(); + const qreal bandBottom = vertical < 0 ? box.top() : y + labelHeight / 2; + const QRectF band(anchorX - markerWidth - 40, bandTop, 2 * markerWidth + 80, bandBottom - bandTop); + for (QMdiSubWindow *other : localWindows) + { + if (other != window && other->isVisible() && !other->isMinimized() && + band.intersects(QRectF(other->geometry().translated(viewportOffset)))) { + return false; + } + } + stubCounts[key]++; + tipY = y; + return true; + }; + // A window can be connected on either side, just outside its left edge (side -1) + // or its right edge (side 1), level with the middle of its title bar. Each link + // uses whichever sides give it the best route. The overlay is a sibling of the + // scrolling viewport, so MDI window coordinates are translated. + auto anchorFor = [&viewportOffset](QMdiSubWindow *window, int side) -> QPointF { + const QPoint inWindow(side < 0 ? -anchorOutset : window->width() + anchorOutset, titleBarMiddle); + return QPointF(window->geometry().topLeft() + inWindow + viewportOffset); + }; + + // A flow label sits beside its route's midpoint, so labels of fanned stubs separate too. + auto placeFlowLabel = [&](Route& route) { + const qreal labelWidth = metrics.horizontalAdvance(route.m_flowLabel) + 10; + const qreal labelHeight = metrics.height() + 4; + const QPointF midpoint = route.m_path.pointAtPercent(0.5); + const qreal labelX = midpoint.x() - labelWidth / 2; + const qreal labelY = midpoint.y() - labelHeight - 6; + route.m_flowLabelRect = QRectF(qBound(bounds.left() + 4, labelX, + qMax(bounds.left() + 4, bounds.right() - labelWidth - 4)), + qBound(bounds.top() + 4, labelY, + qMax(bounds.top() + 4, bounds.bottom() - labelHeight - 4)), + labelWidth, labelHeight); + }; + + // Route links so they can keep out of each other's way: stubs to other workspaces + // first, as their place is fixed, then links within this workspace from the + // smallest vertical span up. Short links take the lanes nearest the windows, + // and longer ones nest around them without crossing. + Occupancy occupancy(size()); + // Candidate routes of each link within this workspace. They do not change while + // other links move, so they are made and sampled once, and only their scores + // among the other links are worked out again when rerouting. + struct Reroute + { + ScoredPath current; + QPointF anchors[2][2]; // [source/target][left/right] + QVector candidates[2][2]; // [source side][target side], empty where an anchor is off screen + QVector> cells[2][2]; // Occupancy cells of each candidate, made when needed + }; + struct Choice + { + int si = -1; + int ti = -1; + int index = -1; + qreal score = 0; + }; + QVector reroutes; // Parallel to m_routes + QVector order; + QVector orderKey(m_connections.size(), 0); + for (int i = 0; i < m_connections.size(); ++i) + { + const Connection& connection = m_connections[i]; + order.append(i); + if (connection.m_source && connection.m_target && localWindows.contains(connection.m_source.data()) && + localWindows.contains(connection.m_target.data())) { + orderKey[i] = 1 + qAbs(connection.m_source->geometry().top() - connection.m_target->geometry().top()); + } + } + std::stable_sort(order.begin(), order.end(), [&orderKey](int a, int b) { return orderKey[a] < orderKey[b]; }); + + for (int connectionIndex : order) + { + const Connection& connection = m_connections[connectionIndex]; + if (!connection.m_source || !connection.m_target) { + continue; + } + const bool sourceLocal = localWindows.contains(connection.m_source.data()); + const bool targetLocal = localWindows.contains(connection.m_target.data()); + if (!sourceLocal && !targetLocal) { + continue; + } + if (sourceLocal && (connection.m_source->parentWidget() != m_mdi->viewport() || + !connection.m_source->isVisible() || connection.m_source->isMinimized())) { + continue; + } + if (targetLocal && (connection.m_target->parentWidget() != m_mdi->viewport() || + !connection.m_target->isVisible() || connection.m_target->isMinimized())) { + continue; + } + // Anchors on both sides of each local endpoint; index 0 is the left, 1 the right. + // A side can be used when its anchor is on screen. If neither is, e.g. a window + // wider than the viewport, but its title bar is visible, pull the left anchor + // inside, onto the ID label end of the title bar, rather than dropping the + // window's links. + auto placeAnchors = [&](QMdiSubWindow *window, QPointF anchors[2], bool on[2]) { + for (int i = 0; i < 2; ++i) + { + anchors[i] = anchorFor(window, i ? 1 : -1); + on[i] = bounds.contains(anchors[i]); + } + const QRectF titleBar(QPointF(window->geometry().topLeft() + viewportOffset), + QSizeF(window->width(), titleBarHeight)); + if (!on[0] && !on[1] && titleBar.intersects(bounds)) + { + anchors[0] = viewportEdge(bounds, anchors[0]); + on[0] = true; + } + }; + QPointF sourceAnchors[2], targetAnchors[2]; + bool sourceOn[2] = {false, false}, targetOn[2] = {false, false}; + if (sourceLocal) { + placeAnchors(connection.m_source.data(), sourceAnchors, sourceOn); + } + if (targetLocal) { + placeAnchors(connection.m_target.data(), targetAnchors, targetOn); + } + const bool sourceVisible = sourceOn[0] || sourceOn[1]; + const bool targetVisible = targetOn[0] || targetOn[1]; + // This workspace draws a link only when at least one endpoint is on screen. + if (!sourceVisible && !targetVisible) { + continue; + } + + Route route; + Reroute reroute; + QPointF markerEdge; + bool crossWorkspace = false; + int labelDirection = 0; // Which side of a stub's tip its label goes + route.m_sourceBox = sourceVisible ? + QRectF(connection.m_source->geometry().translated(viewportOffset)) : QRectF(); + route.m_targetBox = targetVisible ? + QRectF(connection.m_target->geometry().translated(viewportOffset)) : QRectF(); + for (QMdiSubWindow *window : localWindows) + { + if (window != connection.m_source && window != connection.m_target && window->isVisible() && + !window->isMinimized() && window->parentWidget() == m_mdi->viewport()) { + route.m_obstacles.append(QRectF(window->geometry().translated(viewportOffset))); + } + } + + // Nearest on-screen anchor of an endpoint to a point. + auto nearestSide = [](const QPointF anchors[2], const bool on[2], const QPointF& point) -> int { + if (!on[0] || !on[1]) { + return on[1] ? 1 : -1; + } + return QLineF(anchors[1], point).length() < QLineF(anchors[0], point).length() ? 1 : -1; + }; + + // A stub to another workspace beside a local window: from the side with more + // room, level with the title bar; else above or below the window; else as far + // out as the viewport allows on the roomier side. + auto placeStub = [&](QMdiSubWindow *window, const QPointF anchors[2], const bool on[2], + qreal markerWidth, QPointF& local, QPointF& tip, int& side) { + const qreal stubLength = 90; + const qreal roomLeft = on[0] ? anchors[0].x() - bounds.left() : -1; + const qreal roomRight = on[1] ? bounds.right() - anchors[1].x() : -1; + const int roomier = roomRight >= roomLeft ? 1 : -1; + for (int s : {roomier, -roomier}) + { + if ((s > 0 ? roomRight : roomLeft) >= stubLength + markerWidth + 10) + { + side = labelDirection = s; + local = anchors[s > 0 ? 1 : 0]; + const qreal y = qBound(bounds.top() + 4, local.y() + fanOffset(window, s), bounds.bottom() - 4); + tip = QPointF(local.x() + s * stubLength, y); + return; + } + } + side = roomier; + local = anchors[side > 0 ? 1 : 0]; + qreal y = 0; + if (claimVertical(window, side, -1, local.x(), markerWidth, y) || + claimVertical(window, side, 1, local.x(), markerWidth, y)) + { + tip = QPointF(side > 0 ? qMin(bounds.right() - 4, local.x() + 30) : qMax(bounds.left() + 4, local.x() - 30), y); + const bool fitsOutwards = side > 0 ? tip.x() + 6 + markerWidth <= bounds.right() - 4 : + tip.x() - 6 - markerWidth >= bounds.left() + 4; + labelDirection = fitsOutwards ? side : -side; + return; + } + labelDirection = side; + y = qBound(bounds.top() + 4, local.y() + fanOffset(window, side), bounds.bottom() - 4); + tip = QPointF(side > 0 ? qMin(bounds.right() - markerWidth - 10, local.x() + stubLength) : + qMax(bounds.left() + markerWidth + 10, local.x() - stubLength), y); + }; + + // Scrolled endpoints point to a viewport edge. An endpoint in another + // workspace instead gets a short labeled stub beside the local window. + if (sourceVisible && targetVisible) + { + route.m_local = true; + for (int i = 0; i < 2; ++i) + { + reroute.anchors[0][i] = sourceAnchors[i]; + reroute.anchors[1][i] = targetAnchors[i]; + } + // Try each pair of sides; keep the best scoring route. + Choice best; + for (int si = 0; si < 2; ++si) + { + for (int ti = 0; ti < 2; ++ti) + { + if (!sourceOn[si] || !targetOn[ti]) { + continue; + } + QVector& candidates = reroute.candidates[si][ti]; + candidates = routeCandidates(sourceAnchors[si], targetAnchors[ti], si ? 1 : -1, ti ? 1 : -1, + route.m_sourceBox, route.m_targetBox, bounds, route.m_obstacles); + reroute.cells[si][ti].resize(candidates.size()); + qreal score = 0; + const int index = bestCandidate(candidates, si == ti, &occupancy, score); + if (best.index < 0 || score < best.score) { + best = Choice{si, ti, index, score}; + } + } + } + reroute.current = reroute.candidates[best.si][best.ti][best.index]; + route.m_from = sourceAnchors[best.si]; + route.m_to = targetAnchors[best.ti]; + route.m_fromSide = best.si ? 1 : -1; + route.m_toSide = best.ti ? 1 : -1; + route.m_path = reroute.current.path; + } + else if (sourceVisible && targetLocal) + { + route.m_to = viewportEdge(bounds, targetAnchors[0]); + route.m_fromSide = nearestSide(sourceAnchors, sourceOn, route.m_to); + route.m_from = sourceAnchors[route.m_fromSide > 0 ? 1 : 0]; + markerEdge = route.m_to; + route.m_marker = scrollArrow(bounds, targetAnchors[0]) + " " + connection.m_targetLabel; + } + else if (targetVisible && sourceLocal) + { + route.m_from = viewportEdge(bounds, sourceAnchors[0]); + route.m_toSide = nearestSide(targetAnchors, targetOn, route.m_from); + route.m_to = targetAnchors[route.m_toSide > 0 ? 1 : 0]; + markerEdge = route.m_from; + route.m_marker = scrollArrow(bounds, sourceAnchors[0]) + " " + connection.m_sourceLabel; + } + else if (sourceVisible) + { + route.m_marker = QString("W%1 · %2").arg(connection.m_targetWorkspace).arg(connection.m_targetLabel); + if (!connection.m_flowLabel.isEmpty()) { + route.m_marker += " · " + connection.m_flowLabel; // One label per stub, at its tip + } + placeStub(connection.m_source.data(), sourceAnchors, sourceOn, metrics.horizontalAdvance(route.m_marker) + 8, + route.m_from, route.m_to, route.m_fromSide); + route.m_stubTip = 1; + crossWorkspace = true; + } + else + { + route.m_marker = QString("W%1 · %2").arg(connection.m_sourceWorkspace).arg(connection.m_sourceLabel); + if (!connection.m_flowLabel.isEmpty()) { + route.m_marker += " · " + connection.m_flowLabel; // One label per stub, at its tip + } + placeStub(connection.m_target.data(), targetAnchors, targetOn, metrics.horizontalAdvance(route.m_marker) + 8, + route.m_to, route.m_from, route.m_toSide); + route.m_stubTip = -1; + crossWorkspace = true; + } + const QPointF& from = route.m_from; + const QPointF& to = route.m_to; + + route.m_source = connection.m_source.data(); + route.m_target = connection.m_target.data(); + route.m_color = connection.m_color.isValid() ? connection.m_color.lighter(150) : + (connection.m_kind == PipeLink ? QColor(238, 183, 77) : QColor(56, 204, 228)); + route.m_kind = connection.m_kind; + route.m_direction = connection.m_direction; + if (route.m_path.isEmpty()) { + route.m_path = connectionPath(from, to, route.m_fromSide, route.m_toSide, + route.m_sourceBox, route.m_targetBox, bounds, route.m_obstacles, &occupancy); + } + route.m_length = route.m_path.length(); + + if (!connection.m_flowLabel.isEmpty() && !crossWorkspace) // Stubs include it in their marker + { + route.m_flowLabel = connection.m_flowLabel; + placeFlowLabel(route); + } + + if (!route.m_marker.isEmpty()) + { + const qreal labelWidth = metrics.horizontalAdvance(route.m_marker) + 8; + const qreal labelHeight = metrics.height() + 4; + const QPointF remoteAnchor = sourceVisible ? to : from; + // A stub's label continues from its tip, usually in the direction the stub goes. + const qreal labelX = crossWorkspace ? + (labelDirection > 0 ? remoteAnchor.x() + 6 : remoteAnchor.x() - labelWidth - 6) : + (markerEdge.x() >= bounds.right() - 1 ? + markerEdge.x() - labelWidth - 8 : markerEdge.x() + 8); + const qreal labelY = crossWorkspace ? + remoteAnchor.y() - labelHeight / 2 : + (markerEdge.y() >= bounds.bottom() - 1 ? + markerEdge.y() - labelHeight - 8 : markerEdge.y() + 8); + route.m_markerRect = QRectF(qBound(bounds.left() + 4, labelX, + qMax(bounds.left() + 4, bounds.right() - labelWidth - 4)), + qBound(bounds.top() + 4, labelY, + qMax(bounds.top() + 4, bounds.bottom() - labelHeight - 4)), + labelWidth, labelHeight); + } + + route.m_cells = occupancy.cells(route.m_path); + occupancy.add(route.m_cells, 1); + m_routes.append(route); + reroutes.append(reroute); + } + + // Reroute links within this workspace with every other link in place, so the order + // they were first placed in does not decide which gets the better lane, e.g. + // whether two links from one device nest without crossing. + // Links are taken out of the occupancy while they are rerouted, and put back after. + auto scoreCurrent = [&](int r) -> qreal { + return scoreAmong(reroutes[r].current, &occupancy).value(); + }; + // Best route for a link around the others in the occupancy, trying each pair of sides. + auto routeAmong = [&](int r) -> Choice { + Choice best; + for (int si = 0; si < 2; ++si) + { + for (int ti = 0; ti < 2; ++ti) + { + const QVector& candidates = reroutes[r].candidates[si][ti]; + if (candidates.isEmpty()) { + continue; + } + qreal score = 0; + const int index = bestCandidate(candidates, si == ti, &occupancy, score); + if (best.index < 0 || score < best.score) { + best = Choice{si, ti, index, score}; + } + } + } + return best; + }; + auto cellsOf = [&](int r, const Choice& choice) -> const QVector& { + QVector& cells = reroutes[r].cells[choice.si][choice.ti][choice.index]; + if (cells.isEmpty()) { + cells = occupancy.cells(reroutes[r].candidates[choice.si][choice.ti][choice.index].path); + } + return cells; + }; + auto scoreChoice = [&](int r, const Choice& choice) -> qreal { + return scoreAmong(reroutes[r].candidates[choice.si][choice.ti][choice.index], &occupancy).value(); + }; + auto apply = [&](int r, const Choice& choice) { + Route& route = m_routes[r]; + Reroute& reroute = reroutes[r]; + reroute.current = reroute.candidates[choice.si][choice.ti][choice.index]; + route.m_from = reroute.anchors[0][choice.si]; + route.m_to = reroute.anchors[1][choice.ti]; + route.m_fromSide = choice.si ? 1 : -1; + route.m_toSide = choice.ti ? 1 : -1; + route.m_path = reroute.current.path; + route.m_length = route.m_path.length(); + route.m_cells = cellsOf(r, choice); + }; + for (int pass = 0; pass < 2; ++pass) + { + bool changed = false; + // Each link on its own. + for (int r = 0; r < m_routes.size(); ++r) + { + if (!m_routes[r].m_local) { + continue; + } + occupancy.add(m_routes[r].m_cells, -1); + const Choice choice = routeAmong(r); + if (choice.index >= 0 && choice.score < scoreCurrent(r) - 1) + { + apply(r, choice); + changed = true; + } + occupancy.add(m_routes[r].m_cells, 1); + } + // Nearby pairs that get in each other's way, placed again in the opposite order. + // Rerouting one link at a time cannot swap two links' lanes, as each would first + // have to overlap the other. + for (int a = 0; a < m_routes.size(); ++a) + { + for (int b = 0; b < m_routes.size(); ++b) + { + const Route& routeA = m_routes[a]; + const Route& routeB = m_routes[b]; + if (a == b || !routeA.m_local || !routeB.m_local || + !routeA.m_path.boundingRect().adjusted(-32, -32, 32, 32).intersects(routeB.m_path.boundingRect())) { + continue; + } + occupancy.add(routeA.m_cells, -1); + occupancy.add(routeB.m_cells, -1); + const qreal aAlone = scoreCurrent(a); + const qreal bAlone = scoreCurrent(b); + occupancy.add(routeB.m_cells, 1); + const qreal aWithB = scoreCurrent(a); + occupancy.add(routeB.m_cells, -1); + occupancy.add(routeA.m_cells, 1); + const qreal bWithA = scoreCurrent(b); + occupancy.add(routeA.m_cells, -1); + if (aWithB > aAlone + 1 || bWithA > bAlone + 1) + { + const Choice newB = routeAmong(b); + occupancy.add(cellsOf(b, newB), 1); + const Choice newA = routeAmong(a); + occupancy.add(cellsOf(b, newB), -1); + occupancy.add(cellsOf(a, newA), 1); + const qreal newBScore = scoreChoice(b, newB); + occupancy.add(cellsOf(a, newA), -1); + if (newA.score + newBScore < aWithB + bWithA - 1) + { + apply(a, newA); + apply(b, newB); + changed = true; + } + } + occupancy.add(m_routes[a].m_cells, 1); + occupancy.add(m_routes[b].m_cells, 1); + } + } + if (!changed) { + break; + } + } + for (Route& route : m_routes) + { + if (route.m_local && !route.m_flowLabel.isEmpty()) { + placeFlowLabel(route); + } + } + + // Resolve remaining label overlaps. Place workspace and scroll markers first, as + // they sit at route ends, then flow labels. Each label moves up or down by whole + // label heights to the nearest free position inside the viewport. + auto placeLabel = [&](QRectF& label) { + if (label.isEmpty()) { + return; + } + const qreal step = label.height() + 4; + for (int attempt = 0; attempt < 16; ++attempt) + { + const int n = (attempt + 1) / 2; + const QRectF candidate = label.translated(0, (attempt % 2 ? n : -n) * step); + if (candidate.top() < bounds.top() + 4 || candidate.bottom() > bounds.bottom() - 4) { + continue; + } + bool clear = true; + for (const QRectF& obstacle : labelObstacles) + { + if (candidate.adjusted(-2, -2, 2, 2).intersects(obstacle)) + { + clear = false; + break; + } + } + if (clear) + { + label = candidate; + break; + } + } + labelObstacles.append(label); + }; + for (Route& route : m_routes) + { + const qreal before = route.m_markerRect.center().y(); + placeLabel(route.m_markerRect); + const qreal dy = route.m_markerRect.center().y() - before; + if (route.m_stubTip != 0 && !qFuzzyIsNull(dy)) + { + // Keep a moved stub label on the end of its own line. + QPointF& tip = route.m_stubTip > 0 ? route.m_to : route.m_from; + tip.ry() += dy; + route.m_path = connectionPath(route.m_from, route.m_to, route.m_fromSide, route.m_toSide, + route.m_sourceBox, route.m_targetBox, bounds, route.m_obstacles); + route.m_length = route.m_path.length(); + } + } + for (Route& route : m_routes) { + placeLabel(route.m_flowLabelRect); + } + + // End each link on its windows' borders, so it is clear which of two windows + // side by side it belongs to. The anchors it was routed from are just outside, + // so routes keep clear of the frames; they are extended straight in from there. + auto onBorder = [](const QPointF& anchor, int side, const QRectF& box) -> QPointF { + const qreal edge = side < 0 ? box.left() : box.right(); + if (side == 0 || box.isEmpty() || qAbs(anchor.x() - (edge + side * anchorOutset)) > 0.5 || + qAbs(anchor.y() - (box.top() + titleBarMiddle)) > 0.5) { + return anchor; // Not at a window, e.g. a stub's tip, or pulled onto the viewport edge + } + return QPointF(edge, anchor.y()); + }; + for (Route& route : m_routes) + { + const QPointF from = onBorder(route.m_from, route.m_fromSide, route.m_sourceBox); + const QPointF to = onBorder(route.m_to, route.m_toSide, route.m_targetBox); + if (from != route.m_from) + { + QPainterPath path(from); + path.connectPath(route.m_path); + route.m_path = path; + route.m_from = from; + } + if (to != route.m_to) + { + route.m_path.lineTo(to); + route.m_to = to; + } + route.m_length = route.m_path.length(); + } + updateHighlight(); +} + +QVector ConnectionOverlay::pulses() const +{ + QVector result; + for (const Route& route : m_routes) + { + if (route.m_direction == NoDirection || route.m_length <= 32 || isDimmed(route)) { + continue; + } + const int flowCount = route.m_direction == BothDirections ? 2 : 1; + const int pulsesPerFlow = route.m_length > 360 ? 2 : 1; + for (int flow = 0; flow < flowCount; ++flow) + { + const bool reverse = route.m_direction == Reverse || (route.m_direction == BothDirections && flow == 1); + for (int pulse = 0; pulse < pulsesPerFlow; ++pulse) + { + qreal progress = m_phase + qreal(pulse) / pulsesPerFlow; + if (progress >= 1.0) { + progress -= 1.0; + } + if (reverse) { + progress = 1.0 - progress; + } + const qreal tailProgress = qBound(0, progress + (reverse ? 0.025 : -0.025), 1); + result.append({route.m_path.pointAtPercent(tailProgress), route.m_path.pointAtPercent(progress), route.m_color}); + } + } + } + return result; +} + +void ConnectionOverlay::animate() +{ + if (!isVisible()) { + return; // Workspace is a background tab, or minimized. + } + // An OpenGL widget repaints in full, so only repaint when something is moving. + m_phase = (m_clock.elapsed() % 2400) / 2400.0; + if (!pulses().isEmpty()) { + update(); + } +} + +void ConnectionOverlay::paintGL() +{ + // Paint current geometry rather than a stale cache. + if (m_layoutDirty) { + computeLayout(); + } + QOpenGLFunctions *gl = context()->functions(); + const qreal ratio = devicePixelRatioF(); + const QSize pixels = size() * ratio; + if (!m_paintBuffer || m_paintBuffer->size() != pixels) + { + if (m_resolveBuffer != m_paintBuffer) { + delete m_resolveBuffer; + } + delete m_paintBuffer; + // QPainter's OpenGL engine needs multisampling for smooth lines, and a + // stencil buffer for paths. Without framebuffer blits, paint unsampled. + QOpenGLFramebufferObjectFormat bufferFormat; + bufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + const bool blit = QOpenGLFramebufferObject::hasOpenGLFramebufferBlit(); + bufferFormat.setSamples(blit ? 4 : 0); + m_paintBuffer = new QOpenGLFramebufferObject(pixels, bufferFormat); + m_resolveBuffer = blit ? new QOpenGLFramebufferObject(pixels) : m_paintBuffer; + } + + m_paintBuffer->bind(); + gl->glViewport(0, 0, pixels.width(), pixels.height()); + gl->glClearColor(0, 0, 0, 0); + gl->glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + { + QOpenGLPaintDevice device(pixels); + device.setDevicePixelRatio(ratio); + QPainter painter(&device); + paintRoutes(painter); + } + if (m_resolveBuffer != m_paintBuffer) { + QOpenGLFramebufferObject::blitFramebuffer(m_resolveBuffer, m_paintBuffer); + } + + // Copy into the widget, converting to straight alpha. + gl->glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject()); + gl->glViewport(0, 0, pixels.width(), pixels.height()); + gl->glDisable(GL_BLEND); + gl->glDisable(GL_SCISSOR_TEST); + gl->glDisable(GL_DEPTH_TEST); + gl->glDisable(GL_STENCIL_TEST); + gl->glBindBuffer(GL_ARRAY_BUFFER, 0); + gl->glActiveTexture(GL_TEXTURE0); + gl->glBindTexture(GL_TEXTURE_2D, m_resolveBuffer->texture()); + m_unpremultiply->bind(); + m_unpremultiply->setUniformValue("source", 0); + static const GLfloat quad[] = {-1, -1, 1, -1, -1, 1, 1, 1}; + const int position = m_unpremultiply->attributeLocation("position"); + m_unpremultiply->enableAttributeArray(position); + m_unpremultiply->setAttributeArray(position, quad, 2); + gl->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + m_unpremultiply->disableAttributeArray(position); + m_unpremultiply->release(); +} + +void ConnectionOverlay::paintRoutes(QPainter& painter) +{ + painter.setRenderHint(QPainter::Antialiasing); + + for (const Route& route : m_routes) + { + const QColor& color = route.m_color; + const bool highlighted = m_highlightActive && !isDimmed(route); + painter.setOpacity(isDimmed(route) ? dimmedOpacity : 1.0); + // drawPath also fills with the current brush. The preceding edge draws + // its endpoint dots with a solid brush, so clear it before every path. + painter.setBrush(Qt::NoBrush); + painter.setPen(QPen(QColor(color.red(), color.green(), color.blue(), highlighted ? 90 : 35), highlighted ? 8 : 6, + Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.drawPath(route.m_path); + painter.setPen(QPen(QColor(color.red(), color.green(), color.blue(), 180), 2.2, + route.m_kind == PipeLink ? Qt::DashLine : Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.drawPath(route.m_path); + painter.setBrush(QColor(color.red(), color.green(), color.blue(), 220)); + painter.setPen(QPen(palette().window().color(), 1.5)); + painter.drawEllipse(route.m_from, 4, 4); + painter.drawEllipse(route.m_to, 4, 4); + } + painter.setOpacity(1.0); + + for (const Pulse& pulse : pulses()) + { + const QColor& color = pulse.m_color; + painter.setBrush(Qt::NoBrush); + painter.setPen(QPen(QColor(color.red(), color.green(), color.blue(), 210), 4, + Qt::SolidLine, Qt::RoundCap)); + painter.drawLine(pulse.m_tail, pulse.m_head); + painter.setPen(Qt::NoPen); + painter.setBrush(QColor(color.red(), color.green(), color.blue(), 130)); + painter.drawEllipse(pulse.m_head, 7, 7); + painter.setBrush(QColor(255, 255, 255, 245)); + painter.drawEllipse(pulse.m_head, 3, 3); + } + + for (const Route& route : m_routes) + { + painter.setOpacity(isDimmed(route) ? dimmedOpacity : 1.0); + if (!route.m_flowLabel.isEmpty()) + { + painter.setPen(QPen(route.m_color, 1)); + painter.setBrush(QColor(24, 28, 32, 235)); + painter.drawRoundedRect(route.m_flowLabelRect, 3, 3); + painter.setPen(Qt::white); + painter.drawText(route.m_flowLabelRect, Qt::AlignCenter, route.m_flowLabel); + } + if (!route.m_marker.isEmpty()) + { + painter.setPen(Qt::NoPen); + painter.setBrush(QColor(24, 28, 32, 235)); + painter.drawRoundedRect(route.m_markerRect, 3, 3); + painter.setPen(Qt::white); + painter.drawText(route.m_markerRect, Qt::AlignCenter, route.m_marker); + } + } +} + +void ConnectionOverlay::setHovered(QMdiSubWindow *window) +{ + if (m_hovered == window) { + return; + } + m_hovered = window; + const bool wasActive = m_highlightActive; + updateHighlight(); + if (wasActive || m_highlightActive) { + update(); // Opacity changes affect every route + } +} + +void ConnectionOverlay::updateHighlight() +{ + // Only highlight when the hovered window has links drawn in this workspace; + // hovering an unconnected window leaves every link at full strength. + bool active = false; + if (m_hovered) + { + for (const Route& route : m_routes) + { + if (route.m_source == m_hovered || route.m_target == m_hovered) + { + active = true; + break; + } + } + } + m_highlightActive = active; +} + +bool ConnectionOverlay::isDimmed(const Route& route) const +{ + return m_highlightActive && route.m_source != m_hovered && route.m_target != m_hovered; +} diff --git a/sdrgui/gui/connectionoverlay.h b/sdrgui/gui/connectionoverlay.h new file mode 100644 index 000000000..08061574c --- /dev/null +++ b/sdrgui/gui/connectionoverlay.h @@ -0,0 +1,139 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRGUI_GUI_CONNECTIONOVERLAY_H_ +#define SDRGUI_GUI_CONNECTIONOVERLAY_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class QMdiArea; +class QMdiSubWindow; +class QOpenGLFramebufferObject; +class QOpenGLShaderProgram; +class QPainter; + +// A non-interactive drawing layer above one workspace's MDI windows, showing connections between windows. +// It is an OpenGL widget stacked on top, so it blends over OpenGL spectra too; a translucent +// ordinary widget shows black where it overlaps them. +class ConnectionOverlay : public QOpenGLWidget +{ + Q_OBJECT +public: + enum Kind { DeviceLink, PipeLink }; + enum Direction { NoDirection, Forward, Reverse, BothDirections }; + + struct Connection { + QPointer m_source; + QPointer m_target; + QString m_sourceLabel; + QString m_targetLabel; + QString m_flowLabel; + int m_sourceWorkspace = -1; + int m_targetWorkspace = -1; + Kind m_kind = DeviceLink; + Direction m_direction = Forward; + QColor m_color; + }; + + explicit ConnectionOverlay(QMdiArea *mdi); + ~ConnectionOverlay() override; + void setConnections(const QList& connections); + void setOverlayVisible(bool visible); + +protected: + bool eventFilter(QObject *object, QEvent *event) override; + void changeEvent(QEvent *event) override; + void showEvent(QShowEvent *event) override; + void initializeGL() override; + void paintGL() override; + +private: + // Geometry for one drawn connection, cached until windows move or connections change. + struct Route { + QPainterPath m_path; + qreal m_length = 0; + QPointF m_from; + QPointF m_to; + QColor m_color; + Kind m_kind = DeviceLink; + Direction m_direction = Forward; + QString m_flowLabel; + QRectF m_flowLabelRect; + QString m_marker; + QRectF m_markerRect; + // Inputs to connectionPath(), kept so a stub can be rerouted to follow its label. + int m_fromSide = 0; + int m_toSide = 0; + QRectF m_sourceBox; + QRectF m_targetBox; + QVector m_obstacles; // Other windows the route should avoid + int m_stubTip = 0; // Cross-workspace stub: 1 if m_to is its tip, -1 if m_from is + QMdiSubWindow *m_source = nullptr; // For hover highlighting; compared, never dereferenced + QMdiSubWindow *m_target = nullptr; + bool m_local = false; // Both ends in this workspace, so it can be rerouted around other links + QVector m_cells; // Lane cells the route reserves, see Occupancy in the .cpp + }; + struct Pulse { + QPointF m_tail; + QPointF m_head; + QColor m_color; + }; + + QMdiArea *m_mdi; + QList m_connections; + QList> m_windows; // Windows with links, to watch for moves + QList> m_watched; + QVector m_routes; + qreal m_phase = 0; + QPointer m_hovered; // Window under the mouse, if it has links + bool m_highlightActive = false; // Dim links that do not touch m_hovered + bool m_layoutDirty = true; // Cached routes no longer match the windows + bool m_relayoutPending = false; // A queued relayout() is outstanding + QElapsedTimer m_clock; + QTimer m_animationTimer; + // QPainter draws premultiplied alpha, but Qt composites an OpenGL widget as straight + // alpha, which darkens anything translucent. So paint offscreen, then copy through a + // shader that converts to straight alpha. + QOpenGLFramebufferObject *m_paintBuffer = nullptr; // Multisampled, painted by QPainter + QOpenGLFramebufferObject *m_resolveBuffer = nullptr; // Plain texture the shader reads + QOpenGLShaderProgram *m_unpremultiply = nullptr; + + static bool sameConnections(const QList& a, const QList& b); + void watchWindows(); + void invalidateLayout(); + void relayout(); + void computeLayout(); + QVector pulses() const; + void animate(); + void setHovered(QMdiSubWindow *window); + void updateHighlight(); + bool isDimmed(const Route& route) const; + void paintRoutes(QPainter& painter); + void releaseGL(); +}; + +#endif // SDRGUI_GUI_CONNECTIONOVERLAY_H_ diff --git a/sdrgui/gui/workspace.cpp b/sdrgui/gui/workspace.cpp index 2c890f8fb..3db330632 100644 --- a/sdrgui/gui/workspace.cpp +++ b/sdrgui/gui/workspace.cpp @@ -57,6 +57,7 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : m_mdi->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); m_mdi->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setWidget(m_mdi); + m_connectionOverlay = new ConnectionOverlay(m_mdi); setWindowTitle(tr("W%1").arg(m_index)); setObjectName(tr("W%1").arg(m_index)); @@ -180,6 +181,15 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : m_tabSubWindows->setToolTip("Display sub windows in tabs"); m_tabSubWindows->setFixedSize(20, 20); + m_connectionOverlayButton = new ButtonSwitch(); + m_connectionOverlayButton->setCheckable(true); + m_connectionOverlayButton->setFixedSize(20, 20); + // Must match the shortcut created in MainWindow. NativeText shows Cmd on macOS. + m_connectionOverlayButton->setToolTip(QString("Show device, channel, spectrum and feature connections (%1)") + .arg(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_L).toString(QKeySequence::NativeText))); + QIcon connectionOverlayIcon(":/wiring.png"); + m_connectionOverlayButton->setIcon(connectionOverlayIcon); + m_normalButton = new QPushButton(); QIcon normalIcon(":/dock.png"); m_normalButton->setIcon(normalIcon); @@ -211,6 +221,7 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : m_titleBarLayout->addWidget(m_stackVerticalSubWindows); m_titleBarLayout->addWidget(m_stackSubWindows); m_titleBarLayout->addWidget(m_tabSubWindows); + m_titleBarLayout->addWidget(m_connectionOverlayButton); m_titleBarLayout->addStretch(1); m_titleBarLayout->addWidget(m_mcpServerButton); #ifndef ANDROID @@ -315,6 +326,9 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : &Workspace::tabSubWindows ); + QObject::connect(m_connectionOverlayButton, &ButtonSwitch::clicked, + this, &Workspace::connectionOverlayToggled); + QObject::connect( m_normalButton, &QPushButton::clicked, @@ -357,6 +371,7 @@ Workspace::~Workspace() delete m_closeButton; delete m_normalButton; delete m_tabSubWindows; + delete m_connectionOverlayButton; delete m_stackSubWindows; delete m_stackVerticalSubWindows; delete m_tileSubWindows; @@ -389,6 +404,17 @@ void Workspace::setIndex(int index) m_titleLabel->setText(windowTitle()); } +void Workspace::setConnectionOverlayVisible(bool visible) +{ + m_connectionOverlayButton->doToggle(visible); + m_connectionOverlay->setOverlayVisible(visible); +} + +void Workspace::setConnections(const QList& connections) +{ + m_connectionOverlay->setConnections(connections); +} + QList Workspace::getSubWindowList() const { return m_mdi->subWindowList(); @@ -915,6 +941,9 @@ void Workspace::subWindowActivated(QMdiSubWindow *activatedWindow) emit focused(this); } + if (m_connectionOverlay->isVisible()) { + m_connectionOverlay->raise(); + } if (activatedWindow && m_tabSubWindows->isChecked()) { // Move other windows out of the way @@ -1025,6 +1054,9 @@ void Workspace::addToMdiArea(QMdiSubWindow *sub) connect(sub, &QObject::destroyed, this, &Workspace::layoutSubWindows); m_mdi->addSubWindow(sub); sub->show(); + if (m_connectionOverlay->isVisible()) { + m_connectionOverlay->raise(); + } // Auto-stack when sub-window's widgets are rolled up ChannelGUI *channel = qobject_cast(sub); if (channel) { diff --git a/sdrgui/gui/workspace.h b/sdrgui/gui/workspace.h index ff3c90381..3aff0293b 100644 --- a/sdrgui/gui/workspace.h +++ b/sdrgui/gui/workspace.h @@ -28,6 +28,7 @@ #include "export.h" #include "featureadddialog.h" #include "device/deviceapi.h" +#include "connectionoverlay.h" class QHBoxLayout; class QLabel; @@ -70,6 +71,8 @@ public: void updateStartStopButton(bool checked); void updateMCPServerButton(bool available, bool running, int port); QToolButton *getMenuButton() const { return m_menuButton; } + void setConnectionOverlayVisible(bool visible); + void setConnections(const QList& connections); private: int m_index; @@ -90,6 +93,8 @@ private: QPushButton *m_stackVerticalSubWindows; QPushButton *m_stackSubWindows; ButtonSwitch *m_tabSubWindows; + ButtonSwitch *m_connectionOverlayButton; + ConnectionOverlay *m_connectionOverlay; QWidget *m_titleBar; QHBoxLayout *m_titleBarLayout; QLabel *m_titleLabel; @@ -132,6 +137,7 @@ public slots: signals: void focused(Workspace *workspace); // The user is working in this workspace + void connectionOverlayToggled(bool visible); void addRxDevice(Workspace *inWorkspace, int deviceIndex); void addTxDevice(Workspace *inWorkspace, int deviceIndex); void addMIMODevice(Workspace *inWorkspace, int deviceIndex); diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 32f73729b..cf1321c93 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,7 @@ #include #include #include +#include #include "device/devicegui.h" #include "device/deviceapi.h" @@ -78,6 +80,7 @@ #include "gui/fftdialog.h" #include "gui/fftwisdomdialog.h" #include "gui/workspace.h" +#include "gui/connectionoverlay.h" #include "gui/featurepresetsdialog.h" #include "gui/devicesetpresetsdialog.h" #include "gui/commandsdialog.h" @@ -131,6 +134,7 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse m_currentWorkspace(nullptr), m_mainCore(MainCore::instance()), m_dspEngine(DSPEngine::instance()), + m_connectionOverlayEnabled(false), m_lastEngineState(DeviceAPI::StNotStarted), m_dateTimeWidget(nullptr), m_showSystemWidget(nullptr), @@ -207,6 +211,16 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); m_statusTimer.start(1000); + m_connectionOverlayRefreshTimer.setInterval(500); + connect(&m_connectionOverlayRefreshTimer, &QTimer::timeout, + this, &MainWindow::updateConnectionOverlays); + // One application-wide shortcut: a shortcut on each workspace's button would be + // ambiguous with several docked workspaces, and would miss floating ones. + QShortcut *connectionOverlayShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_L), this); + connectionOverlayShortcut->setContext(Qt::ApplicationShortcut); + connect(connectionOverlayShortcut, &QShortcut::activated, this, [this]() { + setConnectionOverlayEnabled(!m_connectionOverlayEnabled); + }); splash->showStatusMessage("load settings...", Qt::white); qDebug() << "MainWindow::MainWindow: load settings..."; @@ -298,6 +312,7 @@ MainWindow::~MainWindow() { qDebug() << "MainWindow::~MainWindow"; + setConnectionOverlayEnabled(false); m_statusTimer.stop(); m_apiServer->stop(); delete m_apiServer; @@ -765,6 +780,7 @@ void RemoveDeviceSetFSM::removeSink() void RemoveDeviceSetFSM::removeUI() { qDebug() << "RemoveDeviceSetFSM::removeUI"; + m_mainWindow->m_connectionOverlayRefreshTimer.stop(); // Remove transitions, as we will delete the object (DSPDevice*Engine) that is the source of these signals m_states[0]->removeTransition(m_t1); @@ -784,8 +800,10 @@ void RemoveDeviceSetFSM::removeUI() } // As for features: QObject only drops an object's connections in ~QObject, so a signal can // still reach the GUI after the derived destructor has deleted its ui object. - QObject::disconnect(m_deviceUISet->m_deviceAPI, nullptr, m_deviceUISet->m_deviceGUI, nullptr); - delete m_deviceUISet->m_deviceGUI; + DeviceGUI *deviceGUI = m_deviceUISet->m_deviceGUI; + m_deviceUISet->m_deviceGUI = nullptr; + QObject::disconnect(m_deviceUISet->m_deviceAPI, nullptr, deviceGUI, nullptr); + delete deviceGUI; m_deviceUISet->m_deviceAPI->resetSamplingDeviceId(); if (!m_deviceMIMOEngine) { m_deviceUISet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists @@ -870,6 +888,11 @@ void RemoveDeviceSetFSM::removeDeviceSet() ); } + if (m_mainWindow->m_connectionOverlayEnabled) + { + m_mainWindow->updateConnectionOverlays(); + m_mainWindow->m_connectionOverlayRefreshTimer.start(); + } emit m_mainWindow->m_mainCore->deviceSetRemoved(m_deviceSetIndex); } @@ -913,6 +936,7 @@ RemoveAllWorkspacesFSM::RemoveAllWorkspacesFSM(MainWindow *mainWindow, QObject * void RemoveAllWorkspacesFSM::removeDeviceSets() { qDebug() << "RemoveAllWorkspacesFSM::removeDeviceSets"; + m_mainWindow->setConnectionOverlayEnabled(false); m_removeAllDeviceSetsFSM->start(); } @@ -932,6 +956,7 @@ void RemoveAllWorkspacesFSM::removeWorkspaces() LoadConfigurationFSM::LoadConfigurationFSM(MainWindow *mainWindow, const Configuration *configuration, QProgressDialog *waitBox, QObject *parent) : MainWindowFSM(mainWindow, parent), m_configuration(configuration), + m_overlayEnabledBeforeLoad(mainWindow->m_connectionOverlayEnabled), m_waitBox(waitBox) { // Create FSM @@ -1194,6 +1219,8 @@ void LoadConfigurationFSM::restoreGeometry() if (m_waitBox) { m_waitBox->setValue(100); } + // Re-enable only now, so the refresh timer doesn't walk device sets while they are being created. + m_mainWindow->setConnectionOverlayEnabled(m_overlayEnabledBeforeLoad); } InitFSM::InitFSM(MainWindow *mainWindow, SDRangelSplash *splash, bool loadDefault, bool showConfigs, QObject *parent) : @@ -2260,6 +2287,7 @@ void MainWindow::createStatusBar() void MainWindow::closeEvent(QCloseEvent *closeEvent) { qDebug("MainWindow::closeEvent"); + m_connectionOverlayRefreshTimer.stop(); if (!m_settingsSaved) { @@ -2274,6 +2302,8 @@ void MainWindow::closeEvent(QCloseEvent *closeEvent) m_settingsSaved = true; } + setConnectionOverlayEnabled(false); + if (m_deviceUIs.size() > 0) { CloseFSM *fsm = new CloseFSM(this); @@ -2675,11 +2705,239 @@ void MainWindow::handleWorkspaceVisibility(Workspace *workspace, bool visibility m_currentWorkspace = workspace; } +void MainWindow::setConnectionOverlayEnabled(bool enabled) +{ + m_connectionOverlayEnabled = enabled; + for (Workspace *workspace : m_workspaces) { + workspace->setConnectionOverlayVisible(enabled); + } + if (enabled) + { + updateConnectionOverlays(); + m_connectionOverlayRefreshTimer.start(); + } + else + { + m_connectionOverlayRefreshTimer.stop(); + } +} + +void MainWindow::updateConnectionOverlays() +{ + if (!m_connectionOverlayEnabled) { + return; + } + + struct Endpoint { + QMdiSubWindow *window; + QString label; + int workspace; + bool feature; + QColor linkColor; + const ChannelAPI *channel; // For its audio sample rate, if a channel + }; + QHash endpoints; + QList connections; + + // Compact sample rate for labels, e.g. 2.048M or 48k. Empty if unknown. + auto formatRate = [](int rate) -> QString { + if (rate <= 0) { + return QString(); + } + return rate >= 1000000 ? QString::number(rate / 1e6, 'g', 4) + "M" : QString::number(rate / 1e3, 'g', 4) + "k"; + }; + // IQ label with the rates at each end in flow order, e.g. "IQ 2.048M → 48k". + auto iqLabel = [&formatRate](int fromRate, int toRate) -> QString { + const QString from = formatRate(fromRate); + const QString to = formatRate(toRate); + if (from.isEmpty() || to.isEmpty() || from == to) { + return QString("IQ %1").arg(from.isEmpty() ? to : from).trimmed(); + } + return QString("IQ %1 → %2").arg(from, to); + }; + auto audioLabel = [&formatRate](const Endpoint& source) -> QString { + const QString rate = source.channel ? formatRate(source.channel->getAudioSampleRate()) : QString(); + return rate.isEmpty() ? QString("Audio") : QString("Audio %1").arg(rate); + }; + + for (DeviceUISet *deviceUI : m_deviceUIs) + { + if (!deviceUI || !deviceUI->m_deviceGUI) { + continue; + } + DeviceGUI *device = deviceUI->m_deviceGUI; + const QString tag = device->getDeviceType() == DeviceGUI::DeviceTx ? "T" : + (device->getDeviceType() == DeviceGUI::DeviceMIMO ? "M" : "R"); + const QString deviceLabel = QString("%1:%2").arg(tag).arg(deviceUI->getIndex()); + const QColor deviceColor = device->getDeviceTypeColor(); + const Endpoint deviceEndpoint{device, deviceLabel, device->getWorkspaceIndex(), false, deviceColor, nullptr}; + endpoints.insert(device, deviceEndpoint); + endpoints.insert(deviceUI->m_deviceAPI, deviceEndpoint); + + // Device sample rate for a stream. MIMO devices have one per stream. + DeviceAPI *deviceAPI = deviceUI->m_deviceAPI; + auto deviceRate = [deviceAPI](bool tx, int stream) -> int { + if (DeviceSampleMIMO *mimo = deviceAPI->getSampleMIMO()) + { + const unsigned int streams = tx ? mimo->getNbSinkStreams() : mimo->getNbSourceStreams(); + if (stream < 0 || (unsigned int) stream >= streams) { + return 0; + } + return tx ? mimo->getSinkSampleRate(stream) : mimo->getSourceSampleRate(stream); + } + if (DeviceSampleSource *source = deviceAPI->getSampleSource()) { + return source->getSampleRate(); + } + if (DeviceSampleSink *sink = deviceAPI->getSampleSink()) { + return sink->getSampleRate(); + } + return 0; + }; + + auto appendDeviceConnection = [&](QMdiSubWindow *target, const QString& label, + int targetWorkspace, ConnectionOverlay::Direction direction, + const QString& flowLabel, const QColor& color) { + if (!target) { + return; + } + ConnectionOverlay::Connection connection; + connection.m_source = device; + connection.m_target = target; + connection.m_sourceLabel = deviceLabel; + connection.m_targetLabel = label; + connection.m_flowLabel = flowLabel; + connection.m_sourceWorkspace = device->getWorkspaceIndex(); + connection.m_targetWorkspace = targetWorkspace; + connection.m_direction = direction; + connection.m_color = color; + connections.append(connection); + }; + + // The spectrum always displays samples from the device, including for Tx, where + // the channels feed the device. + const ConnectionOverlay::Direction spectrumDirection = ConnectionOverlay::Forward; + if (deviceUI->m_mainSpectrumGUI) + { + const int spectrumRate = deviceRate(device->getDeviceType() == DeviceGUI::DeviceTx, 0); + appendDeviceConnection(deviceUI->m_mainSpectrumGUI, deviceLabel + " spectrum", + deviceUI->m_mainSpectrumGUI->getWorkspaceIndex(), spectrumDirection, iqLabel(spectrumRate, spectrumRate), deviceColor); + } + for (int channelIndex = 0; channelIndex < deviceUI->getNumberOfChannels(); ++channelIndex) + { + ChannelGUI *channel = deviceUI->getChannelGUIAt(channelIndex); + if (!channel) { + continue; + } + const QString channelLabel = QString("%1%2:%3").arg(tag).arg(deviceUI->getIndex()).arg(channel->getIndex()); + const int type = deviceUI->getChannelTypeAt(channelIndex); + const ConnectionOverlay::Direction direction = type == 1 ? ConnectionOverlay::Reverse : + (type == 2 ? ConnectionOverlay::BothDirections : ConnectionOverlay::Forward); + ChannelAPI *channelAPI = deviceUI->getChannelAt(channelIndex); + // Show the device rate and the channel's rate after (de)channelization, + // in the direction the IQ flows: device to Rx channel, Tx channel to device. + // A channel that reports no rate (e.g. stopped) shows neither, as the device + // rate alone would look like the channel's. + const bool tx = type == 1; + const int chanRate = channelAPI ? channelAPI->getChannelSampleRate() : 0; + const int devRate = chanRate > 0 ? deviceRate(tx, channelAPI->getStreamIndex()) : 0; + // A Tx channel feeds the device, so its link takes the channel's colour. + appendDeviceConnection(channel, channelLabel, channel->getWorkspaceIndex(), direction, + chanRate <= 0 ? QString("IQ") : (tx ? iqLabel(chanRate, devRate) : iqLabel(devRate, chanRate)), + tx ? channel->getIndexLabelColor() : deviceColor); + const Endpoint endpoint{channel, channelLabel, channel->getWorkspaceIndex(), false, + channel->getIndexLabelColor(), channelAPI}; + endpoints.insert(channel, endpoint); + if (channelAPI) { + endpoints.insert(channelAPI, endpoint); + } + } + } + + for (FeatureUISet *featureUI : m_featureUIs) + { + if (!featureUI) { + continue; + } + for (int featureIndex = 0; featureIndex < featureUI->getNumberOfFeatures(); ++featureIndex) + { + FeatureGUI *featureGUI = featureUI->getFeatureGuiAt(featureIndex); + if (!featureGUI) { + continue; + } + const Endpoint endpoint{featureGUI, QString("F%1").arg(featureGUI->getIndex()), + featureGUI->getWorkspaceIndex(), true, QColor(), nullptr}; + endpoints.insert(featureGUI, endpoint); + if (Feature *feature = featureUI->getFeatureAt(featureIndex)) { + endpoints.insert(feature, endpoint); + } + } + } + + QList pipes = m_mainCore->getDataPipes().getConnections(); + pipes.append(m_mainCore->getMessagePipes().getConnections()); + // A message pipe may terminate at a helper QObject owned by a channel or + // feature. Walk its parent chain to find the window represented in the graph. + auto endpointFor = [&endpoints](const QObject *object) -> const Endpoint* { + for (const QObject *current = object; current; current = current->parent()) + { + auto found = endpoints.constFind(current); + if (found != endpoints.constEnd()) { + return &found.value(); + } + } + return nullptr; + }; + QHash> pipeConnectionIndices; + for (const ObjectPipesRegistrations::Connection& pipe : pipes) + { + // A feature taking a channel's demodulated audio, e.g. the Denoiser, may only + // subscribe to the "demod" pipe while running, but keeps its "reportdemod" pipe. + const bool audio = pipe.type == "demod" || pipe.type == "reportdemod"; + const Endpoint *sourceEndpoint = endpointFor(pipe.producer); + const Endpoint *targetEndpoint = endpointFor(pipe.consumer); + if (!sourceEndpoint || !targetEndpoint) { + continue; + } + const Endpoint& source = *sourceEndpoint; + const Endpoint& target = *targetEndpoint; + if (source.window == target.window || (!source.feature && !target.feature)) { + continue; + } + const int existingIndex = pipeConnectionIndices.value(source.window).value(target.window, -1); + if (existingIndex >= 0) + { + if (audio) { + connections[existingIndex].m_flowLabel = audioLabel(source); + } + continue; + } + ConnectionOverlay::Connection connection; + connection.m_source = source.window; + connection.m_target = target.window; + connection.m_sourceLabel = source.label; + connection.m_targetLabel = target.label; + connection.m_flowLabel = audio ? audioLabel(source) : QString("Data"); + connection.m_sourceWorkspace = source.workspace; + connection.m_targetWorkspace = target.workspace; + connection.m_kind = ConnectionOverlay::PipeLink; + connection.m_direction = ConnectionOverlay::Forward; + connection.m_color = source.linkColor.isValid() ? source.linkColor : target.linkColor; + pipeConnectionIndices[source.window].insert(target.window, connections.size()); + connections.append(connection); + } + + for (Workspace *workspace : m_workspaces) { + workspace->setConnections(connections); + } +} + void MainWindow::addWorkspace() { int workspaceIndex = m_workspaces.size(); auto *workspace = new Workspace(workspaceIndex); m_workspaces.push_back(workspace); + workspace->setConnectionOverlayVisible(m_connectionOverlayEnabled); + connect(workspace, &Workspace::connectionOverlayToggled, this, &MainWindow::setConnectionOverlayEnabled); if (workspace->getMenuButton()) { createMenuBar(workspace->getMenuButton()); } @@ -3266,7 +3524,9 @@ void MainWindow::sampleSourceChange(int deviceSetIndex, int newDeviceIndex, Work // deletes old UI and input object deviceUISet->m_deviceAPI->getSampleSource()->setMessageQueueToGUI(nullptr); // have source stop sending messages to the GUI - delete deviceUISet->m_deviceGUI; + DeviceGUI *oldDeviceGUI = deviceUISet->m_deviceGUI; + deviceUISet->m_deviceGUI = nullptr; + delete oldDeviceGUI; deviceUISet->m_deviceAPI->resetSamplingDeviceId(); deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceInput(deviceUISet->m_deviceAPI->getSampleSource()); deviceUISet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists @@ -3309,7 +3569,9 @@ void MainWindow::sampleSinkChange(int deviceSetIndex, int newDeviceIndex, Worksp // deletes old UI and output object deviceUISet->m_deviceAPI->getSampleSink()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI - delete m_deviceUIs[deviceSetIndex]->m_deviceGUI; + DeviceGUI *oldDeviceGUI = deviceUISet->m_deviceGUI; + deviceUISet->m_deviceGUI = nullptr; + delete oldDeviceGUI; deviceUISet->m_deviceAPI->resetSamplingDeviceId(); deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput(deviceUISet->m_deviceAPI->getSampleSink()); deviceUISet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists @@ -3353,7 +3615,9 @@ void MainWindow::sampleMIMOChange(int deviceSetIndex, int newDeviceIndex, Worksp // deletes old UI and output object deviceUISet->m_deviceAPI->getSampleMIMO()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI - delete deviceUISet->m_deviceGUI; + DeviceGUI *oldDeviceGUI = deviceUISet->m_deviceGUI; + deviceUISet->m_deviceGUI = nullptr; + delete oldDeviceGUI; deviceUISet->m_deviceAPI->resetSamplingDeviceId(); deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleMIMOPluginInstanceMIMO(deviceUISet->m_deviceAPI->getSampleMIMO()); diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h index 4780654b1..82cbbb20f 100644 --- a/sdrgui/mainwindow.h +++ b/sdrgui/mainwindow.h @@ -235,6 +235,7 @@ public: private: const Configuration *m_configuration; + bool m_overlayEnabledBeforeLoad; // The dialog is created with WA_DeleteOnClose and this FSM outlives it, // so a bare pointer can dangle between states. QPointer makes the null // checks in the state handlers mean what they are written to mean. @@ -332,6 +333,8 @@ private: PluginManager* m_pluginManager; QTimer m_statusTimer; + QTimer m_connectionOverlayRefreshTimer; + bool m_connectionOverlayEnabled; int m_lastEngineState; QMenuBar *m_menuBar; @@ -363,6 +366,8 @@ private: void saveFeatureSetPresetSettings(FeatureSetPreset* preset, int featureSetIndex); FeatureGUI *getMCPServerGUI(Feature **feature = nullptr) const; void updateMCPServerButton(); + void setConnectionOverlayEnabled(bool enabled); + void updateConnectionOverlays(); QString openGLVersion() const; void createMenuBar(QToolButton *button) const; diff --git a/sdrgui/resources/res.qrc b/sdrgui/resources/res.qrc index cc76843c6..e4f87c1cb 100644 --- a/sdrgui/resources/res.qrc +++ b/sdrgui/resources/res.qrc @@ -154,6 +154,7 @@ stackvertical.png stackcolumns.png tab.png + wiring.png clockfile.png clockcurrent.png mouse.png diff --git a/sdrgui/resources/wiring.png b/sdrgui/resources/wiring.png new file mode 100644 index 000000000..748b3f960 Binary files /dev/null and b/sdrgui/resources/wiring.png differ