mirror of https://github.com/PCSX2/pcsx2.git
CommonHotkeys: Add volume control hotkeys
This commit is contained in:
parent
fe1bebc12d
commit
2bc2891c73
|
@ -25,6 +25,7 @@
|
|||
#include "HostDisplay.h"
|
||||
#include "IconsFontAwesome5.h"
|
||||
#include "Recording/InputRecording.h"
|
||||
#include "SPU2/spu2.h"
|
||||
#include "VMManager.h"
|
||||
|
||||
#ifdef ENABLE_ACHIEVEMENTS
|
||||
|
@ -49,6 +50,27 @@ static void HotkeyAdjustTargetSpeed(double delta)
|
|||
fmt::format("Target speed set to {:.0f}%.", std::round(EmuConfig.Framerate.NominalScalar * 100.0)), Host::OSD_QUICK_DURATION);
|
||||
}
|
||||
|
||||
static void HotkeyAdjustVolume(s32 fixed, s32 delta)
|
||||
{
|
||||
if (!VMManager::HasValidVM())
|
||||
return;
|
||||
|
||||
const s32 current_vol = SPU2::GetOutputVolume();
|
||||
const s32 new_volume = std::clamp((fixed >= 0) ? fixed : (current_vol + delta), 0, Pcsx2Config::SPU2Options::MAX_VOLUME);
|
||||
if (current_vol != new_volume)
|
||||
SPU2::SetOutputVolume(new_volume);
|
||||
|
||||
if (new_volume == 0)
|
||||
{
|
||||
Host::AddIconOSDMessage("VolumeChanged", ICON_FA_VOLUME_MUTE, "Volume: Muted");
|
||||
}
|
||||
else
|
||||
{
|
||||
Host::AddIconOSDMessage(
|
||||
"VolumeChanged", (current_vol < new_volume) ? ICON_FA_VOLUME_UP : ICON_FA_VOLUME_DOWN, fmt::format("Volume: {}%", new_volume));
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr s32 CYCLE_SAVE_STATE_SLOTS = 10;
|
||||
|
||||
static void HotkeyCycleSaveSlot(s32 delta)
|
||||
|
@ -170,7 +192,7 @@ DEFINE_HOTKEY("HoldTurbo", "System", "Turbo / Fast Forward (Hold)", [](s32 press
|
|||
{
|
||||
s_limiter_mode_prior_to_hold_interaction = VMManager::GetLimiterMode();
|
||||
VMManager::SetLimiterMode((s_limiter_mode_prior_to_hold_interaction.value() != LimiterModeType::Turbo) ? LimiterModeType::Turbo :
|
||||
LimiterModeType::Nominal);
|
||||
LimiterModeType::Nominal);
|
||||
}
|
||||
else if (pressed >= 0 && s_limiter_mode_prior_to_hold_interaction.has_value())
|
||||
{
|
||||
|
@ -179,13 +201,25 @@ DEFINE_HOTKEY("HoldTurbo", "System", "Turbo / Fast Forward (Hold)", [](s32 press
|
|||
}
|
||||
})
|
||||
DEFINE_HOTKEY("IncreaseSpeed", "System", "Increase Target Speed", [](s32 pressed) {
|
||||
if (!pressed)
|
||||
if (!pressed && VMManager::HasValidVM())
|
||||
HotkeyAdjustTargetSpeed(0.1);
|
||||
})
|
||||
DEFINE_HOTKEY("DecreaseSpeed", "System", "Decrease Target Speed", [](s32 pressed) {
|
||||
if (!pressed)
|
||||
if (!pressed && VMManager::HasValidVM())
|
||||
HotkeyAdjustTargetSpeed(-0.1);
|
||||
})
|
||||
DEFINE_HOTKEY("IncreaseVolume", "System", "Increase Volume", [](s32 pressed) {
|
||||
if (!pressed && VMManager::HasValidVM())
|
||||
HotkeyAdjustVolume(-1, 5);
|
||||
})
|
||||
DEFINE_HOTKEY("DecreaseVolume", "System", "Decrease Volume", [](s32 pressed) {
|
||||
if (!pressed && VMManager::HasValidVM())
|
||||
HotkeyAdjustVolume(-1, -5);
|
||||
})
|
||||
DEFINE_HOTKEY("Mute", "System", "Toggle Mute", [](s32 pressed) {
|
||||
if (!pressed && VMManager::HasValidVM())
|
||||
HotkeyAdjustVolume((SPU2::GetOutputVolume() == 0) ? EmuConfig.SPU2.FinalVolume : 0, 0);
|
||||
})
|
||||
DEFINE_HOTKEY("FrameAdvance", "System", "Frame Advance", [](s32 pressed) {
|
||||
if (!pressed && VMManager::HasValidVM())
|
||||
VMManager::FrameAdvance(1);
|
||||
|
|
|
@ -411,7 +411,7 @@ ImFont* ImGuiManager::AddFixedFont(float size)
|
|||
bool ImGuiManager::AddIconFonts(float size)
|
||||
{
|
||||
// clang-format off
|
||||
static constexpr ImWchar range_fa[] = { 0xf001,0xf002,0xf005,0xf005,0xf007,0xf007,0xf00c,0xf00e,0xf011,0xf011,0xf013,0xf013,0xf017,0xf017,0xf019,0xf019,0xf01c,0xf01c,0xf021,0xf021,0xf023,0xf023,0xf025,0xf025,0xf028,0xf028,0xf02d,0xf02e,0xf030,0xf030,0xf03a,0xf03a,0xf03d,0xf03d,0xf04a,0xf04c,0xf04e,0xf04e,0xf050,0xf050,0xf052,0xf052,0xf059,0xf059,0xf05e,0xf05e,0xf065,0xf065,0xf067,0xf067,0xf06a,0xf06a,0xf071,0xf071,0xf077,0xf078,0xf07b,0xf07c,0xf084,0xf085,0xf091,0xf091,0xf0ac,0xf0ad,0xf0b0,0xf0b0,0xf0c5,0xf0c5,0xf0c7,0xf0c9,0xf0cb,0xf0cb,0xf0d0,0xf0d0,0xf0dc,0xf0dc,0xf0e2,0xf0e2,0xf0eb,0xf0eb,0xf0f1,0xf0f1,0xf0f3,0xf0f3,0xf0fe,0xf0fe,0xf110,0xf110,0xf119,0xf119,0xf11b,0xf11c,0xf121,0xf121,0xf133,0xf133,0xf140,0xf140,0xf144,0xf144,0xf14a,0xf14a,0xf15b,0xf15b,0xf15d,0xf15d,0xf188,0xf188,0xf191,0xf192,0xf1c9,0xf1c9,0xf1dd,0xf1de,0xf1e6,0xf1e6,0xf1ea,0xf1eb,0xf1f8,0xf1f8,0xf1fc,0xf1fc,0xf242,0xf242,0xf245,0xf245,0xf26c,0xf26c,0xf279,0xf279,0xf2d0,0xf2d0,0xf2db,0xf2db,0xf2f2,0xf2f2,0xf2f5,0xf2f5,0xf302,0xf302,0xf3c1,0xf3c1,0xf3fd,0xf3fd,0xf410,0xf410,0xf466,0xf466,0xf479,0xf479,0xf500,0xf500,0xf517,0xf517,0xf51f,0xf51f,0xf543,0xf543,0xf545,0xf545,0xf547,0xf548,0xf552,0xf552,0xf5a2,0xf5a2,0xf65d,0xf65e,0xf6a9,0xf6a9,0xf756,0xf756,0xf7c2,0xf7c2,0xf807,0xf807,0xf815,0xf815,0xf818,0xf818,0xf84c,0xf84c,0xf8cc,0xf8cc,0xf8d9,0xf8d9,0x0,0x0 };
|
||||
static constexpr ImWchar range_fa[] = { 0xf001,0xf002,0xf005,0xf005,0xf007,0xf007,0xf00c,0xf00e,0xf011,0xf011,0xf013,0xf013,0xf017,0xf017,0xf019,0xf019,0xf01c,0xf01c,0xf021,0xf021,0xf023,0xf023,0xf025,0xf025,0xf027,0xf028,0xf02d,0xf02e,0xf030,0xf030,0xf03a,0xf03a,0xf03d,0xf03d,0xf04a,0xf04c,0xf04e,0xf04e,0xf050,0xf050,0xf052,0xf052,0xf059,0xf059,0xf05e,0xf05e,0xf065,0xf065,0xf067,0xf067,0xf06a,0xf06a,0xf071,0xf071,0xf077,0xf078,0xf07b,0xf07c,0xf084,0xf085,0xf091,0xf091,0xf0ac,0xf0ad,0xf0b0,0xf0b0,0xf0c5,0xf0c5,0xf0c7,0xf0c9,0xf0cb,0xf0cb,0xf0d0,0xf0d0,0xf0dc,0xf0dc,0xf0e2,0xf0e2,0xf0eb,0xf0eb,0xf0f1,0xf0f1,0xf0f3,0xf0f3,0xf0fe,0xf0fe,0xf110,0xf110,0xf119,0xf119,0xf11b,0xf11c,0xf121,0xf121,0xf133,0xf133,0xf140,0xf140,0xf144,0xf144,0xf14a,0xf14a,0xf15b,0xf15b,0xf15d,0xf15d,0xf188,0xf188,0xf191,0xf192,0xf1c9,0xf1c9,0xf1dd,0xf1de,0xf1e6,0xf1e6,0xf1ea,0xf1eb,0xf1f8,0xf1f8,0xf1fc,0xf1fc,0xf242,0xf242,0xf245,0xf245,0xf26c,0xf26c,0xf279,0xf279,0xf2d0,0xf2d0,0xf2db,0xf2db,0xf2f2,0xf2f2,0xf2f5,0xf2f5,0xf302,0xf302,0xf3c1,0xf3c1,0xf3fd,0xf3fd,0xf410,0xf410,0xf466,0xf466,0xf479,0xf479,0xf500,0xf500,0xf517,0xf517,0xf51f,0xf51f,0xf543,0xf543,0xf545,0xf545,0xf547,0xf548,0xf552,0xf552,0xf5a2,0xf5a2,0xf65d,0xf65e,0xf6a9,0xf6a9,0xf756,0xf756,0xf7c2,0xf7c2,0xf807,0xf807,0xf815,0xf815,0xf818,0xf818,0xf84c,0xf84c,0xf8cc,0xf8cc,0xf8d9,0xf8d9,0x0,0x0 };
|
||||
// clang-format on
|
||||
|
||||
ImFontConfig cfg;
|
||||
|
|
|
@ -861,6 +861,11 @@ __forceinline
|
|||
}
|
||||
}
|
||||
|
||||
s32 SPU2::GetOutputVolume()
|
||||
{
|
||||
return static_cast<s32>(std::round(FinalVolume * 100.0f));
|
||||
}
|
||||
|
||||
void SPU2::SetOutputVolume(s32 volume)
|
||||
{
|
||||
FinalVolume = static_cast<float>(std::clamp<s32>(volume, 0, Pcsx2Config::SPU2Options::MAX_VOLUME)) / 100.0f;
|
||||
|
|
|
@ -37,6 +37,9 @@ void Reset(bool psxmode);
|
|||
/// Identifies any configuration changes and applies them.
|
||||
void CheckForConfigChanges(const Pcsx2Config& old_config);
|
||||
|
||||
/// Returns the current output volume, irrespective of the configuration.
|
||||
s32 GetOutputVolume();
|
||||
|
||||
/// Directly updates the output volume without going through the configuration.
|
||||
void SetOutputVolume(s32 volume);
|
||||
|
||||
|
|
Loading…
Reference in New Issue