VexFlowMultiRestMeasure.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import Vex from "vexflow";
  2. import {SourceMeasure} from "../../VoiceData/SourceMeasure";
  3. import {Staff} from "../../VoiceData/Staff";
  4. import {StaffLine} from "../StaffLine";
  5. import {Beam} from "../../VoiceData/Beam";
  6. import {GraphicalNote} from "../GraphicalNote";
  7. import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
  8. import {Tuplet} from "../../VoiceData/Tuplet";
  9. import {GraphicalVoiceEntry} from "../GraphicalVoiceEntry";
  10. import {Voice} from "../../VoiceData/Voice";
  11. import {VexFlowMeasure} from "./VexFlowMeasure";
  12. // type StemmableNote = Vex.Flow.StemmableNote;
  13. /** A GraphicalMeasure drawing a multiple-rest measure in Vexflow.
  14. * Mostly copied from VexFlowMeasure.
  15. * Even though most of those functions aren't needed, apparently you can't remove the layoutStaffEntry function.
  16. */
  17. export class VexFlowMultiRestMeasure extends VexFlowMeasure {
  18. private multiRestElement: any; // VexFlow: Element
  19. constructor(staff: Staff, sourceMeasure: SourceMeasure = undefined, staffLine: StaffLine = undefined) {
  20. super(staff, sourceMeasure, staffLine);
  21. this.minimumStaffEntriesWidth = -1;
  22. /*
  23. * There is no case in which `staffLine === undefined && sourceMeasure === undefined` holds.
  24. * Hence, it is not necessary to specify an `else` case.
  25. * One can verify this through a usage search for this constructor.
  26. */
  27. if (staffLine) {
  28. this.rules = staffLine.ParentMusicSystem.rules;
  29. } else if (sourceMeasure) {
  30. this.rules = sourceMeasure.Rules;
  31. }
  32. this.resetLayout();
  33. this.multiRestElement = new Vex.Flow.MultiMeasureRest(sourceMeasure.multipleRestMeasures, {
  34. // number_line: 3
  35. });
  36. }
  37. /**
  38. * Draw this measure on a VexFlow CanvasContext
  39. * @param ctx
  40. */
  41. public draw(ctx: Vex.IRenderContext): void {
  42. // Draw stave lines
  43. this.stave.setContext(ctx).draw();
  44. this.multiRestElement.setStave(this.stave);
  45. this.multiRestElement.setContext(ctx);
  46. this.multiRestElement.draw();
  47. // Draw vertical lines
  48. for (const connector of this.connectors) {
  49. connector.setContext(ctx).draw();
  50. }
  51. }
  52. public format(): void {
  53. // like most of the following methods, not necessary / can be simplified for MultiRestMeasure.
  54. }
  55. /**
  56. * Returns all the voices that are present in this measure
  57. */
  58. public getVoicesWithinMeasure(): Voice[] {
  59. return []; // we should still return a list here, not undefined, i guess.
  60. }
  61. /**
  62. * Returns all the graphicalVoiceEntries of a given Voice.
  63. * @param voice the voice for which the graphicalVoiceEntries shall be returned.
  64. */
  65. public getGraphicalVoiceEntriesPerVoice(voice: Voice): GraphicalVoiceEntry[] {
  66. return [];
  67. }
  68. /**
  69. * Finds the gaps between the existing notes within a measure.
  70. * Problem here is, that the graphicalVoiceEntry does not exist yet and
  71. * that Tied notes are not present in the normal voiceEntries.
  72. * To handle this, calculation with absolute timestamps is needed.
  73. * And the graphical notes have to be analysed directly (and not the voiceEntries, as it actually should be -> needs refactoring)
  74. * @param voice the voice for which the ghost notes shall be searched.
  75. */
  76. protected getRestFilledVexFlowStaveNotesPerVoice(voice: Voice): GraphicalVoiceEntry[] {
  77. return [];
  78. }
  79. /**
  80. * Add a note to a beam
  81. * @param graphicalNote
  82. * @param beam
  83. */
  84. public handleBeam(graphicalNote: GraphicalNote, beam: Beam): void {
  85. return;
  86. }
  87. public handleTuplet(graphicalNote: GraphicalNote, tuplet: Tuplet): void {
  88. return;
  89. }
  90. /**
  91. * Complete the creation of VexFlow Beams in this measure
  92. */
  93. public finalizeBeams(): void {
  94. return;
  95. }
  96. /**
  97. * Complete the creation of VexFlow Tuplets in this measure
  98. */
  99. public finalizeTuplets(): void {
  100. return;
  101. }
  102. // this needs to exist, for some reason, or it won't be found, even though i can't find the usage.
  103. public layoutStaffEntry(graphicalStaffEntry: GraphicalStaffEntry): void {
  104. return;
  105. }
  106. public graphicalMeasureCreatedCalculations(): void {
  107. return;
  108. }
  109. /**
  110. * Create the articulations for all notes of the current staff entry
  111. */
  112. protected createArticulations(): void {
  113. return;
  114. }
  115. /**
  116. * Create the ornaments for all notes of the current staff entry
  117. */
  118. protected createOrnaments(): void {
  119. return;
  120. }
  121. protected createFingerings(voiceEntry: GraphicalVoiceEntry): void {
  122. return;
  123. }
  124. /**
  125. * Return the VexFlow Stave corresponding to this graphicalMeasure
  126. * @returns {Vex.Flow.Stave}
  127. */
  128. public getVFStave(): Vex.Flow.Stave {
  129. return this.stave;
  130. }
  131. }