diff options
-rw-r--r-- | include/Config.hpp | 2 | ||||
-rw-r--r-- | include/gui/SettingsPage.hpp | 39 | ||||
-rw-r--r-- | include/gui/Widget.hpp | 2 | ||||
-rw-r--r-- | src/Config.cpp | 6 | ||||
-rw-r--r-- | src/Overlay.cpp | 60 | ||||
-rw-r--r-- | src/gui/SettingsPage.cpp | 280 |
6 files changed, 173 insertions, 216 deletions
diff --git a/include/Config.hpp b/include/Config.hpp index cfb64df..6044ab8 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -25,9 +25,7 @@ namespace gsr { bool merge_audio_tracks = true; bool application_audio_invert = false; bool change_video_resolution = false; - std::string audio_type_view = "audio_devices"; std::vector<std::string> audio_tracks; - std::vector<std::string> application_audio; std::string color_range = "limited"; std::string video_quality = "very_high"; std::string video_codec = "auto"; diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp index 019de80..29f6c1a 100644 --- a/include/gui/SettingsPage.hpp +++ b/include/gui/SettingsPage.hpp @@ -29,7 +29,7 @@ namespace gsr { SettingsPage(const SettingsPage&) = delete; SettingsPage& operator=(const SettingsPage&) = delete; - void load(); + void load(const GsrInfo &gsr_info); void save(); void on_navigate_away_from_page() override; private: @@ -53,18 +53,16 @@ namespace gsr { std::unique_ptr<Button> create_remove_audio_device_button(List *audio_device_list_ptr); std::unique_ptr<List> create_audio_device(); std::unique_ptr<Button> create_add_audio_device_button(); - std::unique_ptr<List> create_audio_device_track_section(); - std::unique_ptr<CheckBox> create_merge_audio_tracks_checkbox(); - std::unique_ptr<RadioButton> create_audio_type_button(); - std::unique_ptr<Widget> create_audio_device_section(); - std::unique_ptr<List> create_application_audio_track_section(); - std::unique_ptr<CheckBox> create_application_audio_invert_checkbox(); - std::unique_ptr<List> create_application_audio_section(); std::unique_ptr<ComboBox> create_application_audio_selection_combobox(); - std::unique_ptr<Button> create_remove_application_audio_button(List *app_audio_item); std::unique_ptr<List> create_application_audio(); std::unique_ptr<List> create_custom_application_audio(); - std::unique_ptr<List> create_add_application_audio_buttons(); + std::unique_ptr<Button> create_add_application_audio_button(); + std::unique_ptr<Button> create_add_custom_application_audio_button(); + std::unique_ptr<List> create_add_audio_buttons(); + std::unique_ptr<List> create_audio_track_track_section(); + std::unique_ptr<CheckBox> create_merge_audio_tracks_checkbox(); + std::unique_ptr<CheckBox> create_application_audio_invert_checkbox(); + std::unique_ptr<Widget> create_audio_track_section(); std::unique_ptr<Widget> create_audio_section(); std::unique_ptr<List> create_video_quality_box(); std::unique_ptr<Entry> create_video_bitrate_entry(); @@ -109,12 +107,11 @@ namespace gsr { std::unique_ptr<List> create_stream_container_section(); void add_stream_widgets(); - void load_audio_device_tracks(RecordOptions &record_options); - void load_application_audio_tracks(RecordOptions &record_options); - void load_common(RecordOptions &record_options); - void load_replay(); - void load_record(); - void load_stream(); + void load_audio_tracks(const RecordOptions &record_options, const GsrInfo &gsr_info); + void load_common(RecordOptions &record_options, const GsrInfo &gsr_info); + void load_replay(const GsrInfo &gsr_info); + void load_record(const GsrInfo &gsr_info); + void load_stream(const GsrInfo &gsr_info); void save_common(RecordOptions &record_options); void save_replay(); @@ -145,14 +142,10 @@ namespace gsr { Entry *framerate_entry_ptr = nullptr; Entry *video_bitrate_entry_ptr = nullptr; List *video_bitrate_list_ptr = nullptr; - List *audio_devices_list_ptr = nullptr; - List *audio_devices_section_list_ptr = nullptr; - Label *audio_devices_label_ptr = nullptr; - List *application_audio_section_list_ptr = nullptr; - LineSeparator *audio_type_line_sep_ptr = nullptr; + List *audio_track_list_ptr = nullptr; + Button *add_application_audio_button_ptr = nullptr; + Button *add_custom_application_audio_button_ptr = nullptr; CheckBox *merge_audio_tracks_checkbox_ptr = nullptr; - RadioButton *audio_type_radio_button_ptr = nullptr; - List *application_audio_list_ptr = nullptr; CheckBox *application_audio_invert_checkbox_ptr = nullptr; CheckBox *change_video_resolution_checkbox_ptr = nullptr; ComboBox *color_range_box_ptr = nullptr; diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp index 9a18722..57424cd 100644 --- a/include/gui/Widget.hpp +++ b/include/gui/Widget.hpp @@ -45,6 +45,8 @@ namespace gsr { Alignment get_vertical_alignment() const; void set_visible(bool visible); + + void *userdata = nullptr; protected: void set_widget_as_selected_in_parent(); void remove_widget_as_selected_in_parent(); diff --git a/src/Config.cpp b/src/Config.cpp index b717723..112688a 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -60,9 +60,7 @@ namespace gsr { {"streaming.record_options.merge_audio_tracks", &config.streaming_config.record_options.merge_audio_tracks}, {"streaming.record_options.application_audio_invert", &config.streaming_config.record_options.application_audio_invert}, {"streaming.record_options.change_video_resolution", &config.streaming_config.record_options.change_video_resolution}, - {"streaming.record_options.audio_type_view", &config.streaming_config.record_options.audio_type_view}, {"streaming.record_options.audio_track", &config.streaming_config.record_options.audio_tracks}, - {"streaming.record_options.application_audio", &config.streaming_config.record_options.application_audio}, {"streaming.record_options.color_range", &config.streaming_config.record_options.color_range}, {"streaming.record_options.video_quality", &config.streaming_config.record_options.video_quality}, {"streaming.record_options.codec", &config.streaming_config.record_options.video_codec}, @@ -91,9 +89,7 @@ namespace gsr { {"record.record_options.merge_audio_tracks", &config.record_config.record_options.merge_audio_tracks}, {"record.record_options.application_audio_invert", &config.record_config.record_options.application_audio_invert}, {"record.record_options.change_video_resolution", &config.record_config.record_options.change_video_resolution}, - {"record.record_options.audio_type_view", &config.record_config.record_options.audio_type_view}, {"record.record_options.audio_track", &config.record_config.record_options.audio_tracks}, - {"record.record_options.application_audio", &config.record_config.record_options.application_audio}, {"record.record_options.color_range", &config.record_config.record_options.color_range}, {"record.record_options.video_quality", &config.record_config.record_options.video_quality}, {"record.record_options.codec", &config.record_config.record_options.video_codec}, @@ -121,9 +117,7 @@ namespace gsr { {"replay.record_options.merge_audio_tracks", &config.replay_config.record_options.merge_audio_tracks}, {"replay.record_options.application_audio_invert", &config.replay_config.record_options.application_audio_invert}, {"replay.record_options.change_video_resolution", &config.replay_config.record_options.change_video_resolution}, - {"replay.record_options.audio_type_view", &config.replay_config.record_options.audio_type_view}, {"replay.record_options.audio_track", &config.replay_config.record_options.audio_tracks}, - {"replay.record_options.application_audio", &config.replay_config.record_options.application_audio}, {"replay.record_options.color_range", &config.replay_config.record_options.color_range}, {"replay.record_options.video_quality", &config.replay_config.record_options.video_quality}, {"replay.record_options.codec", &config.replay_config.record_options.video_codec}, diff --git a/src/Overlay.cpp b/src/Overlay.cpp index 16495fc..33989e5 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -1030,12 +1030,26 @@ namespace gsr { return container; } - static std::string merge_audio_tracks(const std::vector<std::string> &audio_tracks) { + static bool starts_with(std::string_view str, const char *substr) { + size_t len = strlen(substr); + return str.size() >= len && memcmp(str.data(), substr, len) == 0; + } + + static std::string merge_audio_tracks(const std::vector<std::string> &audio_tracks, bool application_audio_invert, const GsrInfo &gsr_info) { std::string result; for(size_t i = 0; i < audio_tracks.size(); ++i) { if(i > 0) result += "|"; - result += audio_tracks[i]; + + std::string audio_track_name = audio_tracks[i]; + const bool is_app_audio = starts_with(audio_track_name, "app:"); + if(is_app_audio && !gsr_info.system_info.supports_app_audio) + continue; + + if(is_app_audio && application_audio_invert) + audio_track_name.replace(0, 4, "app-inverse:"); + + result += audio_track_name; } return result; } @@ -1047,7 +1061,7 @@ namespace gsr { kill(gpu_screen_recorder_process, SIGUSR1); } - static void add_common_gpu_screen_recorder_args(RecordOptions &record_options, std::vector<const char*> &args, const std::string &video_bitrate, const char *region, const std::string &audio_devices_merged, const std::string &application_audio_merged) { + static void add_common_gpu_screen_recorder_args(RecordOptions &record_options, std::vector<const char*> &args, const std::string &video_bitrate, const char *region, const std::string &audio_devices_merged) { if(record_options.video_quality == "custom") { args.push_back("-bm"); args.push_back("cbr"); @@ -1063,26 +1077,13 @@ namespace gsr { args.push_back(region); } - if(record_options.audio_type_view == "audio_devices") { - if(record_options.merge_audio_tracks) { + if(record_options.merge_audio_tracks) { + args.push_back("-a"); + args.push_back(audio_devices_merged.c_str()); + } else { + for(const std::string &audio_track : record_options.audio_tracks) { args.push_back("-a"); - args.push_back(audio_devices_merged.c_str()); - } else { - for(const std::string &audio_track : record_options.audio_tracks) { - args.push_back("-a"); - args.push_back(audio_track.c_str()); - } - } - } else if(record_options.audio_type_view == "app_audio") { - const char *app_audio_option = record_options.application_audio_invert ? "-aai" : "-aa"; - if(record_options.merge_audio_tracks) { - args.push_back(app_audio_option); - args.push_back(application_audio_merged.c_str()); - } else { - for(const std::string &app_audio : record_options.application_audio) { - args.push_back(app_audio_option); - args.push_back(app_audio.c_str()); - } + args.push_back(audio_track.c_str()); } } } @@ -1127,8 +1128,7 @@ namespace gsr { const std::string fps = std::to_string(config.replay_config.record_options.fps); const std::string video_bitrate = std::to_string(config.replay_config.record_options.video_bitrate); const std::string output_directory = config.replay_config.save_directory; - const std::string audio_devices_merged = merge_audio_tracks(config.replay_config.record_options.audio_tracks); - const std::string application_audio_merged = merge_audio_tracks(config.replay_config.record_options.application_audio); + const std::string audio_tracks_merged = merge_audio_tracks(config.replay_config.record_options.audio_tracks, config.replay_config.record_options.application_audio_invert, gsr_info); const std::string framerate_mode = config.replay_config.record_options.framerate_mode == "auto" ? "vfr" : config.replay_config.record_options.framerate_mode; const std::string replay_time = std::to_string(config.replay_config.replay_time); const char *video_codec = config.replay_config.record_options.video_codec.c_str(); @@ -1159,7 +1159,7 @@ namespace gsr { "-o", output_directory.c_str() }; - add_common_gpu_screen_recorder_args(config.replay_config.record_options, args, video_bitrate, region, audio_devices_merged, application_audio_merged); + add_common_gpu_screen_recorder_args(config.replay_config.record_options, args, video_bitrate, region, audio_tracks_merged); setenv("GSR_SHOW_SAVED_NOTIFICATION", config.replay_config.show_replay_saved_notifications ? "1" : "0", true); const std::string script_to_run_on_save = resources_path + (config.replay_config.save_video_in_game_folder ? "scripts/save-video-in-game-folder.sh" : "scripts/notify-saved-name.sh"); @@ -1228,8 +1228,7 @@ namespace gsr { const std::string fps = std::to_string(config.record_config.record_options.fps); const std::string video_bitrate = std::to_string(config.record_config.record_options.video_bitrate); const std::string output_file = config.record_config.save_directory + "/Video_" + get_date_str() + "." + container_to_file_extension(config.record_config.container.c_str()); - const std::string audio_devices_merged = merge_audio_tracks(config.record_config.record_options.audio_tracks); - const std::string application_audio_merged = merge_audio_tracks(config.record_config.record_options.application_audio); + const std::string audio_tracks_merged = merge_audio_tracks(config.record_config.record_options.audio_tracks, config.record_config.record_options.application_audio_invert, gsr_info); const std::string framerate_mode = config.record_config.record_options.framerate_mode == "auto" ? "vfr" : config.record_config.record_options.framerate_mode; const char *video_codec = config.record_config.record_options.video_codec.c_str(); const char *encoder = "gpu"; @@ -1258,7 +1257,7 @@ namespace gsr { "-o", output_file.c_str() }; - add_common_gpu_screen_recorder_args(config.record_config.record_options, args, video_bitrate, region, audio_devices_merged, application_audio_merged); + add_common_gpu_screen_recorder_args(config.record_config.record_options, args, video_bitrate, region, audio_tracks_merged); setenv("GSR_SHOW_SAVED_NOTIFICATION", config.record_config.show_video_saved_notifications ? "1" : "0", true); const std::string script_to_run_on_save = resources_path + (config.record_config.save_video_in_game_folder ? "scripts/save-video-in-game-folder.sh" : "scripts/notify-saved-name.sh"); @@ -1356,8 +1355,7 @@ namespace gsr { // TODO: Validate input, fallback to valid values const std::string fps = std::to_string(config.streaming_config.record_options.fps); const std::string video_bitrate = std::to_string(config.streaming_config.record_options.video_bitrate); - const std::string audio_devices_merged = merge_audio_tracks(config.streaming_config.record_options.audio_tracks); - const std::string application_audio_merged = merge_audio_tracks(config.streaming_config.record_options.application_audio); + const std::string audio_tracks_merged = merge_audio_tracks(config.streaming_config.record_options.audio_tracks, config.streaming_config.record_options.application_audio_invert, gsr_info); const std::string framerate_mode = config.streaming_config.record_options.framerate_mode == "auto" ? "vfr" : config.streaming_config.record_options.framerate_mode; const char *video_codec = config.streaming_config.record_options.video_codec.c_str(); const char *encoder = "gpu"; @@ -1392,7 +1390,7 @@ namespace gsr { "-o", url.c_str() }; - add_common_gpu_screen_recorder_args(config.streaming_config.record_options, args, video_bitrate, region, audio_devices_merged, application_audio_merged); + add_common_gpu_screen_recorder_args(config.streaming_config.record_options, args, video_bitrate, region, audio_tracks_merged); args.push_back(nullptr); diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index fad02fa..949e31a 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -1,7 +1,6 @@ #include "../../include/gui/SettingsPage.hpp" #include "../../include/gui/GsrPage.hpp" #include "../../include/gui/Label.hpp" -#include "../../include/gui/LineSeparator.hpp" #include "../../include/gui/PageStack.hpp" #include "../../include/gui/FileChooser.hpp" #include "../../include/gui/Subsection.hpp" @@ -17,6 +16,12 @@ #include <string.h> namespace gsr { + enum class AudioTrackType { + DEVICE, + APPLICATION, + APPLICATION_CUSTOM + }; + SettingsPage::SettingsPage(Type type, const GsrInfo &gsr_info, Config &config, PageStack *page_stack) : StaticPage(mgl::vec2f(get_theme().window_width, get_theme().window_height).floor()), type(type), @@ -38,7 +43,7 @@ namespace gsr { add_widgets(gsr_info); add_page_specific_widgets(); - load(); + load(gsr_info); } std::unique_ptr<RadioButton> SettingsPage::create_view_radio_button() { @@ -193,13 +198,15 @@ namespace gsr { std::unique_ptr<Button> SettingsPage::create_remove_audio_device_button(List *audio_device_list_ptr) { auto remove_audio_track_button = std::make_unique<Button>(&get_theme().body_font, "Remove", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120)); remove_audio_track_button->on_click = [this, audio_device_list_ptr]() { - audio_devices_list_ptr->remove_widget(audio_device_list_ptr); + audio_track_list_ptr->remove_widget(audio_device_list_ptr); }; return remove_audio_track_button; } std::unique_ptr<List> SettingsPage::create_audio_device() { auto audio_device_list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER); + audio_device_list->userdata = (void*)(uintptr_t)AudioTrackType::DEVICE; + audio_device_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Device:", get_color_theme().text_color)); audio_device_list->add_widget(create_audio_device_selection_combobox()); audio_device_list->add_widget(create_remove_audio_device_button(audio_device_list.get())); return audio_device_list; @@ -209,44 +216,11 @@ namespace gsr { auto add_audio_track_button = std::make_unique<Button>(&get_theme().body_font, "Add audio device", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120)); add_audio_track_button->on_click = [this]() { audio_devices = get_audio_devices(); - audio_devices_list_ptr->add_widget(create_audio_device()); + audio_track_list_ptr->add_widget(create_audio_device()); }; return add_audio_track_button; } - std::unique_ptr<List> SettingsPage::create_audio_device_track_section() { - auto audio_devices_list = std::make_unique<List>(List::Orientation::VERTICAL); - audio_devices_list_ptr = audio_devices_list.get(); - audio_devices_list_ptr->add_widget(create_audio_device()); - return audio_devices_list; - } - - std::unique_ptr<CheckBox> SettingsPage::create_merge_audio_tracks_checkbox() { - auto merge_audio_tracks_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Merge audio tracks"); - merge_audio_tracks_checkbox->set_checked(true); - merge_audio_tracks_checkbox_ptr = merge_audio_tracks_checkbox.get(); - return merge_audio_tracks_checkbox; - } - - std::unique_ptr<RadioButton> SettingsPage::create_audio_type_button() { - auto audio_type_radio_button = std::make_unique<RadioButton>(&get_theme().body_font, RadioButton::Orientation::HORIZONTAL); - audio_type_radio_button->add_item("Audio devices", "audio_devices"); - audio_type_radio_button->add_item("Application audio", "app_audio"); - audio_type_radio_button_ptr = audio_type_radio_button.get(); - return audio_type_radio_button; - } - - std::unique_ptr<Widget> SettingsPage::create_audio_device_section() { - auto audio_devices_section_list = std::make_unique<List>(List::Orientation::VERTICAL); - audio_devices_section_list_ptr = audio_devices_section_list.get(); - auto audio_devices_label = std::make_unique<Label>(&get_theme().title_font, "Audio devices", get_color_theme().text_color); - audio_devices_label_ptr = audio_devices_label.get(); - audio_devices_section_list->add_widget(std::move(audio_devices_label)); - audio_devices_section_list->add_widget(create_add_audio_device_button()); - audio_devices_section_list->add_widget(create_audio_device_track_section()); - return audio_devices_section_list; - } - std::unique_ptr<ComboBox> SettingsPage::create_application_audio_selection_combobox() { auto audio_device_box = std::make_unique<ComboBox>(&get_theme().body_font); for(const auto &app_audio : application_audio) { @@ -255,51 +229,63 @@ namespace gsr { return audio_device_box; } - std::unique_ptr<Button> SettingsPage::create_remove_application_audio_button(List *app_audio_item) { - auto remove_audio_track_button = std::make_unique<Button>(&get_theme().body_font, "Remove", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120)); - remove_audio_track_button->on_click = [this, app_audio_item]() { - application_audio_list_ptr->remove_widget(app_audio_item); - }; - return remove_audio_track_button; - } - std::unique_ptr<List> SettingsPage::create_application_audio() { auto application_audio_list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER); + application_audio_list->userdata = (void*)(uintptr_t)AudioTrackType::APPLICATION; + application_audio_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "App: ", get_color_theme().text_color)); application_audio_list->add_widget(create_application_audio_selection_combobox()); - application_audio_list->add_widget(create_remove_application_audio_button(application_audio_list.get())); + application_audio_list->add_widget(create_remove_audio_device_button(application_audio_list.get())); return application_audio_list; } std::unique_ptr<List> SettingsPage::create_custom_application_audio() { auto application_audio_list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER); + application_audio_list->userdata = (void*)(uintptr_t)AudioTrackType::APPLICATION_CUSTOM; + application_audio_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "App: ", get_color_theme().text_color)); application_audio_list->add_widget(std::make_unique<Entry>(&get_theme().body_font, "", (int)(get_theme().body_font.get_character_size() * 10.0f))); - application_audio_list->add_widget(create_remove_application_audio_button(application_audio_list.get())); + application_audio_list->add_widget(create_remove_audio_device_button(application_audio_list.get())); return application_audio_list; } - std::unique_ptr<List> SettingsPage::create_add_application_audio_buttons() { - auto list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER); - - auto add_application_audio_button = std::make_unique<Button>(&get_theme().body_font, "Add application audio", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120)); - add_application_audio_button->on_click = [this]() { + std::unique_ptr<Button> SettingsPage::create_add_application_audio_button() { + auto add_audio_track_button = std::make_unique<Button>(&get_theme().body_font, "Add application audio", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120)); + add_application_audio_button_ptr = add_audio_track_button.get(); + add_audio_track_button->on_click = [this]() { application_audio = get_application_audio(); - application_audio_list_ptr->add_widget(create_application_audio()); + audio_track_list_ptr->add_widget(create_application_audio()); }; - list->add_widget(std::move(add_application_audio_button)); + return add_audio_track_button; + } - auto add_custom_application_audio_button = std::make_unique<Button>(&get_theme().body_font, "Add custom application audio", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120)); - add_custom_application_audio_button->on_click = [this]() { - application_audio_list_ptr->add_widget(create_custom_application_audio()); + std::unique_ptr<Button> SettingsPage::create_add_custom_application_audio_button() { + auto add_audio_track_button = std::make_unique<Button>(&get_theme().body_font, "Add custom application audio", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120)); + add_custom_application_audio_button_ptr = add_audio_track_button.get(); + add_audio_track_button->on_click = [this]() { + audio_track_list_ptr->add_widget(create_custom_application_audio()); }; - list->add_widget(std::move(add_custom_application_audio_button)); + return add_audio_track_button; + } + std::unique_ptr<List> SettingsPage::create_add_audio_buttons() { + auto list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER); + list->add_widget(create_add_audio_device_button()); + list->add_widget(create_add_application_audio_button()); + list->add_widget(create_add_custom_application_audio_button()); return list; } - std::unique_ptr<List> SettingsPage::create_application_audio_track_section() { - auto application_audio_list = std::make_unique<List>(List::Orientation::VERTICAL); - application_audio_list_ptr = application_audio_list.get(); - return application_audio_list; + std::unique_ptr<List> SettingsPage::create_audio_track_track_section() { + auto list = std::make_unique<List>(List::Orientation::VERTICAL); + audio_track_list_ptr = list.get(); + audio_track_list_ptr->add_widget(create_audio_device()); // Add default_output by default + return list; + } + + std::unique_ptr<CheckBox> SettingsPage::create_merge_audio_tracks_checkbox() { + auto merge_audio_tracks_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Merge audio tracks"); + merge_audio_tracks_checkbox->set_checked(true); + merge_audio_tracks_checkbox_ptr = merge_audio_tracks_checkbox.get(); + return merge_audio_tracks_checkbox; } std::unique_ptr<CheckBox> SettingsPage::create_application_audio_invert_checkbox() { @@ -309,31 +295,20 @@ namespace gsr { return application_audio_invert_checkbox; } - std::unique_ptr<List> SettingsPage::create_application_audio_section() { - auto application_audio_section_list = std::make_unique<List>(List::Orientation::VERTICAL); - application_audio_section_list_ptr = application_audio_section_list.get(); - application_audio_section_list->add_widget(std::make_unique<Label>(&get_theme().title_font, "Application audio", get_color_theme().text_color)); - application_audio_section_list->add_widget(create_add_application_audio_buttons()); - application_audio_section_list->add_widget(create_application_audio_track_section()); - application_audio_section_list->add_widget(create_application_audio_invert_checkbox()); - return application_audio_section_list; + std::unique_ptr<Widget> SettingsPage::create_audio_track_section() { + auto list = std::make_unique<List>(List::Orientation::VERTICAL); + list->add_widget(create_add_audio_buttons()); + list->add_widget(create_audio_track_track_section()); + return list; } std::unique_ptr<Widget> SettingsPage::create_audio_section() { auto audio_device_section_list = std::make_unique<List>(List::Orientation::VERTICAL); - List *audio_device_section_list_ptr = audio_device_section_list.get(); - auto audio_section = std::make_unique<Subsection>("Audio", std::move(audio_device_section_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)); - - audio_device_section_list_ptr->add_widget(create_audio_type_button()); - auto audio_type_line_sep = std::make_unique<LineSeparator>(LineSeparator::Orientation::HORIZONTAL, audio_section->get_inner_size().x); - audio_type_line_sep_ptr = audio_type_line_sep.get(); - audio_device_section_list_ptr->add_widget(std::move(audio_type_line_sep)); - audio_device_section_list_ptr->add_widget(create_audio_device_section()); - audio_device_section_list_ptr->add_widget(create_application_audio_section()); - //audio_device_section_list_ptr->add_widget(std::make_unique<LineSeparator>(LineSeparator::Orientation::HORIZONTAL, audio_section->get_inner_size().x)); - audio_device_section_list_ptr->add_widget(create_merge_audio_tracks_checkbox()); - audio_device_section_list_ptr->add_widget(create_audio_codec()); - return audio_section; + audio_device_section_list->add_widget(create_audio_track_section()); + audio_device_section_list->add_widget(create_merge_audio_tracks_checkbox()); + audio_device_section_list->add_widget(create_application_audio_invert_checkbox()); + audio_device_section_list->add_widget(create_audio_codec()); + return std::make_unique<Subsection>("Audio", std::move(audio_device_section_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)); } std::unique_ptr<List> SettingsPage::create_video_quality_box() { @@ -568,22 +543,10 @@ namespace gsr { else record_area_box_ptr->on_selection_changed("", ""); - audio_type_radio_button_ptr->on_selection_changed = [this](const std::string&, const std::string &id) { - if(id == "audio_devices") { - audio_devices_section_list_ptr->set_visible(true); - application_audio_section_list_ptr->set_visible(false); - } else if(id == "app_audio") { - audio_devices_section_list_ptr->set_visible(false); - application_audio_section_list_ptr->set_visible(true); - } - }; - audio_type_radio_button_ptr->on_selection_changed("", "audio_devices"); - if(!gsr_info.system_info.supports_app_audio) { - audio_type_radio_button_ptr->set_visible(false); - audio_type_line_sep_ptr->set_visible(false); - audio_devices_label_ptr->set_visible(false); - application_audio_section_list_ptr->set_visible(false); + add_application_audio_button_ptr->set_visible(false); + add_custom_application_audio_button_ptr->set_visible(false); + application_audio_invert_checkbox_ptr->set_visible(false); } } @@ -909,16 +872,16 @@ namespace gsr { save(); } - void SettingsPage::load() { + void SettingsPage::load(const GsrInfo &gsr_info) { switch(type) { case Type::REPLAY: - load_replay(); + load_replay(gsr_info); break; case Type::RECORD: - load_record(); + load_record(gsr_info); break; case Type::STREAM: - load_stream(); + load_stream(gsr_info); break; } } @@ -946,42 +909,51 @@ namespace gsr { return nullptr; } - void SettingsPage::load_audio_device_tracks(RecordOptions &record_options) { - audio_devices_list_ptr->clear(); - for(const std::string &audio_track : record_options.audio_tracks) { - std::unique_ptr<List> audio_track_widget = create_audio_device(); - ComboBox *audio_device_box = static_cast<ComboBox*>(audio_track_widget->get_child_widget_by_index(0)); - audio_device_box->set_selected_item(audio_track); - audio_devices_list_ptr->add_widget(std::move(audio_track_widget)); - } + static bool starts_with(std::string_view str, const char *substr) { + size_t len = strlen(substr); + return str.size() >= len && memcmp(str.data(), substr, len) == 0; } - void SettingsPage::load_application_audio_tracks(RecordOptions &record_options) { - application_audio_list_ptr->clear(); - for(const std::string &audio_track : record_options.application_audio) { - const std::string *app_audio = get_application_audio_by_name_case_insensitive(application_audio, audio_track); - if(app_audio) { - std::unique_ptr<List> application_audio_widget = create_application_audio(); - ComboBox *application_audio_box = static_cast<ComboBox*>(application_audio_widget->get_child_widget_by_index(0)); - application_audio_box->set_selected_item(*app_audio); - application_audio_list_ptr->add_widget(std::move(application_audio_widget)); + void SettingsPage::load_audio_tracks(const RecordOptions &record_options, const GsrInfo &gsr_info) { + audio_track_list_ptr->clear(); + for(const std::string &audio_track : record_options.audio_tracks) { + if(starts_with(audio_track, "app:")) { + if(!gsr_info.system_info.supports_app_audio) + continue; + + std::string audio_track_name = audio_track.substr(4); + const std::string *app_audio = get_application_audio_by_name_case_insensitive(application_audio, audio_track_name); + if(app_audio) { + std::unique_ptr<List> application_audio_widget = create_application_audio(); + ComboBox *application_audio_box = static_cast<ComboBox*>(application_audio_widget->get_child_widget_by_index(1)); + application_audio_box->set_selected_item(*app_audio); + audio_track_list_ptr->add_widget(std::move(application_audio_widget)); + } else { + std::unique_ptr<List> application_audio_widget = create_custom_application_audio(); + Entry *application_audio_entry = static_cast<Entry*>(application_audio_widget->get_child_widget_by_index(1)); + application_audio_entry->set_text(std::move(audio_track_name)); + audio_track_list_ptr->add_widget(std::move(application_audio_widget)); + } + } else if(starts_with(audio_track, "device:")) { + std::unique_ptr<List> audio_track_widget = create_audio_device(); + ComboBox *audio_device_box = static_cast<ComboBox*>(audio_track_widget->get_child_widget_by_index(1)); + audio_device_box->set_selected_item(audio_track.substr(7)); + audio_track_list_ptr->add_widget(std::move(audio_track_widget)); } else { - std::unique_ptr<List> application_audio_widget = create_custom_application_audio(); - Entry *application_audio_entry = static_cast<Entry*>(application_audio_widget->get_child_widget_by_index(0)); - application_audio_entry->set_text(audio_track); - application_audio_list_ptr->add_widget(std::move(application_audio_widget)); + std::unique_ptr<List> audio_track_widget = create_audio_device(); + ComboBox *audio_device_box = static_cast<ComboBox*>(audio_track_widget->get_child_widget_by_index(1)); + audio_device_box->set_selected_item(audio_track); + audio_track_list_ptr->add_widget(std::move(audio_track_widget)); } } } - void SettingsPage::load_common(RecordOptions &record_options) { + void SettingsPage::load_common(RecordOptions &record_options, const GsrInfo &gsr_info) { record_area_box_ptr->set_selected_item(record_options.record_area_option); merge_audio_tracks_checkbox_ptr->set_checked(record_options.merge_audio_tracks); application_audio_invert_checkbox_ptr->set_checked(record_options.application_audio_invert); change_video_resolution_checkbox_ptr->set_checked(record_options.change_video_resolution); - audio_type_radio_button_ptr->set_selected_item(record_options.audio_type_view); - load_audio_device_tracks(record_options); - load_application_audio_tracks(record_options); + load_audio_tracks(record_options, gsr_info); color_range_box_ptr->set_selected_item(record_options.color_range); video_quality_box_ptr->set_selected_item(record_options.video_quality); video_codec_box_ptr->set_selected_item(record_options.video_codec); @@ -1030,8 +1002,8 @@ namespace gsr { video_bitrate_entry_ptr->set_text(std::to_string(record_options.video_bitrate)); } - void SettingsPage::load_replay() { - load_common(config.replay_config.record_options); + void SettingsPage::load_replay(const GsrInfo &gsr_info) { + load_common(config.replay_config.record_options, gsr_info); turn_on_replay_automatically_mode_ptr->set_selected_item(config.replay_config.turn_on_replay_automatically_mode); save_replay_in_game_folder_ptr->set_checked(config.replay_config.save_video_in_game_folder); show_replay_started_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_started_notifications); @@ -1045,8 +1017,8 @@ namespace gsr { replay_time_entry_ptr->set_text(std::to_string(config.replay_config.replay_time)); } - void SettingsPage::load_record() { - load_common(config.record_config.record_options); + void SettingsPage::load_record(const GsrInfo &gsr_info) { + load_common(config.record_config.record_options, gsr_info); save_recording_in_game_folder_ptr->set_checked(config.record_config.save_video_in_game_folder); show_recording_started_notification_checkbox_ptr->set_checked(config.record_config.show_recording_started_notifications); show_video_saved_notification_checkbox_ptr->set_checked(config.record_config.show_video_saved_notifications); @@ -1054,8 +1026,8 @@ namespace gsr { container_box_ptr->set_selected_item(config.record_config.container); } - void SettingsPage::load_stream() { - load_common(config.streaming_config.record_options); + void SettingsPage::load_stream(const GsrInfo &gsr_info) { + load_common(config.streaming_config.record_options, gsr_info); show_streaming_started_notification_checkbox_ptr->set_checked(config.streaming_config.show_streaming_started_notifications); show_streaming_stopped_notification_checkbox_ptr->set_checked(config.streaming_config.show_streaming_stopped_notifications); streaming_service_box_ptr->set_selected_item(config.streaming_config.streaming_service); @@ -1065,26 +1037,28 @@ namespace gsr { container_box_ptr->set_selected_item(config.streaming_config.custom.container); } - static void save_audio_device_tracks(std::vector<std::string> &audio_devices, List *audio_devices_list_ptr) { + static void save_audio_tracks(std::vector<std::string> &audio_devices, List *audio_devices_list_ptr) { audio_devices.clear(); audio_devices_list_ptr->for_each_child_widget([&audio_devices](std::unique_ptr<Widget> &child_widget) { - List *audio_device_line = static_cast<List*>(child_widget.get()); - ComboBox *audio_device_box = static_cast<ComboBox*>(audio_device_line->get_child_widget_by_index(0)); - audio_devices.push_back(audio_device_box->get_selected_id()); - return true; - }); - } - - static void save_application_audio_tracks(std::vector<std::string> &application_audio, List *application_audio_list_ptr) { - application_audio.clear(); - application_audio_list_ptr->for_each_child_widget([&application_audio](std::unique_ptr<Widget> &child_widget) { - List *application_audio_line = static_cast<List*>(child_widget.get()); - ComboBox *application_audio_box = dynamic_cast<ComboBox*>(application_audio_line->get_child_widget_by_index(0)); - Entry *application_audio_entry = dynamic_cast<Entry*>(application_audio_line->get_child_widget_by_index(0)); - if(application_audio_box) - application_audio.push_back(application_audio_box->get_selected_id()); - else if(application_audio_entry) - application_audio.push_back(application_audio_entry->get_text()); + List *audio_track_line = static_cast<List*>(child_widget.get()); + const AudioTrackType audio_track_type = (AudioTrackType)(uintptr_t)audio_track_line->userdata; + switch(audio_track_type) { + case AudioTrackType::DEVICE: { + ComboBox *audio_device_box = static_cast<ComboBox*>(audio_track_line->get_child_widget_by_index(1)); + audio_devices.push_back("device:" + audio_device_box->get_selected_id()); + break; + } + case AudioTrackType::APPLICATION: { + ComboBox *application_audio_box = static_cast<ComboBox*>(audio_track_line->get_child_widget_by_index(1)); + audio_devices.push_back("app:" + application_audio_box->get_selected_id()); + break; + } + case AudioTrackType::APPLICATION_CUSTOM: { + Entry *application_audio_entry = static_cast<Entry*>(audio_track_line->get_child_widget_by_index(1)); + audio_devices.push_back("app:" + application_audio_entry->get_text()); + break; + } + } return true; }); } @@ -1100,9 +1074,7 @@ namespace gsr { record_options.merge_audio_tracks = merge_audio_tracks_checkbox_ptr->is_checked(); record_options.application_audio_invert = application_audio_invert_checkbox_ptr->is_checked(); record_options.change_video_resolution = change_video_resolution_checkbox_ptr->is_checked(); - record_options.audio_type_view = audio_type_radio_button_ptr->get_selected_id(); - save_audio_device_tracks(record_options.audio_tracks, audio_devices_list_ptr); - save_application_audio_tracks(record_options.application_audio, application_audio_list_ptr); + save_audio_tracks(record_options.audio_tracks, audio_track_list_ptr); record_options.color_range = color_range_box_ptr->get_selected_id(); record_options.video_quality = video_quality_box_ptr->get_selected_id(); record_options.video_codec = video_codec_box_ptr->get_selected_id(); |