diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs
index d9e92f1264..c3e2b469ae 100644
--- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs
+++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs
@@ -14,7 +14,7 @@ namespace osu.Game.Beatmaps.ControlPoints
public class ControlPointInfo
{
///
- /// Control point groups.
+ /// All control points grouped by time.
///
[JsonProperty]
public IBindableList Groups => groups;
@@ -107,6 +107,62 @@ namespace osu.Game.Beatmaps.ControlPoints
public double BPMMode =>
60000 / (TimingPoints.GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? new TimingControlPoint()).BeatLength;
+ ///
+ /// Remove all s and return to a pristine state.
+ ///
+ public void Clear()
+ {
+ groups.Clear();
+ timingPoints.Clear();
+ difficultyPoints.Clear();
+ samplePoints.Clear();
+ effectPoints.Clear();
+ }
+
+ ///
+ /// Add a new . Note that the provided control point may not be added if the correct state is already present at the provided time.
+ ///
+ /// The time at which the control point should be added.
+ /// The control point to add.
+ /// Whether the control point was added.
+ public bool Add(double time, ControlPoint controlPoint)
+ {
+ if (checkAlreadyExisting(time, controlPoint))
+ return false;
+
+ GroupAt(time, true).Add(controlPoint);
+ return true;
+ }
+
+ public ControlPointGroup GroupAt(double time, bool addIfNotExisting = false)
+ {
+ var newGroup = new ControlPointGroup(time);
+
+ int i = groups.BinarySearch(newGroup);
+
+ if (i >= 0)
+ return groups[i];
+
+ if (addIfNotExisting)
+ {
+ newGroup.ItemAdded += groupItemAdded;
+ newGroup.ItemRemoved += groupItemRemoved;
+
+ groups.Insert(~i, newGroup);
+ return newGroup;
+ }
+
+ return null;
+ }
+
+ public void RemoveGroup(ControlPointGroup group)
+ {
+ group.ItemAdded -= groupItemAdded;
+ group.ItemRemoved -= groupItemRemoved;
+
+ groups.Remove(group);
+ }
+
///
/// Binary searches one of the control point lists to find the active control point at .
/// Includes logic for returning a specific point when no matching point is found.
@@ -161,33 +217,6 @@ namespace osu.Game.Beatmaps.ControlPoints
return list[l - 1];
}
- public void Add(double time, ControlPoint newPoint, bool force = false)
- {
- if (!force && checkAlreadyExisting(time, newPoint))
- return;
-
- GroupAt(time, true).Add(newPoint);
- }
-
- public ControlPointGroup GroupAt(double time, bool createIfNotExisting = false)
- {
- var existing = Groups.FirstOrDefault(g => g.Time == time);
-
- if (existing != null)
- return existing;
-
- if (createIfNotExisting)
- {
- var newGroup = new ControlPointGroup(time);
- newGroup.ItemAdded += groupItemAdded;
- newGroup.ItemRemoved += groupItemRemoved;
- groups.Add(newGroup);
- return newGroup;
- }
-
- return null;
- }
-
///
/// Check whether should be added.
///
@@ -221,31 +250,9 @@ namespace osu.Game.Beatmaps.ControlPoints
return existing?.EquivalentTo(newPoint) == true;
}
- private void groupItemRemoved(ControlPoint obj)
+ private void groupItemAdded(ControlPoint controlPoint)
{
- switch (obj)
- {
- case TimingControlPoint typed:
- timingPoints.Remove(typed);
- break;
-
- case EffectControlPoint typed:
- effectPoints.Remove(typed);
- break;
-
- case SampleControlPoint typed:
- samplePoints.Remove(typed);
- break;
-
- case DifficultyControlPoint typed:
- difficultyPoints.Remove(typed);
- break;
- }
- }
-
- private void groupItemAdded(ControlPoint obj)
- {
- switch (obj)
+ switch (controlPoint)
{
case TimingControlPoint typed:
timingPoints.Add(typed);
@@ -265,29 +272,26 @@ namespace osu.Game.Beatmaps.ControlPoints
}
}
- public void Clear()
+ private void groupItemRemoved(ControlPoint controlPoint)
{
- groups.Clear();
- timingPoints.Clear();
- difficultyPoints.Clear();
- samplePoints.Clear();
- effectPoints.Clear();
+ switch (controlPoint)
+ {
+ case TimingControlPoint typed:
+ timingPoints.Remove(typed);
+ break;
+
+ case EffectControlPoint typed:
+ effectPoints.Remove(typed);
+ break;
+
+ case SampleControlPoint typed:
+ samplePoints.Remove(typed);
+ break;
+
+ case DifficultyControlPoint typed:
+ difficultyPoints.Remove(typed);
+ break;
+ }
}
-
- public ControlPointGroup CreateGroup(double time)
- {
- var newGroup = new ControlPointGroup(time);
-
- int i = groups.BinarySearch(newGroup);
-
- if (i > 0)
- return groups[i];
-
- groups.Insert(~i, newGroup);
-
- return newGroup;
- }
-
- public void RemoveGroup(ControlPointGroup group) => groups.Remove(group);
}
}