VexFlowMusicSheetCalculator.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import {MusicSheetCalculator} from "../MusicSheetCalculator";
  2. import {VexFlowGraphicalSymbolFactory} from "./VexFlowGraphicalSymbolFactory";
  3. import {GraphicalMusicSheet} from "../GraphicalMusicSheet";
  4. import {StaffMeasure} from "../StaffMeasure";
  5. import {MusicSystemBuilder} from "../MusicSystemBuilder";
  6. import {StaffLine} from "../StaffLine";
  7. import {VoiceEntry} from "../../VoiceData/VoiceEntry";
  8. import {MusicSystem} from "../MusicSystem";
  9. import {GraphicalNote} from "../GraphicalNote";
  10. import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
  11. import {GraphicalMusicPage} from "../GraphicalMusicPage";
  12. import {GraphicalTie} from "../GraphicalTie";
  13. import {Tie} from "../../VoiceData/Tie";
  14. import {SourceMeasure} from "../../VoiceData/SourceMeasure";
  15. import {MultiExpression} from "../../VoiceData/Expressions/multiExpression";
  16. import {RepetitionInstruction} from "../../VoiceData/Instructions/RepetitionInstruction";
  17. import {Beam} from "../../VoiceData/Beam";
  18. import {ClefInstruction} from "../../VoiceData/Instructions/ClefInstruction";
  19. import {OctaveEnum} from "../../VoiceData/Expressions/ContinuousExpressions/octaveShift";
  20. import {Fraction} from "../../../Common/DataObjects/fraction";
  21. import {LyricsEntry} from "../../VoiceData/Lyrics/LyricsEntry";
  22. import {LyricWord} from "../../VoiceData/Lyrics/LyricsWord";
  23. import {OrnamentContainer} from "../../VoiceData/OrnamentContainer";
  24. import {ArticulationEnum} from "../../VoiceData/VoiceEntry";
  25. import {Tuplet} from "../../VoiceData/Tuplet";
  26. import {VexFlowMeasure} from "./VexFlowMeasure";
  27. export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
  28. constructor() {
  29. super(new VexFlowGraphicalSymbolFactory());
  30. }
  31. /**
  32. * The main method for the Calculator.
  33. */
  34. public calculate(): void {
  35. this.clearSystemsAndMeasures();
  36. this.clearRecreatedObjects();
  37. this.calculateXLayout(this.graphicalMusicSheet, this.maxInstrNameLabelLength());
  38. this.graphicalMusicSheet.MusicPages.length = 0;
  39. this.calculateMusicSystems();
  40. this.graphicalMusicSheet.MusicPages[0].PositionAndShape.BorderMarginBottom += 9;
  41. GraphicalMusicSheet.transformRelativeToAbsolutePosition(this.graphicalMusicSheet);
  42. }
  43. /**
  44. * Calculates the x layout of the staff entries within the staff measures belonging to one source measure.
  45. * All staff entries are x-aligned throughout all vertically aligned staff measures.
  46. * This method is called within calculateXLayout.
  47. * The staff entries are aligned with minimum needed x distances.
  48. * The MinimumStaffEntriesWidth of every measure will be set - needed for system building.
  49. * @param measures
  50. */
  51. protected calculateMeasureXLayout(measures: StaffMeasure[]): number {
  52. // set measure length and Borders
  53. for (let idx: number = 0, len: number = measures.length; idx < len; ++idx) {
  54. let measure: VexFlowMeasure = <VexFlowMeasure>measures[idx];
  55. // set Measure StaffEntriesLength (needed later to calculate the whole Measure Width)
  56. //measure.MinimumStaffEntriesWidth = measureLength;
  57. }
  58. }
  59. /**
  60. * Creates the music systems and calculates their layout.
  61. */
  62. protected calculateMusicSystems(): void {
  63. let measureList: StaffMeasure[][] = this.graphicalMusicSheet.MeasureList.Select(ml => ml.Where(m => m.isVisible()).ToList()).ToList();
  64. let numberOfStaffLines: number = 0;
  65. for (let idx: number = 0, len: number = measureList.length; idx < len; ++idx) {
  66. let gmlist: StaffMeasure[] = measureList[idx];
  67. numberOfStaffLines = Math.max(gmlist.length, numberOfStaffLines);
  68. break;
  69. }
  70. if (numberOfStaffLines === 0)
  71. return;
  72. let musicSystemBuilder: MusicSystemBuilder = new MusicSystemBuilder();
  73. musicSystemBuilder.initialize(this.graphicalMusicSheet, measureList, numberOfStaffLines, this.symbolFactory);
  74. musicSystemBuilder.buildMusicSystems();
  75. this.checkMeasuresForWholeRestNotes();
  76. }
  77. protected updateStaffLineBorders(staffLine: StaffLine): void {
  78. }
  79. protected calculateMeasureNumberPlacement(musicSystem: MusicSystem): void {
  80. }
  81. /**
  82. * Can be used to calculate stem directions, helper(ledger) lines, and overlapping note x-displacement.
  83. * Is Excecuted per voice entry of a staff entry.
  84. * After that layoutStaffEntry is called.
  85. * @param voiceEntry
  86. * @param graphicalNotes
  87. * @param graphicalStaffEntry
  88. * @param hasPitchedNote
  89. * @param isGraceStaffEntry
  90. */
  91. protected layoutVoiceEntry(voiceEntry: VoiceEntry, graphicalNotes: GraphicalNote[], graphicalStaffEntry: GraphicalStaffEntry, hasPitchedNote: boolean, isGraceStaffEntry: boolean): void {
  92. }
  93. /**
  94. * Do all layout calculations that have to be done per staff entry, like dots, ornaments, arpeggios....
  95. * This method is called after the voice entries are handled by layoutVoiceEntry().
  96. * @param graphicalStaffEntry
  97. */
  98. protected layoutStaffEntry(graphicalStaffEntry: GraphicalStaffEntry): void {
  99. }
  100. /**
  101. * calculates the y positions of the staff lines within a system and
  102. * furthermore the y positions of the systems themselves.
  103. */
  104. protected calculateSystemYLayout(): void {
  105. for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
  106. let graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
  107. if (!this.leadSheet) {
  108. for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
  109. let musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
  110. // calculate y positions of stafflines within system
  111. // ...
  112. }
  113. }
  114. // set y positions of systems using the previous system and a fixed distance.
  115. // ...
  116. }
  117. }
  118. /**
  119. * Is called at the begin of the method for creating the vertically aligned staff measures belonging to one source measure.
  120. */
  121. protected initStaffMeasuresCreation(): void {
  122. }
  123. protected handleTie(tie: Tie, startGraphicalStaffEntry: GraphicalStaffEntry, staffIndex: number, measureIndex: number): void {
  124. }
  125. protected layoutGraphicalTie(tie: GraphicalTie, tieIsAtSystemBreak: boolean): void {
  126. }
  127. protected calculateSingleStaffLineLyricsPosition(staffLine: StaffLine, lyricVersesNumber: number[]): void {
  128. }
  129. protected calculateSingleOctaveShift(sourceMeasure: SourceMeasure, multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
  130. }
  131. protected calculateWordRepetitionInstruction(repetitionInstruction: RepetitionInstruction, measureIndex: number): void {
  132. }
  133. protected calculateMoodAndUnknownExpression(multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
  134. }
  135. protected createGraphicalTieNote(beams: Beam[], activeClef: ClefInstruction,
  136. octaveShiftValue: OctaveEnum, graphicalStaffEntry: GraphicalStaffEntry, duration: Fraction, numberOfDots: number,
  137. openTie: Tie, isLastTieNote: boolean): void {
  138. }
  139. /**
  140. * Is called if a note is part of a beam.
  141. * @param graphicalNote
  142. * @param beam
  143. * @param openBeams a list of all currently open beams
  144. */
  145. protected handleBeam(graphicalNote: GraphicalNote, beam: Beam, openBeams: Beam[]): void {
  146. }
  147. protected handleVoiceEntryLyrics(lyricsEntries: Dictionary<number, LyricsEntry>, voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry, openLyricWords: LyricWord[]): void {
  148. }
  149. protected handleVoiceEntryOrnaments(ornamentContainer: OrnamentContainer, voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry): void {
  150. }
  151. protected handleVoiceEntryArticulations(articulations: ArticulationEnum[], voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry): void {
  152. }
  153. /**
  154. * Is called if a note is part of a tuplet.
  155. * @param graphicalNote
  156. * @param tuplet
  157. * @param openTuplets a list of all currently open tuplets
  158. */
  159. protected handleTuplet(graphicalNote: GraphicalNote, tuplet: Tuplet, openTuplets: Tuplet[]): void {
  160. }
  161. }