VexFlowMeasure.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. import Vex = require("vexflow");
  2. import {StaffMeasure} from "../StaffMeasure";
  3. import {SourceMeasure} from "../../VoiceData/SourceMeasure";
  4. import {Staff} from "../../VoiceData/Staff";
  5. import {StaffLine} from "../StaffLine";
  6. import {SystemLinesEnum} from "../SystemLinesEnum";
  7. import {ClefInstruction} from "../../VoiceData/Instructions/ClefInstruction";
  8. import {KeyInstruction} from "../../VoiceData/Instructions/KeyInstruction";
  9. import {RhythmInstruction} from "../../VoiceData/Instructions/RhythmInstruction";
  10. import {VexFlowConverter, VexFlowRepetitionType, VexFlowBarlineType} from "./VexFlowConverter";
  11. import {VexFlowStaffEntry} from "./VexFlowStaffEntry";
  12. import {Beam} from "../../VoiceData/Beam";
  13. import {GraphicalNote} from "../GraphicalNote";
  14. import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
  15. import StaveConnector = Vex.Flow.StaveConnector;
  16. import StaveNote = Vex.Flow.StaveNote;
  17. import {Logging} from "../../../Common/Logging";
  18. import {unitInPixels} from "./VexFlowMusicSheetDrawer";
  19. import {Tuplet} from "../../VoiceData/Tuplet";
  20. import { RepetitionInstructionEnum } from "../../VoiceData/Instructions/RepetitionInstruction";
  21. import { SystemLinePosition } from "../SystemLinePosition";
  22. import { StemDirectionType } from "../../VoiceData/VoiceEntry";
  23. export class VexFlowMeasure extends StaffMeasure {
  24. constructor(staff: Staff, staffLine: StaffLine = undefined, sourceMeasure: SourceMeasure = undefined) {
  25. super(staff, sourceMeasure, staffLine);
  26. this.minimumStaffEntriesWidth = -1;
  27. this.resetLayout();
  28. }
  29. // octaveOffset according to active clef
  30. public octaveOffset: number = 3;
  31. // The VexFlow Voices in the measure
  32. public vfVoices: { [voiceID: number]: Vex.Flow.Voice; } = {};
  33. // Call this function (if present) to x-format all the voices in the measure
  34. public formatVoices: (width: number) => void;
  35. // The VexFlow Ties in the measure
  36. public vfTies: Vex.Flow.StaveTie[] = [];
  37. // The repetition instructions given as words or symbols (coda, dal segno..)
  38. public vfRepetitionWords: Vex.Flow.Repetition[] = [];
  39. // The VexFlow Stave (= one measure in a staffline)
  40. private stave: Vex.Flow.Stave;
  41. // VexFlow StaveConnectors (vertical lines)
  42. private connectors: Vex.Flow.StaveConnector[] = [];
  43. // Intermediate object to construct beams
  44. private beams: { [voiceID: number]: [Beam, VexFlowStaffEntry[]][]; } = {};
  45. // VexFlow Beams
  46. private vfbeams: { [voiceID: number]: Vex.Flow.Beam[]; };
  47. // Intermediate object to construct tuplets
  48. private tuplets: { [voiceID: number]: [Tuplet, VexFlowStaffEntry[]][]; } = {};
  49. // VexFlow Tuplets
  50. private vftuplets: { [voiceID: number]: Vex.Flow.Tuplet[]; } = {};
  51. // Sets the absolute coordinates of the VFStave on the canvas
  52. public setAbsoluteCoordinates(x: number, y: number): void {
  53. this.stave.setX(x).setY(y);
  54. }
  55. /**
  56. * Reset all the geometric values and parameters of this measure and put it in an initialized state.
  57. * This is needed to evaluate a measure a second time by system builder.
  58. */
  59. public resetLayout(): void {
  60. // Take into account some space for the begin and end lines of the stave
  61. // Will be changed when repetitions will be implemented
  62. //this.beginInstructionsWidth = 20 / UnitInPixels;
  63. //this.endInstructionsWidth = 20 / UnitInPixels;
  64. this.stave = new Vex.Flow.Stave(0, 0, 0, {
  65. space_above_staff_ln: 0,
  66. space_below_staff_ln: 0,
  67. });
  68. this.updateInstructionWidth();
  69. }
  70. public clean(): void {
  71. this.vfTies.length = 0;
  72. this.connectors = [];
  73. // Clean up instructions
  74. this.resetLayout();
  75. }
  76. /**
  77. * returns the x-width (in units) of a given measure line {SystemLinesEnum}.
  78. * @param line
  79. * @returns the x-width in osmd units
  80. */
  81. public getLineWidth(line: SystemLinesEnum): number {
  82. switch (line) {
  83. // return 0 for the normal lines, as the line width will be considered at the updateInstructionWidth() method using the stavemodifiers.
  84. // case SystemLinesEnum.SingleThin:
  85. // return 5.0 / unitInPixels;
  86. // case SystemLinesEnum.DoubleThin:
  87. // return 5.0 / unitInPixels;
  88. // case SystemLinesEnum.ThinBold:
  89. // return 5.0 / unitInPixels;
  90. // but just add a little extra space for repetitions (cosmetics):
  91. case SystemLinesEnum.BoldThinDots:
  92. case SystemLinesEnum.DotsThinBold:
  93. return 10.0 / unitInPixels;
  94. case SystemLinesEnum.DotsBoldBoldDots:
  95. return 10.0 / unitInPixels;
  96. default:
  97. return 0;
  98. }
  99. }
  100. /**
  101. * adds the given clef to the begin of the measure.
  102. * This has to update/increase BeginInstructionsWidth.
  103. * @param clef
  104. */
  105. public addClefAtBegin(clef: ClefInstruction): void {
  106. this.octaveOffset = clef.OctaveOffset;
  107. const vfclef: { type: string, size: string, annotation: string } = VexFlowConverter.Clef(clef, "default");
  108. this.stave.addClef(vfclef.type, vfclef.size, vfclef.annotation, Vex.Flow.Modifier.Position.BEGIN);
  109. this.updateInstructionWidth();
  110. }
  111. /**
  112. * adds the given key to the begin of the measure.
  113. * This has to update/increase BeginInstructionsWidth.
  114. * @param currentKey the new valid key.
  115. * @param previousKey the old cancelled key. Needed to show which accidentals are not valid any more.
  116. * @param currentClef the valid clef. Needed to put the accidentals on the right y-positions.
  117. */
  118. public addKeyAtBegin(currentKey: KeyInstruction, previousKey: KeyInstruction, currentClef: ClefInstruction): void {
  119. this.stave.setKeySignature(
  120. VexFlowConverter.keySignature(currentKey),
  121. VexFlowConverter.keySignature(previousKey),
  122. undefined
  123. );
  124. this.updateInstructionWidth();
  125. }
  126. /**
  127. * adds the given rhythm to the begin of the measure.
  128. * This has to update/increase BeginInstructionsWidth.
  129. * @param rhythm
  130. */
  131. public addRhythmAtBegin(rhythm: RhythmInstruction): void {
  132. const timeSig: Vex.Flow.TimeSignature = VexFlowConverter.TimeSignature(rhythm);
  133. this.stave.addModifier(
  134. timeSig,
  135. Vex.Flow.Modifier.Position.BEGIN
  136. );
  137. this.updateInstructionWidth();
  138. }
  139. /**
  140. * adds the given clef to the end of the measure.
  141. * This has to update/increase EndInstructionsWidth.
  142. * @param clef
  143. */
  144. public addClefAtEnd(clef: ClefInstruction): void {
  145. const vfclef: { type: string, size: string, annotation: string } = VexFlowConverter.Clef(clef, "small");
  146. this.stave.setEndClef(vfclef.type, vfclef.size, vfclef.annotation);
  147. this.updateInstructionWidth();
  148. }
  149. public addMeasureLine(lineType: SystemLinesEnum, linePosition: SystemLinePosition): void {
  150. switch (linePosition) {
  151. case SystemLinePosition.MeasureBegin:
  152. switch (lineType) {
  153. case SystemLinesEnum.BoldThinDots:
  154. this.stave.setBegBarType(VexFlowBarlineType.REPEAT_BEGIN);
  155. break;
  156. default:
  157. break;
  158. }
  159. break;
  160. case SystemLinePosition.MeasureEnd:
  161. switch (lineType) {
  162. case SystemLinesEnum.DotsBoldBoldDots:
  163. this.stave.setEndBarType(VexFlowBarlineType.REPEAT_BOTH);
  164. break;
  165. case SystemLinesEnum.DotsThinBold:
  166. this.stave.setEndBarType(VexFlowBarlineType.REPEAT_END);
  167. break;
  168. case SystemLinesEnum.DoubleThin:
  169. this.stave.setEndBarType(VexFlowBarlineType.DOUBLE);
  170. break;
  171. case SystemLinesEnum.ThinBold:
  172. this.stave.setEndBarType(VexFlowBarlineType.END);
  173. break;
  174. default:
  175. break;
  176. }
  177. break;
  178. default:
  179. break;
  180. }
  181. }
  182. public addWordRepetition(repetitionInstruction: RepetitionInstructionEnum): void {
  183. let instruction: VexFlowRepetitionType = undefined;
  184. let position: any = Vex.Flow.Modifier.Position.END;
  185. switch (repetitionInstruction) {
  186. case RepetitionInstructionEnum.Segno:
  187. // create Segno Symbol:
  188. instruction = VexFlowRepetitionType.SEGNO_LEFT;
  189. position = Vex.Flow.Modifier.Position.BEGIN;
  190. break;
  191. case RepetitionInstructionEnum.Coda:
  192. // create Coda Symbol:
  193. instruction = VexFlowRepetitionType.CODA_LEFT;
  194. position = Vex.Flow.Modifier.Position.BEGIN;
  195. break;
  196. case RepetitionInstructionEnum.DaCapo:
  197. instruction = VexFlowRepetitionType.DC;
  198. break;
  199. case RepetitionInstructionEnum.DalSegno:
  200. instruction = VexFlowRepetitionType.DS;
  201. break;
  202. case RepetitionInstructionEnum.Fine:
  203. instruction = VexFlowRepetitionType.FINE;
  204. break;
  205. case RepetitionInstructionEnum.ToCoda:
  206. //instruction = "To Coda";
  207. break;
  208. case RepetitionInstructionEnum.DaCapoAlFine:
  209. instruction = VexFlowRepetitionType.DC_AL_FINE;
  210. break;
  211. case RepetitionInstructionEnum.DaCapoAlCoda:
  212. instruction = VexFlowRepetitionType.DC_AL_CODA;
  213. break;
  214. case RepetitionInstructionEnum.DalSegnoAlFine:
  215. instruction = VexFlowRepetitionType.DS_AL_FINE;
  216. break;
  217. case RepetitionInstructionEnum.DalSegnoAlCoda:
  218. instruction = VexFlowRepetitionType.DS_AL_CODA;
  219. break;
  220. default:
  221. break;
  222. }
  223. if (instruction !== undefined) {
  224. this.stave.addModifier(new Vex.Flow.Repetition(instruction, 0, 0), position);
  225. }
  226. }
  227. /**
  228. * Sets the overall x-width of the measure.
  229. * @param width
  230. */
  231. public setWidth(width: number): void {
  232. super.setWidth(width);
  233. // Set the width of the Vex.Flow.Stave
  234. this.stave.setWidth(width * unitInPixels);
  235. // Force the width of the Begin Instructions
  236. //this.stave.setNoteStartX(this.beginInstructionsWidth * UnitInPixels);
  237. }
  238. /**
  239. * This method is called after the StaffEntriesScaleFactor has been set.
  240. * Here the final x-positions of the staff entries have to be set.
  241. * (multiply the minimal positions with the scaling factor, considering the BeginInstructionsWidth)
  242. */
  243. public layoutSymbols(): void {
  244. //this.stave.format();
  245. }
  246. //public addGraphicalStaffEntry(entry: VexFlowStaffEntry): void {
  247. // super.addGraphicalStaffEntry(entry);
  248. //}
  249. //
  250. //public addGraphicalStaffEntryAtTimestamp(entry: VexFlowStaffEntry): void {
  251. // super.addGraphicalStaffEntryAtTimestamp(entry);
  252. // // TODO
  253. //}
  254. /**
  255. * Draw this measure on a VexFlow CanvasContext
  256. * @param ctx
  257. */
  258. public draw(ctx: Vex.Flow.RenderContext): void {
  259. // Draw stave lines
  260. this.stave.setContext(ctx).draw();
  261. // Draw all voices
  262. for (const voiceID in this.vfVoices) {
  263. if (this.vfVoices.hasOwnProperty(voiceID)) {
  264. this.vfVoices[voiceID].draw(ctx, this.stave);
  265. }
  266. }
  267. // Draw beams
  268. for (const voiceID in this.vfbeams) {
  269. if (this.vfbeams.hasOwnProperty(voiceID)) {
  270. for (const beam of this.vfbeams[voiceID]) {
  271. beam.setContext(ctx).draw();
  272. }
  273. }
  274. }
  275. // Draw tuplets
  276. for (const voiceID in this.vftuplets) {
  277. if (this.vftuplets.hasOwnProperty(voiceID)) {
  278. for (const tuplet of this.vftuplets[voiceID]) {
  279. tuplet.setContext(ctx).draw();
  280. }
  281. }
  282. }
  283. // Draw ties
  284. for (const tie of this.vfTies) {
  285. tie.setContext(ctx).draw();
  286. }
  287. // Draw vertical lines
  288. for (const connector of this.connectors) {
  289. connector.setContext(ctx).draw();
  290. }
  291. }
  292. public format(): void {
  293. // If this is the first stave in the vertical measure, call the format
  294. // method to set the width of all the voices
  295. if (this.formatVoices) {
  296. // The width of the voices does not include the instructions (StaveModifiers)
  297. this.formatVoices((this.PositionAndShape.BorderRight - this.beginInstructionsWidth - this.endInstructionsWidth) * unitInPixels);
  298. }
  299. // Force the width of the Begin Instructions
  300. this.stave.setNoteStartX(this.stave.getX() + unitInPixels * this.beginInstructionsWidth);
  301. }
  302. /**
  303. * Add a note to a beam
  304. * @param graphicalNote
  305. * @param beam
  306. */
  307. public handleBeam(graphicalNote: GraphicalNote, beam: Beam): void {
  308. const voiceID: number = graphicalNote.sourceNote.ParentVoiceEntry.ParentVoice.VoiceId;
  309. let beams: [Beam, VexFlowStaffEntry[]][] = this.beams[voiceID];
  310. if (beams === undefined) {
  311. beams = this.beams[voiceID] = [];
  312. }
  313. let data: [Beam, VexFlowStaffEntry[]];
  314. for (const mybeam of beams) {
  315. if (mybeam[0] === beam) {
  316. data = mybeam;
  317. }
  318. }
  319. if (data === undefined) {
  320. data = [beam, []];
  321. beams.push(data);
  322. }
  323. const parent: VexFlowStaffEntry = graphicalNote.parentStaffEntry as VexFlowStaffEntry;
  324. if (data[1].indexOf(parent) < 0) {
  325. data[1].push(parent);
  326. }
  327. }
  328. public handleTuplet(graphicalNote: GraphicalNote, tuplet: Tuplet): void {
  329. const voiceID: number = graphicalNote.sourceNote.ParentVoiceEntry.ParentVoice.VoiceId;
  330. tuplet = graphicalNote.sourceNote.NoteTuplet;
  331. let tuplets: [Tuplet, VexFlowStaffEntry[]][] = this.tuplets[voiceID];
  332. if (tuplets === undefined) {
  333. tuplets = this.tuplets[voiceID] = [];
  334. }
  335. let currentTupletBuilder: [Tuplet, VexFlowStaffEntry[]];
  336. for (const t of tuplets) {
  337. if (t[0] === tuplet) {
  338. currentTupletBuilder = t;
  339. }
  340. }
  341. if (currentTupletBuilder === undefined) {
  342. currentTupletBuilder = [tuplet, []];
  343. tuplets.push(currentTupletBuilder);
  344. }
  345. const parent: VexFlowStaffEntry = graphicalNote.parentStaffEntry as VexFlowStaffEntry;
  346. if (currentTupletBuilder[1].indexOf(parent) < 0) {
  347. currentTupletBuilder[1].push(parent);
  348. }
  349. }
  350. /**
  351. * Complete the creation of VexFlow Beams in this measure
  352. */
  353. public finalizeBeams(): void {
  354. // The following line resets the created Vex.Flow Beams and
  355. // created them brand new. Is this needed? And more importantly,
  356. // should the old beams be removed manually by the notes?
  357. this.vfbeams = {};
  358. for (const voiceID in this.beams) {
  359. if (this.beams.hasOwnProperty(voiceID)) {
  360. let vfbeams: Vex.Flow.Beam[] = this.vfbeams[voiceID];
  361. if (vfbeams === undefined) {
  362. vfbeams = this.vfbeams[voiceID] = [];
  363. }
  364. for (const beam of this.beams[voiceID]) {
  365. const notes: Vex.Flow.StaveNote[] = [];
  366. const staffEntries: VexFlowStaffEntry[] = beam[1];
  367. const autoStemBeam: boolean = staffEntries[0].graphicalNotes[voiceID][0].sourceNote.
  368. ParentVoiceEntry.StemDirection === StemDirectionType.Undefined;
  369. for (const entry of staffEntries) {
  370. const note: Vex.Flow.StaveNote = (<VexFlowStaffEntry>entry).vfNotes[voiceID];
  371. if (note !== undefined) {
  372. notes.push(note);
  373. }
  374. }
  375. if (notes.length > 1) {
  376. const vfBeam: Vex.Flow.Beam = new Vex.Flow.Beam(notes, autoStemBeam);
  377. vfbeams.push(vfBeam);
  378. // just a test for coloring the notes:
  379. // for (let note of notes) {
  380. // (<Vex.Flow.StaveNote> note).setStyle({fillStyle: "green", strokeStyle: "green"});
  381. // }
  382. } else {
  383. Logging.log("Warning! Beam with no notes!");
  384. }
  385. }
  386. }
  387. }
  388. }
  389. /**
  390. * Complete the creation of VexFlow Tuplets in this measure
  391. */
  392. public finalizeTuplets(): void {
  393. // The following line resets the created Vex.Flow Tuplets and
  394. // created them brand new. Is this needed? And more importantly,
  395. // should the old tuplets be removed manually from the notes?
  396. this.vftuplets = {};
  397. for (const voiceID in this.tuplets) {
  398. if (this.tuplets.hasOwnProperty(voiceID)) {
  399. let vftuplets: Vex.Flow.Tuplet[] = this.vftuplets[voiceID];
  400. if (vftuplets === undefined) {
  401. vftuplets = this.vftuplets[voiceID] = [];
  402. }
  403. for (const tupletBuilder of this.tuplets[voiceID]) {
  404. const tupletStaveNotes: Vex.Flow.StaveNote[] = [];
  405. const tupletStaffEntries: VexFlowStaffEntry[] = tupletBuilder[1];
  406. for (const tupletStaffEntry of tupletStaffEntries) {
  407. tupletStaveNotes.push((tupletStaffEntry).vfNotes[voiceID]);
  408. }
  409. if (tupletStaveNotes.length > 1) {
  410. const notesOccupied: number = 2;
  411. vftuplets.push(new Vex.Flow.Tuplet( tupletStaveNotes,
  412. {
  413. notes_occupied: notesOccupied,
  414. num_notes: tupletStaveNotes.length //, location: -1, ratioed: true
  415. }));
  416. } else {
  417. Logging.log("Warning! Tuplet with no notes! Trying to ignore, but this is a serious problem.");
  418. }
  419. }
  420. }
  421. }
  422. }
  423. public layoutStaffEntry(graphicalStaffEntry: GraphicalStaffEntry): void {
  424. return;
  425. }
  426. public staffMeasureCreatedCalculations(): void {
  427. for (let idx: number = 0, len: number = this.staffEntries.length; idx < len; ++idx) {
  428. const graphicalStaffEntry: VexFlowStaffEntry = (this.staffEntries[idx] as VexFlowStaffEntry);
  429. // create vex flow Notes:
  430. const gnotes: { [voiceID: number]: GraphicalNote[]; } = graphicalStaffEntry.graphicalNotes;
  431. for (const voiceID in gnotes) {
  432. if (gnotes.hasOwnProperty(voiceID)) {
  433. const vfnote: StaveNote = VexFlowConverter.StaveNote(gnotes[voiceID]);
  434. (graphicalStaffEntry as VexFlowStaffEntry).vfNotes[voiceID] = vfnote;
  435. }
  436. }
  437. }
  438. this.finalizeBeams();
  439. this.finalizeTuplets();
  440. for (let idx: number = 0, len: number = this.staffEntries.length; idx < len; ++idx) {
  441. const graphicalStaffEntry: VexFlowStaffEntry = (this.staffEntries[idx] as VexFlowStaffEntry);
  442. const gnotes: { [voiceID: number]: GraphicalNote[]; } = graphicalStaffEntry.graphicalNotes;
  443. // create vex flow voices and add tickables to it:
  444. const vfVoices: { [voiceID: number]: Vex.Flow.Voice; } = this.vfVoices;
  445. for (const voiceID in gnotes) {
  446. if (gnotes.hasOwnProperty(voiceID)) {
  447. if (!(voiceID in vfVoices)) {
  448. vfVoices[voiceID] = new Vex.Flow.Voice({
  449. beat_value: this.parentSourceMeasure.Duration.Denominator,
  450. num_beats: this.parentSourceMeasure.Duration.Numerator,
  451. resolution: Vex.Flow.RESOLUTION,
  452. }).setMode(Vex.Flow.Voice.Mode.SOFT);
  453. }
  454. vfVoices[voiceID].addTickable(graphicalStaffEntry.vfNotes[voiceID]);
  455. }
  456. }
  457. }
  458. }
  459. /**
  460. * Creates a line from 'top' to this measure, of type 'lineType'
  461. * @param top
  462. * @param lineType
  463. */
  464. public lineTo(top: VexFlowMeasure, lineType: any): void {
  465. const connector: StaveConnector = new Vex.Flow.StaveConnector(top.getVFStave(), this.stave);
  466. connector.setType(lineType);
  467. this.connectors.push(connector);
  468. }
  469. /**
  470. * Return the VexFlow Stave corresponding to this StaffMeasure
  471. * @returns {Vex.Flow.Stave}
  472. */
  473. public getVFStave(): Vex.Flow.Stave {
  474. return this.stave;
  475. }
  476. /**
  477. * After re-running the formatting on the VexFlow Stave, update the
  478. * space needed by Instructions (in VexFlow: StaveModifiers)
  479. */
  480. private updateInstructionWidth(): void {
  481. let beginInstructionsWidth: number = 0;
  482. let endInstructionsWidth: number = 0;
  483. const modifiers: Vex.Flow.StaveModifier[] = this.stave.getModifiers();
  484. for (const mod of modifiers) {
  485. if (mod.getPosition() === Vex.Flow.StaveModifier.Position.BEGIN) {
  486. beginInstructionsWidth += mod.getWidth() + mod.getPadding(undefined);
  487. } else if (mod.getPosition() === Vex.Flow.StaveModifier.Position.END) {
  488. endInstructionsWidth += mod.getWidth() + mod.getPadding(undefined);
  489. }
  490. }
  491. this.beginInstructionsWidth = beginInstructionsWidth / unitInPixels;
  492. this.endInstructionsWidth = endInstructionsWidth / unitInPixels;
  493. //this.beginInstructionsWidth = (this.stave.getNoteStartX() - this.stave.getX()) / unitInPixels;
  494. //this.endInstructionsWidth = (this.stave.getX() + this.stave.getWidth() - this.stave.getNoteEndX()) / unitInPixels;
  495. }
  496. }