浏览代码

fix(Playback): Fix multiple measure rests stopping playback (and sometimes infinite loop)

sschmidTU 3 年之前
父节点
当前提交
981cd597b5
共有 2 个文件被更改,包括 6 次插入2 次删除
  1. 2 1
      src/OpenSheetMusicDisplay/Cursor.ts
  2. 4 1
      src/Playback/PlaybackManager.ts

+ 2 - 1
src/OpenSheetMusicDisplay/Cursor.ts

@@ -56,7 +56,8 @@ export class Cursor implements IPlaybackListener {
   }
   public cursorPositionChanged(timestamp: Fraction, data: CursorPosChangedData): void {
     // update iterator so cursor.NotesUnderCursor() etc works
-    while (this.iterator.CurrentEnrolledTimestamp.lt(timestamp)) {
+    while (this.iterator.CurrentEnrolledTimestamp.lt(timestamp) && !this.iterator.EndReached) {
+      // if iterator.EndReached, this would loop endlessly, because then moveToNext() just returns, without changes
       this.iterator.moveToNext();
     }
     if (this.iterator.CurrentEnrolledTimestamp.gt(timestamp)) {

+ 4 - 1
src/Playback/PlaybackManager.ts

@@ -576,7 +576,10 @@ export class PlaybackManager implements IPlaybackParametersListener {
             // console.log("TS ms: " + this.timingSource.getCurrentTimeInMs());
             // console.log("TS ts: " + this.currentTimestamp);
             endHasBeenReached = this.cursorIterator.EndReached;
-            if (!this.cursorIterator.CurrentMeasure.WasRendered) {
+            // TODO cursorIterator.CurrentMeasure can be undefined (at the end of the piece?)
+            const currentMeasure: SourceMeasure = this.cursorIterator.CurrentMeasure;
+            if (currentMeasure && !currentMeasure.WasRendered && !currentMeasure.isReducedToMultiRest) {
+                // stop if current measure is not rendered, but not if it's part of a multi-measure rest
                 endHasBeenReached = true;
             }