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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user