aboutsummaryrefslogtreecommitdiff
path: root/src/Config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Config.cpp')
-rw-r--r--src/Config.cpp256
1 files changed, 224 insertions, 32 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
index 4ad1107..313cd38 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -1,50 +1,162 @@
#include "../include/Config.hpp"
#include "../include/Utils.hpp"
#include "../include/GsrInfo.hpp"
+#include "../include/GlobalHotkeys/GlobalHotkeys.hpp"
#include <variant>
#include <limits.h>
#include <inttypes.h>
#include <libgen.h>
-#include <iostream>
+#include <string.h>
+#include <assert.h>
+#include <mglpp/window/Keyboard.hpp>
#define FORMAT_I32 "%" PRIi32
#define FORMAT_I64 "%" PRIi64
#define FORMAT_U32 "%" PRIu32
-#define CONFIG_FILE_VERSION 1
-
namespace gsr {
+ static const std::string_view add_audio_track_tag = "[add_audio_track]";
+
+ static std::vector<mgl::Keyboard::Key> hotkey_modifiers_to_mgl_keys(uint32_t modifiers) {
+ std::vector<mgl::Keyboard::Key> result;
+ if(modifiers & HOTKEY_MOD_LCTRL)
+ result.push_back(mgl::Keyboard::LControl);
+ if(modifiers & HOTKEY_MOD_LSHIFT)
+ result.push_back(mgl::Keyboard::LShift);
+ if(modifiers & HOTKEY_MOD_LALT)
+ result.push_back(mgl::Keyboard::LAlt);
+ if(modifiers & HOTKEY_MOD_LSUPER)
+ result.push_back(mgl::Keyboard::LSystem);
+ if(modifiers & HOTKEY_MOD_RCTRL)
+ result.push_back(mgl::Keyboard::RControl);
+ if(modifiers & HOTKEY_MOD_RSHIFT)
+ result.push_back(mgl::Keyboard::RShift);
+ if(modifiers & HOTKEY_MOD_RALT)
+ result.push_back(mgl::Keyboard::RAlt);
+ if(modifiers & HOTKEY_MOD_RSUPER)
+ result.push_back(mgl::Keyboard::RSystem);
+ return result;
+ }
+
+ static void string_remove_all(std::string &str, const std::string &substr) {
+ size_t index = 0;
+ while(true) {
+ index = str.find(substr, index);
+ if(index == std::string::npos)
+ break;
+ str.erase(index, substr.size());
+ }
+ }
+
+ ReplayStartupMode replay_startup_string_to_type(const char *startup_mode_str) {
+ if(strcmp(startup_mode_str, "dont_turn_on_automatically") == 0)
+ return ReplayStartupMode::DONT_TURN_ON_AUTOMATICALLY;
+ else if(strcmp(startup_mode_str, "turn_on_at_system_startup") == 0)
+ return ReplayStartupMode::TURN_ON_AT_SYSTEM_STARTUP;
+ else if(strcmp(startup_mode_str, "turn_on_at_fullscreen") == 0)
+ return ReplayStartupMode::TURN_ON_AT_FULLSCREEN;
+ else if(strcmp(startup_mode_str, "turn_on_at_power_supply_connected") == 0)
+ return ReplayStartupMode::TURN_ON_AT_POWER_SUPPLY_CONNECTED;
+ else
+ return ReplayStartupMode::DONT_TURN_ON_AUTOMATICALLY;
+ }
+
bool ConfigHotkey::operator==(const ConfigHotkey &other) const {
- return keysym == other.keysym && modifiers == other.modifiers;
+ return key == other.key && modifiers == other.modifiers;
}
bool ConfigHotkey::operator!=(const ConfigHotkey &other) const {
return !operator==(other);
}
+ std::string ConfigHotkey::to_string(bool spaces, bool modifier_side) const {
+ std::string result;
+
+ const std::vector<mgl::Keyboard::Key> modifier_keys = hotkey_modifiers_to_mgl_keys(modifiers);
+ std::string modifier_str;
+ for(const mgl::Keyboard::Key modifier_key : modifier_keys) {
+ if(!result.empty()) {
+ if(spaces)
+ result += " + ";
+ else
+ result += "+";
+ }
+
+ modifier_str = mgl::Keyboard::key_to_string(modifier_key);
+ if(!modifier_side) {
+ string_remove_all(modifier_str, "Left ");
+ string_remove_all(modifier_str, "Right ");
+ }
+ result += modifier_str;
+ }
+
+ if(key != 0) {
+ if(!result.empty()) {
+ if(spaces)
+ result += " + ";
+ else
+ result += "+";
+ }
+ result += mgl::Keyboard::key_to_string((mgl::Keyboard::Key)key);
+ }
+
+ return result;
+ }
+
+ bool AudioTrack::operator==(const AudioTrack &other) const {
+ return audio_inputs == other.audio_inputs && application_audio_invert == other.application_audio_invert;
+ }
+
+ bool AudioTrack::operator!=(const AudioTrack &other) const {
+ return !operator==(other);
+ }
+
Config::Config(const SupportedCaptureOptions &capture_options) {
- const std::string default_save_directory = get_videos_dir();
+ const std::string default_videos_save_directory = get_videos_dir();
+ const std::string default_pictures_save_directory = get_pictures_dir();
+
+ set_hotkeys_to_default();
streaming_config.record_options.video_quality = "custom";
- streaming_config.record_options.audio_tracks.push_back("default_output");
- streaming_config.record_options.video_bitrate = 15000;
+ streaming_config.record_options.audio_tracks_list.push_back({std::vector<std::string>{"default_output"}, false});
+ streaming_config.record_options.video_bitrate = 8000;
- record_config.save_directory = default_save_directory;
- record_config.record_options.audio_tracks.push_back("default_output");
- record_config.record_options.video_bitrate = 45000;
+ record_config.save_directory = default_videos_save_directory;
+ record_config.record_options.audio_tracks_list.push_back({std::vector<std::string>{"default_output"}, false});
+ record_config.record_options.video_bitrate = 40000;
replay_config.record_options.video_quality = "custom";
- replay_config.save_directory = default_save_directory;
- replay_config.record_options.audio_tracks.push_back("default_output");
- replay_config.record_options.video_bitrate = 45000;
+ replay_config.save_directory = default_videos_save_directory;
+ replay_config.record_options.audio_tracks_list.push_back({std::vector<std::string>{"default_output"}, false});
+ replay_config.record_options.video_bitrate = 40000;
+
+ screenshot_config.save_directory = default_pictures_save_directory;
if(!capture_options.monitors.empty()) {
- streaming_config.record_options.record_area_option = capture_options.monitors.front().name;
- record_config.record_options.record_area_option = capture_options.monitors.front().name;
- replay_config.record_options.record_area_option = capture_options.monitors.front().name;
+ streaming_config.record_options.record_area_option = "focused_monitor";
+ record_config.record_options.record_area_option = "focused_monitor";
+ replay_config.record_options.record_area_option = "focused_monitor";
+ screenshot_config.record_area_option = "focused_monitor";
}
}
+ void Config::set_hotkeys_to_default() {
+ streaming_config.start_stop_hotkey = {mgl::Keyboard::F8, HOTKEY_MOD_LALT};
+
+ record_config.start_stop_hotkey = {mgl::Keyboard::F9, HOTKEY_MOD_LALT};
+ record_config.pause_unpause_hotkey = {mgl::Keyboard::F7, HOTKEY_MOD_LALT};
+
+ replay_config.start_stop_hotkey = {mgl::Keyboard::F10, HOTKEY_MOD_LALT | HOTKEY_MOD_LSHIFT};
+ replay_config.save_hotkey = {mgl::Keyboard::F10, HOTKEY_MOD_LALT};
+ replay_config.save_1_min_hotkey = {mgl::Keyboard::F11, HOTKEY_MOD_LALT};
+ replay_config.save_10_min_hotkey = {mgl::Keyboard::F12, HOTKEY_MOD_LALT};
+
+ screenshot_config.take_screenshot_hotkey = {mgl::Keyboard::Printscreen, 0};
+ screenshot_config.take_screenshot_region_hotkey = {mgl::Keyboard::Printscreen, HOTKEY_MOD_LCTRL};
+
+ main_config.show_hide_hotkey = {mgl::Keyboard::Z, HOTKEY_MOD_LALT};
+ }
+
static std::optional<KeyValue> parse_key_value(std::string_view line) {
const size_t space_index = line.find(' ');
if(space_index == std::string_view::npos)
@@ -52,14 +164,16 @@ namespace gsr {
return KeyValue{line.substr(0, space_index), line.substr(space_index + 1)};
}
- using ConfigValue = std::variant<bool*, std::string*, int32_t*, ConfigHotkey*, std::vector<std::string>*>;
+ using ConfigValue = std::variant<bool*, std::string*, int32_t*, ConfigHotkey*, std::vector<std::string>*, std::vector<AudioTrack>*>;
static std::map<std::string_view, ConfigValue> get_config_options(Config &config) {
return {
{"main.config_file_version", &config.main_config.config_file_version},
{"main.software_encoding_warning_shown", &config.main_config.software_encoding_warning_shown},
{"main.hotkeys_enable_option", &config.main_config.hotkeys_enable_option},
+ {"main.joystick_hotkeys_enable_option", &config.main_config.joystick_hotkeys_enable_option},
{"main.tint_color", &config.main_config.tint_color},
+ {"main.show_hide_hotkey", &config.main_config.show_hide_hotkey},
{"streaming.record_options.record_area_option", &config.streaming_config.record_options.record_area_option},
{"streaming.record_options.record_area_width", &config.streaming_config.record_options.record_area_width},
@@ -72,6 +186,7 @@ namespace gsr {
{"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_track", &config.streaming_config.record_options.audio_tracks},
+ {"streaming.record_options.audio_track_item", &config.streaming_config.record_options.audio_tracks_list},
{"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},
@@ -86,9 +201,10 @@ namespace gsr {
{"streaming.service", &config.streaming_config.streaming_service},
{"streaming.youtube.key", &config.streaming_config.youtube.stream_key},
{"streaming.twitch.key", &config.streaming_config.twitch.stream_key},
+ {"streaming.rumble.key", &config.streaming_config.rumble.stream_key},
{"streaming.custom.url", &config.streaming_config.custom.url},
{"streaming.custom.container", &config.streaming_config.custom.container},
- {"streaming.start_stop_recording_hotkey", &config.streaming_config.start_stop_recording_hotkey},
+ {"streaming.start_stop_hotkey", &config.streaming_config.start_stop_hotkey},
{"record.record_options.record_area_option", &config.record_config.record_options.record_area_option},
{"record.record_options.record_area_width", &config.record_config.record_options.record_area_width},
@@ -101,6 +217,7 @@ namespace gsr {
{"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_track", &config.record_config.record_options.audio_tracks},
+ {"record.record_options.audio_track_item", &config.record_config.record_options.audio_tracks_list},
{"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},
@@ -113,10 +230,11 @@ namespace gsr {
{"record.save_video_in_game_folder", &config.record_config.save_video_in_game_folder},
{"record.show_recording_started_notifications", &config.record_config.show_recording_started_notifications},
{"record.show_video_saved_notifications", &config.record_config.show_video_saved_notifications},
+ {"record.show_video_paused_notifications", &config.record_config.show_video_paused_notifications},
{"record.save_directory", &config.record_config.save_directory},
{"record.container", &config.record_config.container},
- {"record.start_stop_recording_hotkey", &config.record_config.start_stop_recording_hotkey},
- {"record.pause_unpause_recording_hotkey", &config.record_config.pause_unpause_recording_hotkey},
+ {"record.start_stop_hotkey", &config.record_config.start_stop_hotkey},
+ {"record.pause_unpause_hotkey", &config.record_config.pause_unpause_hotkey},
{"replay.record_options.record_area_option", &config.replay_config.record_options.record_area_option},
{"replay.record_options.record_area_width", &config.replay_config.record_options.record_area_width},
@@ -129,6 +247,7 @@ namespace gsr {
{"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_track", &config.replay_config.record_options.audio_tracks},
+ {"replay.record_options.audio_track_item", &config.replay_config.record_options.audio_tracks_list},
{"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},
@@ -140,14 +259,32 @@ namespace gsr {
{"replay.record_options.restore_portal_session", &config.replay_config.record_options.restore_portal_session},
{"replay.turn_on_replay_automatically_mode", &config.replay_config.turn_on_replay_automatically_mode},
{"replay.save_video_in_game_folder", &config.replay_config.save_video_in_game_folder},
+ {"replay.restart_replay_on_save", &config.replay_config.restart_replay_on_save},
{"replay.show_replay_started_notifications", &config.replay_config.show_replay_started_notifications},
{"replay.show_replay_stopped_notifications", &config.replay_config.show_replay_stopped_notifications},
{"replay.show_replay_saved_notifications", &config.replay_config.show_replay_saved_notifications},
{"replay.save_directory", &config.replay_config.save_directory},
{"replay.container", &config.replay_config.container},
{"replay.time", &config.replay_config.replay_time},
- {"replay.start_stop_recording_hotkey", &config.replay_config.start_stop_recording_hotkey},
- {"replay.save_recording_hotkey", &config.replay_config.save_recording_hotkey}
+ {"replay.replay_storage", &config.replay_config.replay_storage},
+ {"replay.start_stop_hotkey", &config.replay_config.start_stop_hotkey},
+ {"replay.save_hotkey", &config.replay_config.save_hotkey},
+ {"replay.save_1_min_hotkey", &config.replay_config.save_1_min_hotkey},
+ {"replay.save_10_min_hotkey", &config.replay_config.save_10_min_hotkey},
+
+ {"screenshot.record_area_option", &config.screenshot_config.record_area_option},
+ {"screenshot.image_width", &config.screenshot_config.image_width},
+ {"screenshot.image_height", &config.screenshot_config.image_height},
+ {"screenshot.change_image_resolution", &config.screenshot_config.change_image_resolution},
+ {"screenshot.image_quality", &config.screenshot_config.image_quality},
+ {"screenshot.image_format", &config.screenshot_config.image_format},
+ {"screenshot.record_cursor", &config.screenshot_config.record_cursor},
+ {"screenshot.restore_portal_session", &config.screenshot_config.restore_portal_session},
+ {"screenshot.save_screenshot_in_game_folder", &config.screenshot_config.save_screenshot_in_game_folder},
+ {"screenshot.show_screenshot_saved_notifications", &config.screenshot_config.show_screenshot_saved_notifications},
+ {"screenshot.save_directory", &config.screenshot_config.save_directory},
+ {"screenshot.take_screenshot_hotkey", &config.screenshot_config.take_screenshot_hotkey},
+ {"screenshot.take_screenshot_region_hotkey", &config.screenshot_config.take_screenshot_region_hotkey}
};
}
@@ -174,6 +311,11 @@ namespace gsr {
} else if(std::holds_alternative<std::vector<std::string>*>(it.second)) {
if(*std::get<std::vector<std::string>*>(it.second) != *std::get<std::vector<std::string>*>(it_other->second))
return false;
+ } else if(std::holds_alternative<std::vector<AudioTrack>*>(it.second)) {
+ if(*std::get<std::vector<AudioTrack>*>(it.second) != *std::get<std::vector<AudioTrack>*>(it_other->second))
+ return false;
+ } else {
+ assert(false);
}
}
return true;
@@ -183,6 +325,17 @@ namespace gsr {
return !operator==(other);
}
+ static void populate_new_audio_track_from_old(RecordOptions &record_options) {
+ if(record_options.merge_audio_tracks) {
+ record_options.audio_tracks_list.push_back({std::move(record_options.audio_tracks), record_options.application_audio_invert});
+ } else {
+ for(const std::string &audio_input : record_options.audio_tracks) {
+ record_options.audio_tracks_list.push_back({std::vector<std::string>{audio_input}, record_options.application_audio_invert});
+ }
+ }
+ record_options.audio_tracks.clear();
+ }
+
std::optional<Config> read_config(const SupportedCaptureOptions &capture_options) {
std::optional<Config> config;
@@ -194,10 +347,15 @@ namespace gsr {
}
config = Config(capture_options);
+
config->streaming_config.record_options.audio_tracks.clear();
config->record_config.record_options.audio_tracks.clear();
config->replay_config.record_options.audio_tracks.clear();
+ config->streaming_config.record_options.audio_tracks_list.clear();
+ config->record_config.record_options.audio_tracks_list.clear();
+ config->replay_config.record_options.audio_tracks_list.clear();
+
auto config_options = get_config_options(config.value());
string_split_char(file_content, '\n', [&](std::string_view line) {
@@ -228,29 +386,53 @@ namespace gsr {
} else if(std::holds_alternative<ConfigHotkey*>(it->second)) {
std::string value_str(key_value->value);
ConfigHotkey *config_hotkey = std::get<ConfigHotkey*>(it->second);
- if(sscanf(value_str.c_str(), FORMAT_I64 " " FORMAT_U32, &config_hotkey->keysym, &config_hotkey->modifiers) != 2) {
+ if(sscanf(value_str.c_str(), FORMAT_I64 " " FORMAT_U32, &config_hotkey->key, &config_hotkey->modifiers) != 2) {
fprintf(stderr, "Warning: Invalid config option value for %.*s\n", (int)key_value->key.size(), key_value->key.data());
- config_hotkey->keysym = 0;
+ config_hotkey->key = 0;
config_hotkey->modifiers = 0;
}
} else if(std::holds_alternative<std::vector<std::string>*>(it->second)) {
std::string array_value(key_value->value);
std::get<std::vector<std::string>*>(it->second)->push_back(std::move(array_value));
+ } else if(std::holds_alternative<std::vector<AudioTrack>*>(it->second)) {
+ const size_t space_index = key_value->value.find(' ');
+ if(space_index == std::string_view::npos) {
+ fprintf(stderr, "Warning: Invalid config option value for %.*s\n", (int)key_value->key.size(), key_value->key.data());
+ return true;
+ }
+
+ const bool application_audio_invert = key_value->value.substr(0, space_index) == "true";
+ const std::string_view audio_input = key_value->value.substr(space_index + 1);
+ std::vector<AudioTrack> &audio_tracks = *std::get<std::vector<AudioTrack>*>(it->second);
+
+ if(audio_input == add_audio_track_tag) {
+ audio_tracks.push_back({std::vector<std::string>{}, application_audio_invert});
+ } else if(!audio_tracks.empty()) {
+ audio_tracks.back().application_audio_invert = application_audio_invert;
+ audio_tracks.back().audio_inputs.emplace_back(audio_input);
+ }
+ } else {
+ assert(false);
}
return true;
});
- if(config->main_config.config_file_version != CONFIG_FILE_VERSION) {
- fprintf(stderr, "Info: the config file is outdated, resetting it\n");
- config = std::nullopt;
+ if(config->main_config.config_file_version == 1) {
+ populate_new_audio_track_from_old(config->streaming_config.record_options);
+ populate_new_audio_track_from_old(config->record_config.record_options);
+ populate_new_audio_track_from_old(config->replay_config.record_options);
}
+ config->streaming_config.record_options.audio_tracks.clear();
+ config->record_config.record_options.audio_tracks.clear();
+ config->replay_config.record_options.audio_tracks.clear();
+
return config;
}
void save_config(Config &config) {
- config.main_config.config_file_version = CONFIG_FILE_VERSION;
+ config.main_config.config_file_version = GSR_CONFIG_FILE_VERSION;
const std::string config_path = get_config_dir() + "/config_ui";
@@ -279,12 +461,22 @@ namespace gsr {
fprintf(file, "%.*s " FORMAT_I32 "\n", (int)it.first.size(), it.first.data(), *std::get<int32_t*>(it.second));
} else if(std::holds_alternative<ConfigHotkey*>(it.second)) {
const ConfigHotkey *config_hotkey = std::get<ConfigHotkey*>(it.second);
- fprintf(file, "%.*s " FORMAT_I64 " " FORMAT_U32 "\n", (int)it.first.size(), it.first.data(), config_hotkey->keysym, config_hotkey->modifiers);
+ fprintf(file, "%.*s " FORMAT_I64 " " FORMAT_U32 "\n", (int)it.first.size(), it.first.data(), config_hotkey->key, config_hotkey->modifiers);
} else if(std::holds_alternative<std::vector<std::string>*>(it.second)) {
- std::vector<std::string> *array = std::get<std::vector<std::string>*>(it.second);
- for(const std::string &value : *array) {
- fprintf(file, "%.*s %s\n", (int)it.first.size(), it.first.data(), value.c_str());
+ std::vector<std::string> *audio_inputs = std::get<std::vector<std::string>*>(it.second);
+ for(const std::string &audio_input : *audio_inputs) {
+ fprintf(file, "%.*s %s\n", (int)it.first.size(), it.first.data(), audio_input.c_str());
+ }
+ } else if(std::holds_alternative<std::vector<AudioTrack>*>(it.second)) {
+ std::vector<AudioTrack> *audio_tracks = std::get<std::vector<AudioTrack>*>(it.second);
+ for(const AudioTrack &audio_track : *audio_tracks) {
+ fprintf(file, "%.*s %s %.*s\n", (int)it.first.size(), it.first.data(), audio_track.application_audio_invert ? "true" : "false", (int)add_audio_track_tag.size(), add_audio_track_tag.data());
+ for(const std::string &audio_input : audio_track.audio_inputs) {
+ fprintf(file, "%.*s %s %s\n", (int)it.first.size(), it.first.data(), audio_track.application_audio_invert ? "true" : "false", audio_input.c_str());
+ }
}
+ } else {
+ assert(false);
}
}