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.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/lib/module/renderer/Layout/DocumentLayout.js +36 -32
  3. package/lib/module/renderer/Layout/DocumentLayout.js.map +1 -1
  4. package/lib/module/renderer/Layout/LayoutMetrics.js +7 -1
  5. package/lib/module/renderer/Layout/LayoutMetrics.js.map +1 -1
  6. package/lib/module/renderer/constants.js +6 -2
  7. package/lib/module/renderer/constants.js.map +1 -1
  8. package/lib/module/renderer/engraveScore.js +202 -0
  9. package/lib/module/renderer/engraveScore.js.map +1 -0
  10. package/lib/module/renderer/index.js +1 -0
  11. package/lib/module/renderer/index.js.map +1 -1
  12. package/lib/module/renderer/layout.js +4 -1
  13. package/lib/module/renderer/layout.js.map +1 -1
  14. package/lib/module/renderer/measure.js +13 -3
  15. package/lib/module/renderer/measure.js.map +1 -1
  16. package/lib/module/renderer/measureModifiers.js +5 -4
  17. package/lib/module/renderer/measureModifiers.js.map +1 -1
  18. package/lib/module/renderer/noteModifiers.js +15 -8
  19. package/lib/module/renderer/noteModifiers.js.map +1 -1
  20. package/lib/module/renderer/render.js +4 -1
  21. package/lib/module/renderer/render.js.map +1 -1
  22. package/lib/module/renderer/scoreParsing.js +4 -4
  23. package/lib/module/renderer/scoreParsing.js.map +1 -1
  24. package/lib/module/renderer/systemExtents.js +106 -0
  25. package/lib/module/renderer/systemExtents.js.map +1 -0
  26. package/lib/module/renderer/useScoreRecording.js +19 -109
  27. package/lib/module/renderer/useScoreRecording.js.map +1 -1
  28. package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts.map +1 -1
  29. package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts +2 -2
  30. package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts.map +1 -1
  31. package/lib/typescript/src/renderer/constants.d.ts.map +1 -1
  32. package/lib/typescript/src/renderer/engraveScore.d.ts +101 -0
  33. package/lib/typescript/src/renderer/engraveScore.d.ts.map +1 -0
  34. package/lib/typescript/src/renderer/index.d.ts +1 -0
  35. package/lib/typescript/src/renderer/index.d.ts.map +1 -1
  36. package/lib/typescript/src/renderer/layout.d.ts +1 -0
  37. package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
  38. package/lib/typescript/src/renderer/measure.d.ts +5 -0
  39. package/lib/typescript/src/renderer/measure.d.ts.map +1 -1
  40. package/lib/typescript/src/renderer/measureModifiers.d.ts +4 -3
  41. package/lib/typescript/src/renderer/measureModifiers.d.ts.map +1 -1
  42. package/lib/typescript/src/renderer/noteModifiers.d.ts +2 -2
  43. package/lib/typescript/src/renderer/noteModifiers.d.ts.map +1 -1
  44. package/lib/typescript/src/renderer/render.d.ts.map +1 -1
  45. package/lib/typescript/src/renderer/scoreParsing.d.ts +3 -1
  46. package/lib/typescript/src/renderer/scoreParsing.d.ts.map +1 -1
  47. package/lib/typescript/src/renderer/systemExtents.d.ts +21 -0
  48. package/lib/typescript/src/renderer/systemExtents.d.ts.map +1 -0
  49. package/lib/typescript/src/renderer/types.d.ts +32 -0
  50. package/lib/typescript/src/renderer/types.d.ts.map +1 -1
  51. package/lib/typescript/src/renderer/useScoreRecording.d.ts +3 -20
  52. package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -1
  53. package/package.json +3 -2
  54. package/src/renderer/Layout/DocumentLayout.ts +65 -33
  55. package/src/renderer/Layout/LayoutMetrics.ts +9 -2
  56. package/src/renderer/constants.ts +4 -0
  57. package/src/renderer/engraveScore.ts +338 -0
  58. package/src/renderer/index.ts +6 -0
  59. package/src/renderer/layout.ts +5 -2
  60. package/src/renderer/measure.tsx +28 -3
  61. package/src/renderer/measureModifiers.ts +7 -4
  62. package/src/renderer/noteModifiers.ts +11 -20
  63. package/src/renderer/render.tsx +10 -1
  64. package/src/renderer/scoreParsing.tsx +8 -4
  65. package/src/renderer/systemExtents.ts +143 -0
  66. package/src/renderer/types.ts +32 -0
  67. package/src/renderer/useScoreRecording.ts +27 -176
