diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 5683663816..7151a13b74 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -2,6 +2,7 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; +using System.Linq; using OpenTK.Graphics; using osu.Game.Beatmaps.Timing; using osu.Game.Database; @@ -16,6 +17,9 @@ namespace osu.Game.Beatmaps public List HitObjects { get; set; } public List ControlPoints { get; set; } public List ComboColors { get; set; } + public double BPMMaximum => 60000 / ControlPoints.Where(c => c.BeatLength != 0).OrderBy(c => c.BeatLength).First().BeatLength; + public double BPMMinimum => 60000 / ControlPoints.Where(c => c.BeatLength != 0).OrderByDescending(c => c.BeatLength).First().BeatLength; + public double BPMMode => BPMAt(ControlPoints.Where(c => c.BeatLength != 0).GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).First().First().Time); public double BPMAt(double time) { diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index 93280cbe4f..964f4552ba 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -17,6 +17,7 @@ using osu.Framework.Graphics.Colour; using osu.Game.Beatmaps.Drawables; using System.Linq; using osu.Framework.Extensions.IEnumerableExtensions; +using osu.Framework.MathUtils; using osu.Game.Graphics; using osu.Game.Beatmaps.Timing; using osu.Game.Modes; @@ -190,18 +191,12 @@ namespace osu.Game.Screens.Select private string getBPMRange(Beatmap beatmap) { - double bpmMax = double.MinValue; - double bpmMin = double.MaxValue; - double bpmMost = beatmap.BPMAt(beatmap.ControlPoints.Where(c => c.BeatLength != 0).GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).First().First().Time); - foreach (ControlPoint a in beatmap.ControlPoints) - { - if (a.BeatLength == 0) continue; - double tmp = beatmap.BPMAt(a.Time); - if (bpmMax < tmp) bpmMax = tmp; - if (bpmMin > tmp) bpmMin = tmp; - } - if (bpmMax == bpmMin) return Math.Round(bpmMin) + "bpm"; - return Math.Round(bpmMin) + "-" + Math.Round(bpmMax) + "bpm (mostly " + Math.Round(bpmMost) + "bpm)"; + double bpmMax = beatmap.BPMMaximum; + double bpmMin = beatmap.BPMMinimum; + + if (Precision.AlmostEquals(bpmMin, bpmMax)) return Math.Round(bpmMin) + "bpm"; + + return Math.Round(bpmMin) + "-" + Math.Round(bpmMax) + "bpm (mostly " + Math.Round(beatmap.BPMMode) + "bpm)"; } public class InfoLabel : Container