summaryrefslogtreecommitdiff
path: root/map65/widegraph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'map65/widegraph.cpp')
-rw-r--r--map65/widegraph.cpp348
1 files changed, 314 insertions, 34 deletions
diff --git a/map65/widegraph.cpp b/map65/widegraph.cpp
index 0004059e..ff3650b0 100644
--- a/map65/widegraph.cpp
+++ b/map65/widegraph.cpp
@@ -1,10 +1,18 @@
#include "widegraph.h"
-#include <QSettings>
+#include <algorithm>
+#include <QCheckBox>
+#include <QDateTime>
+#include <QHBoxLayout>
#include <QMessageBox>
+#include <QPushButton>
+#include <QSettings>
+#include <QSpinBox>
+#include <QVBoxLayout>
#include "SettingsGroup.hpp"
#include "ui_widegraph.h"
+#include "globals.h"
-#define NFFT 32768
+extern int g_sampleRate;
WideGraph::WideGraph (QString const& settings_filename, QWidget * parent)
: QDialog {parent},
@@ -37,8 +45,20 @@ WideGraph::WideGraph (QString const& settings_filename, QWidget * parent)
int n = settings.value("FreqSpan",60).toInt();
int w = settings.value("PlotWidth",1000).toInt();
ui->freqSpanSpinBox->setValue(n);
+
+ if (g_sampleRate == 96000 || g_sampleRate == 95238)
+ setFreqSpanLimits(60, 90);
+ else
+ setFreqSpanLimits(60, 190);
+ updateSpanFromSpinbox();
+
+ extern int g_sampleRate; // at top of widegraph.cpp
ui->widePlot->setNSpan(n);
- int nbpp = n * 32768.0/(w*96.0) + 0.5;
+ double sr_kHz = g_sampleRate / 1000.0; // 96.0 or 192.0
+ int sr_display = int(sr_kHz + 0.5);
+ ui->srValueLabel->setText(QString::number(sr_display));
+ int nbpp = int(n * g_activeNfft / (w * sr_kHz) + 0.5);
+ if (nbpp < 1) nbpp = 1; // safety
ui->widePlot->setBinsPerPixel(nbpp);
m_waterfallAvg = settings.value("WaterfallAvg",10).toInt();
ui->waterfallAvgSpinBox->setValue(m_waterfallAvg);
@@ -49,6 +69,108 @@ WideGraph::WideGraph (QString const& settings_filename, QWidget * parent)
ui->fCenterLineEdit->setText(QString::number(m_dForceCenterFreq));
m_bLockTxRx=settings.value("LockTxRx",false).toBool();
ui->cbLockTxRx->setChecked(m_bLockTxRx);
+
+ // Decoded-callsign overlay (N6NU 2026-05-12). Mirrors QMAP feature.
+ // INI keys: WideGraph/decode_labels_enabled (default true),
+ // WideGraph/decode_label_periods (default 5).
+ m_decodeLabelsEnabled = settings.value("decode_labels_enabled", true).toBool();
+ m_decodeLabelPeriods = settings.value("decode_label_periods", 5).toInt();
+ if (m_decodeLabelPeriods < 1) m_decodeLabelPeriods = 1;
+ if (m_decodeLabelPeriods > 5) m_decodeLabelPeriods = 5;
+ // Overlay transparency preset. Snap stored value to one of the
+ // three offered presets so a hand-edited INI can't desync the
+ // View menu's checked state.
+ m_decodeLabelAlpha = settings.value("decode_label_alpha", 255).toInt();
+ if (m_decodeLabelAlpha <= 187) m_decodeLabelAlpha = 175;
+ else if (m_decodeLabelAlpha <= 210) m_decodeLabelAlpha = 200;
+ else if (m_decodeLabelAlpha <= 237) m_decodeLabelAlpha = 220;
+ else m_decodeLabelAlpha = 255;
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabelAlpha(m_decodeLabelAlpha);
+ {
+ const int fs = settings.value("decode_label_font_size",
+ static_cast<int>(DecodeLabelFontSize::Normal)).toInt();
+ if (fs == 7 || fs == 8 || fs == 10 || fs == 12) {
+ m_decodeFontSize = static_cast<DecodeLabelFontSize>(fs);
+ } else {
+ m_decodeFontSize = DecodeLabelFontSize::Normal;
+ }
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabelFontSize(m_decodeFontSize);
+ }
+ {
+ const int pos = settings.value("decode_label_position",
+ static_cast<int>(DecodeLabelPosition::Top)).toInt();
+ m_decodeLabelPosition = (pos == static_cast<int>(DecodeLabelPosition::Bottom))
+ ? DecodeLabelPosition::Bottom
+ : DecodeLabelPosition::Top;
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabelPosition(m_decodeLabelPosition);
+ }
+ connect(&m_ageTimer, &QTimer::timeout, this, &WideGraph::ageDecodeLabels);
+ m_ageTimer.start(1000); // 1 Hz prune
+
+ // -- Decoded-callsign overlay controls -- QMAP port (DG2YCB 2026-05-13)
+ // Three widgets appended to the existing horizontalLayout_3 row
+ // (FreqSpan / WaterfallAvg / etc.) so they share the same line:
+ // [? Show callsigns] [age N x TR] [Clear]
+ // Persisted to the .ini under [WideGraph]/{decode_labels_enabled,
+ // decode_label_periods}.
+ {
+ auto* showCb = new QCheckBox("Show callsigns", this);
+ showCb->setObjectName("decodeLabelShowCb");
+ showCb->setChecked(m_decodeLabelsEnabled);
+ showCb->setToolTip("Overlay decoded callsigns on the waterfall at "
+ "their decoded frequency. Q65 labels render "
+ "yellow, JT65 labels cyan. Uncheck to hide all "
+ "labels (existing entries are cleared).");
+ connect(showCb, &QCheckBox::toggled,
+ this, &WideGraph::setDecodeLabelsEnabled);
+ // Keep the row checkbox in sync when the View-menu mirror flips it.
+ connect(this, &WideGraph::decodeLabelsEnabledChanged,
+ showCb, &QCheckBox::setChecked);
+
+ auto* ageSpin = new QSpinBox(this);
+ ageSpin->setObjectName("decodeLabelAgeSpin");
+ ageSpin->setRange(1, 5);
+ ageSpin->setValue(m_decodeLabelPeriods);
+ ageSpin->setSuffix(" x TR");
+ ageSpin->setToolTip("How many TR periods a decoded callsign label "
+ "stays on the waterfall after its last fresh "
+ "decode. Default 5 = 5 minutes for Q65-60.");
+ connect(ageSpin, QOverload<int>::of(&QSpinBox::valueChanged),
+ this, [this](int v) {
+ m_decodeLabelPeriods = v;
+ ageDecodeLabels(); // immediate sweep with new lifetime
+ });
+
+ auto* clearBtn = new QPushButton("Clear", this);
+ clearBtn->setObjectName("decodeLabelClearBtn");
+ clearBtn->setToolTip("Remove all decoded callsign labels from the "
+ "waterfall. Existing decodes will re-appear "
+ "if MAP65 decodes them again.");
+ connect(clearBtn, &QPushButton::clicked, this, [this]() {
+ m_decodeLabels.clear();
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabels(m_decodeLabels);
+ });
+
+ // Insert into the existing controls row (horizontalLayout_3) just
+ // before its trailing stretch, so the new widgets share the line
+ // with FreqSpan/WaterfallAvg instead of wrapping below.
+ if (auto* row = findChild<QHBoxLayout*>("horizontalLayout_3")) {
+ row->addWidget(showCb);
+ row->addWidget(ageSpin);
+ row->addWidget(clearBtn);
+ } else {
+ // Fallback: own row appended to inner verticalLayout.
+ auto* row2 = new QHBoxLayout;
+ row2->setContentsMargins(0, 0, 0, 0);
+ row2->addWidget(showCb);
+ row2->addWidget(ageSpin);
+ row2->addWidget(clearBtn);
+ row2->addStretch();
+ if (auto* inner = findChild<QVBoxLayout*>("verticalLayout")) {
+ inner->addLayout(row2);
+ }
+ }
+ }
}
WideGraph::~WideGraph()
@@ -63,6 +185,7 @@ void WideGraph::resizeEvent(QResizeEvent* ) //resizeEvent()
int w = size().width();
int h = size().height();
ui->labFreq->setGeometry(QRect(w-256,h-100,227,41));
+ updateSpanFromSpinbox();
}
void WideGraph::saveSettings()
@@ -83,12 +206,126 @@ void WideGraph::saveSettings()
settings.setValue("ForceCenterFreqBool",m_bForceCenterFreq);
settings.setValue("ForceCenterFreqMHz",m_dForceCenterFreq);
settings.setValue("LockTxRx",m_bLockTxRx);
+ settings.setValue("decode_labels_enabled", m_decodeLabelsEnabled);
+ settings.setValue("decode_label_periods", m_decodeLabelPeriods);
+ settings.setValue("decode_label_alpha", m_decodeLabelAlpha);
+ settings.setValue("decode_label_font_size", static_cast<int>(m_decodeFontSize));
+ settings.setValue("decode_label_position", static_cast<int>(m_decodeLabelPosition));
+}
+
+void WideGraph::addDecodeLabel(double freq_khz, const QString& callsign,
+ bool is_jt65, bool mode_reliable,
+ bool freq_reliable)
+{
+ if (callsign.isEmpty()) return;
+ if (!m_decodeLabelsEnabled) return;
+ const qint64 now = QDateTime::currentMSecsSinceEpoch();
+ for (auto& lab : m_decodeLabels) {
+ if (lab.callsign == callsign) {
+ lab.last_seen_ms = now;
+ // Only overwrite freq when the caller has sub-kHz precision.
+ // The "&" bandmap tap only has 3-char integer-kHz precision
+ // (display.f90 cfreq0 is character(3) � no ndf field), so it
+ // would otherwise stomp on a precise "!" tick that already
+ // includes ndf, leaving the tick up to ~500 Hz off the signal.
+ if (freq_reliable) lab.freq_khz = freq_khz;
+ // Only overwrite the mode flag when the caller knows for sure.
+ // The "&" bandmap-line tap has no cmode in its payload, so it
+ // would otherwise stomp on an authoritative JT65 mark from the
+ // "!" decoder tap and flip the label color.
+ if (mode_reliable) lab.is_jt65 = is_jt65;
+ ++lab.hits;
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabels(m_decodeLabels);
+ return;
+ }
+ }
+ if (m_decodeLabels.size() >= kDecodeLabelMax) {
+ m_decodeLabels.removeFirst();
+ }
+ m_decodeLabels.append(DecodeLabel{freq_khz, callsign, now, 1, is_jt65});
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabels(m_decodeLabels);
+}
+
+void WideGraph::clearDecodeLabels()
+{
+ if (m_decodeLabels.isEmpty()) return;
+ m_decodeLabels.clear();
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabels(m_decodeLabels);
+}
+
+void WideGraph::ageDecodeLabels()
+{
+ if (m_decodeLabels.isEmpty()) return;
+ const double trp = (m_TRperiod > 0) ? m_TRperiod : 60.0;
+ const qint64 ttl_ms = static_cast<qint64>(trp * m_decodeLabelPeriods * 1000.0);
+ const qint64 cutoff = QDateTime::currentMSecsSinceEpoch() - ttl_ms;
+ const int before = m_decodeLabels.size();
+ m_decodeLabels.erase(
+ std::remove_if(m_decodeLabels.begin(), m_decodeLabels.end(),
+ [cutoff](const DecodeLabel& l) {
+ return l.last_seen_ms < cutoff;
+ }),
+ m_decodeLabels.end());
+ if (m_decodeLabels.size() != before && ui && ui->widePlot) {
+ ui->widePlot->setDecodeLabels(m_decodeLabels);
+ }
+}
+
+void WideGraph::setDecodeLabelsEnabled(bool on)
+{
+ if (m_decodeLabelsEnabled == on) return;
+ m_decodeLabelsEnabled = on;
+ if (!on) {
+ m_decodeLabels.clear();
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabels(m_decodeLabels);
+ }
+ // Persist immediately so the choice survives a crash before saveSettings runs.
+ QSettings settings {m_settings_filename, QSettings::IniFormat};
+ SettingsGroup g {&settings, "WideGraph"};
+ settings.setValue("decode_labels_enabled", on);
+ emit decodeLabelsEnabledChanged(on);
+}
+
+void WideGraph::setDecodeLabelAlpha(int alpha)
+{
+ // Snap to the three offered presets so a stale or hand-edited INI
+ // can't break the View menu's exclusive group.
+ if (alpha <= 187) alpha = 175;
+ else if (alpha <= 210) alpha = 200;
+ else if (alpha <= 237) alpha = 220;
+ else alpha = 255;
+ if (m_decodeLabelAlpha == alpha) return;
+ m_decodeLabelAlpha = alpha;
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabelAlpha(alpha);
+ QSettings settings {m_settings_filename, QSettings::IniFormat};
+ SettingsGroup g {&settings, "WideGraph"};
+ settings.setValue("decode_label_alpha", alpha);
+}
+
+void WideGraph::setDecodeLabelFontSize(DecodeLabelFontSize sz)
+{
+ if (m_decodeFontSize == sz) return;
+ m_decodeFontSize = sz;
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabelFontSize(sz);
+ QSettings settings {m_settings_filename, QSettings::IniFormat};
+ SettingsGroup g {&settings, "WideGraph"};
+ settings.setValue("decode_label_font_size", static_cast<int>(sz));
+}
+
+void WideGraph::setDecodeLabelPosition(DecodeLabelPosition p)
+{
+ if (m_decodeLabelPosition == p) return;
+ m_decodeLabelPosition = p;
+ if (ui && ui->widePlot) ui->widePlot->setDecodeLabelPosition(p);
+ QSettings settings {m_settings_filename, QSettings::IniFormat};
+ SettingsGroup g {&settings, "WideGraph"};
+ settings.setValue("decode_label_position", static_cast<int>(p));
}
void WideGraph::dataSink2(float s[], int nkhz, int ihsym, int ndiskdata,
- uchar lstrong[])
+ uchar lstrong[], int lstrongSize)
{
- static float splot[NFFT];
+ static std::vector<float> splot;
float swide[2048];
float smax;
double df;
@@ -96,8 +333,10 @@ void WideGraph::dataSink2(float s[], int nkhz, int ihsym, int ndiskdata,
static int n=0;
static int nkhz0=-999;
static int ntrz=0;
-
- df = m_fSample/32768.0;
+
+ if ((int)splot.size() != g_activeNfft)
+ splot.assign(g_activeNfft, 0.0f);
+ df = double(g_sampleRate) / double(g_activeNfft);
if(nkhz != nkhz0) {
ui->widePlot->setNkhz(nkhz); //Why do we need both?
ui->widePlot->SetCenterFreq(nkhz); //Why do we need both?
@@ -107,35 +346,59 @@ void WideGraph::dataSink2(float s[], int nkhz, int ihsym, int ndiskdata,
//Average spectra over specified number, m_waterfallAvg
if (n==0) {
- for (int i=0; i<NFFT; i++)
+ for (int i=0; i<g_activeNfft; i++)
splot[i]=s[i];
} else {
- for (int i=0; i<NFFT; i++)
+ for (int i=0; i<g_activeNfft; i++)
splot[i] += s[i];
}
n++;
if (n>=m_waterfallAvg) {
- for (int i=0; i<NFFT; i++)
+ for (int i=0; i<g_activeNfft; i++)
splot[i] /= n; //Normalize the average
n=0;
int w=ui->widePlot->plotWidth();
qint64 sf = nkhz + ui->widePlot->freqOffset() - 0.5*w*nbpp*df/1000.0;
- if(sf != ui->widePlot->startFreq()) ui->widePlot->SetStartFreq(sf);
- int i0=16384.0+(ui->widePlot->startFreq()-nkhz+1.27046+0.001*m_fCal) *
- 1000.0/df + 0.5;
+ if (sf != ui->widePlot->startFreq())
+ ui->widePlot->SetStartFreq(sf);
+
+ int i0 = (g_activeNfft/2)
+ + (ui->widePlot->startFreq() - nkhz + 1.27046 + 0.001*m_fCal) * 1000.0/df
+ + 0.5;
+
+ // Clamp i0 into [0, g_activeNfft-1]
+ if (i0 < 0) i0 = 0;
+ if (i0 > g_activeNfft-1) i0 = g_activeNfft-1;
+
int i=i0;
- for (int j=0; j<2048; j++) {
- smax=0;
- for (int k=0; k<nbpp; k++) {
- i++;
+
+ // How many bins can we safely consume?
+ int maxBins = g_activeNfft - 1 - i0;
+ int maxCols = maxBins > 0 ? maxBins / nbpp : 0;
+ if (maxCols > 2048) maxCols = 2048;
+
+ for (int j = 0; j < maxCols; ++j) {
+ smax = 0.0f;
+ for (int k = 0; k < nbpp; ++k) {
+ ++i;
+ if (i >= g_activeNfft) break;
if(splot[i]>smax) smax=splot[i];
}
swide[j]=smax;
- if(lstrong[1 + i/32]!=0) swide[j]=-smax; //Tag strong signals
+
+ int binsPerStrongFlag = std::max(1, g_activeNfft / lstrongSize);
+ int li = 1 + i / binsPerStrongFlag;
+ if (li >= 0 && li < lstrongSize && lstrong[li] != 0)
+ swide[j] = -smax;
}
+ // Optionally zero any remaining swide entries if j < 2048
+ for (int j = maxCols; j < 2048; ++j)
+ swide[j] = 0.0f;
+
+
// Time according to this computer
qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
int ntr = (ms/1000) % m_TRperiod;
@@ -144,12 +407,12 @@ void WideGraph::dataSink2(float s[], int nkhz, int ihsym, int ndiskdata,
for (int i=0; i<2048; i++) {
swide[i] = 1.e30;
}
- for (int i=0; i<32768; i++) {
+ for (int i=0; i<g_activeNfft; i++) {
splot[i] = 1.e30;
}
}
ntrz=ntr;
- ui->widePlot->draw(swide,i0,splot);
+ ui->widePlot->draw(swide,i0,splot.data());
}
}
@@ -158,15 +421,19 @@ void WideGraph::on_freqOffsetSpinBox_valueChanged(int f)
ui->widePlot->SetFreqOffset(f);
}
-void WideGraph::on_freqSpanSpinBox_valueChanged(int n)
+void WideGraph::on_freqSpanSpinBox_valueChanged(int)
{
- ui->widePlot->setNSpan(n);
- int w = ui->widePlot->plotWidth();
- int nbpp = n * 32768.0/(w*96.0) + 0.5;
- if(nbpp < 1) nbpp=1;
- if(w > 0) {
- ui->widePlot->setBinsPerPixel(nbpp);
- }
+ updateSpanFromSpinbox();
+}
+
+void WideGraph::setFreqSpanLimits(int min, int max)
+{
+ ui->freqSpanSpinBox->setMinimum(min);
+ ui->freqSpanSpinBox->setMaximum(max);
+
+ int v = ui->freqSpanSpinBox->value();
+ if (v < min) ui->freqSpanSpinBox->setValue(min);
+ if (v > max) ui->freqSpanSpinBox->setValue(max);
}
void WideGraph::on_waterfallAvgSpinBox_valueChanged(int n)
@@ -269,11 +536,6 @@ void WideGraph::setPalette(QString palette)
{
ui->widePlot->setPalette(palette);
}
-void WideGraph::setFsample(int n)
-{
- m_fSample=n;
- ui->widePlot->setFsample(n);
-}
void WideGraph::setMode65(int n)
{
@@ -357,7 +619,7 @@ void WideGraph::rx570()
void WideGraph::tx570()
{
- if(m_bForceCenterFreq) datcom_.fcenter=m_dForceCenterFreq;
+ if(m_bForceCenterFreq) setFcenter(m_dForceCenterFreq);
m_bIQxt=true;
double f=ui->widePlot->txFreq();
// double f1=m_mult570Tx*(1.0+0.000001*m_cal570) * f;
@@ -385,3 +647,21 @@ void WideGraph::enableSetRxHardware(bool b)
{
ui->pbSetRxHardware->setEnabled(b);
}
+
+void WideGraph::updateSpanFromSpinbox()
+{
+ int n = ui->freqSpanSpinBox->value();
+
+ // Update NSpan
+ ui->widePlot->setNSpan(n);
+
+ // Recompute bins-per-pixel
+ int w = ui->widePlot->plotWidth();
+ int nbpp = int(n * g_activeNfft / (w * (g_sampleRate / 1000.0)) + 0.5);
+ if (nbpp < 1) nbpp = 1;
+
+ if (w > 0)
+ ui->widePlot->setBinsPerPixel(nbpp);
+}
+
+