From 4b7452bef2847ae285e255b771f1cde5aaa26c82 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Mon, 4 Feb 2019 15:53:13 -0500 Subject: [PATCH] toggleable repetition filter --- GUI/host/textthread.cpp | 2 +- GUI/host/textthread.h | 1 + GUI/mainwindow.cpp | 11 +++++++++++ include/text.h | 1 + text.cpp | 1 + 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/GUI/host/textthread.cpp b/GUI/host/textthread.cpp index 365d23d..62cbcfc 100644 --- a/GUI/host/textthread.cpp +++ b/GUI/host/textthread.cpp @@ -42,7 +42,7 @@ void TextThread::Push(const BYTE* data, int len) lastPushTime = GetTickCount(); if (std::all_of(buffer.begin(), buffer.end(), [&](wchar_t c) { return repeatingChars.count(c) > 0; })) buffer.clear(); - if (Util::RemoveRepetition(buffer)) // sentence repetition detected, which means the entire sentence has already been received + if (filterRepetition && Util::RemoveRepetition(buffer)) // sentence repetition detected, which means the entire sentence has already been received { repeatingChars = std::unordered_set(buffer.begin(), buffer.end()); AddSentence(buffer); diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index d9f1367..de0622b 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -9,6 +9,7 @@ public: using OutputCallback = std::function; inline static OutputCallback Output; + inline static bool filterRepetition = true; inline static int flushDelay = 400; // flush every 400ms by default inline static int maxBufferSize = 1000; diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 112688e..f05f5d9 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ MainWindow::MainWindow(QWidget *parent) : QSettings settings(CONFIG_FILE, QSettings::IniFormat); if (settings.contains(WINDOW)) setGeometry(settings.value(WINDOW).toRect()); + TextThread::filterRepetition = settings.value(FILTER_REPETITION, TextThread::filterRepetition).toBool(); TextThread::flushDelay = settings.value(FLUSH_DELAY, TextThread::flushDelay).toInt(); TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE, TextThread::maxBufferSize).toInt(); Host::defaultCodepage = settings.value(DEFAULT_CODEPAGE, Host::defaultCodepage).toInt(); @@ -311,6 +313,15 @@ void MainWindow::Settings() layout->insertRow(0, label, spinBox); connect(save, &QPushButton::clicked, [=, &value] { settings->setValue(label, value = spinBox->value()); }); } + for (auto[value, label] : Array>{ + { TextThread::filterRepetition, FILTER_REPETITION }, + }) + { + auto checkBox = new QCheckBox(this); + checkBox->setChecked(value); + layout->insertRow(0, label, checkBox); + connect(save, &QPushButton::clicked, [=, &value] { settings->setValue(label, value = checkBox->isChecked()); }); + } connect(save, &QPushButton::clicked, this, &QDialog::accept); setWindowTitle(SETTINGS); exec(); diff --git a/include/text.h b/include/text.h index c8c39ec..9a338e5 100644 --- a/include/text.h +++ b/include/text.h @@ -18,6 +18,7 @@ extern const char* SAVE_SETTINGS; extern const char* EXTEN_WINDOW_INSTRUCTIONS; extern const char* WINDOW; extern const char* USE_JP_LOCALE; +extern const char* FILTER_REPETITION; extern const char* DEFAULT_CODEPAGE; extern const char* FLUSH_DELAY; extern const char* MAX_BUFFER_SIZE; diff --git a/text.cpp b/text.cpp index 1d61369..714f171 100644 --- a/text.cpp +++ b/text.cpp @@ -39,6 +39,7 @@ Drag and drop within the list to reorder Press delete with an extension selected to remove it)"; const char* WINDOW = u8"Window"; const char* USE_JP_LOCALE = u8"Emulate japanese locale?"; +const char* FILTER_REPETITION = u8"Repetition Filter"; const char* DEFAULT_CODEPAGE = u8"Default Codepage"; const char* FLUSH_DELAY = u8"Flush Delay"; const char* MAX_BUFFER_SIZE = u8"Max Buffer Size";