diff --git a/cwsidetone.cpp b/cwsidetone.cpp index 956b510..b17e0e6 100644 --- a/cwsidetone.cpp +++ b/cwsidetone.cpp @@ -119,17 +119,26 @@ void cwSidetone::init() void cwSidetone::send(QString text) { - if (output != Q_NULLPTR && outputDevice != Q_NULLPTR) { - text=text.simplified(); - buffer.clear(); - QString currentChar; + messages.push_back(text.simplified()); + + if (messages.size() > 1) { + // There are already queued messages so just return + return; + } + + QString currentChar; + if (output->state() == QAudio::StoppedState || output->state() == QAudio::SuspendedState) { + output->resume(); + } + + for (auto txt = messages.begin(); txt != messages.end();) + { int pos = 0; - if (output->state() == QAudio::StoppedState || output->state() == QAudio::SuspendedState) { - output->resume(); - } - while (pos < text.size()) + buffer.clear(); + + while (pos < txt->size()) { - QChar ch = text.at(pos).toUpper(); + QChar ch = txt->at(pos).toUpper(); if (ch == NULL) { currentChar = cwTable[' ']; @@ -157,6 +166,7 @@ void cwSidetone::send(QString text) qWarning(logCW()) << QString("Sidetone sending error occurred, aborting (%0 bytes of %1 remaining)").arg(buffer.size()-written).arg(buffer.size()); } } + txt = messages.erase(txt); } //qInfo(logCW()) << "Sending" << this->currentChar; emit finished(); diff --git a/cwsidetone.h b/cwsidetone.h index a09d5af..e43ec97 100644 --- a/cwsidetone.h +++ b/cwsidetone.h @@ -18,6 +18,8 @@ #include #include +#include + //#define SIDETONE_MULTIPLIER 386.0 #define SIDETONE_MULTIPLIER 1095.46 @@ -52,6 +54,7 @@ private: int frequency; double ratio; QAudioFormat format; + std::deque messages; #if (QT_VERSION < QT_VERSION_CHECK(6,0,0)) QAudioOutput* output = Q_NULLPTR; #else