summaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-10-14 14:39:20 +0200
committerChristoph Berg <myon@debian.org>2026-10-14 14:39:20 +0200
commitc576a4281ef8c87990ae6399393a827dfaccacd5 (patch)
tree0f28b7d1fc2ba73ccea5d7513281b0f8cae76fb6 /widgets
parentffc62c792c9a5196cb4ce7a353287dfe20db6524 (diff)
New upstream version 3.3.0~beta2+dfsgupstream/3.3.0_beta2+dfsgupstream
Diffstat (limited to 'widgets')
-rw-r--r--widgets/JttyMessages.hpp17
-rw-r--r--widgets/mainwindow.cpp3
-rw-r--r--widgets/mainwindow_jtty.cpp73
3 files changed, 50 insertions, 43 deletions
diff --git a/widgets/JttyMessages.hpp b/widgets/JttyMessages.hpp
index b25a1cf9..9f51a6a0 100644
--- a/widgets/JttyMessages.hpp
+++ b/widgets/JttyMessages.hpp
@@ -5,6 +5,7 @@
#include <algorithm>
#include <cmath>
#include <cstddef>
+#include <optional>
#include <type_traits>
#include <QByteArray>
@@ -262,6 +263,22 @@ namespace Jtty
return {offset, length, message.mid (offset, length)};
}
+ // A segment that does not encode refuses the line rather than being cut shorter: the rest would continue the receiver's 80-column message.
+ template <typename Encode>
+ std::optional<QVector<TransmitTextSegment>> encodeTransmitLine (QString const& line, Encode&& encode)
+ {
+ QVector<TransmitTextSegment> segments;
+ for (int offset = 0; offset < line.size ();) {
+ auto const source = nextTransmitTextSegment (line, offset);
+ if (!source.text.trimmed ().isEmpty ()) {
+ if (!encode (source.text)) return std::nullopt;
+ segments.append (source);
+ }
+ offset += source.length;
+ }
+ return segments;
+ }
+
// An empty result rejects oversized text before it reaches the fixed-width codec.
inline QString transmitFrame (QString const& message)
{
diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp
index 9c9031fb..41f25835 100644
--- a/widgets/mainwindow.cpp
+++ b/widgets/mainwindow.cpp
@@ -5630,7 +5630,8 @@ void MainWindow::decode (Ft8MtdDecodeCoordinator::Stage ft8Stage,
#if defined (WSJT_ENABLE_LIVE_AUDIO_TEST)
bool MainWindow::startWavDecodeTest (QString const& path)
{
- auto const fixtureMode = ((m_mode == QStringLiteral ("JT9")
+ auto const fixtureMode = ((m_mode == QStringLiteral ("JT4")
+ || m_mode == QStringLiteral ("JT9")
|| m_mode == QStringLiteral ("JT65")
|| m_mode == QStringLiteral ("Q65")) && m_TRperiod == 60.0)
|| (m_mode == QStringLiteral ("FST4") && m_TRperiod == 15.0)
diff --git a/widgets/mainwindow_jtty.cpp b/widgets/mainwindow_jtty.cpp
index 2ad9b573..bd19b584 100644
--- a/widgets/mainwindow_jtty.cpp
+++ b/widgets/mainwindow_jtty.cpp
@@ -341,29 +341,18 @@ int MainWindow::countJttyTransmitFrames(QString const& preparedMessage) const
int totalFrames = 0;
auto const lines = preparedMessage.split (QLatin1Char ('\n'));
for (auto const& line : lines) {
- for (int offset = 0; offset < line.size ();) {
- auto source = Jtty::nextTransmitTextSegment (line, offset);
- if (source.text.trimmed ().isEmpty ()) {
- offset += source.length;
- continue;
- }
- for (;;) {
- auto frame = Jtty::transmitFrame (source.text).toLatin1 ();
- QVector<int> tones (944);
- int nsym = 0;
- int frameStarts[kMaxJttyFrames] = {};
- int const finalFlag = 1; // irrelevant to frame count, which EOM doesn't affect
- genjtty_profile_ (frame.data (), &exchangeProfile, tones.data (),
- &nsym, frameStarts, &finalFlag, (FCL)80);
- if (nsym > 0) {
- totalFrames += nsym / 59;
- break;
- }
- if (source.length <= 1) return totalFrames;
- source = Jtty::nextTransmitTextSegment (line, offset, source.length - 1);
- }
- offset += source.length;
- }
+ auto const encoded = Jtty::encodeTransmitLine (line, [&] (QString const& text) {
+ auto frame = Jtty::transmitFrame (text).toLatin1 ();
+ QVector<int> tones (944);
+ int nsym = 0;
+ int frameStarts[kMaxJttyFrames] = {};
+ int const finalFlag = 1; // irrelevant to frame count, which EOM doesn't affect
+ genjtty_profile_ (frame.data (), &exchangeProfile, tones.data (),
+ &nsym, frameStarts, &finalFlag, (FCL)80);
+ totalFrames += nsym / 59;
+ return nsym > 0;
+ });
+ if (!encoded) return 0;
}
return totalFrames;
}
@@ -475,7 +464,7 @@ void MainWindow::execute_jtty_tx(qint64 requestId, QString message, bool isFinal
}
int const exchangeProfile = static_cast<int>(jttyExchangeProfile(m_config));
- // One-shot encode of text already known to fit (no retry): used for the initial non-final pass and to re-bake a line's true last segment once its real EOM status is known.
+ // One-shot encode; empty tones mean the text did not encode. Used for the initial non-final pass and to re-bake a line's true last segment once its real EOM status is known.
auto encodeOnce = [&] (QString const& text, bool segmentIsFinal) {
Jtty::TransmitSegment segment;
auto frame = Jtty::transmitFrame(text).toLatin1();
@@ -494,9 +483,15 @@ void MainWindow::execute_jtty_tx(qint64 requestId, QString message, bool isFinal
// Fortran gives 1-indexed columns; store 0-indexed offsets.
segment.frameCharStarts.append(frameStarts[i] - 1);
}
+ } else {
+ segment.tones.clear();
}
return segment;
};
+ auto refuseUnencodable = [&] {
+ showStatusMessage(tr("JTTY text not sent: a line does not fit in one message once encoded; shorten it and send again"));
+ Q_EMIT jttyTextRejected(requestId, JttyTxRejectReason::EncodingFailed);
+ };
QVector<Jtty::TransmitSegment> segments;
// Newlines force a new segment; split them out before nextTransmitTextSegment (space-only breaks).
@@ -504,32 +499,26 @@ void MainWindow::execute_jtty_tx(qint64 requestId, QString message, bool isFinal
for (int lineIndex = 0; lineIndex < lines.size(); ++lineIndex) {
auto const& line = lines[lineIndex];
int const lineStart = segments.size();
- for (int offset = 0; offset < line.size();) {
- auto source = Jtty::nextTransmitTextSegment(line, offset);
- if (source.text.trimmed().isEmpty()) {
- offset += source.length;
- continue;
- }
- Jtty::TransmitSegment segment;
- for (;;) {
- segment = encodeOnce(source.text, /*segmentIsFinal=*/false);
- if (!segment.tones.isEmpty()) break;
- if (source.length <= 1) {
- Q_EMIT jttyTextRejected(requestId, JttyTxRejectReason::EncodingFailed);
- return;
- }
- source = Jtty::nextTransmitTextSegment(line, offset, source.length - 1);
- }
+ auto const encoded = Jtty::encodeTransmitLine(line, [&] (QString const& text) {
+ auto segment = encodeOnce(text, /*segmentIsFinal=*/false);
+ if (segment.tones.isEmpty()) return false;
segment.frequency = ui->TxFreqSpinBox_2->value();
segments.append(std::move(segment));
- offset += source.length;
+ return true;
+ });
+ if (!encoded) {
+ refuseUnencodable();
+ return;
}
if (segments.size() == lineStart) continue;
bool const lineIsFinal = lineIndex + 1 < lines.size() || isFinal;
if (!lineIsFinal) continue;
auto& last = segments.last();
auto final_ = encodeOnce(last.text, /*segmentIsFinal=*/true);
- Q_ASSERT (!final_.tones.isEmpty()); // same text that just succeeded above
+ if (final_.tones.isEmpty()) {
+ refuseUnencodable();
+ return;
+ }
final_.frequency = last.frequency;
last = std::move(final_);
}