mirror of
https://github.com/SirusDoma/VoxCharger.git
synced 2025-02-17 10:58:32 +01:00
Fix incorrect time formula
This commit is contained in:
parent
1e9878672e
commit
9641c03539
@ -44,17 +44,24 @@ namespace VoxCharger
|
|||||||
public static Time FromOffset(float absOffset, (int beat, int note) signature)
|
public static Time FromOffset(float absOffset, (int beat, int note) signature)
|
||||||
{
|
{
|
||||||
float remaining = (absOffset % 192f) % (192f / signature.beat);
|
float remaining = (absOffset % 192f) % (192f / signature.beat);
|
||||||
float divisor = (192f / signature.beat);
|
float division = ((192f / signature.beat) / signature.note);
|
||||||
|
|
||||||
int measure = (int)(absOffset / 192f);
|
int measure = (int)(absOffset / 192f);
|
||||||
int beat = (int)((absOffset % 192f) / divisor) + 1;
|
int beat = (int)((absOffset % 192f) / (192f / signature.beat)) + 1;
|
||||||
int offset = (int)Math.Round((remaining / (divisor / signature.note)) * ((192f / 4f) / 4f));
|
int offset = (int)Math.Round((remaining / division) * ((192f / 4f) / 4f));
|
||||||
|
|
||||||
// Since the value rounded up, there's chance this happen (precision rounding problem)
|
// Since the value rounded up, there's chance this happen (precision rounding problem)
|
||||||
beat += offset / 48;
|
beat += offset / 48;
|
||||||
measure += beat > signature.beat ? 1 : 0;
|
offset %= 48;
|
||||||
beat = beat > signature.beat ? signature.beat - (beat - 1) : beat;
|
|
||||||
offset %= 48;
|
measure += beat / signature.beat;
|
||||||
|
beat %= signature.beat;
|
||||||
|
|
||||||
|
if (beat == 0)
|
||||||
|
{
|
||||||
|
measure -= 1;
|
||||||
|
beat = signature.beat;
|
||||||
|
}
|
||||||
|
|
||||||
return new Time(measure, beat, offset);
|
return new Time(measure, beat, offset);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user