Browse Source

fix some rare errors with volta skylines and systemline undefined errors

mpat #70
sschmid 4 years ago
parent
commit
ff068cbb68

+ 1 - 1
src/MusicalScore/Graphical/SkyBottomLineCalculator.ts

@@ -432,7 +432,7 @@ export class SkyBottomLineCalculator {
         endIndex = Math.ceil(endIndex * this.SamplingUnit);
 
         if (endIndex < startIndex) {
-            throw new Error("start index of line is greater then the end index");
+            throw new Error("start index of line is greater than the end index");
         }
 
         if (startIndex < 0) {

+ 1 - 1
src/MusicalScore/Graphical/SystemLine.ts

@@ -17,7 +17,7 @@ export class SystemLine extends GraphicalObject {
         this.parentMusicSystem = musicSystem;
         this.topMeasure = topMeasure;
         this.bottomMeasure = bottomMeasure;
-        this.parentTopStaffLine = topMeasure.ParentStaffLine;
+        this.parentTopStaffLine = topMeasure?.ParentStaffLine;
         this.boundingBox = new BoundingBox(this, musicSystem.PositionAndShape);
     }
 

+ 4 - 2
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -442,7 +442,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
             //This causes getSkyLineMinInRange to return an incorrect min value (one from the previous measure, which has been modified)
             //We need to offset the end of what we are measuring by a bit to prevent this, otherwise volta pairs step up
             const start: number = this.PositionAndShape.AbsolutePosition.x + this.PositionAndShape.BorderMarginLeft + 0.4;
-            const end: number = this.PositionAndShape.AbsolutePosition.x + this.PositionAndShape.BorderMarginRight;
+            const end: number = Math.max(this.PositionAndShape.AbsolutePosition.x + this.PositionAndShape.BorderMarginRight, start + 0.4);
             //2 unit gap, since volta is positioned from y center it seems.
             //This prevents cases where the volta is rendered over another element
             const skylineMinForMeasure: number = skyBottomLineCalculator.getSkyLineMinInRange( start, end ) - 2;
@@ -484,7 +484,9 @@ export class VexFlowMeasure extends GraphicalMeasure {
                     if (nextStaveModifier.hasOwnProperty("volta")) {
                         const prevskyBottomLineCalculator: SkyBottomLineCalculator = prevMeasure.ParentStaffLine.SkyBottomLineCalculator;
                         const prevStart: number = prevMeasure.PositionAndShape.AbsolutePosition.x + prevMeasure.PositionAndShape.BorderMarginLeft + 0.4;
-                        const prevEnd: number = prevMeasure.PositionAndShape.AbsolutePosition.x + prevMeasure.PositionAndShape.BorderMarginRight;
+                        const prevEnd: number = Math.max(
+                            prevMeasure.PositionAndShape.AbsolutePosition.x + prevMeasure.PositionAndShape.BorderMarginRight,
+                            prevStart + 0.4);
                         const prevMeasureSkyline: number = prevskyBottomLineCalculator.getSkyLineMinInRange(prevStart, prevEnd);
                         //if prev skyline is higher, use it
                         if (prevMeasureSkyline <= newSkylineValueForMeasure) {

+ 4 - 3
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSystem.ts

@@ -55,7 +55,7 @@ export class VexFlowMusicSystem extends MusicSystem {
      */
     protected createSystemLine(xPosition: number, lineWidth: number, lineType: SystemLinesEnum, linePosition: SystemLinePosition,
                                musicSystem: MusicSystem, topMeasure: GraphicalMeasure, bottomMeasure: GraphicalMeasure = undefined): SystemLine {
-        const vfMeasure: VexFlowMeasure = topMeasure as VexFlowMeasure;
+        const vfTopMeasure: VexFlowMeasure = topMeasure as VexFlowMeasure;
         let renderInitialLine: boolean = false;
 
         if (bottomMeasure) {
@@ -65,8 +65,9 @@ export class VexFlowMusicSystem extends MusicSystem {
             (bottomMeasure as VexFlowMeasure).lineTo(topMeasure as VexFlowMeasure, VexFlowConverter.line(lineType, linePosition));
             (bottomMeasure as VexFlowMeasure).addMeasureLine(lineType, linePosition);
         }
-
-        vfMeasure.addMeasureLine(lineType, linePosition, renderInitialLine);
+        if (vfTopMeasure) {
+            vfTopMeasure.addMeasureLine(lineType, linePosition, renderInitialLine);
+        }
 
         return new SystemLine(lineType, linePosition, this, topMeasure, bottomMeasure);
     }