mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Make most common BPM more accurate
This commit is contained in:
parent
abfc5f24a3
commit
c6e9a6cd5a
@ -48,6 +48,44 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
public virtual IEnumerable<BeatmapStatistic> GetStatistics() => Enumerable.Empty<BeatmapStatistic>();
|
||||
|
||||
public double GetMostCommonBeatLength()
|
||||
{
|
||||
// The last playable time in the beatmap - the last timing point extends to this time.
|
||||
// Note: This is more accurate and may present different results because osu-stable didn't have the ability to calculate slider durations in this context.
|
||||
double lastTime = HitObjects.LastOrDefault()?.GetEndTime() ?? ControlPointInfo.TimingPoints.LastOrDefault()?.Time ?? 0;
|
||||
|
||||
var beatLengthsAndDurations =
|
||||
// Construct a set of (beatLength, duration) tuples for each individual timing point.
|
||||
ControlPointInfo.TimingPoints.Select((t, i) =>
|
||||
{
|
||||
if (t.Time > lastTime)
|
||||
return (beatLength: t.BeatLength, 0);
|
||||
|
||||
var nextTime = i == ControlPointInfo.TimingPoints.Count - 1 ? lastTime : ControlPointInfo.TimingPoints[i + 1].Time;
|
||||
return (beatLength: t.BeatLength, duration: nextTime - t.Time);
|
||||
})
|
||||
// Aggregate durations into a set of (beatLength, duration) tuples for each beat length
|
||||
.GroupBy(t => t.beatLength)
|
||||
.Select(g => (beatLength: g.Key, duration: g.Sum(t => t.duration)))
|
||||
// And if there are no timing points, use a default.
|
||||
.DefaultIfEmpty((TimingControlPoint.DEFAULT_BEAT_LENGTH, 0));
|
||||
|
||||
// Find the single beat length with the maximum aggregate duration.
|
||||
double maxDurationBeatLength = double.NegativeInfinity;
|
||||
double maxDuration = double.NegativeInfinity;
|
||||
|
||||
foreach (var (beatLength, duration) in beatLengthsAndDurations)
|
||||
{
|
||||
if (duration > maxDuration)
|
||||
{
|
||||
maxDuration = duration;
|
||||
maxDurationBeatLength = beatLength;
|
||||
}
|
||||
}
|
||||
|
||||
return 60000 / maxDurationBeatLength;
|
||||
}
|
||||
|
||||
IBeatmap IBeatmap.Clone() => Clone();
|
||||
|
||||
public Beatmap<T> Clone()
|
||||
|
@ -451,7 +451,7 @@ namespace osu.Game.Beatmaps
|
||||
// TODO: this should be done in a better place once we actually need to dynamically update it.
|
||||
beatmap.BeatmapInfo.StarDifficulty = ruleset?.CreateInstance().CreateDifficultyCalculator(new DummyConversionBeatmap(beatmap)).Calculate().StarRating ?? 0;
|
||||
beatmap.BeatmapInfo.Length = calculateLength(beatmap);
|
||||
beatmap.BeatmapInfo.BPM = beatmap.ControlPointInfo.BPMMode;
|
||||
beatmap.BeatmapInfo.BPM = beatmap.GetMostCommonBeatLength();
|
||||
|
||||
beatmapInfos.Add(beatmap.BeatmapInfo);
|
||||
}
|
||||
|
@ -101,13 +101,6 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
public double BPMMinimum =>
|
||||
60000 / (TimingPoints.OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? TimingControlPoint.DEFAULT).BeatLength;
|
||||
|
||||
/// <summary>
|
||||
/// Finds the mode BPM (most common BPM) represented by the control points.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double BPMMode =>
|
||||
60000 / (TimingPoints.GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? TimingControlPoint.DEFAULT).BeatLength;
|
||||
|
||||
/// <summary>
|
||||
/// Remove all <see cref="ControlPointGroup"/>s and return to a pristine state.
|
||||
/// </summary>
|
||||
|
@ -47,6 +47,11 @@ namespace osu.Game.Beatmaps
|
||||
/// <returns></returns>
|
||||
IEnumerable<BeatmapStatistic> GetStatistics();
|
||||
|
||||
/// <summary>
|
||||
/// Finds the most common beat length represented by the control points in this beatmap.
|
||||
/// </summary>
|
||||
double GetMostCommonBeatLength();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a shallow-clone of this beatmap and returns it.
|
||||
/// </summary>
|
||||
|
@ -84,6 +84,8 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
public IEnumerable<BeatmapStatistic> GetStatistics() => PlayableBeatmap.GetStatistics();
|
||||
|
||||
public double GetMostCommonBeatLength() => PlayableBeatmap.GetMostCommonBeatLength();
|
||||
|
||||
public IBeatmap Clone() => (EditorBeatmap)MemberwiseClone();
|
||||
|
||||
private IList mutableHitObjects => (IList)PlayableBeatmap.HitObjects;
|
||||
|
@ -39,6 +39,8 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public IEnumerable<BeatmapStatistic> GetStatistics() => PlayableBeatmap.GetStatistics();
|
||||
|
||||
public double GetMostCommonBeatLength() => PlayableBeatmap.GetMostCommonBeatLength();
|
||||
|
||||
public IBeatmap Clone() => PlayableBeatmap.Clone();
|
||||
|
||||
private readonly Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
|
||||
|
@ -391,7 +391,7 @@ namespace osu.Game.Screens.Select
|
||||
if (Precision.AlmostEquals(bpmMin, bpmMax))
|
||||
return $"{bpmMin:0}";
|
||||
|
||||
return $"{bpmMin:0}-{bpmMax:0} (mostly {beatmap.ControlPointInfo.BPMMode:0})";
|
||||
return $"{bpmMin:0}-{bpmMax:0} (mostly {beatmap.GetMostCommonBeatLength():0})";
|
||||
}
|
||||
|
||||
private OsuSpriteText[] getMapper(BeatmapMetadata metadata)
|
||||
|
Loading…
Reference in New Issue
Block a user