Port yuzu-emu/yuzu#4164: "hotkeys: Add a "Mute Audio" hotkey" (#5463)

Co-authored-by: Kewlan <colin_rehn@hotmail.com>
This commit is contained in:
Tobias 2022-11-04 20:25:57 +01:00 committed by GitHub
parent 14924e9db3
commit aa84022704
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 2 deletions

View file

@ -86,7 +86,7 @@ void DspInterface::OutputCallback(s16* buffer, std::size_t num_frames) {
// Implementation of the hardware volume slider // Implementation of the hardware volume slider
// A cubic curve is used to approximate a linear change in human-perceived loudness // 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) { if (linear_volume != 1.0) {
const float volume_scale_factor = linear_volume * linear_volume * linear_volume; const float volume_scale_factor = linear_volume * linear_volume * linear_volume;
for (std::size_t i = 0; i < num_frames; i++) { for (std::size_t i = 0; i < num_frames; i++) {

View file

@ -58,7 +58,7 @@ const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> Config:
// This must be in alphabetical order according to action name as it must have the same order as // 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. // UISetting::values.shortcuts, which is alphabetically ordered.
// clang-format off // clang-format off
const std::array<UISettings::Shortcut, 23> default_hotkeys{ const std::array<UISettings::Shortcut, 24> default_hotkeys{
{{QStringLiteral("Advance Frame"), QStringLiteral("Main Window"), {QStringLiteral("\\"), Qt::ApplicationShortcut}}, {{QStringLiteral("Advance Frame"), QStringLiteral("Main Window"), {QStringLiteral("\\"), Qt::ApplicationShortcut}},
{QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::ApplicationShortcut}}, {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::ApplicationShortcut}},
{QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}},
@ -70,6 +70,7 @@ const std::array<UISettings::Shortcut, 23> default_hotkeys{
{QStringLiteral("Load Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::ApplicationShortcut}}, {QStringLiteral("Load Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::ApplicationShortcut}},
{QStringLiteral("Load File"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+O"), Qt::WindowShortcut}}, {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("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("Remove Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F3"), Qt::ApplicationShortcut}},
{QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}},
{QStringLiteral("Rotate Screens Upright"), QStringLiteral("Main Window"), {QStringLiteral("F8"), Qt::WindowShortcut}}, {QStringLiteral("Rotate Screens Upright"), QStringLiteral("Main Window"), {QStringLiteral("F8"), Qt::WindowShortcut}},

View file

@ -596,6 +596,9 @@ void GMainWindow::InitializeHotkeys() {
&QShortcut::activated, ui->action_Load_from_Newest_Slot, &QAction::trigger); &QShortcut::activated, ui->action_Load_from_Newest_Slot, &QAction::trigger);
connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Save to Oldest Slot"), this), connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Save to Oldest Slot"), this),
&QShortcut::activated, ui->action_Save_to_Oldest_Slot, &QAction::trigger); &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() { void GMainWindow::ShowUpdaterWidgets() {

View file

@ -131,6 +131,13 @@ void LogSettings() {
log_setting("Debugging_GdbstubPort", values.gdbstub_port); log_setting("Debugging_GdbstubPort", values.gdbstub_port);
} }
float Volume() {
if (values.audio_muted) {
return 0.0f;
}
return values.volume;
}
void LoadProfile(int index) { void LoadProfile(int index) {
Settings::values.current_input_profile = Settings::values.input_profiles[index]; Settings::values.current_input_profile = Settings::values.input_profiles[index];
Settings::values.current_input_profile_index = index; Settings::values.current_input_profile_index = index;

View file

@ -210,6 +210,7 @@ struct Values {
bool use_vsync_new; bool use_vsync_new;
// Audio // Audio
bool audio_muted;
bool enable_dsp_lle; bool enable_dsp_lle;
bool enable_dsp_lle_multithread; bool enable_dsp_lle_multithread;
std::string sink_id; std::string sink_id;
@ -244,6 +245,8 @@ struct Values {
u64 audio_bitrate; u64 audio_bitrate;
} extern values; } extern values;
float Volume();
// a special value for Values::region_value indicating that citra will automatically select a region // 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 // value to fit the region lockout info of the game
static constexpr int REGION_VALUE_AUTO_SELECT = -1; static constexpr int REGION_VALUE_AUTO_SELECT = -1;