vexflow-native 2.3.1 → 2.5.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 +7 -1
- package/lib/module/base/FontManager.js +41 -27
- package/lib/module/base/FontManager.js.map +1 -1
- package/lib/module/base/VexflowCanvas.js +8 -6
- package/lib/module/base/VexflowCanvas.js.map +1 -1
- package/lib/module/base/VexflowRecordingClone.js +83 -0
- package/lib/module/base/VexflowRecordingClone.js.map +1 -0
- package/lib/module/base/VexflowRecordingContext.js +1 -80
- package/lib/module/base/VexflowRecordingContext.js.map +1 -1
- package/lib/module/base/builtInTextFont.js +21 -0
- package/lib/module/base/builtInTextFont.js.map +1 -0
- package/lib/module/base/cssFontShorthand.js +34 -0
- package/lib/module/base/cssFontShorthand.js.map +1 -0
- package/lib/module/base/fonts/OFL.txt +93 -0
- package/lib/module/base/fonts/academico.js +12 -0
- package/lib/module/base/fonts/academico.js.map +1 -0
- package/lib/module/base/pictureRetirement.js +70 -0
- package/lib/module/base/pictureRetirement.js.map +1 -0
- package/lib/module/base/setupVexflowReactNative.js +1 -36
- package/lib/module/base/setupVexflowReactNative.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js +22 -119
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/MusicXmlNotes.js +129 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlNotes.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/PartParser.js +8 -1
- package/lib/module/musicxml/MusicXmlParser/PartParser.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/Spanners.js +8 -5
- package/lib/module/musicxml/MusicXmlParser/Spanners.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/mappers.js +83 -3
- package/lib/module/musicxml/MusicXmlParser/mappers.js.map +1 -1
- package/lib/module/renderer/Layout/DocumentLayout.js +13 -4
- package/lib/module/renderer/Layout/DocumentLayout.js.map +1 -1
- package/lib/module/renderer/Layout/VerticalSpacing.js +37 -7
- package/lib/module/renderer/Layout/VerticalSpacing.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js +80 -46
- package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +10 -22
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js +18 -8
- package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/utils.js +42 -88
- package/lib/module/renderer/ScoreRenderer/utils.js.map +1 -1
- package/lib/module/renderer/constants.js +1 -1
- package/lib/module/renderer/layout.js +11 -4
- package/lib/module/renderer/layout.js.map +1 -1
- package/lib/module/renderer/lyrics.js +127 -0
- package/lib/module/renderer/lyrics.js.map +1 -0
- package/lib/module/renderer/measure.js +52 -13
- package/lib/module/renderer/measure.js.map +1 -1
- package/lib/module/renderer/measureBounds.js +5 -0
- package/lib/module/renderer/measureBounds.js.map +1 -1
- package/lib/module/renderer/measureModifiers.js +24 -6
- package/lib/module/renderer/measureModifiers.js.map +1 -1
- package/lib/module/renderer/noteModifiers.js +6 -14
- package/lib/module/renderer/noteModifiers.js.map +1 -1
- package/lib/module/renderer/{fixedNoteSpacing.js → noteSpacing.js} +46 -10
- package/lib/module/renderer/noteSpacing.js.map +1 -0
- package/lib/module/renderer/render.js +41 -21
- package/lib/module/renderer/render.js.map +1 -1
- package/lib/module/renderer/scale.js +8 -1
- package/lib/module/renderer/scale.js.map +1 -1
- package/lib/module/renderer/tempoMark.js +162 -0
- package/lib/module/renderer/tempoMark.js.map +1 -0
- package/lib/module/renderer/useScoreRecording.js +2 -1
- package/lib/module/renderer/useScoreRecording.js.map +1 -1
- package/lib/typescript/src/base/FontManager.d.ts +12 -7
- package/lib/typescript/src/base/FontManager.d.ts.map +1 -1
- package/lib/typescript/src/base/VexflowCanvas.d.ts.map +1 -1
- package/lib/typescript/src/base/VexflowRecordingClone.d.ts +8 -0
- package/lib/typescript/src/base/VexflowRecordingClone.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -1
- package/lib/typescript/src/base/builtInTextFont.d.ts +6 -0
- package/lib/typescript/src/base/builtInTextFont.d.ts.map +1 -0
- package/lib/typescript/src/base/cssFontShorthand.d.ts +3 -0
- package/lib/typescript/src/base/cssFontShorthand.d.ts.map +1 -0
- package/lib/typescript/src/base/fonts/academico.d.ts +5 -0
- package/lib/typescript/src/base/fonts/academico.d.ts.map +1 -0
- package/lib/typescript/src/base/pictureRetirement.d.ts +26 -0
- package/lib/typescript/src/base/pictureRetirement.d.ts.map +1 -0
- package/lib/typescript/src/base/setupVexflowReactNative.d.ts +0 -8
- package/lib/typescript/src/base/setupVexflowReactNative.d.ts.map +1 -1
- package/lib/typescript/src/base/types.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts +4 -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/MusicXmlNotes.d.ts +13 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlNotes.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts +6 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts +7 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts.map +1 -1
- package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts.map +1 -1
- package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts +6 -0
- package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts +14 -11
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts +8 -27
- package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts.map +1 -1
- package/lib/typescript/src/renderer/layout.d.ts +5 -1
- package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
- package/lib/typescript/src/renderer/lyrics.d.ts +42 -0
- package/lib/typescript/src/renderer/lyrics.d.ts.map +1 -0
- package/lib/typescript/src/renderer/measure.d.ts +7 -2
- package/lib/typescript/src/renderer/measure.d.ts.map +1 -1
- package/lib/typescript/src/renderer/measureBounds.d.ts +3 -0
- package/lib/typescript/src/renderer/measureBounds.d.ts.map +1 -1
- package/lib/typescript/src/renderer/measureModifiers.d.ts +14 -4
- package/lib/typescript/src/renderer/measureModifiers.d.ts.map +1 -1
- package/lib/typescript/src/renderer/noteModifiers.d.ts +3 -2
- package/lib/typescript/src/renderer/noteModifiers.d.ts.map +1 -1
- package/lib/typescript/src/renderer/{fixedNoteSpacing.d.ts → noteSpacing.d.ts} +9 -1
- package/lib/typescript/src/renderer/noteSpacing.d.ts.map +1 -0
- package/lib/typescript/src/renderer/render.d.ts.map +1 -1
- package/lib/typescript/src/renderer/scale.d.ts.map +1 -1
- package/lib/typescript/src/renderer/tempoMark.d.ts +21 -0
- package/lib/typescript/src/renderer/tempoMark.d.ts.map +1 -0
- package/lib/typescript/src/renderer/types.d.ts +31 -7
- package/lib/typescript/src/renderer/types.d.ts.map +1 -1
- package/lib/typescript/src/state/types.d.ts +11 -3
- package/lib/typescript/src/state/types.d.ts.map +1 -1
- package/package.json +34 -26
- package/src/base/FontManager.ts +50 -31
- package/src/base/VexflowCanvas.tsx +10 -10
- package/src/base/VexflowRecordingClone.ts +89 -0
- package/src/base/VexflowRecordingContext.ts +8 -81
- package/src/base/builtInTextFont.ts +25 -0
- package/src/base/cssFontShorthand.ts +45 -0
- package/src/base/fonts/OFL.txt +93 -0
- package/src/base/fonts/academico.ts +10 -0
- package/src/base/pictureRetirement.ts +74 -0
- package/src/base/setupVexflowReactNative.ts +1 -49
- package/src/base/types.ts +0 -3
- package/src/musicxml/MusicXmlParser/InternalTypes.ts +5 -0
- package/src/musicxml/MusicXmlParser/MeasureParser.ts +31 -182
- package/src/musicxml/MusicXmlParser/MusicXmlNotes.ts +198 -0
- package/src/musicxml/MusicXmlParser/PartParser.ts +10 -3
- package/src/musicxml/MusicXmlParser/Spanners.ts +11 -8
- package/src/musicxml/MusicXmlParser/mappers.ts +55 -6
- package/src/renderer/Layout/DocumentLayout.ts +12 -3
- package/src/renderer/Layout/VerticalSpacing.ts +46 -13
- package/src/renderer/ScoreRenderer/ScoreOverlayPicture.tsx +127 -66
- package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +8 -23
- package/src/renderer/ScoreRenderer/ScoreScrollbar.tsx +16 -2
- package/src/renderer/ScoreRenderer/types.ts +14 -12
- package/src/renderer/ScoreRenderer/utils.ts +54 -125
- package/src/renderer/constants.ts +1 -1
- package/src/renderer/layout.ts +19 -4
- package/src/renderer/lyrics.ts +163 -0
- package/src/renderer/measure.tsx +70 -12
- package/src/renderer/measureBounds.ts +10 -0
- package/src/renderer/measureModifiers.ts +27 -7
- package/src/renderer/noteModifiers.ts +9 -10
- package/src/renderer/{fixedNoteSpacing.ts → noteSpacing.ts} +60 -9
- package/src/renderer/render.tsx +63 -27
- package/src/renderer/scale.ts +9 -0
- package/src/renderer/tempoMark.ts +224 -0
- package/src/renderer/types.ts +32 -7
- package/src/renderer/useScoreRecording.ts +1 -0
- package/src/state/types.ts +11 -3
- package/lib/module/renderer/fixedNoteSpacing.js.map +0 -1
- package/lib/module/utils.js +0 -44
- package/lib/module/utils.js.map +0 -1
- package/lib/typescript/src/renderer/fixedNoteSpacing.d.ts.map +0 -1
- package/lib/typescript/src/utils.d.ts +0 -1
- package/lib/typescript/src/utils.d.ts.map +0 -1
- package/src/utils.tsx +0 -42
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Chord,
|
|
3
|
+
Clef,
|
|
4
|
+
DurationValue,
|
|
5
|
+
Pitch,
|
|
6
|
+
Voice,
|
|
7
|
+
VoiceItem,
|
|
8
|
+
} from '../../state';
|
|
9
|
+
import type { ParserState } from './InternalTypes';
|
|
10
|
+
import {
|
|
11
|
+
mapDurationType,
|
|
12
|
+
mapNotehead,
|
|
13
|
+
mapPitch,
|
|
14
|
+
mapStemDirection,
|
|
15
|
+
mapUnpitched,
|
|
16
|
+
} from './mappers';
|
|
17
|
+
import { inferDurationType } from './MusicXmlTiming';
|
|
18
|
+
import { MusicXmlParseError } from './types';
|
|
19
|
+
import {
|
|
20
|
+
attr,
|
|
21
|
+
childText,
|
|
22
|
+
childrenNamed,
|
|
23
|
+
firstChild,
|
|
24
|
+
hasChild,
|
|
25
|
+
optionalChild,
|
|
26
|
+
requiredNumberText,
|
|
27
|
+
textOf,
|
|
28
|
+
type XmlElement,
|
|
29
|
+
} from './XmlOrder';
|
|
30
|
+
|
|
31
|
+
export function createVoiceItem(
|
|
32
|
+
note: XmlElement,
|
|
33
|
+
voice: Voice,
|
|
34
|
+
isChordTone: boolean,
|
|
35
|
+
clef: Clef,
|
|
36
|
+
state: ParserState
|
|
37
|
+
): VoiceItem {
|
|
38
|
+
const duration = parseDuration(note, state);
|
|
39
|
+
|
|
40
|
+
if (hasChild(note, 'rest')) {
|
|
41
|
+
if (isChordTone) {
|
|
42
|
+
throw new MusicXmlParseError('Rest chord tones are unsupported');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
id: '',
|
|
47
|
+
type: 'rest',
|
|
48
|
+
duration,
|
|
49
|
+
voiceId: voice.id,
|
|
50
|
+
kind: attr(note, 'print-object') === 'no' ? 'hidden' : 'visible',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
id: '',
|
|
56
|
+
type: 'note',
|
|
57
|
+
pitch: parsePitch(note, clef),
|
|
58
|
+
duration,
|
|
59
|
+
voiceId: voice.id,
|
|
60
|
+
stemDirection: mapStemDirection(childText(note, 'stem')),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function parseDuration(note: XmlElement, state: ParserState): DurationValue {
|
|
65
|
+
const typeText = childText(note, 'type');
|
|
66
|
+
const type = typeText
|
|
67
|
+
? mapDurationType(typeText)
|
|
68
|
+
: inferDurationType(requiredNumberText(note, 'duration'), state.divisions);
|
|
69
|
+
const dotCount = childrenNamed(note, 'dot').length;
|
|
70
|
+
|
|
71
|
+
if (dotCount > 3) {
|
|
72
|
+
throw new MusicXmlParseError('More than three dots are unsupported');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
length: type,
|
|
77
|
+
dots: dotCount ? (dotCount as 1 | 2 | 3) : undefined,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function parsePitch(note: XmlElement, clef: Clef): Pitch {
|
|
82
|
+
const pitched = optionalChild(note, 'pitch');
|
|
83
|
+
const unpitched = optionalChild(note, 'unpitched');
|
|
84
|
+
const pitch = pitched
|
|
85
|
+
? mapPitch(pitched, childText(note, 'accidental'))
|
|
86
|
+
: unpitched && mapUnpitched(unpitched, clef);
|
|
87
|
+
|
|
88
|
+
if (!pitch) {
|
|
89
|
+
throw new MusicXmlParseError('Missing <pitch> or <unpitched>', {
|
|
90
|
+
path: note.name,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const notehead = optionalChild(note, 'notehead');
|
|
95
|
+
const shape = notehead && mapNotehead(textOf(notehead));
|
|
96
|
+
|
|
97
|
+
if (shape) {
|
|
98
|
+
pitch.notehead = shape;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (notehead && attr(notehead, 'parentheses') === 'yes') {
|
|
102
|
+
pitch.parenthesized = true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return pitch;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Grace chord tones keep only their first pitch; the group's slash comes
|
|
110
|
+
* from its first grace note.
|
|
111
|
+
*/
|
|
112
|
+
export function collectGraceNote(
|
|
113
|
+
note: XmlElement,
|
|
114
|
+
voiceName: string,
|
|
115
|
+
clef: Clef,
|
|
116
|
+
state: ParserState
|
|
117
|
+
) {
|
|
118
|
+
if (hasChild(note, 'chord')) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const graceNote = {
|
|
123
|
+
pitch: parsePitch(note, clef),
|
|
124
|
+
duration: parseDuration(note, state),
|
|
125
|
+
};
|
|
126
|
+
const pending = state.pendingGraceNotes.get(voiceName);
|
|
127
|
+
|
|
128
|
+
if (pending) {
|
|
129
|
+
pending.notes.push(graceNote);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
state.pendingGraceNotes.set(voiceName, {
|
|
134
|
+
notes: [graceNote],
|
|
135
|
+
slash: attr(firstChild(note, 'grace'), 'slash') === 'yes',
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function attachPendingGraceNotes(
|
|
140
|
+
itemId: string,
|
|
141
|
+
voiceName: string,
|
|
142
|
+
state: ParserState
|
|
143
|
+
) {
|
|
144
|
+
const pending = state.pendingGraceNotes.get(voiceName);
|
|
145
|
+
|
|
146
|
+
if (!pending) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
state.pendingGraceNotes.delete(voiceName);
|
|
151
|
+
state.attachments.push({
|
|
152
|
+
id: `${itemId}-grace`,
|
|
153
|
+
ownerId: itemId,
|
|
154
|
+
type: 'grace',
|
|
155
|
+
notes: pending.notes,
|
|
156
|
+
...(pending.slash ? { slash: true } : {}),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function pushItem(voice: Voice, item: VoiceItem): string {
|
|
161
|
+
item.id = `${voice.id}-item-${(voice.items.length + 1).toString()}`;
|
|
162
|
+
voice.items.push(item);
|
|
163
|
+
return item.id;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function mergeChordTone(
|
|
167
|
+
voice: Voice,
|
|
168
|
+
item: VoiceItem,
|
|
169
|
+
note: XmlElement
|
|
170
|
+
): string {
|
|
171
|
+
const previous = voice.items[voice.items.length - 1];
|
|
172
|
+
|
|
173
|
+
if (!previous || item.type !== 'note') {
|
|
174
|
+
throw new MusicXmlParseError('Chord tone has no previous pitched note');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (previous.type === 'note') {
|
|
178
|
+
const chord: Chord = {
|
|
179
|
+
id: previous.id,
|
|
180
|
+
type: 'chord',
|
|
181
|
+
pitches: [previous.pitch, item.pitch],
|
|
182
|
+
duration: previous.duration,
|
|
183
|
+
voiceId: previous.voiceId,
|
|
184
|
+
targetStaffId: previous.targetStaffId ?? item.targetStaffId,
|
|
185
|
+
stemDirection:
|
|
186
|
+
mapStemDirection(childText(note, 'stem')) ?? previous.stemDirection,
|
|
187
|
+
};
|
|
188
|
+
voice.items[voice.items.length - 1] = chord;
|
|
189
|
+
return chord.id;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (previous.type === 'chord') {
|
|
193
|
+
previous.pitches.push(item.pitch);
|
|
194
|
+
return previous.id;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
throw new MusicXmlParseError('Chord tone cannot follow a rest');
|
|
198
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Staff, StaffGroup } from '../../state';
|
|
1
|
+
import type { Clef, Staff, StaffGroup } from '../../state';
|
|
2
2
|
import type { PartInfo, ParserState, StaffBuild } from './InternalTypes';
|
|
3
3
|
import { parseMeasure } from './MeasureParser';
|
|
4
4
|
import {
|
|
@@ -25,6 +25,7 @@ export function parsePart(
|
|
|
25
25
|
? partInfo.name
|
|
26
26
|
: `${partInfo.name ?? partInfo.id} ${index + 1}`,
|
|
27
27
|
order: orderOffset + index,
|
|
28
|
+
clef: fallbackClef(orderOffset + index),
|
|
28
29
|
measures: [],
|
|
29
30
|
})
|
|
30
31
|
);
|
|
@@ -36,14 +37,16 @@ export function parsePart(
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
state.pendingGraceNotes.clear();
|
|
40
|
+
state.pendingDynamics.clear();
|
|
41
|
+
state.activeTies.clear();
|
|
39
42
|
|
|
40
43
|
const staves = builds.map(
|
|
41
44
|
(staff): Staff => ({
|
|
42
45
|
id: staff.id,
|
|
43
46
|
name: staff.name,
|
|
44
47
|
order: staff.order,
|
|
45
|
-
defaultClef:
|
|
46
|
-
|
|
48
|
+
defaultClef: staff.defaultClef ?? fallbackClef(staff.order),
|
|
49
|
+
lines: staff.lines,
|
|
47
50
|
measures: staff.measures,
|
|
48
51
|
})
|
|
49
52
|
);
|
|
@@ -64,6 +67,10 @@ export function parsePart(
|
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
69
|
|
|
70
|
+
function fallbackClef(order: number): Clef {
|
|
71
|
+
return order % 2 === 0 ? 'treble' : 'bass';
|
|
72
|
+
}
|
|
73
|
+
|
|
67
74
|
function getStaffCount(measure: XmlElement): number {
|
|
68
75
|
const attributes = optionalChild(measure, 'attributes');
|
|
69
76
|
const staves = attributes ? numberText(attributes, 'staves') : undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Pitch, TupletGroup } from '../../state';
|
|
1
|
+
import type { Pitch, TupletGroup, VoiceItem } from '../../state';
|
|
2
2
|
import type { ParserState } from './InternalTypes';
|
|
3
|
-
import { articulationsFromNotations
|
|
3
|
+
import { articulationsFromNotations } from './mappers';
|
|
4
4
|
import { MusicXmlParseError } from './types';
|
|
5
5
|
import {
|
|
6
6
|
attr,
|
|
@@ -78,20 +78,23 @@ export function applyNoteAttachments(
|
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
applyTies(note, itemId, voiceId, state);
|
|
82
81
|
applySlurs(notations, itemId, voiceId, state);
|
|
83
82
|
applyTuplets(note, notations, itemId, voiceId, state);
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Ties match by MusicXML voice name and pitch, so they cross barlines (each
|
|
87
|
+
* measure has its own `Voice`).
|
|
88
|
+
*/
|
|
89
|
+
export function applyTies(
|
|
87
90
|
note: XmlElement,
|
|
91
|
+
item: VoiceItem,
|
|
88
92
|
itemId: string,
|
|
89
|
-
|
|
93
|
+
voiceName: string,
|
|
90
94
|
state: ParserState
|
|
91
95
|
) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
pitch ? pitchKey(mapPitch(pitch, childText(note, 'accidental'))) : 'rest'
|
|
96
|
+
const tieKey = `${voiceName}:${
|
|
97
|
+
item.type === 'note' ? pitchKey(item.pitch) : 'rest'
|
|
95
98
|
}`;
|
|
96
99
|
|
|
97
100
|
childrenNamed(note, 'tie').forEach((tie) => {
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
Dynamic,
|
|
7
7
|
KeyMode,
|
|
8
8
|
KeySignature,
|
|
9
|
+
Notehead,
|
|
9
10
|
NoteLength,
|
|
10
11
|
Pitch,
|
|
11
12
|
Step,
|
|
@@ -144,17 +145,65 @@ export function mapDurationType(type: string): NoteLength {
|
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
export function mapPitch(pitch: XmlElement, accidental?: string): Pitch {
|
|
147
|
-
|
|
148
|
+
return {
|
|
149
|
+
...mapStaffPosition(pitch, 'step', 'octave'),
|
|
150
|
+
accidental: mapAccidental(childText(pitch, 'alter'), accidental),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Pitch on the middle staff line under each clef (VexFlow line positions). */
|
|
155
|
+
const MIDDLE_LINE_PITCHES: Record<Clef, Pitch> = {
|
|
156
|
+
'treble': { step: 'B', octave: 4 },
|
|
157
|
+
'bass': { step: 'D', octave: 3 },
|
|
158
|
+
'alto': { step: 'C', octave: 4 },
|
|
159
|
+
'tenor': { step: 'A', octave: 3 },
|
|
160
|
+
'soprano': { step: 'G', octave: 4 },
|
|
161
|
+
'mezzo-soprano': { step: 'E', octave: 4 },
|
|
162
|
+
'baritone-c': { step: 'F', octave: 3 },
|
|
163
|
+
'baritone-f': { step: 'F', octave: 3 },
|
|
164
|
+
'subbass': { step: 'B', octave: 2 },
|
|
165
|
+
'french': { step: 'D', octave: 5 },
|
|
166
|
+
'percussion': { step: 'B', octave: 4 },
|
|
167
|
+
'tab': { step: 'B', octave: 4 },
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* `<display-step>`/`<display-octave>` place the note under `clef`; without
|
|
172
|
+
* them it sits on the middle line.
|
|
173
|
+
*/
|
|
174
|
+
export function mapUnpitched(unpitched: XmlElement, clef: Clef): Pitch {
|
|
175
|
+
return hasChild(unpitched, 'display-step')
|
|
176
|
+
? mapStaffPosition(unpitched, 'display-step', 'display-octave')
|
|
177
|
+
: { ...MIDDLE_LINE_PITCHES[clef] };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function mapStaffPosition(
|
|
181
|
+
element: XmlElement,
|
|
182
|
+
stepName: string,
|
|
183
|
+
octaveName: string
|
|
184
|
+
): Pitch {
|
|
185
|
+
const step = requiredChildText(element, stepName);
|
|
148
186
|
|
|
149
187
|
if (!isStep(step)) {
|
|
150
188
|
throw new MusicXmlParseError(`Unsupported pitch step "${step}"`);
|
|
151
189
|
}
|
|
152
190
|
|
|
153
|
-
return {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
191
|
+
return { step, octave: Number(requiredChildText(element, octaveName)) };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const NOTEHEADS: Record<string, Notehead> = {
|
|
195
|
+
'x': 'x',
|
|
196
|
+
'circle-x': 'circle-x',
|
|
197
|
+
'diamond': 'diamond',
|
|
198
|
+
'circled': 'circle',
|
|
199
|
+
'square': 'square',
|
|
200
|
+
'triangle': 'triangle',
|
|
201
|
+
'inverted triangle': 'triangle-down',
|
|
202
|
+
'slash': 'slash',
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export function mapNotehead(value: string): Notehead | undefined {
|
|
206
|
+
return NOTEHEADS[value];
|
|
158
207
|
}
|
|
159
208
|
|
|
160
209
|
export function mapStemDirection(value?: string) {
|
|
@@ -11,6 +11,7 @@ import { getSystemGap } from './LayoutMetrics';
|
|
|
11
11
|
import {
|
|
12
12
|
resolveSystemVerticalLayout,
|
|
13
13
|
resolveUniformSystemVerticalLayout,
|
|
14
|
+
resolveVerseBaselines,
|
|
14
15
|
} from './VerticalSpacing';
|
|
15
16
|
|
|
16
17
|
type DocumentLine = {
|
|
@@ -41,13 +42,14 @@ export function resolveDocumentEvenMeasureWidth(
|
|
|
41
42
|
Math.floor(availableWidth / widestMeasure)
|
|
42
43
|
);
|
|
43
44
|
|
|
44
|
-
// A clef added at a system start
|
|
45
|
+
// A clef and key signature added at a system start have to fit the equal
|
|
46
|
+
// measure width too.
|
|
45
47
|
while (
|
|
46
48
|
measuresPerFullLine > 1 &&
|
|
47
49
|
measuredScore.measures.some(
|
|
48
50
|
(measure) =>
|
|
49
51
|
measure.measureIndex % measuresPerFullLine === 0 &&
|
|
50
|
-
measure.intrinsicNoteWidth + (measure.
|
|
52
|
+
measure.intrinsicNoteWidth + (measure.systemStartModifierWidth ?? 0) >
|
|
51
53
|
availableWidth / measuresPerFullLine
|
|
52
54
|
)
|
|
53
55
|
) {
|
|
@@ -112,6 +114,7 @@ export function layoutDocumentEvenGroup(
|
|
|
112
114
|
group.staves.length,
|
|
113
115
|
options.spacing.staffGap
|
|
114
116
|
);
|
|
117
|
+
const verseBaselines = resolveVerseBaselines(chunk, group.staves.length);
|
|
115
118
|
let cursorX = origin.x;
|
|
116
119
|
|
|
117
120
|
systems.push({
|
|
@@ -138,6 +141,7 @@ export function layoutDocumentEvenGroup(
|
|
|
138
141
|
width: equalMeasureWidth,
|
|
139
142
|
height: verticalLayout.height,
|
|
140
143
|
staffYOffsets: verticalLayout.staffYOffsets,
|
|
144
|
+
...(verseBaselines ? { verseBaselines } : {}),
|
|
141
145
|
systemIndex,
|
|
142
146
|
});
|
|
143
147
|
|
|
@@ -195,6 +199,10 @@ export function layoutDocumentGroup(
|
|
|
195
199
|
group.staves.length,
|
|
196
200
|
options.spacing.staffGap
|
|
197
201
|
);
|
|
202
|
+
const verseBaselines = resolveVerseBaselines(
|
|
203
|
+
line.measures,
|
|
204
|
+
group.staves.length
|
|
205
|
+
);
|
|
198
206
|
const systemX = origin.x + line.indent;
|
|
199
207
|
let cursorX = systemX;
|
|
200
208
|
|
|
@@ -224,6 +232,7 @@ export function layoutDocumentGroup(
|
|
|
224
232
|
width,
|
|
225
233
|
height: verticalLayout.height,
|
|
226
234
|
staffYOffsets: verticalLayout.staffYOffsets,
|
|
235
|
+
...(verseBaselines ? { verseBaselines } : {}),
|
|
227
236
|
systemIndex,
|
|
228
237
|
});
|
|
229
238
|
|
|
@@ -286,5 +295,5 @@ function getMeasureLineWidth(measure: MeasuredGroupMeasure): number {
|
|
|
286
295
|
}
|
|
287
296
|
|
|
288
297
|
function getSystemStartWidth(measure: MeasuredGroupMeasure): number {
|
|
289
|
-
return getMeasureLineWidth(measure) + (measure.
|
|
298
|
+
return getMeasureLineWidth(measure) + (measure.systemStartModifierWidth ?? 0);
|
|
290
299
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { layoutVerseLines, mergeVerseLines } from '../lyrics';
|
|
2
|
+
import type { VerseBaselines } from '../lyrics';
|
|
1
3
|
import type { StaffVerticalBounds } from '../measureBounds';
|
|
2
4
|
import type { MeasuredGroupMeasure } from '../layout';
|
|
3
5
|
import {
|
|
@@ -86,25 +88,56 @@ function shiftBelowOrigin(
|
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
/** Each staff's bounds over `measures`, its verse lines merged, not placed. */
|
|
92
|
+
function mergeStaffBounds(
|
|
90
93
|
measures: MeasuredGroupMeasure[],
|
|
91
94
|
staffCount: number
|
|
92
95
|
): StaffVerticalBounds[] {
|
|
93
|
-
return Array.from({ length: staffCount }, (_, staffIndex) =>
|
|
94
|
-
|
|
96
|
+
return Array.from({ length: staffCount }, (_, staffIndex) =>
|
|
97
|
+
measures
|
|
95
98
|
.map((measure) => measure.staffBounds[staffIndex])
|
|
96
99
|
.filter((staffBounds): staffBounds is StaffVerticalBounds =>
|
|
97
100
|
Boolean(staffBounds)
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
)
|
|
102
|
+
.reduce<StaffVerticalBounds>((merged, staffBounds) => {
|
|
103
|
+
const lyrics = mergeVerseLines(merged.lyrics, staffBounds.lyrics);
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
top: Math.min(merged.top, staffBounds.top),
|
|
107
|
+
bottom: Math.max(merged.bottom, staffBounds.bottom),
|
|
108
|
+
...(lyrics ? { lyrics } : {}),
|
|
109
|
+
};
|
|
110
|
+
}, defaultStaffBounds())
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Each staff's extent in a system, down to its last verse line. */
|
|
115
|
+
function resolveStaffBounds(
|
|
116
|
+
measures: MeasuredGroupMeasure[],
|
|
117
|
+
staffCount: number
|
|
118
|
+
): StaffVerticalBounds[] {
|
|
119
|
+
return mergeStaffBounds(measures, staffCount).map(
|
|
120
|
+
({ top, bottom, lyrics }) => ({
|
|
121
|
+
top,
|
|
122
|
+
bottom: lyrics ? layoutVerseLines(bottom, lyrics).bottom : bottom,
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Verse-line baselines of each staff in the system formed by `measures`, the
|
|
129
|
+
* lines level across the system; undefined when no staff has lyrics.
|
|
130
|
+
*/
|
|
131
|
+
export function resolveVerseBaselines(
|
|
132
|
+
measures: MeasuredGroupMeasure[],
|
|
133
|
+
staffCount: number
|
|
134
|
+
): Array<VerseBaselines | undefined> | undefined {
|
|
135
|
+
const baselines = mergeStaffBounds(measures, staffCount).map(
|
|
136
|
+
({ bottom, lyrics }) =>
|
|
137
|
+
lyrics ? layoutVerseLines(bottom, lyrics).baselines : undefined
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return baselines.some(Boolean) ? baselines : undefined;
|
|
108
141
|
}
|
|
109
142
|
|
|
110
143
|
function resolveRawStaffYOffsets(
|