vexflow-native 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +33 -405
  2. package/lib/module/base/FontManager.js +2 -0
  3. package/lib/module/base/FontManager.js.map +1 -1
  4. package/lib/module/base/VexflowRecordingContext.js +2 -0
  5. package/lib/module/base/VexflowRecordingContext.js.map +1 -1
  6. package/lib/module/base/index.js +1 -0
  7. package/lib/module/base/index.js.map +1 -1
  8. package/lib/module/musicxml/MusicXmlParser/MeasureParser.js +24 -7
  9. package/lib/module/musicxml/MusicXmlParser/MeasureParser.js.map +1 -1
  10. package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js +11 -3
  11. package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js.map +1 -1
  12. package/lib/module/musicxml/MusicXmlParser/Spanners.js +21 -5
  13. package/lib/module/musicxml/MusicXmlParser/Spanners.js.map +1 -1
  14. package/lib/module/musicxml/MusicXmlParser/mappers.js +1 -1
  15. package/lib/module/musicxml/MusicXmlParser/mappers.js.map +1 -1
  16. package/lib/module/{state/constants.js → percussion/index.js} +3 -3
  17. package/lib/module/percussion/index.js.map +1 -0
  18. package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +4 -0
  19. package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -1
  20. package/lib/module/renderer/fixedNoteSpacing.js +56 -0
  21. package/lib/module/renderer/fixedNoteSpacing.js.map +1 -0
  22. package/lib/module/renderer/index.js +1 -0
  23. package/lib/module/renderer/index.js.map +1 -1
  24. package/lib/module/renderer/itemLayout.js +108 -0
  25. package/lib/module/renderer/itemLayout.js.map +1 -0
  26. package/lib/module/renderer/measure.js +30 -106
  27. package/lib/module/renderer/measure.js.map +1 -1
  28. package/lib/module/renderer/measureBounds.js +73 -0
  29. package/lib/module/renderer/measureBounds.js.map +1 -0
  30. package/lib/module/renderer/measureModifiers.js +99 -0
  31. package/lib/module/renderer/measureModifiers.js.map +1 -0
  32. package/lib/module/renderer/noteModifiers.js +212 -0
  33. package/lib/module/renderer/noteModifiers.js.map +1 -0
  34. package/lib/module/renderer/render.js +33 -116
  35. package/lib/module/renderer/render.js.map +1 -1
  36. package/lib/module/renderer/scale.js +16 -2
  37. package/lib/module/renderer/scale.js.map +1 -1
  38. package/lib/module/renderer/scoreParsing.js +37 -199
  39. package/lib/module/renderer/scoreParsing.js.map +1 -1
  40. package/lib/module/renderer/stave.js +19 -3
  41. package/lib/module/renderer/stave.js.map +1 -1
  42. package/lib/module/renderer/useScoreRecording.js +10 -3
  43. package/lib/module/renderer/useScoreRecording.js.map +1 -1
  44. package/lib/module/renderer/vfKeys.js +72 -0
  45. package/lib/module/renderer/vfKeys.js.map +1 -0
  46. package/lib/module/state/index.js +1 -1
  47. package/lib/module/state/index.js.map +1 -1
  48. package/lib/typescript/src/base/FontManager.d.ts +1 -0
  49. package/lib/typescript/src/base/FontManager.d.ts.map +1 -1
  50. package/lib/typescript/src/base/VexflowRecordingContext.d.ts +1 -0
  51. package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -1
  52. package/lib/typescript/src/base/index.d.ts +1 -0
  53. package/lib/typescript/src/base/index.d.ts.map +1 -1
  54. package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts +4 -2
  55. package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts.map +1 -1
  56. package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts.map +1 -1
  57. package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts +6 -1
  58. package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts.map +1 -1
  59. package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts +6 -1
  60. package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts.map +1 -1
  61. package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts.map +1 -1
  62. package/lib/typescript/src/musicxml/index.d.ts +1 -0
  63. package/lib/typescript/src/musicxml/index.d.ts.map +1 -1
  64. package/lib/typescript/src/percussion/index.d.ts +4 -0
  65. package/lib/typescript/src/percussion/index.d.ts.map +1 -0
  66. package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -1
  67. package/lib/typescript/src/renderer/fixedNoteSpacing.d.ts +17 -0
  68. package/lib/typescript/src/renderer/fixedNoteSpacing.d.ts.map +1 -0
  69. package/lib/typescript/src/renderer/index.d.ts +2 -0
  70. package/lib/typescript/src/renderer/index.d.ts.map +1 -1
  71. package/lib/typescript/src/renderer/itemLayout.d.ts +23 -0
  72. package/lib/typescript/src/renderer/itemLayout.d.ts.map +1 -0
  73. package/lib/typescript/src/renderer/layout.d.ts +1 -1
  74. package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
  75. package/lib/typescript/src/renderer/measure.d.ts +3 -6
  76. package/lib/typescript/src/renderer/measure.d.ts.map +1 -1
  77. package/lib/typescript/src/renderer/measureBounds.d.ts +13 -0
  78. package/lib/typescript/src/renderer/measureBounds.d.ts.map +1 -0
  79. package/lib/typescript/src/renderer/measureModifiers.d.ts +20 -0
  80. package/lib/typescript/src/renderer/measureModifiers.d.ts.map +1 -0
  81. package/lib/typescript/src/renderer/noteModifiers.d.ts +29 -0
  82. package/lib/typescript/src/renderer/noteModifiers.d.ts.map +1 -0
  83. package/lib/typescript/src/renderer/render.d.ts +2 -27
  84. package/lib/typescript/src/renderer/render.d.ts.map +1 -1
  85. package/lib/typescript/src/renderer/scale.d.ts.map +1 -1
  86. package/lib/typescript/src/renderer/scoreParsing.d.ts +14 -42
  87. package/lib/typescript/src/renderer/scoreParsing.d.ts.map +1 -1
  88. package/lib/typescript/src/renderer/stave.d.ts +2 -0
  89. package/lib/typescript/src/renderer/stave.d.ts.map +1 -1
  90. package/lib/typescript/src/renderer/types.d.ts +51 -2
  91. package/lib/typescript/src/renderer/types.d.ts.map +1 -1
  92. package/lib/typescript/src/renderer/useScoreRecording.d.ts +2 -2
  93. package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -1
  94. package/lib/typescript/src/renderer/vfKeys.d.ts +17 -0
  95. package/lib/typescript/src/renderer/vfKeys.d.ts.map +1 -0
  96. package/lib/typescript/src/state/index.d.ts +1 -1
  97. package/lib/typescript/src/state/index.d.ts.map +1 -1
  98. package/lib/typescript/src/state/types.d.ts +23 -5
  99. package/lib/typescript/src/state/types.d.ts.map +1 -1
  100. package/package.json +12 -2
  101. package/src/base/FontManager.ts +1 -0
  102. package/src/base/VexflowRecordingContext.ts +1 -0
  103. package/src/base/index.ts +1 -0
  104. package/src/musicxml/MusicXmlParser/InternalTypes.ts +5 -2
  105. package/src/musicxml/MusicXmlParser/MeasureParser.ts +36 -7
  106. package/src/musicxml/MusicXmlParser/MusicXmlDirections.ts +25 -8
  107. package/src/musicxml/MusicXmlParser/Spanners.ts +27 -4
  108. package/src/musicxml/MusicXmlParser/mappers.ts +7 -0
  109. package/src/musicxml/index.ts +1 -0
  110. package/src/percussion/index.ts +7 -0
  111. package/src/renderer/Layout/VerticalSpacing.ts +1 -1
  112. package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +4 -0
  113. package/src/renderer/fixedNoteSpacing.ts +78 -0
  114. package/src/renderer/index.ts +8 -0
  115. package/src/renderer/itemLayout.ts +137 -0
  116. package/src/renderer/layout.ts +1 -1
  117. package/src/renderer/measure.tsx +84 -186
  118. package/src/renderer/measureBounds.ts +109 -0
  119. package/src/renderer/measureModifiers.ts +133 -0
  120. package/src/renderer/noteModifiers.ts +298 -0
  121. package/src/renderer/render.tsx +59 -169
  122. package/src/renderer/scale.ts +21 -1
  123. package/src/renderer/scoreParsing.tsx +77 -288
  124. package/src/renderer/stave.ts +22 -3
  125. package/src/renderer/types.ts +65 -2
  126. package/src/renderer/useScoreRecording.ts +11 -3
  127. package/src/renderer/vfKeys.ts +88 -0
  128. package/src/state/index.ts +1 -1
  129. package/src/state/types.ts +30 -5
  130. package/lib/module/state/constants.js.map +0 -1
  131. package/lib/typescript/src/state/constants.d.ts +0 -4
  132. package/lib/typescript/src/state/constants.d.ts.map +0 -1
  133. package/src/state/constants.ts +0 -4
