osu/osu.Game/Beatmaps/Beatmap.cs

52 lines
2.0 KiB
C#
Raw Normal View History

//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
2017-01-30 07:03:45 +00:00
using System.Linq;
2016-10-10 17:00:16 +00:00
using OpenTK.Graphics;
using osu.Game.Beatmaps.Timing;
2016-10-18 17:35:01 +00:00
using osu.Game.Database;
2016-11-14 09:03:20 +00:00
using osu.Game.Modes.Objects;
namespace osu.Game.Beatmaps
{
public class Beatmap
{
2016-10-18 17:35:01 +00:00
public BeatmapInfo BeatmapInfo { get; set; }
public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata;
public List<HitObject> HitObjects { get; set; }
public List<ControlPoint> ControlPoints { get; set; }
2016-10-10 17:00:16 +00:00
public List<Color4> ComboColors { get; set; }
2017-01-30 07:03:45 +00:00
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);
2016-12-17 18:57:58 +00:00
public double BPMAt(double time)
{
return 60000 / BeatLengthAt(time);
}
public double BeatLengthAt(double time, bool applyMultipliers = false)
{
int point = 0;
int samplePoint = 0;
for (int i = 0; i < ControlPoints.Count; i++)
if (ControlPoints[i].Time <= time)
{
if (ControlPoints[i].TimingChange)
point = i;
else
samplePoint = i;
}
double mult = 1;
2016-12-03 13:52:51 +00:00
if (applyMultipliers && samplePoint > point)
mult = ControlPoints[samplePoint].VelocityAdjustment;
return ControlPoints[point].BeatLength * mult;
}
}
}