vexflow-native 1.6.0 → 1.8.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.
- package/README.md +84 -1
- package/lib/module/base/FontManager.js +0 -0
- package/lib/module/base/FontManager.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js +61 -12
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/PartParser.js +1 -0
- package/lib/module/musicxml/MusicXmlParser/PartParser.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/index.js +1 -0
- package/lib/module/musicxml/MusicXmlParser/index.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/mappers.js +11 -1
- package/lib/module/musicxml/MusicXmlParser/mappers.js.map +1 -1
- package/lib/module/renderer/measure.js +27 -17
- package/lib/module/renderer/measure.js.map +1 -1
- package/lib/module/renderer/render.js +28 -15
- package/lib/module/renderer/render.js.map +1 -1
- package/lib/module/renderer/scoreParsing.js +94 -22
- package/lib/module/renderer/scoreParsing.js.map +1 -1
- package/lib/module/renderer/stave.js +21 -0
- package/lib/module/renderer/stave.js.map +1 -0
- package/lib/module/state/constants.js +8 -0
- package/lib/module/state/constants.js.map +1 -0
- package/lib/module/state/index.js +1 -0
- package/lib/module/state/index.js.map +1 -1
- package/lib/typescript/src/base/FontManager.d.ts +6 -0
- package/lib/typescript/src/base/FontManager.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts +7 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/index.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts.map +1 -1
- package/lib/typescript/src/renderer/measure.d.ts.map +1 -1
- package/lib/typescript/src/renderer/render.d.ts +7 -3
- package/lib/typescript/src/renderer/render.d.ts.map +1 -1
- package/lib/typescript/src/renderer/scoreParsing.d.ts +17 -4
- package/lib/typescript/src/renderer/scoreParsing.d.ts.map +1 -1
- package/lib/typescript/src/renderer/stave.d.ts +9 -0
- package/lib/typescript/src/renderer/stave.d.ts.map +1 -0
- package/lib/typescript/src/renderer/types.d.ts +2 -2
- package/lib/typescript/src/renderer/types.d.ts.map +1 -1
- package/lib/typescript/src/state/constants.d.ts +4 -0
- package/lib/typescript/src/state/constants.d.ts.map +1 -0
- package/lib/typescript/src/state/index.d.ts +1 -0
- package/lib/typescript/src/state/index.d.ts.map +1 -1
- package/lib/typescript/src/state/types.d.ts +30 -2
- package/lib/typescript/src/state/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/base/FontManager.ts +0 -0
- package/src/musicxml/MusicXmlParser/InternalTypes.ts +8 -0
- package/src/musicxml/MusicXmlParser/MeasureParser.ts +83 -20
- package/src/musicxml/MusicXmlParser/PartParser.ts +2 -0
- package/src/musicxml/MusicXmlParser/index.ts +1 -0
- package/src/musicxml/MusicXmlParser/mappers.ts +15 -1
- package/src/renderer/measure.tsx +30 -18
- package/src/renderer/render.tsx +40 -19
- package/src/renderer/scoreParsing.tsx +145 -23
- package/src/renderer/stave.ts +25 -0
- package/src/renderer/types.ts +2 -2
- package/src/state/constants.ts +4 -0
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +38 -2
package/src/renderer/render.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
makeVFVoice,
|
|
19
19
|
noteheadWidth,
|
|
20
20
|
} from './scoreParsing';
|
|
21
|
+
import { applyStaffLines } from './stave';
|
|
21
22
|
import type { ScoreItemsLayout, ScoreOptions } from './types';
|
|
22
23
|
import type { VFVoiceNote } from './scoreParsing';
|
|
23
24
|
|
|
@@ -101,9 +102,13 @@ interface RenderMeasureOptions {
|
|
|
101
102
|
* area, overriding the formatter's duration-weighted spacing. Runs after
|
|
102
103
|
* `formatToStave` (the same post-format `setX` mechanism the formatter's own
|
|
103
104
|
* tuning uses), so beams, tuplets and modifiers pick the final positions up
|
|
104
|
-
* at draw time. The
|
|
105
|
-
*
|
|
106
|
-
*
|
|
105
|
+
* at draw time. The lattice follows VexFlow's own convention for its first
|
|
106
|
+
* tick: it starts at that context's left-modifier width (`totalLeftPx`), so a
|
|
107
|
+
* grace group or accidental on beat 1 hangs inside the note area instead of
|
|
108
|
+
* over the clef. The proportional span is clamped only by that inset and the
|
|
109
|
+
* LAST context's width — with a spacer voice on the lattice the latter is
|
|
110
|
+
* constant, so the mapping stays a pure function of time and of what hangs
|
|
111
|
+
* left of beat 1.
|
|
107
112
|
*/
|
|
108
113
|
export function applyFixedNoteSpacing(
|
|
109
114
|
formatter: Formatter,
|
|
@@ -111,13 +116,13 @@ export function applyFixedNoteSpacing(
|
|
|
111
116
|
stave: Stave
|
|
112
117
|
) {
|
|
113
118
|
const contexts = formatter.getTickContexts();
|
|
114
|
-
const
|
|
119
|
+
const lastTickKey = contexts?.list[contexts.list.length - 1];
|
|
115
120
|
|
|
116
121
|
if (
|
|
117
122
|
!contexts ||
|
|
118
123
|
voices.length === 0 ||
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
lastTickKey === undefined ||
|
|
125
|
+
lastTickKey <= 0
|
|
121
126
|
) {
|
|
122
127
|
return;
|
|
123
128
|
}
|
|
@@ -128,6 +133,14 @@ export function applyFixedNoteSpacing(
|
|
|
128
133
|
return;
|
|
129
134
|
}
|
|
130
135
|
|
|
136
|
+
// Tick context keys are ticks × the formatter's resolution multiplier (the
|
|
137
|
+
// lcm that keeps tuplet ticks integral: 3 with triplets, 5 with
|
|
138
|
+
// quintuplets…), while getTotalTicks() is in plain ticks. Compare in plain
|
|
139
|
+
// ticks, or every position scales by the multiplier and the overflow
|
|
140
|
+
// correction below crushes the last tick flush against the note end.
|
|
141
|
+
const multiplier = contexts.resolutionMultiplier || 1;
|
|
142
|
+
const lastTick = lastTickKey / multiplier;
|
|
143
|
+
|
|
131
144
|
// Tick context x is relative to noteStartX + the stave's left note padding
|
|
132
145
|
// (see Tickable.getAbsoluteX), so the usable span ends at noteEndX. The
|
|
133
146
|
// padding is derived from Stave statics because the `Metrics` module is not
|
|
@@ -135,11 +148,15 @@ export function applyFixedNoteSpacing(
|
|
|
135
148
|
const stavePadding = Stave.defaultPadding - Stave.rightPadding;
|
|
136
149
|
const noteAreaWidth =
|
|
137
150
|
stave.getNoteEndX() - stave.getNoteStartX() - stavePadding;
|
|
138
|
-
|
|
151
|
+
const firstLeft = contexts.map[contexts.list[0]!]!.getMetrics().totalLeftPx;
|
|
152
|
+
let span = noteAreaWidth - firstLeft;
|
|
139
153
|
|
|
140
|
-
const lastContext = contexts.map[
|
|
154
|
+
const lastContext = contexts.map[lastTickKey]!;
|
|
141
155
|
const lastOverflow =
|
|
142
|
-
|
|
156
|
+
firstLeft +
|
|
157
|
+
(lastTick / totalTicks) * span +
|
|
158
|
+
lastContext.getWidth() -
|
|
159
|
+
noteAreaWidth;
|
|
143
160
|
|
|
144
161
|
if (lastOverflow > 0) {
|
|
145
162
|
span -= (lastOverflow * totalTicks) / lastTick;
|
|
@@ -149,8 +166,10 @@ export function applyFixedNoteSpacing(
|
|
|
149
166
|
return;
|
|
150
167
|
}
|
|
151
168
|
|
|
152
|
-
for (const
|
|
153
|
-
contexts.map[
|
|
169
|
+
for (const tickKey of contexts.list) {
|
|
170
|
+
contexts.map[tickKey]!.setX(
|
|
171
|
+
firstLeft + (tickKey / multiplier / totalTicks) * span
|
|
172
|
+
);
|
|
154
173
|
}
|
|
155
174
|
}
|
|
156
175
|
|
|
@@ -184,6 +203,7 @@ function renderMeasure(
|
|
|
184
203
|
const voiceArtifacts = measure.voices.map((voice) => ({
|
|
185
204
|
...makeVFVoice(score, resolvedState.meter, resolvedState.clef, voice, {
|
|
186
205
|
attachmentsByOwner,
|
|
206
|
+
staffLines: staff.lines,
|
|
187
207
|
resolveClef: (item) =>
|
|
188
208
|
item.targetStaffId
|
|
189
209
|
? resolvedStateByStaffId.get(item.targetStaffId)?.clef ??
|
|
@@ -195,9 +215,7 @@ function renderMeasure(
|
|
|
195
215
|
}));
|
|
196
216
|
const vfVoices = voiceArtifacts.map(({ vfVoice }) => vfVoice);
|
|
197
217
|
|
|
198
|
-
|
|
199
|
-
formatter.joinVoices(vfVoices);
|
|
200
|
-
}
|
|
218
|
+
formatter.joinVoices(vfVoices);
|
|
201
219
|
|
|
202
220
|
return {
|
|
203
221
|
vfVoices,
|
|
@@ -220,13 +238,16 @@ function renderMeasure(
|
|
|
220
238
|
const measure = staff.measures[measurePlan.measureIndex]!;
|
|
221
239
|
const resolvedState =
|
|
222
240
|
group.resolvedStatesByStaff[staffIndex]![measurePlan.measureIndex]!;
|
|
223
|
-
const stave =
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
241
|
+
const stave = applyStaffLines(
|
|
242
|
+
new Stave(
|
|
243
|
+
measurePlan.x,
|
|
244
|
+
measurePlan.y + (measurePlan.staffYOffsets[staffIndex] ?? 0),
|
|
245
|
+
measurePlan.width
|
|
246
|
+
),
|
|
247
|
+
staff.lines
|
|
227
248
|
);
|
|
228
249
|
|
|
229
|
-
if (measurePlan.measureIndex === 0
|
|
250
|
+
if (measure.leftModifiers?.showClef ?? measurePlan.measureIndex === 0) {
|
|
230
251
|
stave.addClef(resolvedState.clef);
|
|
231
252
|
}
|
|
232
253
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Accidental as VFAccidental,
|
|
3
|
+
Annotation as VFAnnotation,
|
|
4
|
+
AnnotationVerticalJustify,
|
|
3
5
|
Articulation as VFArticulation,
|
|
4
6
|
Beam,
|
|
5
7
|
Dot,
|
|
6
8
|
Element,
|
|
7
9
|
Fraction as VFFraction,
|
|
8
10
|
GhostNote,
|
|
11
|
+
GraceNote as VFGraceNote,
|
|
12
|
+
GraceNoteGroup,
|
|
9
13
|
ModifierPosition,
|
|
10
14
|
Parenthesis,
|
|
11
15
|
StaveNote,
|
|
@@ -20,6 +24,7 @@ import type {
|
|
|
20
24
|
Clef,
|
|
21
25
|
KeySignature,
|
|
22
26
|
DurationValue,
|
|
27
|
+
GraceNoteAttachment,
|
|
23
28
|
Meter,
|
|
24
29
|
NoteAttachment,
|
|
25
30
|
Notehead,
|
|
@@ -27,6 +32,7 @@ import type {
|
|
|
27
32
|
Score,
|
|
28
33
|
Staff,
|
|
29
34
|
StaffGroup,
|
|
35
|
+
StaffLines,
|
|
30
36
|
StemDirection,
|
|
31
37
|
Tempo,
|
|
32
38
|
TupletGroup,
|
|
@@ -57,6 +63,8 @@ export interface MakeVFVoiceOptions {
|
|
|
57
63
|
* rebuilding it on every call.
|
|
58
64
|
*/
|
|
59
65
|
attachmentsByOwner?: Map<string, NoteAttachment[]>;
|
|
66
|
+
/** `Staff.lines`; on a one-line staff auto stems point up. */
|
|
67
|
+
staffLines?: StaffLines;
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
/**
|
|
@@ -83,6 +91,8 @@ export const ARTICULATION_TO_VF_CODE: Record<Articulation, string> = {
|
|
|
83
91
|
accent: 'a>',
|
|
84
92
|
marcato: 'a^',
|
|
85
93
|
fermata: 'a@',
|
|
94
|
+
open: 'ah',
|
|
95
|
+
stopped: 'a+',
|
|
86
96
|
};
|
|
87
97
|
|
|
88
98
|
/**
|
|
@@ -148,7 +158,10 @@ export function applyDots(note: StaveNote, dots?: 0 | 1 | 2 | 3) {
|
|
|
148
158
|
/**
|
|
149
159
|
* Adds pitch accidentals to the matching keys in a VexFlow note.
|
|
150
160
|
*/
|
|
151
|
-
export function addPitchAccidentals(
|
|
161
|
+
export function addPitchAccidentals(
|
|
162
|
+
note: StaveNote,
|
|
163
|
+
pitches: readonly Pitch[]
|
|
164
|
+
) {
|
|
152
165
|
pitches.forEach((pitch, index) => {
|
|
153
166
|
if (!pitch.accidental) {
|
|
154
167
|
return;
|
|
@@ -182,8 +195,49 @@ export function applyGhostParentheses(
|
|
|
182
195
|
});
|
|
183
196
|
}
|
|
184
197
|
|
|
185
|
-
|
|
198
|
+
function hasAccentAttachment(attachments: NoteAttachment[] | undefined) {
|
|
199
|
+
return (
|
|
200
|
+
attachments?.some(
|
|
201
|
+
(attachment) =>
|
|
202
|
+
attachment.type === 'articulation' &&
|
|
203
|
+
attachment.articulation === 'accent'
|
|
204
|
+
) ?? false
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Draws one accent above a note whose pitches carry the `accent` flag, unless
|
|
210
|
+
* the owner already has an accent attachment.
|
|
211
|
+
*/
|
|
212
|
+
export function applyPitchAccent(
|
|
186
213
|
note: StaveNote,
|
|
214
|
+
pitches: readonly Pitch[],
|
|
215
|
+
attachments?: NoteAttachment[]
|
|
216
|
+
) {
|
|
217
|
+
if (!pitches.some((pitch) => pitch.accent)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (hasAccentAttachment(attachments)) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
note.addModifier(new VFArticulation(ARTICULATION_TO_VF_CODE.accent), 0);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const ANNOTATION_FONT = {
|
|
229
|
+
family: 'Arial, Helvetica, sans-serif',
|
|
230
|
+
size: 10,
|
|
231
|
+
weight: 'bold',
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Attaches the owner's articulation, annotation and grace-note modifiers to
|
|
236
|
+
* a VexFlow note; dynamics and lyrics are drawn elsewhere.
|
|
237
|
+
*/
|
|
238
|
+
export function applyNoteModifiers(
|
|
239
|
+
note: StaveNote,
|
|
240
|
+
clef: Clef,
|
|
187
241
|
attachments: NoteAttachment[] | undefined
|
|
188
242
|
) {
|
|
189
243
|
if (!attachments) {
|
|
@@ -191,20 +245,76 @@ export function applyArticulations(
|
|
|
191
245
|
}
|
|
192
246
|
|
|
193
247
|
for (const attachment of attachments) {
|
|
194
|
-
if (attachment.type
|
|
195
|
-
|
|
196
|
-
|
|
248
|
+
if (attachment.type === 'articulation') {
|
|
249
|
+
const articulation = new VFArticulation(
|
|
250
|
+
ARTICULATION_TO_VF_CODE[attachment.articulation]
|
|
251
|
+
);
|
|
197
252
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
253
|
+
if (attachment.placement === 'below') {
|
|
254
|
+
articulation.setPosition(ModifierPosition.BELOW);
|
|
255
|
+
}
|
|
201
256
|
|
|
202
|
-
|
|
203
|
-
|
|
257
|
+
note.addModifier(articulation, 0);
|
|
258
|
+
} else if (attachment.type === 'annotation') {
|
|
259
|
+
const annotation = new VFAnnotation(attachment.text);
|
|
260
|
+
|
|
261
|
+
annotation.setFont(ANNOTATION_FONT);
|
|
262
|
+
annotation.setVerticalJustification(
|
|
263
|
+
attachment.placement === 'above'
|
|
264
|
+
? AnnotationVerticalJustify.TOP
|
|
265
|
+
: AnnotationVerticalJustify.BOTTOM
|
|
266
|
+
);
|
|
267
|
+
note.addModifier(annotation, 0);
|
|
268
|
+
} else if (attachment.type === 'grace') {
|
|
269
|
+
applyGraceNoteGroup(note, clef, attachment);
|
|
204
270
|
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Grace notes stem up unless the owner was built stem-down (auto stems that
|
|
276
|
+
* flip later in `Beam.generateBeams` are not followed); two or more are
|
|
277
|
+
* beamed together, with the acciaccatura slash on the first stem only.
|
|
278
|
+
*/
|
|
279
|
+
function applyGraceNoteGroup(
|
|
280
|
+
note: StaveNote,
|
|
281
|
+
clef: Clef,
|
|
282
|
+
attachment: GraceNoteAttachment
|
|
283
|
+
) {
|
|
284
|
+
if (attachment.notes.length === 0) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const stemDirection =
|
|
289
|
+
note.getStemDirection() === Stem.DOWN ? Stem.DOWN : Stem.UP;
|
|
290
|
+
const graceNotes = attachment.notes.map((graceNote, index) => {
|
|
291
|
+
const vfGraceNote = new VFGraceNote({
|
|
292
|
+
clef,
|
|
293
|
+
keys: [pitchToVFKey(graceNote.pitch)],
|
|
294
|
+
duration: durationToVF(graceNote.duration),
|
|
295
|
+
slash: index === 0 && attachment.slash === true,
|
|
296
|
+
stemDirection,
|
|
297
|
+
});
|
|
298
|
+
decorateStaveNote(vfGraceNote, [graceNote.pitch], graceNote.duration);
|
|
299
|
+
return vfGraceNote;
|
|
300
|
+
});
|
|
301
|
+
const group = new GraceNoteGroup(graceNotes);
|
|
205
302
|
|
|
206
|
-
|
|
303
|
+
if (graceNotes.length > 1) {
|
|
304
|
+
group.beamNotes();
|
|
207
305
|
}
|
|
306
|
+
|
|
307
|
+
note.addModifier(group, 0);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function decorateStaveNote(
|
|
311
|
+
note: StaveNote,
|
|
312
|
+
pitches: readonly Pitch[],
|
|
313
|
+
duration: DurationValue
|
|
314
|
+
) {
|
|
315
|
+
addPitchAccidentals(note, pitches);
|
|
316
|
+
applyGhostParentheses(note, pitches);
|
|
317
|
+
applyDots(note, duration.dots);
|
|
208
318
|
}
|
|
209
319
|
|
|
210
320
|
export function indexAttachmentsByOwner(
|
|
@@ -269,6 +379,11 @@ export function voiceItemToStaveNote(
|
|
|
269
379
|
duration: durationToVF(item.duration, true),
|
|
270
380
|
});
|
|
271
381
|
applyDots(note, item.duration.dots);
|
|
382
|
+
applyNoteModifiers(
|
|
383
|
+
note,
|
|
384
|
+
clef,
|
|
385
|
+
attachments?.filter((attachment) => attachment.type === 'annotation')
|
|
386
|
+
);
|
|
272
387
|
return note;
|
|
273
388
|
}
|
|
274
389
|
|
|
@@ -279,10 +394,9 @@ export function voiceItemToStaveNote(
|
|
|
279
394
|
duration: durationToVF(item.duration),
|
|
280
395
|
stemDirection: toVFStemDirection(item.stemDirection),
|
|
281
396
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
applyDots(note, item.duration.dots);
|
|
397
|
+
decorateStaveNote(note, [item.pitch], item.duration);
|
|
398
|
+
applyPitchAccent(note, [item.pitch], attachments);
|
|
399
|
+
applyNoteModifiers(note, clef, attachments);
|
|
286
400
|
return note;
|
|
287
401
|
}
|
|
288
402
|
|
|
@@ -292,22 +406,29 @@ export function voiceItemToStaveNote(
|
|
|
292
406
|
duration: durationToVF(item.duration),
|
|
293
407
|
stemDirection: toVFStemDirection(item.stemDirection),
|
|
294
408
|
});
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
applyDots(note, item.duration.dots);
|
|
409
|
+
decorateStaveNote(note, item.pitches, item.duration);
|
|
410
|
+
applyPitchAccent(note, item.pitches, attachments);
|
|
411
|
+
applyNoteModifiers(note, clef, attachments);
|
|
299
412
|
return note;
|
|
300
413
|
}
|
|
301
414
|
|
|
302
415
|
/**
|
|
303
|
-
*
|
|
416
|
+
* Beam groups for a meter: its explicit `beamGroups`, otherwise VexFlow's
|
|
417
|
+
* conventional grouping for the time signature (quarters in x/4, dotted
|
|
418
|
+
* quarters in 6/8, 9/8, 12/8, halves in x/2).
|
|
304
419
|
*/
|
|
305
420
|
export function beamGroupsToVF(meter?: Meter): VFFraction[] | undefined {
|
|
306
|
-
if (!meter
|
|
421
|
+
if (!meter) {
|
|
307
422
|
return undefined;
|
|
308
423
|
}
|
|
309
424
|
|
|
310
|
-
|
|
425
|
+
if (meter.beamGroups?.length) {
|
|
426
|
+
return meter.beamGroups.map(
|
|
427
|
+
(group) => new VFFraction(group.num, group.den)
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return Beam.getDefaultBeamGroups(`${meter.beats}/${meter.beatUnit}`);
|
|
311
432
|
}
|
|
312
433
|
|
|
313
434
|
function hasExplicitStemDirection(item: VoiceItem): boolean {
|
|
@@ -436,7 +557,8 @@ export function makeVFVoice(
|
|
|
436
557
|
}
|
|
437
558
|
|
|
438
559
|
const groups = beamGroupsToVF(meter);
|
|
439
|
-
const maintainStemDirections =
|
|
560
|
+
const maintainStemDirections =
|
|
561
|
+
options.staffLines === 1 || voice.items.some(hasExplicitStemDirection);
|
|
440
562
|
const beamOptions =
|
|
441
563
|
groups || maintainStemDirections
|
|
442
564
|
? {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Stave } from 'vexflow';
|
|
2
|
+
|
|
3
|
+
import type { StaffLines } from '../state';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hides the outer lines of a 5-line stave so `lines` stay visible around the
|
|
7
|
+
* middle one. Must run after construction: the constructor resets the line
|
|
8
|
+
* config.
|
|
9
|
+
*/
|
|
10
|
+
export function applyStaffLines(stave: Stave, lines?: StaffLines): Stave {
|
|
11
|
+
const lineCount = stave.getNumLines();
|
|
12
|
+
|
|
13
|
+
if (lines === undefined || lines === lineCount) {
|
|
14
|
+
return stave;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const middleLine = (lineCount - 1) / 2;
|
|
18
|
+
const reach = (lines - 1) / 2;
|
|
19
|
+
|
|
20
|
+
return stave.setConfigForLines(
|
|
21
|
+
Array.from({ length: lineCount }, (_, index) => ({
|
|
22
|
+
visible: Math.abs(index - middleLine) <= reach,
|
|
23
|
+
}))
|
|
24
|
+
);
|
|
25
|
+
}
|
package/src/renderer/types.ts
CHANGED
|
@@ -182,9 +182,9 @@ export interface ScoreMeasureItemsLayout {
|
|
|
182
182
|
y: number;
|
|
183
183
|
/** Height of the measure's system block. */
|
|
184
184
|
height: number;
|
|
185
|
-
/** Top edge of this stave's top staff line. */
|
|
185
|
+
/** Top edge of this stave's top staff line (hidden lines included). */
|
|
186
186
|
staveLineTopY: number;
|
|
187
|
-
/** Bottom edge of this stave's bottom staff line. */
|
|
187
|
+
/** Bottom edge of this stave's bottom staff line (hidden lines included). */
|
|
188
188
|
staveLineBottomY: number;
|
|
189
189
|
}
|
|
190
190
|
|
package/src/state/index.ts
CHANGED
package/src/state/types.ts
CHANGED
|
@@ -64,7 +64,9 @@ export type Articulation =
|
|
|
64
64
|
| 'accent'
|
|
65
65
|
| 'marcato'
|
|
66
66
|
| 'staccatissimo'
|
|
67
|
-
| 'fermata'
|
|
67
|
+
| 'fermata'
|
|
68
|
+
| 'open'
|
|
69
|
+
| 'stopped';
|
|
68
70
|
|
|
69
71
|
export type Dynamic =
|
|
70
72
|
| 'ppp'
|
|
@@ -102,6 +104,8 @@ export interface Pitch {
|
|
|
102
104
|
accidental?: Accidental;
|
|
103
105
|
notehead?: Notehead;
|
|
104
106
|
ghost?: boolean;
|
|
107
|
+
/** A note or chord with any accented pitch draws one accent (`>`) above it. */
|
|
108
|
+
accent?: boolean;
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
export interface DurationValue {
|
|
@@ -175,6 +179,7 @@ export interface MeasureState {
|
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
export interface MeasureLeftModifiers {
|
|
182
|
+
/** undefined = shown on the first measure only; false hides it there too. */
|
|
178
183
|
showClef?: boolean;
|
|
179
184
|
showMeter?: boolean;
|
|
180
185
|
showKeySignature?: boolean;
|
|
@@ -214,12 +219,20 @@ export interface Measure {
|
|
|
214
219
|
voices: Voice[];
|
|
215
220
|
}
|
|
216
221
|
|
|
222
|
+
export type StaffLines = 1 | 3 | 5;
|
|
223
|
+
|
|
217
224
|
export interface Staff {
|
|
218
225
|
id: Id;
|
|
219
226
|
name?: string;
|
|
220
227
|
shortName?: string;
|
|
221
228
|
order: number;
|
|
222
229
|
defaultClef: Clef;
|
|
230
|
+
/**
|
|
231
|
+
* Visible staff lines (default 5). Fewer lines hide the outer lines
|
|
232
|
+
* symmetrically around the middle one while notes keep the 5-line pitch
|
|
233
|
+
* geometry, so a one-line staff's line is `ONE_LINE_STAFF_PITCH`.
|
|
234
|
+
*/
|
|
235
|
+
lines?: StaffLines;
|
|
223
236
|
transposition?: number;
|
|
224
237
|
measures: Measure[];
|
|
225
238
|
}
|
|
@@ -269,10 +282,33 @@ export interface LyricAttachment extends AttachmentBase {
|
|
|
269
282
|
verse?: number;
|
|
270
283
|
}
|
|
271
284
|
|
|
285
|
+
/** Free text drawn above or below the owner (a note, chord or rest), e.g. a
|
|
286
|
+
* sticking letter or a fingering. */
|
|
287
|
+
export interface AnnotationAttachment extends AttachmentBase {
|
|
288
|
+
type: 'annotation';
|
|
289
|
+
text: string;
|
|
290
|
+
placement?: 'above' | 'below';
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface GraceNote {
|
|
294
|
+
pitch: Pitch;
|
|
295
|
+
duration: DurationValue;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface GraceNoteAttachment extends AttachmentBase {
|
|
299
|
+
type: 'grace';
|
|
300
|
+
/** Played before the owner, in order. */
|
|
301
|
+
notes: GraceNote[];
|
|
302
|
+
/** Acciaccatura slash through the (first) stem. */
|
|
303
|
+
slash?: boolean;
|
|
304
|
+
}
|
|
305
|
+
|
|
272
306
|
export type NoteAttachment =
|
|
273
307
|
| ArticulationAttachment
|
|
274
308
|
| DynamicAttachment
|
|
275
|
-
| LyricAttachment
|
|
309
|
+
| LyricAttachment
|
|
310
|
+
| AnnotationAttachment
|
|
311
|
+
| GraceNoteAttachment;
|
|
276
312
|
|
|
277
313
|
export interface Tie {
|
|
278
314
|
id: Id;
|