1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-18 11:43:22 +08:00

Display volume in decibel format

This commit is contained in:
Mike Will 2025-01-12 20:02:06 -05:00
parent 1d8ca0f93d
commit ec861080dd
3 changed files with 40 additions and 28 deletions

View File

@ -29,41 +29,48 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
{
LabelText = AudioSettingsStrings.MasterVolume,
Current = audio.Volume.Scaled,
KeyboardStep = 0.01f,
DisplayAsPercentage = true
KeyboardStep = (float)VolumeScaler.STEP,
},
new SettingsSlider<double>
new VolumeAdjustSlider
{
LabelText = AudioSettingsStrings.MasterVolumeInactive,
Current = volumeInactive.Scaled,
KeyboardStep = 0.01f,
DisplayAsPercentage = true
KeyboardStep = (float)VolumeScaler.STEP,
PlaySamplesOnAdjust = true,
},
new VolumeAdjustSlider
{
LabelText = AudioSettingsStrings.EffectVolume,
Current = audio.VolumeSample.Scaled,
KeyboardStep = 0.01f,
DisplayAsPercentage = true
KeyboardStep = (float)VolumeScaler.STEP,
},
new VolumeAdjustSlider
{
LabelText = AudioSettingsStrings.MusicVolume,
Current = audio.VolumeTrack.Scaled,
KeyboardStep = 0.01f,
DisplayAsPercentage = true
KeyboardStep = (float)VolumeScaler.STEP,
},
};
}
private partial class DecibelSliderBar : RoundedSliderBar<double>
{
public override LocalisableString TooltipText => (Current.Value <= VolumeScaler.MIN ? "-∞" : Current.Value.ToString("+#0.0;-#0.0;+0.0")) + " dB";
}
private partial class VolumeAdjustSlider : SettingsSlider<double>
{
protected override Drawable CreateControl()
protected override Drawable CreateControl() => new DecibelSliderBar
{
var sliderBar = (RoundedSliderBar<double>)base.CreateControl();
sliderBar.PlaySamplesOnAdjust = false;
return sliderBar;
RelativeSizeAxes = Axes.X,
PlaySamplesOnAdjust = false,
};
public bool PlaySamplesOnAdjust
{
get => ((DecibelSliderBar)Control).PlaySamplesOnAdjust;
set => ((DecibelSliderBar)Control).PlaySamplesOnAdjust = value;
}
}
}

View File

@ -78,7 +78,7 @@ namespace osu.Game.Overlays.Toolbar
base.LoadComplete();
globalVolume = audio.Volume.Scaled.GetBoundCopy();
globalVolume.BindValueChanged(v => volumeBar.ResizeHeightTo((float)v.NewValue, 200, Easing.OutQuint), true);
globalVolume.BindValueChanged(v => volumeBar.ResizeHeightTo((float)(1 - v.NewValue / VolumeScaler.MIN), 200, Easing.OutQuint), true);
}
protected override bool OnKeyDown(KeyDownEvent e)

View File

@ -37,7 +37,7 @@ namespace osu.Game.Overlays.Volume
protected static readonly Vector2 LABEL_SIZE = new Vector2(120, 20);
public BindableDouble Bindable { get; } = new BindableDouble { MinValue = 0, MaxValue = 1, Precision = 0.01 };
public BindableDouble Bindable { get; } = new BindableDouble { MinValue = VolumeScaler.MIN, MaxValue = 0, Precision = adjust_step };
protected readonly float CircleSize;
@ -242,8 +242,9 @@ namespace osu.Game.Overlays.Volume
bgProgress.Progress = 0.75f;
}
private int? displayVolumeInt;
private int currentStep;
private double percentage;
private double displayVolume;
protected double DisplayVolume
@ -251,14 +252,15 @@ namespace osu.Game.Overlays.Volume
get => displayVolume;
set
{
displayVolume = value;
percentage = 1 - value / VolumeScaler.MIN;
int intValue = (int)Math.Round(displayVolume * 100);
bool intVolumeChanged = intValue != displayVolumeInt;
int step = (int)Math.Round(value / adjust_step);
bool stepChanged = step != currentStep;
displayVolumeInt = intValue;
currentStep = step;
displayVolume = currentStep * adjust_step;
if (displayVolume >= 0.995f)
if (currentStep >= step_max)
{
text.Text = "MAX";
maxGlow.EffectColour = meterColour.Opacity(2f);
@ -266,13 +268,13 @@ namespace osu.Game.Overlays.Volume
else
{
maxGlow.EffectColour = Color4.Transparent;
text.Text = intValue.ToString(CultureInfo.CurrentCulture);
text.Text = currentStep <= step_min ? "-INF" : displayVolume.ToString("N1", CultureInfo.CurrentCulture);
}
volumeCircle.Progress = displayVolume * 0.75f;
volumeCircleGlow.Progress = displayVolume * 0.75f;
volumeCircle.Progress = percentage * 0.75f;
volumeCircleGlow.Progress = percentage * 0.75f;
if (intVolumeChanged && IsLoaded)
if (stepChanged && IsLoaded)
Scheduler.AddOnce(playTickSound);
}
}
@ -286,10 +288,10 @@ namespace osu.Game.Overlays.Volume
var channel = notchSample.GetChannel();
channel.Frequency.Value = 0.99f + RNG.NextDouble(0.02f) + displayVolume * 0.1f;
channel.Frequency.Value = 0.99f + RNG.NextDouble(0.02f) + percentage * 0.1f;
// intentionally pitched down, even when hitting max.
if (displayVolumeInt == 0 || displayVolumeInt == 100)
if (currentStep == step_min || currentStep == step_max)
channel.Frequency.Value -= 0.5f;
channel.Play();
@ -302,7 +304,10 @@ namespace osu.Game.Overlays.Volume
private set => Bindable.Value = value;
}
private const double adjust_step = 0.01;
private const double adjust_step = VolumeScaler.STEP;
private const int step_min = (int)(VolumeScaler.MIN / VolumeScaler.STEP);
private const int step_max = 0;
public void Increase(double amount = 1, bool isPrecise = false) => adjust(amount, isPrecise);
public void Decrease(double amount = 1, bool isPrecise = false) => adjust(-amount, isPrecise);