Define local adjustments component for mods in MusicController

Isolates `CurrentTrack` from being directly adjusted by the mod, which could lead to issues depending on how the mod adds adjustments (i.e. `ModTimeRamp`, which adds adjustments based on changes to a setting bindable).
This commit is contained in:
Salman Ahmed 2022-05-10 18:02:32 +03:00
parent 82b784ce5a
commit 725ff93f34

View File

@ -377,6 +377,8 @@ namespace osu.Game.Overlays
} }
} }
private readonly AudioAdjustments modTrackAdjustments = new AudioAdjustments();
/// <summary> /// <summary>
/// Resets the adjustments currently applied on <see cref="CurrentTrack"/> and applies the mod adjustments if <see cref="AllowTrackAdjustments"/> is <c>true</c>. /// Resets the adjustments currently applied on <see cref="CurrentTrack"/> and applies the mod adjustments if <see cref="AllowTrackAdjustments"/> is <c>true</c>.
/// </summary> /// </summary>
@ -385,15 +387,27 @@ namespace osu.Game.Overlays
/// </remarks> /// </remarks>
public void ResetTrackAdjustments() public void ResetTrackAdjustments()
{ {
// todo: we probably want a helper method rather than this.
CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Balance); CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Balance);
CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Frequency); CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Frequency);
CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Tempo); CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Tempo);
CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Volume); CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Volume);
if (allowTrackAdjustments) modTrackAdjustments.RemoveAllAdjustments(AdjustableProperty.Balance);
modTrackAdjustments.RemoveAllAdjustments(AdjustableProperty.Frequency);
modTrackAdjustments.RemoveAllAdjustments(AdjustableProperty.Tempo);
modTrackAdjustments.RemoveAllAdjustments(AdjustableProperty.Volume);
var applicableToTrack = mods.Value.OfType<IApplicableToTrack>();
if (!allowTrackAdjustments || !applicableToTrack.Any())
CurrentTrack.UnbindAdjustments(modTrackAdjustments);
else
{ {
foreach (var mod in mods.Value.OfType<IApplicableToTrack>()) CurrentTrack.BindAdjustments(modTrackAdjustments);
mod.ApplyToTrack(CurrentTrack);
foreach (var mod in applicableToTrack)
mod.ApplyToTrack(modTrackAdjustments);
} }
} }
} }