Bladeren bron

Fixed bugs and some lint errors.
Cursor and Labels rendering methods are now called from core code.
Added a test cursor at first Fraction in sheet.

Matthias 9 jaren geleden
bovenliggende
commit
7b807bac12

+ 18 - 5
src/MusicalScore/Graphical/GraphicalMusicSheet.ts

@@ -23,6 +23,7 @@ import Dictionary from "typescript-collections/dist/lib/Dictionary";
 import {CollectionUtil} from "../../Util/collectionUtil";
 import {SelectionStartSymbol} from "./SelectionStartSymbol";
 import {SelectionEndSymbol} from "./SelectionEndSymbol";
+import {OutlineAndFillStyleEnum} from "./DrawingEnums";
 
 export class GraphicalMusicSheet {
     constructor(musicSheet: MusicSheet, calculator: MusicSheetCalculator) {
@@ -670,14 +671,26 @@ export class GraphicalMusicSheet {
         return undefined;
     }
 
-    public calculateXPositionFromTimestamp(timeStamp: Fraction, currentMusicSystem: MusicSystem): number {
+    public calculateCursorLineAtTimestamp(musicTimestamp: Fraction, styleEnum: OutlineAndFillStyleEnum): GraphicalLine {
+        let result: [number, MusicSystem] = this.calculateXPositionFromTimestamp(musicTimestamp);
+        let xPos: number = result[0];
+        let correspondingMusicSystem: MusicSystem = result[1];
+        if (correspondingMusicSystem === undefined || correspondingMusicSystem.StaffLines.length === 0) {
+            return undefined;
+        }
+        let yCoordinate: number = correspondingMusicSystem.PositionAndShape.AbsolutePosition.y;
+        let height: number = CollectionUtil.last(correspondingMusicSystem.StaffLines).PositionAndShape.RelativePosition.y + 4;
+        return new GraphicalLine(new PointF2D(xPos, yCoordinate), new PointF2D(xPos, yCoordinate + height), 3, styleEnum);
+    }
+
+    public calculateXPositionFromTimestamp(timeStamp: Fraction): [number, MusicSystem] {
+        let currentMusicSystem: MusicSystem = undefined;
         let fractionalIndex: number = this.GetInterpolatedIndexInVerticalContainers(timeStamp);
         let previousStaffEntry: GraphicalStaffEntry = this.findClosestLeftStaffEntry(fractionalIndex, true);
         let nextStaffEntry: GraphicalStaffEntry = this.findClosestRightStaffEntry(fractionalIndex, true);
         let currentTimeStamp: number = timeStamp.RealValue;
         if (previousStaffEntry === undefined && nextStaffEntry === undefined) {
-            currentMusicSystem = undefined;
-            return 0;
+            return [0, undefined];
         }
         let previousStaffEntryMusicSystem: MusicSystem = undefined;
         if (previousStaffEntry !== undefined) {
@@ -717,7 +730,7 @@ export class GraphicalMusicSheet {
             }
             fraction = Math.min(1, Math.max(0, fraction));
             let interpolatedXPosition: number = previousStaffEntryPositionX + fraction * (nextStaffEntryPositionX - previousStaffEntryPositionX);
-            return interpolatedXPosition;
+            return [interpolatedXPosition, currentMusicSystem];
         } else {
             let nextSystemLeftBorderTimeStamp: number = nextStaffEntry.parentMeasure.parentSourceMeasure.AbsoluteTimestamp.RealValue;
             let fraction: number;
@@ -739,7 +752,7 @@ export class GraphicalMusicSheet {
                 fraction = Math.min(1, Math.max(0, fraction));
                 interpolatedXPosition = nextSystemLeftBorderX + fraction * (nextStaffEntryPositionX - nextSystemLeftBorderX);
             }
-            return interpolatedXPosition;
+            return [interpolatedXPosition, currentMusicSystem];
         }
     }
 

+ 0 - 8
src/MusicalScore/Graphical/GraphicalOctaveShift.ts

@@ -25,25 +25,17 @@ export class GraphicalOctaveShift extends GraphicalObject {
     private setSymbol(): void {
         switch (this.getOctaveShift.Type) {
             case OctaveEnum.VA8:
-            {
                 this.octaveSymbol = MusicSymbol.VA8;
                 break;
-            }
             case OctaveEnum.VB8:
-            {
                 this.octaveSymbol = MusicSymbol.VB8;
                 break;
-            }
             case OctaveEnum.MA15:
-            {
                 this.octaveSymbol = MusicSymbol.MA15;
                 break;
-            }
             case OctaveEnum.MB15:
-            {
                 this.octaveSymbol = MusicSymbol.MB15;
                 break;
-            }
             default:
                 throw new ArgumentOutOfRangeException("");
         }

+ 13 - 17
src/MusicalScore/Graphical/MusicSheetDrawer.ts

@@ -27,8 +27,8 @@ import {GraphicalObject} from "./GraphicalObject";
 
 export abstract class MusicSheetDrawer {
     public drawingParameters: DrawingParameters = new DrawingParameters();
-    public SplitScreenLineColor: number;
-    public MidiPlaybackAvailable: boolean;
+    public splitScreenLineColor: number;
+    public midiPlaybackAvailable: boolean;
 
     protected rules: EngravingRules;
     protected graphicalMusicSheet: GraphicalMusicSheet;
@@ -38,7 +38,7 @@ export abstract class MusicSheetDrawer {
     constructor(textMeasurer: ITextMeasurer,
                 isPreviewImageDrawer: boolean = false) {
         this.textMeasurer = textMeasurer;
-        this.SplitScreenLineColor = -1;
+        this.splitScreenLineColor = -1;
         if (isPreviewImageDrawer) {
             this.drawingParameters.setForThumbmail();
         } else {
@@ -253,7 +253,7 @@ export abstract class MusicSheetDrawer {
     protected getSystemAbsBoundingRect(system: MusicSystem): RectangleF2D {
         let relBoundingRect: RectangleF2D = system.PositionAndShape.BoundingRectangle;
         let absBoundingRectWithMargin: RectangleF2D = new RectangleF2D(system.PositionAndShape.AbsolutePosition.x + system.PositionAndShape.BorderLeft - 1,
-            system.PositionAndShape.AbsolutePosition.y + system.PositionAndShape.BorderTop - 1,
+                                                                       system.PositionAndShape.AbsolutePosition.y + system.PositionAndShape.BorderTop - 1,
             (relBoundingRect.width + 6), (relBoundingRect.height + 2));
         return absBoundingRectWithMargin;
     }
@@ -328,7 +328,8 @@ export abstract class MusicSheetDrawer {
         this.drawSymbol(graphicalOctaveShift.octaveSymbol, MusicSymbolDrawingStyle.Normal, graphicalOctaveShift.PositionAndShape.AbsolutePosition);
         let absolutePos: PointF2D = staffLine.PositionAndShape.AbsolutePosition;
         if (graphicalOctaveShift.dashesStart.x < graphicalOctaveShift.dashesEnd.x) {
-            let horizontalLine: GraphicalLine = new GraphicalLine(graphicalOctaveShift.dashesStart, graphicalOctaveShift.dashesEnd, this.rules.OctaveShiftLineWidth);
+            let horizontalLine: GraphicalLine = new GraphicalLine(graphicalOctaveShift.dashesStart, graphicalOctaveShift.dashesEnd,
+                                                                  this.rules.OctaveShiftLineWidth);
             this.drawLineAsHorizontalRectangleWithOffset(horizontalLine, absolutePos, <number>GraphicalLayers.Notes);
         }
         if (!graphicalOctaveShift.endsOnDifferentStaffLine || graphicalOctaveShift.isSecondPart) {
@@ -348,8 +349,9 @@ export abstract class MusicSheetDrawer {
     protected drawStaffLines(staffLine: StaffLine): void {
         if (staffLine.StaffLines !== undefined) {
             let position: PointF2D = staffLine.PositionAndShape.AbsolutePosition;
-            for (let i: number = 0; i < 5; i++)
+            for (let i: number = 0; i < 5; i++) {
                 this.drawLineAsHorizontalRectangleWithOffset(staffLine.StaffLines[i], position, <number>GraphicalLayers.Notes);
+            }
         }
     }
 
@@ -440,34 +442,28 @@ export abstract class MusicSheetDrawer {
         let borderRight: number = staffLine.PositionAndShape.BorderRight;
         if (parentInst.highlight && this.drawingParameters.drawHighlights) {
             this.drawLineAsHorizontalRectangle(new GraphicalLine(new PointF2D(absX, absY),
-                new PointF2D(absX + borderRight, absY), 4,
-                OutlineAndFillStyleEnum.Highlighted), <number>GraphicalLayers.Highlight);
+                                               new PointF2D(absX + borderRight, absY), 4,
+                                               OutlineAndFillStyleEnum.Highlighted), <number>GraphicalLayers.Highlight);
         }
         let style: MusicSymbolDrawingStyle = MusicSymbolDrawingStyle.Disabled;
         let symbol: MusicSymbol = MusicSymbol.PLAY;
         let drawSymbols: boolean = this.drawingParameters.drawActivitySymbols;
         switch (this.phonicScoreMode) {
             case PhonicScoreModes.Midi:
-            {
                 symbol = MusicSymbol.PLAY;
-                if (this.MidiPlaybackAvailable && staffLine.ParentStaff.audible) {
+                if (this.midiPlaybackAvailable && staffLine.ParentStaff.audible) {
                     style = MusicSymbolDrawingStyle.PlaybackSymbols;
                 }
                 break;
-            }
             case PhonicScoreModes.Following:
-            {
                 symbol = MusicSymbol.MIC;
                 if (staffLine.ParentStaff.following) {
                     style = MusicSymbolDrawingStyle.FollowSymbols;
                 }
                 break;
-            }
             default:
-            {
                 drawSymbols = false;
                 break;
-            }
         }
         if (drawSymbols) {
             let p: PointF2D = new PointF2D(absX + borderRight + 2, absY);
@@ -480,8 +476,8 @@ export abstract class MusicSheetDrawer {
                 let absYPSI: number = measurePSI.AbsolutePosition.y + 2;
                 if (measure.hasError && this.graphicalMusicSheet.ParentMusicSheet.DrawErroneousMeasures) {
                     this.drawLineAsHorizontalRectangle(new GraphicalLine(new PointF2D(absXPSI, absYPSI),
-                        new PointF2D(absXPSI + measurePSI.BorderRight, absYPSI), 4,
-                        OutlineAndFillStyleEnum.ErrorUnderlay), <number>GraphicalLayers.MeasureError);
+                                                       new PointF2D(absXPSI + measurePSI.BorderRight, absYPSI), 4,
+                                                       OutlineAndFillStyleEnum.ErrorUnderlay), <number>GraphicalLayers.MeasureError);
                 }
             }
         }

+ 2 - 2
src/MusicalScore/Graphical/SelectionStartSymbol.ts

@@ -14,7 +14,7 @@ export class SelectionStartSymbol extends GraphicalObject {
         let lineThickness: number = 0.4;
         let height: number = CollectionUtil.last(system.StaffLines).PositionAndShape.RelativePosition.y + 4;
         this.verticalLine = new GraphicalLine(new PointF2D(xCoordinate, yCoordinate), new PointF2D(xCoordinate, yCoordinate + height), lineThickness, OutlineAndFillStyleEnum.SelectionSymbol);
-        for (let idx: number = 0, len = system.StaffLines.length; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = system.StaffLines.length; idx < len; ++idx) {
             let staffLine: StaffLine = system.StaffLines[idx];
             let anchor: PointF2D = new PointF2D(xCoordinate, yCoordinate + staffLine.PositionAndShape.RelativePosition.y);
             let arrowPoints: PointF2D[] = new Array(7);
@@ -43,4 +43,4 @@ export class SelectionStartSymbol extends GraphicalObject {
 
     public verticalLine: GraphicalLine;
     public arrows: PointF2D[][];
-}
+}

+ 3 - 0
test/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer.ts

@@ -6,6 +6,8 @@ import {VexFlowMusicSheetCalculator} from "../../../../src/MusicalScore/Graphica
 import {TestUtils} from "../../../Util/TestUtils";
 import {IXmlElement} from "../../../../src/Common/FileIO/Xml";
 import {VexFlowTextMeasurer} from "../../../../src/MusicalScore/Graphical/VexFlow/VexFlowTextMeasurer";
+import {Fraction} from "../../../../src/Common/DataObjects/fraction";
+import {OutlineAndFillStyleEnum} from "../../../../src/MusicalScore/Graphical/DrawingEnums";
 
 describe("VexFlow Music Sheet Drawer", () => {
 
@@ -18,6 +20,7 @@ describe("VexFlow Music Sheet Drawer", () => {
         let reader: MusicSheetReader = new MusicSheetReader();
         let sheet: MusicSheet = reader.createMusicSheet(score, path);
         let gms: GraphicalMusicSheet = new GraphicalMusicSheet(sheet, calc);
+        gms.Cursors.push(gms.calculateCursorLineAtTimestamp(new Fraction(), OutlineAndFillStyleEnum.PlaybackCursor));
         (new VexFlowMusicSheetDrawer(new VexFlowTextMeasurer())).drawSheet(gms);
         done();
     });