From 852fd6e10c0e190ae46865f672bd8f3e50a1b760 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Sun, 27 Sep 2026 23:09:10 +0100 Subject: [PATCH 1/8] Add connections overlay --- .../radioastronomy/radioastronomy.cpp | 2 +- plugins/feature/ais/ais.cpp | 2 +- plugins/feature/aprs/aprs.cpp | 2 +- .../feature/demodanalyzer/demodanalyzer.cpp | 3 +- .../demodanalyzer/demodanalyzerworker.cpp | 5 + plugins/feature/denoiser/denoiser.cpp | 3 +- plugins/feature/denoiser/denoiserworker.cpp | 5 + plugins/feature/map/map.cpp | 2 +- plugins/feature/morsedecoder/morsedecoder.cpp | 3 +- .../morsedecoder/morsedecoderworker.cpp | 5 + plugins/feature/radiosonde/radiosonde.cpp | 2 +- plugins/feature/skymap/skymapgui.cpp | 2 +- plugins/feature/startracker/startracker.cpp | 4 +- sdrbase/availablechannelorfeaturehandler.h | 6 +- sdrbase/pipes/datapipes.cpp | 5 + sdrbase/pipes/datapipes.h | 1 + sdrbase/pipes/messagepipes.cpp | 5 + sdrbase/pipes/messagepipes.h | 1 + sdrbase/pipes/objectpipe.cpp | 3 +- sdrbase/pipes/objectpipesregistrations.cpp | 28 +- sdrbase/pipes/objectpipesregistrations.h | 6 + sdrgui/CMakeLists.txt | 2 + sdrgui/channel/channelgui.cpp | 2 + sdrgui/channel/channelgui.h | 3 + sdrgui/device/devicegui.cpp | 13 +- sdrgui/device/devicegui.h | 3 +- sdrgui/device/deviceuiset.cpp | 5 + sdrgui/device/deviceuiset.h | 1 + sdrgui/feature/featuregui.cpp | 1 + sdrgui/gui/connectionoverlay.cpp | 818 ++++++++++++++++++ sdrgui/gui/connectionoverlay.h | 118 +++ sdrgui/gui/workspace.cpp | 32 + sdrgui/gui/workspace.h | 6 + sdrgui/mainspectrum/mainspectrumgui.cpp | 1 + sdrgui/mainwindow.cpp | 216 ++++- sdrgui/mainwindow.h | 5 + sdrgui/resources/res.qrc | 1 + sdrgui/resources/wiring.png | Bin 0 -> 539 bytes 38 files changed, 1292 insertions(+), 30 deletions(-) create mode 100644 sdrgui/gui/connectionoverlay.cpp create mode 100644 sdrgui/gui/connectionoverlay.h create mode 100644 sdrgui/resources/wiring.png diff --git a/plugins/channelrx/radioastronomy/radioastronomy.cpp b/plugins/channelrx/radioastronomy/radioastronomy.cpp index 107b19211..7d3248609 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) { 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 8e2f41af9..ef19245fb 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 f94a717ed..c9d434cd1 100644 --- a/plugins/feature/demodanalyzer/demodanalyzer.cpp +++ b/plugins/feature/demodanalyzer/demodanalyzer.cpp @@ -342,7 +342,7 @@ void DemodAnalyzer::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) { @@ -668,6 +668,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 af2baa8f3..88138d792 100644 --- a/plugins/feature/denoiser/denoiser.cpp +++ b/plugins/feature/denoiser/denoiser.cpp @@ -343,7 +343,7 @@ void Denoiser::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) { @@ -680,6 +680,7 @@ void Denoiser::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/denoiser/denoiserworker.cpp b/plugins/feature/denoiser/denoiserworker.cpp index 2b70fce7f..166ffd11d 100644 --- a/plugins/feature/denoiser/denoiserworker.cpp +++ b/plugins/feature/denoiser/denoiserworker.cpp @@ -198,6 +198,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; @@ -301,6 +302,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/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 69ab896ad..f5f3bb1b7 100644 --- a/plugins/feature/morsedecoder/morsedecoder.cpp +++ b/plugins/feature/morsedecoder/morsedecoder.cpp @@ -388,7 +388,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) { @@ -703,6 +703,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 1fa53a1c4..94e38ea94 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/pipes/datapipes.cpp b/sdrbase/pipes/datapipes.cpp index c5c3a05b2..749dc44ea 100644 --- a/sdrbase/pipes/datapipes.cpp +++ b/sdrbase/pipes/datapipes.cpp @@ -52,6 +52,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 1104e0150..1d3146d0d 100644 --- a/sdrbase/pipes/messagepipes.cpp +++ b/sdrbase/pipes/messagepipes.cpp @@ -52,6 +52,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..88ea87050 100644 --- a/sdrgui/channel/channelgui.cpp +++ b/sdrgui/channel/channelgui.cpp @@ -58,6 +58,7 @@ ChannelGUI::ChannelGUI(QWidget *parent) : .arg(palette().dark().color().darker(115).name()))); m_indexLabel = new QLabel(); + m_indexLabel->setObjectName("connectionIndexLabel"); m_indexLabel->setFixedSize(50, 16); m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }"); m_indexLabel->setText(tr("X%1:%2").arg(m_deviceSetIndex).arg(m_channelIndex)); @@ -464,6 +465,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..0bb38ce1e 100644 --- a/sdrgui/device/devicegui.cpp +++ b/sdrgui/device/devicegui.cpp @@ -55,6 +55,7 @@ DeviceGUI::DeviceGUI(QWidget *parent) : .arg(palette().dark().color().darker(115).name())); m_indexLabel = new QLabel(); + m_indexLabel->setObjectName("connectionIndexLabel"); m_indexLabel->setFixedSize(32, 16); m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }"); m_indexLabel->setText(tr("X:%1").arg(m_deviceSetIndex)); @@ -448,7 +449,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 +457,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/feature/featuregui.cpp b/sdrgui/feature/featuregui.cpp index a74dc5c29..e3439f821 100644 --- a/sdrgui/feature/featuregui.cpp +++ b/sdrgui/feature/featuregui.cpp @@ -56,6 +56,7 @@ FeatureGUI::FeatureGUI(QWidget *parent) : .arg(palette().dark().color().darker(115).name())); m_indexLabel = new QLabel(); + m_indexLabel->setObjectName("connectionIndexLabel"); m_indexLabel->setFixedSize(40, 16); m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }"); m_indexLabel->setText(tr("F:%1").arg(m_featureIndex)); diff --git a/sdrgui/gui/connectionoverlay.cpp b/sdrgui/gui/connectionoverlay.cpp new file mode 100644 index 000000000..9baee8672 --- /dev/null +++ b/sdrgui/gui/connectionoverlay.cpp @@ -0,0 +1,818 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 + +ConnectionOverlay::ConnectionOverlay(QMdiArea *mdi) : + QWidget(mdi), + m_mdi(mdi) +{ + // QMdiArea scrolls its viewport children; keep the overlay fixed above the viewport. + setAttribute(Qt::WA_TransparentForMouseEvents); + setAttribute(Qt::WA_TranslucentBackground); + setGeometry(mdi->viewport()->geometry()); + mdi->viewport()->installEventFilter(this); + m_animationTimer.setInterval(33); + connect(&m_animationTimer, &QTimer::timeout, this, &ConnectionOverlay::animate); + m_clock.start(); + hide(); +} + +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.source.data() != y.source.data() || x.target.data() != y.target.data() || + x.sourceLabel != y.sourceLabel || x.targetLabel != y.targetLabel || + x.flowLabel != y.flowLabel || x.sourceWorkspace != y.sourceWorkspace || + x.targetWorkspace != y.targetWorkspace || x.kind != y.kind || + x.direction != y.direction || x.color != y.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_indexLabels.clear(); + // Cache each title ID widget so paths can anchor beside it and avoid painting over it. + for (const Connection& connection : m_connections) + { + for (QMdiSubWindow *window : {connection.source.data(), connection.target.data()}) + { + if (window && !m_indexLabels.contains(window)) { + m_indexLabels.insert(window, window->findChild("connectionIndexLabel")); + } + } + } + watchWindows(); + invalidateLayout(); +} + +void ConnectionOverlay::watchWindows() +{ + // Cached routes depend on the connected windows' geometry and their ID labels. + for (const QPointer& object : m_watched) + { + if (object) { + object->removeEventFilter(this); + } + } + m_watched.clear(); + for (auto it = m_indexLabels.constBegin(); it != m_indexLabels.constEnd(); ++it) + { + for (QObject *object : {static_cast(it.key()), static_cast(it.value().data())}) + { + if (object) + { + object->installEventFilter(this); + m_watched.append(object); + } + } + } +} + +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(); + m_pulseRegion = QRegion(); + } +} + +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::Move || type == QEvent::Resize || type == QEvent::Show || + type == QEvent::Hide || type == QEvent::WindowStateChange || type == QEvent::ParentChange) + { + invalidateLayout(); // A connected window or its ID label moved, e.g. when scrolling. + } + return QWidget::eventFilter(object, event); +} + +void ConnectionOverlay::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::FontChange || event->type() == QEvent::PaletteChange) { + invalidateLayout(); + } + QWidget::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) +{ + QWidget::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; +} + +static int crossingCost(const QPainterPath& path, const QRectF& sourceBox, const QRectF& targetBox) +{ + // Count samples drawn over a window body. An endpoint can be inside a window, + // e.g. the source's own title bar, or an ID label covered by an overlapping + // window. The route may then leave that window at the start, or arrive in it + // at the end, but any other part inside a window is a crossing. + constexpr int samples = 80; + QPointF points[samples + 1]; + for (int i = 0; i <= samples; ++i) { + points[i] = path.pointAtPercent(qreal(i) / samples); + } + int cost = 0; + for (const QRectF& box : {sourceBox, targetBox}) + { + if (box.isEmpty()) { + continue; + } + const QRectF body = box.adjusted(-2, -2, 2, 2); + int first = 0; + while (first <= samples && body.contains(points[first])) { + ++first; // Leading run inside, leaving the start window + } + int last = samples; + while (last >= first && body.contains(points[last])) { + --last; // Trailing run inside, arriving in the end window + } + for (int i = first; i <= last; ++i) + { + if (body.contains(points[i])) { + ++cost; + } + } + } + return cost; +} + +static QPainterPath connectionPath(const QPointF& from, const QPointF& to, + int fromSide, int toSide, const QRectF& sourceBox, + const QRectF& targetBox, const QRectF& bounds) +{ + constexpr qreal labelLead = 14; + const QPointF curveFrom = from + QPointF(fromSide * labelLead, 0); + const QPointF curveTo = to + QPointF(toSide * labelLead, 0); + const QPointF delta = curveTo - curveFrom; + const qreal handle = qBound(32, qAbs(delta.x()) * 0.35 + qAbs(delta.y()) * 0.3, 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 (fromSide != 0) { + direct.lineTo(curveFrom); + } + direct.cubicTo(firstControl, lastControl, curveTo); + if (toSide != 0) { + direct.lineTo(to); + } + if (sourceBox.isEmpty() || targetBox.isEmpty()) { + return direct; + } + // Prefer the route that crosses windows least, then the shortest. 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. + QPainterPath bestRoute = direct; + int bestCost = crossingCost(direct, sourceBox, targetBox); + qreal bestLength = direct.length(); + if (bestCost == 0) { + return direct; + } + auto consider = [&](const QPainterPath& candidate) { + const qreal length = candidate.length(); + if (bestCost == 0 && length >= bestLength) { + return; // Cannot beat a shorter clear route + } + const int cost = crossingCost(candidate, sourceBox, targetBox); + if (cost < bestCost || (cost == bestCost && length < bestLength)) + { + bestRoute = candidate; + bestCost = cost; + bestLength = length; + } + }; + + // 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 bestRoute; +} + +bool 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()); + m_clipRegion = QRegion(rect()); + QRegion paintedRegion; + QVector labelObstacles; // Title ID labels, then 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, ... + }; + QPainterPathStroker maskStroker; + maskStroker.setWidth(20); + maskStroker.setCapStyle(Qt::RoundCap); + maskStroker.setJoinStyle(Qt::RoundJoin); + for (auto it = m_indexLabels.constBegin(); it != m_indexLabels.constEnd(); ++it) + { + QMdiSubWindow *window = it.key(); + QWidget *indexLabel = it.value().data(); + if (!window || !localWindows.contains(window) || !indexLabel || !indexLabel->isVisible()) { + continue; + } + const QPoint labelTopLeft = window->geometry().topLeft() + + indexLabel->mapTo(window, QPoint(0, 0)) + viewportOffset; + const QRect indexRect = QRect(labelTopLeft, indexLabel->size()).adjusted(-2, -2, 2, 2); + m_clipRegion -= indexRect; + labelObstacles.append(indexRect); + } + // The overlay is a sibling of the scrolling viewport, so translate MDI + // window coordinates before using their title labels as endpoints. + auto anchorFor = [this, &viewportOffset](QMdiSubWindow *window, int side) -> QPointF { + QWidget *indexLabel = m_indexLabels.value(window).data(); + const QPoint insideWindow = indexLabel && indexLabel->isVisible() ? + indexLabel->mapTo(window, QPoint(side < 0 ? -10 : indexLabel->width() + 10, + indexLabel->height() / 2)) : + QPoint(side < 0 ? -10 : 48, 12); + return QPointF(window->geometry().topLeft() + insideWindow + viewportOffset); + }; + + for (const Connection& connection : m_connections) + { + if (!connection.source || !connection.target) { + continue; + } + const bool sourceLocal = localWindows.contains(connection.source.data()); + const bool targetLocal = localWindows.contains(connection.target.data()); + if (!sourceLocal && !targetLocal) { + continue; + } + if (sourceLocal && (connection.source->parentWidget() != m_mdi->viewport() || + !connection.source->isVisible() || connection.source->isMinimized())) { + continue; + } + if (targetLocal && (connection.target->parentWidget() != m_mdi->viewport() || + !connection.target->isVisible() || connection.target->isMinimized())) { + continue; + } + const int sourceSide = 1; // Device ID, or the producer of a pipe. + const int targetSide = -1; // Inputs meet the left side of channel, spectrum, and feature IDs. + const QPointF sourceAnchor = sourceLocal ? anchorFor(connection.source.data(), sourceSide) : QPointF(); + const QPointF targetAnchor = targetLocal ? anchorFor(connection.target.data(), targetSide) : QPointF(); + const bool sourceVisible = sourceLocal && bounds.contains(sourceAnchor); + const bool targetVisible = targetLocal && bounds.contains(targetAnchor); + // This workspace draws a link only when at least one endpoint is on screen. + if (!sourceVisible && !targetVisible) { + continue; + } + + Route route; + QPointF markerEdge; + bool crossWorkspace = false; + int stubDirection = 0; // Which way a cross-workspace stub goes from its window + // 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.from = sourceAnchor; + route.to = targetAnchor; + } + else if (sourceVisible && targetLocal) + { + route.from = sourceAnchor; + route.to = viewportEdge(bounds, targetAnchor); + markerEdge = route.to; + route.marker = scrollArrow(bounds, targetAnchor) + " " + connection.targetLabel; + } + else if (targetVisible && sourceLocal) + { + route.from = viewportEdge(bounds, sourceAnchor); + route.to = targetAnchor; + markerEdge = route.from; + route.marker = scrollArrow(bounds, sourceAnchor) + " " + connection.sourceLabel; + } + else if (sourceVisible) + { + route.from = sourceAnchor; + route.marker = QString("W%1 · %2").arg(connection.targetWorkspace).arg(connection.targetLabel); + if (!connection.flowLabel.isEmpty()) { + route.marker += " · " + connection.flowLabel; // One label per stub, at its tip + } + const qreal markerWidth = metrics.horizontalAdvance(route.marker) + 8; + const qreal stubLength = 90; + const qreal stubY = qBound(bounds.top() + 4, route.from.y() + fanOffset(connection.source.data(), sourceSide), + bounds.bottom() - 4); + // Stubs leave to the right. Near the right edge there is no room for the + // stub and its label, so go left instead, past the window's ID label. + stubDirection = route.from.x() + stubLength + markerWidth + 10 <= bounds.right() ? 1 : -1; + const qreal tipX = stubDirection > 0 ? route.from.x() + stubLength : + qMax(bounds.left() + markerWidth + 10, route.from.x() - stubLength - 60); + route.to = QPointF(tipX, stubY); + route.stubTip = 1; + crossWorkspace = true; + } + else + { + route.to = targetAnchor; + route.marker = QString("W%1 · %2").arg(connection.sourceWorkspace).arg(connection.sourceLabel); + if (!connection.flowLabel.isEmpty()) { + route.marker += " · " + connection.flowLabel; // One label per stub, at its tip + } + const qreal markerWidth = metrics.horizontalAdvance(route.marker) + 8; + const qreal stubLength = 90; + // Stubs arrive from the left. Near the left edge there is no room for the + // stub and its label, so come from the right instead, past the ID label. + stubDirection = route.to.x() - stubLength - markerWidth - 10 >= bounds.left() ? -1 : 1; + const qreal tipX = stubDirection < 0 ? route.to.x() - stubLength : + qMin(bounds.right() - markerWidth - 10, route.to.x() + stubLength + 60); + const qreal stubY = qBound(bounds.top() + 4, route.to.y() + fanOffset(connection.target.data(), targetSide), + bounds.bottom() - 4); + route.from = QPointF(tipX, stubY); + route.stubTip = -1; + crossWorkspace = true; + } + const QPointF& from = route.from; + const QPointF& to = route.to; + + route.color = connection.color.isValid() ? connection.color.lighter(150) : + (connection.kind == PipeLink ? QColor(238, 183, 77) : QColor(56, 204, 228)); + route.kind = connection.kind; + route.direction = connection.direction; + route.sourceBox = sourceVisible ? + QRectF(connection.source->geometry().translated(viewportOffset)) : QRectF(); + route.targetBox = targetVisible ? + QRectF(connection.target->geometry().translated(viewportOffset)) : QRectF(); + // A stub flipped to the other side goes straight out, behind its ID label. + route.fromSide = sourceVisible && stubDirection >= 0 ? sourceSide : 0; + route.toSide = targetVisible && stubDirection <= 0 ? targetSide : 0; + route.path = connectionPath(from, to, route.fromSide, route.toSide, + route.sourceBox, route.targetBox, bounds); + route.length = route.path.length(); + + if (!connection.flowLabel.isEmpty() && !crossWorkspace) // Stubs include it in their marker + { + const qreal labelWidth = metrics.horizontalAdvance(connection.flowLabel) + 10; + const qreal labelHeight = metrics.height() + 4; + // Beside each route's own midpoint, so labels of fanned stubs separate too. + const QPointF midpoint = route.path.pointAtPercent(0.5); + const qreal labelX = midpoint.x() - labelWidth / 2; + const qreal labelY = midpoint.y() - labelHeight - 6; + route.flowLabel = connection.flowLabel; + route.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); + } + + if (!route.marker.isEmpty()) + { + const qreal labelWidth = metrics.horizontalAdvance(route.marker) + 8; + const qreal labelHeight = metrics.height() + 4; + const QPointF remoteAnchor = sourceVisible ? to : from; + // A stub's label continues from its tip, in the direction the stub goes. + const qreal labelX = crossWorkspace ? + (stubDirection > 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.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); + } + + m_routes.append(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.markerRect.center().y(); + placeLabel(route.markerRect); + const qreal dy = route.markerRect.center().y() - before; + if (route.stubTip != 0 && !qFuzzyIsNull(dy)) + { + // Keep a moved stub label on the end of its own line. + QPointF& tip = route.stubTip > 0 ? route.to : route.from; + tip.ry() += dy; + route.path = connectionPath(route.from, route.to, route.fromSide, route.toSide, + route.sourceBox, route.targetBox, bounds); + route.length = route.path.length(); + } + } + for (Route& route : m_routes) { + placeLabel(route.flowLabelRect); + } + // Only now are the routes final, so build the painted region. + for (Route& route : m_routes) + { + QRegion routeRegion(maskStroker.createStroke(route.path).toFillPolygon().toPolygon(), Qt::WindingFill); + routeRegion += QRectF(route.from.x() - 9, route.from.y() - 9, 18, 18).toAlignedRect(); + routeRegion += QRectF(route.to.x() - 9, route.to.y() - 9, 18, 18).toAlignedRect(); + for (const QRectF& label : {route.markerRect, route.flowLabelRect}) + { + if (!label.isEmpty()) { + routeRegion += label.toAlignedRect().adjusted(-2, -2, 2, 2); + } + } + route.bounds = routeRegion.boundingRect(); + paintedRegion += routeRegion; + } + + paintedRegion &= m_clipRegion; + // A full-size widget above QOpenGLWidget spectra can occlude their entire + // viewport. Give the overlay only the pixels needed by its drawing. + if (paintedRegion.isEmpty()) { + paintedRegion = QRegion(0, 0, 1, 1); + } + if (mask() != paintedRegion) + { + // An empty mask means the whole widget was painted. + const QRegion oldMask = mask().isEmpty() ? QRegion(rect()) : mask(); + setMask(paintedRegion); + // setMask() asks the QMdiArea to repaint what the overlay no longer covers, + // but the opaque viewport above it is not repainted, leaving trails of old + // routes. Repaint the viewport (and its sub windows) there explicitly. + const QRegion exposed = oldMask - paintedRegion; + if (!exposed.isEmpty()) { + m_mdi->viewport()->update(exposed.translated(pos() - m_mdi->viewport()->pos())); + } + return true; + } + return false; +} + +QVector ConnectionOverlay::pulses() const +{ + QVector result; + for (const Route& route : m_routes) + { + if (route.direction == NoDirection || route.length <= 32) { + continue; + } + const int flowCount = route.direction == BothDirections ? 2 : 1; + const int pulsesPerFlow = route.length > 360 ? 2 : 1; + for (int flow = 0; flow < flowCount; ++flow) + { + const bool reverse = route.direction == Reverse || (route.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.path.pointAtPercent(tailProgress), route.path.pointAtPercent(progress), route.color}); + } + } + } + return result; +} + +QRegion ConnectionOverlay::pulsesRegion(const QVector& pulses) const +{ + QRegion region; + for (const Pulse& pulse : pulses) { + region += QRectF(pulse.tail, pulse.head).normalized().adjusted(-9, -9, 9, 9).toAlignedRect(); + } + return region; +} + +void ConnectionOverlay::animate() +{ + if (!isVisible()) { + return; // Workspace is a background tab, or minimized. + } + // Only the pulses move, so repaint just where they were and where they are now. + m_phase = (m_clock.elapsed() % 2400) / 2400.0; + const QRegion region = pulsesRegion(pulses()); + const QRegion dirty = m_pulseRegion | region; + m_pulseRegion = region; + if (!dirty.isEmpty()) { + update(dirty); + } +} + +void ConnectionOverlay::paintEvent(QPaintEvent *event) +{ + // Paint current geometry rather than a stale cache. This paint is clipped to the + // old mask, so repaint again only if the mask changed. + if (m_layoutDirty && computeLayout()) { + update(); + } + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setClipRegion(m_clipRegion & event->region()); + const QRegion& dirty = event->region(); + + for (const Route& route : m_routes) + { + if (!dirty.intersects(route.bounds)) { + continue; + } + const QColor& color = route.color; + // 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(), 35), 6, + Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.drawPath(route.path); + painter.setPen(QPen(QColor(color.red(), color.green(), color.blue(), 180), 2.2, + route.kind == PipeLink ? Qt::DashLine : Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.drawPath(route.path); + painter.setBrush(QColor(color.red(), color.green(), color.blue(), 220)); + painter.setPen(QPen(palette().window().color(), 1.5)); + painter.drawEllipse(route.from, 4, 4); + painter.drawEllipse(route.to, 4, 4); + } + + for (const Pulse& pulse : pulses()) + { + const QColor& color = pulse.color; + painter.setBrush(Qt::NoBrush); + painter.setPen(QPen(QColor(color.red(), color.green(), color.blue(), 210), 4, + Qt::SolidLine, Qt::RoundCap)); + painter.drawLine(pulse.tail, pulse.head); + painter.setPen(Qt::NoPen); + painter.setBrush(QColor(color.red(), color.green(), color.blue(), 130)); + painter.drawEllipse(pulse.head, 7, 7); + painter.setBrush(QColor(255, 255, 255, 245)); + painter.drawEllipse(pulse.head, 3, 3); + } + + for (const Route& route : m_routes) + { + if (!route.flowLabel.isEmpty() && dirty.intersects(route.flowLabelRect.toAlignedRect())) + { + painter.setPen(QPen(route.color, 1)); + painter.setBrush(QColor(24, 28, 32, 235)); + painter.drawRoundedRect(route.flowLabelRect, 3, 3); + painter.setPen(Qt::white); + painter.drawText(route.flowLabelRect, Qt::AlignCenter, route.flowLabel); + } + if (!route.marker.isEmpty() && dirty.intersects(route.markerRect.toAlignedRect())) + { + painter.setPen(Qt::NoPen); + painter.setBrush(QColor(24, 28, 32, 235)); + painter.drawRoundedRect(route.markerRect, 3, 3); + painter.setPen(Qt::white); + painter.drawText(route.markerRect, Qt::AlignCenter, route.marker); + } + } +} diff --git a/sdrgui/gui/connectionoverlay.h b/sdrgui/gui/connectionoverlay.h new file mode 100644 index 000000000..fb04620a1 --- /dev/null +++ b/sdrgui/gui/connectionoverlay.h @@ -0,0 +1,118 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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; + +// A non-interactive drawing layer above one workspace's MDI windows, showing connections between windows. +class ConnectionOverlay : public QWidget +{ + Q_OBJECT +public: + enum Kind { DeviceLink, PipeLink }; + enum Direction { NoDirection, Forward, Reverse, BothDirections }; + + struct Connection { + QPointer source; + QPointer target; + QString sourceLabel; + QString targetLabel; + QString flowLabel; + int sourceWorkspace = -1; + int targetWorkspace = -1; + Kind kind = DeviceLink; + Direction direction = Forward; + QColor color; + }; + + explicit ConnectionOverlay(QMdiArea *mdi); + 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 paintEvent(QPaintEvent *event) override; + +private: + // Geometry for one drawn connection, cached until windows move or connections change. + struct Route { + QPainterPath path; + qreal length = 0; + QRect bounds; + QPointF from; + QPointF to; + QColor color; + Kind kind = DeviceLink; + Direction direction = Forward; + QString flowLabel; + QRectF flowLabelRect; + QString marker; + QRectF markerRect; + // Inputs to connectionPath(), kept so a stub can be rerouted to follow its label. + int fromSide = 0; + int toSide = 0; + QRectF sourceBox; + QRectF targetBox; + int stubTip = 0; // Cross-workspace stub: 1 if to is its tip, -1 if from is + }; + struct Pulse { + QPointF tail; + QPointF head; + QColor color; + }; + + QMdiArea *m_mdi; + QList m_connections; + QHash> m_indexLabels; + QList> m_watched; + QVector m_routes; + QRegion m_clipRegion; // Everything except the title ID labels + QRegion m_pulseRegion; // Area covered by the pulses last painted + qreal m_phase = 0; + 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; + + static bool sameConnections(const QList& a, const QList& b); + void watchWindows(); + void invalidateLayout(); + void relayout(); + bool computeLayout(); // Returns true if the mask changed + QVector pulses() const; + QRegion pulsesRegion(const QVector& pulses) const; + void animate(); +}; + +#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/mainspectrum/mainspectrumgui.cpp b/sdrgui/mainspectrum/mainspectrumgui.cpp index 0c17b7071..457f7dfe0 100644 --- a/sdrgui/mainspectrum/mainspectrumgui.cpp +++ b/sdrgui/mainspectrum/mainspectrumgui.cpp @@ -56,6 +56,7 @@ MainSpectrumGUI::MainSpectrumGUI(GLSpectrum *spectrum, GLSpectrumGUI *spectrumGU setMinimumSize(m_MinimumWidth, m_MinimumHeight); m_indexLabel = new QLabel(); + m_indexLabel->setObjectName("connectionIndexLabel"); m_indexLabel->setFixedSize(32, 16); m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }"); m_indexLabel->setText(tr("X:%1").arg(m_deviceSetIndex)); diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 32f73729b..87afccebb 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,181 @@ 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; + }; + QHash endpoints; + QList connections; + + 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}; + endpoints.insert(device, deviceEndpoint); + endpoints.insert(deviceUI->m_deviceAPI, deviceEndpoint); + + auto appendDeviceConnection = [&](QMdiSubWindow *target, const QString& label, + int targetWorkspace, ConnectionOverlay::Direction direction) { + if (!target) { + return; + } + ConnectionOverlay::Connection connection; + connection.source = device; + connection.target = target; + connection.sourceLabel = deviceLabel; + connection.targetLabel = label; + connection.flowLabel = "IQ"; + connection.sourceWorkspace = device->getWorkspaceIndex(); + connection.targetWorkspace = targetWorkspace; + connection.direction = direction; + connection.color = deviceColor; + connections.append(connection); + }; + + const ConnectionOverlay::Direction spectrumDirection = + device->getDeviceType() == DeviceGUI::DeviceTx ? ConnectionOverlay::Reverse : + (device->getDeviceType() == DeviceGUI::DeviceMIMO ? ConnectionOverlay::BothDirections : ConnectionOverlay::Forward); + if (deviceUI->m_mainSpectrumGUI) + { + appendDeviceConnection(deviceUI->m_mainSpectrumGUI, deviceLabel + " spectrum", + deviceUI->m_mainSpectrumGUI->getWorkspaceIndex(), spectrumDirection); + } + 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); + appendDeviceConnection(channel, channelLabel, channel->getWorkspaceIndex(), direction); + const Endpoint endpoint{channel, channelLabel, channel->getWorkspaceIndex(), false, + channel->getIndexLabelColor()}; + endpoints.insert(channel, endpoint); + if (ChannelAPI *channelAPI = deviceUI->getChannelAt(channelIndex)) { + 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()}; + 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) + { + 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 (pipe.type == "demod") { + connections[existingIndex].flowLabel = "Audio"; + } + continue; + } + ConnectionOverlay::Connection connection; + connection.source = source.window; + connection.target = target.window; + connection.sourceLabel = source.label; + connection.targetLabel = target.label; + connection.flowLabel = pipe.type == "demod" ? "Audio" : "Data"; + connection.sourceWorkspace = source.workspace; + connection.targetWorkspace = target.workspace; + connection.kind = ConnectionOverlay::PipeLink; + connection.direction = ConnectionOverlay::Forward; + connection.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 +3466,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 +3511,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 +3557,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 0000000000000000000000000000000000000000..748b3f9606366a3148c31d1d8bdc795f59176820 GIT binary patch literal 539 zcmV+$0_6RPP)!r!8z7AlAs zk|ITv-TPX2CJcA)UUy&zhQpmbbI;dv?pavivMt*x&s1|6XaLVpk)%o1m1GvZY#*Pp zT5)*LvuZf`P+75KG{0MAxFQpy~0W7I4yeo^9S#NB&#rd(= z0DrRKR6uNC(gEB42es{^bmr%_!}>V(blA~>OSYfberJ0<&YJ<$ROn!P-S%7CFKwU5 zT`k*5(%AL}u#-asz7#JvumY?CzkuByip~L}(0?jv({`Fw|AmgeOslD@U2DpeO;?!bn>*VSc^}+yj09w}1~d18we+xrm`ZL{c95O@OfQ dp+EJveeE002ovPDHLkV1ilV`7Hnd literal 0 HcmV?d00001 From 4ca7379e7cb0270c2ecee6986e0e394fd1f69f1b Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 28 Sep 2026 14:03:25 +0100 Subject: [PATCH 2/8] ChannelAPI: Add getChannelSampleRate and getAudioSampleRate. Set m_basebandSink to nullptr when stopped, to avoid dangling pointer. --- plugins/channelmimo/doa2/doa2.cpp | 5 +++++ plugins/channelmimo/doa2/doa2.h | 1 + plugins/channelrx/chanalyzer/chanalyzer.cpp | 9 +++++++-- plugins/channelrx/chanalyzer/chanalyzer.h | 3 ++- plugins/channelrx/chanalyzer/chanalyzergui.cpp | 6 +++--- plugins/channelrx/channelpower/channelpower.cpp | 4 ++++ plugins/channelrx/channelpower/channelpower.h | 1 + plugins/channelrx/demodadsb/adsbdemod.cpp | 5 +++++ plugins/channelrx/demodadsb/adsbdemod.h | 1 + plugins/channelrx/demodais/aisdemod.cpp | 10 ++++++++++ plugins/channelrx/demodais/aisdemod.h | 2 ++ plugins/channelrx/demodam/amdemod.cpp | 6 ++++++ plugins/channelrx/demodam/amdemod.h | 3 ++- plugins/channelrx/demodatv/atvdemod.cpp | 5 +++++ plugins/channelrx/demodatv/atvdemod.h | 1 + plugins/channelrx/demodbfm/bfmdemod.cpp | 6 ++++++ plugins/channelrx/demodbfm/bfmdemod.h | 3 ++- plugins/channelrx/demodchirpchat/chirpchatdemod.cpp | 6 ++++++ plugins/channelrx/demodchirpchat/chirpchatdemod.h | 1 + plugins/channelrx/demoddab/dabdemod.cpp | 5 +++++ plugins/channelrx/demoddab/dabdemod.h | 3 ++- plugins/channelrx/demoddatv/datvdemod.cpp | 5 +++++ plugins/channelrx/demoddatv/datvdemod.h | 1 + plugins/channelrx/demoddsc/dscdemod.cpp | 10 ++++++++++ plugins/channelrx/demoddsc/dscdemod.h | 2 ++ plugins/channelrx/demoddsd/dsddemod.cpp | 7 +++++++ plugins/channelrx/demoddsd/dsddemod.h | 3 ++- plugins/channelrx/demodendoftrain/endoftraindemod.cpp | 10 ++++++++++ plugins/channelrx/demodendoftrain/endoftraindemod.h | 2 ++ plugins/channelrx/demodfreedv/freedvdemod.cpp | 5 +++++ plugins/channelrx/demodfreedv/freedvdemod.h | 3 ++- plugins/channelrx/demodft8/ft8demod.cpp | 7 +++++++ plugins/channelrx/demodft8/ft8demod.h | 3 ++- plugins/channelrx/demodils/ilsdemod.cpp | 5 +++++ plugins/channelrx/demodils/ilsdemod.h | 3 ++- plugins/channelrx/demodinmarsat/inmarsatdemod.cpp | 10 ++++++++++ plugins/channelrx/demodinmarsat/inmarsatdemod.h | 2 ++ plugins/channelrx/demodm17/m17demod.cpp | 6 ++++++ plugins/channelrx/demodm17/m17demod.h | 3 ++- plugins/channelrx/demodmeshcore/meshcoredemod.cpp | 5 +++++ plugins/channelrx/demodmeshcore/meshcoredemod.h | 1 + plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp | 5 +++++ plugins/channelrx/demodmeshtastic/meshtasticdemod.h | 1 + plugins/channelrx/demodnavtex/navtexdemod.cpp | 10 ++++++++++ plugins/channelrx/demodnavtex/navtexdemod.h | 2 ++ plugins/channelrx/demodnfm/nfmdemod.cpp | 6 ++++++ plugins/channelrx/demodnfm/nfmdemod.h | 3 ++- plugins/channelrx/demodpacket/packetdemod.cpp | 10 ++++++++++ plugins/channelrx/demodpacket/packetdemod.h | 2 ++ plugins/channelrx/demodpager/pagerdemod.cpp | 10 ++++++++++ plugins/channelrx/demodpager/pagerdemod.h | 2 ++ plugins/channelrx/demodradiosonde/radiosondedemod.cpp | 10 ++++++++++ plugins/channelrx/demodradiosonde/radiosondedemod.h | 2 ++ plugins/channelrx/demodrtty/rttydemod.cpp | 10 ++++++++++ plugins/channelrx/demodrtty/rttydemod.h | 2 ++ plugins/channelrx/demodssb/ssbdemod.cpp | 1 + plugins/channelrx/demodssb/ssbdemod.h | 4 ++-- plugins/channelrx/demodvor/vordemod.cpp | 1 + plugins/channelrx/demodvor/vordemod.h | 2 +- plugins/channelrx/demodvormc/vordemodmc.h | 2 +- plugins/channelrx/demodwfm/wfmdemod.cpp | 6 ++++++ plugins/channelrx/demodwfm/wfmdemod.h | 3 ++- plugins/channelrx/filesink/filesink.cpp | 7 +++++++ plugins/channelrx/filesink/filesink.h | 1 + plugins/channelrx/freqscanner/freqscanner.cpp | 6 ++++++ plugins/channelrx/freqscanner/freqscanner.h | 1 + plugins/channelrx/freqtracker/freqtracker.cpp | 6 ++++++ plugins/channelrx/freqtracker/freqtracker.h | 1 + plugins/channelrx/heatmap/heatmap.cpp | 5 +++++ plugins/channelrx/heatmap/heatmap.h | 1 + plugins/channelrx/localsink/localsink.cpp | 6 ++++++ plugins/channelrx/localsink/localsink.h | 1 + plugins/channelrx/noisefigure/noisefigure.cpp | 5 +++++ plugins/channelrx/noisefigure/noisefigure.h | 1 + plugins/channelrx/radioastronomy/radioastronomy.cpp | 5 +++++ plugins/channelrx/radioastronomy/radioastronomy.h | 1 + plugins/channelrx/radioclock/radioclock.cpp | 5 +++++ plugins/channelrx/radioclock/radioclock.h | 1 + plugins/channelrx/remotesink/remotesink.cpp | 6 ++++++ plugins/channelrx/remotesink/remotesink.h | 1 + plugins/channelrx/remotetcpsink/remotetcpsink.cpp | 5 +++++ plugins/channelrx/remotetcpsink/remotetcpsink.h | 1 + plugins/channelrx/sigmffilesink/sigmffilesink.cpp | 7 +++++++ plugins/channelrx/sigmffilesink/sigmffilesink.h | 1 + plugins/channelrx/udpsink/udpsink.cpp | 5 +++++ plugins/channelrx/udpsink/udpsink.h | 1 + plugins/channelrx/wdsprx/wdsprx.cpp | 1 + plugins/channelrx/wdsprx/wdsprx.h | 4 ++-- plugins/channeltx/filesource/filesource.cpp | 5 +++++ plugins/channeltx/filesource/filesource.h | 1 + plugins/channeltx/localsource/localsource.cpp | 5 +++++ plugins/channeltx/localsource/localsource.h | 1 + plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.cpp | 5 +++++ plugins/channeltx/mod802.15.4/ieee_802_15_4_mod.h | 1 + plugins/channeltx/modais/aismod.cpp | 10 ++++++++++ plugins/channeltx/modais/aismod.h | 2 ++ plugins/channeltx/modam/ammod.cpp | 6 ++++++ plugins/channeltx/modam/ammod.h | 3 ++- plugins/channeltx/modatv/atvmod.cpp | 5 +++++ plugins/channeltx/modatv/atvmod.h | 1 + plugins/channeltx/modchirpchat/chirpchatmod.cpp | 5 +++++ plugins/channeltx/modchirpchat/chirpchatmod.h | 1 + plugins/channeltx/moddatv/datvmod.cpp | 5 +++++ plugins/channeltx/moddatv/datvmod.h | 1 + plugins/channeltx/modfreedv/freedvmod.cpp | 5 +++++ plugins/channeltx/modfreedv/freedvmod.h | 3 ++- plugins/channeltx/modm17/m17mod.cpp | 5 +++++ plugins/channeltx/modm17/m17mod.h | 3 ++- plugins/channeltx/modmeshcore/meshcoremod.cpp | 5 +++++ plugins/channeltx/modmeshcore/meshcoremod.h | 1 + plugins/channeltx/modmeshtastic/meshtasticmod.cpp | 5 +++++ plugins/channeltx/modmeshtastic/meshtasticmod.h | 1 + plugins/channeltx/modnfm/nfmmod.cpp | 6 ++++++ plugins/channeltx/modnfm/nfmmod.h | 3 ++- plugins/channeltx/modpacket/packetmod.cpp | 10 ++++++++++ plugins/channeltx/modpacket/packetmod.h | 2 ++ plugins/channeltx/modpsk31/psk31mod.cpp | 10 ++++++++++ plugins/channeltx/modpsk31/psk31mod.h | 2 ++ plugins/channeltx/modrtty/rttymod.cpp | 10 ++++++++++ plugins/channeltx/modrtty/rttymod.h | 2 ++ plugins/channeltx/modssb/ssbmod.cpp | 5 +++++ plugins/channeltx/modssb/ssbmod.h | 3 ++- plugins/channeltx/modwfm/wfmmod.cpp | 5 +++++ plugins/channeltx/modwfm/wfmmod.h | 3 ++- plugins/channeltx/remotesource/remotesource.cpp | 5 +++++ plugins/channeltx/remotesource/remotesource.h | 1 + plugins/channeltx/udpsource/udpsource.cpp | 5 +++++ plugins/channeltx/udpsource/udpsource.h | 1 + sdrbase/channel/channelapi.h | 2 ++ 129 files changed, 490 insertions(+), 28 deletions(-) diff --git a/plugins/channelmimo/doa2/doa2.cpp b/plugins/channelmimo/doa2/doa2.cpp index 87e9e9bdc..d26643304 100644 --- a/plugins/channelmimo/doa2/doa2.cpp +++ b/plugins/channelmimo/doa2/doa2.cpp @@ -694,3 +694,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 ba4d7da43..0cf5f0c7c 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzer.cpp @@ -53,7 +53,7 @@ ChannelAnalyzer::ChannelAnalyzer(DeviceAPI *deviceAPI) : { qDebug("ChannelAnalyzer::ChannelAnalyzer"); setObjectName(m_channelId); - getChannelSampleRate(); + getBasebandSampleRate(); m_basebandSink = new ChannelAnalyzerBaseband(); m_basebandSink->moveToThread(&m_thread); @@ -116,7 +116,7 @@ uint32_t ChannelAnalyzer::getNumberOfDeviceStreams() const return m_deviceAPI->getNbSourceStreams(); } -int ChannelAnalyzer::getChannelSampleRate() +int ChannelAnalyzer::getBasebandSampleRate() { DeviceSampleSource *source = m_deviceAPI->getSampleSource(); @@ -724,3 +724,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 5d4f724d8..398309cde 100644 --- a/plugins/channelrx/channelpower/channelpower.cpp +++ b/plugins/channelrx/channelpower/channelpower.cpp @@ -563,3 +563,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 d03bfcd0c..fdd49ea81 100644 --- a/plugins/channelrx/demodadsb/adsbdemod.cpp +++ b/plugins/channelrx/demodadsb/adsbdemod.cpp @@ -807,3 +807,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 3c745e8e1..788bcb984 100644 --- a/plugins/channelrx/demodais/aisdemod.cpp +++ b/plugins/channelrx/demodais/aisdemod.cpp @@ -751,3 +751,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 f66b6a004..e155331bd 100644 --- a/plugins/channelrx/demodam/amdemod.cpp +++ b/plugins/channelrx/demodam/amdemod.cpp @@ -157,6 +157,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) @@ -717,3 +718,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 27d20ce5a..078845d7e 100644 --- a/plugins/channelrx/demodatv/atvdemod.cpp +++ b/plugins/channelrx/demodatv/atvdemod.cpp @@ -209,3 +209,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 71ab4520b..a75a0be1c 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.cpp +++ b/plugins/channelrx/demodbfm/bfmdemod.cpp @@ -163,6 +163,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) @@ -761,3 +762,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 bddc7f512..285204884 100644 --- a/plugins/channelrx/demodchirpchat/chirpchatdemod.cpp +++ b/plugins/channelrx/demodchirpchat/chirpchatdemod.cpp @@ -183,6 +183,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; @@ -1094,3 +1095,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 b0daca5d6..c7546dc4b 100644 --- a/plugins/channelrx/demoddab/dabdemod.cpp +++ b/plugins/channelrx/demoddab/dabdemod.cpp @@ -917,3 +917,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 36f2aa49b..5abbacb32 100644 --- a/plugins/channelrx/demoddsc/dscdemod.cpp +++ b/plugins/channelrx/demoddsc/dscdemod.cpp @@ -760,3 +760,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 11c6d1998..cba3835d8 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), @@ -202,6 +203,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) @@ -920,3 +922,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 997ca1301..e4a58f2dd 100644 --- a/plugins/channelrx/demodendoftrain/endoftraindemod.cpp +++ b/plugins/channelrx/demodendoftrain/endoftraindemod.cpp @@ -699,3 +699,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 e0687f46a..d5c94e74b 100644 --- a/plugins/channelrx/demodfreedv/freedvdemod.cpp +++ b/plugins/channelrx/demodfreedv/freedvdemod.cpp @@ -655,3 +655,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 377c787e0..507e31eab 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), @@ -205,6 +206,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) @@ -859,3 +861,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 111ccc463..8879d1574 100644 --- a/plugins/channelrx/demodils/ilsdemod.cpp +++ b/plugins/channelrx/demodils/ilsdemod.cpp @@ -918,3 +918,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 1e5865d8c..f91c32824 100644 --- a/plugins/channelrx/demodinmarsat/inmarsatdemod.cpp +++ b/plugins/channelrx/demodinmarsat/inmarsatdemod.cpp @@ -693,3 +693,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 46285c615..ba3254399 100644 --- a/plugins/channelrx/demodm17/m17demod.cpp +++ b/plugins/channelrx/demodm17/m17demod.cpp @@ -165,6 +165,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) @@ -761,3 +762,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 4825a20b7..c301e3cc4 100644 --- a/plugins/channelrx/demodmeshcore/meshcoredemod.cpp +++ b/plugins/channelrx/demodmeshcore/meshcoredemod.cpp @@ -1753,3 +1753,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 245d4c979..74afae893 100644 --- a/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp +++ b/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp @@ -1683,3 +1683,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 265eacb7c..42c86a4fe 100644 --- a/plugins/channelrx/demodnavtex/navtexdemod.cpp +++ b/plugins/channelrx/demodnavtex/navtexdemod.cpp @@ -749,3 +749,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 92c4fc289..2991f9422 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.cpp +++ b/plugins/channelrx/demodnfm/nfmdemod.cpp @@ -173,6 +173,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) @@ -721,3 +722,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 bc8b70f11..9ba17d67f 100644 --- a/plugins/channelrx/demodpacket/packetdemod.cpp +++ b/plugins/channelrx/demodpacket/packetdemod.cpp @@ -715,3 +715,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 9f01a7ea2..cc3666cba 100644 --- a/plugins/channelrx/demodpager/pagerdemod.cpp +++ b/plugins/channelrx/demodpager/pagerdemod.cpp @@ -723,3 +723,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 65758e3d8..2553f2a9c 100644 --- a/plugins/channelrx/demodradiosonde/radiosondedemod.cpp +++ b/plugins/channelrx/demodradiosonde/radiosondedemod.cpp @@ -767,3 +767,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 f50637209..b21062cac 100644 --- a/plugins/channelrx/demodrtty/rttydemod.cpp +++ b/plugins/channelrx/demodrtty/rttydemod.cpp @@ -794,3 +794,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 4c5378f96..d4cb23202 100644 --- a/plugins/channelrx/demodssb/ssbdemod.cpp +++ b/plugins/channelrx/demodssb/ssbdemod.cpp @@ -190,6 +190,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 a09de93f5..3740b5a26 100644 --- a/plugins/channelrx/demodvor/vordemod.cpp +++ b/plugins/channelrx/demodvor/vordemod.cpp @@ -164,6 +164,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 b2552c864..c60d72f2d 100644 --- a/plugins/channelrx/demodwfm/wfmdemod.cpp +++ b/plugins/channelrx/demodwfm/wfmdemod.cpp @@ -161,6 +161,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) @@ -662,3 +663,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 33f8697dc..324a26fa1 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), @@ -206,6 +207,7 @@ void FileSink::stop() m_thread->quit(); m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished if (getMessageQueueToGUI()) { @@ -833,3 +835,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 b29957194..452639367 100644 --- a/plugins/channelrx/freqscanner/freqscanner.cpp +++ b/plugins/channelrx/freqscanner/freqscanner.cpp @@ -201,6 +201,7 @@ void FreqScanner::stop() m_thread->exit(); #ifndef __EMSCRIPTEN__ m_thread->wait(); + m_basebandSink = nullptr; // Freed by deleteLater when the thread finished #endif } @@ -1455,3 +1456,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 99f71a521..ac46b5095 100644 --- a/plugins/channelrx/freqtracker/freqtracker.cpp +++ b/plugins/channelrx/freqtracker/freqtracker.cpp @@ -160,6 +160,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) @@ -708,3 +709,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 3d3d8b3bc..e068f321d 100644 --- a/plugins/channelrx/heatmap/heatmap.cpp +++ b/plugins/channelrx/heatmap/heatmap.cpp @@ -599,3 +599,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 c96fc6575..fbd6a7b3f 100644 --- a/plugins/channelrx/localsink/localsink.cpp +++ b/plugins/channelrx/localsink/localsink.cpp @@ -185,6 +185,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) @@ -861,3 +862,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 34a009ba2..3f586d624 100644 --- a/plugins/channelrx/noisefigure/noisefigure.cpp +++ b/plugins/channelrx/noisefigure/noisefigure.cpp @@ -977,3 +977,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 7d3248609..1d767fc85 100644 --- a/plugins/channelrx/radioastronomy/radioastronomy.cpp +++ b/plugins/channelrx/radioastronomy/radioastronomy.cpp @@ -1357,3 +1357,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 9401aed96..88b8da6ed 100644 --- a/plugins/channelrx/radioclock/radioclock.cpp +++ b/plugins/channelrx/radioclock/radioclock.cpp @@ -628,3 +628,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 2956a6167..54500050e 100644 --- a/plugins/channelrx/remotesink/remotesink.cpp +++ b/plugins/channelrx/remotesink/remotesink.cpp @@ -162,6 +162,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) @@ -705,3 +706,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 46ad2907d..75dd8e262 100644 --- a/plugins/channelrx/remotetcpsink/remotetcpsink.cpp +++ b/plugins/channelrx/remotetcpsink/remotetcpsink.cpp @@ -764,3 +764,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 5d826ea2d..99243915d 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), @@ -204,6 +205,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()) { @@ -838,3 +840,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 6480bdddf..5cf65450a 100644 --- a/plugins/channelrx/udpsink/udpsink.cpp +++ b/plugins/channelrx/udpsink/udpsink.cpp @@ -695,3 +695,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 079fa17ba..70642ab15 100644 --- a/plugins/channelrx/wdsprx/wdsprx.cpp +++ b/plugins/channelrx/wdsprx/wdsprx.cpp @@ -192,6 +192,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 551e90ea9..61cafe420 100644 --- a/plugins/channeltx/filesource/filesource.cpp +++ b/plugins/channeltx/filesource/filesource.cpp @@ -701,3 +701,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 da3ca869d..2d0ba2d71 100644 --- a/plugins/channeltx/localsource/localsource.cpp +++ b/plugins/channeltx/localsource/localsource.cpp @@ -627,3 +627,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 4a96860d2..d6fddf69b 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 @@ -813,3 +813,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 27e3ab039..a4e36e233 100644 --- a/plugins/channeltx/modais/aismod.cpp +++ b/plugins/channeltx/modais/aismod.cpp @@ -996,3 +996,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 1a2feba19..b1b2f2c32 100644 --- a/plugins/channeltx/modam/ammod.cpp +++ b/plugins/channeltx/modam/ammod.cpp @@ -161,6 +161,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) @@ -836,3 +837,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 87ab166c8..57a9858a8 100644 --- a/plugins/channeltx/modatv/atvmod.cpp +++ b/plugins/channeltx/modatv/atvmod.cpp @@ -800,3 +800,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 1b5165244..100ed308c 100644 --- a/plugins/channeltx/modchirpchat/chirpchatmod.cpp +++ b/plugins/channeltx/modchirpchat/chirpchatmod.cpp @@ -1154,3 +1154,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 84c133720..9a6a8bb3b 100644 --- a/plugins/channeltx/moddatv/datvmod.cpp +++ b/plugins/channeltx/moddatv/datvmod.cpp @@ -790,3 +790,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 3a7a242c7..52cb50f25 100644 --- a/plugins/channeltx/modfreedv/freedvmod.cpp +++ b/plugins/channeltx/modfreedv/freedvmod.cpp @@ -810,3 +810,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 141ebc3fe..2dd1d4974 100644 --- a/plugins/channeltx/modm17/m17mod.cpp +++ b/plugins/channeltx/modm17/m17mod.cpp @@ -955,3 +955,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 0a45a083e..99dea0c39 100644 --- a/plugins/channeltx/modmeshcore/meshcoremod.cpp +++ b/plugins/channeltx/modmeshcore/meshcoremod.cpp @@ -907,3 +907,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 6840495d2..d3703fdff 100644 --- a/plugins/channeltx/modmeshtastic/meshtasticmod.cpp +++ b/plugins/channeltx/modmeshtastic/meshtasticmod.cpp @@ -870,3 +870,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 6a1fbc261..d057b5257 100644 --- a/plugins/channeltx/modnfm/nfmmod.cpp +++ b/plugins/channeltx/modnfm/nfmmod.cpp @@ -158,6 +158,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) @@ -923,3 +924,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 b1dc4a224..ea08d3e8a 100644 --- a/plugins/channeltx/modpacket/packetmod.cpp +++ b/plugins/channeltx/modpacket/packetmod.cpp @@ -1016,3 +1016,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 4fdae2cdf..830327102 100644 --- a/plugins/channeltx/modpsk31/psk31mod.cpp +++ b/plugins/channeltx/modpsk31/psk31mod.cpp @@ -798,3 +798,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 9197e83e7..90e06175c 100644 --- a/plugins/channeltx/modrtty/rttymod.cpp +++ b/plugins/channeltx/modrtty/rttymod.cpp @@ -841,3 +841,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 874acfa83..24fb6fd03 100644 --- a/plugins/channeltx/modssb/ssbmod.cpp +++ b/plugins/channeltx/modssb/ssbmod.cpp @@ -922,3 +922,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 4c37b6d68..4183fea3f 100644 --- a/plugins/channeltx/modwfm/wfmmod.cpp +++ b/plugins/channeltx/modwfm/wfmmod.cpp @@ -782,3 +782,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 7459bf27b..e64177c20 100644 --- a/plugins/channeltx/remotesource/remotesource.cpp +++ b/plugins/channeltx/remotesource/remotesource.cpp @@ -602,3 +602,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 656a483d9..b88d7ec95 100644 --- a/plugins/channeltx/udpsource/udpsource.cpp +++ b/plugins/channeltx/udpsource/udpsource.cpp @@ -741,3 +741,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/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; From 467ad6dfa4699ebc163e1851b67137a482a3c9c3 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 28 Sep 2026 14:05:04 +0100 Subject: [PATCH 3/8] Remove object names as no longer needed. --- sdrgui/channel/channelgui.cpp | 1 - sdrgui/device/devicegui.cpp | 1 - sdrgui/feature/featuregui.cpp | 1 - sdrgui/mainspectrum/mainspectrumgui.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/sdrgui/channel/channelgui.cpp b/sdrgui/channel/channelgui.cpp index 88ea87050..cc07bf45b 100644 --- a/sdrgui/channel/channelgui.cpp +++ b/sdrgui/channel/channelgui.cpp @@ -58,7 +58,6 @@ ChannelGUI::ChannelGUI(QWidget *parent) : .arg(palette().dark().color().darker(115).name()))); m_indexLabel = new QLabel(); - m_indexLabel->setObjectName("connectionIndexLabel"); m_indexLabel->setFixedSize(50, 16); m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }"); m_indexLabel->setText(tr("X%1:%2").arg(m_deviceSetIndex).arg(m_channelIndex)); diff --git a/sdrgui/device/devicegui.cpp b/sdrgui/device/devicegui.cpp index 0bb38ce1e..671ff7f8e 100644 --- a/sdrgui/device/devicegui.cpp +++ b/sdrgui/device/devicegui.cpp @@ -55,7 +55,6 @@ DeviceGUI::DeviceGUI(QWidget *parent) : .arg(palette().dark().color().darker(115).name())); m_indexLabel = new QLabel(); - m_indexLabel->setObjectName("connectionIndexLabel"); m_indexLabel->setFixedSize(32, 16); m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }"); m_indexLabel->setText(tr("X:%1").arg(m_deviceSetIndex)); diff --git a/sdrgui/feature/featuregui.cpp b/sdrgui/feature/featuregui.cpp index e3439f821..a74dc5c29 100644 --- a/sdrgui/feature/featuregui.cpp +++ b/sdrgui/feature/featuregui.cpp @@ -56,7 +56,6 @@ FeatureGUI::FeatureGUI(QWidget *parent) : .arg(palette().dark().color().darker(115).name())); m_indexLabel = new QLabel(); - m_indexLabel->setObjectName("connectionIndexLabel"); m_indexLabel->setFixedSize(40, 16); m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }"); m_indexLabel->setText(tr("F:%1").arg(m_featureIndex)); diff --git a/sdrgui/mainspectrum/mainspectrumgui.cpp b/sdrgui/mainspectrum/mainspectrumgui.cpp index 457f7dfe0..0c17b7071 100644 --- a/sdrgui/mainspectrum/mainspectrumgui.cpp +++ b/sdrgui/mainspectrum/mainspectrumgui.cpp @@ -56,7 +56,6 @@ MainSpectrumGUI::MainSpectrumGUI(GLSpectrum *spectrum, GLSpectrumGUI *spectrumGU setMinimumSize(m_MinimumWidth, m_MinimumHeight); m_indexLabel = new QLabel(); - m_indexLabel->setObjectName("connectionIndexLabel"); m_indexLabel->setFixedSize(32, 16); m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }"); m_indexLabel->setText(tr("X:%1").arg(m_deviceSetIndex)); From 87aa906a49d628fb0f7f998683ca8572369b4cb6 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 28 Sep 2026 14:06:06 +0100 Subject: [PATCH 4/8] Add labels indicating IQ or Audio and sample rates. --- sdrgui/mainwindow.cpp | 88 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 87afccebb..a6e720933 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -2734,10 +2734,32 @@ void MainWindow::updateConnectionOverlays() 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) { @@ -2748,12 +2770,33 @@ void MainWindow::updateConnectionOverlays() (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}; + 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) { + int targetWorkspace, ConnectionOverlay::Direction direction, + const QString& flowLabel, const QColor& color) { if (!target) { return; } @@ -2762,21 +2805,22 @@ void MainWindow::updateConnectionOverlays() connection.target = target; connection.sourceLabel = deviceLabel; connection.targetLabel = label; - connection.flowLabel = "IQ"; + connection.flowLabel = flowLabel; connection.sourceWorkspace = device->getWorkspaceIndex(); connection.targetWorkspace = targetWorkspace; connection.direction = direction; - connection.color = deviceColor; + connection.color = color; connections.append(connection); }; - const ConnectionOverlay::Direction spectrumDirection = - device->getDeviceType() == DeviceGUI::DeviceTx ? ConnectionOverlay::Reverse : - (device->getDeviceType() == DeviceGUI::DeviceMIMO ? ConnectionOverlay::BothDirections : ConnectionOverlay::Forward); + // 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); + deviceUI->m_mainSpectrumGUI->getWorkspaceIndex(), spectrumDirection, iqLabel(spectrumRate, spectrumRate), deviceColor); } for (int channelIndex = 0; channelIndex < deviceUI->getNumberOfChannels(); ++channelIndex) { @@ -2788,11 +2832,22 @@ void MainWindow::updateConnectionOverlays() const int type = deviceUI->getChannelTypeAt(channelIndex); const ConnectionOverlay::Direction direction = type == 1 ? ConnectionOverlay::Reverse : (type == 2 ? ConnectionOverlay::BothDirections : ConnectionOverlay::Forward); - appendDeviceConnection(channel, channelLabel, channel->getWorkspaceIndex(), direction); + 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()}; + channel->getIndexLabelColor(), channelAPI}; endpoints.insert(channel, endpoint); - if (ChannelAPI *channelAPI = deviceUI->getChannelAt(channelIndex)) { + if (channelAPI) { endpoints.insert(channelAPI, endpoint); } } @@ -2810,7 +2865,7 @@ void MainWindow::updateConnectionOverlays() continue; } const Endpoint endpoint{featureGUI, QString("F%1").arg(featureGUI->getIndex()), - featureGUI->getWorkspaceIndex(), true, QColor()}; + featureGUI->getWorkspaceIndex(), true, QColor(), nullptr}; endpoints.insert(featureGUI, endpoint); if (Feature *feature = featureUI->getFeatureAt(featureIndex)) { endpoints.insert(feature, endpoint); @@ -2835,6 +2890,9 @@ void MainWindow::updateConnectionOverlays() 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) { @@ -2848,8 +2906,8 @@ void MainWindow::updateConnectionOverlays() const int existingIndex = pipeConnectionIndices.value(source.window).value(target.window, -1); if (existingIndex >= 0) { - if (pipe.type == "demod") { - connections[existingIndex].flowLabel = "Audio"; + if (audio) { + connections[existingIndex].flowLabel = audioLabel(source); } continue; } @@ -2858,7 +2916,7 @@ void MainWindow::updateConnectionOverlays() connection.target = target.window; connection.sourceLabel = source.label; connection.targetLabel = target.label; - connection.flowLabel = pipe.type == "demod" ? "Audio" : "Data"; + connection.flowLabel = audio ? audioLabel(source) : QString("Data"); connection.sourceWorkspace = source.workspace; connection.targetWorkspace = target.workspace; connection.kind = ConnectionOverlay::PipeLink; From 97e1cc1601660525aba0acae698403fd5779a9b5 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 28 Sep 2026 14:13:15 +0100 Subject: [PATCH 5/8] Use OpenGL for overlay for better blending. Improve routing. --- sdrgui/gui/connectionoverlay.cpp | 1347 +++++++++++++++++++++++------- sdrgui/gui/connectionoverlay.h | 97 ++- sdrgui/mainwindow.cpp | 40 +- 3 files changed, 1133 insertions(+), 351 deletions(-) diff --git a/sdrgui/gui/connectionoverlay.cpp b/sdrgui/gui/connectionoverlay.cpp index 9baee8672..94f1fd1a3 100644 --- a/sdrgui/gui/connectionoverlay.cpp +++ b/sdrgui/gui/connectionoverlay.cpp @@ -27,18 +27,35 @@ #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; + ConnectionOverlay::ConnectionOverlay(QMdiArea *mdi) : - QWidget(mdi), + QOpenGLWidget(mdi), m_mdi(mdi) { // QMdiArea scrolls its viewport children; keep the overlay fixed above the viewport. setAttribute(Qt::WA_TransparentForMouseEvents); - setAttribute(Qt::WA_TranslucentBackground); + // 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); @@ -47,6 +64,50 @@ ConnectionOverlay::ConnectionOverlay(QMdiArea *mdi) : 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()) { @@ -56,11 +117,11 @@ bool ConnectionOverlay::sameConnections(const QList& a, const QList< { const Connection& x = a[i]; const Connection& y = b[i]; - if (x.source.data() != y.source.data() || x.target.data() != y.target.data() || - x.sourceLabel != y.sourceLabel || x.targetLabel != y.targetLabel || - x.flowLabel != y.flowLabel || x.sourceWorkspace != y.sourceWorkspace || - x.targetWorkspace != y.targetWorkspace || x.kind != y.kind || - x.direction != y.direction || x.color != y.color) { + 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; } } @@ -74,14 +135,13 @@ void ConnectionOverlay::setConnections(const QList& connections) return; } m_connections = connections; - m_indexLabels.clear(); - // Cache each title ID widget so paths can anchor beside it and avoid painting over it. + m_windows.clear(); for (const Connection& connection : m_connections) { - for (QMdiSubWindow *window : {connection.source.data(), connection.target.data()}) + for (QMdiSubWindow *window : {connection.m_source.data(), connection.m_target.data()}) { - if (window && !m_indexLabels.contains(window)) { - m_indexLabels.insert(window, window->findChild("connectionIndexLabel")); + if (window && !m_windows.contains(window)) { + m_windows.append(window); } } } @@ -91,7 +151,7 @@ void ConnectionOverlay::setConnections(const QList& connections) void ConnectionOverlay::watchWindows() { - // Cached routes depend on the connected windows' geometry and their ID labels. + // Cached routes depend on the connected windows' geometry. for (const QPointer& object : m_watched) { if (object) { @@ -99,15 +159,12 @@ void ConnectionOverlay::watchWindows() } } m_watched.clear(); - for (auto it = m_indexLabels.constBegin(); it != m_indexLabels.constEnd(); ++it) + for (const QPointer& window : m_windows) { - for (QObject *object : {static_cast(it.key()), static_cast(it.value().data())}) + if (window) { - if (object) - { - object->installEventFilter(this); - m_watched.append(object); - } + window->installEventFilter(this); + m_watched.append(window.data()); } } } @@ -126,7 +183,6 @@ void ConnectionOverlay::setOverlayVisible(bool visible) else { m_animationTimer.stop(); - m_pulseRegion = QRegion(); } } @@ -148,12 +204,28 @@ bool ConnectionOverlay::eventFilter(QObject *object, QEvent *event) 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) { - invalidateLayout(); // A connected window or its ID label moved, e.g. when scrolling. + 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 QWidget::eventFilter(object, event); + return QOpenGLWidget::eventFilter(object, event); } void ConnectionOverlay::changeEvent(QEvent *event) @@ -161,7 +233,7 @@ void ConnectionOverlay::changeEvent(QEvent *event) if (event->type() == QEvent::FontChange || event->type() == QEvent::PaletteChange) { invalidateLayout(); } - QWidget::changeEvent(event); + QOpenGLWidget::changeEvent(event); } void ConnectionOverlay::invalidateLayout() @@ -188,7 +260,7 @@ void ConnectionOverlay::relayout() void ConnectionOverlay::showEvent(QShowEvent *event) { - QWidget::showEvent(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) @@ -241,88 +313,399 @@ static QPainterPath roundedRoute(const QVector& points) return path; } -static int crossingCost(const QPainterPath& path, const QRectF& sourceBox, const QRectF& targetBox) +// 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) { - // Count samples drawn over a window body. An endpoint can be inside a window, - // e.g. the source's own title bar, or an ID label covered by an overlapping - // window. The route may then leave that window at the start, or arrive in it - // at the end, but any other part inside a window is a crossing. + 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; - QPointF points[samples + 1]; - for (int i = 0; i <= samples; ++i) { - points[i] = path.pointAtPercent(qreal(i) / samples); + 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; } - int cost = 0; - for (const QRectF& box : {sourceBox, targetBox}) + 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()) { - continue; + 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 } - const QRectF body = box.adjusted(-2, -2, 2, 2); int first = 0; - while (first <= samples && body.contains(points[first])) { + while (first <= last && first < maxFree && body.contains(points[first])) { ++first; // Leading run inside, leaving the start window } - int last = samples; - while (last >= first && body.contains(points[last])) { - --last; // Trailing run inside, arriving in the end window + int end = last; + while (end >= first && last - end < maxFree && body.contains(points[end])) { + --end; // Trailing run inside, arriving in the end window } - for (int i = first; i <= last; ++i) + // 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])) { - ++cost; + 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); } - return cost; + // 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; } -static QPainterPath connectionPath(const QPointF& from, const QPointF& to, - int fromSide, int toSide, const QRectF& sourceBox, - const QRectF& targetBox, const QRectF& bounds) +// 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 = 14; + 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; - const qreal handle = qBound(32, qAbs(delta.x()) * 0.35 + qAbs(delta.y()) * 0.3, 180); + // 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 (fromSide != 0) { - direct.lineTo(curveFrom); - } - direct.cubicTo(firstControl, lastControl, curveTo); - if (toSide != 0) { - direct.lineTo(to); - } - if (sourceBox.isEmpty() || targetBox.isEmpty()) { - return direct; + 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}); } - // Prefer the route that crosses windows least, then the shortest. 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. - QPainterPath bestRoute = direct; - int bestCost = crossingCost(direct, sourceBox, targetBox); - qreal bestLength = direct.length(); - if (bestCost == 0) { - return direct; + 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) { - const qreal length = candidate.length(); - if (bestCost == 0 && length >= bestLength) { - return; // Cannot beat a shorter clear route + 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); } - const int cost = crossingCost(candidate, sourceBox, targetBox); - if (cost < bestCost || (cost == bestCost && length < bestLength)) + for (qreal elbowX : elbowXs) { - bestRoute = candidate; - bestCost = cost; - bestLength = length; + 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; @@ -403,10 +786,82 @@ static QPainterPath connectionPath(const QPointF& from, const QPointF& 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; } -bool ConnectionOverlay::computeLayout() +void ConnectionOverlay::computeLayout() { m_layoutDirty = false; m_routes.clear(); @@ -414,9 +869,7 @@ bool ConnectionOverlay::computeLayout() const QRectF bounds = rect().adjusted(8, 8, -8, -8); const QPoint viewportOffset = m_mdi->viewport()->pos() - pos(); const QFontMetrics metrics(font()); - m_clipRegion = QRegion(rect()); - QRegion paintedRegion; - QVector labelObstacles; // Title ID labels, then each label as it is placed + 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; @@ -426,184 +879,450 @@ bool ConnectionOverlay::computeLayout() const int step = (n + 1) / 2; // 0, 1, 1, 2, 2, ... return (n % 2 ? step : -step) * stubSpacing; // 0, +1, -1, +2, -2, ... }; - QPainterPathStroker maskStroker; - maskStroker.setWidth(20); - maskStroker.setCapStyle(Qt::RoundCap); - maskStroker.setJoinStyle(Qt::RoundJoin); - for (auto it = m_indexLabels.constBegin(); it != m_indexLabels.constEnd(); ++it) - { - QMdiSubWindow *window = it.key(); - QWidget *indexLabel = it.value().data(); - if (!window || !localWindows.contains(window) || !indexLabel || !indexLabel->isVisible()) { - continue; + // 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; + } } - const QPoint labelTopLeft = window->geometry().topLeft() + - indexLabel->mapTo(window, QPoint(0, 0)) + viewportOffset; - const QRect indexRect = QRect(labelTopLeft, indexLabel->size()).adjusted(-2, -2, 2, 2); - m_clipRegion -= indexRect; - labelObstacles.append(indexRect); - } - // The overlay is a sibling of the scrolling viewport, so translate MDI - // window coordinates before using their title labels as endpoints. - auto anchorFor = [this, &viewportOffset](QMdiSubWindow *window, int side) -> QPointF { - QWidget *indexLabel = m_indexLabels.value(window).data(); - const QPoint insideWindow = indexLabel && indexLabel->isVisible() ? - indexLabel->mapTo(window, QPoint(side < 0 ? -10 : indexLabel->width() + 10, - indexLabel->height() / 2)) : - QPoint(side < 0 ? -10 : 48, 12); - return QPointF(window->geometry().topLeft() + insideWindow + viewportOffset); + 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 ? -6 : window->width() + 6, titleBarMiddle); + return QPointF(window->geometry().topLeft() + inWindow + viewportOffset); }; - for (const Connection& connection : m_connections) + // 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 { - if (!connection.source || !connection.target) { + 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.source.data()); - const bool targetLocal = localWindows.contains(connection.target.data()); + 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.source->parentWidget() != m_mdi->viewport() || - !connection.source->isVisible() || connection.source->isMinimized())) { + if (sourceLocal && (connection.m_source->parentWidget() != m_mdi->viewport() || + !connection.m_source->isVisible() || connection.m_source->isMinimized())) { continue; } - if (targetLocal && (connection.target->parentWidget() != m_mdi->viewport() || - !connection.target->isVisible() || connection.target->isMinimized())) { + if (targetLocal && (connection.m_target->parentWidget() != m_mdi->viewport() || + !connection.m_target->isVisible() || connection.m_target->isMinimized())) { continue; } - const int sourceSide = 1; // Device ID, or the producer of a pipe. - const int targetSide = -1; // Inputs meet the left side of channel, spectrum, and feature IDs. - const QPointF sourceAnchor = sourceLocal ? anchorFor(connection.source.data(), sourceSide) : QPointF(); - const QPointF targetAnchor = targetLocal ? anchorFor(connection.target.data(), targetSide) : QPointF(); - const bool sourceVisible = sourceLocal && bounds.contains(sourceAnchor); - const bool targetVisible = targetLocal && bounds.contains(targetAnchor); + // 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 stubDirection = 0; // Which way a cross-workspace stub goes from its window + 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.from = sourceAnchor; - route.to = targetAnchor; + 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.from = sourceAnchor; - route.to = viewportEdge(bounds, targetAnchor); - markerEdge = route.to; - route.marker = scrollArrow(bounds, targetAnchor) + " " + connection.targetLabel; + 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.from = viewportEdge(bounds, sourceAnchor); - route.to = targetAnchor; - markerEdge = route.from; - route.marker = scrollArrow(bounds, sourceAnchor) + " " + connection.sourceLabel; + 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.from = sourceAnchor; - route.marker = QString("W%1 · %2").arg(connection.targetWorkspace).arg(connection.targetLabel); - if (!connection.flowLabel.isEmpty()) { - route.marker += " · " + connection.flowLabel; // One label per stub, at its tip + 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 } - const qreal markerWidth = metrics.horizontalAdvance(route.marker) + 8; - const qreal stubLength = 90; - const qreal stubY = qBound(bounds.top() + 4, route.from.y() + fanOffset(connection.source.data(), sourceSide), - bounds.bottom() - 4); - // Stubs leave to the right. Near the right edge there is no room for the - // stub and its label, so go left instead, past the window's ID label. - stubDirection = route.from.x() + stubLength + markerWidth + 10 <= bounds.right() ? 1 : -1; - const qreal tipX = stubDirection > 0 ? route.from.x() + stubLength : - qMax(bounds.left() + markerWidth + 10, route.from.x() - stubLength - 60); - route.to = QPointF(tipX, stubY); - route.stubTip = 1; + 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.to = targetAnchor; - route.marker = QString("W%1 · %2").arg(connection.sourceWorkspace).arg(connection.sourceLabel); - if (!connection.flowLabel.isEmpty()) { - route.marker += " · " + connection.flowLabel; // One label per stub, at its tip + 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 } - const qreal markerWidth = metrics.horizontalAdvance(route.marker) + 8; - const qreal stubLength = 90; - // Stubs arrive from the left. Near the left edge there is no room for the - // stub and its label, so come from the right instead, past the ID label. - stubDirection = route.to.x() - stubLength - markerWidth - 10 >= bounds.left() ? -1 : 1; - const qreal tipX = stubDirection < 0 ? route.to.x() - stubLength : - qMin(bounds.right() - markerWidth - 10, route.to.x() + stubLength + 60); - const qreal stubY = qBound(bounds.top() + 4, route.to.y() + fanOffset(connection.target.data(), targetSide), - bounds.bottom() - 4); - route.from = QPointF(tipX, stubY); - route.stubTip = -1; + 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.from; - const QPointF& to = route.to; - - route.color = connection.color.isValid() ? connection.color.lighter(150) : - (connection.kind == PipeLink ? QColor(238, 183, 77) : QColor(56, 204, 228)); - route.kind = connection.kind; - route.direction = connection.direction; - route.sourceBox = sourceVisible ? - QRectF(connection.source->geometry().translated(viewportOffset)) : QRectF(); - route.targetBox = targetVisible ? - QRectF(connection.target->geometry().translated(viewportOffset)) : QRectF(); - // A stub flipped to the other side goes straight out, behind its ID label. - route.fromSide = sourceVisible && stubDirection >= 0 ? sourceSide : 0; - route.toSide = targetVisible && stubDirection <= 0 ? targetSide : 0; - route.path = connectionPath(from, to, route.fromSide, route.toSide, - route.sourceBox, route.targetBox, bounds); - route.length = route.path.length(); - - if (!connection.flowLabel.isEmpty() && !crossWorkspace) // Stubs include it in their marker - { - const qreal labelWidth = metrics.horizontalAdvance(connection.flowLabel) + 10; - const qreal labelHeight = metrics.height() + 4; - // Beside each route's own midpoint, so labels of fanned stubs separate too. - const QPointF midpoint = route.path.pointAtPercent(0.5); - const qreal labelX = midpoint.x() - labelWidth / 2; - const qreal labelY = midpoint.y() - labelHeight - 6; - route.flowLabel = connection.flowLabel; - route.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); + 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 (!route.marker.isEmpty()) + if (!connection.m_flowLabel.isEmpty() && !crossWorkspace) // Stubs include it in their marker { - const qreal labelWidth = metrics.horizontalAdvance(route.marker) + 8; + 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, in the direction the stub goes. + // A stub's label continues from its tip, usually in the direction the stub goes. const qreal labelX = crossWorkspace ? - (stubDirection > 0 ? remoteAnchor.x() + 6 : remoteAnchor.x() - labelWidth - 6) : + (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.markerRect = QRectF(qBound(bounds.left() + 4, labelX, + 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 @@ -640,59 +1359,23 @@ bool ConnectionOverlay::computeLayout() }; for (Route& route : m_routes) { - const qreal before = route.markerRect.center().y(); - placeLabel(route.markerRect); - const qreal dy = route.markerRect.center().y() - before; - if (route.stubTip != 0 && !qFuzzyIsNull(dy)) + 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.stubTip > 0 ? route.to : route.from; + QPointF& tip = route.m_stubTip > 0 ? route.m_to : route.m_from; tip.ry() += dy; - route.path = connectionPath(route.from, route.to, route.fromSide, route.toSide, - route.sourceBox, route.targetBox, bounds); - route.length = route.path.length(); + 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.flowLabelRect); - } - // Only now are the routes final, so build the painted region. - for (Route& route : m_routes) - { - QRegion routeRegion(maskStroker.createStroke(route.path).toFillPolygon().toPolygon(), Qt::WindingFill); - routeRegion += QRectF(route.from.x() - 9, route.from.y() - 9, 18, 18).toAlignedRect(); - routeRegion += QRectF(route.to.x() - 9, route.to.y() - 9, 18, 18).toAlignedRect(); - for (const QRectF& label : {route.markerRect, route.flowLabelRect}) - { - if (!label.isEmpty()) { - routeRegion += label.toAlignedRect().adjusted(-2, -2, 2, 2); - } - } - route.bounds = routeRegion.boundingRect(); - paintedRegion += routeRegion; - } - - paintedRegion &= m_clipRegion; - // A full-size widget above QOpenGLWidget spectra can occlude their entire - // viewport. Give the overlay only the pixels needed by its drawing. - if (paintedRegion.isEmpty()) { - paintedRegion = QRegion(0, 0, 1, 1); + placeLabel(route.m_flowLabelRect); } - if (mask() != paintedRegion) - { - // An empty mask means the whole widget was painted. - const QRegion oldMask = mask().isEmpty() ? QRegion(rect()) : mask(); - setMask(paintedRegion); - // setMask() asks the QMdiArea to repaint what the overlay no longer covers, - // but the opaque viewport above it is not repainted, leaving trails of old - // routes. Repaint the viewport (and its sub windows) there explicitly. - const QRegion exposed = oldMask - paintedRegion; - if (!exposed.isEmpty()) { - m_mdi->viewport()->update(exposed.translated(pos() - m_mdi->viewport()->pos())); - } - return true; - } - return false; + updateHighlight(); } QVector ConnectionOverlay::pulses() const @@ -700,14 +1383,14 @@ QVector ConnectionOverlay::pulses() const QVector result; for (const Route& route : m_routes) { - if (route.direction == NoDirection || route.length <= 32) { + if (route.m_direction == NoDirection || route.m_length <= 32 || isDimmed(route)) { continue; } - const int flowCount = route.direction == BothDirections ? 2 : 1; - const int pulsesPerFlow = route.length > 360 ? 2 : 1; + 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.direction == Reverse || (route.direction == BothDirections && flow == 1); + 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; @@ -718,101 +1401,179 @@ QVector ConnectionOverlay::pulses() const progress = 1.0 - progress; } const qreal tailProgress = qBound(0, progress + (reverse ? 0.025 : -0.025), 1); - result.append({route.path.pointAtPercent(tailProgress), route.path.pointAtPercent(progress), route.color}); + result.append({route.m_path.pointAtPercent(tailProgress), route.m_path.pointAtPercent(progress), route.m_color}); } } } return result; } -QRegion ConnectionOverlay::pulsesRegion(const QVector& pulses) const -{ - QRegion region; - for (const Pulse& pulse : pulses) { - region += QRectF(pulse.tail, pulse.head).normalized().adjusted(-9, -9, 9, 9).toAlignedRect(); - } - return region; -} - void ConnectionOverlay::animate() { if (!isVisible()) { return; // Workspace is a background tab, or minimized. } - // Only the pulses move, so repaint just where they were and where they are now. + // An OpenGL widget repaints in full, so only repaint when something is moving. m_phase = (m_clock.elapsed() % 2400) / 2400.0; - const QRegion region = pulsesRegion(pulses()); - const QRegion dirty = m_pulseRegion | region; - m_pulseRegion = region; - if (!dirty.isEmpty()) { - update(dirty); + if (!pulses().isEmpty()) { + update(); } } -void ConnectionOverlay::paintEvent(QPaintEvent *event) +void ConnectionOverlay::paintGL() { - // Paint current geometry rather than a stale cache. This paint is clipped to the - // old mask, so repaint again only if the mask changed. - if (m_layoutDirty && computeLayout()) { - update(); + // 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); } - QPainter painter(this); + 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); - painter.setClipRegion(m_clipRegion & event->region()); - const QRegion& dirty = event->region(); for (const Route& route : m_routes) { - if (!dirty.intersects(route.bounds)) { - continue; - } - const QColor& color = route.color; + 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(), 35), 6, + 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.path); + painter.drawPath(route.m_path); painter.setPen(QPen(QColor(color.red(), color.green(), color.blue(), 180), 2.2, - route.kind == PipeLink ? Qt::DashLine : Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.drawPath(route.path); + 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.from, 4, 4); - painter.drawEllipse(route.to, 4, 4); + 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.color; + 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.tail, pulse.head); + 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.head, 7, 7); + painter.drawEllipse(pulse.m_head, 7, 7); painter.setBrush(QColor(255, 255, 255, 245)); - painter.drawEllipse(pulse.head, 3, 3); + painter.drawEllipse(pulse.m_head, 3, 3); } for (const Route& route : m_routes) { - if (!route.flowLabel.isEmpty() && dirty.intersects(route.flowLabelRect.toAlignedRect())) + painter.setOpacity(isDimmed(route) ? dimmedOpacity : 1.0); + if (!route.m_flowLabel.isEmpty()) { - painter.setPen(QPen(route.color, 1)); + painter.setPen(QPen(route.m_color, 1)); painter.setBrush(QColor(24, 28, 32, 235)); - painter.drawRoundedRect(route.flowLabelRect, 3, 3); + painter.drawRoundedRect(route.m_flowLabelRect, 3, 3); painter.setPen(Qt::white); - painter.drawText(route.flowLabelRect, Qt::AlignCenter, route.flowLabel); + painter.drawText(route.m_flowLabelRect, Qt::AlignCenter, route.m_flowLabel); } - if (!route.marker.isEmpty() && dirty.intersects(route.markerRect.toAlignedRect())) + if (!route.m_marker.isEmpty()) { painter.setPen(Qt::NoPen); painter.setBrush(QColor(24, 28, 32, 235)); - painter.drawRoundedRect(route.markerRect, 3, 3); + painter.drawRoundedRect(route.m_markerRect, 3, 3); painter.setPen(Qt::white); - painter.drawText(route.markerRect, Qt::AlignCenter, route.marker); + 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 index fb04620a1..08061574c 100644 --- a/sdrgui/gui/connectionoverlay.h +++ b/sdrgui/gui/connectionoverlay.h @@ -28,13 +28,18 @@ #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. -class ConnectionOverlay : public QWidget +// 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: @@ -42,19 +47,20 @@ public: enum Direction { NoDirection, Forward, Reverse, BothDirections }; struct Connection { - QPointer source; - QPointer target; - QString sourceLabel; - QString targetLabel; - QString flowLabel; - int sourceWorkspace = -1; - int targetWorkspace = -1; - Kind kind = DeviceLink; - Direction direction = Forward; - QColor color; + 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); @@ -62,57 +68,72 @@ protected: bool eventFilter(QObject *object, QEvent *event) override; void changeEvent(QEvent *event) override; void showEvent(QShowEvent *event) override; - void paintEvent(QPaintEvent *event) override; + void initializeGL() override; + void paintGL() override; private: // Geometry for one drawn connection, cached until windows move or connections change. struct Route { - QPainterPath path; - qreal length = 0; - QRect bounds; - QPointF from; - QPointF to; - QColor color; - Kind kind = DeviceLink; - Direction direction = Forward; - QString flowLabel; - QRectF flowLabelRect; - QString marker; - QRectF markerRect; + 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 fromSide = 0; - int toSide = 0; - QRectF sourceBox; - QRectF targetBox; - int stubTip = 0; // Cross-workspace stub: 1 if to is its tip, -1 if from is + 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 tail; - QPointF head; - QColor color; + QPointF m_tail; + QPointF m_head; + QColor m_color; }; QMdiArea *m_mdi; QList m_connections; - QHash> m_indexLabels; + QList> m_windows; // Windows with links, to watch for moves QList> m_watched; QVector m_routes; - QRegion m_clipRegion; // Everything except the title ID labels - QRegion m_pulseRegion; // Area covered by the pulses last painted 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(); - bool computeLayout(); // Returns true if the mask changed + void computeLayout(); QVector pulses() const; - QRegion pulsesRegion(const 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/mainwindow.cpp b/sdrgui/mainwindow.cpp index a6e720933..cf1321c93 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -2801,15 +2801,15 @@ void MainWindow::updateConnectionOverlays() return; } ConnectionOverlay::Connection connection; - connection.source = device; - connection.target = target; - connection.sourceLabel = deviceLabel; - connection.targetLabel = label; - connection.flowLabel = flowLabel; - connection.sourceWorkspace = device->getWorkspaceIndex(); - connection.targetWorkspace = targetWorkspace; - connection.direction = direction; - connection.color = color; + 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); }; @@ -2907,21 +2907,21 @@ void MainWindow::updateConnectionOverlays() if (existingIndex >= 0) { if (audio) { - connections[existingIndex].flowLabel = audioLabel(source); + connections[existingIndex].m_flowLabel = audioLabel(source); } continue; } ConnectionOverlay::Connection connection; - connection.source = source.window; - connection.target = target.window; - connection.sourceLabel = source.label; - connection.targetLabel = target.label; - connection.flowLabel = audio ? audioLabel(source) : QString("Data"); - connection.sourceWorkspace = source.workspace; - connection.targetWorkspace = target.workspace; - connection.kind = ConnectionOverlay::PipeLink; - connection.direction = ConnectionOverlay::Forward; - connection.color = source.linkColor.isValid() ? source.linkColor : target.linkColor; + 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); } From c46445139cc00a9f4e6c1f2611e238c9f58d3b07 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 28 Sep 2026 15:12:00 +0100 Subject: [PATCH 6/8] Move connections on to window border. --- sdrgui/gui/connectionoverlay.cpp | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/sdrgui/gui/connectionoverlay.cpp b/sdrgui/gui/connectionoverlay.cpp index 94f1fd1a3..904df470b 100644 --- a/sdrgui/gui/connectionoverlay.cpp +++ b/sdrgui/gui/connectionoverlay.cpp @@ -44,6 +44,7 @@ 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), @@ -911,7 +912,7 @@ void ConnectionOverlay::computeLayout() // 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 ? -6 : window->width() + 6, titleBarMiddle); + const QPoint inWindow(side < 0 ? -anchorOutset : window->width() + anchorOutset, titleBarMiddle); return QPointF(window->geometry().topLeft() + inWindow + viewportOffset); }; @@ -1375,6 +1376,36 @@ void ConnectionOverlay::computeLayout() 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(); } From 24e66204cbd9c3a54076f202747babb5e9439f4c Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 28 Sep 2026 15:12:28 +0100 Subject: [PATCH 7/8] Denoiser: Only subscribe to pipe when running, to avoid overflows. --- plugins/feature/denoiser/denoiser.cpp | 52 +++++++++++++++++---------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/plugins/feature/denoiser/denoiser.cpp b/plugins/feature/denoiser/denoiser.cpp index 202a020ce..fed578526 100644 --- a/plugins/feature/denoiser/denoiser.cpp +++ b/plugins/feature/denoiser/denoiser.cpp @@ -173,6 +173,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); @@ -219,12 +229,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())); } } @@ -232,6 +238,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 @@ -658,13 +670,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"); @@ -690,16 +705,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); } From 4d83991fc7e7df6e646a511075449c89ccab6e0f Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 28 Sep 2026 16:23:32 +0100 Subject: [PATCH 8/8] Prevent ancestor windows becoming native. --- plugins/feature/denoiser/vst3effect.cpp | 5 +++++ 1 file changed, 5 insertions(+) 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;