vexflow-native 0.1.0 → 1.0.1
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 +286 -11
- package/lib/module/base/FontManager.js +139 -0
- package/lib/module/base/FontManager.js.map +1 -0
- package/lib/module/base/TextMeasureContext.js +46 -0
- package/lib/module/base/TextMeasureContext.js.map +1 -0
- package/lib/module/base/VexflowCanvas.js +48 -0
- package/lib/module/base/VexflowCanvas.js.map +1 -0
- package/lib/module/base/VexflowColorScheme.js +16 -0
- package/lib/module/base/VexflowColorScheme.js.map +1 -0
- package/lib/module/base/VexflowRecordingContext.js +425 -0
- package/lib/module/base/VexflowRecordingContext.js.map +1 -0
- package/lib/module/base/VexflowRecordingReplay.js +140 -0
- package/lib/module/base/VexflowRecordingReplay.js.map +1 -0
- package/lib/module/base/VexflowRecordingTypes.js +4 -0
- package/lib/module/base/VexflowRecordingTypes.js.map +1 -0
- package/lib/module/base/index.js +8 -0
- package/lib/module/base/index.js.map +1 -0
- package/lib/module/base/setupVexflowReactNative.js +96 -0
- package/lib/module/base/setupVexflowReactNative.js.map +1 -0
- package/lib/module/base/types.js +4 -0
- package/lib/module/base/types.js.map +1 -0
- package/lib/module/base/utils.js +18 -0
- package/lib/module/base/utils.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/InternalTypes.js +4 -0
- package/lib/module/musicxml/MusicXmlParser/InternalTypes.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js +269 -0
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js +62 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlTiming.js +124 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlTiming.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/PartParser.js +41 -0
- package/lib/module/musicxml/MusicXmlParser/PartParser.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/Spanners.js +149 -0
- package/lib/module/musicxml/MusicXmlParser/Spanners.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/XmlOrder.js +106 -0
- package/lib/module/musicxml/MusicXmlParser/XmlOrder.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/index.js +110 -0
- package/lib/module/musicxml/MusicXmlParser/index.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/mappers.js +312 -0
- package/lib/module/musicxml/MusicXmlParser/mappers.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/types.js +10 -0
- package/lib/module/musicxml/MusicXmlParser/types.js.map +1 -0
- package/lib/module/musicxml/index.js +4 -0
- package/lib/module/musicxml/index.js.map +1 -0
- package/lib/module/musicxml/testfiles/lg-8102429.xml +79620 -0
- package/lib/module/renderer/Layout/DocumentLayout.js +156 -0
- package/lib/module/renderer/Layout/DocumentLayout.js.map +1 -0
- package/lib/module/renderer/Layout/LayoutMetrics.js +13 -0
- package/lib/module/renderer/Layout/LayoutMetrics.js.map +1 -0
- package/lib/module/renderer/Layout/VerticalSpacing.js +69 -0
- package/lib/module/renderer/Layout/VerticalSpacing.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +232 -0
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js +108 -0
- package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/index.js +7 -0
- package/lib/module/renderer/ScoreRenderer/index.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/types.js +4 -0
- package/lib/module/renderer/ScoreRenderer/types.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/useScoreScroll.js +77 -0
- package/lib/module/renderer/ScoreRenderer/useScoreScroll.js.map +1 -0
- package/lib/module/renderer/colorScheme.js +17 -0
- package/lib/module/renderer/colorScheme.js.map +1 -0
- package/lib/module/renderer/constants.js +18 -0
- package/lib/module/renderer/constants.js.map +1 -0
- package/lib/module/renderer/index.js +6 -0
- package/lib/module/renderer/index.js.map +1 -0
- package/lib/module/renderer/layout.js +153 -0
- package/lib/module/renderer/layout.js.map +1 -0
- package/lib/module/renderer/measure.js +202 -0
- package/lib/module/renderer/measure.js.map +1 -0
- package/lib/module/renderer/render.js +163 -0
- package/lib/module/renderer/render.js.map +1 -0
- package/lib/module/renderer/scoreParsing.js +230 -0
- package/lib/module/renderer/scoreParsing.js.map +1 -0
- package/lib/module/renderer/types.js +4 -0
- package/lib/module/renderer/types.js.map +1 -0
- package/lib/module/renderer/useScoreRecording.js +112 -0
- package/lib/module/renderer/useScoreRecording.js.map +1 -0
- package/lib/module/renderer/viewport.js +26 -0
- package/lib/module/renderer/viewport.js.map +1 -0
- package/lib/module/shared/Logger.js +67 -0
- package/lib/module/shared/Logger.js.map +1 -0
- package/lib/module/state/index.js +4 -0
- package/lib/module/state/index.js.map +1 -0
- package/lib/module/state/types.js +2 -0
- package/lib/module/state/types.js.map +1 -0
- package/lib/module/types.js +7 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js +42 -77
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/src/base/FontManager.d.ts +23 -0
- package/lib/typescript/src/base/FontManager.d.ts.map +1 -0
- package/lib/typescript/src/base/TextMeasureContext.d.ts +22 -0
- package/lib/typescript/src/base/TextMeasureContext.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowCanvas.d.ts +5 -0
- package/lib/typescript/src/base/VexflowCanvas.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowColorScheme.d.ts +7 -0
- package/lib/typescript/src/base/VexflowColorScheme.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts +74 -0
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts +4 -0
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingTypes.d.ts +94 -0
- package/lib/typescript/src/base/VexflowRecordingTypes.d.ts.map +1 -0
- package/lib/typescript/src/base/index.d.ts +6 -0
- package/lib/typescript/src/base/index.d.ts.map +1 -0
- package/lib/typescript/src/base/setupVexflowReactNative.d.ts +11 -0
- package/lib/typescript/src/base/setupVexflowReactNative.d.ts.map +1 -0
- package/lib/typescript/src/base/types.d.ts +13 -0
- package/lib/typescript/src/base/types.d.ts.map +1 -0
- package/lib/typescript/src/base/utils.d.ts +2 -0
- package/lib/typescript/src/base/utils.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts +30 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts +4 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts +5 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlTiming.d.ts +6 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlTiming.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts +8 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts +4 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/XmlOrder.d.ts +20 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/XmlOrder.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/index.d.ts +5 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/index.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts +15 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/types.d.ts +13 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/types.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/index.d.ts +2 -0
- package/lib/typescript/src/musicxml/index.d.ts.map +1 -0
- package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts +10 -0
- package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts.map +1 -0
- package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts +6 -0
- package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts.map +1 -0
- package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts +9 -0
- package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts +14 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts +24 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/index.d.ts +5 -0
- package/lib/typescript/src/renderer/ScoreRenderer/index.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts +12 -0
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/useScoreScroll.d.ts +13 -0
- package/lib/typescript/src/renderer/ScoreRenderer/useScoreScroll.d.ts.map +1 -0
- package/lib/typescript/src/renderer/colorScheme.d.ts +9 -0
- package/lib/typescript/src/renderer/colorScheme.d.ts.map +1 -0
- package/lib/typescript/src/renderer/constants.d.ts +5 -0
- package/lib/typescript/src/renderer/constants.d.ts.map +1 -0
- package/lib/typescript/src/renderer/index.d.ts +4 -0
- package/lib/typescript/src/renderer/index.d.ts.map +1 -0
- package/lib/typescript/src/renderer/layout.d.ts +56 -0
- package/lib/typescript/src/renderer/layout.d.ts.map +1 -0
- package/lib/typescript/src/renderer/measure.d.ts +23 -0
- package/lib/typescript/src/renderer/measure.d.ts.map +1 -0
- package/lib/typescript/src/renderer/render.d.ts +9 -0
- package/lib/typescript/src/renderer/render.d.ts.map +1 -0
- package/lib/typescript/src/renderer/scoreParsing.d.ts +76 -0
- package/lib/typescript/src/renderer/scoreParsing.d.ts.map +1 -0
- package/lib/typescript/src/renderer/types.d.ts +51 -0
- package/lib/typescript/src/renderer/types.d.ts.map +1 -0
- package/lib/typescript/src/renderer/useScoreRecording.d.ts +21 -0
- package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -0
- package/lib/typescript/src/renderer/viewport.d.ts +3 -0
- package/lib/typescript/src/renderer/viewport.d.ts.map +1 -0
- package/lib/typescript/src/shared/Logger.d.ts +18 -0
- package/lib/typescript/src/shared/Logger.d.ts.map +1 -0
- package/lib/typescript/src/state/index.d.ts +2 -0
- package/lib/typescript/src/state/index.d.ts.map +1 -0
- package/lib/typescript/src/state/types.d.ts +190 -0
- package/lib/typescript/src/state/types.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +0 -6
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +0 -6
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/package.json +41 -13
- package/src/base/FontManager.ts +206 -0
- package/src/base/TextMeasureContext.ts +59 -0
- package/src/base/VexflowCanvas.tsx +60 -0
- package/src/base/VexflowColorScheme.ts +32 -0
- package/src/base/VexflowRecordingContext.ts +495 -0
- package/src/base/VexflowRecordingReplay.ts +211 -0
- package/src/base/VexflowRecordingTypes.ts +117 -0
- package/src/base/index.ts +6 -0
- package/src/base/setupVexflowReactNative.ts +124 -0
- package/src/base/types.ts +17 -0
- package/src/base/utils.ts +21 -0
- package/src/musicxml/MusicXmlParser/InternalTypes.ts +41 -0
- package/src/musicxml/MusicXmlParser/MeasureParser.ts +469 -0
- package/src/musicxml/MusicXmlParser/MusicXmlDirections.ts +84 -0
- package/src/musicxml/MusicXmlParser/MusicXmlTiming.ts +153 -0
- package/src/musicxml/MusicXmlParser/PartParser.ts +69 -0
- package/src/musicxml/MusicXmlParser/Spanners.ts +215 -0
- package/src/musicxml/MusicXmlParser/XmlOrder.ts +170 -0
- package/src/musicxml/MusicXmlParser/index.ts +144 -0
- package/src/musicxml/MusicXmlParser/mappers.ts +307 -0
- package/src/musicxml/MusicXmlParser/types.ts +24 -0
- package/src/musicxml/index.ts +5 -0
- package/src/musicxml/testfiles/lg-8102429.xml +79620 -0
- package/src/renderer/Layout/DocumentLayout.ts +240 -0
- package/src/renderer/Layout/LayoutMetrics.ts +21 -0
- package/src/renderer/Layout/VerticalSpacing.ts +122 -0
- package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +310 -0
- package/src/renderer/ScoreRenderer/ScoreScrollbar.tsx +231 -0
- package/src/renderer/ScoreRenderer/index.ts +13 -0
- package/src/renderer/ScoreRenderer/types.ts +14 -0
- package/src/renderer/ScoreRenderer/useScoreScroll.ts +146 -0
- package/src/renderer/colorScheme.ts +28 -0
- package/src/renderer/constants.ts +19 -0
- package/src/renderer/index.ts +3 -0
- package/src/renderer/layout.ts +309 -0
- package/src/renderer/measure.tsx +304 -0
- package/src/renderer/render.tsx +281 -0
- package/src/renderer/scoreParsing.tsx +352 -0
- package/src/renderer/types.ts +60 -0
- package/src/renderer/useScoreRecording.ts +177 -0
- package/src/renderer/viewport.ts +45 -0
- package/src/shared/Logger.ts +85 -0
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +295 -0
- package/src/types.ts +6 -6
- package/src/utils.tsx +32 -98
- package/lib/module/SkiaVexflowContext.js +0 -285
- package/lib/module/SkiaVexflowContext.js.map +0 -1
- package/lib/module/VexflowCanvas.js +0 -101
- package/lib/module/VexflowCanvas.js.map +0 -1
- package/lib/module/colorUtils.js +0 -34
- package/lib/module/colorUtils.js.map +0 -1
- package/lib/module/colorUtils.test.js +0 -37
- package/lib/module/colorUtils.test.js.map +0 -1
- package/lib/module/constants.js +0 -30
- package/lib/module/constants.js.map +0 -1
- package/lib/module/index.js +0 -8
- package/lib/module/index.js.map +0 -1
- package/lib/typescript/src/SkiaVexflowContext.d.ts +0 -101
- package/lib/typescript/src/SkiaVexflowContext.d.ts.map +0 -1
- package/lib/typescript/src/VexflowCanvas.d.ts +0 -15
- package/lib/typescript/src/VexflowCanvas.d.ts.map +0 -1
- package/lib/typescript/src/colorUtils.d.ts +0 -2
- package/lib/typescript/src/colorUtils.d.ts.map +0 -1
- package/lib/typescript/src/colorUtils.test.d.ts +0 -2
- package/lib/typescript/src/colorUtils.test.d.ts.map +0 -1
- package/lib/typescript/src/constants.d.ts +0 -21
- package/lib/typescript/src/constants.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -7
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/src/SkiaVexflowContext.ts +0 -462
- package/src/VexflowCanvas.tsx +0 -140
- package/src/colorUtils.test.ts +0 -52
- package/src/colorUtils.ts +0 -55
- package/src/constants.tsx +0 -34
- package/src/index.ts +0 -8
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { Formatter, Stave, StaveConnector, Voice as VFVoice } from 'vexflow';
|
|
2
|
+
import type { StaveConnectorType } from 'vexflow';
|
|
3
|
+
|
|
4
|
+
import type { VexflowRecordingContext } from '../base';
|
|
5
|
+
import type { Score, StaffGroupSymbol, VoiceItem } from '../state';
|
|
6
|
+
import type {
|
|
7
|
+
GroupLayoutContext,
|
|
8
|
+
MeasureLayoutPlan,
|
|
9
|
+
ScoreLayoutPlan,
|
|
10
|
+
} from './layout';
|
|
11
|
+
import { makeVFVoice } from './scoreParsing';
|
|
12
|
+
import type { ScoreOptions } from './types';
|
|
13
|
+
import type { VFVoiceNote } from './scoreParsing';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Renders the score from a precomputed layout plan.
|
|
17
|
+
*/
|
|
18
|
+
export function renderScore(
|
|
19
|
+
ctx: VexflowRecordingContext,
|
|
20
|
+
score: Score,
|
|
21
|
+
layoutPlan: ScoreLayoutPlan,
|
|
22
|
+
_options: ScoreOptions
|
|
23
|
+
) {
|
|
24
|
+
const groupsById = new Map(
|
|
25
|
+
layoutPlan.groups.map((group) => [group.groupId, group])
|
|
26
|
+
);
|
|
27
|
+
const measuresByGroup = groupMeasuresByIndex(layoutPlan.measures);
|
|
28
|
+
|
|
29
|
+
for (const system of layoutPlan.systems) {
|
|
30
|
+
const group = groupsById.get(system.groupId);
|
|
31
|
+
|
|
32
|
+
if (!group || group.staves.length === 0) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const measurePlans = system.measureIndices
|
|
37
|
+
.map((measureIndex) =>
|
|
38
|
+
measuresByGroup.get(system.groupId)?.get(measureIndex)
|
|
39
|
+
)
|
|
40
|
+
.filter((measure): measure is MeasureLayoutPlan => Boolean(measure));
|
|
41
|
+
|
|
42
|
+
for (const [measureIndex, measurePlan] of measurePlans.entries()) {
|
|
43
|
+
renderMeasure(ctx, score, group, measurePlan, {
|
|
44
|
+
isFirstMeasureInSystem: measureIndex === 0,
|
|
45
|
+
isLastMeasureInSystem: measureIndex === measurePlans.length - 1,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type StaffRenderArtifacts = {
|
|
52
|
+
beams: Array<{
|
|
53
|
+
setContext: (ctx: VexflowRecordingContext) => { draw: () => void };
|
|
54
|
+
}>;
|
|
55
|
+
voiceArtifacts: Array<{
|
|
56
|
+
items: VoiceItem[];
|
|
57
|
+
notes: VFVoiceNote[];
|
|
58
|
+
ownerStaffId: string;
|
|
59
|
+
}>;
|
|
60
|
+
tuplets: Array<{
|
|
61
|
+
setContext: (ctx: VexflowRecordingContext) => { draw: () => void };
|
|
62
|
+
}>;
|
|
63
|
+
vfVoices: VFVoice[];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
interface RenderMeasureOptions {
|
|
67
|
+
isFirstMeasureInSystem: boolean;
|
|
68
|
+
isLastMeasureInSystem: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function renderMeasure(
|
|
72
|
+
ctx: VexflowRecordingContext,
|
|
73
|
+
score: Score,
|
|
74
|
+
group: GroupLayoutContext,
|
|
75
|
+
measurePlan: MeasureLayoutPlan,
|
|
76
|
+
options: RenderMeasureOptions
|
|
77
|
+
) {
|
|
78
|
+
const formatter = new Formatter();
|
|
79
|
+
const resolvedStateByStaffId = new Map(
|
|
80
|
+
group.staves.map((staff, staffIndex) => [
|
|
81
|
+
staff.id,
|
|
82
|
+
group.resolvedStatesByStaff[staffIndex]?.[measurePlan.measureIndex],
|
|
83
|
+
])
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const staffRenderArtifacts: StaffRenderArtifacts[] = group.staves.map(
|
|
87
|
+
(staff, staffIndex) => {
|
|
88
|
+
const measure = staff.measures[measurePlan.measureIndex];
|
|
89
|
+
const resolvedState =
|
|
90
|
+
group.resolvedStatesByStaff[staffIndex]?.[measurePlan.measureIndex];
|
|
91
|
+
|
|
92
|
+
if (!measure || !resolvedState) {
|
|
93
|
+
return { vfVoices: [], voiceArtifacts: [], beams: [], tuplets: [] };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const voiceArtifacts = measure.voices.map((voice) => ({
|
|
97
|
+
...makeVFVoice(score, resolvedState.meter, resolvedState.clef, voice, {
|
|
98
|
+
resolveClef: (item) =>
|
|
99
|
+
item.targetStaffId
|
|
100
|
+
? resolvedStateByStaffId.get(item.targetStaffId)?.clef ??
|
|
101
|
+
resolvedState.clef
|
|
102
|
+
: resolvedState.clef,
|
|
103
|
+
}),
|
|
104
|
+
items: voice.items,
|
|
105
|
+
ownerStaffId: staff.id,
|
|
106
|
+
}));
|
|
107
|
+
const vfVoices = voiceArtifacts.map(({ vfVoice }) => vfVoice);
|
|
108
|
+
|
|
109
|
+
if (vfVoices.length > 1) {
|
|
110
|
+
formatter.joinVoices(vfVoices);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
vfVoices,
|
|
115
|
+
voiceArtifacts: voiceArtifacts.map(
|
|
116
|
+
({ items, notes, ownerStaffId }) => ({
|
|
117
|
+
notes,
|
|
118
|
+
items,
|
|
119
|
+
ownerStaffId,
|
|
120
|
+
})
|
|
121
|
+
),
|
|
122
|
+
beams: voiceArtifacts.flatMap(({ beams }) => beams),
|
|
123
|
+
tuplets: voiceArtifacts.flatMap(({ tuplets }) => tuplets),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const allVoices = staffRenderArtifacts.flatMap(({ vfVoices }) => vfVoices);
|
|
129
|
+
|
|
130
|
+
const renderedStaves = group.staves.map((staff, staffIndex) => {
|
|
131
|
+
const measure = staff.measures[measurePlan.measureIndex]!;
|
|
132
|
+
const resolvedState =
|
|
133
|
+
group.resolvedStatesByStaff[staffIndex]![measurePlan.measureIndex]!;
|
|
134
|
+
const stave = new Stave(
|
|
135
|
+
measurePlan.x,
|
|
136
|
+
measurePlan.y + (measurePlan.staffYOffsets[staffIndex] ?? 0),
|
|
137
|
+
measurePlan.width
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
if (measurePlan.measureIndex === 0 || measure.leftModifiers?.showClef) {
|
|
141
|
+
stave.addClef(resolvedState.clef);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
stave.setContext(ctx).draw();
|
|
145
|
+
return stave;
|
|
146
|
+
});
|
|
147
|
+
const renderedStaveByStaffId = new Map(
|
|
148
|
+
group.staves.map((staff, staffIndex) => [
|
|
149
|
+
staff.id,
|
|
150
|
+
renderedStaves[staffIndex],
|
|
151
|
+
])
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
renderStaffConnectors(ctx, group, renderedStaves, options);
|
|
155
|
+
|
|
156
|
+
staffRenderArtifacts.forEach(({ voiceArtifacts }) => {
|
|
157
|
+
voiceArtifacts.forEach(({ items, notes, ownerStaffId }) => {
|
|
158
|
+
items.forEach((item, index) => {
|
|
159
|
+
const targetStave =
|
|
160
|
+
renderedStaveByStaffId.get(item.targetStaffId ?? ownerStaffId) ??
|
|
161
|
+
renderedStaveByStaffId.get(ownerStaffId);
|
|
162
|
+
|
|
163
|
+
if (targetStave) {
|
|
164
|
+
notes[index]?.setStave(targetStave);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (allVoices.length > 0) {
|
|
171
|
+
formatter.formatToStave(allVoices, renderedStaves[0]!);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
staffRenderArtifacts.forEach(({ vfVoices, beams, tuplets }) => {
|
|
175
|
+
vfVoices.forEach((voice) => voice.draw(ctx));
|
|
176
|
+
beams.forEach((beam) => beam.setContext(ctx).draw());
|
|
177
|
+
tuplets.forEach((tuplet) => tuplet.setContext(ctx).draw());
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function renderStaffConnectors(
|
|
182
|
+
ctx: VexflowRecordingContext,
|
|
183
|
+
group: GroupLayoutContext,
|
|
184
|
+
renderedStaves: Stave[],
|
|
185
|
+
options: RenderMeasureOptions
|
|
186
|
+
) {
|
|
187
|
+
if (!group.staffGroup || renderedStaves.length < 2) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const topStave = renderedStaves[0];
|
|
192
|
+
const bottomStave = renderedStaves[renderedStaves.length - 1];
|
|
193
|
+
|
|
194
|
+
if (!topStave || !bottomStave) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const connectorSymbol = resolveStaffGroupConnectorSymbol(group);
|
|
199
|
+
|
|
200
|
+
if (options.isFirstMeasureInSystem && connectorSymbol) {
|
|
201
|
+
drawStaveConnector(
|
|
202
|
+
ctx,
|
|
203
|
+
topStave,
|
|
204
|
+
bottomStave,
|
|
205
|
+
connectorSymbolToVFType(connectorSymbol)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
drawStaveConnector(
|
|
210
|
+
ctx,
|
|
211
|
+
topStave,
|
|
212
|
+
bottomStave,
|
|
213
|
+
requireStaveConnectorType(StaveConnector.type.SINGLE_LEFT)
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
if (options.isLastMeasureInSystem) {
|
|
217
|
+
drawStaveConnector(
|
|
218
|
+
ctx,
|
|
219
|
+
topStave,
|
|
220
|
+
bottomStave,
|
|
221
|
+
requireStaveConnectorType(StaveConnector.type.SINGLE_RIGHT)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function resolveStaffGroupConnectorSymbol(
|
|
227
|
+
group: GroupLayoutContext
|
|
228
|
+
): Exclude<StaffGroupSymbol, 'line'> | undefined {
|
|
229
|
+
if (group.staffGroup?.symbol === 'line') {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (group.staffGroup?.symbol) {
|
|
234
|
+
return group.staffGroup.symbol;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return group.staffGroup?.role === 'grandStaff' ? 'brace' : 'bracket';
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function connectorSymbolToVFType(symbol: Exclude<StaffGroupSymbol, 'line'>) {
|
|
241
|
+
return symbol === 'brace'
|
|
242
|
+
? requireStaveConnectorType(StaveConnector.type.BRACE)
|
|
243
|
+
: requireStaveConnectorType(StaveConnector.type.BRACKET);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function drawStaveConnector(
|
|
247
|
+
ctx: VexflowRecordingContext,
|
|
248
|
+
topStave: Stave,
|
|
249
|
+
bottomStave: Stave,
|
|
250
|
+
type: StaveConnectorType
|
|
251
|
+
) {
|
|
252
|
+
new StaveConnector(topStave, bottomStave)
|
|
253
|
+
.setType(type)
|
|
254
|
+
.setContext(ctx)
|
|
255
|
+
.draw();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function requireStaveConnectorType(
|
|
259
|
+
type: Exclude<StaveConnectorType, string> | undefined
|
|
260
|
+
): StaveConnectorType {
|
|
261
|
+
if (typeof type !== 'number') {
|
|
262
|
+
throw new Error('Expected VexFlow StaveConnector type constant');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return type;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function groupMeasuresByIndex(measures: MeasureLayoutPlan[]) {
|
|
269
|
+
const measuresByGroup = new Map<string, Map<number, MeasureLayoutPlan>>();
|
|
270
|
+
|
|
271
|
+
for (const measure of measures) {
|
|
272
|
+
const groupMeasures =
|
|
273
|
+
measuresByGroup.get(measure.groupId) ??
|
|
274
|
+
new Map<number, MeasureLayoutPlan>();
|
|
275
|
+
|
|
276
|
+
groupMeasures.set(measure.measureIndex, measure);
|
|
277
|
+
measuresByGroup.set(measure.groupId, groupMeasures);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return measuresByGroup;
|
|
281
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Accidental as VFAccidental,
|
|
3
|
+
Beam,
|
|
4
|
+
Dot,
|
|
5
|
+
Fraction as VFFraction,
|
|
6
|
+
GhostNote,
|
|
7
|
+
StaveNote,
|
|
8
|
+
Stem,
|
|
9
|
+
Tuplet,
|
|
10
|
+
Voice as VFVoice,
|
|
11
|
+
} from 'vexflow';
|
|
12
|
+
import type { StemmableNote } from 'vexflow';
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
Clef,
|
|
16
|
+
KeySignature,
|
|
17
|
+
DurationValue,
|
|
18
|
+
Meter,
|
|
19
|
+
Pitch,
|
|
20
|
+
Score,
|
|
21
|
+
Staff,
|
|
22
|
+
StaffGroup,
|
|
23
|
+
StemDirection,
|
|
24
|
+
Tempo,
|
|
25
|
+
TupletGroup,
|
|
26
|
+
Voice,
|
|
27
|
+
VoiceItem,
|
|
28
|
+
VoiceTimingMode,
|
|
29
|
+
} from '../state';
|
|
30
|
+
|
|
31
|
+
export type StaffGroupLookup = {
|
|
32
|
+
groupId: string;
|
|
33
|
+
staffGroup?: StaffGroup;
|
|
34
|
+
staffIds: string[];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export interface ResolvedMeasureState {
|
|
38
|
+
clef: Clef;
|
|
39
|
+
meter: Meter;
|
|
40
|
+
keySignature?: KeySignature;
|
|
41
|
+
tempo?: Tempo;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type VFVoiceNote = StemmableNote;
|
|
45
|
+
|
|
46
|
+
export interface MakeVFVoiceOptions {
|
|
47
|
+
resolveClef?: (item: VoiceItem) => Clef;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Maps the library stem direction to the numeric VexFlow value.
|
|
52
|
+
*/
|
|
53
|
+
export function toVFStemDirection(dir?: StemDirection): number | undefined {
|
|
54
|
+
if (dir === 'up') {
|
|
55
|
+
return Stem.UP;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (dir === 'down') {
|
|
59
|
+
return Stem.DOWN;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Converts an internal pitch into the VexFlow key string format.
|
|
67
|
+
*/
|
|
68
|
+
export function pitchToVFKey(pitch: Pitch): string {
|
|
69
|
+
const accidental =
|
|
70
|
+
pitch.accidental === 'quarter-flat'
|
|
71
|
+
? 'db'
|
|
72
|
+
: pitch.accidental === 'quarter-sharp'
|
|
73
|
+
? 'd#'
|
|
74
|
+
: pitch.accidental ?? '';
|
|
75
|
+
|
|
76
|
+
return `${pitch.step.toLowerCase()}${accidental}/${pitch.octave}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Converts a duration into the VexFlow duration token, including rests.
|
|
81
|
+
*/
|
|
82
|
+
export function durationToVF(duration: DurationValue, isRest = false): string {
|
|
83
|
+
const length =
|
|
84
|
+
duration.length === 'long' || duration.length === 'breve'
|
|
85
|
+
? '1/2'
|
|
86
|
+
: duration.length;
|
|
87
|
+
|
|
88
|
+
if (isRest) {
|
|
89
|
+
return `${length}r`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (duration.dots) {
|
|
93
|
+
return `${length}${'d'.repeat(duration.dots)}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return length;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Applies the requested number of augmentation dots to a note.
|
|
101
|
+
*/
|
|
102
|
+
export function applyDots(note: StaveNote, dots?: 0 | 1 | 2 | 3) {
|
|
103
|
+
for (let i = 0; i < (dots ?? 0); i++) {
|
|
104
|
+
Dot.buildAndAttach([note], { all: true });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Adds pitch accidentals to the matching keys in a VexFlow note.
|
|
110
|
+
*/
|
|
111
|
+
export function addPitchAccidentals(note: StaveNote, pitches: Pitch[]) {
|
|
112
|
+
pitches.forEach((pitch, index) => {
|
|
113
|
+
if (!pitch.accidental) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const type =
|
|
118
|
+
pitch.accidental === 'quarter-flat'
|
|
119
|
+
? 'db'
|
|
120
|
+
: pitch.accidental === 'quarter-sharp'
|
|
121
|
+
? 'd#'
|
|
122
|
+
: pitch.accidental;
|
|
123
|
+
|
|
124
|
+
note.addModifier(new VFAccidental(type), index);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Builds a VexFlow stave note from a score voice item and clef.
|
|
130
|
+
*/
|
|
131
|
+
export function voiceItemToStaveNote(item: VoiceItem, clef: Clef): VFVoiceNote {
|
|
132
|
+
if (item.type === 'rest') {
|
|
133
|
+
if (item.kind === 'hidden' || item.kind === 'spacer') {
|
|
134
|
+
return new GhostNote(durationToVF(item.duration));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const note = new StaveNote({
|
|
138
|
+
clef,
|
|
139
|
+
keys: ['b/4'],
|
|
140
|
+
duration: durationToVF(item.duration, true),
|
|
141
|
+
});
|
|
142
|
+
applyDots(note, item.duration.dots);
|
|
143
|
+
return note;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (item.type === 'note') {
|
|
147
|
+
const note = new StaveNote({
|
|
148
|
+
clef,
|
|
149
|
+
keys: [pitchToVFKey(item.pitch)],
|
|
150
|
+
duration: durationToVF(item.duration),
|
|
151
|
+
stemDirection: toVFStemDirection(item.stemDirection),
|
|
152
|
+
});
|
|
153
|
+
addPitchAccidentals(note, [item.pitch]);
|
|
154
|
+
applyDots(note, item.duration.dots);
|
|
155
|
+
return note;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const note = new StaveNote({
|
|
159
|
+
clef,
|
|
160
|
+
keys: item.pitches.map(pitchToVFKey),
|
|
161
|
+
duration: durationToVF(item.duration),
|
|
162
|
+
stemDirection: toVFStemDirection(item.stemDirection),
|
|
163
|
+
});
|
|
164
|
+
addPitchAccidentals(note, item.pitches);
|
|
165
|
+
applyDots(note, item.duration.dots);
|
|
166
|
+
return note;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Translates beam group fractions into the VexFlow representation.
|
|
171
|
+
*/
|
|
172
|
+
export function beamGroupsToVF(meter?: Meter): VFFraction[] | undefined {
|
|
173
|
+
if (!meter?.beamGroups?.length) {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return meter.beamGroups.map((group) => new VFFraction(group.num, group.den));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function hasExplicitStemDirection(item: VoiceItem): boolean {
|
|
181
|
+
return (
|
|
182
|
+
item.type !== 'rest' &&
|
|
183
|
+
(item.stemDirection === 'up' || item.stemDirection === 'down')
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Finds the tuplet groups that belong to a given voice.
|
|
189
|
+
*/
|
|
190
|
+
export function findTupletsForVoice(score: Score, voice: Voice): TupletGroup[] {
|
|
191
|
+
return (score.tuplets ?? []).filter((tuplet) => tuplet.voiceId === voice.id);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Maps the internal timing mode to the matching VexFlow voice mode.
|
|
196
|
+
*/
|
|
197
|
+
export function modeToVF(mode: VoiceTimingMode): number {
|
|
198
|
+
switch (mode) {
|
|
199
|
+
case 'soft':
|
|
200
|
+
return VFVoice.Mode.SOFT;
|
|
201
|
+
case 'free':
|
|
202
|
+
return VFVoice.Mode.FULL;
|
|
203
|
+
case 'strict':
|
|
204
|
+
default:
|
|
205
|
+
return VFVoice.Mode.STRICT;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Resolves each measure state by carrying forward prior staff state.
|
|
211
|
+
*/
|
|
212
|
+
export function buildResolvedMeasureStates(
|
|
213
|
+
score: Score,
|
|
214
|
+
staff: Staff
|
|
215
|
+
): ResolvedMeasureState[] {
|
|
216
|
+
let previousState: ResolvedMeasureState | undefined;
|
|
217
|
+
|
|
218
|
+
return staff.measures.map((measure) => {
|
|
219
|
+
const resolvedState: ResolvedMeasureState = {
|
|
220
|
+
clef: measure.state?.clef ?? previousState?.clef ?? staff.defaultClef,
|
|
221
|
+
meter:
|
|
222
|
+
measure.state?.meter ?? previousState?.meter ?? score.defaults.meter,
|
|
223
|
+
keySignature:
|
|
224
|
+
measure.state?.keySignature ??
|
|
225
|
+
previousState?.keySignature ??
|
|
226
|
+
score.defaults.keySignature,
|
|
227
|
+
tempo:
|
|
228
|
+
measure.state?.tempo ?? previousState?.tempo ?? score.defaults.tempo,
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
previousState = resolvedState;
|
|
232
|
+
return resolvedState;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Builds the VexFlow voice, notes, beams, and tuplets for one score voice.
|
|
238
|
+
*/
|
|
239
|
+
export function makeVFVoice(
|
|
240
|
+
score: Score,
|
|
241
|
+
meter: Meter,
|
|
242
|
+
clef: Clef,
|
|
243
|
+
voice: Voice,
|
|
244
|
+
options: MakeVFVoiceOptions = {}
|
|
245
|
+
): {
|
|
246
|
+
vfVoice: VFVoice;
|
|
247
|
+
notes: VFVoiceNote[];
|
|
248
|
+
beams: Beam[];
|
|
249
|
+
tuplets: Tuplet[];
|
|
250
|
+
} {
|
|
251
|
+
const notes = voice.items.map((item) =>
|
|
252
|
+
voiceItemToStaveNote(item, options.resolveClef?.(item) ?? clef)
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
const noteByItemId = new Map<string, VFVoiceNote>();
|
|
256
|
+
voice.items.forEach((item, index) =>
|
|
257
|
+
noteByItemId.set(item.id, notes[index]!)
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const vfVoice = new VFVoice({
|
|
261
|
+
numBeats: meter.beats,
|
|
262
|
+
beatValue: meter.beatUnit,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
if (voice.timingMode) {
|
|
266
|
+
vfVoice.setMode(modeToVF(voice.timingMode));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
try {
|
|
270
|
+
vfVoice.addTickables(notes);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`Error adding tickables to voice ${voice.id}: ${(error as Error).message}`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const groups = beamGroupsToVF(meter);
|
|
278
|
+
const maintainStemDirections = voice.items.some(hasExplicitStemDirection);
|
|
279
|
+
const beamOptions =
|
|
280
|
+
groups || maintainStemDirections
|
|
281
|
+
? {
|
|
282
|
+
...(groups ? { groups } : {}),
|
|
283
|
+
...(maintainStemDirections ? { maintainStemDirections } : {}),
|
|
284
|
+
}
|
|
285
|
+
: undefined;
|
|
286
|
+
const beams = Beam.generateBeams(notes, beamOptions);
|
|
287
|
+
|
|
288
|
+
const tuplets = findTupletsForVoice(score, voice)
|
|
289
|
+
.map((group) => {
|
|
290
|
+
const tupletNotes = group.itemIds
|
|
291
|
+
.map((id) => noteByItemId.get(id))
|
|
292
|
+
.filter((note): note is StaveNote => Boolean(note));
|
|
293
|
+
|
|
294
|
+
if (tupletNotes.length < 2) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return new Tuplet(tupletNotes, {
|
|
299
|
+
numNotes: group.ratio.num,
|
|
300
|
+
notesOccupied: group.ratio.den,
|
|
301
|
+
bracketed: group.bracketed,
|
|
302
|
+
location:
|
|
303
|
+
group.placement === 'below'
|
|
304
|
+
? Tuplet.LOCATION_BOTTOM
|
|
305
|
+
: Tuplet.LOCATION_TOP,
|
|
306
|
+
});
|
|
307
|
+
})
|
|
308
|
+
.filter((tuplet): tuplet is Tuplet => Boolean(tuplet));
|
|
309
|
+
|
|
310
|
+
return { vfVoice, notes, beams, tuplets };
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Resolves explicit staff groups and standalone staves into render groups.
|
|
315
|
+
*/
|
|
316
|
+
export function buildMeasurementGroups(score: Score): StaffGroupLookup[] {
|
|
317
|
+
const explicitGroups = (score.staffGroups ?? []).map((group) => ({
|
|
318
|
+
groupId: group.id,
|
|
319
|
+
staffGroup: group,
|
|
320
|
+
staffIds: [...(group.staffIds ?? [])].sort((staffIdA, staffIdB) => {
|
|
321
|
+
const staffA = score.staves.find((staff) => staff.id === staffIdA);
|
|
322
|
+
const staffB = score.staves.find((staff) => staff.id === staffIdB);
|
|
323
|
+
return (staffA?.order ?? 0) - (staffB?.order ?? 0);
|
|
324
|
+
}),
|
|
325
|
+
}));
|
|
326
|
+
|
|
327
|
+
const groupedStaffIds = new Set(
|
|
328
|
+
explicitGroups.flatMap((group) => group.staffIds)
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
const singles = score.staves
|
|
332
|
+
.filter((staff) => !groupedStaffIds.has(staff.id))
|
|
333
|
+
.sort((staffA, staffB) => staffA.order - staffB.order)
|
|
334
|
+
.map((staff) => ({
|
|
335
|
+
groupId: `staff:${staff.id}`,
|
|
336
|
+
staffIds: [staff.id],
|
|
337
|
+
}));
|
|
338
|
+
|
|
339
|
+
return [...explicitGroups, ...singles];
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Resolves a staff group lookup into the existing ordered score staves.
|
|
344
|
+
*/
|
|
345
|
+
export function resolveGroupStaves(
|
|
346
|
+
score: Score,
|
|
347
|
+
group: StaffGroupLookup
|
|
348
|
+
): Staff[] {
|
|
349
|
+
return group.staffIds
|
|
350
|
+
.map((id) => score.staves.find((staff) => staff.id === id))
|
|
351
|
+
.filter((staff): staff is Staff => Boolean(staff));
|
|
352
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { SkTypefaceFontProvider } from '@shopify/react-native-skia';
|
|
2
|
+
|
|
3
|
+
import type { Score } from '../state';
|
|
4
|
+
import type { ScoreColorScheme } from './colorScheme';
|
|
5
|
+
|
|
6
|
+
export type RendererType = 'infiniteScore' | 'document' | 'documentEven';
|
|
7
|
+
|
|
8
|
+
export interface ScoreRendererProps {
|
|
9
|
+
score: Score;
|
|
10
|
+
defaultFont: string;
|
|
11
|
+
fontManager: SkTypefaceFontProvider;
|
|
12
|
+
colorScheme?: ScoreColorScheme;
|
|
13
|
+
rendererType?: RendererType;
|
|
14
|
+
options?: Partial<ScoreOptions>;
|
|
15
|
+
scrollEnabled?: boolean;
|
|
16
|
+
showScrollbars?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Viewport {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ScoreInsets {
|
|
25
|
+
top: number;
|
|
26
|
+
right: number;
|
|
27
|
+
bottom: number;
|
|
28
|
+
left: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ScoreSpacing {
|
|
32
|
+
staffGap: number;
|
|
33
|
+
minIntrinsicSizeMultiplier: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface RenderOptions {
|
|
37
|
+
pixelRatio: number;
|
|
38
|
+
scale: number;
|
|
39
|
+
debug: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ScoreOptions {
|
|
43
|
+
spacing: ScoreSpacing;
|
|
44
|
+
insets: ScoreInsets;
|
|
45
|
+
render: RenderOptions;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface RendererPoint {
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface RendererSize {
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface RendererRect extends RendererPoint, RendererSize {}
|
|
59
|
+
|
|
60
|
+
export interface VisibleViewport extends RendererRect {}
|