vexflow-native 2.1.0 → 2.2.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 +1 -1
- package/lib/module/renderer/Layout/DocumentLayout.js +36 -32
- package/lib/module/renderer/Layout/DocumentLayout.js.map +1 -1
- package/lib/module/renderer/Layout/LayoutMetrics.js +7 -1
- package/lib/module/renderer/Layout/LayoutMetrics.js.map +1 -1
- package/lib/module/renderer/constants.js +4 -1
- package/lib/module/renderer/constants.js.map +1 -1
- package/lib/module/renderer/engraveScore.js +202 -0
- package/lib/module/renderer/engraveScore.js.map +1 -0
- package/lib/module/renderer/index.js +1 -0
- package/lib/module/renderer/index.js.map +1 -1
- package/lib/module/renderer/layout.js +4 -1
- package/lib/module/renderer/layout.js.map +1 -1
- package/lib/module/renderer/measure.js +12 -3
- package/lib/module/renderer/measure.js.map +1 -1
- package/lib/module/renderer/measureModifiers.js +5 -4
- package/lib/module/renderer/measureModifiers.js.map +1 -1
- package/lib/module/renderer/render.js +2 -1
- package/lib/module/renderer/render.js.map +1 -1
- package/lib/module/renderer/systemExtents.js +104 -0
- package/lib/module/renderer/systemExtents.js.map +1 -0
- package/lib/module/renderer/useScoreRecording.js +19 -109
- package/lib/module/renderer/useScoreRecording.js.map +1 -1
- package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts.map +1 -1
- package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts +2 -2
- package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts.map +1 -1
- package/lib/typescript/src/renderer/constants.d.ts.map +1 -1
- package/lib/typescript/src/renderer/engraveScore.d.ts +101 -0
- package/lib/typescript/src/renderer/engraveScore.d.ts.map +1 -0
- package/lib/typescript/src/renderer/index.d.ts +1 -0
- package/lib/typescript/src/renderer/index.d.ts.map +1 -1
- package/lib/typescript/src/renderer/layout.d.ts +1 -0
- package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
- package/lib/typescript/src/renderer/measure.d.ts +5 -0
- package/lib/typescript/src/renderer/measure.d.ts.map +1 -1
- package/lib/typescript/src/renderer/measureModifiers.d.ts +4 -3
- package/lib/typescript/src/renderer/measureModifiers.d.ts.map +1 -1
- package/lib/typescript/src/renderer/render.d.ts.map +1 -1
- package/lib/typescript/src/renderer/systemExtents.d.ts +15 -0
- package/lib/typescript/src/renderer/systemExtents.d.ts.map +1 -0
- package/lib/typescript/src/renderer/types.d.ts +25 -0
- package/lib/typescript/src/renderer/types.d.ts.map +1 -1
- package/lib/typescript/src/renderer/useScoreRecording.d.ts +3 -20
- package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/renderer/Layout/DocumentLayout.ts +65 -33
- package/src/renderer/Layout/LayoutMetrics.ts +9 -2
- package/src/renderer/constants.ts +3 -0
- package/src/renderer/engraveScore.ts +338 -0
- package/src/renderer/index.ts +6 -0
- package/src/renderer/layout.ts +5 -2
- package/src/renderer/measure.tsx +27 -3
- package/src/renderer/measureModifiers.ts +7 -4
- package/src/renderer/render.tsx +7 -1
- package/src/renderer/systemExtents.ts +134 -0
- package/src/renderer/types.ts +25 -0
- package/src/renderer/useScoreRecording.ts +27 -176
package/src/renderer/layout.ts
CHANGED
|
@@ -29,6 +29,7 @@ export interface MeasuredGroupMeasure {
|
|
|
29
29
|
groupId: string;
|
|
30
30
|
measureIndex: number;
|
|
31
31
|
intrinsicWidth: number;
|
|
32
|
+
systemStartClefWidth?: number;
|
|
32
33
|
measureNumbers: number[];
|
|
33
34
|
staffBounds: StaffVerticalBounds[];
|
|
34
35
|
}
|
|
@@ -180,6 +181,9 @@ function buildGroupLayoutContext(
|
|
|
180
181
|
groupId: measure.groupId,
|
|
181
182
|
measureIndex: measure.measureIndex,
|
|
182
183
|
intrinsicWidth: measure.intrinsicNoteWidth,
|
|
184
|
+
...(measure.systemStartClefWidth
|
|
185
|
+
? { systemStartClefWidth: measure.systemStartClefWidth }
|
|
186
|
+
: {}),
|
|
183
187
|
measureNumbers: measure.measureNumbers,
|
|
184
188
|
staffBounds: measure.staffBounds,
|
|
185
189
|
})),
|
|
@@ -243,8 +247,7 @@ function layoutInfiniteScoreGroup(
|
|
|
243
247
|
groupId: group.groupId,
|
|
244
248
|
systems,
|
|
245
249
|
measures,
|
|
246
|
-
nextY:
|
|
247
|
-
origin.y + verticalLayout.height + getSystemGap(options.spacing.staffGap),
|
|
250
|
+
nextY: origin.y + verticalLayout.height + getSystemGap(options.spacing),
|
|
248
251
|
};
|
|
249
252
|
}
|
|
250
253
|
|
package/src/renderer/measure.tsx
CHANGED
|
@@ -35,6 +35,11 @@ export interface MeasuredMeasure {
|
|
|
35
35
|
staffIds: string[];
|
|
36
36
|
staffBounds: StaffVerticalBounds[];
|
|
37
37
|
intrinsicNoteWidth: number;
|
|
38
|
+
/**
|
|
39
|
+
* Extra width the measure needs when it starts a system and
|
|
40
|
+
* `spacing.clefOnEachSystem` adds its clef; absent = 0.
|
|
41
|
+
*/
|
|
42
|
+
systemStartClefWidth?: number;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
export interface MeasuredScore {
|
|
@@ -64,7 +69,7 @@ export function measureScore(
|
|
|
64
69
|
const attachmentsByOwner = indexAttachmentsByOwner(score);
|
|
65
70
|
const measures: MeasuredMeasure[] = [];
|
|
66
71
|
const {
|
|
67
|
-
spacing: { minIntrinsicSizeMultiplier },
|
|
72
|
+
spacing: { minIntrinsicSizeMultiplier, clefOnEachSystem },
|
|
68
73
|
} = options;
|
|
69
74
|
|
|
70
75
|
if (Platform.OS === 'ios' || Platform.OS === 'android') {
|
|
@@ -139,11 +144,26 @@ export function measureScore(
|
|
|
139
144
|
// Clef and time signature sit before the note area, so the intrinsic
|
|
140
145
|
// width must include them or an empty measure with a time signature
|
|
141
146
|
// measures ~0 wide and the signature clips.
|
|
147
|
+
const leftModifierWidth = measureLeftModifierWidth(
|
|
148
|
+
staffMeasurementContexts
|
|
149
|
+
);
|
|
142
150
|
const intrinsicNoteWidth =
|
|
143
151
|
(allVoices.length > 0
|
|
144
152
|
? formatter.preCalculateMinTotalWidth(allVoices) *
|
|
145
153
|
Math.max(1, minIntrinsicSizeMultiplier)
|
|
146
|
-
: 0) +
|
|
154
|
+
: 0) + leftModifierWidth;
|
|
155
|
+
const systemStartClefWidth =
|
|
156
|
+
clefOnEachSystem &&
|
|
157
|
+
measureLeftModifierWidth(
|
|
158
|
+
staffMeasurementContexts.map((context) => ({
|
|
159
|
+
...context,
|
|
160
|
+
modifiers: resolveMeasureModifiers(
|
|
161
|
+
context.measure,
|
|
162
|
+
measureIndex,
|
|
163
|
+
true
|
|
164
|
+
),
|
|
165
|
+
}))
|
|
166
|
+
) - leftModifierWidth;
|
|
147
167
|
const staffBounds = measureStaffVerticalBounds({
|
|
148
168
|
allVoices,
|
|
149
169
|
intrinsicNoteWidth,
|
|
@@ -158,6 +178,7 @@ export function measureScore(
|
|
|
158
178
|
staffIds: group.staffIds,
|
|
159
179
|
staffBounds,
|
|
160
180
|
intrinsicNoteWidth,
|
|
181
|
+
...(systemStartClefWidth ? { systemStartClefWidth } : {}),
|
|
161
182
|
});
|
|
162
183
|
} catch (error) {
|
|
163
184
|
throw new Error(
|
|
@@ -186,7 +207,10 @@ const MODIFIER_PROBE_STAVE_WIDTH = 500;
|
|
|
186
207
|
* between a bare probe stave and one carrying the resolved modifiers.
|
|
187
208
|
*/
|
|
188
209
|
function measureLeftModifierWidth(
|
|
189
|
-
staffMeasurementContexts:
|
|
210
|
+
staffMeasurementContexts: Pick<
|
|
211
|
+
StaffMeasurementContext,
|
|
212
|
+
'resolvedState' | 'modifiers'
|
|
213
|
+
>[]
|
|
190
214
|
): number {
|
|
191
215
|
return staffMeasurementContexts.reduce(
|
|
192
216
|
(maxWidth, { resolvedState, modifiers }) => {
|
|
@@ -67,17 +67,20 @@ const END_BARLINE_TYPES: Record<Barline, BarlineType> = {
|
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* Resolves the tri-state measure modifiers: `true` shows, `false` hides,
|
|
70
|
-
* `undefined` falls back to the default (clef on the first measure
|
|
71
|
-
* meter and key signature hidden,
|
|
70
|
+
* `undefined` falls back to the default (clef on the first measure, and on
|
|
71
|
+
* a measure that `startsSystemWithClef`; meter and key signature hidden,
|
|
72
|
+
* single barlines).
|
|
72
73
|
*/
|
|
73
74
|
export function resolveMeasureModifiers(
|
|
74
75
|
measure: Pick<Measure, 'leftModifiers' | 'rightModifiers'>,
|
|
75
|
-
measureIndex: number
|
|
76
|
+
measureIndex: number,
|
|
77
|
+
startsSystemWithClef = false
|
|
76
78
|
): ResolvedMeasureModifiers {
|
|
77
79
|
const { leftModifiers, rightModifiers } = measure;
|
|
78
80
|
|
|
79
81
|
return {
|
|
80
|
-
showClef:
|
|
82
|
+
showClef:
|
|
83
|
+
leftModifiers?.showClef ?? (measureIndex === 0 || startsSystemWithClef),
|
|
81
84
|
showMeter: leftModifiers?.showMeter ?? false,
|
|
82
85
|
showKeySignature: leftModifiers?.showKeySignature ?? false,
|
|
83
86
|
startBarline: leftModifiers?.startBarline ?? 'single',
|
package/src/renderer/render.tsx
CHANGED
|
@@ -72,6 +72,7 @@ export function renderScore(
|
|
|
72
72
|
isFirstMeasureInSystem: measureIndex === 0,
|
|
73
73
|
isLastMeasureInSystem: measureIndex === measurePlans.length - 1,
|
|
74
74
|
fixedNoteSpacing: options.render.fixedNoteSpacing,
|
|
75
|
+
clefOnEachSystem: options.spacing.clefOnEachSystem,
|
|
75
76
|
...hooks,
|
|
76
77
|
},
|
|
77
78
|
itemsLayout
|
|
@@ -101,6 +102,7 @@ interface RenderMeasureOptions extends ScoreItemHooks {
|
|
|
101
102
|
isFirstMeasureInSystem: boolean;
|
|
102
103
|
isLastMeasureInSystem: boolean;
|
|
103
104
|
fixedNoteSpacing: boolean;
|
|
105
|
+
clefOnEachSystem: boolean;
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
function renderMeasure(
|
|
@@ -187,7 +189,11 @@ function renderMeasure(
|
|
|
187
189
|
|
|
188
190
|
applyMeasureModifiers(
|
|
189
191
|
stave,
|
|
190
|
-
resolveMeasureModifiers(
|
|
192
|
+
resolveMeasureModifiers(
|
|
193
|
+
measure,
|
|
194
|
+
measurePlan.measureIndex,
|
|
195
|
+
options.clefOnEachSystem && options.isFirstMeasureInSystem
|
|
196
|
+
),
|
|
191
197
|
resolvedState
|
|
192
198
|
);
|
|
193
199
|
stave.setContext(ctx).draw();
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { SkFont } from 'react-native-skia';
|
|
2
|
+
|
|
3
|
+
import type { VexflowRecordingCommand } from '../base';
|
|
4
|
+
import type FontManager from '../base/FontManager';
|
|
5
|
+
import type { VexflowRecordingPathCommand } from '../base/VexflowRecordingTypes';
|
|
6
|
+
|
|
7
|
+
interface VerticalExtent {
|
|
8
|
+
top: number;
|
|
9
|
+
bottom: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface VerticalBand {
|
|
13
|
+
y: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Grows each band to cover everything the recording draws for it. A command
|
|
19
|
+
* belongs to the band its vertical centre is in, or else the nearest one.
|
|
20
|
+
* Curve control points count as drawn, so a band can come out slightly taller
|
|
21
|
+
* than its ink, never shorter.
|
|
22
|
+
*/
|
|
23
|
+
export function coverDrawnExtents<Band extends VerticalBand>(
|
|
24
|
+
bands: readonly Band[],
|
|
25
|
+
commands: readonly VexflowRecordingCommand[],
|
|
26
|
+
fontManager: FontManager
|
|
27
|
+
): Band[] {
|
|
28
|
+
const extents = bands.map(
|
|
29
|
+
(band): VerticalExtent => ({ top: band.y, bottom: band.y + band.height })
|
|
30
|
+
);
|
|
31
|
+
const textExtents = new Map<SkFont, Map<string, VerticalExtent>>();
|
|
32
|
+
|
|
33
|
+
for (const command of commands) {
|
|
34
|
+
const drawn = commandExtent(command, fontManager, textExtents);
|
|
35
|
+
const extent = drawn && nearestExtent(extents, bands, drawn);
|
|
36
|
+
|
|
37
|
+
if (drawn && extent) {
|
|
38
|
+
extent.top = Math.min(extent.top, drawn.top);
|
|
39
|
+
extent.bottom = Math.max(extent.bottom, drawn.bottom);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return bands.map((band, index) => ({
|
|
44
|
+
...band,
|
|
45
|
+
y: extents[index]!.top,
|
|
46
|
+
height: extents[index]!.bottom - extents[index]!.top,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function nearestExtent(
|
|
51
|
+
extents: VerticalExtent[],
|
|
52
|
+
bands: readonly VerticalBand[],
|
|
53
|
+
drawn: VerticalExtent
|
|
54
|
+
): VerticalExtent | undefined {
|
|
55
|
+
const centre = (drawn.top + drawn.bottom) / 2;
|
|
56
|
+
let nearest: VerticalExtent | undefined;
|
|
57
|
+
let nearestDistance = Infinity;
|
|
58
|
+
|
|
59
|
+
bands.forEach((band, index) => {
|
|
60
|
+
const distance = Math.max(band.y - centre, centre - band.y - band.height);
|
|
61
|
+
|
|
62
|
+
if (distance < nearestDistance) {
|
|
63
|
+
nearest = extents[index];
|
|
64
|
+
nearestDistance = distance;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return nearest;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function commandExtent(
|
|
72
|
+
command: VexflowRecordingCommand,
|
|
73
|
+
fontManager: FontManager,
|
|
74
|
+
textExtents: Map<SkFont, Map<string, VerticalExtent>>
|
|
75
|
+
): VerticalExtent | undefined {
|
|
76
|
+
switch (command.type) {
|
|
77
|
+
case 'fillRect':
|
|
78
|
+
return {
|
|
79
|
+
top: command.rect.y,
|
|
80
|
+
bottom: command.rect.y + command.rect.height,
|
|
81
|
+
};
|
|
82
|
+
case 'fillPath':
|
|
83
|
+
return pathExtent(command.path, 0);
|
|
84
|
+
case 'strokePath':
|
|
85
|
+
return pathExtent(command.path, (command.paint.strokeWidth ?? 0) / 2);
|
|
86
|
+
case 'fillText': {
|
|
87
|
+
const { font, size, weight, style } = command.font;
|
|
88
|
+
const skFont = fontManager.createSkFont(font, size, weight, style);
|
|
89
|
+
const byText = textExtents.get(skFont) ?? new Map();
|
|
90
|
+
let glyphs = byText.get(command.text);
|
|
91
|
+
|
|
92
|
+
if (!glyphs) {
|
|
93
|
+
const rect = skFont.measureText(command.text);
|
|
94
|
+
|
|
95
|
+
glyphs = { top: rect.y, bottom: rect.y + rect.height };
|
|
96
|
+
byText.set(command.text, glyphs);
|
|
97
|
+
textExtents.set(skFont, byText);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
top: command.y + glyphs.top,
|
|
102
|
+
bottom: command.y + glyphs.bottom,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
default:
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function pathExtent(
|
|
111
|
+
path: VexflowRecordingPathCommand[],
|
|
112
|
+
outset: number
|
|
113
|
+
): VerticalExtent | undefined {
|
|
114
|
+
const ys = path.flatMap((segment) => {
|
|
115
|
+
switch (segment.type) {
|
|
116
|
+
case 'moveTo':
|
|
117
|
+
case 'lineTo':
|
|
118
|
+
return [segment.y];
|
|
119
|
+
case 'quadTo':
|
|
120
|
+
return [segment.cpy, segment.y];
|
|
121
|
+
case 'cubicTo':
|
|
122
|
+
return [segment.cp1y, segment.cp2y, segment.y];
|
|
123
|
+
case 'addRect':
|
|
124
|
+
case 'addArc':
|
|
125
|
+
return [segment.rect.y, segment.rect.y + segment.rect.height];
|
|
126
|
+
default:
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return ys.length > 0
|
|
132
|
+
? { top: Math.min(...ys) - outset, bottom: Math.max(...ys) + outset }
|
|
133
|
+
: undefined;
|
|
134
|
+
}
|
package/src/renderer/types.ts
CHANGED
|
@@ -152,6 +152,31 @@ export interface ScoreSpacing {
|
|
|
152
152
|
* rows of two renderers laid out side by side stay aligned. Default false.
|
|
153
153
|
*/
|
|
154
154
|
uniformSystemPitch: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* `document` only: indent of the first system of each staff group, in
|
|
157
|
+
* content units (before `render.scale`). That system starts later and is
|
|
158
|
+
* narrower by the same amount. Default 0.
|
|
159
|
+
*/
|
|
160
|
+
firstSystemIndent: number;
|
|
161
|
+
/**
|
|
162
|
+
* Vertical gap between systems in content units, clamped to >= 0. With
|
|
163
|
+
* `uniformSystemPitch` the pitch is the shared system height plus this gap.
|
|
164
|
+
* Undefined or non-finite = the built-in `max(82, staffGap / 8)`.
|
|
165
|
+
*/
|
|
166
|
+
systemGap?: number;
|
|
167
|
+
/**
|
|
168
|
+
* `document` only: `justify` stretches the last system of each staff group
|
|
169
|
+
* to the full width like every other system; `natural` keeps its intrinsic
|
|
170
|
+
* width (a one-system score counts as its own last system). `documentEven`
|
|
171
|
+
* never stretches a partial last system. Default `justify`.
|
|
172
|
+
*/
|
|
173
|
+
lastSystemFill: 'justify' | 'natural';
|
|
174
|
+
/**
|
|
175
|
+
* Draw the clef on the first measure of every system instead of the first
|
|
176
|
+
* measure of the score only; line breaking reserves its width. A measure
|
|
177
|
+
* with `leftModifiers.showClef: false` still hides it. Default false.
|
|
178
|
+
*/
|
|
179
|
+
clefOnEachSystem: boolean;
|
|
155
180
|
}
|
|
156
181
|
|
|
157
182
|
export interface RenderOptions {
|
|
@@ -1,27 +1,14 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import type { SkTypefaceFontProvider } from 'react-native-skia';
|
|
3
3
|
|
|
4
|
-
import type { VexflowRecordingCommand } from '../base';
|
|
5
|
-
import VexflowRecordingContext from '../base/VexflowRecordingContext';
|
|
6
|
-
import {
|
|
7
|
-
buildVexflowGroupIndex,
|
|
8
|
-
type VexflowRecordingGroupIndex,
|
|
9
|
-
} from '../base/VexflowRecordingIndex';
|
|
10
4
|
import type { Score } from '../state';
|
|
11
|
-
import { isVexflowNativeDebugEnabled } from '../shared/debug';
|
|
12
|
-
import {
|
|
13
|
-
layoutScore,
|
|
14
|
-
layoutUsesViewportHeight,
|
|
15
|
-
type ScoreLayoutPlan,
|
|
16
|
-
} from './layout';
|
|
17
|
-
import { measureScore, type MeasuredScore } from './measure';
|
|
18
|
-
import { renderScore } from './render';
|
|
19
|
-
import {
|
|
20
|
-
createContentViewport,
|
|
21
|
-
getRenderScale,
|
|
22
|
-
scaleItemsLayoutToViewSpace,
|
|
23
|
-
} from './scale';
|
|
24
5
|
import type { ResolvedScoreColorScheme } from './colorScheme';
|
|
6
|
+
import {
|
|
7
|
+
measureScoreRecording,
|
|
8
|
+
recordScore,
|
|
9
|
+
type ScoreRecording,
|
|
10
|
+
} from './engraveScore';
|
|
11
|
+
import { layoutUsesViewportHeight, type ScoreLayoutPlan } from './layout';
|
|
25
12
|
import type {
|
|
26
13
|
RendererRect,
|
|
27
14
|
RendererType,
|
|
@@ -30,23 +17,7 @@ import type {
|
|
|
30
17
|
ScoreOptions,
|
|
31
18
|
} from './types';
|
|
32
19
|
|
|
33
|
-
|
|
34
|
-
/** Recorded draw commands, content-space coordinates. */
|
|
35
|
-
commands: readonly VexflowRecordingCommand[];
|
|
36
|
-
/**
|
|
37
|
-
* `commands` bucketed by `groupId` so a style-override replay can redraw
|
|
38
|
-
* just the overridden items instead of the whole recording.
|
|
39
|
-
*/
|
|
40
|
-
groupIndex: VexflowRecordingGroupIndex;
|
|
41
|
-
/**
|
|
42
|
-
* Layout plan in content space; multiply its `contentSize` by the render
|
|
43
|
-
* scale for the view-space size that drives scrolling.
|
|
44
|
-
*/
|
|
45
|
-
layoutPlan: ScoreLayoutPlan;
|
|
46
|
-
/** Emitted geometry, already converted to view space. */
|
|
47
|
-
itemsLayout: ScoreItemsLayout;
|
|
48
|
-
}
|
|
49
|
-
|
|
20
|
+
/** Memoised `engraveScore` pipeline for a mounted renderer. */
|
|
50
21
|
export function useScoreRecording({
|
|
51
22
|
decorateItem,
|
|
52
23
|
defaultFont,
|
|
@@ -68,22 +39,19 @@ export function useScoreRecording({
|
|
|
68
39
|
score: Score;
|
|
69
40
|
viewport: RendererRect;
|
|
70
41
|
}): ScoreRecording {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return { measuredScore, measureMs: nowMs() - measureStart };
|
|
86
|
-
}, [decorateItem, defaultFont, enabled, fontManager, options, score]);
|
|
42
|
+
const measurement = useMemo(
|
|
43
|
+
() =>
|
|
44
|
+
enabled
|
|
45
|
+
? measureScoreRecording({
|
|
46
|
+
score,
|
|
47
|
+
options,
|
|
48
|
+
fontManager,
|
|
49
|
+
defaultFont,
|
|
50
|
+
decorateItem,
|
|
51
|
+
})
|
|
52
|
+
: null,
|
|
53
|
+
[decorateItem, defaultFont, enabled, fontManager, options, score]
|
|
54
|
+
);
|
|
87
55
|
|
|
88
56
|
// Height-only changes (a late safe-area inset, the keyboard) cannot move a
|
|
89
57
|
// layout that ignores the height, so the height is pinned to 0 for it and
|
|
@@ -113,62 +81,18 @@ export function useScoreRecording({
|
|
|
113
81
|
};
|
|
114
82
|
}
|
|
115
83
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const scale = getRenderScale(options);
|
|
119
|
-
const contentViewport = createContentViewport(layoutViewport, scale);
|
|
120
|
-
const ctx = new VexflowRecordingContext(
|
|
121
|
-
fontManager,
|
|
122
|
-
defaultFont,
|
|
123
|
-
colorScheme
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const layoutStart = nowMs();
|
|
127
|
-
const layoutPlan = layoutScore(
|
|
84
|
+
return recordScore({
|
|
85
|
+
measurement,
|
|
128
86
|
score,
|
|
129
|
-
measurement.measuredScore,
|
|
130
87
|
options,
|
|
131
88
|
rendererType,
|
|
132
|
-
contentViewport
|
|
133
|
-
);
|
|
134
|
-
const layoutMs = nowMs() - layoutStart;
|
|
135
|
-
|
|
136
|
-
const renderStart = nowMs();
|
|
137
|
-
const itemsLayout = scaleItemsLayoutToViewSpace(
|
|
138
|
-
renderScore(ctx, score, layoutPlan, options, {
|
|
139
|
-
decorateItem,
|
|
140
|
-
onDrawItem,
|
|
141
|
-
}),
|
|
142
|
-
scale
|
|
143
|
-
);
|
|
144
|
-
const renderMs = nowMs() - renderStart;
|
|
145
|
-
|
|
146
|
-
const finishStart = nowMs();
|
|
147
|
-
const commands = ctx.finish();
|
|
148
|
-
const groupIndex = buildVexflowGroupIndex(commands);
|
|
149
|
-
const finishMs = nowMs() - finishStart;
|
|
150
|
-
|
|
151
|
-
logScoreRecordingProfile({
|
|
152
|
-
commandCount: commands.length,
|
|
153
|
-
groupCount: Object.keys(groupIndex).length,
|
|
154
|
-
contentSize: layoutPlan.contentSize,
|
|
155
|
-
finishMs,
|
|
156
|
-
layoutMs,
|
|
157
|
-
measureCount: layoutPlan.measures.length,
|
|
158
|
-
measurement,
|
|
159
|
-
renderMs,
|
|
160
|
-
rendererType,
|
|
161
|
-
scoreId: score.id,
|
|
162
|
-
systemCount: layoutPlan.systems.length,
|
|
163
89
|
viewport: layoutViewport,
|
|
90
|
+
fontManager,
|
|
91
|
+
defaultFont,
|
|
92
|
+
colorScheme,
|
|
93
|
+
decorateItem,
|
|
94
|
+
onDrawItem,
|
|
164
95
|
});
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
commands,
|
|
168
|
-
groupIndex,
|
|
169
|
-
layoutPlan,
|
|
170
|
-
itemsLayout,
|
|
171
|
-
};
|
|
172
96
|
}, [
|
|
173
97
|
colorScheme,
|
|
174
98
|
decorateItem,
|
|
@@ -183,18 +107,6 @@ export function useScoreRecording({
|
|
|
183
107
|
]);
|
|
184
108
|
}
|
|
185
109
|
|
|
186
|
-
interface ScoreMeasurement {
|
|
187
|
-
measuredScore: MeasuredScore;
|
|
188
|
-
measureMs: number;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Measurements already counted by a profile line. A cached measurement is
|
|
193
|
-
* reported once, by the first recording built on it, so summed profiles
|
|
194
|
-
* count each measure pass once.
|
|
195
|
-
*/
|
|
196
|
-
const profiledMeasurements = new WeakSet<ScoreMeasurement>();
|
|
197
|
-
|
|
198
110
|
function createEmptyItemsLayout(viewport: RendererRect): ScoreItemsLayout {
|
|
199
111
|
return {
|
|
200
112
|
items: {},
|
|
@@ -221,64 +133,3 @@ function createEmptyLayoutPlan(
|
|
|
221
133
|
groups: [],
|
|
222
134
|
};
|
|
223
135
|
}
|
|
224
|
-
|
|
225
|
-
function logScoreRecordingProfile({
|
|
226
|
-
commandCount,
|
|
227
|
-
groupCount,
|
|
228
|
-
contentSize,
|
|
229
|
-
finishMs,
|
|
230
|
-
layoutMs,
|
|
231
|
-
measureCount,
|
|
232
|
-
measurement,
|
|
233
|
-
renderMs,
|
|
234
|
-
rendererType,
|
|
235
|
-
scoreId,
|
|
236
|
-
systemCount,
|
|
237
|
-
viewport,
|
|
238
|
-
}: {
|
|
239
|
-
commandCount: number;
|
|
240
|
-
groupCount: number;
|
|
241
|
-
contentSize: { height: number; width: number };
|
|
242
|
-
finishMs: number;
|
|
243
|
-
layoutMs: number;
|
|
244
|
-
measureCount: number;
|
|
245
|
-
measurement: ScoreMeasurement;
|
|
246
|
-
renderMs: number;
|
|
247
|
-
rendererType: RendererType;
|
|
248
|
-
scoreId: string;
|
|
249
|
-
systemCount: number;
|
|
250
|
-
viewport: RendererRect;
|
|
251
|
-
}) {
|
|
252
|
-
if (!isVexflowNativeDebugEnabled()) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const measureMs = profiledMeasurements.has(measurement)
|
|
257
|
-
? 0
|
|
258
|
-
: measurement.measureMs;
|
|
259
|
-
profiledMeasurements.add(measurement);
|
|
260
|
-
|
|
261
|
-
console.info('[ScoreRenderer] recording profile', {
|
|
262
|
-
scoreId,
|
|
263
|
-
rendererType,
|
|
264
|
-
viewport,
|
|
265
|
-
contentSize,
|
|
266
|
-
measureCount,
|
|
267
|
-
systemCount,
|
|
268
|
-
commandCount,
|
|
269
|
-
groupCount,
|
|
270
|
-
measureMs: roundMs(measureMs),
|
|
271
|
-
layoutMs: roundMs(layoutMs),
|
|
272
|
-
renderMs: roundMs(renderMs),
|
|
273
|
-
finishMs: roundMs(finishMs),
|
|
274
|
-
totalMs: roundMs(measureMs + layoutMs + renderMs + finishMs),
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function nowMs(): number {
|
|
279
|
-
return globalThis.performance?.now?.() ?? Date.now();
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function roundMs(value: number): number {
|
|
283
|
-
return Math.round(value * 10) / 10;
|
|
284
|
-
}
|