Fix inaccurate beat snapping for osu charts. Fix osu charts with too low BPM not able to be imported.

This commit is contained in:
2023-03-05 20:40:02 +08:00
parent 6d74685cb7
commit 1851bd3c54
3 changed files with 16 additions and 6 deletions

View File

@@ -42,15 +42,24 @@ namespace Cryville.Crtr.Extensions {
}
}
public class TimeTimingModel : TimingModel {
public TimeTimingModel(double offset = 0) : base(offset) { }
public readonly double InputTimeAccuracy;
public TimeTimingModel(double accuracy = 2e-3, double offset = 0) : base(offset) {
if (accuracy <= 0) throw new ArgumentOutOfRangeException("accuracy");
InputTimeAccuracy = accuracy;
}
public void ForwardTo(double t) {
if (t == Time) return;
if (BPM == 0) throw new InvalidOperationException("BPM not determined");
BeatTime += (t - Time) * BPM / 60;
int n, d;
FractionUtils.ToFraction(BeatTime, 1f / 48 / BPM * 60, out n, out d);
FractionUtils.ToFraction(BeatTime, Math.Min(1, InputTimeAccuracy * BPM / 60), out n, out d);
FractionalBeatTime = new BeatTime(n, d);
Time = t;
}
public void ForceSnap() {
var alignedBeat = (int)Math.Round(BeatTime);
BeatTime = alignedBeat;
FractionalBeatTime = new BeatTime(alignedBeat, 1);
}
}
}