@@ -0,0 +1,133 @@
1
+ import { BarlineType, type Stave, StaveModifierPosition } from 'vexflow';
2
+
3
+ import type { Barline, KeyMode, KeySignature, Measure, Step } from '../state';
4
+ import type { ResolvedMeasureState } from './scoreParsing';
5
+
6
+ export interface ResolvedMeasureModifiers {
7
+ showClef: boolean;
8
+ showMeter: boolean;
9
+ showKeySignature: boolean;
10
+ startBarline: Barline;
11
+ endBarline: Barline;
12
+ }
13
+
14
+ /** Fifths of the natural tonic; `#` adds 7, `b` subtracts 7. */
15
+ const STEP_FIFTHS: Record<Step, number> = {
16
+ C: 0,
17
+ D: 2,
18
+ E: 4,
19
+ F: -1,
20
+ G: 1,
21
+ A: 3,
22
+ B: 5,
23
+ };
24
+
25
+ /** Fifths offset from the parallel major with the same tonic. */
26
+ const MODE_FIFTHS: Record<KeyMode, number> = {
27
+ major: 0,
28
+ mixolydian: -1,
29
+ dorian: -2,
30
+ minor: -3,
31
+ phrygian: -4,
32
+ lydian: 1,
33
+ locrian: -5,
34
+ };
35
+
36
+ /** VexFlow major key specs indexed by fifths + 7. */
37
+ const MAJOR_KEY_SPECS = [
38
+ 'Cb',
39
+ 'Gb',
40
+ 'Db',
41
+ 'Ab',
42
+ 'Eb',
43
+ 'Bb',
44
+ 'F',
45
+ 'C',
46
+ 'G',
47
+ 'D',
48
+ 'A',
49
+ 'E',
50
+ 'B',
51
+ 'F#',
52
+ 'C#',
53
+ ] as const;
54
+
55
+ const START_BARLINE_TYPES: Partial<Record<Barline, BarlineType>> = {
56
+ 'repeat-begin': BarlineType.REPEAT_BEGIN,
57
+ };
58
+
59
+ const END_BARLINE_TYPES: Record<Barline, BarlineType> = {
60
+ 'single': BarlineType.SINGLE,
61
+ 'double': BarlineType.DOUBLE,
62
+ 'end': BarlineType.END,
63
+ 'final': BarlineType.END,
64
+ 'repeat-begin': BarlineType.SINGLE,
65
+ 'repeat-end': BarlineType.REPEAT_END,
66
+ };
67
+
68
+ /**
69
+ * Resolves the tri-state measure modifiers: `true` shows, `false` hides,
70
+ * `undefined` falls back to the default (clef on the first measure only,
71
+ * meter and key signature hidden, single barlines).
72
+ */
73
+ export function resolveMeasureModifiers(
74
+ measure: Pick<Measure, 'leftModifiers' | 'rightModifiers'>,
75
+ measureIndex: number
76
+ ): ResolvedMeasureModifiers {
77
+ const { leftModifiers, rightModifiers } = measure;
78
+
79
+ return {
80
+ showClef: leftModifiers?.showClef ?? measureIndex === 0,
81
+ showMeter: leftModifiers?.showMeter ?? false,
82
+ showKeySignature: leftModifiers?.showKeySignature ?? false,
83
+ startBarline: leftModifiers?.startBarline ?? 'single',
84
+ endBarline: rightModifiers?.endBarline ?? 'single',
85
+ };
86
+ }
87
+
88
+ export function applyMeasureModifiers(
89
+ stave: Stave,
90
+ modifiers: ResolvedMeasureModifiers,
91
+ resolvedState: ResolvedMeasureState
92
+ ): Stave {
93
+ const { clef, keySignature, meter } = resolvedState;
94
+
95
+ if (modifiers.showClef) {
96
+ stave.addClef(clef);
97
+ }
98
+
99
+ if (modifiers.showKeySignature && keySignature && clef !== 'percussion') {
100
+ stave.addKeySignature(keySignatureToVFSpec(keySignature));
101
+ }
102
+
103
+ if (modifiers.showMeter) {
104
+ stave.addTimeSignature(`${meter.beats}/${meter.beatUnit}`);
105
+ }
106
+
107
+ stave.setBegBarType(
108
+ START_BARLINE_TYPES[modifiers.startBarline] ?? BarlineType.SINGLE
109
+ );
110
+ stave.setEndBarType(END_BARLINE_TYPES[modifiers.endBarline]);
111
+
112
+ // Stave.format pads a lone REPEAT_BEGIN by 0, so its dots would overlap the first note.
113
+ if (
114
+ modifiers.startBarline === 'repeat-begin' &&
115
+ stave.getModifiers(StaveModifierPosition.BEGIN).length === 1
116
+ ) {
117
+ const { xMax, paddingRight } = stave.getModifiers()[0]!.getLayoutMetrics()!;
118
+
119
+ stave.setNoteStartX(stave.getX() + xMax + paddingRight);
120
+ }
121
+
122
+ return stave;
123
+ }
124
+
125
+ /** Major-key VexFlow spec for the key's accidentals, respelt enharmonically beyond 7 sharps/flats. */
126
+ export function keySignatureToVFSpec(keySignature: KeySignature): string {
127
+ const { tonic, accidental, mode = 'major' } = keySignature;
128
+ const accidentalFifths = accidental === '#' ? 7 : accidental === 'b' ? -7 : 0;
129
+ const fifths = STEP_FIFTHS[tonic] + accidentalFifths + MODE_FIFTHS[mode];
130
+ const wrapped = fifths > 7 ? fifths - 12 : fifths < -7 ? fifths + 12 : fifths;
131
+
132
+ return MAJOR_KEY_SPECS[wrapped + 7]!;
133
+ }
@@ -0,0 +1,298 @@
1
+ import {
2
+ Accidental as VFAccidental,
3
+ Annotation as VFAnnotation,
4
+ AnnotationVerticalJustify,
5
+ Articulation as VFArticulation,
6
+ Dot,
7
+ GraceNote as VFGraceNote,
8
+ GraceNoteGroup,
9
+ ModifierPosition,
10
+ Parenthesis,
11
+ StaveNote,
12
+ Stem,
13
+ } from 'vexflow';
14
+ import type { StemmableNote } from 'vexflow';
15
+
16
+ import type {
17
+ Articulation,
18
+ Clef,
19
+ Direction,
20
+ DurationValue,
21
+ Dynamic,
22
+ GraceNoteAttachment,
23
+ LyricAttachment,
24
+ NoteAttachment,
25
+ Pitch,
26
+ } from '../state';
27
+ import { durationToVF, pitchToVFKey } from './vfKeys';
28
+
29
+ /**
30
+ * Maps library articulation names to VexFlow articulation codes.
31
+ */
32
+ export const ARTICULATION_TO_VF_CODE: Record<Articulation, string> = {
33
+ staccato: 'a.',
34
+ staccatissimo: 'av',
35
+ tenuto: 'a-',
36
+ accent: 'a>',
37
+ marcato: 'a^',
38
+ fermata: 'a@',
39
+ open: 'ah',
40
+ stopped: 'a+',
41
+ };
42
+
43
+ /** SMuFL dynamics glyphs, drawn with the music font. */
44
+ const DYNAMIC_GLYPHS: Record<Dynamic, string> = {
45
+ ppp: '',
46
+ pp: '',
47
+ p: '',
48
+ mp: '',
49
+ mf: '',
50
+ f: '',
51
+ ff: '',
52
+ fff: '',
53
+ fp: '',
54
+ sf: '',
55
+ sfp: '',
56
+ sfz: '',
57
+ rf: '',
58
+ rfz: '',
59
+ fz: '',
60
+ n: '',
61
+ };
62
+
63
+ const DYNAMIC_FONT_SIZE = 30;
64
+
65
+ const ANNOTATION_FONT = {
66
+ family: 'Arial, Helvetica, sans-serif',
67
+ size: 10,
68
+ weight: 'bold',
69
+ };
70
+
71
+ const LYRIC_FONT = {
72
+ family: ANNOTATION_FONT.family,
73
+ size: 10,
74
+ weight: 'normal',
75
+ };
76
+
77
+ const DIRECTION_FONT = {
78
+ family: ANNOTATION_FONT.family,
79
+ size: 11,
80
+ weight: 'bold',
81
+ };
82
+
83
+ /** `GhostNote`s have no glyphs, so their element box is the origin. */
84
+ export function hasNoteHeads(note: StemmableNote): note is StaveNote {
85
+ return 'getNoteHeadBeginX' in note;
86
+ }
87
+
88
+ /**
89
+ * Applies the requested number of augmentation dots to a note.
90
+ */
91
+ export function applyDots(note: StaveNote, dots?: 0 | 1 | 2 | 3) {
92
+ for (let i = 0; i < (dots ?? 0); i++) {
93
+ Dot.buildAndAttach([note], { all: true });
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Adds pitch accidentals to the matching keys in a VexFlow note.
99
+ */
100
+ function addPitchAccidentals(note: StaveNote, pitches: readonly Pitch[]) {
101
+ pitches.forEach((pitch, index) => {
102
+ if (!pitch.accidental) {
103
+ return;
104
+ }
105
+
106
+ const type =
107
+ pitch.accidental === 'quarter-flat'
108
+ ? 'db'
109
+ : pitch.accidental === 'quarter-sharp'
110
+ ? 'd#'
111
+ : pitch.accidental;
112
+
113
+ note.addModifier(new VFAccidental(type), index);
114
+ });
115
+ }
116
+
117
+ /**
118
+ * Wraps each parenthesized pitch of a note in parentheses.
119
+ */
120
+ function applyPitchParentheses(note: StaveNote, pitches: readonly Pitch[]) {
121
+ pitches.forEach((pitch, index) => {
122
+ if (!pitch.parenthesized) {
123
+ return;
124
+ }
125
+
126
+ note.addModifier(new Parenthesis(ModifierPosition.LEFT), index);
127
+ note.addModifier(new Parenthesis(ModifierPosition.RIGHT), index);
128
+ });
129
+ }
130
+
131
+ export function decorateStaveNote(
132
+ note: StaveNote,
133
+ pitches: readonly Pitch[],
134
+ duration: DurationValue
135
+ ) {
136
+ addPitchAccidentals(note, pitches);
137
+ applyPitchParentheses(note, pitches);
138
+ applyDots(note, duration.dots);
139
+ }
140
+
141
+ /** Every attachment a rest can carry: grace notes need a pitched owner. */
142
+ export function restAttachments(
143
+ attachments: NoteAttachment[] | undefined
144
+ ): NoteAttachment[] | undefined {
145
+ return attachments?.filter((attachment) => attachment.type !== 'grace');
146
+ }
147
+
148
+ function verticalJustification(placement: 'above' | 'below') {
149
+ return placement === 'above'
150
+ ? AnnotationVerticalJustify.TOP
151
+ : AnnotationVerticalJustify.BOTTOM;
152
+ }
153
+
154
+ function byVerse(left: LyricAttachment, right: LyricAttachment) {
155
+ return (left.verse ?? -Infinity) - (right.verse ?? -Infinity);
156
+ }
157
+
158
+ /**
159
+ * Attaches the owner's marks to a VexFlow note in a fixed order regardless of
160
+ * the attachments' order: articulations, annotations, dynamics, lyrics (by
161
+ * verse), grace notes. Same-side marks stack outward in that order.
162
+ */
163
+ export function applyNoteModifiers(
164
+ note: StaveNote,
165
+ clef: Clef,
166
+ attachments: NoteAttachment[] | undefined
167
+ ) {
168
+ if (!attachments) {
169
+ return;
170
+ }
171
+
172
+ for (const attachment of attachments) {
173
+ if (attachment.type === 'articulation') {
174
+ const articulation = new VFArticulation(
175
+ ARTICULATION_TO_VF_CODE[attachment.articulation]
176
+ );
177
+
178
+ if (attachment.placement === 'below') {
179
+ articulation.setPosition(ModifierPosition.BELOW);
180
+ }
181
+
182
+ note.addModifier(articulation, 0);
183
+ }
184
+ }
185
+
186
+ for (const attachment of attachments) {
187
+ if (attachment.type === 'annotation') {
188
+ const annotation = new VFAnnotation(attachment.text);
189
+
190
+ annotation.setFont(ANNOTATION_FONT);
191
+ annotation.setVerticalJustification(
192
+ verticalJustification(attachment.placement ?? 'below')
193
+ );
194
+ note.addModifier(annotation, 0);
195
+ }
196
+ }
197
+
198
+ for (const attachment of attachments) {
199
+ if (attachment.type === 'dynamic') {
200
+ const dynamic = new VFAnnotation(DYNAMIC_GLYPHS[attachment.dynamic]);
201
+
202
+ dynamic.setFontSize(DYNAMIC_FONT_SIZE);
203
+ dynamic.setVerticalJustification(
204
+ verticalJustification(attachment.placement ?? 'below')
205
+ );
206
+ note.addModifier(dynamic, 0);
207
+ }
208
+ }
209
+
210
+ attachments
211
+ .filter(
212
+ (attachment): attachment is LyricAttachment => attachment.type === 'lyric'
213
+ )
214
+ .sort(byVerse)
215
+ .forEach((attachment) => {
216
+ const lyric = new VFAnnotation(attachment.text);
217
+
218
+ lyric.setFont(LYRIC_FONT);
219
+ lyric.setVerticalJustification(AnnotationVerticalJustify.BOTTOM);
220
+ note.addModifier(lyric, 0);
221
+ });
222
+
223
+ for (const attachment of attachments) {
224
+ if (attachment.type === 'grace') {
225
+ applyGraceNoteGroup(note, clef, attachment);
226
+ }
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Grace notes stem up unless the owner was built stem-down (auto stems that
232
+ * flip later in `Beam.generateBeams` are not followed); two or more are
233
+ * beamed together, with the acciaccatura slash on the first stem only.
234
+ */
235
+ function applyGraceNoteGroup(
236
+ note: StaveNote,
237
+ clef: Clef,
238
+ attachment: GraceNoteAttachment
239
+ ) {
240
+ if (attachment.notes.length === 0) {
241
+ return;
242
+ }
243
+
244
+ const stemDirection =
245
+ note.getStemDirection() === Stem.DOWN ? Stem.DOWN : Stem.UP;
246
+ const graceNotes = attachment.notes.map((graceNote, index) => {
247
+ const vfGraceNote = new VFGraceNote({
248
+ clef,
249
+ keys: [pitchToVFKey(graceNote.pitch)],
250
+ duration: durationToVF(graceNote.duration),
251
+ slash: index === 0 && attachment.slash === true,
252
+ stemDirection,
253
+ });
254
+ decorateStaveNote(vfGraceNote, [graceNote.pitch], graceNote.duration);
255
+ return vfGraceNote;
256
+ });
257
+ const group = new GraceNoteGroup(graceNotes);
258
+
259
+ if (graceNotes.length > 1) {
260
+ group.beamNotes();
261
+ }
262
+
263
+ note.addModifier(group, 0);
264
+ }
265
+
266
+ /**
267
+ * Draws each text direction of a measure on the voice's first drawn item,
268
+ * after that item's own marks; a voice of spacers draws none. Tempo
269
+ * directions are not drawn.
270
+ */
271
+ export function applyMeasureDirections(
272
+ notes: readonly StemmableNote[],
273
+ directions: readonly Direction[] | undefined
274
+ ) {
275
+ if (!directions?.length) {
276
+ return;
277
+ }
278
+
279
+ const anchor = notes.find(hasNoteHeads);
280
+
281
+ if (!anchor) {
282
+ return;
283
+ }
284
+
285
+ for (const direction of directions) {
286
+ if (direction.type !== 'text') {
287
+ continue;
288
+ }
289
+
290
+ const annotation = new VFAnnotation(direction.text);
291
+
292
+ annotation.setFont(DIRECTION_FONT);
293
+ annotation.setVerticalJustification(
294
+ verticalJustification(direction.placement ?? 'above')
295
+ );
296
+ anchor.addModifier(annotation, 0);
297
+ }
298
+ }