@@ -24,6 +24,7 @@ import type {
24
24
  NoteAttachment,
25
25
  Pitch,
26
26
  } from '../state';
27
+ import { renderOptions } from './constants';
27
28
  import { durationToVF, pitchToVFKey } from './vfKeys';
28
29
 
29
30
  /**
@@ -62,23 +63,11 @@ const DYNAMIC_GLYPHS: Record<Dynamic, string> = {
62
63
 
63
64
  const DYNAMIC_FONT_SIZE = 30;
64
65
 
65
- const ANNOTATION_FONT = {
66
- family: 'Arial, Helvetica, sans-serif',
67
- size: 10,
68
- weight: 'bold',
69
- };
66
+ const ANNOTATION_FONT = { size: 10, weight: 'bold' };
70
67
 
71
- const LYRIC_FONT = {
72
- family: ANNOTATION_FONT.family,
73
- size: 10,
74
- weight: 'normal',
75
- };
68
+ const LYRIC_FONT = { size: 10, weight: 'normal' };
76
69
 
77
- const DIRECTION_FONT = {
78
- family: ANNOTATION_FONT.family,
79
- size: 11,
80
- weight: 'bold',
81
- };
70
+ const DIRECTION_FONT = { size: 11, weight: 'bold' };
82
71
 
83
72
  /** `GhostNote`s have no glyphs, so their element box is the origin. */
