Skip to content

Commit

Permalink
Reinstantiate mod adjustments layer for safety against previous mods
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed May 10, 2022
1 parent a0f1c48 commit 36a7644
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions osu.Game/Overlays/MusicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public bool AllowTrackAdjustments
}
}

private readonly AudioAdjustments modTrackAdjustments = new AudioAdjustments();
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>.
Expand All @@ -393,18 +393,19 @@ public void ResetTrackAdjustments()
CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Tempo);
CurrentTrack.RemoveAllAdjustments(AdjustableProperty.Volume);

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);
{
if (modTrackAdjustments != null)
{
CurrentTrack.UnbindAdjustments(modTrackAdjustments);
modTrackAdjustments = null;
}
}
else
{
CurrentTrack.BindAdjustments(modTrackAdjustments);
CurrentTrack.BindAdjustments(modTrackAdjustments = new AudioAdjustments());

foreach (var mod in applicableToTrack)
mod.ApplyToTrack(modTrackAdjustments);
Expand Down

0 comments on commit 36a7644

Please sign in to comment.