2019-01-26 12:15:19 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
2019-03-06 05:14:41 +00:00
|
|
|
using System.Linq;
|
2019-12-09 10:41:31 +00:00
|
|
|
using osu.Framework.Audio;
|
2019-12-09 08:34:04 +00:00
|
|
|
using osu.Framework.Audio.Track;
|
2019-12-09 10:41:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2019-01-26 12:15:19 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2019-12-09 10:58:51 +00:00
|
|
|
using osu.Game.Configuration;
|
2019-01-26 12:15:19 +00:00
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-06-16 13:58:23 +00:00
|
|
|
using osu.Framework.Audio.Sample;
|
2019-01-26 12:15:19 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mods
|
|
|
|
{
|
2020-06-17 10:43:32 +00:00
|
|
|
public abstract class ModTimeRamp : Mod, IUpdatableByPlayfield, IApplicableToBeatmap, IApplicableToAudio
|
2019-01-26 12:15:19 +00:00
|
|
|
{
|
2019-08-01 03:35:17 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The point in the beatmap at which the final ramping rate should be reached.
|
|
|
|
/// </summary>
|
|
|
|
private const double final_rate_progress = 0.75f;
|
|
|
|
|
2020-01-26 23:56:18 +00:00
|
|
|
[SettingSource("Initial rate", "The starting speed of the track")]
|
|
|
|
public abstract BindableNumber<double> InitialRate { get; }
|
|
|
|
|
2019-12-09 10:58:51 +00:00
|
|
|
[SettingSource("Final rate", "The final speed to ramp to")]
|
|
|
|
public abstract BindableNumber<double> FinalRate { get; }
|
2019-01-26 12:15:19 +00:00
|
|
|
|
2020-06-13 15:32:43 +00:00
|
|
|
[SettingSource("Adjust pitch", "Should pitch be adjusted with speed")]
|
2020-06-13 14:16:27 +00:00
|
|
|
public abstract BindableBool AdjustPitch { get; }
|
|
|
|
|
2020-03-23 16:54:08 +00:00
|
|
|
public override string SettingDescription => $"{InitialRate.Value:N2}x to {FinalRate.Value:N2}x";
|
2020-03-19 03:43:26 +00:00
|
|
|
|
2019-03-06 05:14:41 +00:00
|
|
|
private double finalRateTime;
|
|
|
|
private double beginRampTime;
|
|
|
|
|
2019-12-09 10:41:31 +00:00
|
|
|
public BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
2019-01-26 12:15:19 +00:00
|
|
|
{
|
2019-12-09 10:41:31 +00:00
|
|
|
Default = 1,
|
|
|
|
Value = 1,
|
|
|
|
Precision = 0.01,
|
|
|
|
};
|
2019-03-06 05:14:41 +00:00
|
|
|
|
2019-12-09 10:41:31 +00:00
|
|
|
private Track track;
|
2019-03-12 09:15:18 +00:00
|
|
|
|
2019-12-12 14:33:18 +00:00
|
|
|
protected ModTimeRamp()
|
2019-12-12 08:28:31 +00:00
|
|
|
{
|
|
|
|
// for preview purpose at song select. eventually we'll want to be able to update every frame.
|
2020-06-14 16:48:49 +00:00
|
|
|
FinalRate.BindValueChanged(val => applyRateAdjustment(1), true);
|
|
|
|
AdjustPitch.BindValueChanged(applyPitchAdjustment);
|
2019-12-12 08:28:31 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 10:41:31 +00:00
|
|
|
public void ApplyToTrack(Track track)
|
|
|
|
{
|
|
|
|
this.track = track;
|
2020-06-13 14:16:27 +00:00
|
|
|
|
2019-12-12 08:45:11 +00:00
|
|
|
FinalRate.TriggerChange();
|
2020-06-13 15:32:43 +00:00
|
|
|
AdjustPitch.TriggerChange();
|
2019-01-26 12:15:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 13:58:23 +00:00
|
|
|
public void ApplyToSample(SampleChannel sample)
|
|
|
|
{
|
|
|
|
sample.AddAdjustment(AdjustableProperty.Frequency, SpeedChange);
|
|
|
|
}
|
|
|
|
|
2019-08-01 03:35:17 +00:00
|
|
|
public virtual void ApplyToBeatmap(IBeatmap beatmap)
|
2019-01-26 12:15:19 +00:00
|
|
|
{
|
2019-03-06 05:14:41 +00:00
|
|
|
HitObject lastObject = beatmap.HitObjects.LastOrDefault();
|
|
|
|
|
2019-12-09 10:58:51 +00:00
|
|
|
SpeedChange.SetDefault();
|
|
|
|
|
2019-03-06 05:14:41 +00:00
|
|
|
beginRampTime = beatmap.HitObjects.FirstOrDefault()?.StartTime ?? 0;
|
2019-11-25 10:01:24 +00:00
|
|
|
finalRateTime = final_rate_progress * (lastObject?.GetEndTime() ?? 0);
|
2019-01-26 12:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Update(Playfield playfield)
|
|
|
|
{
|
2020-06-14 16:48:49 +00:00
|
|
|
applyRateAdjustment((track.CurrentTime - beginRampTime) / finalRateTime);
|
2019-03-12 09:15:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 03:29:16 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Adjust the rate along the specified ramp
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="amount">The amount of adjustment to apply (from 0..1).</param>
|
2020-06-14 16:48:49 +00:00
|
|
|
private void applyRateAdjustment(double amount) =>
|
2020-01-26 23:56:18 +00:00
|
|
|
SpeedChange.Value = InitialRate.Value + (FinalRate.Value - InitialRate.Value) * Math.Clamp(amount, 0, 1);
|
2020-06-13 14:16:27 +00:00
|
|
|
|
2020-06-14 16:50:07 +00:00
|
|
|
private void applyPitchAdjustment(ValueChangedEvent<bool> adjustPitchSetting)
|
2020-06-13 14:16:27 +00:00
|
|
|
{
|
|
|
|
// remove existing old adjustment
|
2020-06-26 14:21:44 +00:00
|
|
|
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
|
2020-06-13 14:16:27 +00:00
|
|
|
|
2020-06-26 14:21:44 +00:00
|
|
|
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
|
2020-06-13 14:16:27 +00:00
|
|
|
}
|
2020-06-13 15:32:43 +00:00
|
|
|
|
2020-06-14 16:50:07 +00:00
|
|
|
private AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue)
|
|
|
|
=> adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo;
|
2019-01-26 12:15:19 +00:00
|
|
|
}
|
2019-03-06 05:14:41 +00:00
|
|
|
}
|