فهرست منبع

improve PlaybackManager.getSheetDurationInMs to respect each measure's bpm, also the first one's.

related to #62
sschmidTU 3 سال پیش
والد
کامیت
3cc323760d
1فایلهای تغییر یافته به همراه17 افزوده شده و 1 حذف شده
  1. 17 1
      src/Playback/PlaybackManager.ts

+ 17 - 1
src/Playback/PlaybackManager.ts

@@ -1286,8 +1286,24 @@ export class PlaybackManager implements IPlaybackParametersListener {
         }
     }
 
-    /** Returns the duration of the piece in ms. Including repeats. */
+    /** Returns the duration of the piece in ms (by each measure's bpm, without repeats).
+     *  The result may be inaccurate if you haven't set the bpm to the first measure's bpm before playback.
+     *  In that case, getSheetDurationInMsEvenBpm() can be more accurate (previous version of this method)
+     */
     public getSheetDurationInMs(): number {
+        let totalDuration: number = 0;
+        // code similar to PlaybackSettings.getDurationInMilliseconds()
+        const beatRealValue: number = 1.0 / 4.0;
+        for (const measure of this.musicPartManager.MusicSheet.SourceMeasures) {
+            const beatLengthInMs: number = 60000.0 / measure.TempoInBPM;
+            totalDuration += measure.Duration.RealValue * beatLengthInMs / beatRealValue;
+
+        }
+        return totalDuration;
+    }
+
+    /** Returns the sheet duration of the piece in ms given the tempo set via setBpm() doesn't change. */
+    public getSheetDurationInMsEvenBpm(): number {
         return this.timingSource.getDurationInMs(this.musicPartManager.MusicSheet.SheetEndTimestamp);
     }