VexFlowMusicSheetCalculator.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. import {MusicSheetCalculator} from "../MusicSheetCalculator";
  2. import {VexFlowGraphicalSymbolFactory} from "./VexFlowGraphicalSymbolFactory";
  3. import {GraphicalMeasure} from "../GraphicalMeasure";
  4. import {StaffLine} from "../StaffLine";
  5. import {VoiceEntry} from "../../VoiceData/VoiceEntry";
  6. import {GraphicalNote} from "../GraphicalNote";
  7. import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
  8. import {GraphicalTie} from "../GraphicalTie";
  9. import {Tie} from "../../VoiceData/Tie";
  10. import {SourceMeasure} from "../../VoiceData/SourceMeasure";
  11. import {MultiExpression} from "../../VoiceData/Expressions/MultiExpression";
  12. import {RepetitionInstruction} from "../../VoiceData/Instructions/RepetitionInstruction";
  13. import {Beam} from "../../VoiceData/Beam";
  14. import {ClefInstruction} from "../../VoiceData/Instructions/ClefInstruction";
  15. import {OctaveEnum, OctaveShift} from "../../VoiceData/Expressions/ContinuousExpressions/OctaveShift";
  16. import {Fraction} from "../../../Common/DataObjects/Fraction";
  17. import {LyricWord} from "../../VoiceData/Lyrics/LyricsWord";
  18. import {OrnamentContainer} from "../../VoiceData/OrnamentContainer";
  19. import {ArticulationEnum} from "../../VoiceData/VoiceEntry";
  20. import {Tuplet} from "../../VoiceData/Tuplet";
  21. import {VexFlowMeasure} from "./VexFlowMeasure";
  22. import {VexFlowTextMeasurer} from "./VexFlowTextMeasurer";
  23. import Vex = require("vexflow");
  24. import * as log from "loglevel";
  25. import {unitInPixels} from "./VexFlowMusicSheetDrawer";
  26. import {VexFlowGraphicalNote} from "./VexFlowGraphicalNote";
  27. import {TechnicalInstruction} from "../../VoiceData/Instructions/TechnicalInstruction";
  28. import {GraphicalLyricEntry} from "../GraphicalLyricEntry";
  29. import {GraphicalLabel} from "../GraphicalLabel";
  30. import {LyricsEntry} from "../../VoiceData/Lyrics/LyricsEntry";
  31. import {GraphicalLyricWord} from "../GraphicalLyricWord";
  32. import {VexFlowStaffEntry} from "./VexFlowStaffEntry";
  33. import { VexFlowOctaveShift } from "./VexFlowOctaveShift";
  34. import { VexFlowInstantaniousDynamicExpression } from "./VexFlowInstantaniousDynamicExpression";
  35. import {BoundingBox} from "../BoundingBox";
  36. import { EngravingRules } from "../EngravingRules";
  37. export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
  38. constructor() {
  39. super();
  40. MusicSheetCalculator.symbolFactory = new VexFlowGraphicalSymbolFactory();
  41. MusicSheetCalculator.TextMeasurer = new VexFlowTextMeasurer();
  42. }
  43. protected clearRecreatedObjects(): void {
  44. super.clearRecreatedObjects();
  45. for (const graphicalMeasures of this.graphicalMusicSheet.MeasureList) {
  46. for (const graphicalMeasure of graphicalMeasures) {
  47. (<VexFlowMeasure>graphicalMeasure).clean();
  48. }
  49. }
  50. }
  51. protected formatMeasures(): void {
  52. for (const verticalMeasureList of this.graphicalMusicSheet.MeasureList) {
  53. const firstMeasure: VexFlowMeasure = verticalMeasureList[0] as VexFlowMeasure;
  54. // first measure has formatting method as lambda function object, but formats all measures. TODO this could be refactored
  55. firstMeasure.format();
  56. for (const staffEntry of firstMeasure.staffEntries) {
  57. (<VexFlowStaffEntry>staffEntry).calculateXPosition();
  58. }
  59. }
  60. }
  61. //protected clearSystemsAndMeasures(): void {
  62. // for (let measure of measures) {
  63. //
  64. // }
  65. //}
  66. /**
  67. * Calculates the x layout of the staff entries within the staff measures belonging to one source measure.
  68. * All staff entries are x-aligned throughout all vertically aligned staff measures.
  69. * This method is called within calculateXLayout.
  70. * The staff entries are aligned with minimum needed x distances.
  71. * The MinimumStaffEntriesWidth of every measure will be set - needed for system building.
  72. * Prepares the VexFlow formatter for later formatting
  73. * Does not calculate measure width from lyrics (which is called from MusicSheetCalculator)
  74. * @param measures
  75. * @returns the minimum required x width of the source measure (=list of staff measures)
  76. */
  77. protected calculateMeasureXLayout(measures: GraphicalMeasure[]): number {
  78. // Finalize beams
  79. /*for (let measure of measures) {
  80. (measure as VexFlowMeasure).finalizeBeams();
  81. (measure as VexFlowMeasure).finalizeTuplets();
  82. }*/
  83. // Format the voices
  84. const allVoices: Vex.Flow.Voice[] = [];
  85. const formatter: Vex.Flow.Formatter = new Vex.Flow.Formatter();
  86. for (const measure of measures) {
  87. const mvoices: { [voiceID: number]: Vex.Flow.Voice; } = (measure as VexFlowMeasure).vfVoices;
  88. const voices: Vex.Flow.Voice[] = [];
  89. for (const voiceID in mvoices) {
  90. if (mvoices.hasOwnProperty(voiceID)) {
  91. voices.push(mvoices[voiceID]);
  92. allVoices.push(mvoices[voiceID]);
  93. }
  94. }
  95. if (voices.length === 0) {
  96. log.warn("Found a measure with no voices... Continuing anyway.", mvoices);
  97. continue;
  98. }
  99. // all voices that belong to one stave are collectively added to create a common context in VexFlow.
  100. formatter.joinVoices(voices);
  101. }
  102. let minStaffEntriesWidth: number = 200;
  103. if (allVoices.length > 0) {
  104. // FIXME: The following ``+ 5.0'' is temporary: it was added as a workaround for
  105. // FIXME: a more relaxed formatting of voices
  106. minStaffEntriesWidth = formatter.preCalculateMinTotalWidth(allVoices) / unitInPixels + 5.0;
  107. // firstMeasure.formatVoices = (w: number) => {
  108. // formatter.format(allVoices, w);
  109. // };
  110. MusicSheetCalculator.setMeasuresMinStaffEntriesWidth(measures, minStaffEntriesWidth);
  111. for (const measure of measures) {
  112. if (measure === measures[0]) {
  113. const vexflowMeasure: VexFlowMeasure = (measure as VexFlowMeasure);
  114. // prepare format function for voices, will be called later for formatting measure again
  115. vexflowMeasure.formatVoices = (w: number) => {
  116. formatter.format(allVoices, w, {
  117. align_rests: true,
  118. });
  119. };
  120. // format now for minimum width
  121. vexflowMeasure.formatVoices(minStaffEntriesWidth * unitInPixels);
  122. } else {
  123. (measure as VexFlowMeasure).formatVoices = undefined;
  124. }
  125. }
  126. }
  127. for (const graphicalMeasure of measures) {
  128. for (const staffEntry of graphicalMeasure.staffEntries) {
  129. // here the measure modifiers are not yet set, therefore the begin instruction width will be empty
  130. (<VexFlowStaffEntry>staffEntry).calculateXPosition();
  131. }
  132. }
  133. // calculateMeasureWidthFromLyrics() will be called from MusicSheetCalculator after this
  134. return minStaffEntriesWidth;
  135. }
  136. public calculateMeasureWidthFromLyrics(measuresVertical: GraphicalMeasure[], oldMinimumStaffEntriesWidth: number): number {
  137. let elongationFactorMeasureWidth: number = 1;
  138. // information we need for the previous lyricsEntries to space the current one
  139. interface LyricEntryInfo {
  140. extend: boolean;
  141. labelHalfWidth: number;
  142. staffEntryXPosition: number;
  143. text: string;
  144. measureNumber: number;
  145. }
  146. // holds lyrics entries for verses i
  147. interface LyricEntryDict {
  148. [i: number]: LyricEntryInfo;
  149. }
  150. for (const measure of measuresVertical) {
  151. const lastLyricEntryDict: LyricEntryDict = {}; // holds info about last lyrics entries for all verses
  152. for (let i: number = 0; i < measure.staffEntries.length; i++) {
  153. const staffEntry: GraphicalStaffEntry = measure.staffEntries[i];
  154. if (staffEntry.LyricsEntries.length === 0) {
  155. continue;
  156. }
  157. // for all verses
  158. for (let j: number = 0; j < staffEntry.LyricsEntries.length; j++) {
  159. const lyricsEntry: GraphicalLyricEntry = staffEntry.LyricsEntries[j];
  160. // const lyricsEntryText = lyricsEntry.GetLyricsEntry.Text; // for easier debugging
  161. let minLyricsSpacing: number = EngravingRules.Rules.HorizontalBetweenLyricsDistance;
  162. // spacing for multi-syllable words
  163. if (lyricsEntry.ParentLyricWord) {
  164. if (lyricsEntry.GetLyricsEntry.SyllableIndex > 0) { // syllables after first
  165. // give a little more spacing for dash between syllables
  166. minLyricsSpacing = EngravingRules.Rules.BetweenSyllabelMinimumDistance;
  167. }
  168. }
  169. const lyricsBbox: BoundingBox = lyricsEntry.GraphicalLabel.PositionAndShape;
  170. const lyricsLabelHalfWidth: number = lyricsBbox.Size.width / 2;
  171. const staffEntryXPosition: number = (staffEntry as VexFlowStaffEntry).PositionAndShape.RelativePosition.x;
  172. // if we don't have a previous lyricEntry, skip spacing, just save lastLyricEntry information
  173. if (lastLyricEntryDict[j] !== undefined) {
  174. if (lastLyricEntryDict[j].extend) {
  175. // TODO handle extend of last entry (extend is stored in lyrics entry of preceding syllable)
  176. }
  177. const spaceNeededByLyrics: number =
  178. lastLyricEntryDict[j].labelHalfWidth + lyricsLabelHalfWidth + minLyricsSpacing;
  179. const staffEntrySpacing: number = staffEntryXPosition - lastLyricEntryDict[j].staffEntryXPosition;
  180. // get factor of how much we need to stretch the measure to space the current lyric with the last one
  181. const elongationFactorMeasureWidthForCurrentLabels: number = spaceNeededByLyrics / staffEntrySpacing;
  182. elongationFactorMeasureWidth = Math.max(elongationFactorMeasureWidth, elongationFactorMeasureWidthForCurrentLabels);
  183. }
  184. // TODO for spacing between last lyric of a measure and first lyric of the next measure,
  185. // we need to look ahead into the next measure, because first note position is not affected
  186. // by measure elongation. or return this elongation and let MusicSheetCalculator apply it to prev. measure
  187. // e.g. for Austrian national hymn:
  188. // if (lyricsEntry.GetLyricsEntry.Text === "kunfts") {
  189. // elongationFactorMeasureWidth *= 1.5;
  190. // }
  191. // set up last lyric entry information for next measure
  192. lastLyricEntryDict[j] = {
  193. extend: lyricsEntry.GetLyricsEntry.extend,
  194. labelHalfWidth: lyricsLabelHalfWidth,
  195. measureNumber: measure.MeasureNumber,
  196. staffEntryXPosition: staffEntryXPosition,
  197. text: lyricsEntry.GetLyricsEntry.Text,
  198. // lyricExtend: lyricExtend
  199. };
  200. }
  201. }
  202. }
  203. return oldMinimumStaffEntriesWidth * elongationFactorMeasureWidth;
  204. // calculateMeasureWidthFromLyrics is called afterwards from MusicSheetCalculator
  205. }
  206. protected createGraphicalTie(tie: Tie, startGse: GraphicalStaffEntry, endGse: GraphicalStaffEntry,
  207. startNote: GraphicalNote, endNote: GraphicalNote): GraphicalTie {
  208. return new GraphicalTie(tie, startNote, endNote);
  209. }
  210. protected updateStaffLineBorders(staffLine: StaffLine): void {
  211. staffLine.SkyBottomLineCalculator.updateStaffLineBorders();
  212. }
  213. protected graphicalMeasureCreatedCalculations(measure: GraphicalMeasure): void {
  214. (measure as VexFlowMeasure).graphicalMeasureCreatedCalculations();
  215. }
  216. /**
  217. * Can be used to calculate articulations, stem directions, helper(ledger) lines, and overlapping note x-displacement.
  218. * Is Excecuted per voice entry of a staff entry.
  219. * After that layoutStaffEntry is called.
  220. * @param voiceEntry
  221. * @param graphicalNotes
  222. * @param graphicalStaffEntry
  223. * @param hasPitchedNote
  224. */
  225. protected layoutVoiceEntry(voiceEntry: VoiceEntry, graphicalNotes: GraphicalNote[], graphicalStaffEntry: GraphicalStaffEntry,
  226. hasPitchedNote: boolean): void {
  227. return;
  228. }
  229. /**
  230. * Do all layout calculations that have to be done per staff entry, like dots, ornaments, arpeggios....
  231. * This method is called after the voice entries are handled by layoutVoiceEntry().
  232. * @param graphicalStaffEntry
  233. */
  234. protected layoutStaffEntry(graphicalStaffEntry: GraphicalStaffEntry): void {
  235. (graphicalStaffEntry.parentMeasure as VexFlowMeasure).layoutStaffEntry(graphicalStaffEntry);
  236. }
  237. /**
  238. * calculates the y positions of the staff lines within a system and
  239. * furthermore the y positions of the systems themselves.
  240. */
  241. protected calculateSystemYLayout(): void {
  242. for (const graphicalMusicPage of this.graphicalMusicSheet.MusicPages) {
  243. for (const musicSystem of graphicalMusicPage.MusicSystems) {
  244. this.optimizeDistanceBetweenStaffLines(musicSystem);
  245. }
  246. // set y positions of systems using the previous system and a fixed distance.
  247. this.calculateMusicSystemsRelativePositions(graphicalMusicPage);
  248. }
  249. }
  250. /**
  251. * Is called at the begin of the method for creating the vertically aligned staff measures belonging to one source measure.
  252. */
  253. protected initGraphicalMeasuresCreation(): void {
  254. return;
  255. }
  256. /**
  257. * add here all given articulations to the VexFlowGraphicalStaffEntry and prepare them for rendering.
  258. * @param articulations
  259. * @param voiceEntry
  260. * @param graphicalStaffEntry
  261. */
  262. protected layoutArticulationMarks(articulations: ArticulationEnum[], voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry): void {
  263. // uncomment this when implementing:
  264. // let vfse: VexFlowStaffEntry = (graphicalStaffEntry as VexFlowStaffEntry);
  265. return;
  266. }
  267. /**
  268. * Calculate the shape (Bezier curve) for this tie.
  269. * @param tie
  270. * @param tieIsAtSystemBreak
  271. */
  272. protected layoutGraphicalTie(tie: GraphicalTie, tieIsAtSystemBreak: boolean): void {
  273. const startNote: VexFlowGraphicalNote = (tie.StartNote as VexFlowGraphicalNote);
  274. const endNote: VexFlowGraphicalNote = (tie.EndNote as VexFlowGraphicalNote);
  275. let vfStartNote: Vex.Flow.StaveNote = undefined;
  276. let startNoteIndexInTie: number = 0;
  277. if (startNote !== undefined) {
  278. vfStartNote = startNote.vfnote[0];
  279. startNoteIndexInTie = startNote.vfnote[1];
  280. }
  281. let vfEndNote: Vex.Flow.StaveNote = undefined;
  282. let endNoteIndexInTie: number = 0;
  283. if (endNote !== undefined) {
  284. vfEndNote = endNote.vfnote[0];
  285. endNoteIndexInTie = endNote.vfnote[1];
  286. }
  287. if (tieIsAtSystemBreak) {
  288. // split tie into two ties:
  289. const vfTie1: Vex.Flow.StaveTie = new Vex.Flow.StaveTie({
  290. first_indices: [startNoteIndexInTie],
  291. first_note: vfStartNote
  292. });
  293. const measure1: VexFlowMeasure = (startNote.parentVoiceEntry.parentStaffEntry.parentMeasure as VexFlowMeasure);
  294. measure1.vfTies.push(vfTie1);
  295. const vfTie2: Vex.Flow.StaveTie = new Vex.Flow.StaveTie({
  296. last_indices: [endNoteIndexInTie],
  297. last_note: vfEndNote
  298. });
  299. const measure2: VexFlowMeasure = (endNote.parentVoiceEntry.parentStaffEntry.parentMeasure as VexFlowMeasure);
  300. measure2.vfTies.push(vfTie2);
  301. } else {
  302. // normal case
  303. const vfTie: Vex.Flow.StaveTie = new Vex.Flow.StaveTie({
  304. first_indices: [startNoteIndexInTie],
  305. first_note: vfStartNote,
  306. last_indices: [endNoteIndexInTie],
  307. last_note: vfEndNote
  308. });
  309. const measure: VexFlowMeasure = (endNote.parentVoiceEntry.parentStaffEntry.parentMeasure as VexFlowMeasure);
  310. measure.vfTies.push(vfTie);
  311. }
  312. }
  313. protected calculateDynamicExpressionsForSingleMultiExpression(multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
  314. if (multiExpression.InstantaniousDynamic) {
  315. const timeStamp: Fraction = multiExpression.Timestamp;
  316. const measure: GraphicalMeasure = this.graphicalMusicSheet.MeasureList[measureIndex][staffIndex];
  317. const startStaffEntry: GraphicalStaffEntry = measure.findGraphicalStaffEntryFromTimestamp(timeStamp);
  318. const idx: VexFlowInstantaniousDynamicExpression = new VexFlowInstantaniousDynamicExpression(multiExpression.InstantaniousDynamic, startStaffEntry);
  319. // idx.calculcateBottomLine(measure);
  320. (measure as VexFlowMeasure).instantaniousDynamics.push(idx);
  321. }
  322. }
  323. /**
  324. * Calculate a single OctaveShift for a [[MultiExpression]].
  325. * @param sourceMeasure
  326. * @param multiExpression
  327. * @param measureIndex
  328. * @param staffIndex
  329. */
  330. protected calculateSingleOctaveShift(sourceMeasure: SourceMeasure, multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
  331. // calculate absolute Timestamp and startStaffLine (and EndStaffLine if needed)
  332. const octaveShift: OctaveShift = multiExpression.OctaveShiftStart;
  333. const startTimeStamp: Fraction = octaveShift.ParentStartMultiExpression.Timestamp;
  334. const endTimeStamp: Fraction = octaveShift.ParentEndMultiExpression.Timestamp;
  335. const startStaffLine: StaffLine = this.graphicalMusicSheet.MeasureList[measureIndex][staffIndex].ParentStaffLine;
  336. let endMeasure: GraphicalMeasure = undefined;
  337. if (octaveShift.ParentEndMultiExpression !== undefined) {
  338. endMeasure = this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(octaveShift.ParentEndMultiExpression.SourceMeasureParent,
  339. staffIndex);
  340. }
  341. let startMeasure: GraphicalMeasure = undefined;
  342. if (octaveShift.ParentEndMultiExpression !== undefined) {
  343. startMeasure = this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(octaveShift.ParentStartMultiExpression.SourceMeasureParent,
  344. staffIndex);
  345. }
  346. if (endMeasure !== undefined) {
  347. // calculate GraphicalOctaveShift and RelativePositions
  348. const graphicalOctaveShift: VexFlowOctaveShift = new VexFlowOctaveShift(octaveShift, startStaffLine.PositionAndShape);
  349. startStaffLine.OctaveShifts.push(graphicalOctaveShift);
  350. // calculate RelativePosition and Dashes
  351. const startStaffEntry: GraphicalStaffEntry = startMeasure.findGraphicalStaffEntryFromTimestamp(startTimeStamp);
  352. const endStaffEntry: GraphicalStaffEntry = endMeasure.findGraphicalStaffEntryFromTimestamp(endTimeStamp);
  353. graphicalOctaveShift.setStartNote(startStaffEntry);
  354. if (endMeasure.ParentStaffLine !== startMeasure.ParentStaffLine) {
  355. graphicalOctaveShift.endsOnDifferentStaffLine = true;
  356. const lastMeasure: GraphicalMeasure = startMeasure.ParentStaffLine.Measures[startMeasure.ParentStaffLine.Measures.length - 1];
  357. const lastNote: GraphicalStaffEntry = lastMeasure.staffEntries[lastMeasure.staffEntries.length - 1];
  358. graphicalOctaveShift.setEndNote(lastNote);
  359. // Now finish the shift on the next line
  360. const remainingOctaveShift: VexFlowOctaveShift = new VexFlowOctaveShift(octaveShift, endMeasure.PositionAndShape);
  361. endMeasure.ParentStaffLine.OctaveShifts.push(remainingOctaveShift);
  362. const firstMeasure: GraphicalMeasure = endMeasure.ParentStaffLine.Measures[0];
  363. const firstNote: GraphicalStaffEntry = firstMeasure.staffEntries[0];
  364. remainingOctaveShift.setStartNote(firstNote);
  365. remainingOctaveShift.setEndNote(endStaffEntry);
  366. } else {
  367. graphicalOctaveShift.setEndNote(endStaffEntry);
  368. }
  369. } else {
  370. log.warn("End measure for octave shift is undefined! This should not happen!");
  371. }
  372. }
  373. /**
  374. * Calculate all the textual and symbolic [[RepetitionInstruction]]s (e.g. dal segno) for a single [[SourceMeasure]].
  375. * @param repetitionInstruction
  376. * @param measureIndex
  377. */
  378. protected calculateWordRepetitionInstruction(repetitionInstruction: RepetitionInstruction, measureIndex: number): void {
  379. // find first visible StaffLine
  380. let uppermostMeasure: VexFlowMeasure = undefined;
  381. const measures: VexFlowMeasure[] = <VexFlowMeasure[]>this.graphicalMusicSheet.MeasureList[measureIndex];
  382. for (let idx: number = 0, len: number = measures.length; idx < len; ++idx) {
  383. const graphicalMeasure: VexFlowMeasure = measures[idx];
  384. if (graphicalMeasure.ParentStaffLine !== undefined && graphicalMeasure.ParentStaff.ParentInstrument.Visible) {
  385. uppermostMeasure = <VexFlowMeasure>graphicalMeasure;
  386. break;
  387. }
  388. }
  389. // ToDo: feature/Repetitions
  390. // now create corresponding graphical symbol or Text in VexFlow:
  391. // use top measure and staffline for positioning.
  392. if (uppermostMeasure !== undefined) {
  393. uppermostMeasure.addWordRepetition(repetitionInstruction);
  394. }
  395. }
  396. protected calculateMoodAndUnknownExpression(multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
  397. return;
  398. }
  399. /**
  400. * Check if the tied graphical note belongs to any beams or tuplets and react accordingly.
  401. * @param tiedGraphicalNote
  402. * @param beams
  403. * @param activeClef
  404. * @param octaveShiftValue
  405. * @param graphicalStaffEntry
  406. * @param duration
  407. * @param openTie
  408. * @param isLastTieNote
  409. */
  410. protected handleTiedGraphicalNote(tiedGraphicalNote: GraphicalNote, beams: Beam[], activeClef: ClefInstruction,
  411. octaveShiftValue: OctaveEnum, graphicalStaffEntry: GraphicalStaffEntry, duration: Fraction,
  412. openTie: Tie, isLastTieNote: boolean): void {
  413. return;
  414. }
  415. /**
  416. * Is called if a note is part of a beam.
  417. * @param graphicalNote
  418. * @param beam
  419. * @param openBeams a list of all currently open beams
  420. */
  421. protected handleBeam(graphicalNote: GraphicalNote, beam: Beam, openBeams: Beam[]): void {
  422. (graphicalNote.parentVoiceEntry.parentStaffEntry.parentMeasure as VexFlowMeasure).handleBeam(graphicalNote, beam);
  423. }
  424. protected handleVoiceEntryLyrics(voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry, lyricWords: LyricWord[]): void {
  425. voiceEntry.LyricsEntries.forEach((key: number, lyricsEntry: LyricsEntry) => {
  426. const graphicalLyricEntry: GraphicalLyricEntry = new GraphicalLyricEntry(lyricsEntry,
  427. graphicalStaffEntry,
  428. this.rules.LyricsHeight,
  429. this.rules.StaffHeight);
  430. graphicalStaffEntry.LyricsEntries.push(graphicalLyricEntry);
  431. // create corresponding GraphicalLabel
  432. const graphicalLabel: GraphicalLabel = graphicalLyricEntry.GraphicalLabel;
  433. graphicalLabel.setLabelPositionAndShapeBorders();
  434. if (lyricsEntry.Word !== undefined) {
  435. const lyricsEntryIndex: number = lyricsEntry.Word.Syllables.indexOf(lyricsEntry);
  436. let index: number = lyricWords.indexOf(lyricsEntry.Word);
  437. if (index === -1) {
  438. lyricWords.push(lyricsEntry.Word);
  439. index = lyricWords.indexOf(lyricsEntry.Word);
  440. }
  441. if (this.graphicalLyricWords.length === 0 || index > this.graphicalLyricWords.length - 1) {
  442. const graphicalLyricWord: GraphicalLyricWord = new GraphicalLyricWord(lyricsEntry.Word);
  443. graphicalLyricEntry.ParentLyricWord = graphicalLyricWord;
  444. graphicalLyricWord.GraphicalLyricsEntries[lyricsEntryIndex] = graphicalLyricEntry;
  445. this.graphicalLyricWords.push(graphicalLyricWord);
  446. } else {
  447. const graphicalLyricWord: GraphicalLyricWord = this.graphicalLyricWords[index];
  448. graphicalLyricEntry.ParentLyricWord = graphicalLyricWord;
  449. graphicalLyricWord.GraphicalLyricsEntries[lyricsEntryIndex] = graphicalLyricEntry;
  450. if (graphicalLyricWord.isFilled()) {
  451. lyricWords.splice(index, 1);
  452. this.graphicalLyricWords.splice(this.graphicalLyricWords.indexOf(graphicalLyricWord), 1);
  453. }
  454. }
  455. }
  456. });
  457. }
  458. protected handleVoiceEntryOrnaments(ornamentContainer: OrnamentContainer, voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry): void {
  459. return;
  460. }
  461. /**
  462. * Add articulations to the given vexflow staff entry.
  463. * @param articulations
  464. * @param voiceEntry
  465. * @param graphicalStaffEntry
  466. */
  467. protected handleVoiceEntryArticulations(articulations: ArticulationEnum[],
  468. voiceEntry: VoiceEntry, staffEntry: GraphicalStaffEntry): void {
  469. // uncomment this when implementing:
  470. // let vfse: VexFlowStaffEntry = (graphicalStaffEntry as VexFlowStaffEntry);
  471. return;
  472. }
  473. /**
  474. * Add technical instructions to the given vexflow staff entry.
  475. * @param technicalInstructions
  476. * @param voiceEntry
  477. * @param staffEntry
  478. */
  479. protected handleVoiceEntryTechnicalInstructions(technicalInstructions: TechnicalInstruction[],
  480. voiceEntry: VoiceEntry, staffEntry: GraphicalStaffEntry): void {
  481. // uncomment this when implementing:
  482. // let vfse: VexFlowStaffEntry = (graphicalStaffEntry as VexFlowStaffEntry);
  483. return;
  484. }
  485. /**
  486. * Is called if a note is part of a tuplet.
  487. * @param graphicalNote
  488. * @param tuplet
  489. * @param openTuplets a list of all currently open tuplets
  490. */
  491. protected handleTuplet(graphicalNote: GraphicalNote, tuplet: Tuplet, openTuplets: Tuplet[]): void {
  492. (graphicalNote.parentVoiceEntry.parentStaffEntry.parentMeasure as VexFlowMeasure).handleTuplet(graphicalNote, tuplet);
  493. }
  494. }