1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 22:33:05 +08:00

Move audio adjustment hookup to own method for clarity

This commit is contained in:
Dean Herbert 2023-10-18 17:38:11 +09:00
parent e56ff33271
commit 161890292f
No known key found for this signature in database
5 changed files with 39 additions and 8 deletions

View File

@ -126,7 +126,8 @@ namespace osu.Game.Rulesets.Mods
public ModAdaptiveSpeed() public ModAdaptiveSpeed()
{ {
rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch); rateAdjustHelper = new RateAdjustModHelper(SpeedChange);
rateAdjustHelper.HandleAudioAdjustments(AdjustPitch);
InitialRate.BindValueChanged(val => InitialRate.BindValueChanged(val =>
{ {

View File

@ -34,7 +34,8 @@ namespace osu.Game.Rulesets.Mods
protected ModDoubleTime() protected ModDoubleTime()
{ {
rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch); rateAdjustHelper = new RateAdjustModHelper(SpeedChange);
rateAdjustHelper.HandleAudioAdjustments(AdjustPitch);
} }
public override void ApplyToTrack(IAdjustableAudioComponent track) public override void ApplyToTrack(IAdjustableAudioComponent track)

View File

@ -34,7 +34,8 @@ namespace osu.Game.Rulesets.Mods
protected ModHalfTime() protected ModHalfTime()
{ {
rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch); rateAdjustHelper = new RateAdjustModHelper(SpeedChange);
rateAdjustHelper.HandleAudioAdjustments(AdjustPitch);
} }
public override void ApplyToTrack(IAdjustableAudioComponent track) public override void ApplyToTrack(IAdjustableAudioComponent track)

View File

@ -48,7 +48,8 @@ namespace osu.Game.Rulesets.Mods
protected ModTimeRamp() 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. // for preview purpose at song select. eventually we'll want to be able to update every frame.
FinalRate.BindValueChanged(_ => applyRateAdjustment(double.PositiveInfinity), true); FinalRate.BindValueChanged(_ => applyRateAdjustment(double.PositiveInfinity), true);

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -11,17 +12,32 @@ namespace osu.Game.Rulesets.Mods
/// </summary> /// </summary>
public class RateAdjustModHelper : IApplicableToTrack public class RateAdjustModHelper : IApplicableToTrack
{ {
private readonly BindableBool? adjustPitch;
private readonly BindableNumber<double> speedChange; private readonly BindableNumber<double> speedChange;
private IAdjustableAudioComponent? track; private IAdjustableAudioComponent? track;
public RateAdjustModHelper(BindableNumber<double> speedChange, BindableBool? adjustPitch = null) private BindableBool? adjustPitch;
/// <summary>
/// Construct a new <see cref="RateAdjustModHelper"/>.
/// </summary>
/// <param name="speedChange">The main speed adjust parameter which is exposed to the user.</param>
public RateAdjustModHelper(BindableNumber<double> speedChange)
{ {
this.speedChange = speedChange; this.speedChange = speedChange;
}
/// <summary>
/// Setup audio track adjustments for a rate adjust mod.
/// Importantly, <see cref="ApplyToTrack"/> must be called when a track is obtained/changed for this to work.
/// </summary>
/// <param name="adjustPitch">The "adjust pitch" setting as exposed to the user.</param>
public void HandleAudioAdjustments(BindableBool adjustPitch)
{
this.adjustPitch = adjustPitch; this.adjustPitch = adjustPitch;
// When switching between pitch adjust, we need to update adjustments to time-shift or frequency-scale. // 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?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), speedChange);
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), speedChange); track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), speedChange);
@ -31,12 +47,23 @@ namespace osu.Game.Rulesets.Mods
}); });
} }
/// <summary>
/// Should be invoked when a track is obtained / changed.
/// </summary>
/// <param name="track">The new track.</param>
/// <exception cref="InvalidOperationException">If this method is called before <see cref="HandleAudioAdjustments"/>.</exception>
public void ApplyToTrack(IAdjustableAudioComponent track) public void ApplyToTrack(IAdjustableAudioComponent track)
{ {
if (adjustPitch == null)
throw new InvalidOperationException($"Must call {nameof(HandleAudioAdjustments)} first");
this.track = track; this.track = track;
adjustPitch?.TriggerChange(); adjustPitch.TriggerChange();
} }
/// <summary>
/// The score multiplier for the current <see cref="speedChange"/>.
/// </summary>
public double ScoreMultiplier public double ScoreMultiplier
{ {
get get