mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 07:33:20 +08:00
Merge pull request #18211 from frenzibyte/audio-adjustment-breakage-alt
Fix mods potentially adjusting track while not selected
This commit is contained in:
commit
5f2d9bf04c
@ -3,9 +3,11 @@
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.UI;
|
||||
|
||||
namespace osu.Game.Tests.Rulesets.Mods
|
||||
{
|
||||
@ -16,11 +18,14 @@ namespace osu.Game.Tests.Rulesets.Mods
|
||||
private const double duration = 9000;
|
||||
|
||||
private TrackVirtual track;
|
||||
private OsuPlayfield playfield;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
track = new TrackVirtual(20_000);
|
||||
// define a fake playfield to re-calculate the current rate by ModTimeRamp.Update(Playfield).
|
||||
playfield = new OsuPlayfield { Clock = new FramedClock(track) };
|
||||
}
|
||||
|
||||
[TestCase(0, 1)]
|
||||
@ -80,8 +85,8 @@ namespace osu.Game.Tests.Rulesets.Mods
|
||||
private void seekTrackAndUpdateMod(ModTimeRamp mod, double time)
|
||||
{
|
||||
track.Seek(time);
|
||||
// update the mod via a fake playfield to re-calculate the current rate.
|
||||
mod.Update(null);
|
||||
playfield.Clock.ProcessFrame();
|
||||
mod.Update(playfield);
|
||||
}
|
||||
|
||||
private static Beatmap createSingleSpinnerBeatmap()
|
||||
|
@ -377,6 +377,8 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
}
|
||||
|
||||
private AudioAdjustments modTrackAdjustments;
|
||||
|
||||
/// <summary>
|
||||
/// Resets the adjustments currently applied on <see cref="CurrentTrack"/> and applies the mod adjustments if <see cref="AllowTrackAdjustments"/> is <c>true</c>.
|
||||
/// </summary>
|
||||
@ -385,6 +387,7 @@ namespace osu.Game.Overlays
|
||||
/// </remarks>
|
||||
public void ResetTrackAdjustments()
|
||||
{
|
||||
// todo: we probably want a helper method rather than this.
|
||||
CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Balance);
|
||||
CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Frequency);
|
||||
CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Tempo);
|
||||
@ -392,8 +395,10 @@ namespace osu.Game.Overlays
|
||||
|
||||
if (allowTrackAdjustments)
|
||||
{
|
||||
CurrentTrack.BindAdjustments(modTrackAdjustments = new AudioAdjustments());
|
||||
|
||||
foreach (var mod in mods.Value.OfType<IApplicableToTrack>())
|
||||
mod.ApplyToTrack(CurrentTrack);
|
||||
mod.ApplyToTrack(modTrackAdjustments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// 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 osu.Framework.Graphics.Audio;
|
||||
using osu.Framework.Audio;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
@ -10,6 +10,6 @@ namespace osu.Game.Rulesets.Mods
|
||||
/// </summary>
|
||||
public interface IApplicableToSample : IApplicableMod
|
||||
{
|
||||
void ApplyToSample(DrawableSample sample);
|
||||
void ApplyToSample(IAdjustableAudioComponent sample);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// 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 osu.Framework.Audio.Track;
|
||||
using osu.Framework.Audio;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
@ -10,6 +10,6 @@ namespace osu.Game.Rulesets.Mods
|
||||
/// </summary>
|
||||
public interface IApplicableToTrack : IApplicableMod
|
||||
{
|
||||
void ApplyToTrack(ITrack track);
|
||||
void ApplyToTrack(IAdjustableAudioComponent track);
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Audio;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
@ -79,7 +77,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
// 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 IAdjustableAudioComponent track;
|
||||
private double targetRate = 1d;
|
||||
|
||||
/// <summary>
|
||||
@ -141,7 +139,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
AdjustPitch.BindValueChanged(adjustPitchChanged);
|
||||
}
|
||||
|
||||
public void ApplyToTrack(ITrack track)
|
||||
public void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
this.track = track;
|
||||
|
||||
@ -151,7 +149,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
recentRates.AddRange(Enumerable.Repeat(InitialRate.Value, recent_rate_count));
|
||||
}
|
||||
|
||||
public void ApplyToSample(DrawableSample sample)
|
||||
public void ApplyToSample(IAdjustableAudioComponent sample)
|
||||
{
|
||||
sample.AddAdjustment(AdjustableProperty.Frequency, SpeedChange);
|
||||
}
|
||||
@ -210,7 +208,6 @@ namespace osu.Game.Rulesets.Mods
|
||||
private void adjustPitchChanged(ValueChangedEvent<bool> adjustPitchSetting)
|
||||
{
|
||||
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
|
||||
|
||||
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
|
||||
@ -27,7 +26,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
}, true);
|
||||
}
|
||||
|
||||
public override void ApplyToTrack(ITrack track)
|
||||
public override void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
// base.ApplyToTrack() intentionally not called (different tempo adjustment is applied)
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, freqAdjust);
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
@ -71,7 +70,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
InverseMuting.BindValueChanged(i => MuteComboCount.MinValue = i.NewValue ? 1 : 0, true);
|
||||
}
|
||||
|
||||
public void ApplyToTrack(ITrack track)
|
||||
public void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
track.AddAdjustment(AdjustableProperty.Volume, mainVolumeAdjust);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
}, true);
|
||||
}
|
||||
|
||||
public override void ApplyToTrack(ITrack track)
|
||||
public override void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
// base.ApplyToTrack() intentionally not called (different tempo adjustment is applied)
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, freqAdjust);
|
||||
|
@ -3,9 +3,7 @@
|
||||
|
||||
using System;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Audio;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
@ -15,12 +13,12 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
public abstract BindableNumber<double> SpeedChange { get; }
|
||||
|
||||
public virtual void ApplyToTrack(ITrack track)
|
||||
public virtual void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
track.AddAdjustment(AdjustableProperty.Tempo, SpeedChange);
|
||||
}
|
||||
|
||||
public virtual void ApplyToSample(DrawableSample sample)
|
||||
public virtual void ApplyToSample(IAdjustableAudioComponent sample)
|
||||
{
|
||||
sample.AddAdjustment(AdjustableProperty.Frequency, SpeedChange);
|
||||
}
|
||||
|
@ -4,9 +4,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Audio;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
@ -46,7 +44,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
private ITrack track;
|
||||
private IAdjustableAudioComponent track;
|
||||
|
||||
protected ModTimeRamp()
|
||||
{
|
||||
@ -55,7 +53,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
AdjustPitch.BindValueChanged(applyPitchAdjustment);
|
||||
}
|
||||
|
||||
public void ApplyToTrack(ITrack track)
|
||||
public void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
this.track = track;
|
||||
|
||||
@ -63,7 +61,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
AdjustPitch.TriggerChange();
|
||||
}
|
||||
|
||||
public void ApplyToSample(DrawableSample sample)
|
||||
public void ApplyToSample(IAdjustableAudioComponent sample)
|
||||
{
|
||||
sample.AddAdjustment(AdjustableProperty.Frequency, SpeedChange);
|
||||
}
|
||||
@ -90,7 +88,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
public virtual void Update(Playfield playfield)
|
||||
{
|
||||
applyRateAdjustment(track.CurrentTime);
|
||||
applyRateAdjustment(playfield.Clock.CurrentTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user