Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions EarTrumpet/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@ public float LogarithmicVolumeMinDb
}
}

public int VolumeStepAmount
{
get => _settings.Get("VolumeStepAmount", 2);
set => _settings.Set("VolumeStepAmount", Math.Max(1, Math.Min(50, value)));
}

public bool UseRangeSnapping
{
get => _settings.Get("UseRangeSnapping", true);
set => _settings.Set("UseRangeSnapping", value);
}

public bool UseSliderSnap
{
get => _settings.Get("UseSliderSnap", false);
set => _settings.Set("UseSliderSnap", value);
}

public WINDOWPLACEMENT? FullMixerWindowPlacement
{
get => _settings.Get("FullMixerWindowPlacement", default(WINDOWPLACEMENT?));
Expand Down
27 changes: 27 additions & 0 deletions EarTrumpet/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions EarTrumpet/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,13 @@ Open [https://eartrumpet.app/jmp/fixstartup] to resolve this?</value>
<data name="VolumeUnit_Decibel" xml:space="preserve">
<value>dB</value>
</data>
<data name="SettingsVolumeStepAmount" xml:space="preserve">
<value>Volume step amount</value>
</data>
<data name="SettingsUseRangeSnapping" xml:space="preserve">
<value>Snap scroll wheel to volume step grid</value>
</data>
<data name="SettingsUseSliderSnap" xml:space="preserve">
<value>Snap slider to volume steps when dragging</value>
</data>
</root>
63 changes: 58 additions & 5 deletions EarTrumpet/UI/Controls/VolumeSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,48 @@ 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);
ChangePositionByAmount(amount);
if (App.Settings.UseLogarithmicVolume)
{
var amount = Math.Sign(e.Delta) * 0.2;
ChangePositionByAmount(amount);
}
else
{
var step = App.Settings.VolumeStepAmount;
if (App.Settings.UseRangeSnapping)
{
var newValue = (e.Delta > 0)
? GetNextSnapPoint(Value, step)
: GetPrevSnapPoint(Value, step);
Value = Bound(newValue);
}
else
{
ChangePositionByAmount(Math.Sign(e.Delta) * step);
}
}
e.Handled = true;
}

public void SetPositionByControlPoint(Point point)
{
var percent = point.X / ActualWidth;
Value = App.Settings.UseLogarithmicVolume
? Bound(Math.Round(Minimum + percent * (Maximum - Minimum), 1))
: Bound(Minimum + (Maximum - Minimum) * percent);
if (App.Settings.UseLogarithmicVolume)
{
Value = Bound(Math.Round(Minimum + percent * (Maximum - Minimum), 1));
}
else
{
var rawValue = (Maximum - Minimum) * percent;
if (App.Settings.UseSliderSnap)
{
Value = Bound(GetNearestSnapPoint(rawValue, App.Settings.VolumeStepAmount));
}
else
{
Value = Bound(rawValue);
}
}
}

public void ChangePositionByAmount(double amount)
Expand All @@ -224,4 +255,26 @@ public double Bound(double val)
{
return Math.Max(Minimum, Math.Min(Maximum, val));
}

private static double GetNextSnapPoint(double current, int step)
{
var target = Math.Floor(current / step) * step + step;
return (target > 100) ? 100 : target;
}

private static double GetPrevSnapPoint(double current, int step)
{
var target = Math.Ceiling(current / step) * step - step;
return (target < 0) ? 0 : target;
}

private static double GetNearestSnapPoint(double current, int step)
{
var snap = Math.Round(current / step) * step;
if (Math.Abs(100 - current) < Math.Abs(snap - current))
{
return 100;
}
return Math.Min(100, Math.Max(0, snap));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,45 @@ public bool ShowFullMixerWindowOnStartup
set => _settings.ShowFullMixerWindowOnStartup = value;
}

public int VolumeStepAmount
{
get => _settings.VolumeStepAmount;
set
{
if (_settings.VolumeStepAmount != value)
{
_settings.VolumeStepAmount = value;
RaisePropertyChanged(nameof(VolumeStepAmount));
}
}
}

public bool UseRangeSnapping
{
get => _settings.UseRangeSnapping;
set
{
if (_settings.UseRangeSnapping != value)
{
_settings.UseRangeSnapping = value;
RaisePropertyChanged(nameof(UseRangeSnapping));
}
}
}

public bool UseSliderSnap
{
get => _settings.UseSliderSnap;
set
{
if (_settings.UseSliderSnap != value)
{
_settings.UseSliderSnap = value;
RaisePropertyChanged(nameof(UseSliderSnap));
}
}
}

public EarTrumpetCommunitySettingsPageViewModel(AppSettings settings) : base(null)
{
_settings = settings;
Expand Down
25 changes: 25 additions & 0 deletions EarTrumpet/UI/Views/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,31 @@
<CheckBox HorizontalAlignment="Left"
Content="{x:Static resx:Resources.SettingsShowFullMixerWindowOnStartup}"
IsChecked="{Binding ShowFullMixerWindowOnStartup, Mode=TwoWay}" />
<StackPanel>
<TextBlock VerticalAlignment="Center"
Style="{StaticResource BodyText}"
Text="{x:Static resx:Resources.SettingsVolumeStepAmount}" />
<StackPanel Orientation="Horizontal"
Margin="12,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom">
<Slider Minimum="1"
Maximum="50"
Width="200"
IsSnapToTickEnabled="True"
TickFrequency="1"
Value="{Binding VolumeStepAmount, Mode=TwoWay}" />
<TextBlock VerticalAlignment="Center"
Style="{StaticResource BodyText}"
Text="{Binding VolumeStepAmount, StringFormat=\{0\}%}" />
</StackPanel>
</StackPanel>
<CheckBox HorizontalAlignment="Left"
Content="{x:Static resx:Resources.SettingsUseRangeSnapping}"
IsChecked="{Binding UseRangeSnapping, Mode=TwoWay}" />
<CheckBox HorizontalAlignment="Left"
Content="{x:Static resx:Resources.SettingsUseSliderSnap}"
IsChecked="{Binding UseSliderSnap, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:EarTrumpetLegacySettingsPageViewModel}">
Expand Down