diff --git a/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs b/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs index 93251f7b2ddb..0b4bb78c57b0 100644 --- a/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs +++ b/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs @@ -65,6 +65,22 @@ public class ModAdaptiveSpeed : Mod, IApplicableToRate, IApplicableToDrawableHit Value = 1 }; + private readonly BindableNumber frequencyAdjustment = new BindableDouble + { + MinValue = min_allowable_rate, + MaxValue = max_allowable_rate, + Default = 1, + Value = 1 + }; + + private readonly BindableNumber tempoAdjustment = new BindableDouble + { + MinValue = min_allowable_rate, + MaxValue = max_allowable_rate, + Default = 1, + Value = 1 + }; + // The two constants below denote the maximum allowable range of rates that `SpeedChange` can take. // The range is purposefully wider than the range of values that `InitialRate` allows // in order to give some leeway for change even when extreme initial rates are chosen. @@ -79,7 +95,6 @@ public class ModAdaptiveSpeed : Mod, IApplicableToRate, IApplicableToDrawableHit // Apply a fixed rate change when missing, allowing the player to catch up when the rate is too fast. private const double rate_change_on_miss = 0.95d; - private ITrack track; private double targetRate = 1d; /// @@ -143,7 +158,8 @@ public ModAdaptiveSpeed() public void ApplyToTrack(ITrack track) { - this.track = track; + track.AddAdjustment(AdjustableProperty.Frequency, frequencyAdjustment); + track.AddAdjustment(AdjustableProperty.Tempo, tempoAdjustment); InitialRate.TriggerChange(); AdjustPitch.TriggerChange(); @@ -209,13 +225,14 @@ public void ApplyToBeatmap(IBeatmap beatmap) private void adjustPitchChanged(ValueChangedEvent adjustPitchSetting) { - track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange); + adjustmentForPitchSetting(adjustPitchSetting.OldValue).UnbindFrom(SpeedChange); + adjustmentForPitchSetting(adjustPitchSetting.OldValue).SetDefault(); - track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange); + adjustmentForPitchSetting(adjustPitchSetting.NewValue).BindTo(SpeedChange); } - private AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue) - => adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo; + private BindableNumber adjustmentForPitchSetting(bool adjustPitchSettingValue) + => adjustPitchSettingValue ? frequencyAdjustment : tempoAdjustment; private IEnumerable getAllApplicableHitObjects(IEnumerable hitObjects) { diff --git a/osu.Game/Rulesets/Mods/ModTimeRamp.cs b/osu.Game/Rulesets/Mods/ModTimeRamp.cs index fe6d54332c70..45191026164f 100644 --- a/osu.Game/Rulesets/Mods/ModTimeRamp.cs +++ b/osu.Game/Rulesets/Mods/ModTimeRamp.cs @@ -46,6 +46,20 @@ public abstract class ModTimeRamp : Mod, IUpdatableByPlayfield, IApplicableToBea Precision = 0.01, }; + private readonly BindableNumber frequencyAdjustment = new BindableDouble + { + Default = 1, + Value = 1, + Precision = 0.01 + }; + + private readonly BindableNumber tempoAdjustment = new BindableDouble + { + Default = 1, + Value = 1, + Precision = 0.01 + }; + private ITrack track; protected ModTimeRamp() @@ -57,8 +71,12 @@ protected ModTimeRamp() public void ApplyToTrack(ITrack track) { + // stored only for the purpose of accessing track.CurrentTime. this.track = track; + track.AddAdjustment(AdjustableProperty.Frequency, frequencyAdjustment); + track.AddAdjustment(AdjustableProperty.Tempo, tempoAdjustment); + FinalRate.TriggerChange(); AdjustPitch.TriggerChange(); } @@ -100,13 +118,13 @@ public virtual void Update(Playfield playfield) private void applyPitchAdjustment(ValueChangedEvent adjustPitchSetting) { - // remove existing old adjustment - track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange); + adjustmentForPitchSetting(adjustPitchSetting.OldValue).UnbindFrom(SpeedChange); + adjustmentForPitchSetting(adjustPitchSetting.OldValue).SetDefault(); - track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange); + adjustmentForPitchSetting(adjustPitchSetting.NewValue).BindTo(SpeedChange); } - private AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue) - => adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo; + private BindableNumber adjustmentForPitchSetting(bool adjustPitchSettingValue) + => adjustPitchSettingValue ? frequencyAdjustment : tempoAdjustment; } }