84
73
  export function hasNoteHeads(note: StemmableNote): note is StaveNote {
@@ -163,7 +152,8 @@ function byVerse(left: LyricAttachment, right: LyricAttachment) {
163
152
  export function applyNoteModifiers(
164
153
  note: StaveNote,
165
154
  clef: Clef,
166
- attachments: NoteAttachment[] | undefined
155
+ attachments: NoteAttachment[] | undefined,
156
+ textFontFamily: string = renderOptions.textFontFamily
167
157
  ) {
168
158
  if (!attachments) {
169
159
  return;
@@ -187,7 +177,7 @@ export function applyNoteModifiers(
187
177
  if (attachment.type === 'annotation') {
188
178
  const annotation = new VFAnnotation(attachment.text);
189
179
 
190
- annotation.setFont(ANNOTATION_FONT);
180
+ annotation.setFont({ family: textFontFamily, ...ANNOTATION_FONT });
191
181
  annotation.setVerticalJustification(
192
182
  verticalJustification(attachment.placement ?? 'below')
193
183
  );
@@ -215,7 +205,7 @@ export function applyNoteModifiers(
215
205
  .forEach((attachment) => {
216
206
  const lyric = new VFAnnotation(attachment.text);
217
207
 
218
- lyric.setFont(LYRIC_FONT);
208
+ lyric.setFont({ family: textFontFamily, ...LYRIC_FONT });
219
209
  lyric.setVerticalJustification(AnnotationVerticalJustify.BOTTOM);
220
210
  note.addModifier(lyric, 0);
221
211
  });
@@ -270,7 +260,8 @@ function applyGraceNoteGroup(
270
260
  */
271
261
  export function applyMeasureDirections(
272
262
  notes: readonly StemmableNote[],
273
- directions: readonly Direction[] | undefined
263
+ directions: readonly Direction[] | undefined,
264
+ textFontFamily: string = renderOptions.textFontFamily
274
265
  ) {
275
266
  if (!directions?.length) {
276
267
  return;
@@ -289,7 +280,7 @@ export function applyMeasureDirections(
289
280
 
290
281
  const annotation = new VFAnnotation(direction.text);
291
282
 
292
- annotation.setFont(DIRECTION_FONT);
283
+ annotation.setFont({ family: textFontFamily, ...DIRECTION_FONT });
293
284
  annotation.setVerticalJustification(
294
285
  verticalJustification(direction.placement ?? 'above')
295
286
  );
@@ -72,6 +72,8 @@ 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,
76
+ textFontFamily: options.render.textFontFamily,
75
77
  ...hooks,
76
78
  },
77
79
  itemsLayout
@@ -101,6 +103,8 @@ interface RenderMeasureOptions extends ScoreItemHooks {
101
103
  isFirstMeasureInSystem: boolean;
102
104
  isLastMeasureInSystem: boolean;
103
105
  fixedNoteSpacing: boolean;
106
+ clefOnEachSystem: boolean;
107
+ textFontFamily: string;
104
108
  }
105
109
 
106
110
  function renderMeasure(
@@ -135,6 +139,7 @@ function renderMeasure(
135
139
  attachmentsByOwner,
136
140
  staff,
137
141
  directions: voiceIndex === 0 ? measure.directions : undefined,
142
+ textFontFamily: options.textFontFamily,
138
143
  itemContext: options.decorateItem
139
144
  ? {
140
145
  decorateItem: options.decorateItem,
@@ -187,7 +192,11 @@ function renderMeasure(
187
192
 
188
193
  applyMeasureModifiers(
189
194
  stave,
190
- resolveMeasureModifiers(measure, measurePlan.measureIndex),
195
+ resolveMeasureModifiers(
196
+ measure,
197
+ measurePlan.measureIndex,
198
+ options.clefOnEachSystem && options.isFirstMeasureInSystem
199
+ ),
191
200
  resolvedState
192
201
  );
193
202
  stave.setContext(ctx).draw();
@@ -62,6 +62,8 @@ export interface MakeVFVoiceOptions {
62
62
  staff?: Staff;
63
63
  /** Measure directions drawn on this voice's first drawn item. */
64
64
  directions?: Direction[];
65
+ /** `RenderOptions.textFontFamily`; absent = its default. */
66
+ textFontFamily?: string;
65
67
  itemContext?: {
66
68
  decorateItem: DecorateItem;
67
69
  staff: Staff;
@@ -136,7 +138,8 @@ export function voiceItemToStaveNote(
136
138
  item: VoiceItem,
137
139
  clef: Clef,
138
140
  attachments?: NoteAttachment[],
139
- decorate?: ItemDecorator
141
+ decorate?: ItemDecorator,
142
+ textFontFamily?: string
140
143
  ): VFVoiceNote {
141
144
  if (
142
145
  item.type === 'rest' &&
@@ -155,7 +158,7 @@ export function voiceItemToStaveNote(
155
158
  const applied =
156
159
  (item.type === 'rest' ? restAttachments(attachments) : attachments) ?? [];
157
160
 
158
- applyNoteModifiers(note, clef, applied);
161
+ applyNoteModifiers(note, clef, applied, textFontFamily);
159
162
  decorate?.(item, note, applied);
160
163
 
161
164
  return note;
@@ -296,10 +299,11 @@ export function makeVFVoice(
296
299
  item,
297
300
  itemClef,
298
301
  attachmentsByOwner.get(item.id),
299
- decorate
302
+ decorate,
303
+ options.textFontFamily
300
304
  );
301
305
  });
302
- applyMeasureDirections(notes, options.directions);
306
+ applyMeasureDirections(notes, options.directions, options.textFontFamily);
303
307
 
304
308
  const noteByItemId = new Map<string, VFVoiceNote>();
305
309
  voice.items.forEach((item, index) =>
@@ -0,0 +1,143 @@
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
+ type MeasuringFont = Pick<SkFont, 'measureText'>;
8
+
9
+ /** The part of `FontManager` the extents need. */
10
+ interface TextMeasurer {
11
+ createSkFont: (
12
+ ...descriptor: Parameters<FontManager['createSkFont']>
13
+ ) => MeasuringFont;
14
+ }
15
+
16
+ interface VerticalExtent {
17
+ top: number;
18
+ bottom: number;
19
+ }
20
+
21
+ interface VerticalBand {
22
+ y: number;
23
+ height: number;
24
+ }
25
+
26
+ /**
27
+ * Grows each band to cover everything the recording draws for it. A command
28
+ * belongs to the band its vertical centre is in, or else the nearest one.
29
+ * Curve control points count as drawn, so a band can come out slightly taller
30
+ * than its ink, never shorter.
31
+ */
32
+ export function coverDrawnExtents<Band extends VerticalBand>(
33
+ bands: readonly Band[],
34
+ commands: readonly VexflowRecordingCommand[],
35
+ fontManager: TextMeasurer
36
+ ): Band[] {
37
+ const extents = bands.map(
38
+ (band): VerticalExtent => ({ top: band.y, bottom: band.y + band.height })
39
+ );
40
+ const textExtents = new Map<MeasuringFont, Map<string, VerticalExtent>>();
41
+
42
+ for (const command of commands) {
43
+ const drawn = commandExtent(command, fontManager, textExtents);
44
+ const extent = drawn && nearestExtent(extents, bands, drawn);
45
+
46
+ if (drawn && extent) {
47
+ extent.top = Math.min(extent.top, drawn.top);
48
+ extent.bottom = Math.max(extent.bottom, drawn.bottom);
49
+ }
50
+ }
51
+
52
+ return bands.map((band, index) => ({
53
+ ...band,
54
+ y: extents[index]!.top,
55
+ height: extents[index]!.bottom - extents[index]!.top,
56
+ }));
57
+ }
58
+
59
+ function nearestExtent(
60
+ extents: VerticalExtent[],
61
+ bands: readonly VerticalBand[],
62
+ drawn: VerticalExtent
63
+ ): VerticalExtent | undefined {
64
+ const centre = (drawn.top + drawn.bottom) / 2;
65
+ let nearest: VerticalExtent | undefined;
66
+ let nearestDistance = Infinity;
67
+
68
+ bands.forEach((band, index) => {
69
+ const distance = Math.max(band.y - centre, centre - band.y - band.height);
70
+
71
+ if (distance < nearestDistance) {
72
+ nearest = extents[index];
73
+ nearestDistance = distance;
74
+ }
75
+ });
76
+
77
+ return nearest;
78
+ }
79
+
80
+ function commandExtent(
81
+ command: VexflowRecordingCommand,
82
+ fontManager: TextMeasurer,
83
+ textExtents: Map<MeasuringFont, Map<string, VerticalExtent>>
84
+ ): VerticalExtent | undefined {
85
+ switch (command.type) {
86
+ case 'fillRect':
87
+ return {
88
+ top: command.rect.y,
89
+ bottom: command.rect.y + command.rect.height,
90
+ };
91
+ case 'fillPath':
92
+ return pathExtent(command.path, 0);
93
+ case 'strokePath':
94
+ return pathExtent(command.path, (command.paint.strokeWidth ?? 0) / 2);
95
+ case 'fillText': {
96
+ const { font, size, weight, style } = command.font;
97
+ const skFont = fontManager.createSkFont(font, size, weight, style);
98
+ const byText = textExtents.get(skFont) ?? new Map();
99
+ let glyphs = byText.get(command.text);
100
+
101
+ if (!glyphs) {
102
+ const rect = skFont.measureText(command.text);
103
+
104
+ glyphs = { top: rect.y, bottom: rect.y + rect.height };
105
+ byText.set(command.text, glyphs);
106
+ textExtents.set(skFont, byText);
107
+ }
108
+
109
+ return {
110
+ top: command.y + glyphs.top,
111
+ bottom: command.y + glyphs.bottom,
112
+ };
113
+ }
114
+ default:
115
+ return undefined;
116
+ }
117
+ }
118
+
119
+ function pathExtent(
120
+ path: VexflowRecordingPathCommand[],
121
+ outset: number
122
+ ): VerticalExtent | undefined {
123
+ const ys = path.flatMap((segment) => {
124
+ switch (segment.type) {
125
+ case 'moveTo':
126
+ case 'lineTo':
127
+ return [segment.y];
128
+ case 'quadTo':
129
+ return [segment.cpy, segment.y];
130
+ case 'cubicTo':
131
+ return [segment.cp1y, segment.cp2y, segment.y];
132
+ case 'addRect':
133
+ case 'addArc':
134
+ return [segment.rect.y, segment.rect.y + segment.rect.height];
135
+ default:
136
+ return [];
137
+ }
138
+ });
139
+
140
+ return ys.length > 0
141
+ ? { top: Math.min(...ys) - outset, bottom: Math.max(...ys) + outset }
142
+ : undefined;
143
+ }
@@ -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 {
@@ -172,6 +197,13 @@ export interface RenderOptions {
172
197
  * step-editor previews; default false (classic engraving spacing).
173
198
  */
174
199
  fixedNoteSpacing: boolean;
200
+ /**
201
+ * Font family list for the text drawn on a score: annotations, lyrics and
202
+ * text directions. A family the font provider holds is taken from it;
203
+ * otherwise the system font manager resolves the list. Default
204
+ * `Arial, Helvetica, sans-serif`.
205
+ */
206
+ textFontFamily: string;
175
207
  }
176
208
 
177
209
  export interface ScoreOptions {
@@ -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
- export interface ScoreRecording {
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
- // Measuring does not depend on the viewport and is the most expensive pass,
72
- // so it is cached apart from layout and render.
73
- const measurement = useMemo((): ScoreMeasurement | null => {
74
- if (!enabled) {
75
- return null;
76
- }
77
-
78
- const measureStart = nowMs();
79
- // On native, constructing a context installs it as VexFlow's text
80
- // measurement canvas, so text is measured with this font setup.
81
- // eslint-disable-next-line no-new
82
- new VexflowRecordingContext(fontManager, defaultFont);
83
- const measuredScore = measureScore(score, options, { decorateItem });
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
- // Layout and render run in content space against the virtual viewport;
117
- // see src/renderer/scale.ts.
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
- }