diff --git a/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs b/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs index f122baed90..607e6b8399 100644 --- a/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs +++ b/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs @@ -126,7 +126,8 @@ namespace osu.Game.Rulesets.Mods public ModAdaptiveSpeed() { - rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch); + rateAdjustHelper = new RateAdjustModHelper(SpeedChange); + rateAdjustHelper.HandleAudioAdjustments(AdjustPitch); InitialRate.BindValueChanged(val => { diff --git a/osu.Game/Rulesets/Mods/ModDoubleTime.cs b/osu.Game/Rulesets/Mods/ModDoubleTime.cs index f20cdcb18d..789291772d 100644 --- a/osu.Game/Rulesets/Mods/ModDoubleTime.cs +++ b/osu.Game/Rulesets/Mods/ModDoubleTime.cs @@ -34,7 +34,8 @@ namespace osu.Game.Rulesets.Mods protected ModDoubleTime() { - rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch); + rateAdjustHelper = new RateAdjustModHelper(SpeedChange); + rateAdjustHelper.HandleAudioAdjustments(AdjustPitch); } public override void ApplyToTrack(IAdjustableAudioComponent track) diff --git a/osu.Game/Rulesets/Mods/ModHalfTime.cs b/osu.Game/Rulesets/Mods/ModHalfTime.cs index 4d75ee16bd..8b5dd39584 100644 --- a/osu.Game/Rulesets/Mods/ModHalfTime.cs +++ b/osu.Game/Rulesets/Mods/ModHalfTime.cs @@ -34,7 +34,8 @@ namespace osu.Game.Rulesets.Mods protected ModHalfTime() { - rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch); + rateAdjustHelper = new RateAdjustModHelper(SpeedChange); + rateAdjustHelper.HandleAudioAdjustments(AdjustPitch); } public override void ApplyToTrack(IAdjustableAudioComponent track) diff --git a/osu.Game/Rulesets/Mods/ModTimeRamp.cs b/osu.Game/Rulesets/Mods/ModTimeRamp.cs index 1048caa698..d2772417db 100644 --- a/osu.Game/Rulesets/Mods/ModTimeRamp.cs +++ b/osu.Game/Rulesets/Mods/ModTimeRamp.cs @@ -48,7 +48,8 @@ namespace osu.Game.Rulesets.Mods protected ModTimeRamp() { - rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch); + rateAdjustHelper = new RateAdjustModHelper(SpeedChange); + rateAdjustHelper.HandleAudioAdjustments(AdjustPitch); // for preview purpose at song select. eventually we'll want to be able to update every frame. FinalRate.BindValueChanged(_ => applyRateAdjustment(double.PositiveInfinity), true); diff --git a/osu.Game/Rulesets/Mods/RateAdjustModHelper.cs b/osu.Game/Rulesets/Mods/RateAdjustModHelper.cs index 034c20fc78..701bad06bc 100644 --- a/osu.Game/Rulesets/Mods/RateAdjustModHelper.cs +++ b/osu.Game/Rulesets/Mods/RateAdjustModHelper.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Audio; using osu.Framework.Bindables; @@ -11,17 +12,32 @@ namespace osu.Game.Rulesets.Mods /// public class RateAdjustModHelper : IApplicableToTrack { - private readonly BindableBool? adjustPitch; private readonly BindableNumber speedChange; + private IAdjustableAudioComponent? track; - public RateAdjustModHelper(BindableNumber speedChange, BindableBool? adjustPitch = null) + private BindableBool? adjustPitch; + + /// + /// Construct a new . + /// + /// The main speed adjust parameter which is exposed to the user. + public RateAdjustModHelper(BindableNumber speedChange) { this.speedChange = speedChange; + } + + /// + /// Setup audio track adjustments for a rate adjust mod. + /// Importantly, must be called when a track is obtained/changed for this to work. + /// + /// The "adjust pitch" setting as exposed to the user. + public void HandleAudioAdjustments(BindableBool adjustPitch) + { this.adjustPitch = adjustPitch; // When switching between pitch adjust, we need to update adjustments to time-shift or frequency-scale. - adjustPitch?.BindValueChanged(adjustPitchSetting => + adjustPitch.BindValueChanged(adjustPitchSetting => { track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), speedChange); track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), speedChange); @@ -31,12 +47,23 @@ namespace osu.Game.Rulesets.Mods }); } + /// + /// Should be invoked when a track is obtained / changed. + /// + /// The new track. + /// If this method is called before . public void ApplyToTrack(IAdjustableAudioComponent track) { + if (adjustPitch == null) + throw new InvalidOperationException($"Must call {nameof(HandleAudioAdjustments)} first"); + this.track = track; - adjustPitch?.TriggerChange(); + adjustPitch.TriggerChange(); } + /// + /// The score multiplier for the current . + /// public double ScoreMultiplier { get