1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-03 06:33:10 +08:00

Replace manual usages of AudioFilter with new ducking methods

This commit is contained in:
Jamie Taylor 2024-06-22 01:57:14 +09:00
parent a56751511e
commit 0d11b2b91c
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C
3 changed files with 18 additions and 35 deletions

View File

@ -7,11 +7,11 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Audio.Effects;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK; using osuTK;
namespace osu.Game.Collections namespace osu.Game.Collections
@ -21,11 +21,12 @@ namespace osu.Game.Collections
private const double enter_duration = 500; private const double enter_duration = 500;
private const double exit_duration = 200; private const double exit_duration = 200;
private AudioFilter lowPassFilter = null!;
protected override string PopInSampleName => @"UI/overlay-big-pop-in"; protected override string PopInSampleName => @"UI/overlay-big-pop-in";
protected override string PopOutSampleName => @"UI/overlay-big-pop-out"; protected override string PopOutSampleName => @"UI/overlay-big-pop-out";
[Resolved]
private MusicController? musicController { get; set; }
public ManageCollectionsDialog() public ManageCollectionsDialog()
{ {
Anchor = Anchor.Centre; Anchor = Anchor.Centre;
@ -110,19 +111,14 @@ namespace osu.Game.Collections
}, },
} }
} }
}, }
lowPassFilter = new AudioFilter(audio.TrackMixer)
}; };
} }
public override bool IsPresent => base.IsPresent
// Safety for low pass filter potentially getting stuck in applied state due to
// transforms on `this` causing children to no longer be updated.
|| lowPassFilter.IsAttached;
protected override void PopIn() protected override void PopIn()
{ {
lowPassFilter.CutoffTo(300, 100, Easing.OutCubic); musicController?.Duck(100, 1f);
this.FadeIn(enter_duration, Easing.OutQuint); this.FadeIn(enter_duration, Easing.OutQuint);
this.ScaleTo(0.9f).Then().ScaleTo(1f, enter_duration, Easing.OutQuint); this.ScaleTo(0.9f).Then().ScaleTo(1f, enter_duration, Easing.OutQuint);
} }
@ -131,7 +127,7 @@ namespace osu.Game.Collections
{ {
base.PopOut(); base.PopOut();
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, 100, Easing.InCubic); musicController?.Unduck(100);
this.FadeOut(exit_duration, Easing.OutQuint); this.FadeOut(exit_duration, Easing.OutQuint);
this.ScaleTo(0.9f, exit_duration); this.ScaleTo(0.9f, exit_duration);

View File

@ -10,7 +10,6 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Audio.Effects;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -48,6 +47,9 @@ namespace osu.Game.Overlays.Dialog
private partial class DangerousConfirmContainer : HoldToConfirmContainer private partial class DangerousConfirmContainer : HoldToConfirmContainer
{ {
[Resolved]
private MusicController musicController { get; set; }
public DangerousConfirmContainer() public DangerousConfirmContainer()
: base(isDangerousAction: true) : base(isDangerousAction: true)
{ {
@ -56,7 +58,6 @@ namespace osu.Game.Overlays.Dialog
private Sample tickSample; private Sample tickSample;
private Sample confirmSample; private Sample confirmSample;
private double lastTickPlaybackTime; private double lastTickPlaybackTime;
private AudioFilter lowPassFilter = null!;
private bool mouseDown; private bool mouseDown;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -64,8 +65,6 @@ namespace osu.Game.Overlays.Dialog
{ {
tickSample = audio.Samples.Get(@"UI/dialog-dangerous-tick"); tickSample = audio.Samples.Get(@"UI/dialog-dangerous-tick");
confirmSample = audio.Samples.Get(@"UI/dialog-dangerous-select"); confirmSample = audio.Samples.Get(@"UI/dialog-dangerous-select");
AddInternal(lowPassFilter = new AudioFilter(audio.SampleMixer));
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -76,13 +75,13 @@ namespace osu.Game.Overlays.Dialog
protected override void AbortConfirm() protected override void AbortConfirm()
{ {
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF); musicController?.Unduck();
base.AbortConfirm(); base.AbortConfirm();
} }
protected override void Confirm() protected override void Confirm()
{ {
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF); musicController?.Duck();
confirmSample?.Play(); confirmSample?.Play();
base.Confirm(); base.Confirm();
} }
@ -126,8 +125,6 @@ namespace osu.Game.Overlays.Dialog
if (Clock.CurrentTime - lastTickPlaybackTime < 30) return; if (Clock.CurrentTime - lastTickPlaybackTime < 30) return;
lowPassFilter.CutoffTo((int)(progress.NewValue * AudioFilter.MAX_LOWPASS_CUTOFF * 0.5));
var channel = tickSample.GetChannel(); var channel = tickSample.GetChannel();
channel.Frequency.Value = 1 + progress.NewValue * 0.5f; channel.Frequency.Value = 1 + progress.NewValue * 0.5f;

View File

@ -10,9 +10,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Audio.Effects;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
@ -23,15 +21,13 @@ namespace osu.Game.Overlays
protected override string PopInSampleName => "UI/dialog-pop-in"; protected override string PopInSampleName => "UI/dialog-pop-in";
protected override string PopOutSampleName => "UI/dialog-pop-out"; protected override string PopOutSampleName => "UI/dialog-pop-out";
private AudioFilter lowPassFilter; [Resolved]
private MusicController musicController { get; set; }
public PopupDialog CurrentDialog { get; private set; } public PopupDialog CurrentDialog { get; private set; }
public override bool IsPresent => Scheduler.HasPendingTasks public override bool IsPresent => Scheduler.HasPendingTasks
|| dialogContainer.Children.Count > 0 || dialogContainer.Children.Count > 0;
// Safety for low pass filter potentially getting stuck in applied state due to
// transforms on `this` causing children to no longer be updated.
|| lowPassFilter.IsAttached;
public DialogOverlay() public DialogOverlay()
{ {
@ -49,12 +45,6 @@ namespace osu.Game.Overlays
Origin = Anchor.Centre; Origin = Anchor.Centre;
} }
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
AddInternal(lowPassFilter = new AudioFilter(audio.TrackMixer));
}
public void Push(PopupDialog dialog) public void Push(PopupDialog dialog)
{ {
if (dialog == CurrentDialog || dialog.State.Value == Visibility.Hidden) return; if (dialog == CurrentDialog || dialog.State.Value == Visibility.Hidden) return;
@ -105,13 +95,13 @@ namespace osu.Game.Overlays
protected override void PopIn() protected override void PopIn()
{ {
lowPassFilter.CutoffTo(300, 100, Easing.OutCubic); musicController.Duck(100, 1f);
} }
protected override void PopOut() protected override void PopOut()
{ {
base.PopOut(); base.PopOut();
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, 100, Easing.InCubic); musicController.Unduck(100);
// PopOut gets called initially, but we only want to hide dialog when we have been loaded and are present. // PopOut gets called initially, but we only want to hide dialog when we have been loaded and are present.
if (IsLoaded && CurrentDialog?.State.Value == Visibility.Visible) if (IsLoaded && CurrentDialog?.State.Value == Visibility.Visible)