Skip to content

VERY experimental Nintendo Switch 2 emulator

C++

[desktop] fix audio output engine not saving (#3083)

crueter027085e5ba1c
diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h
index a7e6bb6168..9af2cebde0 100644
--- a/src/common/settings_setting.h
+++ b/src/common/settings_setting.h
@@ -129,7 +129,7 @@ protected:
} else if constexpr (std::is_floating_point_v<Type>) {
return fmt::format("{:f}", value_);
} else if constexpr (std::is_enum_v<Type>) {
- return std::to_string(static_cast<u32>(value_));
+ return std::to_string(u32(value_));
} else {
return std::to_string(value_);
}
@@ -192,15 +192,13 @@ public:
if constexpr (std::is_same_v<Type, std::string>) {
this->SetValue(input);
} else if constexpr (std::is_same_v<Type, std::optional<u32>>) {
- this->SetValue(static_cast<u32>(std::stoul(input)));
+ this->SetValue(u32(std::stoul(input)));
} else if constexpr (std::is_same_v<Type, bool>) {
this->SetValue(input == "true");
} else if constexpr (std::is_same_v<Type, float>) {
this->SetValue(std::stof(input));
- } else if constexpr (std::is_same_v<Type, AudioEngine>) {
- this->SetValue(ToEnum<AudioEngine>(input));
} else {
- this->SetValue(static_cast<Type>(std::stoll(input)));
+ this->SetValue(Type(std::stoll(input)));
}
} catch (std::invalid_argument&) {
this->SetValue(this->GetDefault());
diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp
index fa1383436e..eec169aa14 100644
--- a/src/frontend_common/config.cpp
+++ b/src/frontend_common/config.cpp
@@ -1,3 +1,6 @@
+// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -10,14 +13,14 @@
#include "common/settings_common.h"
#include "common/settings_enums.h"
#include "config.h"
-#include "core/core.h"
-#include "core/hle/service/acc/profile_manager.h"
-#include "hid_core/resources/npad/npad.h"
-#include "network/network.h"
+
+#ifdef _WIN32
+#include "common/string_util.h"
+#endif
#include <boost/algorithm/string/replace.hpp>
-#include "common/string_util.h"
+#include "common/assert.h"
namespace FS = Common::FS;
@@ -145,9 +148,9 @@ void Config::ReadPlayerValues(const std::size_t player_index) {
}
if (player_prefix.empty() && Settings::IsConfiguringGlobal()) {
- const auto controller = static_cast<Settings::ControllerType>(
+ const auto controller = Settings::ControllerType(
ReadIntegerSetting(std::string(player_prefix).append("type"),
- static_cast<u8>(Settings::ControllerType::ProController)));
+ u8(Settings::ControllerType::ProController)));
if (controller == Settings::ControllerType::LeftJoycon ||
controller == Settings::ControllerType::RightJoycon) {
@@ -162,26 +165,26 @@ void Config::ReadPlayerValues(const std::size_t player_index) {
player.connected = ReadBooleanSetting(connected_key.append("connected"),
std::make_optional(player_index == 0));
- player.controller_type = static_cast<Settings::ControllerType>(
+ player.controller_type = Settings::ControllerType(
ReadIntegerSetting(std::string(player_prefix).append("type"),
- static_cast<u8>(Settings::ControllerType::ProController)));
+ u8(Settings::ControllerType::ProController)));
player.vibration_enabled = ReadBooleanSetting(
std::string(player_prefix).append("vibration_enabled"), std::make_optional(true));
- player.vibration_strength = static_cast<int>(
- ReadIntegerSetting(std::string(player_prefix).append("vibration_strength"), 100));
+ player.vibration_strength =
+ int(ReadIntegerSetting(std::string(player_prefix).append("vibration_strength"), 100));
- player.body_color_left = static_cast<u32>(ReadIntegerSetting(
+ player.body_color_left = u32(ReadIntegerSetting(
std::string(player_prefix).append("body_color_left"), Settings::JOYCON_BODY_NEON_BLUE));
- player.body_color_right = static_cast<u32>(ReadIntegerSetting(
+ player.body_color_right = u32(ReadIntegerSetting(
std::string(player_prefix).append("body_color_right"), Settings::JOYCON_BODY_NEON_RED));
- player.button_color_left = static_cast<u32>(
- ReadIntegerSetting(std::string(player_prefix).append("button_color_left"),
- Settings::JOYCON_BUTTONS_NEON_BLUE));
- player.button_color_right = static_cast<u32>(
- ReadIntegerSetting(std::string(player_prefix).append("button_color_right"),
- Settings::JOYCON_BUTTONS_NEON_RED));
+ player.button_color_left =
+ u32(ReadIntegerSetting(std::string(player_prefix).append("button_color_left"),
+ Settings::JOYCON_BUTTONS_NEON_BLUE));
+ player.button_color_right =
+ u32(ReadIntegerSetting(std::string(player_prefix).append("button_color_right"),
+ Settings::JOYCON_BUTTONS_NEON_RED));
}
}
@@ -189,11 +192,11 @@ void Config::ReadTouchscreenValues() {
Settings::values.touchscreen.enabled =
ReadBooleanSetting(std::string("touchscreen_enabled"), std::make_optional(true));
Settings::values.touchscreen.rotation_angle =
- static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_angle"), 0));
+ u32(ReadIntegerSetting(std::string("touchscreen_angle"), 0));
Settings::values.touchscreen.diameter_x =
- static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_x"), 90));
+ u32(ReadIntegerSetting(std::string("touchscreen_diameter_x"), 90));
Settings::values.touchscreen.diameter_y =
- static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_y"), 90));
+ u32(ReadIntegerSetting(std::string("touchscreen_diameter_y"), 90));
}
void Config::ReadAudioValues() {
@@ -275,11 +278,17 @@ void Config::ReadCoreValues() {
void Config::ReadDataStorageValues() {
BeginGroup(Settings::TranslateCategory(Settings::Category::DataStorage));
- FS::SetEdenPath(FS::EdenPath::NANDDir, ReadStringSetting(std::string("nand_directory")));
- FS::SetEdenPath(FS::EdenPath::SDMCDir, ReadStringSetting(std::string("sdmc_directory")));
- FS::SetEdenPath(FS::EdenPath::LoadDir, ReadStringSetting(std::string("load_directory")));
- FS::SetEdenPath(FS::EdenPath::DumpDir, ReadStringSetting(std::string("dump_directory")));
- FS::SetEdenPath(FS::EdenPath::TASDir, ReadStringSetting(std::string("tas_directory")));
+ using namespace Common::FS;
+
+ const auto setPath = [this](const EdenPath& path, const char* setting) {
+ SetEdenPath(path, ReadStringSetting(std::string(setting)));
+ };
+
+ setPath(EdenPath::NANDDir, "nand_directory");
+ setPath(EdenPath::SDMCDir, "sdmc_directory");
+ setPath(EdenPath::LoadDir, "load_directory");
+ setPath(EdenPath::DumpDir, "dump_directory");
+ setPath(EdenPath::TASDir, "tas_directory");
ReadCategory(Settings::Category::DataStorage);
@@ -449,9 +458,8 @@ void Config::SavePlayerValues(const std::size_t player_index) {
std::make_optional(std::string("")));
}
- WriteIntegerSetting(
- std::string(player_prefix).append("type"), static_cast<u8>(player.controller_type),
- std::make_optional(static_cast<u8>(Settings::ControllerType::ProController)));
+ WriteIntegerSetting(std::string(player_prefix).append("type"), u8(player.controller_type),
+ std::make_optional(u8(Settings::ControllerType::ProController)));
if (!player_prefix.empty() || !Settings::IsConfiguringGlobal()) {
if (global) {
@@ -487,24 +495,24 @@ void Config::SaveTouchscreenValues() {
std::make_optional(true));
WriteIntegerSetting(std::string("touchscreen_angle"), touchscreen.rotation_angle,
- std::make_optional(static_cast<u32>(0)));
+ std::make_optional(u32(0)));
WriteIntegerSetting(std::string("touchscreen_diameter_x"), touchscreen.diameter_x,
- std::make_optional(static_cast<u32>(90)));
+ std::make_optional(u32(90)));
WriteIntegerSetting(std::string("touchscreen_diameter_y"), touchscreen.diameter_y,
- std::make_optional(static_cast<u32>(90)));
+ std::make_optional(u32(90)));
}
void Config::SaveMotionTouchValues() {
BeginArray(std::string("touch_from_button_maps"));
for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) {
- SetArrayIndex(static_cast<int>(p));
+ SetArrayIndex(int(p));
WriteStringSetting(std::string("name"), Settings::values.touch_from_button_maps[p].name,
std::make_optional(std::string("default")));
BeginArray(std::string("entries"));
for (std::size_t q = 0; q < Settings::values.touch_from_button_maps[p].buttons.size();
++q) {
- SetArrayIndex(static_cast<int>(q));
+ SetArrayIndex(int(q));
WriteStringSetting(std::string("bind"),
Settings::values.touch_from_button_maps[p].buttons[q]);
}
@@ -578,16 +586,18 @@ void Config::SaveCoreValues() {
void Config::SaveDataStorageValues() {
BeginGroup(Settings::TranslateCategory(Settings::Category::DataStorage));
- WriteStringSetting(std::string("nand_directory"), FS::GetEdenPathString(FS::EdenPath::NANDDir),
- std::make_optional(FS::GetEdenPathString(FS::EdenPath::NANDDir)));
- WriteStringSetting(std::string("sdmc_directory"), FS::GetEdenPathString(FS::EdenPath::SDMCDir),
- std::make_optional(FS::GetEdenPathString(FS::EdenPath::SDMCDir)));
- WriteStringSetting(std::string("load_directory"), FS::GetEdenPathString(FS::EdenPath::LoadDir),
- std::make_optional(FS::GetEdenPathString(FS::EdenPath::LoadDir)));
- WriteStringSetting(std::string("dump_directory"), FS::GetEdenPathString(FS::EdenPath::DumpDir),
- std::make_optional(FS::GetEdenPathString(FS::EdenPath::DumpDir)));
- WriteStringSetting(std::string("tas_directory"), FS::GetEdenPathString(FS::EdenPath::TASDir),
- std::make_optional(FS::GetEdenPathString(FS::EdenPath::TASDir)));
+ using namespace Common::FS;
+
+ const auto writePath = [this](const char* setting, const EdenPath& path) {
+ WriteStringSetting(std::string(setting), FS::GetEdenPathString(path),
+ std::make_optional(FS::GetEdenPathString(path)));
+ };
+
+ writePath("nand_directory", EdenPath::NANDDir);
+ writePath("sdmc_directory", EdenPath::SDMCDir);
+ writePath("load_directory", EdenPath::LoadDir);
+ writePath("dump_directory", EdenPath::DumpDir);
+ writePath("tas_directory", EdenPath::TASDir);
WriteCategory(Settings::Category::DataStorage);
@@ -632,11 +642,10 @@ void Config::SaveDisabledAddOnValues() {
BeginArray(std::string(""));
for (const auto& elem : Settings::values.disabled_addons) {
SetArrayIndex(i);
- WriteIntegerSetting(std::string("title_id"), elem.first,
- std::make_optional(static_cast<u64>(0)));
+ WriteIntegerSetting(std::string("title_id"), elem.first, std::make_optional(u64(0)));
BeginArray(std::string("disabled"));
for (std::size_t j = 0; j < elem.second.size(); ++j) {
- SetArrayIndex(static_cast<int>(j));
+ SetArrayIndex(int(j));
WriteStringSetting(std::string("d"), elem.second[j],
std::make_optional(std::string("")));
}
@@ -720,10 +729,10 @@ bool Config::ReadBooleanSetting(const std::string& key, const std::optional<bool
if (config->GetBoolValue(GetSection().c_str(),
std::string(full_key).append("\\default").c_str(), false)) {
- return static_cast<bool>(default_value.value());
+ return bool(default_value.value());
} else {
return config->GetBoolValue(GetSection().c_str(), full_key.c_str(),
- static_cast<bool>(default_value.value()));
+ bool(default_value.value()));
}
}
@@ -926,8 +935,7 @@ void Config::ReadSettingGeneric(Settings::BasicSetting* const setting) {
const bool is_default =
ReadBooleanSetting(std::string(key).append("\\default"), std::make_optional(true));
if (!is_default) {
- const std::string setting_string = ReadStringSetting(key, default_value);
- setting->LoadString(setting_string);
+ setting->LoadString(ReadStringSetting(key, default_value));
} else {
// Empty string resets the Setting to default
setting->LoadString("");
diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp
index 9d21759240..10eacf39cb 100644
--- a/src/yuzu/configuration/configure_audio.cpp
+++ b/src/yuzu/configuration/configure_audio.cpp
@@ -186,16 +186,23 @@ void ConfigureAudio::SetConfiguration() {
void ConfigureAudio::SetOutputSinkFromSinkID() {
[[maybe_unused]] const QSignalBlocker blocker(sink_combo_box);
- int new_sink_index = 0;
- const QString sink_id = QString::fromStdString(Settings::values.sink_id.ToString());
- for (int index = 0; index < sink_combo_box->count(); index++) {
- if (sink_combo_box->itemText(index) == sink_id) {
- new_sink_index = index;
- break;
+ const std::string new_sink_id = []() -> const std::string {
+ const Settings::AudioEngine sink_id = Settings::values.sink_id.GetValue();
+ const auto canonicalizations
+ = Settings::EnumMetadata<Settings::AudioEngine>::Canonicalizations();
+
+ for (u32 i = 0; i < canonicalizations.size(); ++i) {
+ const Settings::AudioEngine value = canonicalizations[i].second;
+ const std::string_view key = canonicalizations[i].first;
+
+ if (sink_id == value)
+ return std::string(key);
}
- }
- sink_combo_box->setCurrentIndex(new_sink_index);
+ return std::string("null");
+ }();
+
+ sink_combo_box->setCurrentText(QString::fromStdString(new_sink_id));
}
void ConfigureAudio::SetOutputDevicesFromDeviceID() {
@@ -233,8 +240,20 @@ void ConfigureAudio::ApplyConfiguration() {
apply_func(is_powered_on);
}
- Settings::values.sink_id.LoadString(
- sink_combo_box->itemText(sink_combo_box->currentIndex()).toStdString());
+ const u32 new_sink_id = [this]() {
+ const std::string sink_id = sink_combo_box->currentText().toStdString();
+ const auto canonicalizations
+ = Settings::EnumMetadata<Settings::AudioEngine>::Canonicalizations();
+
+ for (u32 i = 0; i < canonicalizations.size(); ++i) {
+ if (sink_id == canonicalizations[i].first)
+ return i;
+ }
+
+ return u32(0);
+ }();
+
+ Settings::values.sink_id.SetValue(Settings::AudioEngine(new_sink_id));
Settings::values.audio_output_device_id.SetValue(
output_device_combo_box->itemText(output_device_combo_box->currentIndex()).toStdString());
Settings::values.audio_input_device_id.SetValue(