// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using JetBrains.Annotations; using Newtonsoft.Json; using osu.Framework.Bindables; using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Beatmaps.Legacy { public class LegacyControlPointInfo : ControlPointInfo { /// /// All sound points. /// [JsonProperty] public IBindableList SamplePoints => samplePoints; private readonly BindableList samplePoints = new BindableList(); /// /// Finds the sound control point that is active at . /// /// The time to find the sound control point at. /// The sound control point. [NotNull] public SampleControlPoint SamplePointAt(double time) => BinarySearchWithFallback(SamplePoints, time, SamplePoints.Count > 0 ? SamplePoints[0] : SampleControlPoint.DEFAULT); public override void Clear() { base.Clear(); samplePoints.Clear(); } protected override bool CheckAlreadyExisting(double time, ControlPoint newPoint) { if (newPoint is SampleControlPoint) { var existing = BinarySearch(SamplePoints, time); return newPoint.IsRedundant(existing); } return base.CheckAlreadyExisting(time, newPoint); } protected override void GroupItemAdded(ControlPoint controlPoint) { if (controlPoint is SampleControlPoint typed) samplePoints.Add(typed); base.GroupItemAdded(controlPoint); } protected override void GroupItemRemoved(ControlPoint controlPoint) { if (controlPoint is SampleControlPoint typed) samplePoints.Remove(typed); base.GroupItemRemoved(controlPoint); } } }