Pull up BeatTimeTimingModel.

This commit is contained in:
2022-12-13 08:59:35 +08:00
parent 4b4356aaab
commit 1470fa87dd
2 changed files with 23 additions and 9 deletions

View File

@@ -1,4 +1,6 @@
namespace Cryville.Crtr.Extensions {
using Cryville.Common.Math;
namespace Cryville.Crtr.Extensions {
public abstract class TimingModel {
public double Time { get; protected set; }
public double BeatTime { get; protected set; }
@@ -17,4 +19,18 @@
BeatTime = nt;
}
}
public class BeatTimeTimingModel : TimingModel {
public void ForwardTo(double t) {
if (t == BeatTime) return;
Time += (t - BeatTime) / BPM * 60;
BeatTime = t;
FractionalBeatTime = ToBeatTime(t);
}
BeatTime ToBeatTime(double beat, double error = 1e-4) {
int i, n, d;
FractionUtils.ToFraction(beat, error, out n, out d);
i = n / d; n %= d;
return new BeatTime(i, n, d);
}
}
}