Pull up FractionalBeatTimeTimingModel.

This commit is contained in:
2022-12-12 23:48:15 +08:00
parent a8658856ca
commit 4b4356aaab
4 changed files with 79 additions and 24 deletions

View File

@@ -73,30 +73,28 @@ namespace Cryville.Crtr.Extensions.Malody {
Dictionary<MalodyChart.IEvent, StartEventState> longEvents
= new Dictionary<MalodyChart.IEvent, StartEventState>();
float? baseBpm = null, cbpm = null;
float pbeat = 0f, ctime = 0f;
int[] endbeat = new int[] { 0, 0, 1 };
float? baseBpm = null;
var tm = new FractionalBeatTimeTimingModel();
foreach (var ev in events) {
float cbeat = ConvertBeat(ev.beat);
ctime += cbpm == null ? 0 : (cbeat - pbeat) / cbpm.Value * 60f;
pbeat = cbeat;
var beat = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]);
tm.ForwardTo(beat);
if (ev is MalodyChart.Time) {
var tev = (MalodyChart.Time)ev;
if (baseBpm == null) baseBpm = tev.bpm;
cbpm = tev.bpm;
tm.BPM = tev.bpm;
chart.sigs.Add(new Chart.Signature {
time = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]),
time = beat,
tempo = tev.bpm,
});
chart.motions.Add(new Chart.Motion {
time = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]),
time = beat,
motion = "svm:" + (tev.bpm / baseBpm.Value).ToString(CultureInfo.InvariantCulture)
});
}
else if (ev is MalodyChart.Effect) {
var tev = (MalodyChart.Effect)ev;
if (tev.scroll != null) group.motions.Add(new Chart.Motion {
time = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]),
time = beat,
motion = "svm:" + tev.scroll.Value.ToString(CultureInfo.InvariantCulture)
});
}
@@ -115,19 +113,17 @@ namespace Cryville.Crtr.Extensions.Malody {
else throw new NotImplementedException();
}
else {
if (ConvertBeat(tev.beat) > ConvertBeat(endbeat)) endbeat = tev.beat;
var rn = new Chart.Note() {
time = new BeatTime(tev.beat[0], tev.beat[1], tev.beat[2]),
time = beat,
motions = new List<Chart.Motion> {
new Chart.Motion() { motion = "track:" + tev.column.ToString(CultureInfo.InvariantCulture) }
},
};
if (tev.endbeat != null) {
if (ConvertBeat(tev.endbeat) > ConvertBeat(endbeat)) endbeat = tev.endbeat;
rn.endtime = new BeatTime(tev.endbeat[0], tev.endbeat[1], tev.endbeat[2]);
longEvents.Add(ev, new StartEventState {
Destination = rn,
Time = ctime,
Time = tm.Time,
});
}
group.notes.Add(rn);
@@ -143,8 +139,10 @@ namespace Cryville.Crtr.Extensions.Malody {
}
else throw new NotSupportedException();
}
chart.endtime = new BeatTime(endbeat[0] + 4, endbeat[1], endbeat[2]);
meta.length = ctime;
var endbeat = tm.FractionalBeatTime;
endbeat.b += 4;
chart.endtime = endbeat;
meta.length = (float)tm.Time;
meta.note_count = group.notes.Count;
string chartName = string.Format("{0} - {1}", meta.song.name, meta.name);
if (src.meta.background != null) {
@@ -155,14 +153,10 @@ namespace Cryville.Crtr.Extensions.Malody {
}
struct StartEventState {
public float Time { get; set; }
public double Time { get; set; }
public ChartEvent Destination { get; set; }
}
float ConvertBeat(int[] beat) {
return beat[0] + (float)beat[1] / beat[2];
}
#pragma warning disable IDE1006
struct MalodyChart {
public interface IEvent {