Add TimeTimingModel.

This commit is contained in:
2022-12-13 10:51:05 +08:00
parent b582da90e5
commit f5df56687b
2 changed files with 18 additions and 1 deletions

View File

@@ -16,6 +16,11 @@ namespace Cryville.Crtr {
n = _n;
d = _d;
}
public BeatTime(int _n, int _d) {
b = _n / _d;
n = _n % _d;
d = _d;
}
[JsonIgnore]
public int b;

View File

@@ -39,4 +39,16 @@ namespace Cryville.Crtr.Extensions {
return new BeatTime(i, n, d);
}
}
public class TimeTimingModel : TimingModel {
public TimeTimingModel(double offset = 0) : base(offset) { }
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);
FractionalBeatTime = new BeatTime(n, d);
Time = t;
}
}
}