diff --git a/EarTrumpet/App.xaml.cs b/EarTrumpet/App.xaml.cs index ee4a2952b..3fdc6035f 100644 --- a/EarTrumpet/App.xaml.cs +++ b/EarTrumpet/App.xaml.cs @@ -189,7 +189,8 @@ private void TrayIconScrolled(object _, int wheelDelta) if (Settings.UseScrollWheelInTray && (!Settings.UseGlobalMouseWheelHook || _flyoutViewModel.State == FlyoutViewState.Hidden)) { CollectionViewModel.Default?.IncrementVolume( - Math.Sign(wheelDelta) * (Settings.UseLogarithmicVolume ? 0.2f : 2.0f)); + Math.Sign(wheelDelta) * + (Settings.UseLogarithmicVolume ? Settings.ScrollWheelOrHotkeyVolumeChangeDb : Settings.ScrollWheelOrHotkeyVolumeChangePercent)); } } @@ -411,7 +412,7 @@ private void AbsoluteVolumeIncrement() foreach (var device in CollectionViewModel.AllDevices.Where(d => !d.IsMuted || d.IsAbsMuted)) { device.IsAbsMuted = false; - device.IncrementVolume(2); + device.Volume += Settings.UseLogarithmicVolume ? Settings.ScrollWheelOrHotkeyVolumeChangeDb : Settings.ScrollWheelOrHotkeyVolumeChangePercent; } } @@ -419,10 +420,9 @@ private void AbsoluteVolumeDecrement() { foreach (var device in CollectionViewModel.AllDevices.Where(d => !d.IsMuted)) { - var wasMuted = device.IsMuted; - device.Volume -= 2; + device.Volume -= Settings.UseLogarithmicVolume ? Settings.ScrollWheelOrHotkeyVolumeChangeDb : Settings.ScrollWheelOrHotkeyVolumeChangePercent; - if (!wasMuted == (device.Volume <= 0)) + if (device.Volume <= (Settings.UseLogarithmicVolume ? Settings.LogarithmicVolumeMinDb : 0.0f)) { device.IsAbsMuted = true; } diff --git a/EarTrumpet/AppSettings.cs b/EarTrumpet/AppSettings.cs index 310cad2d5..c46e09045 100644 --- a/EarTrumpet/AppSettings.cs +++ b/EarTrumpet/AppSettings.cs @@ -140,6 +140,18 @@ public bool UseScrollWheelInTray set => _settings.Set("UseScrollWheelInTray", value); } + public int ScrollWheelOrHotkeyVolumeChangePercent + { + get => _settings.Get("ScrollWheelOrHotkeyVolumeChangePercent", 2); + set => _settings.Set("ScrollWheelOrHotkeyVolumeChangePercent", value); + } + + public float ScrollWheelOrHotkeyVolumeChangeDb + { + get => _settings.Get("ScrollWheelOrHotkeyVolumeChangeDb", 0.5f); + set => _settings.Set("ScrollWheelOrHotkeyVolumeChangeDb", value); + } + public bool UseGlobalMouseWheelHook { get => _settings.Get("UseGlobalMouseWheelHook", false); diff --git a/EarTrumpet/Properties/Resources.resx b/EarTrumpet/Properties/Resources.resx index 97f1fb8d9..9638f25d3 100644 --- a/EarTrumpet/Properties/Resources.resx +++ b/EarTrumpet/Properties/Resources.resx @@ -685,4 +685,7 @@ Open [https://eartrumpet.app/jmp/fixstartup] to resolve this? dB + + Volume change amount for each wheel scroll or hotkey press + \ No newline at end of file diff --git a/EarTrumpet/Properties/Resources.zh-CN.resx b/EarTrumpet/Properties/Resources.zh-CN.resx index b961f09f2..258f601a3 100644 --- a/EarTrumpet/Properties/Resources.zh-CN.resx +++ b/EarTrumpet/Properties/Resources.zh-CN.resx @@ -679,4 +679,7 @@ 对数音量刻度最小值 + + 滚动滚轮或按下快捷键时的音量变化幅度 + \ No newline at end of file diff --git a/EarTrumpet/UI/Controls/VolumeSlider.cs b/EarTrumpet/UI/Controls/VolumeSlider.cs index 2f5cf5efc..c678cc55b 100644 --- a/EarTrumpet/UI/Controls/VolumeSlider.cs +++ b/EarTrumpet/UI/Controls/VolumeSlider.cs @@ -202,7 +202,8 @@ private void OnMouseMove(object sender, MouseEventArgs e) private void OnMouseWheel(object sender, MouseWheelEventArgs e) { - var amount = Math.Sign(e.Delta) * (App.Settings.UseLogarithmicVolume ? 0.2 : 2.0); + var amount = Math.Sign(e.Delta) * + (App.Settings.UseLogarithmicVolume ? App.Settings.ScrollWheelOrHotkeyVolumeChangeDb : App.Settings.ScrollWheelOrHotkeyVolumeChangePercent); ChangePositionByAmount(amount); e.Handled = true; } diff --git a/EarTrumpet/UI/Converters/NegateConverter.cs b/EarTrumpet/UI/Converters/NegateConverter.cs index 128f7ace8..fdb6235f1 100644 --- a/EarTrumpet/UI/Converters/NegateConverter.cs +++ b/EarTrumpet/UI/Converters/NegateConverter.cs @@ -7,6 +7,7 @@ public class NegateConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { + if (value is bool b) return !b; if (value is double d) return -d; if (value is float f) return (double)-f; if (value is int i) return (double)-i; @@ -15,6 +16,7 @@ public object Convert(object value, Type targetType, object parameter, System.Gl public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { + if (value is bool b) return !b; if (value is double d) return -d; throw new InvalidOperationException(); } diff --git a/EarTrumpet/UI/ViewModels/EarTrumpetCommunitySettingsPageViewModel.cs b/EarTrumpet/UI/ViewModels/EarTrumpetCommunitySettingsPageViewModel.cs index 0abba004a..caeb9afc6 100644 --- a/EarTrumpet/UI/ViewModels/EarTrumpetCommunitySettingsPageViewModel.cs +++ b/EarTrumpet/UI/ViewModels/EarTrumpetCommunitySettingsPageViewModel.cs @@ -1,4 +1,6 @@ -namespace EarTrumpet.UI.ViewModels; +using System; + +namespace EarTrumpet.UI.ViewModels; public class EarTrumpetCommunitySettingsPageViewModel : SettingsPageViewModel { @@ -29,6 +31,32 @@ public double LogarithmicVolumeMinDb } } + public double ScrollWheelOrHotkeyVolumeChangePercent + { + get => _settings.ScrollWheelOrHotkeyVolumeChangePercent; + set + { + if (_settings.ScrollWheelOrHotkeyVolumeChangePercent != (float)value) + { + _settings.ScrollWheelOrHotkeyVolumeChangePercent = (int)Math.Round(value); + RaisePropertyChanged(nameof(ScrollWheelOrHotkeyVolumeChangePercent)); + } + } + } + + public double ScrollWheelOrHotkeyVolumeChangeDb + { + get => _settings.ScrollWheelOrHotkeyVolumeChangeDb; + set + { + if (_settings.ScrollWheelOrHotkeyVolumeChangeDb != (float)value) + { + _settings.ScrollWheelOrHotkeyVolumeChangeDb = (float)value; + RaisePropertyChanged(nameof(ScrollWheelOrHotkeyVolumeChangeDb)); + } + } + } + public bool ShowFullMixerWindowOnStartup { get => _settings.ShowFullMixerWindowOnStartup; diff --git a/EarTrumpet/UI/ViewModels/FlyoutViewModel.cs b/EarTrumpet/UI/ViewModels/FlyoutViewModel.cs index c8ee6dafc..d591ae674 100644 --- a/EarTrumpet/UI/ViewModels/FlyoutViewModel.cs +++ b/EarTrumpet/UI/ViewModels/FlyoutViewModel.cs @@ -326,7 +326,8 @@ private int OnMouseWheelEvent(object sender, System.Windows.Forms.MouseEventArgs { if (!_winRect.Contains(new Point(e.X, e.Y))) { - existing.IncrementVolume(Math.Sign(e.Delta) * 2); + existing.Volume += Math.Sign(e.Delta) * + (App.Settings.UseLogarithmicVolume ? App.Settings.ScrollWheelOrHotkeyVolumeChangeDb : App.Settings.ScrollWheelOrHotkeyVolumeChangePercent); return -1; } } diff --git a/EarTrumpet/UI/Views/SettingsWindow.xaml b/EarTrumpet/UI/Views/SettingsWindow.xaml index b72d72c62..82567a26e 100644 --- a/EarTrumpet/UI/Views/SettingsWindow.xaml +++ b/EarTrumpet/UI/Views/SettingsWindow.xaml @@ -180,14 +180,12 @@ Content="{x:Static resx:Resources.SettingsUseLogarithmicVolume}" IsChecked="{Binding UseLogarithmicVolume, Mode=TwoWay}" /> - + VerticalAlignment="Center">