ソースを参照

getDurationAsNoteDuration: reenable numerator bump from 0 to 1 if tmp !== 0 (#63) (improve fraction rounding/precision)

sschmidTU 3 年 前
コミット
6c6516bd3c
1 ファイル変更5 行追加4 行削除
  1. 5 4
      src/Common/DataObjects/PlaybackSettings.ts

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

@@ -74,10 +74,11 @@ 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; // error: this turns 4/4 into 1.0009 instead of 1
-        //       -> too far in playFromMs() (see extended issue 63). better just to round.
-        // }
+        if (tmp !== 0 && numerator === 0 && milliseconds > 0) {
+            numerator = 1;
+            // tmp !== 0 necessary because otherwise 4/4 turns into e.g. 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;