VexFlowGraphicalSymbolFactory.ts 7.4 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 {StaffMeasure} from "../StaffMeasure";
  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 {TechnicalInstruction} from "../../VoiceData/Instructions/TechnicalInstruction";
  20. import {VexFlowGraphicalNote} from "./VexFlowGraphicalNote";
  21. export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
  22. /**
  23. * Create a new music system for the given page.
  24. * Currently only one vertically endless page exists where all systems are put to.
  25. * @param page
  26. * @param systemIndex
  27. * @returns {VexFlowMusicSystem}
  28. */
  29. public createMusicSystem(page: GraphicalMusicPage, systemIndex: number): MusicSystem {
  30. return new VexFlowMusicSystem(page, systemIndex);
  31. }
  32. /**
  33. * Create a staffline object containing all staff measures belonging to a given system and staff.
  34. * @param parentSystem
  35. * @param parentStaff
  36. * @returns {VexFlowStaffLine}
  37. */
  38. public createStaffLine(parentSystem: MusicSystem, parentStaff: Staff): StaffLine {
  39. return new VexFlowStaffLine(parentSystem, parentStaff);
  40. }
  41. /**
  42. * Construct an empty staffMeasure from the given source measure and staff.
  43. * @param sourceMeasure
  44. * @param staff
  45. * @returns {VexFlowMeasure}
  46. */
  47. public createStaffMeasure(sourceMeasure: SourceMeasure, staff: Staff): StaffMeasure {
  48. return new VexFlowMeasure(staff, undefined, sourceMeasure);
  49. }
  50. /**
  51. * Create empty measure, which will be used to show key, rhythm changes at the end of the system.
  52. * @param staffLine
  53. * @returns {VexFlowMeasure}
  54. */
  55. public createExtraStaffMeasure(staffLine: StaffLine): StaffMeasure {
  56. return new VexFlowMeasure(staffLine.ParentStaff, staffLine);
  57. }
  58. /**
  59. * Create a staffEntry in the given measure for a given sourceStaffEntry.
  60. * @param sourceStaffEntry
  61. * @param measure
  62. * @returns {VexFlowStaffEntry}
  63. */
  64. public createStaffEntry(sourceStaffEntry: SourceStaffEntry, measure: StaffMeasure): GraphicalStaffEntry {
  65. return new VexFlowStaffEntry(<VexFlowMeasure>measure, sourceStaffEntry, undefined);
  66. }
  67. /**
  68. * Create an empty staffEntry which will be used for grace notes.
  69. * it will be linked to the given staffEntryParent, which is a staffEntry for normal notes.
  70. * Grace notes are always given before (rarely also after) normal notes.
  71. * @param staffEntryParent
  72. * @param measure
  73. * @returns {VexFlowStaffEntry}
  74. */
  75. public createGraceStaffEntry(staffEntryParent: GraphicalStaffEntry, measure: StaffMeasure): GraphicalStaffEntry {
  76. return new VexFlowStaffEntry(<VexFlowMeasure>measure, undefined, <VexFlowStaffEntry>staffEntryParent);
  77. }
  78. /**
  79. * Create a Graphical Note for given note and clef and as part of graphicalStaffEntry.
  80. * @param note
  81. * @param numberOfDots The number of dots the note has to increase its musical duration.
  82. * @param graphicalStaffEntry
  83. * @param activeClef The currently active clef, needed for positioning the note vertically
  84. * @param octaveShift The currently active octave transposition enum, needed for positioning the note vertically
  85. * @returns {GraphicalNote}
  86. */
  87. public createNote(note: Note, numberOfDots: number, graphicalStaffEntry: GraphicalStaffEntry,
  88. activeClef: ClefInstruction, octaveShift: OctaveEnum = OctaveEnum.NONE): GraphicalNote {
  89. // Creates the note:
  90. let graphicalNote: GraphicalNote = new VexFlowGraphicalNote(note, graphicalStaffEntry, activeClef);
  91. // Adds the note to the right (graphical) voice (mynotes)
  92. let voiceID: number = note.ParentVoiceEntry.ParentVoice.VoiceId;
  93. let mynotes: { [id: number]: GraphicalNote[]; } = (graphicalStaffEntry as VexFlowStaffEntry).graphicalNotes;
  94. if (!(voiceID in mynotes)) {
  95. mynotes[voiceID] = [];
  96. }
  97. mynotes[voiceID].push(graphicalNote);
  98. return graphicalNote;
  99. }
  100. /**
  101. * Create a Graphical Grace Note (smaller head, stem...) for given note and clef and as part of graphicalStaffEntry.
  102. * @param note
  103. * @param numberOfDots
  104. * @param graphicalStaffEntry
  105. * @param activeClef
  106. * @param octaveShift
  107. * @returns {GraphicalNote}
  108. */
  109. public createGraceNote(note: Note, numberOfDots: number, graphicalStaffEntry: GraphicalStaffEntry,
  110. activeClef: ClefInstruction, octaveShift: OctaveEnum = OctaveEnum.NONE): GraphicalNote {
  111. return new GraphicalNote(note, graphicalStaffEntry);
  112. }
  113. /**
  114. * Sets a pitch which will be used for rendering the given graphical note (not changing the original pitch of the note!!!).
  115. * Will be only called if the displayed accidental is different from the original (e.g. a C# with C# as key instruction)
  116. * @param graphicalNote
  117. * @param pitch The pitch which will be rendered.
  118. * @param grace
  119. * @param graceScalingFactor
  120. */
  121. public addGraphicalAccidental(graphicalNote: GraphicalNote, pitch: Pitch, grace: boolean, graceScalingFactor: number): void {
  122. // ToDo: set accidental here from pitch.Accidental
  123. let note: VexFlowGraphicalNote = <VexFlowGraphicalNote> graphicalNote;
  124. note.setPitch(pitch);
  125. }
  126. /**
  127. * Adds a Fermata symbol at the last note of the given tied Note.
  128. * The last graphical note of this tied note is located at the given graphicalStaffEntry.
  129. * A Fermata has to be located at the last tied note.
  130. * @param tiedNote
  131. * @param graphicalStaffEntry
  132. */
  133. public addFermataAtTiedEndNote(tiedNote: Note, graphicalStaffEntry: GraphicalStaffEntry): void {
  134. return;
  135. }
  136. /**
  137. * Adds a technical instruction at the given staff entry.
  138. * @param technicalInstruction
  139. * @param graphicalStaffEntry
  140. */
  141. public createGraphicalTechnicalInstruction(technicalInstruction: TechnicalInstruction, graphicalStaffEntry: GraphicalStaffEntry): void {
  142. return;
  143. }
  144. /**
  145. * Adds a clef change within a measure before the given staff entry.
  146. * @param graphicalStaffEntry
  147. * @param clefInstruction
  148. */
  149. public createInStaffClef(graphicalStaffEntry: GraphicalStaffEntry, clefInstruction: ClefInstruction): void {
  150. return;
  151. }
  152. /**
  153. * Adds a chord symbol at the given staff entry
  154. * @param sourceStaffEntry
  155. * @param graphicalStaffEntry
  156. * @param transposeHalftones
  157. */
  158. public createChordSymbol(sourceStaffEntry: SourceStaffEntry, graphicalStaffEntry: GraphicalStaffEntry, transposeHalftones: number): void {
  159. return;
  160. }
  161. }