From 6477e5fb54aa0f74894f0a3863e35fec4cdd01b0 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 10 May 2020 00:54:23 +1000 Subject: [PATCH] CommonHostInterface: Add volume up/down/mute hotkeys --- src/frontend-common/common_host_interface.cpp | 35 +++++++++++++++++++ src/frontend-common/common_host_interface.h | 1 + 2 files changed, 36 insertions(+) diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index b27f6d20b..7ac9b0e22 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -40,6 +40,7 @@ bool CommonHostInterface::Initialize() RegisterGeneralHotkeys(); RegisterGraphicsHotkeys(); RegisterSaveStateHotkeys(); + RegisterAudioHotkeys(); m_controller_interface = CreateControllerInterface(); if (m_controller_interface && !m_controller_interface->Initialize(this)) @@ -909,6 +910,40 @@ void CommonHostInterface::RegisterSaveStateHotkeys() } } +void CommonHostInterface::RegisterAudioHotkeys() +{ + RegisterHotkey(StaticString("Audio"), StaticString("AudioMute"), StaticString("Toggle Mute"), [this](bool pressed) { + if (m_system && !pressed) + { + m_settings.audio_output_muted = !m_settings.audio_output_muted; + m_audio_stream->SetOutputVolume(m_settings.audio_output_muted ? 0 : m_settings.audio_output_volume); + if (m_settings.audio_output_muted) + AddOSDMessage("Volume: Muted", 2.0f); + else + AddFormattedOSDMessage(2.0f, "Volume: %d%%", m_settings.audio_output_volume); + } + }); + RegisterHotkey(StaticString("Audio"), StaticString("AudioVolumeUp"), StaticString("Volume Up"), [this](bool pressed) { + if (m_system && pressed) + { + m_settings.audio_output_volume = std::min(m_settings.audio_output_volume + 10, 100); + m_settings.audio_output_muted = false; + m_audio_stream->SetOutputVolume(m_settings.audio_output_volume); + AddFormattedOSDMessage(2.0f, "Volume: %d%%", m_settings.audio_output_volume); + } + }); + RegisterHotkey(StaticString("Audio"), StaticString("AudioVolumeDown"), StaticString("Volume Down"), + [this](bool pressed) { + if (m_system && pressed) + { + m_settings.audio_output_volume = std::max(m_settings.audio_output_volume - 10, 0); + m_settings.audio_output_muted = false; + m_audio_stream->SetOutputVolume(m_settings.audio_output_volume); + AddFormattedOSDMessage(2.0f, "Volume: %d%%", m_settings.audio_output_volume); + } + }); +} + std::string CommonHostInterface::GetPathForInputProfile(const char* name) const { return GetUserDirectoryRelativePath("inputprofiles/%s.ini", name); diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index f93e37ac6..e482a5996 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -124,6 +124,7 @@ private: void RegisterGeneralHotkeys(); void RegisterGraphicsHotkeys(); void RegisterSaveStateHotkeys(); + void RegisterAudioHotkeys(); void UpdateControllerInputMap(SettingsInterface& si); void UpdateHotkeyInputMap(SettingsInterface& si); void ClearAllControllerBindings(SettingsInterface& si);