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,177 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { SkTypefaceFontProvider } from '@shopify/react-native-skia';
|
|
3
|
+
|
|
4
|
+
import type { VexflowRecordingCommand } from '../base';
|
|
5
|
+
import VexflowRecordingContext from '../base/VexflowRecordingContext';
|
|
6
|
+
import type { Score } from '../state';
|
|
7
|
+
import { layoutScore, type ScoreLayoutPlan } from './layout';
|
|
8
|
+
import { measureScore } from './measure';
|
|
9
|
+
import { renderScore } from './render';
|
|
10
|
+
import type { ResolvedScoreColorScheme } from './colorScheme';
|
|
11
|
+
import type { RendererRect, RendererType, ScoreOptions } from './types';
|
|
12
|
+
|
|
13
|
+
export interface ScoreRecording {
|
|
14
|
+
commands: readonly VexflowRecordingCommand[];
|
|
15
|
+
layoutPlan: ScoreLayoutPlan;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function useScoreRecording({
|
|
19
|
+
defaultFont,
|
|
20
|
+
enabled = true,
|
|
21
|
+
fontManager,
|
|
22
|
+
colorScheme,
|
|
23
|
+
options,
|
|
24
|
+
rendererType,
|
|
25
|
+
score,
|
|
26
|
+
viewport,
|
|
27
|
+
}: {
|
|
28
|
+
defaultFont: string;
|
|
29
|
+
enabled?: boolean;
|
|
30
|
+
fontManager: SkTypefaceFontProvider;
|
|
31
|
+
colorScheme: ResolvedScoreColorScheme;
|
|
32
|
+
options: ScoreOptions;
|
|
33
|
+
rendererType: RendererType;
|
|
34
|
+
score: Score;
|
|
35
|
+
viewport: RendererRect;
|
|
36
|
+
}): ScoreRecording {
|
|
37
|
+
return useMemo(() => {
|
|
38
|
+
if (!enabled) {
|
|
39
|
+
return {
|
|
40
|
+
commands: [],
|
|
41
|
+
layoutPlan: createEmptyLayoutPlan(rendererType, viewport),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const measureStart = nowMs();
|
|
46
|
+
const ctx = new VexflowRecordingContext(
|
|
47
|
+
fontManager,
|
|
48
|
+
defaultFont,
|
|
49
|
+
colorScheme
|
|
50
|
+
);
|
|
51
|
+
const measuredScore = measureScore(score, options);
|
|
52
|
+
const measureMs = nowMs() - measureStart;
|
|
53
|
+
|
|
54
|
+
const layoutStart = nowMs();
|
|
55
|
+
const layoutPlan = layoutScore(
|
|
56
|
+
score,
|
|
57
|
+
measuredScore,
|
|
58
|
+
options,
|
|
59
|
+
rendererType,
|
|
60
|
+
viewport
|
|
61
|
+
);
|
|
62
|
+
const layoutMs = nowMs() - layoutStart;
|
|
63
|
+
|
|
64
|
+
const renderStart = nowMs();
|
|
65
|
+
renderScore(ctx, score, layoutPlan, options);
|
|
66
|
+
const renderMs = nowMs() - renderStart;
|
|
67
|
+
|
|
68
|
+
const finishStart = nowMs();
|
|
69
|
+
const commands = ctx.finish();
|
|
70
|
+
const finishMs = nowMs() - finishStart;
|
|
71
|
+
|
|
72
|
+
logScoreRecordingProfile({
|
|
73
|
+
commandCount: commands.length,
|
|
74
|
+
contentSize: layoutPlan.contentSize,
|
|
75
|
+
finishMs,
|
|
76
|
+
layoutMs,
|
|
77
|
+
measureCount: layoutPlan.measures.length,
|
|
78
|
+
measureMs,
|
|
79
|
+
renderMs,
|
|
80
|
+
rendererType,
|
|
81
|
+
scoreId: score.id,
|
|
82
|
+
systemCount: layoutPlan.systems.length,
|
|
83
|
+
viewport,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
commands,
|
|
88
|
+
layoutPlan,
|
|
89
|
+
};
|
|
90
|
+
}, [
|
|
91
|
+
colorScheme,
|
|
92
|
+
defaultFont,
|
|
93
|
+
enabled,
|
|
94
|
+
fontManager,
|
|
95
|
+
options,
|
|
96
|
+
rendererType,
|
|
97
|
+
score,
|
|
98
|
+
viewport,
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function createEmptyLayoutPlan(
|
|
103
|
+
rendererType: RendererType,
|
|
104
|
+
viewport: RendererRect
|
|
105
|
+
): ScoreLayoutPlan {
|
|
106
|
+
return {
|
|
107
|
+
rendererType,
|
|
108
|
+
contentSize: {
|
|
109
|
+
width: viewport.width,
|
|
110
|
+
height: viewport.height,
|
|
111
|
+
},
|
|
112
|
+
systems: [],
|
|
113
|
+
measures: [],
|
|
114
|
+
groups: [],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function logScoreRecordingProfile({
|
|
119
|
+
commandCount,
|
|
120
|
+
contentSize,
|
|
121
|
+
finishMs,
|
|
122
|
+
layoutMs,
|
|
123
|
+
measureCount,
|
|
124
|
+
measureMs,
|
|
125
|
+
renderMs,
|
|
126
|
+
rendererType,
|
|
127
|
+
scoreId,
|
|
128
|
+
systemCount,
|
|
129
|
+
viewport,
|
|
130
|
+
}: {
|
|
131
|
+
commandCount: number;
|
|
132
|
+
contentSize: { height: number; width: number };
|
|
133
|
+
finishMs: number;
|
|
134
|
+
layoutMs: number;
|
|
135
|
+
measureCount: number;
|
|
136
|
+
measureMs: number;
|
|
137
|
+
renderMs: number;
|
|
138
|
+
rendererType: RendererType;
|
|
139
|
+
scoreId: string;
|
|
140
|
+
systemCount: number;
|
|
141
|
+
viewport: RendererRect;
|
|
142
|
+
}) {
|
|
143
|
+
if (!isDevBuild()) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
console.info('[ScoreRenderer] recording profile', {
|
|
148
|
+
scoreId,
|
|
149
|
+
rendererType,
|
|
150
|
+
viewport,
|
|
151
|
+
contentSize,
|
|
152
|
+
measureCount,
|
|
153
|
+
systemCount,
|
|
154
|
+
commandCount,
|
|
155
|
+
measureMs: roundMs(measureMs),
|
|
156
|
+
layoutMs: roundMs(layoutMs),
|
|
157
|
+
renderMs: roundMs(renderMs),
|
|
158
|
+
finishMs: roundMs(finishMs),
|
|
159
|
+
totalMs: roundMs(measureMs + layoutMs + renderMs + finishMs),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function nowMs(): number {
|
|
164
|
+
return globalThis.performance?.now?.() ?? Date.now();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function roundMs(value: number): number {
|
|
168
|
+
return Math.round(value * 10) / 10;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function isDevBuild(): boolean {
|
|
172
|
+
if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'test') {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return typeof __DEV__ === 'undefined' ? false : __DEV__;
|
|
177
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RendererSize,
|
|
3
|
+
RendererType,
|
|
4
|
+
Viewport,
|
|
5
|
+
VisibleViewport,
|
|
6
|
+
} from './types';
|
|
7
|
+
|
|
8
|
+
function clampOffset(
|
|
9
|
+
offset: number,
|
|
10
|
+
contentExtent: number,
|
|
11
|
+
viewportExtent: number
|
|
12
|
+
): number {
|
|
13
|
+
'worklet';
|
|
14
|
+
|
|
15
|
+
const maxOffset = Math.max(0, contentExtent - viewportExtent);
|
|
16
|
+
|
|
17
|
+
return Math.min(Math.max(offset, 0), maxOffset);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createVisibleViewport(
|
|
21
|
+
scrollOffset: number,
|
|
22
|
+
rendererType: RendererType,
|
|
23
|
+
viewport: Viewport,
|
|
24
|
+
contentSize: RendererSize
|
|
25
|
+
): VisibleViewport {
|
|
26
|
+
'worklet';
|
|
27
|
+
|
|
28
|
+
const offset =
|
|
29
|
+
rendererType === 'infiniteScore'
|
|
30
|
+
? {
|
|
31
|
+
x: clampOffset(scrollOffset, contentSize.width, viewport.width),
|
|
32
|
+
y: 0,
|
|
33
|
+
}
|
|
34
|
+
: {
|
|
35
|
+
x: 0,
|
|
36
|
+
y: clampOffset(scrollOffset, contentSize.height, viewport.height),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
x: offset.x,
|
|
41
|
+
y: offset.y,
|
|
42
|
+
width: viewport.width,
|
|
43
|
+
height: viewport.height,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export enum LogCategory {
|
|
4
|
+
FontManager = 'FontManager',
|
|
5
|
+
VexflowRecordingContext = 'VexflowRecordingContext',
|
|
6
|
+
VexflowCanvas = 'VexflowCanvas',
|
|
7
|
+
Default = 'Default',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const disabledCategories: Set<LogCategory> = new Set([
|
|
11
|
+
LogCategory.FontManager,
|
|
12
|
+
// LogCategory.VexflowRecordingContext,
|
|
13
|
+
// LogCategory.VexflowCanvas,
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const categoryColors: Record<LogCategory, string> = Platform.select({
|
|
17
|
+
web: {
|
|
18
|
+
[LogCategory.FontManager]: '#1d56b3',
|
|
19
|
+
[LogCategory.VexflowRecordingContext]: 'green',
|
|
20
|
+
[LogCategory.VexflowCanvas]: 'cyan',
|
|
21
|
+
[LogCategory.Default]: 'black',
|
|
22
|
+
},
|
|
23
|
+
default: {
|
|
24
|
+
[LogCategory.FontManager]: '\x1b[34m', // Blue
|
|
25
|
+
[LogCategory.VexflowRecordingContext]: '\x1b[32m', // Green
|
|
26
|
+
[LogCategory.VexflowCanvas]: '\x1b[36m', // Cyan
|
|
27
|
+
[LogCategory.Default]: '\x1b[0m', // Reset
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
class Logger {
|
|
32
|
+
private logCategory: string;
|
|
33
|
+
|
|
34
|
+
constructor(category: LogCategory = LogCategory.Default) {
|
|
35
|
+
this.logCategory = category;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
extend(logCategory: LogCategory): Logger {
|
|
39
|
+
return new Logger(logCategory);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
formatMessage(...params: unknown[]) {
|
|
43
|
+
if (Platform.OS === 'web') {
|
|
44
|
+
const color = categoryColors[this.logCategory as LogCategory] || 'black';
|
|
45
|
+
|
|
46
|
+
return [
|
|
47
|
+
`%c${this.logCategory}`,
|
|
48
|
+
`background-color: ${color}; font-weight: bold;`,
|
|
49
|
+
...params,
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const colorCode =
|
|
54
|
+
categoryColors[this.logCategory as LogCategory] ||
|
|
55
|
+
categoryColors[LogCategory.Default];
|
|
56
|
+
|
|
57
|
+
return [`${colorCode}${this.logCategory}`, ...params, '\x1b[0m'];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
log(...params: unknown[]) {
|
|
61
|
+
if (disabledCategories.has(this.logCategory as LogCategory)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log(...this.formatMessage(...params));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
warn(...params: unknown[]) {
|
|
69
|
+
if (disabledCategories.has(this.logCategory as LogCategory)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
console.warn(...this.formatMessage(...params));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
error(...params: unknown[]) {
|
|
77
|
+
if (disabledCategories.has(this.logCategory as LogCategory)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.error(...this.formatMessage(...params));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default new Logger();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
export type Id = string;
|
|
2
|
+
|
|
3
|
+
export type Clef =
|
|
4
|
+
| 'treble'
|
|
5
|
+
| 'bass'
|
|
6
|
+
| 'alto'
|
|
7
|
+
| 'tenor'
|
|
8
|
+
| 'soprano'
|
|
9
|
+
| 'mezzo-soprano'
|
|
10
|
+
| 'baritone-c'
|
|
11
|
+
| 'baritone-f'
|
|
12
|
+
| 'subbass'
|
|
13
|
+
| 'french'
|
|
14
|
+
| 'percussion'
|
|
15
|
+
| 'tab';
|
|
16
|
+
|
|
17
|
+
export type Step = 'C' | 'D' | 'E' | 'F' | 'G' | 'A' | 'B';
|
|
18
|
+
|
|
19
|
+
export type Accidental =
|
|
20
|
+
| 'bb'
|
|
21
|
+
| 'b'
|
|
22
|
+
| 'n'
|
|
23
|
+
| '#'
|
|
24
|
+
| '##'
|
|
25
|
+
| 'x'
|
|
26
|
+
| 'quarter-flat'
|
|
27
|
+
| 'quarter-sharp';
|
|
28
|
+
|
|
29
|
+
export type NoteLength =
|
|
30
|
+
| 'long'
|
|
31
|
+
| 'breve'
|
|
32
|
+
| 'w'
|
|
33
|
+
| 'h'
|
|
34
|
+
| 'q'
|
|
35
|
+
| '8'
|
|
36
|
+
| '16'
|
|
37
|
+
| '32'
|
|
38
|
+
| '64'
|
|
39
|
+
| '128';
|
|
40
|
+
|
|
41
|
+
export type StemDirection = 'up' | 'down' | 'auto';
|
|
42
|
+
|
|
43
|
+
export type Barline =
|
|
44
|
+
| 'single'
|
|
45
|
+
| 'double'
|
|
46
|
+
| 'end'
|
|
47
|
+
| 'repeat-begin'
|
|
48
|
+
| 'repeat-end'
|
|
49
|
+
| 'final';
|
|
50
|
+
|
|
51
|
+
export type Articulation =
|
|
52
|
+
| 'staccato'
|
|
53
|
+
| 'tenuto'
|
|
54
|
+
| 'accent'
|
|
55
|
+
| 'marcato'
|
|
56
|
+
| 'staccatissimo'
|
|
57
|
+
| 'fermata';
|
|
58
|
+
|
|
59
|
+
export type Dynamic =
|
|
60
|
+
| 'ppp'
|
|
61
|
+
| 'pp'
|
|
62
|
+
| 'p'
|
|
63
|
+
| 'mp'
|
|
64
|
+
| 'mf'
|
|
65
|
+
| 'f'
|
|
66
|
+
| 'ff'
|
|
67
|
+
| 'fff'
|
|
68
|
+
| 'sfz';
|
|
69
|
+
|
|
70
|
+
export type KeyMode =
|
|
71
|
+
| 'major'
|
|
72
|
+
| 'minor'
|
|
73
|
+
| 'dorian'
|
|
74
|
+
| 'phrygian'
|
|
75
|
+
| 'lydian'
|
|
76
|
+
| 'mixolydian'
|
|
77
|
+
| 'locrian';
|
|
78
|
+
|
|
79
|
+
export type VoiceTimingMode = 'strict' | 'soft' | 'free';
|
|
80
|
+
|
|
81
|
+
export type StaffGroupRole = 'grandStaff' | 'choir' | 'section' | 'custom';
|
|
82
|
+
export type StaffGroupSymbol = 'brace' | 'bracket' | 'line';
|
|
83
|
+
|
|
84
|
+
export interface Fraction {
|
|
85
|
+
num: number;
|
|
86
|
+
den: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface Pitch {
|
|
90
|
+
step: Step;
|
|
91
|
+
octave: number;
|
|
92
|
+
accidental?: Accidental;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface DurationValue {
|
|
96
|
+
length: NoteLength;
|
|
97
|
+
dots?: 0 | 1 | 2 | 3;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface KeySignature {
|
|
101
|
+
tonic: Step;
|
|
102
|
+
accidental?: 'b' | '#';
|
|
103
|
+
mode?: KeyMode;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface Meter {
|
|
107
|
+
beats: number;
|
|
108
|
+
beatUnit: number;
|
|
109
|
+
beamGroups?: Fraction[];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface Tempo {
|
|
113
|
+
bpm: number;
|
|
114
|
+
beatUnit?: DurationValue;
|
|
115
|
+
text?: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface Note {
|
|
119
|
+
id: Id;
|
|
120
|
+
type: 'note';
|
|
121
|
+
pitch: Pitch;
|
|
122
|
+
duration: DurationValue;
|
|
123
|
+
voiceId: Id;
|
|
124
|
+
targetStaffId?: Id;
|
|
125
|
+
stemDirection?: StemDirection;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface Rest {
|
|
129
|
+
id: Id;
|
|
130
|
+
type: 'rest';
|
|
131
|
+
duration: DurationValue;
|
|
132
|
+
voiceId: Id;
|
|
133
|
+
targetStaffId?: Id;
|
|
134
|
+
kind?: 'visible' | 'spacer' | 'hidden';
|
|
135
|
+
staffLine?: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface Chord {
|
|
139
|
+
id: Id;
|
|
140
|
+
type: 'chord';
|
|
141
|
+
pitches: Pitch[];
|
|
142
|
+
duration: DurationValue;
|
|
143
|
+
voiceId: Id;
|
|
144
|
+
targetStaffId?: Id;
|
|
145
|
+
stemDirection?: StemDirection;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export type VoiceItem = Note | Rest | Chord;
|
|
149
|
+
|
|
150
|
+
export interface Voice {
|
|
151
|
+
id: Id;
|
|
152
|
+
name?: string;
|
|
153
|
+
index: number;
|
|
154
|
+
timingMode?: VoiceTimingMode;
|
|
155
|
+
items: VoiceItem[];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface MeasureState {
|
|
159
|
+
clef?: Clef;
|
|
160
|
+
meter?: Meter;
|
|
161
|
+
keySignature?: KeySignature;
|
|
162
|
+
tempo?: Tempo;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface MeasureLeftModifiers {
|
|
166
|
+
showClef?: boolean;
|
|
167
|
+
showMeter?: boolean;
|
|
168
|
+
showKeySignature?: boolean;
|
|
169
|
+
startBarline?: Barline;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface MeasureRightModifiers {
|
|
173
|
+
endBarline?: Barline;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface TextDirection {
|
|
177
|
+
id: Id;
|
|
178
|
+
type: 'text';
|
|
179
|
+
text: string;
|
|
180
|
+
placement?: 'above' | 'below';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface TempoDirection {
|
|
184
|
+
id: Id;
|
|
185
|
+
type: 'tempo';
|
|
186
|
+
tempo: Tempo;
|
|
187
|
+
placement?: 'above' | 'below';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export type Direction = TextDirection | TempoDirection;
|
|
191
|
+
|
|
192
|
+
export interface Measure {
|
|
193
|
+
id: Id;
|
|
194
|
+
number: number;
|
|
195
|
+
|
|
196
|
+
state?: MeasureState;
|
|
197
|
+
|
|
198
|
+
leftModifiers?: MeasureLeftModifiers;
|
|
199
|
+
rightModifiers?: MeasureRightModifiers;
|
|
200
|
+
|
|
201
|
+
directions?: Direction[];
|
|
202
|
+
voices: Voice[];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface Staff {
|
|
206
|
+
id: Id;
|
|
207
|
+
name?: string;
|
|
208
|
+
shortName?: string;
|
|
209
|
+
order: number;
|
|
210
|
+
defaultClef: Clef;
|
|
211
|
+
transposition?: number;
|
|
212
|
+
measures: Measure[];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface StaffGroup {
|
|
216
|
+
id: Id;
|
|
217
|
+
staffIds?: Id[];
|
|
218
|
+
role: StaffGroupRole;
|
|
219
|
+
symbol?: StaffGroupSymbol;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface ScoreMetadata {
|
|
223
|
+
title?: string;
|
|
224
|
+
subtitle?: string;
|
|
225
|
+
composer?: string;
|
|
226
|
+
lyricist?: string;
|
|
227
|
+
arranger?: string;
|
|
228
|
+
copyright?: string;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface ScoreDefaults {
|
|
232
|
+
meter: Meter;
|
|
233
|
+
keySignature?: KeySignature;
|
|
234
|
+
tempo?: Tempo;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface AttachmentBase {
|
|
238
|
+
id: Id;
|
|
239
|
+
ownerId: Id;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface ArticulationAttachment extends AttachmentBase {
|
|
243
|
+
type: 'articulation';
|
|
244
|
+
articulation: Articulation;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface DynamicAttachment extends AttachmentBase {
|
|
248
|
+
type: 'dynamic';
|
|
249
|
+
dynamic: Dynamic;
|
|
250
|
+
placement?: 'above' | 'below';
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export interface LyricAttachment extends AttachmentBase {
|
|
254
|
+
type: 'lyric';
|
|
255
|
+
text: string;
|
|
256
|
+
verse?: number;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export type NoteAttachment =
|
|
260
|
+
| ArticulationAttachment
|
|
261
|
+
| DynamicAttachment
|
|
262
|
+
| LyricAttachment;
|
|
263
|
+
|
|
264
|
+
export interface Tie {
|
|
265
|
+
id: Id;
|
|
266
|
+
fromNoteId: Id;
|
|
267
|
+
toNoteId: Id;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export interface Slur {
|
|
271
|
+
id: Id;
|
|
272
|
+
fromNoteId: Id;
|
|
273
|
+
toNoteId: Id;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface TupletGroup {
|
|
277
|
+
id: Id;
|
|
278
|
+
voiceId: Id;
|
|
279
|
+
itemIds: Id[];
|
|
280
|
+
ratio: Fraction;
|
|
281
|
+
bracketed?: boolean;
|
|
282
|
+
placement?: 'above' | 'below';
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export interface Score {
|
|
286
|
+
id: Id;
|
|
287
|
+
metadata?: ScoreMetadata;
|
|
288
|
+
defaults: ScoreDefaults;
|
|
289
|
+
staves: Staff[];
|
|
290
|
+
staffGroups?: StaffGroup[];
|
|
291
|
+
attachments?: NoteAttachment[];
|
|
292
|
+
ties?: Tie[];
|
|
293
|
+
slurs?: Slur[];
|
|
294
|
+
tuplets?: TupletGroup[];
|
|
295
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type LineCap = 'butt' | 'round' | 'square';
|
|
2
|
-
export type LineJoin = 'miter' | 'round' | 'bevel';
|
|
1
|
+
// export type LineCap = 'butt' | 'round' | 'square';
|
|
2
|
+
// export type LineJoin = 'miter' | 'round' | 'bevel';
|
|
3
3
|
|
|
4
|
-
export type ParsedCssFont = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
4
|
+
// export type ParsedCssFont = {
|
|
5
|
+
// sizePx: number;
|
|
6
|
+
// family?: string;
|
|
7
|
+
// };
|