diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs index 89b6485..0aa29cb 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs @@ -339,39 +339,19 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan } } - // Newer .net has Math.Clamp - private T Clamp(T val, T min, T max) where T : IComparable - { - if (val.CompareTo(min) < 0) return min; - else if (val.CompareTo(max) > 0) return max; - else return val; - } - - // A change in amplitude by a factor of 10 corresponds to a 20 dB change - private const double DecibelAmplitudeMult = 20.0; - public double LinearVolume { - // mediaElement.Volume returns [0,1] where 0 = -100db, 1 = 0db - // Decibel is logarithmic. See amplitude table https://en.wikipedia.org/wiki/Decibel - get - { - var dbVol = 100.0 * (mediaElement.Volume - 1.0); - var linearVol = Math.Pow(10, dbVol / DecibelAmplitudeMult); - return linearVol; - } + get => mediaElement.Volume; set { - var linearVol = Clamp(value, 0.00001, 1.0); - var dbVol = DecibelAmplitudeMult * Math.Log10(linearVol); - mediaElement.Volume = dbVol / 100.0 + 1.0; + mediaElement.Volume = value; OnPropertyChanged(); } } private void ChangeVolume(double delta) { - LinearVolume = LinearVolume + delta; // setter will clamp + LinearVolume += delta; } private void TogglePlayPause(object sender, EventArgs e)