Explorar o código

Merge PR #34 from fix/top-measure-number

Prevent negative topMeasureNumber in pieces with precount measures (measure 0)
Simon %!s(int64=3) %!d(string=hai) anos
pai
achega
3ec90baa75
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      src/OpenSheetMusicDisplay/Cursor.ts

+ 3 - 1
src/OpenSheetMusicDisplay/Cursor.ts

@@ -151,7 +151,9 @@ export class Cursor implements IPlaybackListener {
     this.updateCurrentPageFromSystem(currentSystem);
     const previousStaffEntry: GraphicalStaffEntry = values[2];
 
-    const topMeasureNumber: number = previousStaffEntry.parentMeasure.MeasureNumber;
+    // for samples starting with a precount measure (e.g. Mozart - An Chloe), the measure number can be 0,
+    //   so without max(n, 1), [topMeasureNumber - 1] would be [-1], causing an error
+    const topMeasureNumber: number = Math.max(previousStaffEntry.parentMeasure.MeasureNumber, 1);
     // we have to find the top measure, otherwise the cursor with type 3 "jumps around" between vertical measures
     let topMeasure: GraphicalMeasure;
     for (const measure of this.graphic.MeasureList[topMeasureNumber - 1]) {