Cursor.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. import {MusicPartManagerIterator} from "../MusicalScore/MusicParts/MusicPartManagerIterator";
  2. import {MusicPartManager} from "../MusicalScore/MusicParts/MusicPartManager";
  3. import {VoiceEntry} from "../MusicalScore/VoiceData/VoiceEntry";
  4. import {VexFlowStaffEntry} from "../MusicalScore/Graphical/VexFlow/VexFlowStaffEntry";
  5. import {MusicSystem} from "../MusicalScore/Graphical/MusicSystem";
  6. import {OpenSheetMusicDisplay} from "./OpenSheetMusicDisplay";
  7. import {GraphicalMusicSheet} from "../MusicalScore/Graphical/GraphicalMusicSheet";
  8. import {Instrument} from "../MusicalScore/Instrument";
  9. import {Note} from "../MusicalScore/VoiceData/Note";
  10. import {Fraction} from "../Common/DataObjects/Fraction";
  11. import { EngravingRules } from "../MusicalScore/Graphical/EngravingRules";
  12. import { SourceMeasure } from "../MusicalScore/VoiceData/SourceMeasure";
  13. import { StaffLine } from "../MusicalScore/Graphical/StaffLine";
  14. import { GraphicalMeasure } from "../MusicalScore/Graphical/GraphicalMeasure";
  15. import { VexFlowMeasure } from "../MusicalScore/Graphical/VexFlow/VexFlowMeasure";
  16. import { CursorOptions } from "./OSMDOptions";
  17. import { BoundingBox } from "../MusicalScore/Graphical/BoundingBox";
  18. import { GraphicalNote } from "../MusicalScore/Graphical/GraphicalNote";
  19. import { GraphicalStaffEntry } from "../MusicalScore/Graphical/GraphicalStaffEntry";
  20. import { IPlaybackListener } from "../Common/Interfaces/IPlaybackListener";
  21. import { CursorPosChangedData } from "../Common/DataObjects/CursorPosChangedData";
  22. import { PointF2D } from "../Common/DataObjects";
  23. /**
  24. * A cursor which can iterate through the music sheet.
  25. */
  26. export class Cursor implements IPlaybackListener {
  27. constructor(container: HTMLElement, openSheetMusicDisplay: OpenSheetMusicDisplay, cursorOptions: CursorOptions) {
  28. this.container = container;
  29. this.openSheetMusicDisplay = openSheetMusicDisplay;
  30. this.rules = this.openSheetMusicDisplay.EngravingRules;
  31. this.cursorOptions = cursorOptions;
  32. // set cursor id
  33. // TODO add this for the OSMD object as well and refactor this into a util method?
  34. let id: number = 0;
  35. this.cursorElementId = "cursorImg-0";
  36. // find unique cursor id in document
  37. while (document.getElementById(this.cursorElementId)) {
  38. id++;
  39. this.cursorElementId = `cursorImg-${id}`;
  40. }
  41. const curs: HTMLElement = document.createElement("img");
  42. curs.id = this.cursorElementId;
  43. curs.style.position = "absolute";
  44. if (this.cursorOptions.follow === true) {
  45. this.wantedZIndex = "-1";
  46. curs.style.zIndex = this.wantedZIndex;
  47. } else {
  48. this.wantedZIndex = "-2";
  49. curs.style.zIndex = this.wantedZIndex;
  50. }
  51. this.cursorElement = <HTMLImageElement>curs;
  52. this.container.appendChild(curs);
  53. }
  54. public cursorPositionChanged(timestamp: Fraction, data: CursorPosChangedData): void {
  55. // update iterator so cursor.NotesUnderCursor() etc works
  56. while (this.iterator.CurrentEnrolledTimestamp.lt(timestamp)) {
  57. this.iterator.moveToNext();
  58. }
  59. if (this.iterator.CurrentEnrolledTimestamp.gt(timestamp)) {
  60. this.iterator = new MusicPartManagerIterator(this.manager.MusicSheet, timestamp);
  61. }
  62. this.updateWithTimestamp(data.PredictedPosition);
  63. }
  64. public pauseOccurred(o: object): void {
  65. // throw new Error("Method not implemented.");
  66. }
  67. public setSound(): void {}
  68. public selectionEndReached(o: object): void {
  69. // throw new Error("Method not implemented.");
  70. }
  71. public resetOccurred(o: object): void {
  72. this.reset();
  73. }
  74. public notesPlaybackEventOccurred(o: object): void {
  75. // throw new Error("Method not implemented.");
  76. }
  77. public adjustToBackgroundColor(): void {
  78. let zIndex: string;
  79. if (!this.rules.PageBackgroundColor) {
  80. zIndex = this.wantedZIndex;
  81. } else {
  82. zIndex = "1";
  83. }
  84. this.cursorElement.style.zIndex = zIndex;
  85. }
  86. private container: HTMLElement;
  87. public cursorElement: HTMLImageElement;
  88. /** a unique id of the cursor's HTMLElement in the document.
  89. * Should be constant between re-renders and backend changes,
  90. * but different between different OSMD objects on the same page.
  91. */
  92. public cursorElementId: string;
  93. /** The desired zIndex (layer) of the cursor when no background color is set.
  94. * When a background color is set, using a negative zIndex would make the cursor invisible.
  95. */
  96. public wantedZIndex: string;
  97. private openSheetMusicDisplay: OpenSheetMusicDisplay;
  98. private rules: EngravingRules;
  99. private manager: MusicPartManager;
  100. public iterator: MusicPartManagerIterator;
  101. private graphic: GraphicalMusicSheet;
  102. public hidden: boolean = false;
  103. public currentPageNumber: number = 1;
  104. private cursorOptions: CursorOptions;
  105. /** Initialize the cursor. Necessary before using functions like show() and next(). */
  106. public init(manager: MusicPartManager, graphic: GraphicalMusicSheet): void {
  107. this.manager = manager;
  108. this.graphic = graphic;
  109. this.reset();
  110. this.hidden = false;
  111. }
  112. /**
  113. * Make the cursor visible
  114. */
  115. public show(): void {
  116. this.hidden = false;
  117. //this.resetIterator(); // TODO maybe not here? though setting measure range to draw, rerendering, then handling cursor show is difficult
  118. this.update();
  119. this.adjustToBackgroundColor();
  120. }
  121. public resetIterator(): void {
  122. if (!this.openSheetMusicDisplay.Sheet || !this.openSheetMusicDisplay.Sheet.SourceMeasures) { // just a safety measure
  123. console.log("OSMD.Cursor.resetIterator(): sheet or measures were null/undefined.");
  124. return;
  125. }
  126. // set selection start, so that when there's MinMeasureToDraw set, the cursor starts there right away instead of at measure 1
  127. const lastSheetMeasureIndex: number = this.openSheetMusicDisplay.Sheet.SourceMeasures.length - 1; // last measure in data model
  128. let startMeasureIndex: number = this.rules.MinMeasureToDrawIndex;
  129. startMeasureIndex = Math.min(startMeasureIndex, lastSheetMeasureIndex);
  130. let endMeasureIndex: number = this.rules.MaxMeasureToDrawIndex;
  131. endMeasureIndex = Math.min(endMeasureIndex, lastSheetMeasureIndex);
  132. const updateSelectionStart: boolean = this.openSheetMusicDisplay.Sheet && (
  133. !this.openSheetMusicDisplay.Sheet.SelectionStart ||
  134. this.openSheetMusicDisplay.Sheet.SelectionStart.WholeValue < startMeasureIndex) &&
  135. this.openSheetMusicDisplay.Sheet.SourceMeasures.length > startMeasureIndex;
  136. if (updateSelectionStart) {
  137. this.openSheetMusicDisplay.Sheet.SelectionStart = this.openSheetMusicDisplay.Sheet.SourceMeasures[startMeasureIndex].AbsoluteTimestamp;
  138. }
  139. if (this.openSheetMusicDisplay.Sheet && this.openSheetMusicDisplay.Sheet.SourceMeasures.length > endMeasureIndex) {
  140. const lastMeasure: SourceMeasure = this.openSheetMusicDisplay.Sheet.SourceMeasures[endMeasureIndex];
  141. this.openSheetMusicDisplay.Sheet.SelectionEnd = Fraction.plus(lastMeasure.AbsoluteTimestamp, lastMeasure.Duration);
  142. }
  143. this.iterator = this.manager.getIterator();
  144. }
  145. private getStaffEntryFromVoiceEntry(voiceEntry: VoiceEntry): VexFlowStaffEntry {
  146. const measureIndex: number = voiceEntry.ParentSourceStaffEntry.VerticalContainerParent.ParentMeasure.measureListIndex;
  147. const staffIndex: number = voiceEntry.ParentSourceStaffEntry.ParentStaff.idInMusicSheet;
  148. return <VexFlowStaffEntry>this.graphic.findGraphicalStaffEntryFromMeasureList(staffIndex, measureIndex, voiceEntry.ParentSourceStaffEntry);
  149. }
  150. public updateWithTimestamp(timestamp: Fraction): void {
  151. const sheetTimestamp: Fraction = this.manager.absoluteEnrolledToSheetTimestamp(timestamp);
  152. const values: [number, MusicSystem, GraphicalStaffEntry] = this.graphic.calculateXPositionFromTimestamp(sheetTimestamp);
  153. const x: number = values[0];
  154. const currentSystem: MusicSystem = values[1];
  155. this.updateCurrentPageFromSystem(currentSystem);
  156. const previousStaffEntry: GraphicalStaffEntry = values[2];
  157. if (!previousStaffEntry) {
  158. return; // TODO maybe fix calculateXPositionFromTimestamp() instead
  159. }
  160. // for samples starting with a precount measure (e.g. Mozart - An Chloe), the measure number can be 0,
  161. // so without max(n, 1), [topMeasureNumber - 1] would be [-1], causing an error
  162. const topMeasureNumber: number = Math.max(previousStaffEntry.parentMeasure.MeasureNumber, 1);
  163. // we have to find the top measure, otherwise the cursor with type 3 "jumps around" between vertical measures
  164. let topMeasure: GraphicalMeasure;
  165. for (const measure of this.graphic.MeasureList[topMeasureNumber - 1]) {
  166. if (measure) {
  167. topMeasure = measure;
  168. break;
  169. }
  170. }
  171. const points: [PointF2D, PointF2D] = this.graphic.calculateCursorPoints(x, currentSystem);
  172. const y: number = points[0].y;
  173. const height: number = points[1].y - y;
  174. // 修改 修复部分报错问题
  175. if (!topMeasure) {return;}
  176. this.updateWidthAndStyle(topMeasure.PositionAndShape, x, y, height);
  177. if (this.openSheetMusicDisplay.FollowCursor) {
  178. const diff: number = this.cursorElement.getBoundingClientRect().top;
  179. this.cursorElement.scrollIntoView({behavior: diff < 1000 ? "smooth" : "auto", block: "center"});
  180. }
  181. // Show cursor
  182. // // Old cursor: this.graphic.Cursors.push(cursor);
  183. this.cursorElement.style.display = "";
  184. }
  185. public update(): void {
  186. if (this.hidden || this.hidden === undefined || this.hidden === null) {
  187. return;
  188. }
  189. this.updateCurrentPage(); // attach cursor to new page DOM if necessary
  190. // this.graphic?.Cursors?.length = 0;
  191. const iterator: MusicPartManagerIterator = this.Iterator;
  192. // TODO when measure draw range (drawUpToMeasureNumber) was changed, next/update can fail to move cursor. but of course it can be reset before.
  193. const voiceEntries: VoiceEntry[] = iterator.CurrentVisibleVoiceEntries();
  194. if (iterator.EndReached || !iterator.CurrentVoiceEntries || voiceEntries.length === 0) {
  195. return;
  196. }
  197. let x: number = 0, y: number = 0, height: number = 0;
  198. let musicSystem: MusicSystem;
  199. if (iterator.CurrentMeasure.isReducedToMultiRest) {
  200. const multiRestGMeasure: GraphicalMeasure = this.graphic.findGraphicalMeasure(iterator.CurrentMeasureIndex, 0);
  201. const totalRestMeasures: number = multiRestGMeasure.parentSourceMeasure.multipleRestMeasures;
  202. const currentRestMeasureNumber: number = iterator.CurrentMeasure.multipleRestMeasureNumber;
  203. const progressRatio: number = currentRestMeasureNumber / (totalRestMeasures + 1);
  204. const effectiveWidth: number = multiRestGMeasure.PositionAndShape.Size.width - (multiRestGMeasure as VexFlowMeasure).beginInstructionsWidth;
  205. x = multiRestGMeasure.PositionAndShape.AbsolutePosition.x + (multiRestGMeasure as VexFlowMeasure).beginInstructionsWidth + progressRatio * effectiveWidth;
  206. musicSystem = multiRestGMeasure.ParentMusicSystem;
  207. } else {
  208. // get all staff entries inside the current voice entry
  209. const gseArr: VexFlowStaffEntry[] = voiceEntries.map(ve => this.getStaffEntryFromVoiceEntry(ve));
  210. // console.log(gseArr)
  211. // sort them by x position and take the leftmost entry
  212. const gse: VexFlowStaffEntry =
  213. gseArr.sort((a, b) => a?.PositionAndShape?.AbsolutePosition?.x <= b?.PositionAndShape?.AbsolutePosition?.x ? -1 : 1 )[0];
  214. if(gse){
  215. x = gse.PositionAndShape.AbsolutePosition.x;
  216. musicSystem = gse.parentMeasure.ParentMusicSystem;
  217. }
  218. // debug: change color of notes under cursor (needs re-render)
  219. // for (const gve of gse.graphicalVoiceEntries) {
  220. // for (const note of gve.notes) {
  221. // note.sourceNote.NoteheadColor = "#0000FF";
  222. // }
  223. // }
  224. }
  225. if (!musicSystem) {
  226. return;
  227. }
  228. // y is common for both multirest and non-multirest, given the MusicSystem
  229. y = musicSystem.PositionAndShape.AbsolutePosition.y + musicSystem.StaffLines[0].PositionAndShape.RelativePosition.y ?? 0;
  230. const bottomStaffline: StaffLine = musicSystem.StaffLines[musicSystem.StaffLines.length - 1];
  231. const endY: number = musicSystem.PositionAndShape.AbsolutePosition.y +
  232. bottomStaffline.PositionAndShape.RelativePosition.y + bottomStaffline.StaffHeight;
  233. height = endY - y;
  234. // Update the graphical cursor
  235. const measurePositionAndShape: BoundingBox = this.graphic.findGraphicalMeasure(iterator.CurrentMeasureIndex, 0).PositionAndShape;
  236. this.updateWidthAndStyle(measurePositionAndShape, x, y, height);
  237. if (this.openSheetMusicDisplay.FollowCursor && this.cursorOptions.follow) {
  238. if (!this.openSheetMusicDisplay.EngravingRules.RenderSingleHorizontalStaffline) {
  239. const diff: number = this.cursorElement.getBoundingClientRect().top;
  240. this.cursorElement.scrollIntoView({behavior: diff < 1000 ? "smooth" : "auto", block: "center"});
  241. } else {
  242. this.cursorElement.scrollIntoView({behavior: "smooth", inline: "center"});
  243. }
  244. }
  245. // Show cursor
  246. // // Old cursor: this.graphic.Cursors.push(cursor);
  247. this.cursorElement.style.display = "";
  248. }
  249. public updateWidthAndStyle(measurePositionAndShape: BoundingBox, x: number, y: number, height: number): void {
  250. const cursorElement: HTMLImageElement = this.cursorElement;
  251. let newWidth: number = 0;
  252. let heightCalc: number = height;
  253. switch (this.cursorOptions.type) {
  254. case 1:
  255. cursorElement.style.top = (y * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
  256. cursorElement.style.left = ((x - 1.5) * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
  257. heightCalc = (height * 10.0 * this.openSheetMusicDisplay.zoom);
  258. cursorElement.height = heightCalc;
  259. cursorElement.style.height = heightCalc + "px";
  260. newWidth = 5 * this.openSheetMusicDisplay.zoom;
  261. break;
  262. case 2:
  263. cursorElement.style.top = ((y-2.5) * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
  264. cursorElement.style.left = (x * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
  265. heightCalc = (1.5 * 10.0 * this.openSheetMusicDisplay.zoom);
  266. cursorElement.height = heightCalc;
  267. cursorElement.style.height = heightCalc + "px";
  268. newWidth = 5 * this.openSheetMusicDisplay.zoom;
  269. break;
  270. case 3:
  271. cursorElement.style.top = measurePositionAndShape.AbsolutePosition.y * 10.0 * this.openSheetMusicDisplay.zoom +"px";
  272. cursorElement.style.left = measurePositionAndShape.AbsolutePosition.x * 10.0 * this.openSheetMusicDisplay.zoom +"px";
  273. heightCalc = (height * 10.0 * this.openSheetMusicDisplay.zoom);
  274. cursorElement.height = heightCalc;
  275. cursorElement.style.height = heightCalc + "px";
  276. newWidth = measurePositionAndShape.Size.width * 10 * this.openSheetMusicDisplay.zoom;
  277. break;
  278. case 4:
  279. cursorElement.style.top = measurePositionAndShape.AbsolutePosition.y * 10.0 * this.openSheetMusicDisplay.zoom +"px";
  280. cursorElement.style.left = measurePositionAndShape.AbsolutePosition.x * 10.0 * this.openSheetMusicDisplay.zoom +"px";
  281. heightCalc = (height * 10.0 * this.openSheetMusicDisplay.zoom);
  282. cursorElement.height = heightCalc;
  283. cursorElement.style.height = heightCalc + "px";
  284. newWidth = (x-measurePositionAndShape.AbsolutePosition.x) * 10 * this.openSheetMusicDisplay.zoom;
  285. break;
  286. default:
  287. cursorElement.style.top = (y * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
  288. cursorElement.style.left = ((x - 1.5) * 10.0 * this.openSheetMusicDisplay.zoom) + "px";
  289. heightCalc = (height * 10.0 * this.openSheetMusicDisplay.zoom);
  290. cursorElement.height = heightCalc;
  291. cursorElement.style.height = heightCalc + "px";
  292. newWidth = 3 * 10.0 * this.openSheetMusicDisplay.zoom;
  293. break;
  294. }
  295. if ((window as any).GYM?.multitrack) {
  296. cursorElement.height = heightCalc + 24;
  297. cursorElement.style.height = heightCalc + 24 + "px";
  298. }
  299. if (newWidth !== cursorElement.width) {
  300. cursorElement.width = newWidth;
  301. this.updateStyle(newWidth, this.cursorOptions);
  302. }
  303. }
  304. /**
  305. * Hide the cursor
  306. */
  307. public hide(): void {
  308. // Hide the actual cursor element
  309. this.cursorElement.style.display = "none";
  310. //this.graphic.Cursors.length = 0;
  311. // Forcing the sheet to re-render is not necessary anymore
  312. //if (!this.hidden) {
  313. // this.openSheetMusicDisplay.render();
  314. //}
  315. this.hidden = true;
  316. }
  317. /**
  318. * Go to next entry
  319. */
  320. public next(): void {
  321. this.Iterator.moveToNextVisibleVoiceEntry(false); // moveToNext() would not skip notes in hidden (visible = false) parts
  322. this.update();
  323. }
  324. /**
  325. * reset cursor to start
  326. */
  327. public reset(): void {
  328. this.resetIterator();
  329. //this.iterator.moveToNext();
  330. const iterTmp: MusicPartManagerIterator = this.manager.getIterator(this.graphic.ParentMusicSheet.SelectionStart);
  331. this.updateWithTimestamp(iterTmp.CurrentEnrolledTimestamp);
  332. }
  333. private updateStyle(width: number, cursorOptions: CursorOptions = undefined): void {
  334. if (cursorOptions !== undefined) {
  335. this.cursorOptions = cursorOptions;
  336. }
  337. // 修改 cursor样式
  338. // this.cursorElement.width = 5*this.openSheetMusicDisplay.zoom;
  339. // Create a dummy canvas to generate the gradient for the cursor
  340. // FIXME This approach needs to be improved
  341. const c: HTMLCanvasElement = document.createElement("canvas");
  342. c.width = this.cursorElement.width;
  343. c.height = 1;
  344. const ctx: CanvasRenderingContext2D = c.getContext("2d");
  345. ctx.globalAlpha = this.cursorOptions.alpha;
  346. // Generate the gradient
  347. const gradient: CanvasGradient = ctx.createLinearGradient(0, 0, this.cursorElement.width, 0);
  348. switch (this.cursorOptions.type) {
  349. case 1:
  350. case 2:
  351. case 3:
  352. case 4:
  353. gradient.addColorStop(1, this.cursorOptions.color);
  354. break;
  355. default:
  356. gradient.addColorStop(0, "white"); // it was: "transparent"
  357. gradient.addColorStop(0.2, this.cursorOptions.color);
  358. gradient.addColorStop(0.8, this.cursorOptions.color);
  359. gradient.addColorStop(1, "white"); // it was: "transparent"
  360. break;
  361. }
  362. ctx.fillStyle = gradient;
  363. ctx.fillRect(0, 0, width, 1);
  364. // Set the actual image
  365. this.cursorElement.src = c.toDataURL("image/png");
  366. }
  367. public get Iterator(): MusicPartManagerIterator {
  368. // if (this.openSheetMusicDisplay.PlaybackManager) {
  369. // return this.openSheetMusicDisplay.PlaybackManager.CursorIterator;
  370. // }
  371. // PlaybackManager.CursorIterator is often not at the visible cursor position.
  372. return this.iterator;
  373. }
  374. public get Hidden(): boolean {
  375. return this.hidden;
  376. }
  377. /** returns voices under the current Cursor position. Without instrument argument, all voices are returned. */
  378. public VoicesUnderCursor(instrument?: Instrument): VoiceEntry[] {
  379. return this.Iterator.CurrentVisibleVoiceEntries(instrument);
  380. }
  381. public NotesUnderCursor(instrument?: Instrument): Note[] {
  382. const voiceEntries: VoiceEntry[] = this.VoicesUnderCursor(instrument);
  383. const notes: Note[] = [];
  384. voiceEntries.forEach(voiceEntry => {
  385. notes.push.apply(notes, voiceEntry.Notes);
  386. });
  387. return notes;
  388. }
  389. public GNotesUnderCursor(instrument?: Instrument): GraphicalNote[] {
  390. const voiceEntries: VoiceEntry[] = this.VoicesUnderCursor(instrument);
  391. const notes: GraphicalNote[] = [];
  392. voiceEntries.forEach(voiceEntry => {
  393. notes.push(...voiceEntry.Notes.map(note => this.rules.GNote(note)));
  394. });
  395. return notes;
  396. }
  397. /** Check if there was a change in current page, and attach cursor element to the corresponding HTMLElement (div).
  398. * This is only necessary if using PageFormat (multiple pages).
  399. */
  400. public updateCurrentPage(): number {
  401. const timestamp: Fraction = this.Iterator.currentTimeStamp;
  402. for (const page of this.graphic.MusicPages) {
  403. const lastSystemTimestamp: Fraction = page.MusicSystems.last().GetSystemsLastTimeStamp();
  404. if (lastSystemTimestamp.gt(timestamp)) {
  405. // gt: the last timestamp of the last system is equal to the first of the next page,
  406. // so we do need to use gt, not gte here.
  407. const newPageNumber: number = page.PageNumber;
  408. if (newPageNumber !== this.currentPageNumber) {
  409. this.container.removeChild(this.cursorElement);
  410. this.container = document.getElementById(this.rules.DYContainerId + newPageNumber);
  411. this.container.appendChild(this.cursorElement);
  412. // TODO maybe store this.pageCurrentlyAttachedTo, though right now it isn't necessary
  413. // alternative to remove/append:
  414. // this.openSheetMusicDisplay.enableOrDisableCursor(true);
  415. }
  416. return this.currentPageNumber = newPageNumber;
  417. }
  418. }
  419. return 1;
  420. }
  421. public updateCurrentPageFromSystem(system: MusicSystem): number {
  422. if (system?.Parent) {
  423. const newPageNumber: number = system.Parent.PageNumber;
  424. if (newPageNumber !== this.currentPageNumber) {
  425. this.container.removeChild(this.cursorElement);
  426. this.container = document.getElementById(this.rules.DYContainerId + newPageNumber);
  427. this.container.appendChild(this.cursorElement);
  428. // TODO maybe store this.pageCurrentlyAttachedTo, though right now it isn't necessary
  429. // alternative to remove/append:
  430. // this.openSheetMusicDisplay.enableOrDisableCursor(true);
  431. }
  432. return this.currentPageNumber = newPageNumber;
  433. }
  434. return 1;
  435. }
  436. }