From 3eb8efc09574f7a49d11cccecc245674b7282fa2 Mon Sep 17 00:00:00 2001 From: Kewlan Date: Thu, 25 Jun 2020 21:05:03 +0200 Subject: Add a "Mute Audio" hotkey --- src/audio_core/stream.cpp | 2 +- src/core/settings.cpp | 7 +++++++ src/core/settings.h | 3 +++ src/yuzu/configuration/config.cpp | 3 ++- src/yuzu/configuration/config.h | 2 +- src/yuzu/main.cpp | 3 +++ 6 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index 4ca98f8ea..ca7cfb030 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -67,7 +67,7 @@ s64 Stream::GetBufferReleaseCycles(const Buffer& buffer) const { } static void VolumeAdjustSamples(std::vector& samples, float game_volume) { - const float volume{std::clamp(Settings::values.volume - (1.0f - game_volume), 0.0f, 1.0f)}; + const float volume{std::clamp(Settings::Volume() - (1.0f - game_volume), 0.0f, 1.0f)}; if (volume == 1.0f) { return; diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 4edff9cd8..56df5e925 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -127,6 +127,13 @@ void LogSettings() { LogSetting("Services_BCATBoxcatLocal", Settings::values.bcat_boxcat_local); } +float Volume() { + if (values.audio_muted) { + return 0.0f; + } + return values.volume; +} + bool IsGPULevelExtreme() { return values.gpu_accuracy == GPUAccuracy::Extreme; } diff --git a/src/core/settings.h b/src/core/settings.h index 33e1e06cd..a598ccbc1 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -459,6 +459,7 @@ struct Values { bool use_dev_keys; // Audio + bool audio_muted; std::string sink_id; bool enable_audio_stretching; std::string audio_device_id; @@ -490,6 +491,8 @@ struct Values { std::map> disabled_addons; } extern values; +float Volume(); + bool IsGPULevelExtreme(); bool IsGPULevelHigh(); diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 32c81dc70..bbbd96113 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -211,7 +211,7 @@ const std::array Config::default // 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 Config::default_hotkeys{{ +const std::array Config::default_hotkeys{{ {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::ApplicationShortcut}}, {QStringLiteral("Change Docked Mode"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::ApplicationShortcut}}, {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, @@ -222,6 +222,7 @@ const std::array Config::default_hotkeys{{ {QStringLiteral("Increase Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("+"), Qt::ApplicationShortcut}}, {QStringLiteral("Load Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::ApplicationShortcut}}, {QStringLiteral("Load File"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+O"), Qt::WindowShortcut}}, + {QStringLiteral("Mute Audio"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}}, {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}}, {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 5cd2a5feb..09316382c 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -27,7 +27,7 @@ public: default_mouse_buttons; static const std::array default_keyboard_keys; static const std::array default_keyboard_mods; - static const std::array default_hotkeys; + static const std::array default_hotkeys; private: void ReadValues(); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 059b96e70..6516f279a 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -736,6 +736,9 @@ void GMainWindow::InitializeHotkeys() { Settings::values.use_docked_mode); dock_status_button->setChecked(Settings::values.use_docked_mode); }); + connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Mute Audio"), this), + &QShortcut::activated, this, + [] { Settings::values.audio_muted = !Settings::values.audio_muted; }); } void GMainWindow::SetDefaultUIGeometry() { -- cgit v1.2.3