mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 06:33:20 +08:00
Merge pull request #13726 from nekodex/notch-tick-sfx
Add audio feedback for changing volume
This commit is contained in:
commit
5a7706edee
@ -51,7 +51,7 @@
|
|||||||
<Reference Include="Java.Interop" />
|
<Reference Include="Java.Interop" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.618.0" />
|
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.701.0" />
|
||||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.702.0" />
|
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.702.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Label="Transitive Dependencies">
|
<ItemGroup Label="Transitive Dependencies">
|
||||||
|
@ -15,6 +15,7 @@ using osu.Framework.Graphics.Cursor;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Framework.Utils;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
@ -99,7 +100,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(AudioManager audio, OsuColour colours)
|
private void load(AudioManager audio, OsuColour colours)
|
||||||
{
|
{
|
||||||
sample = audio.Samples.Get(@"UI/sliderbar-notch");
|
sample = audio.Samples.Get(@"UI/notch-tick");
|
||||||
AccentColour = colours.Pink;
|
AccentColour = colours.Pink;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
private void playSample(T value)
|
private void playSample(T value)
|
||||||
{
|
{
|
||||||
if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50)
|
if (Clock == null || Clock.CurrentTime - lastSampleTime <= 30)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (value.Equals(lastSampleValue))
|
if (value.Equals(lastSampleValue))
|
||||||
@ -158,13 +159,15 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
lastSampleValue = value;
|
lastSampleValue = value;
|
||||||
lastSampleTime = Clock.CurrentTime;
|
lastSampleTime = Clock.CurrentTime;
|
||||||
|
|
||||||
var channel = sample.Play();
|
var channel = sample.GetChannel();
|
||||||
|
|
||||||
channel.Frequency.Value = 1 + NormalizedValue * 0.2f;
|
channel.Frequency.Value = 0.99f + RNG.NextDouble(0.02f) + NormalizedValue * 0.2f;
|
||||||
if (NormalizedValue == 0)
|
|
||||||
channel.Frequency.Value -= 0.4f;
|
// intentionally pitched down, even when hitting max.
|
||||||
else if (NormalizedValue == 1)
|
if (NormalizedValue == 0 || NormalizedValue == 1)
|
||||||
channel.Frequency.Value += 0.4f;
|
channel.Frequency.Value -= 0.5f;
|
||||||
|
|
||||||
|
channel.Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTooltipText(T value)
|
private void updateTooltipText(T value)
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Audio.Sample;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -36,6 +38,9 @@ namespace osu.Game.Overlays.Volume
|
|||||||
private OsuSpriteText text;
|
private OsuSpriteText text;
|
||||||
private BufferedContainer maxGlow;
|
private BufferedContainer maxGlow;
|
||||||
|
|
||||||
|
private Sample sample;
|
||||||
|
private double sampleLastPlaybackTime;
|
||||||
|
|
||||||
public VolumeMeter(string name, float circleSize, Color4 meterColour)
|
public VolumeMeter(string name, float circleSize, Color4 meterColour)
|
||||||
{
|
{
|
||||||
this.circleSize = circleSize;
|
this.circleSize = circleSize;
|
||||||
@ -46,8 +51,11 @@ namespace osu.Game.Overlays.Volume
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours, AudioManager audio)
|
||||||
{
|
{
|
||||||
|
sample = audio.Samples.Get(@"UI/notch-tick");
|
||||||
|
sampleLastPlaybackTime = Time.Current;
|
||||||
|
|
||||||
Color4 backgroundColour = colours.Gray1;
|
Color4 backgroundColour = colours.Gray1;
|
||||||
|
|
||||||
CircularProgress bgProgress;
|
CircularProgress bgProgress;
|
||||||
@ -178,22 +186,12 @@ namespace osu.Game.Overlays.Volume
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Bindable.ValueChanged += volume =>
|
Bindable.BindValueChanged(volume => { this.TransformTo(nameof(DisplayVolume), volume.NewValue, 400, Easing.OutQuint); }, true);
|
||||||
{
|
|
||||||
this.TransformTo("DisplayVolume",
|
|
||||||
volume.NewValue,
|
|
||||||
400,
|
|
||||||
Easing.OutQuint);
|
|
||||||
};
|
|
||||||
|
|
||||||
bgProgress.Current.Value = 0.75f;
|
bgProgress.Current.Value = 0.75f;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
private int displayVolumeInt;
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
Bindable.TriggerChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
private double displayVolume;
|
private double displayVolume;
|
||||||
|
|
||||||
@ -202,8 +200,16 @@ namespace osu.Game.Overlays.Volume
|
|||||||
get => displayVolume;
|
get => displayVolume;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
if (value == displayVolume)
|
||||||
|
return;
|
||||||
|
|
||||||
displayVolume = value;
|
displayVolume = value;
|
||||||
|
|
||||||
|
int intValue = (int)Math.Round(displayVolume * 100);
|
||||||
|
bool intVolumeChanged = intValue != displayVolumeInt;
|
||||||
|
|
||||||
|
displayVolumeInt = intValue;
|
||||||
|
|
||||||
if (displayVolume >= 0.995f)
|
if (displayVolume >= 0.995f)
|
||||||
{
|
{
|
||||||
text.Text = "MAX";
|
text.Text = "MAX";
|
||||||
@ -212,14 +218,36 @@ namespace osu.Game.Overlays.Volume
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
maxGlow.EffectColour = Color4.Transparent;
|
maxGlow.EffectColour = Color4.Transparent;
|
||||||
text.Text = Math.Round(displayVolume * 100).ToString(CultureInfo.CurrentCulture);
|
text.Text = displayVolumeInt.ToString(CultureInfo.CurrentCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeCircle.Current.Value = displayVolume * 0.75f;
|
volumeCircle.Current.Value = displayVolume * 0.75f;
|
||||||
volumeCircleGlow.Current.Value = displayVolume * 0.75f;
|
volumeCircleGlow.Current.Value = displayVolume * 0.75f;
|
||||||
|
|
||||||
|
if (intVolumeChanged && IsLoaded)
|
||||||
|
Scheduler.AddOnce(playTickSound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void playTickSound()
|
||||||
|
{
|
||||||
|
const int tick_debounce_time = 30;
|
||||||
|
|
||||||
|
if (Time.Current - sampleLastPlaybackTime <= tick_debounce_time)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var channel = sample.GetChannel();
|
||||||
|
|
||||||
|
channel.Frequency.Value = 0.99f + RNG.NextDouble(0.02f) + displayVolume * 0.1f;
|
||||||
|
|
||||||
|
// intentionally pitched down, even when hitting max.
|
||||||
|
if (displayVolumeInt == 0 || displayVolumeInt == 100)
|
||||||
|
channel.Frequency.Value -= 0.5f;
|
||||||
|
|
||||||
|
channel.Play();
|
||||||
|
sampleLastPlaybackTime = Time.Current;
|
||||||
|
}
|
||||||
|
|
||||||
public double Volume
|
public double Volume
|
||||||
{
|
{
|
||||||
get => Bindable.Value;
|
get => Bindable.Value;
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Realm" Version="10.2.1" />
|
<PackageReference Include="Realm" Version="10.2.1" />
|
||||||
<PackageReference Include="ppy.osu.Framework" Version="2021.702.0" />
|
<PackageReference Include="ppy.osu.Framework" Version="2021.702.0" />
|
||||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.618.0" />
|
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.701.0" />
|
||||||
<PackageReference Include="Sentry" Version="3.6.0" />
|
<PackageReference Include="Sentry" Version="3.6.0" />
|
||||||
<PackageReference Include="SharpCompress" Version="0.28.3" />
|
<PackageReference Include="SharpCompress" Version="0.28.3" />
|
||||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||||
|
@ -71,7 +71,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Label="Package References">
|
<ItemGroup Label="Package References">
|
||||||
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.702.0" />
|
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.702.0" />
|
||||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.618.0" />
|
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.701.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
|
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user