From 12bcd1d40df21cb9bad6ae353ea4f6697e1275a6 Mon Sep 17 00:00:00 2001 From: yum Date: Thu, 29 Dec 2022 23:01:09 -0800 Subject: GUI: Users can now control board dimensions Users can now control how many letters wide and tall the board is. Tested at 4x48, 5x60, 10x120, and 20x240. At 20x240, Unity freezes and does not make forward progress. Perhaps creating 4800 float parameters isn't a truly scalable interface. --- GUI/GUI/GUI/Frame.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++ GUI/GUI/GUI/Frame.h | 5 +++ GUI/GUI/GUI/PythonWrapper.cpp | 44 ++++++++++++++++++++++-- GUI/GUI/GUI/PythonWrapper.h | 4 ++- 4 files changed, 127 insertions(+), 4 deletions(-) (limited to 'GUI') diff --git a/GUI/GUI/GUI/Frame.cpp b/GUI/GUI/GUI/Frame.cpp index 6ed408f..b708953 100644 --- a/GUI/GUI/GUI/Frame.cpp +++ b/GUI/GUI/GUI/Frame.cpp @@ -32,6 +32,8 @@ namespace { ID_PY_APP_BYTES_PER_CHAR, ID_PY_APP_MODEL_PANEL, ID_PY_APP_ENABLE_LOCAL_BEEP, + ID_PY_APP_ROWS, + ID_PY_APP_COLS, ID_UNITY_PANEL, ID_UNITY_CONFIG_PANEL, ID_UNITY_OUT, @@ -47,6 +49,8 @@ namespace { ID_UNITY_BUTTON_GEN_ANIMATOR, ID_UNITY_CHARS_PER_SYNC, ID_UNITY_BYTES_PER_CHAR, + ID_UNITY_ROWS, + ID_UNITY_COLS, }; const wxString kMicChoices[] = { @@ -324,6 +328,20 @@ Frame::Frame() "characters (i.e. not English), set this to 2."); py_app_bytes_per_char_ = py_app_bytes_per_char; + auto* py_app_rows = new wxTextCtrl(py_app_config_panel_pairs, + ID_PY_APP_ROWS, /*value=*/"4", + wxDefaultPosition, wxDefaultSize, /*style=*/0); + py_app_rows->SetToolTip( + "The number of rows on the text box."); + py_app_rows_ = py_app_rows; + + auto* py_app_cols = new wxTextCtrl(py_app_config_panel_pairs, + ID_PY_APP_COLS, /*value=*/"48", + wxDefaultPosition, wxDefaultSize, /*style=*/0); + py_app_cols->SetToolTip( + "The number of columns on the text box."); + py_app_cols_ = py_app_cols; + auto* sizer = new wxFlexGridSizer(/*cols=*/2); py_app_config_panel_pairs->SetSizer(sizer); @@ -341,6 +359,12 @@ 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=*/"Text box rows:")); + sizer->Add(py_app_rows, /*proportion=*/0, /*flags=*/wxEXPAND); + + sizer->Add(new wxStaticText(py_app_config_panel_pairs, wxID_ANY, /*label=*/"Text box columns:")); + sizer->Add(py_app_cols, /*proportion=*/0, /*flags=*/wxEXPAND); } auto* py_app_enable_local_beep = new wxCheckBox(py_config_panel, @@ -513,6 +537,19 @@ Frame::Frame() "characters (i.e. not English), set this to 2."); unity_bytes_per_char_ = unity_bytes_per_char; + auto* unity_rows = new wxTextCtrl(unity_config_panel_pairs, + ID_UNITY_ROWS, /*value=*/"4", + wxDefaultPosition, wxDefaultSize, /*style=*/0); + unity_rows->SetToolTip( + "The number of rows on the text box."); + unity_rows_ = unity_rows; + + auto* unity_cols = new wxTextCtrl(unity_config_panel_pairs, + ID_UNITY_COLS, /*value=*/"48", + wxDefaultPosition, wxDefaultSize, /*style=*/0); + unity_cols->SetToolTip( + "The number of columns on the text box."); + unity_cols_ = unity_cols; auto* sizer = new wxFlexGridSizer(/*cols=*/2); unity_config_panel_pairs->SetSizer(sizer); @@ -546,6 +583,12 @@ Frame::Frame() sizer->Add(new wxStaticText(unity_config_panel_pairs, wxID_ANY, /*label=*/"Bytes per character:")); sizer->Add(unity_bytes_per_char, /*proportion=*/0, /*flags=*/wxEXPAND); + + sizer->Add(new wxStaticText(unity_config_panel_pairs, wxID_ANY, /*label=*/"Text box rows:")); + sizer->Add(unity_rows, /*proportion=*/0, /*flags=*/wxEXPAND); + + sizer->Add(new wxStaticText(unity_config_panel_pairs, wxID_ANY, /*label=*/"Text box columns:")); + sizer->Add(unity_cols, /*proportion=*/0, /*flags=*/wxEXPAND); } auto* unity_button_gen_fx = new wxButton(unity_config_panel, ID_UNITY_BUTTON_GEN_ANIMATOR, "Generate avatar assets"); @@ -713,6 +756,22 @@ void Frame::OnGenerateFX(wxCommandEvent& event) } std::string bytes_per_char = kBytesPerChar[bytes_per_char_idx].ToStdString(); + std::string rows_str = unity_rows_->GetValue().ToStdString(); + std::string cols_str = unity_cols_->GetValue().ToStdString(); + int rows, cols; + try { + rows = std::stoi(rows_str); + cols = std::stoi(cols_str); + } + catch (const std::invalid_argument& e) { + Log(unity_out_, "Could not parse rows \"{}\" or cols \"{}\" as an integer\n", rows_str, cols_str); + return; + } + catch (const std::out_of_range& e) { + Log(unity_out_, "Rows \"{}\" or cols \"{}\" are out of range\n", rows_str, cols_str); + return; + } + std::string out; if (!PythonWrapper::GenerateAnimator( unity_assets_path.string(), @@ -725,6 +784,8 @@ void Frame::OnGenerateFX(wxCommandEvent& event) unity_menu_generated_name, chars_per_sync, bytes_per_char, + rows, + cols, unity_out_)) { wxLogError("Failed to generate animator:\n%s\n", out.c_str()); } @@ -810,6 +871,21 @@ void Frame::OnAppStart(wxCommandEvent& event) { bytes_per_char_idx = kBytesDefault; } const bool enable_local_beep = py_app_enable_local_beep_->GetValue(); + std::string rows_str = py_app_rows_->GetValue().ToStdString(); + std::string cols_str = py_app_cols_->GetValue().ToStdString(); + int rows, cols; + try { + rows = std::stoi(rows_str); + cols = std::stoi(cols_str); + } + catch (const std::invalid_argument& e) { + Log(transcribe_out_, "Could not parse rows \"{}\" or cols \"{}\" as an integer\n", rows_str, cols_str); + return; + } + catch (const std::out_of_range& e) { + Log(transcribe_out_, "Rows \"{}\" or cols \"{}\" are out of range\n", rows_str, cols_str); + return; + } wxProcess* p = PythonWrapper::StartApp(std::move(cb), kMicChoices[which_mic].ToStdString(), @@ -817,6 +893,8 @@ void Frame::OnAppStart(wxCommandEvent& event) { kModelChoices[which_model].ToStdString(), kCharsPerSync[chars_per_sync_idx].ToStdString(), kBytesPerChar[bytes_per_char_idx].ToStdString(), + rows, + cols, enable_local_beep); if (!p) { Log(transcribe_out_, "Failed to launch transcription engine\n"); diff --git a/GUI/GUI/GUI/Frame.h b/GUI/GUI/GUI/Frame.h index 8a17ff2..3ce6cb9 100644 --- a/GUI/GUI/GUI/Frame.h +++ b/GUI/GUI/GUI/Frame.h @@ -29,6 +29,11 @@ private: wxTextCtrl* unity_parameters_generated_name_; wxTextCtrl* unity_menu_generated_name_; + wxTextCtrl* py_app_rows_; + wxTextCtrl* py_app_cols_; + wxTextCtrl* unity_rows_; + wxTextCtrl* unity_cols_; + wxDirPickerCtrl* unity_assets_file_picker_; wxFilePickerCtrl* unity_animator_file_picker_; wxFilePickerCtrl* unity_parameters_file_picker_; diff --git a/GUI/GUI/GUI/PythonWrapper.cpp b/GUI/GUI/GUI/PythonWrapper.cpp index 9cfaeba..4162a4e 100644 --- a/GUI/GUI/GUI/PythonWrapper.cpp +++ b/GUI/GUI/GUI/PythonWrapper.cpp @@ -125,7 +125,7 @@ wxProcess* PythonWrapper::StartApp( std::function&& exit_callback, const std::string& mic, const std::string& lang, const std::string& model, const std::string& chars_per_sync, const std::string& bytes_per_char, - const bool enable_local_beep) { + int rows, int cols, bool enable_local_beep) { return InvokeAsyncWithArgs({ "-u", "Resources/Scripts/transcribe.py", @@ -135,6 +135,8 @@ wxProcess* PythonWrapper::StartApp( "--chars_per_sync", chars_per_sync, "--bytes_per_char", bytes_per_char, "--enable_local_beep", enable_local_beep ? "1" : "0", + "--rows", std::to_string(rows), + "--cols", std::to_string(cols), }, std::move(exit_callback)); } @@ -150,12 +152,17 @@ bool PythonWrapper::GenerateAnimator( const std::string& unity_menu_generated_name, const std::string& chars_per_sync, const std::string& bytes_per_char, + const int rows, + const int cols, wxTextCtrl* out) { // Python script locations std::string libunity_path = "Resources/Scripts/libunity.py"; std::string libtastt_path = "Resources/Scripts/libtastt.py"; std::string generate_params_path = "Resources/Scripts/generate_params.py"; std::string generate_menu_path = "Resources/Scripts/generate_menu.py"; + std::string generate_shader_path = "Resources/Scripts/generate_shader.py"; + std::string shader_template_path = "Resources/Shaders/TaSTT_template.shader"; + std::string shader_path = "Resources/Shaders/TaSTT.shader"; // Generated directory locations std::filesystem::path tastt_generated_dir_path = @@ -186,6 +193,33 @@ bool PythonWrapper::GenerateAnimator( std::filesystem::path tastt_animator_path = tastt_generated_dir_path / unity_animator_generated_name; + { + Log(out, "Generating shader for {}x{} board...", rows, cols); + + std::string py_stdout, py_stderr; + if (InvokeWithArgs({ generate_shader_path, + "--bytes_per_char", bytes_per_char, + "--rows", std::to_string(rows), + "--cols", std::to_string(cols), + "--shader_template", shader_template_path, + "--shader_path", shader_path }, + &py_stdout, &py_stderr)) { + Log(out, "success!\n"); + Log(out, py_stdout.c_str()); + if (!py_stdout.empty()) { + Log(out, "\n"); + } + Log(out, py_stderr.c_str()); + if (!py_stderr.empty()) { + Log(out, "\n"); + } + } + else { + wxLogError("Failed to generate shader: %s", py_stderr.c_str()); + Log(out, "failed!\n"); + return false; + } + } { Log(out, "Creating {}\n", tastt_generated_dir_path.string()); std::filesystem::create_directories(tastt_generated_dir_path); @@ -276,7 +310,9 @@ bool PythonWrapper::GenerateAnimator( "--gen_anim_dir", tastt_animations_path.string(), "--guid_map", guid_map_path.string(), "--chars_per_sync", chars_per_sync, - "--bytes_per_char", bytes_per_char }, + "--bytes_per_char", bytes_per_char, + "--rows", std::to_string(rows), + "--cols", std::to_string(cols)}, &py_stdout, &py_stderr)) { Log(out, "success!\n"); Log(out, py_stdout.c_str()); @@ -302,7 +338,9 @@ bool PythonWrapper::GenerateAnimator( "--gen_anim_dir", tastt_animations_path.string(), "--guid_map", guid_map_path.string(), "--chars_per_sync", chars_per_sync, - "--bytes_per_char", bytes_per_char }, + "--bytes_per_char", bytes_per_char, + "--rows", std::to_string(rows), + "--cols", std::to_string(cols)}, &py_stdout, &py_stderr)) { Log(out, "success!\n"); Log(out, py_stdout.c_str()); diff --git a/GUI/GUI/GUI/PythonWrapper.h b/GUI/GUI/GUI/PythonWrapper.h index b0a66aa..95195b9 100644 --- a/GUI/GUI/GUI/PythonWrapper.h +++ b/GUI/GUI/GUI/PythonWrapper.h @@ -44,7 +44,7 @@ namespace PythonWrapper std::function&& exit_callback, const std::string& mic, const std::string& lang, const std::string& model, const std::string& chars_per_sync, const std::string& bytes_per_char, - const bool enable_local_beep + int rows, int cols, bool enable_local_beep ); bool GenerateAnimator( @@ -58,6 +58,8 @@ namespace PythonWrapper const std::string& unity_menu_generated_name, const std::string& chars_per_sync, const std::string& bytes_per_char, + int rows, + int cols, wxTextCtrl* out); }; -- cgit v1.2.3