Преглед изворни кода

fix(Cursor jumping around): Instead first staffentry the minimum is c… (#377)

* fix(Cursor jumping around): Instead first staffentry the minimum is calculated and taken as x refere

#376

* docs(Cursor jumoing): Added more detailed description of code
Benjamin Giesinger пре 6 година
родитељ
комит
f43e30592f
1 измењених фајлова са 10 додато и 5 уклоњено
  1. 10 5
      src/OpenSheetMusicDisplay/Cursor.ts

+ 10 - 5
src/OpenSheetMusicDisplay/Cursor.ts

@@ -47,6 +47,12 @@ export class Cursor {
     // this.openSheetMusicDisplay.render();
   }
 
+  private getStaffEntriesFromVoiceEntry(voiceEntry: VoiceEntry): VexFlowStaffEntry {
+    const measureIndex: number = voiceEntry.ParentSourceStaffEntry.VerticalContainerParent.ParentMeasure.measureListIndex;
+    const staffIndex: number = voiceEntry.ParentSourceStaffEntry.ParentStaff.idInMusicSheet;
+    return <VexFlowStaffEntry>this.graphic.findGraphicalStaffEntryFromMeasureList(staffIndex, measureIndex, voiceEntry.ParentSourceStaffEntry);
+  }
+
   public update(): void {
     // Warning! This should NEVER call this.openSheetMusicDisplay.render()
     if (this.hidden) {
@@ -59,12 +65,11 @@ export class Cursor {
     }
     let x: number = 0, y: number = 0, height: number = 0;
 
-    const voiceEntry: VoiceEntry = iterator.CurrentVoiceEntries[0];
-    const measureIndex: number = voiceEntry.ParentSourceStaffEntry.VerticalContainerParent.ParentMeasure.measureListIndex;
-    const staffIndex: number = voiceEntry.ParentSourceStaffEntry.ParentStaff.idInMusicSheet;
+    // get all staff entries inside the current voice entry
+    const gseArr: VexFlowStaffEntry[] = iterator.CurrentVoiceEntries.map(ve => this.getStaffEntriesFromVoiceEntry(ve));
+    // sort them by x position and take the leftmost entry
     const gse: VexFlowStaffEntry =
-      <VexFlowStaffEntry>this.graphic.findGraphicalStaffEntryFromMeasureList(staffIndex, measureIndex, voiceEntry.ParentSourceStaffEntry);
-
+          gseArr.sort((a, b) => a.PositionAndShape.AbsolutePosition.x <= b.PositionAndShape.AbsolutePosition.x ? -1 : 1 )[0];
     x = gse.PositionAndShape.AbsolutePosition.x;
     const musicSystem: MusicSystem = gse.parentMeasure.parentMusicSystem;
     y = musicSystem.PositionAndShape.AbsolutePosition.y + musicSystem.StaffLines[0].PositionAndShape.RelativePosition.y;