Pull up FractionalBeatTimeTimingModel.
This commit is contained in:
@@ -9,7 +9,7 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
[JsonConverter(typeof(BeatTimeConverter))]
|
||||
public struct BeatTime {
|
||||
public struct BeatTime : IComparable<BeatTime>, IEquatable<BeatTime> {
|
||||
[JsonConstructor()]
|
||||
public BeatTime(int _b, int _n, int _d) {
|
||||
b = _b;
|
||||
@@ -25,6 +25,36 @@ namespace Cryville.Crtr {
|
||||
|
||||
[JsonIgnore]
|
||||
public int d;
|
||||
|
||||
[JsonIgnore]
|
||||
public double Decimal { get { return b + (double)n / d; } }
|
||||
|
||||
public int CompareTo(BeatTime other) {
|
||||
var c = b.CompareTo(other.b);
|
||||
if (c != 0) return c;
|
||||
return ((double)n / d).CompareTo((double)other.n / other.d);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
if (!(obj is BeatTime)) return false;
|
||||
return Equals((BeatTime)obj);
|
||||
}
|
||||
|
||||
public bool Equals(BeatTime other) {
|
||||
return b.Equals(other.b) && ((double)n / d).Equals((double)other.n / other.d);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return Decimal.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(BeatTime left, BeatTime right) {
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(BeatTime left, BeatTime right) {
|
||||
return !left.Equals(right);
|
||||
}
|
||||
}
|
||||
|
||||
public class BeatTimeConverter : JsonConverter {
|
||||
@@ -56,7 +86,7 @@ namespace Cryville.Crtr {
|
||||
[JsonIgnore]
|
||||
public float BeatPosition {
|
||||
get {
|
||||
return time.Value.b + time.Value.n / (float)time.Value.d + BeatOffset;
|
||||
return (float)time.Value.Decimal + BeatOffset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +96,7 @@ namespace Cryville.Crtr {
|
||||
public float EndBeatPosition {
|
||||
get {
|
||||
if (endtime == null) return BeatPosition;
|
||||
return endtime.Value.b + endtime.Value.n / (float)endtime.Value.d + BeatOffset;
|
||||
return (float)endtime.Value.Decimal + BeatOffset;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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 {
|
||||
|
20
Assets/Cryville/Crtr/Extensions/TimingModel.cs
Normal file
20
Assets/Cryville/Crtr/Extensions/TimingModel.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace Cryville.Crtr.Extensions {
|
||||
public abstract class TimingModel {
|
||||
public double Time { get; protected set; }
|
||||
public double BeatTime { get; protected set; }
|
||||
public BeatTime FractionalBeatTime { get; protected set; }
|
||||
public double BPM { get; set; }
|
||||
public TimingModel() {
|
||||
FractionalBeatTime = new BeatTime(0, 0, 1);
|
||||
}
|
||||
}
|
||||
public class FractionalBeatTimeTimingModel : TimingModel {
|
||||
public void ForwardTo(BeatTime t) {
|
||||
if (t == FractionalBeatTime) return;
|
||||
FractionalBeatTime = t;
|
||||
var nt = t.Decimal;
|
||||
Time += (nt - BeatTime) / BPM * 60;
|
||||
BeatTime = nt;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Extensions/TimingModel.cs.meta
Normal file
11
Assets/Cryville/Crtr/Extensions/TimingModel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c4a1fab8f53dd742ba6501d682eb7f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user