From 8fafea9d026b2b65599456e70d3f5aa61ef073d1 Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 22 May 2023 03:59:45 -0700 Subject: Add keyboard toggle Users can now configure a keybind to start/stop/dismiss the STT when in desktop mode. The default keybind is ctrl+x, since by default VRC doesn't use 'x' for anything. --- GUI/GUI/GUI/Config.cpp | 3 +++ GUI/GUI/GUI/Config.h | 1 + GUI/GUI/GUI/Frame.cpp | 19 +++++++++++++++++++ GUI/GUI/GUI/Frame.h | 1 + GUI/GUI/GUI/PythonWrapper.cpp | 1 + 5 files changed, 25 insertions(+) (limited to 'GUI') diff --git a/GUI/GUI/GUI/Config.cpp b/GUI/GUI/GUI/Config.cpp index 02646ab..73b28bc 100644 --- a/GUI/GUI/GUI/Config.cpp +++ b/GUI/GUI/GUI/Config.cpp @@ -72,6 +72,7 @@ AppConfig::AppConfig(wxTextCtrl* out) use_cpu(false), use_builtin(false), gpu_idx(0), + keybind("ctrl+x"), chars_per_sync(8), bytes_per_char(1), @@ -115,6 +116,7 @@ bool AppConfig::Serialize(const std::filesystem::path& path) { cm.Set("use_cpu", use_cpu); cm.Set("use_builtin", use_builtin); cm.Set("gpu_idx", gpu_idx); + cm.Set("keybind", keybind); cm.Set("chars_per_sync", chars_per_sync); cm.Set("bytes_per_char", bytes_per_char); @@ -171,6 +173,7 @@ bool AppConfig::Deserialize(const std::filesystem::path& path) { cm.Get("use_cpu", c.use_cpu); cm.Get("use_builtin", c.use_builtin); cm.Get("gpu_idx", c.gpu_idx); + cm.Get("keybind", c.keybind); cm.Get("chars_per_sync", c.chars_per_sync); cm.Get("bytes_per_char", c.bytes_per_char); diff --git a/GUI/GUI/GUI/Config.h b/GUI/GUI/GUI/Config.h index d86c8d8..f53b700 100644 --- a/GUI/GUI/GUI/Config.h +++ b/GUI/GUI/GUI/Config.h @@ -58,6 +58,7 @@ public: bool use_cpu; bool use_builtin; int gpu_idx; + std::string keybind; // Unity and transcription shared settings. int chars_per_sync; diff --git a/GUI/GUI/GUI/Frame.cpp b/GUI/GUI/GUI/Frame.cpp index ae07ad9..3bf1545 100644 --- a/GUI/GUI/GUI/Frame.cpp +++ b/GUI/GUI/GUI/Frame.cpp @@ -43,6 +43,7 @@ namespace { ID_PY_APP_COLS, ID_PY_APP_WINDOW_DURATION, ID_PY_APP_GPU_IDX, + ID_PY_APP_KEYBIND, ID_UNITY_PANEL, ID_UNITY_CONFIG_PANEL, ID_UNITY_OUT, @@ -537,6 +538,16 @@ Frame::Frame() "discrete GPU."); py_app_gpu_idx_ = py_app_gpu_idx; + auto* py_app_keybind = new wxTextCtrl( + py_app_config_panel_pairs, ID_PY_APP_KEYBIND, + app_c_->keybind, wxDefaultPosition, + wxDefaultSize, /*style=*/0); + py_app_keybind->SetToolTip( + "The keybind to use to toggle the STT when in desktop " + "mode. To dismiss the STT, double press the keybind " + "quickly."); + py_app_keybind_ = py_app_keybind; + auto* sizer = new wxFlexGridSizer(/*cols=*/2); py_app_config_panel_pairs->SetSizer(sizer); @@ -570,6 +581,11 @@ Frame::Frame() sizer->Add(py_app_button, /*proportion=*/0, /*flags=*/wxEXPAND); + sizer->Add(new wxStaticText(py_app_config_panel_pairs, + wxID_ANY, /*label=*/"Desktop keybind:")); + sizer->Add(py_app_keybind, /*proportion=*/0, + /*flags=*/wxEXPAND); + sizer->Add(new wxStaticText(py_app_config_panel_pairs, wxID_ANY, /*label=*/"Text box rows:")); sizer->Add(py_app_rows, /*proportion=*/0, @@ -2118,6 +2134,8 @@ void Frame::OnAppStart(wxCommandEvent& event) { py_app_window_duration_->GetValue().ToStdString(); std::string gpu_idx_str = py_app_gpu_idx_->GetValue().ToStdString(); + std::string keybind = + py_app_keybind_->GetValue().ToStdString(); int rows, cols, chars_per_sync, bytes_per_char, window_duration, gpu_idx; try { rows = std::stoi(rows_str); @@ -2175,6 +2193,7 @@ void Frame::OnAppStart(wxCommandEvent& event) { app_c_->use_cpu = use_cpu; app_c_->use_builtin = use_builtin; app_c_->gpu_idx = gpu_idx; + app_c_->keybind = keybind; app_c_->Serialize(AppConfig::kConfigPath); auto out_cb = [&](const std::string& out, const std::string& err) { diff --git a/GUI/GUI/GUI/Frame.h b/GUI/GUI/GUI/Frame.h index 1252542..7e55347 100644 --- a/GUI/GUI/GUI/Frame.h +++ b/GUI/GUI/GUI/Frame.h @@ -41,6 +41,7 @@ private: wxTextCtrl* py_app_cols_; wxTextCtrl* py_app_window_duration_; wxTextCtrl* py_app_gpu_idx_; + wxTextCtrl* py_app_keybind_; wxTextCtrl* unity_rows_; wxTextCtrl* unity_cols_; wxTextCtrl* whisper_rows_; diff --git a/GUI/GUI/GUI/PythonWrapper.cpp b/GUI/GUI/GUI/PythonWrapper.cpp index c5f355a..c875874 100644 --- a/GUI/GUI/GUI/PythonWrapper.cpp +++ b/GUI/GUI/GUI/PythonWrapper.cpp @@ -473,6 +473,7 @@ std::future PythonWrapper::StartApp( "--use_builtin", config.use_builtin ? "1" : "0", "--emotes_pickle", kEmotesPickle, "--gpu_idx", std::to_string(config.gpu_idx), + "--keybind", Quote(config.keybind), }, std::move(out_cb), std::move(in_cb), -- cgit v1.2.3