From aa84022704c61ea48546d39b4f99b9e72ffb6692 Mon Sep 17 00:00:00 2001 From: Tobias Date: Fri, 4 Nov 2022 20:25:57 +0100 Subject: [PATCH] Port yuzu-emu/yuzu#4164: "hotkeys: Add a "Mute Audio" hotkey" (#5463) Co-authored-by: Kewlan --- src/audio_core/dsp_interface.cpp | 2 +- src/citra_qt/configuration/config.cpp | 3 ++- src/citra_qt/main.cpp | 3 +++ src/core/settings.cpp | 7 +++++++ src/core/settings.h | 3 +++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/audio_core/dsp_interface.cpp b/src/audio_core/dsp_interface.cpp index 00c8dd65d..74ab37f54 100644 --- a/src/audio_core/dsp_interface.cpp +++ b/src/audio_core/dsp_interface.cpp @@ -86,7 +86,7 @@ void DspInterface::OutputCallback(s16* buffer, std::size_t num_frames) { // Implementation of the hardware volume slider // A cubic curve is used to approximate a linear change in human-perceived loudness - const float linear_volume = std::clamp(Settings::values.volume, 0.0f, 1.0f); + const float linear_volume = std::clamp(Settings::Volume(), 0.0f, 1.0f); if (linear_volume != 1.0) { const float volume_scale_factor = linear_volume * linear_volume * linear_volume; for (std::size_t i = 0; i < num_frames; i++) { diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index b4dcd4759..52dc5c852 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -58,7 +58,7 @@ const std::array, Settings::NativeAnalog::NumAnalogs> Config: // This must be in alphabetical order according to action name as it must have the same order as // UISetting::values.shortcuts, which is alphabetically ordered. // clang-format off -const std::array default_hotkeys{ +const std::array default_hotkeys{ {{QStringLiteral("Advance Frame"), QStringLiteral("Main Window"), {QStringLiteral("\\"), Qt::ApplicationShortcut}}, {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::ApplicationShortcut}}, {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, @@ -70,6 +70,7 @@ const std::array default_hotkeys{ {QStringLiteral("Load Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::ApplicationShortcut}}, {QStringLiteral("Load File"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+O"), Qt::WindowShortcut}}, {QStringLiteral("Load from Newest Slot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+V"), Qt::WindowShortcut}}, + {QStringLiteral("Mute Audio"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}}, {QStringLiteral("Remove Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F3"), Qt::ApplicationShortcut}}, {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, {QStringLiteral("Rotate Screens Upright"), QStringLiteral("Main Window"), {QStringLiteral("F8"), Qt::WindowShortcut}}, diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index b10003dbd..637937a06 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -596,6 +596,9 @@ void GMainWindow::InitializeHotkeys() { &QShortcut::activated, ui->action_Load_from_Newest_Slot, &QAction::trigger); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Save to Oldest Slot"), this), &QShortcut::activated, ui->action_Save_to_Oldest_Slot, &QAction::trigger); + connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Mute Audio"), this), + &QShortcut::activated, this, + [] { Settings::values.audio_muted = !Settings::values.audio_muted; }); } void GMainWindow::ShowUpdaterWidgets() { diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 3a26e7217..913dd01ed 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -131,6 +131,13 @@ void LogSettings() { log_setting("Debugging_GdbstubPort", values.gdbstub_port); } +float Volume() { + if (values.audio_muted) { + return 0.0f; + } + return values.volume; +} + void LoadProfile(int index) { Settings::values.current_input_profile = Settings::values.input_profiles[index]; Settings::values.current_input_profile_index = index; diff --git a/src/core/settings.h b/src/core/settings.h index b7d35e070..518f1a8eb 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -210,6 +210,7 @@ struct Values { bool use_vsync_new; // Audio + bool audio_muted; bool enable_dsp_lle; bool enable_dsp_lle_multithread; std::string sink_id; @@ -244,6 +245,8 @@ struct Values { u64 audio_bitrate; } extern values; +float Volume(); + // a special value for Values::region_value indicating that citra will automatically select a region // value to fit the region lockout info of the game static constexpr int REGION_VALUE_AUTO_SELECT = -1;