Prechádzať zdrojové kódy

fix playFromMs() and getTimestampFromMs() rounding error (#63), playFromMs() starting too late

prior to this, getTimeStampFromMs(4000) would return a realValue 1.0009,
so in playFromMs(4000), it would start in the next timestamp after the one at 4 seconds.
sschmidTU 3 rokov pred
rodič
commit
2c87df393e

+ 4 - 3
src/Common/DataObjects/PlaybackSettings.ts

@@ -74,9 +74,10 @@ export class PlaybackSettings {
         // now approximate as good as possible by using fractionPrecision as smallest fraction
         const tmp: number = numBeats - numerator;
         numerator = <number>Math.round(tmp / (1.0 / fractionPrecision) / 4);
-        if (numerator === 0 && milliseconds > 0) {
-            numerator = 1;
-        }
+        // if (numerator === 0 && milliseconds > 0) {
+        //     numerator = 1; // error: this turns 4/4 into 1.0009 instead of 1
+        //       -> too far in playFromMs() (see extended issue 63). better just to round.
+        // }
         // add the 2 fractions
         ret.Add(new Fraction(numerator, fractionPrecision));
         return ret;