|
@@ -14,7 +14,7 @@ import { StaffLine } from "../MusicalScore/Graphical/StaffLine";
|
|
|
import { GraphicalMeasure } from "../MusicalScore/Graphical/GraphicalMeasure";
|
|
|
import { VexFlowMeasure } from "../MusicalScore/Graphical/VexFlow/VexFlowMeasure";
|
|
|
import { CursorOptions } from "./OSMDOptions";
|
|
|
-import { BoundingBox } from "../MusicalScore";
|
|
|
+import { BoundingBox, GraphicalStaffEntry } from "../MusicalScore";
|
|
|
import { IPlaybackListener } from "../Common/Interfaces/IPlaybackListener";
|
|
|
import { CursorPosChangedData } from "../Common/DataObjects/CursorPosChangedData";
|
|
|
import { PointF2D } from "../Common/DataObjects";
|
|
@@ -145,25 +145,28 @@ export class Cursor implements IPlaybackListener {
|
|
|
public updateWithTimestamp(timestamp: Fraction): void {
|
|
|
const sheetTimestamp: Fraction = this.manager.absoluteEnrolledToSheetTimestamp(timestamp);
|
|
|
|
|
|
- const values: [number, MusicSystem] = this.graphic.calculateXPositionFromTimestamp(sheetTimestamp);
|
|
|
+ const values: [number, MusicSystem, GraphicalStaffEntry] = this.graphic.calculateXPositionFromTimestamp(sheetTimestamp);
|
|
|
const x: number = values[0];
|
|
|
const currentSystem: MusicSystem = values[1];
|
|
|
this.updateCurrentPageFromSystem(currentSystem);
|
|
|
+ const previousStaffEntry: GraphicalStaffEntry = values[2];
|
|
|
+
|
|
|
+ const topMeasureNumber: number = previousStaffEntry.parentMeasure.MeasureNumber;
|
|
|
+ // 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]) {
|
|
|
+ if (measure) {
|
|
|
+ topMeasure = measure;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
const points: [PointF2D, PointF2D] = this.graphic.calculateCursorPoints(x, currentSystem);
|
|
|
const y: number = points[0].y;
|
|
|
const height: number = points[1].y - y;
|
|
|
|
|
|
- // This the current HTML Cursor:
|
|
|
- const cursorElement: HTMLImageElement = this.cursorElement;
|
|
|
- cursorElement.style.top = (y * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
|
|
|
- cursorElement.style.left = ((x - 1.5) * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
|
|
|
- cursorElement.height = (height * 10.0 * this.openSheetMusicDisplay.zoom);
|
|
|
- const newWidth: number = 3 * 10.0 * this.openSheetMusicDisplay.zoom;
|
|
|
- if (newWidth !== cursorElement.width) {
|
|
|
- cursorElement.width = newWidth;
|
|
|
- this.updateStyle(newWidth);
|
|
|
- }
|
|
|
+ this.updateWidthAndStyle(topMeasure.PositionAndShape, x, y, height);
|
|
|
+
|
|
|
if (this.openSheetMusicDisplay.FollowCursor) {
|
|
|
const diff: number = this.cursorElement.getBoundingClientRect().top;
|
|
|
this.cursorElement.scrollIntoView({behavior: diff < 1000 ? "smooth" : "auto", block: "center"});
|
|
@@ -225,15 +228,26 @@ export class Cursor implements IPlaybackListener {
|
|
|
bottomStaffline.PositionAndShape.RelativePosition.y + bottomStaffline.StaffHeight;
|
|
|
height = endY - y;
|
|
|
|
|
|
+ const measurePositionAndShape: BoundingBox = this.graphic.findGraphicalMeasure(iterator.CurrentMeasureIndex, 0).PositionAndShape;
|
|
|
// Update the graphical cursor
|
|
|
- // The following is the legacy cursor rendered on the canvas:
|
|
|
- // // let cursor: GraphicalLine = new GraphicalLine(new PointF2D(x, y), new PointF2D(x, y + height), 3, OutlineAndFillStyleEnum.PlaybackCursor);
|
|
|
+ this.updateWidthAndStyle(measurePositionAndShape, x, y, height);
|
|
|
|
|
|
- // This the current HTML Cursor:
|
|
|
- const cursorElement: HTMLImageElement = this.cursorElement;
|
|
|
+ if (this.openSheetMusicDisplay.FollowCursor) {
|
|
|
+ if (!this.openSheetMusicDisplay.EngravingRules.RenderSingleHorizontalStaffline) {
|
|
|
+ const diff: number = this.cursorElement.getBoundingClientRect().top;
|
|
|
+ this.cursorElement.scrollIntoView({behavior: diff < 1000 ? "smooth" : "auto", block: "center"});
|
|
|
+ } else {
|
|
|
+ this.cursorElement.scrollIntoView({behavior: "smooth", inline: "center"});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Show cursor
|
|
|
+ // // Old cursor: this.graphic.Cursors.push(cursor);
|
|
|
+ this.cursorElement.style.display = "";
|
|
|
+ }
|
|
|
|
|
|
+ public updateWidthAndStyle(measurePositionAndShape: BoundingBox, x: number, y: number, height: number): void {
|
|
|
+ const cursorElement: HTMLImageElement = this.cursorElement;
|
|
|
let newWidth: number = 0;
|
|
|
- const meassurePositionAndShape: BoundingBox = this.graphic.findGraphicalMeasure(iterator.CurrentMeasureIndex, 0).PositionAndShape;
|
|
|
switch (this.cursorOptions.type) {
|
|
|
case 1:
|
|
|
cursorElement.style.top = (y * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
|
|
@@ -248,16 +262,16 @@ export class Cursor implements IPlaybackListener {
|
|
|
newWidth = 5 * this.openSheetMusicDisplay.zoom;
|
|
|
break;
|
|
|
case 3:
|
|
|
- cursorElement.style.top = meassurePositionAndShape.AbsolutePosition.y * 10.0 * this.openSheetMusicDisplay.zoom +"px";
|
|
|
- cursorElement.style.left = meassurePositionAndShape.AbsolutePosition.x * 10.0 * this.openSheetMusicDisplay.zoom +"px";
|
|
|
+ cursorElement.style.top = measurePositionAndShape.AbsolutePosition.y * 10.0 * this.openSheetMusicDisplay.zoom +"px";
|
|
|
+ cursorElement.style.left = measurePositionAndShape.AbsolutePosition.x * 10.0 * this.openSheetMusicDisplay.zoom +"px";
|
|
|
cursorElement.height = (height * 10.0 * this.openSheetMusicDisplay.zoom);
|
|
|
- newWidth = meassurePositionAndShape.Size.width * 10 * this.openSheetMusicDisplay.zoom;
|
|
|
+ newWidth = measurePositionAndShape.Size.width * 10 * this.openSheetMusicDisplay.zoom;
|
|
|
break;
|
|
|
case 4:
|
|
|
- cursorElement.style.top = meassurePositionAndShape.AbsolutePosition.y * 10.0 * this.openSheetMusicDisplay.zoom +"px";
|
|
|
- cursorElement.style.left = meassurePositionAndShape.AbsolutePosition.x * 10.0 * this.openSheetMusicDisplay.zoom +"px";
|
|
|
+ cursorElement.style.top = measurePositionAndShape.AbsolutePosition.y * 10.0 * this.openSheetMusicDisplay.zoom +"px";
|
|
|
+ cursorElement.style.left = measurePositionAndShape.AbsolutePosition.x * 10.0 * this.openSheetMusicDisplay.zoom +"px";
|
|
|
cursorElement.height = (height * 10.0 * this.openSheetMusicDisplay.zoom);
|
|
|
- newWidth = (x-meassurePositionAndShape.AbsolutePosition.x) * 10 * this.openSheetMusicDisplay.zoom;
|
|
|
+ newWidth = (x-measurePositionAndShape.AbsolutePosition.x) * 10 * this.openSheetMusicDisplay.zoom;
|
|
|
break;
|
|
|
default:
|
|
|
cursorElement.style.top = (y * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
|
|
@@ -271,17 +285,6 @@ export class Cursor implements IPlaybackListener {
|
|
|
cursorElement.width = newWidth;
|
|
|
this.updateStyle(newWidth, this.cursorOptions);
|
|
|
}
|
|
|
- if (this.openSheetMusicDisplay.FollowCursor) {
|
|
|
- if (!this.openSheetMusicDisplay.EngravingRules.RenderSingleHorizontalStaffline) {
|
|
|
- const diff: number = this.cursorElement.getBoundingClientRect().top;
|
|
|
- this.cursorElement.scrollIntoView({behavior: diff < 1000 ? "smooth" : "auto", block: "center"});
|
|
|
- } else {
|
|
|
- this.cursorElement.scrollIntoView({behavior: "smooth", inline: "center"});
|
|
|
- }
|
|
|
- }
|
|
|
- // Show cursor
|
|
|
- // // Old cursor: this.graphic.Cursors.push(cursor);
|
|
|
- this.cursorElement.style.display = "";
|
|
|
}
|
|
|
|
|
|
/**
|