From c576a4281ef8c87990ae6399393a827dfaccacd5 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 14 Oct 2026 14:39:20 +0200 Subject: New upstream version 3.3.0~beta2+dfsg --- widgets/mainwindow_jtty.cpp | 73 +++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 42 deletions(-) (limited to 'widgets/mainwindow_jtty.cpp') 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 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 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(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 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_); } -- cgit v1.2.3