vexflow-native 2.1.0 → 2.3.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 +6 -2
- 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 +13 -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/noteModifiers.js +15 -8
- package/lib/module/renderer/noteModifiers.js.map +1 -1
- package/lib/module/renderer/render.js +4 -1
- package/lib/module/renderer/render.js.map +1 -1
- package/lib/module/renderer/scoreParsing.js +4 -4
- package/lib/module/renderer/scoreParsing.js.map +1 -1
- package/lib/module/renderer/systemExtents.js +106 -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/noteModifiers.d.ts +2 -2
- package/lib/typescript/src/renderer/noteModifiers.d.ts.map +1 -1
- package/lib/typescript/src/renderer/render.d.ts.map +1 -1
- package/lib/typescript/src/renderer/scoreParsing.d.ts +3 -1
- package/lib/typescript/src/renderer/scoreParsing.d.ts.map +1 -1
- package/lib/typescript/src/renderer/systemExtents.d.ts +21 -0
- package/lib/typescript/src/renderer/systemExtents.d.ts.map +1 -0
- package/lib/typescript/src/renderer/types.d.ts +32 -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 +3 -2
- package/src/renderer/Layout/DocumentLayout.ts +65 -33
- package/src/renderer/Layout/LayoutMetrics.ts +9 -2
- package/src/renderer/constants.ts +4 -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 +28 -3
- package/src/renderer/measureModifiers.ts +7 -4
- package/src/renderer/noteModifiers.ts +11 -20
- package/src/renderer/render.tsx +10 -1
- package/src/renderer/scoreParsing.tsx +8 -4
- package/src/renderer/systemExtents.ts +143 -0
- package/src/renderer/types.ts +32 -0
- package/src/renderer/useScoreRecording.ts +27 -176
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
type DocumentLine = {
|
|
17
17
|
measures: MeasuredGroupMeasure[];
|
|
18
18
|
intrinsicWidth: number;
|
|
19
|
+
availableWidth: number;
|
|
20
|
+
indent: number;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
export function resolveDocumentEvenMeasureWidth(
|
|
@@ -34,11 +36,24 @@ export function resolveDocumentEvenMeasureWidth(
|
|
|
34
36
|
};
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
let measuresPerFullLine = Math.max(
|
|
38
40
|
1,
|
|
39
41
|
Math.floor(availableWidth / widestMeasure)
|
|
40
42
|
);
|
|
41
43
|
|
|
44
|
+
// A clef added at a system start has to fit the equal measure width too.
|
|
45
|
+
while (
|
|
46
|
+
measuresPerFullLine > 1 &&
|
|
47
|
+
measuredScore.measures.some(
|
|
48
|
+
(measure) =>
|
|
49
|
+
measure.measureIndex % measuresPerFullLine === 0 &&
|
|
50
|
+
measure.intrinsicNoteWidth + (measure.systemStartClefWidth ?? 0) >
|
|
51
|
+
availableWidth / measuresPerFullLine
|
|
52
|
+
)
|
|
53
|
+
) {
|
|
54
|
+
measuresPerFullLine -= 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
return {
|
|
43
58
|
measuresPerFullLine,
|
|
44
59
|
equalMeasureWidth: availableWidth / measuresPerFullLine,
|
|
@@ -66,7 +81,7 @@ export function layoutDocumentEvenGroup(
|
|
|
66
81
|
}
|
|
67
82
|
|
|
68
83
|
let cursorY = origin.y;
|
|
69
|
-
const systemGap = getSystemGap(options.spacing
|
|
84
|
+
const systemGap = getSystemGap(options.spacing);
|
|
70
85
|
const chunks: MeasuredGroupMeasure[][] = [];
|
|
71
86
|
|
|
72
87
|
for (
|
|
@@ -158,24 +173,35 @@ export function layoutDocumentGroup(
|
|
|
158
173
|
};
|
|
159
174
|
}
|
|
160
175
|
|
|
161
|
-
const
|
|
176
|
+
const { firstSystemIndent, lastSystemFill } = options.spacing;
|
|
177
|
+
const lines = splitDocumentLines(
|
|
178
|
+
group.measures,
|
|
179
|
+
availableWidth,
|
|
180
|
+
firstSystemIndent
|
|
181
|
+
);
|
|
162
182
|
let cursorY = origin.y;
|
|
163
|
-
const systemGap = getSystemGap(options.spacing
|
|
183
|
+
const systemGap = getSystemGap(options.spacing);
|
|
164
184
|
|
|
165
185
|
for (const [systemIndex, line] of lines.entries()) {
|
|
166
|
-
const
|
|
186
|
+
const fullWidth =
|
|
187
|
+
line.availableWidth > 0 ? line.availableWidth : line.intrinsicWidth;
|
|
188
|
+
const lineWidth =
|
|
189
|
+
lastSystemFill === 'natural' && systemIndex === lines.length - 1
|
|
190
|
+
? Math.min(fullWidth, line.intrinsicWidth)
|
|
191
|
+
: fullWidth;
|
|
167
192
|
const stretchRatio = lineWidth / line.intrinsicWidth;
|
|
168
193
|
const verticalLayout = resolveSystemVerticalLayout(
|
|
169
194
|
line.measures,
|
|
170
195
|
group.staves.length,
|
|
171
196
|
options.spacing.staffGap
|
|
172
197
|
);
|
|
173
|
-
|
|
198
|
+
const systemX = origin.x + line.indent;
|
|
199
|
+
let cursorX = systemX;
|
|
174
200
|
|
|
175
201
|
systems.push({
|
|
176
202
|
groupId: group.groupId,
|
|
177
203
|
systemIndex,
|
|
178
|
-
x:
|
|
204
|
+
x: systemX,
|
|
179
205
|
y: cursorY,
|
|
180
206
|
width: lineWidth,
|
|
181
207
|
height: verticalLayout.height,
|
|
@@ -184,8 +210,11 @@ export function layoutDocumentGroup(
|
|
|
184
210
|
measureIndices: line.measures.map((measure) => measure.measureIndex),
|
|
185
211
|
});
|
|
186
212
|
|
|
187
|
-
for (const measure of line.measures) {
|
|
188
|
-
const width =
|
|
213
|
+
for (const [lineIndex, measure] of line.measures.entries()) {
|
|
214
|
+
const width =
|
|
215
|
+
(lineIndex === 0
|
|
216
|
+
? getSystemStartWidth(measure)
|
|
217
|
+
: getMeasureLineWidth(measure)) * stretchRatio;
|
|
189
218
|
|
|
190
219
|
measures.push({
|
|
191
220
|
groupId: group.groupId,
|
|
@@ -214,40 +243,39 @@ export function layoutDocumentGroup(
|
|
|
214
243
|
|
|
215
244
|
function splitDocumentLines(
|
|
216
245
|
measures: MeasuredGroupMeasure[],
|
|
217
|
-
availableWidth: number
|
|
246
|
+
availableWidth: number,
|
|
247
|
+
firstSystemIndent: number
|
|
218
248
|
): DocumentLine[] {
|
|
219
249
|
const lines: DocumentLine[] = [];
|
|
220
|
-
let
|
|
221
|
-
let lineWidth = 0;
|
|
250
|
+
let line: DocumentLine | undefined;
|
|
222
251
|
|
|
223
252
|
for (const measure of measures) {
|
|
224
253
|
const measureWidth = getMeasureLineWidth(measure);
|
|
225
254
|
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
intrinsicWidth: lineWidth,
|
|
236
|
-
});
|
|
237
|
-
lineMeasures = [measure];
|
|
238
|
-
lineWidth = measureWidth;
|
|
255
|
+
if (
|
|
256
|
+
line &&
|
|
257
|
+
!(
|
|
258
|
+
line.availableWidth > 0 &&
|
|
259
|
+
line.intrinsicWidth + measureWidth > line.availableWidth
|
|
260
|
+
)
|
|
261
|
+
) {
|
|
262
|
+
line.measures.push(measure);
|
|
263
|
+
line.intrinsicWidth += measureWidth;
|
|
239
264
|
continue;
|
|
240
265
|
}
|
|
241
266
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
267
|
+
const indent =
|
|
268
|
+
lines.length === 0 && firstSystemIndent < availableWidth
|
|
269
|
+
? Math.max(0, firstSystemIndent)
|
|
270
|
+
: 0;
|
|
245
271
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
272
|
+
line = {
|
|
273
|
+
measures: [measure],
|
|
274
|
+
intrinsicWidth: getSystemStartWidth(measure),
|
|
275
|
+
availableWidth: availableWidth - indent,
|
|
276
|
+
indent,
|
|
277
|
+
};
|
|
278
|
+
lines.push(line);
|
|
251
279
|
}
|
|
252
280
|
|
|
253
281
|
return lines;
|
|
@@ -256,3 +284,7 @@ function splitDocumentLines(
|
|
|
256
284
|
function getMeasureLineWidth(measure: MeasuredGroupMeasure): number {
|
|
257
285
|
return Math.max(measure.intrinsicWidth, 1);
|
|
258
286
|
}
|
|
287
|
+
|
|
288
|
+
function getSystemStartWidth(measure: MeasuredGroupMeasure): number {
|
|
289
|
+
return getMeasureLineWidth(measure) + (measure.systemStartClefWidth ?? 0);
|
|
290
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RendererRect, ScoreOptions } from '../types';
|
|
1
|
+
import type { RendererRect, ScoreOptions, ScoreSpacing } from '../types';
|
|
2
2
|
|
|
3
3
|
const MIN_SYSTEM_GAP = 82;
|
|
4
4
|
const SYSTEM_GAP_DIVISOR = 8;
|
|
@@ -16,6 +16,13 @@ export function getAvailableDocumentWidth(
|
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function getSystemGap(
|
|
19
|
+
export function getSystemGap({
|
|
20
|
+
staffGap,
|
|
21
|
+
systemGap,
|
|
22
|
+
}: Pick<ScoreSpacing, 'staffGap' | 'systemGap'>): number {
|
|
23
|
+
if (systemGap !== undefined && Number.isFinite(systemGap)) {
|
|
24
|
+
return Math.max(0, systemGap);
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
return Math.max(MIN_SYSTEM_GAP, staffGap / SYSTEM_GAP_DIVISOR);
|
|
21
28
|
}
|
|
@@ -11,6 +11,9 @@ export const spacing: ScoreSpacing = {
|
|
|
11
11
|
staffGap: 96,
|
|
12
12
|
minIntrinsicSizeMultiplier: 2,
|
|
13
13
|
uniformSystemPitch: false,
|
|
14
|
+
firstSystemIndent: 0,
|
|
15
|
+
lastSystemFill: 'justify',
|
|
16
|
+
clefOnEachSystem: false,
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
export const renderOptions: RenderOptions = {
|
|
@@ -18,4 +21,5 @@ export const renderOptions: RenderOptions = {
|
|
|
18
21
|
scale: 1,
|
|
19
22
|
debug: false,
|
|
20
23
|
fixedNoteSpacing: false,
|
|
24
|
+
textFontFamily: 'Arial, Helvetica, sans-serif',
|
|
21
25
|
};
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import type { SkTypefaceFontProvider } from 'react-native-skia';
|
|
2
|
+
|
|
3
|
+
import type { VexflowRecordingCommand } from '../base';
|
|
4
|
+
import FontManager from '../base/FontManager';
|
|
5
|
+
import VexflowRecordingContext from '../base/VexflowRecordingContext';
|
|
6
|
+
import {
|
|
7
|
+
buildVexflowGroupIndex,
|
|
8
|
+
type VexflowRecordingGroupIndex,
|
|
9
|
+
} from '../base/VexflowRecordingIndex';
|
|
10
|
+
import type { Score } from '../state';
|
|
11
|
+
import { isVexflowNativeDebugEnabled } from '../shared/debug';
|
|
12
|
+
import {
|
|
13
|
+
resolveScoreColorScheme,
|
|
14
|
+
type ResolvedScoreColorScheme,
|
|
15
|
+
type ScoreColorScheme,
|
|
16
|
+
} from './colorScheme';
|
|
17
|
+
import { layoutScore, type ScoreLayoutPlan } from './layout';
|
|
18
|
+
import { measureScore, type MeasuredScore } from './measure';
|
|
19
|
+
import { renderScore } from './render';
|
|
20
|
+
import {
|
|
21
|
+
createContentViewport,
|
|
22
|
+
getRenderScale,
|
|
23
|
+
scaleItemsLayoutToViewSpace,
|
|
24
|
+
} from './scale';
|
|
25
|
+
import { withDefaultOptions } from './ScoreRenderer/utils';
|
|
26
|
+
import { coverDrawnExtents } from './systemExtents';
|
|
27
|
+
import type {
|
|
28
|
+
RendererRect,
|
|
29
|
+
RendererSize,
|
|
30
|
+
RendererType,
|
|
31
|
+
ScoreItemHooks,
|
|
32
|
+
ScoreItemsLayout,
|
|
33
|
+
ScoreOptions,
|
|
34
|
+
ScoreRendererOptions,
|
|
35
|
+
} from './types';
|
|
36
|
+
|
|
37
|
+
export interface EngraveScoreParams extends ScoreItemHooks {
|
|
38
|
+
score: Score;
|
|
39
|
+
defaultFont: string;
|
|
40
|
+
fontManager: SkTypefaceFontProvider;
|
|
41
|
+
colorScheme?: ScoreColorScheme;
|
|
42
|
+
options?: ScoreRendererOptions;
|
|
43
|
+
/** Default `document`. */
|
|
44
|
+
rendererType?: RendererType;
|
|
45
|
+
/** View-space width the score is laid out against. */
|
|
46
|
+
width: number;
|
|
47
|
+
/**
|
|
48
|
+
* View-space height. Only `infiniteScore`, which centers on it, and a
|
|
49
|
+
* score without measures read it. Default 0.
|
|
50
|
+
*/
|
|
51
|
+
height?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** One system of an engraving, in content space. */
|
|
55
|
+
export interface ScoreSystemLayout {
|
|
56
|
+
groupId: string;
|
|
57
|
+
/** Index within the staff group. */
|
|
58
|
+
systemIndex: number;
|
|
59
|
+
x: number;
|
|
60
|
+
width: number;
|
|
61
|
+
/**
|
|
62
|
+
* `y`/`height` cover the system's layout band and everything drawn for it
|
|
63
|
+
* (clefs, ledger lines, stems, modifiers, text), so clipping the commands
|
|
64
|
+
* to this band cuts nothing off.
|
|
65
|
+
*/
|
|
66
|
+
y: number;
|
|
67
|
+
height: number;
|
|
68
|
+
measureIndices: number[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ScoreEngraving {
|
|
72
|
+
/**
|
|
73
|
+
* Display list in content space (VexFlow units before `render.scale`);
|
|
74
|
+
* replay it with `renderVexflowRecordingCommands`.
|
|
75
|
+
*/
|
|
76
|
+
commands: readonly VexflowRecordingCommand[];
|
|
77
|
+
/** Content space; multiply by `render.scale` for view space. */
|
|
78
|
+
contentSize: RendererSize;
|
|
79
|
+
/** Top to bottom per staff group. */
|
|
80
|
+
systems: ScoreSystemLayout[];
|
|
81
|
+
/** View space, the value `ScoreRenderer` passes to `onItemsLayout`. */
|
|
82
|
+
itemsLayout: ScoreItemsLayout;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Engraves a score to a display list without mounting a view, for print,
|
|
87
|
+
* export or custom drawing. Same pipeline and output as `ScoreRenderer`.
|
|
88
|
+
*/
|
|
89
|
+
export function engraveScore({
|
|
90
|
+
score,
|
|
91
|
+
defaultFont,
|
|
92
|
+
fontManager,
|
|
93
|
+
colorScheme,
|
|
94
|
+
options: userOptions = {},
|
|
95
|
+
rendererType = 'document',
|
|
96
|
+
width,
|
|
97
|
+
height = 0,
|
|
98
|
+
decorateItem,
|
|
99
|
+
onDrawItem,
|
|
100
|
+
}: EngraveScoreParams): ScoreEngraving {
|
|
101
|
+
const options = withDefaultOptions(userOptions);
|
|
102
|
+
const { commands, layoutPlan, itemsLayout } = recordScore({
|
|
103
|
+
measurement: measureScoreRecording({
|
|
104
|
+
score,
|
|
105
|
+
options,
|
|
106
|
+
fontManager,
|
|
107
|
+
defaultFont,
|
|
108
|
+
decorateItem,
|
|
109
|
+
}),
|
|
110
|
+
score,
|
|
111
|
+
options,
|
|
112
|
+
rendererType,
|
|
113
|
+
viewport: { x: 0, y: 0, width, height },
|
|
114
|
+
fontManager,
|
|
115
|
+
defaultFont,
|
|
116
|
+
colorScheme: resolveScoreColorScheme(colorScheme),
|
|
117
|
+
decorateItem,
|
|
118
|
+
onDrawItem,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
commands,
|
|
123
|
+
contentSize: layoutPlan.contentSize,
|
|
124
|
+
systems: coverDrawnExtents(
|
|
125
|
+
layoutPlan.systems.map(
|
|
126
|
+
(system): ScoreSystemLayout => ({
|
|
127
|
+
groupId: system.groupId,
|
|
128
|
+
systemIndex: system.systemIndex,
|
|
129
|
+
x: system.x,
|
|
130
|
+
width: system.width,
|
|
131
|
+
y: system.y,
|
|
132
|
+
height: system.height,
|
|
133
|
+
measureIndices: system.measureIndices,
|
|
134
|
+
})
|
|
135
|
+
),
|
|
136
|
+
commands,
|
|
137
|
+
new FontManager(fontManager, defaultFont)
|
|
138
|
+
),
|
|
139
|
+
itemsLayout,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface ScoreMeasurement {
|
|
144
|
+
measuredScore: MeasuredScore;
|
|
145
|
+
measureMs: number;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface ScoreRecording {
|
|
149
|
+
/** Recorded draw commands, content-space coordinates. */
|
|
150
|
+
commands: readonly VexflowRecordingCommand[];
|
|
151
|
+
/**
|
|
152
|
+
* `commands` bucketed by `groupId` so a style-override replay can redraw
|
|
153
|
+
* just the overridden items instead of the whole recording.
|
|
154
|
+
*/
|
|
155
|
+
groupIndex: VexflowRecordingGroupIndex;
|
|
156
|
+
/**
|
|
157
|
+
* Layout plan in content space; multiply its `contentSize` by the render
|
|
158
|
+
* scale for the view-space size that drives scrolling.
|
|
159
|
+
*/
|
|
160
|
+
layoutPlan: ScoreLayoutPlan;
|
|
161
|
+
/** Emitted geometry, already converted to view space. */
|
|
162
|
+
itemsLayout: ScoreItemsLayout;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The measuring pass. It does not depend on the viewport and is the most
|
|
167
|
+
* expensive pass, so callers that re-layout cache it apart from
|
|
168
|
+
* {@link recordScore}.
|
|
169
|
+
*/
|
|
170
|
+
export function measureScoreRecording({
|
|
171
|
+
score,
|
|
172
|
+
options,
|
|
173
|
+
fontManager,
|
|
174
|
+
defaultFont,
|
|
175
|
+
decorateItem,
|
|
176
|
+
}: Pick<ScoreItemHooks, 'decorateItem'> & {
|
|
177
|
+
score: Score;
|
|
178
|
+
options: ScoreOptions;
|
|
179
|
+
fontManager: SkTypefaceFontProvider;
|
|
180
|
+
defaultFont: string;
|
|
181
|
+
}): ScoreMeasurement {
|
|
182
|
+
const measureStart = nowMs();
|
|
183
|
+
// On native, constructing a context installs it as VexFlow's text
|
|
184
|
+
// measurement canvas, so text is measured with this font setup.
|
|
185
|
+
// eslint-disable-next-line no-new
|
|
186
|
+
new VexflowRecordingContext(fontManager, defaultFont);
|
|
187
|
+
const measuredScore = measureScore(score, options, { decorateItem });
|
|
188
|
+
|
|
189
|
+
return { measuredScore, measureMs: nowMs() - measureStart };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Layout and render passes; `viewport` is view space. */
|
|
193
|
+
export function recordScore({
|
|
194
|
+
measurement,
|
|
195
|
+
score,
|
|
196
|
+
options,
|
|
197
|
+
rendererType,
|
|
198
|
+
viewport,
|
|
199
|
+
fontManager,
|
|
200
|
+
defaultFont,
|
|
201
|
+
colorScheme,
|
|
202
|
+
decorateItem,
|
|
203
|
+
onDrawItem,
|
|
204
|
+
}: ScoreItemHooks & {
|
|
205
|
+
measurement: ScoreMeasurement;
|
|
206
|
+
score: Score;
|
|
207
|
+
options: ScoreOptions;
|
|
208
|
+
rendererType: RendererType;
|
|
209
|
+
viewport: RendererRect;
|
|
210
|
+
fontManager: SkTypefaceFontProvider;
|
|
211
|
+
defaultFont: string;
|
|
212
|
+
colorScheme: ResolvedScoreColorScheme;
|
|
213
|
+
}): ScoreRecording {
|
|
214
|
+
// Layout and render run in content space against the virtual viewport;
|
|
215
|
+
// see src/renderer/scale.ts.
|
|
216
|
+
const scale = getRenderScale(options);
|
|
217
|
+
const contentViewport = createContentViewport(viewport, scale);
|
|
218
|
+
const ctx = new VexflowRecordingContext(
|
|
219
|
+
fontManager,
|
|
220
|
+
defaultFont,
|
|
221
|
+
colorScheme
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const layoutStart = nowMs();
|
|
225
|
+
const layoutPlan = layoutScore(
|
|
226
|
+
score,
|
|
227
|
+
measurement.measuredScore,
|
|
228
|
+
options,
|
|
229
|
+
rendererType,
|
|
230
|
+
contentViewport
|
|
231
|
+
);
|
|
232
|
+
const layoutMs = nowMs() - layoutStart;
|
|
233
|
+
|
|
234
|
+
const renderStart = nowMs();
|
|
235
|
+
const itemsLayout = scaleItemsLayoutToViewSpace(
|
|
236
|
+
renderScore(ctx, score, layoutPlan, options, {
|
|
237
|
+
decorateItem,
|
|
238
|
+
onDrawItem,
|
|
239
|
+
}),
|
|
240
|
+
scale
|
|
241
|
+
);
|
|
242
|
+
const renderMs = nowMs() - renderStart;
|
|
243
|
+
|
|
244
|
+
const finishStart = nowMs();
|
|
245
|
+
const commands = ctx.finish();
|
|
246
|
+
const groupIndex = buildVexflowGroupIndex(commands);
|
|
247
|
+
const finishMs = nowMs() - finishStart;
|
|
248
|
+
|
|
249
|
+
logScoreRecordingProfile({
|
|
250
|
+
commandCount: commands.length,
|
|
251
|
+
groupCount: Object.keys(groupIndex).length,
|
|
252
|
+
contentSize: layoutPlan.contentSize,
|
|
253
|
+
finishMs,
|
|
254
|
+
layoutMs,
|
|
255
|
+
measureCount: layoutPlan.measures.length,
|
|
256
|
+
measurement,
|
|
257
|
+
renderMs,
|
|
258
|
+
rendererType,
|
|
259
|
+
scoreId: score.id,
|
|
260
|
+
systemCount: layoutPlan.systems.length,
|
|
261
|
+
viewport,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
commands,
|
|
266
|
+
groupIndex,
|
|
267
|
+
layoutPlan,
|
|
268
|
+
itemsLayout,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Measurements already counted by a profile line. A cached measurement is
|
|
274
|
+
* reported once, by the first recording built on it, so summed profiles
|
|
275
|
+
* count each measure pass once.
|
|
276
|
+
*/
|
|
277
|
+
const profiledMeasurements = new WeakSet<ScoreMeasurement>();
|
|
278
|
+
|
|
279
|
+
function logScoreRecordingProfile({
|
|
280
|
+
commandCount,
|
|
281
|
+
groupCount,
|
|
282
|
+
contentSize,
|
|
283
|
+
finishMs,
|
|
284
|
+
layoutMs,
|
|
285
|
+
measureCount,
|
|
286
|
+
measurement,
|
|
287
|
+
renderMs,
|
|
288
|
+
rendererType,
|
|
289
|
+
scoreId,
|
|
290
|
+
systemCount,
|
|
291
|
+
viewport,
|
|
292
|
+
}: {
|
|
293
|
+
commandCount: number;
|
|
294
|
+
groupCount: number;
|
|
295
|
+
contentSize: { height: number; width: number };
|
|
296
|
+
finishMs: number;
|
|
297
|
+
layoutMs: number;
|
|
298
|
+
measureCount: number;
|
|
299
|
+
measurement: ScoreMeasurement;
|
|
300
|
+
renderMs: number;
|
|
301
|
+
rendererType: RendererType;
|
|
302
|
+
scoreId: string;
|
|
303
|
+
systemCount: number;
|
|
304
|
+
viewport: RendererRect;
|
|
305
|
+
}) {
|
|
306
|
+
if (!isVexflowNativeDebugEnabled()) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const measureMs = profiledMeasurements.has(measurement)
|
|
311
|
+
? 0
|
|
312
|
+
: measurement.measureMs;
|
|
313
|
+
profiledMeasurements.add(measurement);
|
|
314
|
+
|
|
315
|
+
console.info('[ScoreRenderer] recording profile', {
|
|
316
|
+
scoreId,
|
|
317
|
+
rendererType,
|
|
318
|
+
viewport,
|
|
319
|
+
contentSize,
|
|
320
|
+
measureCount,
|
|
321
|
+
systemCount,
|
|
322
|
+
commandCount,
|
|
323
|
+
groupCount,
|
|
324
|
+
measureMs: roundMs(measureMs),
|
|
325
|
+
layoutMs: roundMs(layoutMs),
|
|
326
|
+
renderMs: roundMs(renderMs),
|
|
327
|
+
finishMs: roundMs(finishMs),
|
|
328
|
+
totalMs: roundMs(measureMs + layoutMs + renderMs + finishMs),
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function nowMs(): number {
|
|
333
|
+
return globalThis.performance?.now?.() ?? Date.now();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function roundMs(value: number): number {
|
|
337
|
+
return Math.round(value * 10) / 10;
|
|
338
|
+
}
|
package/src/renderer/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export { default as ScoreRenderer } from './ScoreRenderer';
|
|
2
|
+
export {
|
|
3
|
+
engraveScore,
|
|
4
|
+
type EngraveScoreParams,
|
|
5
|
+
type ScoreEngraving,
|
|
6
|
+
type ScoreSystemLayout,
|
|
7
|
+
} from './engraveScore';
|
|
2
8
|
export * from './colorScheme';
|
|
3
9
|
export * from './types';
|
|
4
10
|
export {
|
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') {
|
|
@@ -108,6 +113,7 @@ export function measureScore(
|
|
|
108
113
|
attachmentsByOwner,
|
|
109
114
|
staff,
|
|
110
115
|
directions: voiceIndex === 0 ? measure.directions : undefined,
|
|
116
|
+
textFontFamily: options.render.textFontFamily,
|
|
111
117
|
itemContext: decorateItem
|
|
112
118
|
? { decorateItem, staff, measureIndex }
|
|
113
119
|
: undefined,
|
|
@@ -139,11 +145,26 @@ export function measureScore(
|
|
|
139
145
|
// Clef and time signature sit before the note area, so the intrinsic
|
|
140
146
|
// width must include them or an empty measure with a time signature
|
|
141
147
|
// measures ~0 wide and the signature clips.
|
|
148
|
+
const leftModifierWidth = measureLeftModifierWidth(
|
|
149
|
+
staffMeasurementContexts
|
|
150
|
+
);
|
|
142
151
|
const intrinsicNoteWidth =
|
|
143
152
|
(allVoices.length > 0
|
|
144
153
|
? formatter.preCalculateMinTotalWidth(allVoices) *
|
|
145
154
|
Math.max(1, minIntrinsicSizeMultiplier)
|
|
146
|
-
: 0) +
|
|
155
|
+
: 0) + leftModifierWidth;
|
|
156
|
+
const systemStartClefWidth =
|
|
157
|
+
clefOnEachSystem &&
|
|
158
|
+
measureLeftModifierWidth(
|
|
159
|
+
staffMeasurementContexts.map((context) => ({
|
|
160
|
+
...context,
|
|
161
|
+
modifiers: resolveMeasureModifiers(
|
|
162
|
+
context.measure,
|
|
163
|
+
measureIndex,
|
|
164
|
+
true
|
|
165
|
+
),
|
|
166
|
+
}))
|
|
167
|
+
) - leftModifierWidth;
|
|
147
168
|
const staffBounds = measureStaffVerticalBounds({
|
|
148
169
|
allVoices,
|
|
149
170
|
intrinsicNoteWidth,
|
|
@@ -158,6 +179,7 @@ export function measureScore(
|
|
|
158
179
|
staffIds: group.staffIds,
|
|
159
180
|
staffBounds,
|
|
160
181
|
intrinsicNoteWidth,
|
|
182
|
+
...(systemStartClefWidth ? { systemStartClefWidth } : {}),
|
|
161
183
|
});
|
|
162
184
|
} catch (error) {
|
|
163
185
|
throw new Error(
|
|
@@ -186,7 +208,10 @@ const MODIFIER_PROBE_STAVE_WIDTH = 500;
|
|
|
186
208
|
* between a bare probe stave and one carrying the resolved modifiers.
|
|
187
209
|
*/
|
|
188
210
|
function measureLeftModifierWidth(
|
|
189
|
-
staffMeasurementContexts:
|
|
211
|
+
staffMeasurementContexts: Pick<
|
|
212
|
+
StaffMeasurementContext,
|
|
213
|
+
'resolvedState' | 'modifiers'
|
|
214
|
+
>[]
|
|
190
215
|
): number {
|
|
191
216
|
return staffMeasurementContexts.reduce(
|
|
192
217
|
(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',
|