From e05d1b3401a20114c7c992aefc747025bec19d92 Mon Sep 17 00:00:00 2001 From: 0penBrain <48731257+0penBrain@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:47:55 +0200 Subject: [PATCH] Improve automatic bookmark selection Currently only frequency is used for comparison, and mechanism selects the first bookmark whose bandwidth includes selected frequency. The new mechanism takes into account the chosen modulation by auto-selecting matching bookmark with higher priority, and will then select bookmark whose central frequency is the closest from currently selected frequency. --- src/applications/gqrx/mainwindow.cpp | 3 ++- src/qtgui/dockbookmarks.cpp | 35 ++++++++++++++++++++++++---- src/qtgui/dockbookmarks.h | 2 +- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/applications/gqrx/mainwindow.cpp b/src/applications/gqrx/mainwindow.cpp index 784564158..e84e894b3 100644 --- a/src/applications/gqrx/mainwindow.cpp +++ b/src/applications/gqrx/mainwindow.cpp @@ -909,7 +909,7 @@ void MainWindow::setNewFrequency(qint64 rx_freq) ui->plotter->setCenterFreq(center_freq); uiDockRxOpt->setHwFreq(d_hw_freq); ui->freqCtrl->setFrequency(rx_freq); - uiDockBookmarks->setNewFrequency(rx_freq); + uiDockBookmarks->newFrequencyOrModSet(rx_freq, uiDockRxOpt->currentDemod()); } // Update delta and center (of marker span) when markers are updated @@ -1311,6 +1311,7 @@ void MainWindow::selectDemod(int mode_idx) d_have_audio = (mode_idx != DockRxOpt::MODE_OFF); uiDockRxOpt->setCurrentDemod(mode_idx); + uiDockBookmarks->newFrequencyOrModSet(ui->freqCtrl->getFrequency(), mode_idx); } diff --git a/src/qtgui/dockbookmarks.cpp b/src/qtgui/dockbookmarks.cpp index ff518588d..bc2007eb3 100644 --- a/src/qtgui/dockbookmarks.cpp +++ b/src/qtgui/dockbookmarks.cpp @@ -107,20 +107,45 @@ void DockBookmarks::activated(const QModelIndex & index) emit newBookmarkActivated(info->frequency, info->modulation, info->bandwidth); } -void DockBookmarks::setNewFrequency(qint64 rx_freq) +void DockBookmarks::newFrequencyOrModSet(qint64 rx_freq, int modulation) { ui->tableViewFrequencyList->clearSelection(); const int iRowCount = bookmarksTableModel->rowCount(); + bool modMatch = false; + qint64 freqGap = -1; + int rowIndex = -1;; for (int row = 0; row < iRowCount; ++row) { BookmarkInfo& info = *(bookmarksTableModel->getBookmarkAtRow(row)); - if (std::abs(rx_freq - info.frequency) <= ((info.bandwidth / 2 ) + 1)) + auto tmpFreqGap = std::abs(rx_freq - info.frequency); + auto tmpModMatch = (info.modulation == DockRxOpt::GetStringForModulationIndex(modulation)); + // Already have a bookmark where modulation matches and this one doesn't + if (modMatch && !tmpModMatch) { - ui->tableViewFrequencyList->selectRow(row); - ui->tableViewFrequencyList->scrollTo(ui->tableViewFrequencyList->currentIndex(), QAbstractItemView::EnsureVisible ); - break; + continue; } + // Current frequency is outside the bookmark bandwith + if (tmpFreqGap > ((info.bandwidth / 2 ) + 1)) + { + continue; + } + // Bookmark has same modulation matching but hasn't closer frequency + if ((modMatch == tmpModMatch) && freqGap >= 0 && tmpFreqGap >= freqGap) + { + continue; + } + // All in all the bookmark is a better match + freqGap = tmpFreqGap; + modMatch = tmpModMatch; + rowIndex = row; } + + if (rowIndex >= 0) + { + ui->tableViewFrequencyList->selectRow(rowIndex); + ui->tableViewFrequencyList->scrollTo(ui->tableViewFrequencyList->currentIndex(), QAbstractItemView::EnsureVisible ); + } + m_currentFrequency = rx_freq; } diff --git a/src/qtgui/dockbookmarks.h b/src/qtgui/dockbookmarks.h index baf3818b0..3a600e585 100644 --- a/src/qtgui/dockbookmarks.h +++ b/src/qtgui/dockbookmarks.h @@ -70,7 +70,7 @@ class DockBookmarks : public QDockWidget void newBookmarkActivated(qint64, QString, int); public slots: - void setNewFrequency(qint64 rx_freq); + void newFrequencyOrModSet(qint64 rx_freq, int modulation = 0); private slots: void activated(const QModelIndex & index );