mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 01:47:30 +09:00
Merge pull request #11495 from smoogipoo/more-accurate-most-common-bpm
Make most common BPM more accurate
This commit is contained in:
commit
0dd1b1026c
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Game.Beatmaps.Timing;
|
using osu.Game.Beatmaps.Timing;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -48,6 +49,31 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public virtual IEnumerable<BeatmapStatistic> GetStatistics() => Enumerable.Empty<BeatmapStatistic>();
|
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 mostCommon =
|
||||||
|
// 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 => Math.Round(t.beatLength * 1000) / 1000)
|
||||||
|
.Select(g => (beatLength: g.Key, duration: g.Sum(t => t.duration)))
|
||||||
|
// Get the most common one, or 0 as a suitable default
|
||||||
|
.OrderByDescending(i => i.duration).FirstOrDefault();
|
||||||
|
|
||||||
|
return mostCommon.beatLength;
|
||||||
|
}
|
||||||
|
|
||||||
IBeatmap IBeatmap.Clone() => Clone();
|
IBeatmap IBeatmap.Clone() => Clone();
|
||||||
|
|
||||||
public Beatmap<T> Clone() => (Beatmap<T>)MemberwiseClone();
|
public Beatmap<T> Clone() => (Beatmap<T>)MemberwiseClone();
|
||||||
|
@ -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.
|
// 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.StarDifficulty = ruleset?.CreateInstance().CreateDifficultyCalculator(new DummyConversionBeatmap(beatmap)).Calculate().StarRating ?? 0;
|
||||||
beatmap.BeatmapInfo.Length = calculateLength(beatmap);
|
beatmap.BeatmapInfo.Length = calculateLength(beatmap);
|
||||||
beatmap.BeatmapInfo.BPM = beatmap.ControlPointInfo.BPMMode;
|
beatmap.BeatmapInfo.BPM = 60000 / beatmap.GetMostCommonBeatLength();
|
||||||
|
|
||||||
beatmapInfos.Add(beatmap.BeatmapInfo);
|
beatmapInfos.Add(beatmap.BeatmapInfo);
|
||||||
}
|
}
|
||||||
|
@ -101,13 +101,6 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
public double BPMMinimum =>
|
public double BPMMinimum =>
|
||||||
60000 / (TimingPoints.OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? TimingControlPoint.DEFAULT).BeatLength;
|
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>
|
/// <summary>
|
||||||
/// Remove all <see cref="ControlPointGroup"/>s and return to a pristine state.
|
/// Remove all <see cref="ControlPointGroup"/>s and return to a pristine state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -47,6 +47,11 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IEnumerable<BeatmapStatistic> GetStatistics();
|
IEnumerable<BeatmapStatistic> GetStatistics();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the most common beat length represented by the control points in this beatmap.
|
||||||
|
/// </summary>
|
||||||
|
double GetMostCommonBeatLength();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a shallow-clone of this beatmap and returns it.
|
/// Creates a shallow-clone of this beatmap and returns it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -88,6 +88,8 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
public IEnumerable<BeatmapStatistic> GetStatistics() => PlayableBeatmap.GetStatistics();
|
public IEnumerable<BeatmapStatistic> GetStatistics() => PlayableBeatmap.GetStatistics();
|
||||||
|
|
||||||
|
public double GetMostCommonBeatLength() => PlayableBeatmap.GetMostCommonBeatLength();
|
||||||
|
|
||||||
public IBeatmap Clone() => (EditorBeatmap)MemberwiseClone();
|
public IBeatmap Clone() => (EditorBeatmap)MemberwiseClone();
|
||||||
|
|
||||||
private IList mutableHitObjects => (IList)PlayableBeatmap.HitObjects;
|
private IList mutableHitObjects => (IList)PlayableBeatmap.HitObjects;
|
||||||
|
@ -43,6 +43,8 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public IEnumerable<BeatmapStatistic> GetStatistics() => PlayableBeatmap.GetStatistics();
|
public IEnumerable<BeatmapStatistic> GetStatistics() => PlayableBeatmap.GetStatistics();
|
||||||
|
|
||||||
|
public double GetMostCommonBeatLength() => PlayableBeatmap.GetMostCommonBeatLength();
|
||||||
|
|
||||||
public IBeatmap Clone() => PlayableBeatmap.Clone();
|
public IBeatmap Clone() => PlayableBeatmap.Clone();
|
||||||
|
|
||||||
private readonly Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
|
private readonly Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
|
||||||
|
@ -391,7 +391,7 @@ namespace osu.Game.Screens.Select
|
|||||||
if (Precision.AlmostEquals(bpmMin, bpmMax))
|
if (Precision.AlmostEquals(bpmMin, bpmMax))
|
||||||
return $"{bpmMin:0}";
|
return $"{bpmMin:0}";
|
||||||
|
|
||||||
return $"{bpmMin:0}-{bpmMax:0} (mostly {beatmap.ControlPointInfo.BPMMode:0})";
|
return $"{bpmMin:0}-{bpmMax:0} (mostly {60000 / beatmap.GetMostCommonBeatLength():0})";
|
||||||
}
|
}
|
||||||
|
|
||||||
private OsuSpriteText[] getMapper(BeatmapMetadata metadata)
|
private OsuSpriteText[] getMapper(BeatmapMetadata metadata)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user