فهرست منبع

player: cursor: fix cursor.NotesUnderCursor() not returning the notes at current playback position

it always returned the first notes, because the cursor's iterator was never updated from playback,
it just set the visible position.
this was a request from a developer, to be able to use NotesUnderCursor().
sschmidTU 3 سال پیش
والد
کامیت
41329c424a
1فایلهای تغییر یافته به همراه15 افزوده شده و 17 حذف شده
  1. 15 17
      src/OpenSheetMusicDisplay/Cursor.ts

+ 15 - 17
src/OpenSheetMusicDisplay/Cursor.ts

@@ -55,14 +55,13 @@ export class Cursor implements IPlaybackListener {
     this.container.appendChild(curs);
   }
   public cursorPositionChanged(timestamp: Fraction, data: CursorPosChangedData): void {
-    // if (this.iterator.CurrentEnrolledTimestamp.lt(timestamp)) {
-    //   this.iterator.moveToNext();
-    //   while (this.iterator.CurrentEnrolledTimestamp.lt(timestamp)) {
-    //     this.iterator.moveToNext();
-    //   }
-    // } else if (this.iterator.CurrentEnrolledTimestamp.gt(timestamp)) {
-    //   this.iterator = new MusicPartManagerIterator(this.manager.MusicSheet, timestamp);
-    // }
+    // update iterator so cursor.NotesUnderCursor() etc works
+    while (this.iterator.CurrentEnrolledTimestamp.lt(timestamp)) {
+      this.iterator.moveToNext();
+    }
+    if (this.iterator.CurrentEnrolledTimestamp.gt(timestamp)) {
+      this.iterator = new MusicPartManagerIterator(this.manager.MusicSheet, timestamp);
+    }
 
     this.updateWithTimestamp(data.PredictedPosition);
   }
@@ -207,12 +206,7 @@ export class Cursor implements IPlaybackListener {
     this.updateCurrentPage(); // attach cursor to new page DOM if necessary
 
     // this.graphic?.Cursors?.length = 0;
-    let iterator: MusicPartManagerIterator;
-    if (this.openSheetMusicDisplay.PlaybackManager) {
-      iterator = this.openSheetMusicDisplay.PlaybackManager.CursorIterator;
-    } else {
-      iterator = this.iterator;
-    }
+    const iterator: MusicPartManagerIterator = this.Iterator;
 
     // TODO when measure draw range (drawUpToMeasureNumber) was changed, next/update can fail to move cursor. but of course it can be reset before.
 
@@ -347,7 +341,7 @@ export class Cursor implements IPlaybackListener {
    * Go to next entry
    */
   public next(): void {
-    this.iterator.moveToNextVisibleVoiceEntry(false); // moveToNext() would not skip notes in hidden (visible = false) parts
+    this.Iterator.moveToNextVisibleVoiceEntry(false); // moveToNext() would not skip notes in hidden (visible = false) parts
     this.update();
   }
 
@@ -395,6 +389,10 @@ export class Cursor implements IPlaybackListener {
   }
 
   public get Iterator(): MusicPartManagerIterator {
+    // if (this.openSheetMusicDisplay.PlaybackManager) {
+    //   return this.openSheetMusicDisplay.PlaybackManager.CursorIterator;
+    // }
+    // PlaybackManager.CursorIterator is often not at the visible cursor position.
     return this.iterator;
   }
 
@@ -404,7 +402,7 @@ export class Cursor implements IPlaybackListener {
 
   /** returns voices under the current Cursor position. Without instrument argument, all voices are returned. */
   public VoicesUnderCursor(instrument?: Instrument): VoiceEntry[] {
-    return this.iterator.CurrentVisibleVoiceEntries(instrument);
+    return this.Iterator.CurrentVisibleVoiceEntries(instrument);
   }
 
   public NotesUnderCursor(instrument?: Instrument): Note[] {
@@ -429,7 +427,7 @@ export class Cursor implements IPlaybackListener {
    *  This is only necessary if using PageFormat (multiple pages).
    */
   public updateCurrentPage(): number {
-    const timestamp: Fraction = this.iterator.currentTimeStamp;
+    const timestamp: Fraction = this.Iterator.currentTimeStamp;
     for (const page of this.graphic.MusicPages) {
       const lastSystemTimestamp: Fraction = page.MusicSystems.last().GetSystemsLastTimeStamp();
       if (lastSystemTimestamp.gt(timestamp)) {