Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve automatic bookmark selection #1315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/applications/gqrx/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}


Expand Down
35 changes: 30 additions & 5 deletions src/qtgui/dockbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/qtgui/dockbookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down