Make snapped time always positive

This commit is contained in:
ansel 2023-01-12 03:38:57 +03:00
parent 03ac2fd7d7
commit 51e21ee6f0
1 changed files with 8 additions and 2 deletions

View File

@ -183,9 +183,15 @@ public int GetClosestBeatDivisor(double time, double? referenceTime = null)
private static double getClosestSnappedTime(TimingControlPoint timingPoint, double time, int beatDivisor)
{
double beatLength = timingPoint.BeatLength / beatDivisor;
int beatLengths = (int)Math.Round((time - timingPoint.Time) / beatLength, MidpointRounding.AwayFromZero);
double beats = (Math.Max(time, 0) - timingPoint.Time) / beatLength;
return timingPoint.Time + beatLengths * beatLength;
int roundedBeats = (int)Math.Round(beats, MidpointRounding.AwayFromZero);
double snappedTime = timingPoint.Time + roundedBeats * beatLength;
if (snappedTime >= 0)
return snappedTime;
return snappedTime + beatLength;
}
/// <summary>