From 227ff7aa0ed2fd03c54ae53aa01430012ff3f7d0 Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 25 Jan 2023 12:38:28 -0800 Subject: GUI: Add ability to choose button We use a button to start/stop transcription. Previously this was hardcoded to left joystick. Now users can pick from {left, right} x {joystick, a, b}. --- GUI/GUI/GUI/Config.cpp | 3 +++ GUI/GUI/GUI/Config.h | 1 + GUI/GUI/GUI/Frame.cpp | 31 +++++++++++++++++++++++++++++++ GUI/GUI/GUI/Frame.h | 1 + GUI/GUI/GUI/PythonWrapper.cpp | 1 + 5 files changed, 37 insertions(+) (limited to 'GUI') diff --git a/GUI/GUI/GUI/Config.cpp b/GUI/GUI/GUI/Config.cpp index 4e6eb48..3994e62 100644 --- a/GUI/GUI/GUI/Config.cpp +++ b/GUI/GUI/GUI/Config.cpp @@ -73,6 +73,7 @@ TranscriptionAppConfig::TranscriptionAppConfig() model("base.en"), chars_per_sync("20"), bytes_per_char("1"), + button("left joystick"), rows("4"), cols("48"), window_duration("15"), @@ -90,6 +91,7 @@ bool TranscriptionAppConfig::Serialize(const std::filesystem::path& path) { root["model"] << ryml::to_substr(model); root["chars_per_sync"] << ryml::to_substr(chars_per_sync); root["bytes_per_char"] << ryml::to_substr(bytes_per_char); + root["button"] << ryml::to_substr(button); root["rows"] << ryml::to_substr(rows); root["cols"] << ryml::to_substr(cols); root["window_duration"] << ryml::to_substr(window_duration); @@ -119,6 +121,7 @@ bool TranscriptionAppConfig::Deserialize(const std::filesystem::path& path) { root.get_if("model", &c.model); root.get_if("chars_per_sync", &c.chars_per_sync); root.get_if("bytes_per_char", &c.bytes_per_char); + root.get_if("button", &c.button); root.get_if("rows", &c.rows); root.get_if("cols", &c.cols); root.get_if("window_duration", &c.window_duration); diff --git a/GUI/GUI/GUI/Config.h b/GUI/GUI/GUI/Config.h index fe7b862..511ba01 100644 --- a/GUI/GUI/GUI/Config.h +++ b/GUI/GUI/GUI/Config.h @@ -41,6 +41,7 @@ public: std::string model; std::string chars_per_sync; std::string bytes_per_char; + std::string button; std::string rows; std::string cols; std::string window_duration; diff --git a/GUI/GUI/GUI/Frame.cpp b/GUI/GUI/GUI/Frame.cpp index 5c73bf6..e0663c5 100644 --- a/GUI/GUI/GUI/Frame.cpp +++ b/GUI/GUI/GUI/Frame.cpp @@ -32,6 +32,7 @@ namespace { ID_PY_APP_MODEL, ID_PY_APP_CHARS_PER_SYNC, ID_PY_APP_BYTES_PER_CHAR, + ID_PY_APP_BUTTON, ID_PY_APP_MODEL_PANEL, ID_PY_APP_ENABLE_LOCAL_BEEP, ID_PY_APP_USE_CPU, @@ -230,6 +231,17 @@ namespace { // Sorry international users. Optimize for English speakers, by default. constexpr int kBytesDefault = 0; + const wxString kButton[] = { + "left joystick", + "left a", + "left b", + "right joystick", + "right a", + "right b", + }; + const size_t kNumButtons = sizeof(kButton) / sizeof(kButton[0]); + constexpr int kButtonDefault = 0; + // Given the string value of a dropdown menu's entry, find its index. If no // entry matches, return `default_index`. int GetDropdownChoiceIndex(const wxString menu[], @@ -360,6 +372,17 @@ Frame::Frame() "characters (i.e. not English), set this to 2."); py_app_bytes_per_char_ = py_app_bytes_per_char; + auto* py_app_button = new wxChoice(py_app_config_panel_pairs, + ID_PY_APP_BUTTON, wxDefaultPosition, + wxDefaultSize, kNumButtons, kButton); + int button_idx = GetDropdownChoiceIndex(kButton, kNumButtons, py_c.button, kButtonDefault); + py_app_button->SetSelection(button_idx); + py_app_button->SetToolTip( + "You will use this button in game to start and stop " + "transcription. Set it to a button you're not using " + "for anything else!"); + py_app_button_ = py_app_button; + auto* py_app_rows = new wxTextCtrl(py_app_config_panel_pairs, ID_PY_APP_ROWS, py_c.rows, wxDefaultPosition, wxDefaultSize, /*style=*/0); @@ -404,6 +427,9 @@ Frame::Frame() sizer->Add(new wxStaticText(py_app_config_panel_pairs, wxID_ANY, /*label=*/"Bytes per character:")); sizer->Add(py_app_bytes_per_char, /*proportion=*/0, /*flags=*/wxEXPAND); + sizer->Add(new wxStaticText(py_app_config_panel_pairs, wxID_ANY, /*label=*/"Button:")); + sizer->Add(py_app_button, /*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, /*flags=*/wxEXPAND); @@ -946,6 +972,10 @@ void Frame::OnAppStart(wxCommandEvent& event) { if (bytes_per_char_idx == wxNOT_FOUND) { bytes_per_char_idx = kBytesDefault; } + int button_idx = py_app_button_->GetSelection(); + if (button_idx == wxNOT_FOUND) { + button_idx = kBytesDefault; + } const bool enable_local_beep = py_app_enable_local_beep_->GetValue(); const bool use_cpu = py_app_use_cpu_->GetValue(); const bool use_builtin = py_app_use_builtin_->GetValue(); @@ -987,6 +1017,7 @@ void Frame::OnAppStart(wxCommandEvent& event) { py_c.model = kModelChoices[which_model].ToStdString(); py_c.chars_per_sync = kCharsPerSync[chars_per_sync_idx].ToStdString(); py_c.bytes_per_char = kBytesPerChar[bytes_per_char_idx].ToStdString(); + py_c.button = kButton[button_idx].ToStdString(); py_c.rows = std::to_string(rows); py_c.cols = std::to_string(cols); py_c.window_duration = std::to_string(window_duration); diff --git a/GUI/GUI/GUI/Frame.h b/GUI/GUI/GUI/Frame.h index c55830e..28c8f09 100644 --- a/GUI/GUI/GUI/Frame.h +++ b/GUI/GUI/GUI/Frame.h @@ -46,6 +46,7 @@ private: // TODO(yum) figure out how to deduplicate these objects wxChoice* py_app_chars_per_sync_; wxChoice* py_app_bytes_per_char_; + wxChoice* py_app_button_; wxChoice* unity_chars_per_sync_; wxChoice* unity_bytes_per_char_; diff --git a/GUI/GUI/GUI/PythonWrapper.cpp b/GUI/GUI/GUI/PythonWrapper.cpp index 7571833..cad9395 100644 --- a/GUI/GUI/GUI/PythonWrapper.cpp +++ b/GUI/GUI/GUI/PythonWrapper.cpp @@ -154,6 +154,7 @@ wxProcess* PythonWrapper::StartApp( "--model", config.model, "--chars_per_sync", config.chars_per_sync, "--bytes_per_char", config.bytes_per_char, + "--button", Quote(config.button), "--enable_local_beep", config.enable_local_beep ? "1" : "0", "--rows", config.rows, "--cols", config.cols, -- cgit v1.2.3