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

@@ -36,15 +36,12 @@ namespace Cryville.Crtr.Extensions.Bestdori {
motions = new List<Chart.Motion>(),
groups = new List<Chart.Group> { group },
};
var tm = new BeatTimeTimingModel();
string bgm = null;
double? cbpm = null;
double pbeat = 0, ctime = 0;
double endbeat = 0;
foreach (var ev in src) {
double cbeat = ev.StartBeat;
ctime += cbpm == null ? 0 : (cbeat - pbeat) / cbpm.Value * 60;
pbeat = cbeat;
if (cbeat > endbeat) endbeat = cbeat;
tm.ForwardTo(ev.StartBeat);
if (ev.StartBeat > endbeat) endbeat = ev.StartBeat;
if (ev is BestdoriChartEvent.System) {
if (bgm != null) continue;
var tev = (BestdoriChartEvent.System)ev;
@@ -55,7 +52,7 @@ namespace Cryville.Crtr.Extensions.Bestdori {
}
else if (ev is BestdoriChartEvent.BPM) {
var tev = (BestdoriChartEvent.BPM)ev;
cbpm = tev.bpm;
tm.BPM = tev.bpm;
chart.sigs.Add(new Chart.Signature { time = ToBeatTime(tev.beat), tempo = (float)tev.bpm });
}
else if (ev is BestdoriChartEvent.Single) {
@@ -95,12 +92,13 @@ namespace Cryville.Crtr.Extensions.Bestdori {
}
if (bgm == null) throw new FormatException("Chart contains no song");
chart.endtime = ToBeatTime(endbeat + 4);
if (endbeat > tm.BeatTime) tm.ForwardTo(endbeat);
result.Add(new RawChartResource(string.Format("bang_dream_girls_band_party__{0}__{1}", bgm, StringUtils.TrimExt(file.Name)), chart, new ChartMeta {
name = string.Format("Bandori {0} {1}", bgm, StringUtils.TrimExt(file.Name)),
author = "©BanG Dream! Project ©Craft Egg Inc. ©bushiroad",
ruleset = "bang_dream_girls_band_party",
note_count = group.notes.Count,
length = (float)ctime,
length = (float)tm.Time,
song = new SongMetaInfo {
name = bgm,
author = "©BanG Dream! Project ©Craft Egg Inc. ©bushiroad",

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);
}
}
}