VexFlowGraphicalSymbolFactory.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import {IGraphicalSymbolFactory} from "../../Interfaces/IGraphicalSymbolFactory";
  2. import {GraphicalMusicPage} from "../GraphicalMusicPage";
  3. import {MusicSystem} from "../MusicSystem";
  4. import {VexFlowMusicSystem} from "./VexFlowMusicSystem";
  5. import {Staff} from "../../VoiceData/Staff";
  6. import {StaffLine} from "../StaffLine";
  7. import {VexFlowStaffLine} from "./VexFlowStaffLine";
  8. import {SourceMeasure} from "../../VoiceData/SourceMeasure";
  9. import {GraphicalMeasure} from "../GraphicalMeasure";
  10. import {VexFlowMeasure} from "./VexFlowMeasure";
  11. import {SourceStaffEntry} from "../../VoiceData/SourceStaffEntry";
  12. import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
  13. import {VexFlowStaffEntry} from "./VexFlowStaffEntry";
  14. import {Note} from "../../VoiceData/Note";
  15. import {ClefInstruction} from "../../VoiceData/Instructions/ClefInstruction";
  16. import {OctaveEnum} from "../../VoiceData/Expressions/ContinuousExpressions/OctaveShift";
  17. import {GraphicalNote} from "../GraphicalNote";
  18. import {Pitch} from "../../../Common/DataObjects/Pitch";
  19. import {VexFlowGraphicalNote} from "./VexFlowGraphicalNote";
  20. import {Fraction} from "../../../Common/DataObjects/Fraction";
  21. import {GraphicalChordSymbolContainer} from "../GraphicalChordSymbolContainer";
  22. import {GraphicalLabel} from "../GraphicalLabel";
  23. import {EngravingRules} from "../EngravingRules";
  24. import { TechnicalInstruction } from "../../VoiceData/Instructions/TechnicalInstruction";
  25. import { GraphicalVoiceEntry } from "../GraphicalVoiceEntry";
  26. import { VoiceEntry } from "../../VoiceData/VoiceEntry";
  27. import { VexFlowVoiceEntry } from "./VexFlowVoiceEntry";
  28. export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
  29. /**
  30. * Create a new music system for the given page.
  31. * Currently only one vertically endless page exists where all systems are put to.
  32. * @param page
  33. * @param systemIndex
  34. * @returns {VexFlowMusicSystem}
  35. */
  36. public createMusicSystem(page: GraphicalMusicPage, systemIndex: number): MusicSystem {
  37. return new VexFlowMusicSystem(page, systemIndex);
  38. }
  39. /**
  40. * Create a staffline object containing all staff measures belonging to a given system and staff.
  41. * @param parentSystem
  42. * @param parentStaff
  43. * @returns {VexFlowStaffLine}
  44. */
  45. public createStaffLine(parentSystem: MusicSystem, parentStaff: Staff): StaffLine {
  46. return new VexFlowStaffLine(parentSystem, parentStaff);
  47. }
  48. /**
  49. * Construct an empty graphicalMeasure from the given source measure and staff.
  50. * @param sourceMeasure
  51. * @param staff
  52. * @returns {VexFlowMeasure}
  53. */
  54. public createGraphicalMeasure(sourceMeasure: SourceMeasure, staff: Staff): GraphicalMeasure {
  55. return new VexFlowMeasure(staff, undefined, sourceMeasure);
  56. }
  57. /**
  58. * Create empty measure, which will be used to show key, rhythm changes at the end of the system.
  59. * @param staffLine
  60. * @returns {VexFlowMeasure}
  61. */
  62. public createExtraGraphicalMeasure(staffLine: StaffLine): GraphicalMeasure {
  63. return new VexFlowMeasure(staffLine.ParentStaff, staffLine);
  64. }
  65. /**
  66. * Create a staffEntry in the given measure for a given sourceStaffEntry.
  67. * @param sourceStaffEntry
  68. * @param measure
  69. * @returns {VexFlowStaffEntry}
  70. */
  71. public createStaffEntry(sourceStaffEntry: SourceStaffEntry, measure: GraphicalMeasure): GraphicalStaffEntry {
  72. return new VexFlowStaffEntry(<VexFlowMeasure>measure, sourceStaffEntry, undefined);
  73. }
  74. public createVoiceEntry(parentVoiceEntry: VoiceEntry, parentStaffEntry: GraphicalStaffEntry): GraphicalVoiceEntry {
  75. return new VexFlowVoiceEntry(parentVoiceEntry, parentStaffEntry);
  76. }
  77. /**
  78. * Create a Graphical Note for given note and clef and as part of graphicalStaffEntry.
  79. * @param note
  80. * @param numberOfDots The number of dots the note has to increase its musical duration.
  81. * @param graphicalStaffEntry
  82. * @param activeClef The currently active clef, needed for positioning the note vertically
  83. * @param octaveShift The currently active octave transposition enum, needed for positioning the note vertically
  84. * @returns {GraphicalNote}
  85. */
  86. public createNote(note: Note, graphicalVoiceEntry: GraphicalVoiceEntry,
  87. activeClef: ClefInstruction, octaveShift: OctaveEnum = OctaveEnum.NONE, graphicalNoteLength: Fraction = undefined): GraphicalNote {
  88. // Creates and returns the note:
  89. return new VexFlowGraphicalNote(note, graphicalVoiceEntry, activeClef, octaveShift, graphicalNoteLength);
  90. }
  91. /**
  92. * Create a Graphical Grace Note (smaller head, stem...) for given note and clef and as part of graphicalStaffEntry.
  93. * @param note
  94. * @param numberOfDots
  95. * @param graphicalVoiceEntry
  96. * @param activeClef
  97. * @param octaveShift
  98. * @returns {GraphicalNote}
  99. */
  100. public createGraceNote(note: Note, graphicalVoiceEntry: GraphicalVoiceEntry,
  101. activeClef: ClefInstruction, octaveShift: OctaveEnum = OctaveEnum.NONE): GraphicalNote {
  102. return new VexFlowGraphicalNote(note, graphicalVoiceEntry, activeClef, octaveShift);
  103. }
  104. /**
  105. * Sets a pitch which will be used for rendering the given graphical note (not changing the original pitch of the note!!!).
  106. * Will be only called if the displayed accidental is different from the original (e.g. a C# with C# as key instruction)
  107. * @param graphicalNote
  108. * @param pitch The pitch which will be rendered.
  109. */
  110. public addGraphicalAccidental(graphicalNote: GraphicalNote, pitch: Pitch): void {
  111. // ToDo: set accidental here from pitch.Accidental
  112. const note: VexFlowGraphicalNote = (graphicalNote as VexFlowGraphicalNote);
  113. note.setPitch(pitch);
  114. }
  115. /**
  116. * Adds a Fermata symbol at the last note of the given tied Note.
  117. * The last graphical note of this tied note is located at the given graphicalStaffEntry.
  118. * A Fermata has to be located at the last tied note.
  119. * @param tiedNote
  120. * @param graphicalStaffEntry
  121. */
  122. public addFermataAtTiedEndNote(tiedNote: Note, graphicalStaffEntry: GraphicalStaffEntry): void {
  123. return;
  124. }
  125. /**
  126. * Adds a clef change within a measure before the given staff entry.
  127. * @param graphicalStaffEntry
  128. * @param clefInstruction
  129. */
  130. public createInStaffClef(graphicalStaffEntry: GraphicalStaffEntry, clefInstruction: ClefInstruction): void {
  131. return;
  132. }
  133. /**
  134. * Adds a chord symbol at the given staff entry
  135. * @param sourceStaffEntry
  136. * @param graphicalStaffEntry
  137. * @param transposeHalftones
  138. */
  139. public createChordSymbol(sourceStaffEntry: SourceStaffEntry, graphicalStaffEntry: GraphicalStaffEntry, transposeHalftones: number): void {
  140. const graphicalChordSymbolContainer: GraphicalChordSymbolContainer =
  141. new GraphicalChordSymbolContainer(sourceStaffEntry.ChordContainer,
  142. graphicalStaffEntry.PositionAndShape,
  143. EngravingRules.Rules.ChordSymbolTextHeight,
  144. transposeHalftones);
  145. const graphicalLabel: GraphicalLabel = graphicalChordSymbolContainer.GetGraphicalLabel;
  146. graphicalLabel.setLabelPositionAndShapeBorders();
  147. graphicalChordSymbolContainer.PositionAndShape.calculateBoundingBox();
  148. graphicalStaffEntry.graphicalChordContainer = graphicalChordSymbolContainer;
  149. }
  150. /**
  151. * Adds a technical instruction at the given staff entry.
  152. * @param technicalInstruction
  153. * @param graphicalStaffEntry
  154. */
  155. public createGraphicalTechnicalInstruction(technicalInstruction: TechnicalInstruction, graphicalStaffEntry: GraphicalStaffEntry): void {
  156. return;
  157. }
  158. }