1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 12:22:57 +08:00

Move BPM calculations to Beatmap.

This commit is contained in:
Dean Herbert 2017-01-30 16:03:45 +09:00
parent 8f1e7ef19a
commit 9f90b57543
2 changed files with 11 additions and 12 deletions

View File

@ -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<HitObject> HitObjects { get; set; }
public List<ControlPoint> ControlPoints { get; set; }
public List<Color4> 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)
{

View File

@ -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