vexflow-native 1.8.0 → 2.0.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 +71 -403
- package/lib/module/base/FontManager.js +5 -5
- package/lib/module/base/FontManager.js.map +1 -1
- package/lib/module/base/VexflowCanvas.js +1 -1
- package/lib/module/base/VexflowCanvas.js.map +1 -1
- package/lib/module/base/VexflowRecordingContext.js +2 -0
- package/lib/module/base/VexflowRecordingContext.js.map +1 -1
- package/lib/module/base/VexflowRecordingReplay.js +1 -1
- package/lib/module/base/VexflowRecordingReplay.js.map +1 -1
- package/lib/module/base/index.js +1 -0
- package/lib/module/base/index.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js +24 -7
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js +11 -3
- package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/Spanners.js +21 -5
- package/lib/module/musicxml/MusicXmlParser/Spanners.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/mappers.js +1 -1
- package/lib/module/musicxml/MusicXmlParser/mappers.js.map +1 -1
- package/lib/module/{state/constants.js → percussion/index.js} +3 -3
- package/lib/module/percussion/index.js.map +1 -0
- package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js +4 -3
- package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScorePlayhead.js +1 -1
- package/lib/module/renderer/ScoreRenderer/ScorePlayhead.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +5 -1
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/utils.js +1 -1
- package/lib/module/renderer/ScoreRenderer/utils.js.map +1 -1
- package/lib/module/renderer/fixedNoteSpacing.js +56 -0
- package/lib/module/renderer/fixedNoteSpacing.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/itemLayout.js +108 -0
- package/lib/module/renderer/itemLayout.js.map +1 -0
- package/lib/module/renderer/measure.js +30 -106
- package/lib/module/renderer/measure.js.map +1 -1
- package/lib/module/renderer/measureBounds.js +73 -0
- package/lib/module/renderer/measureBounds.js.map +1 -0
- package/lib/module/renderer/measureModifiers.js +99 -0
- package/lib/module/renderer/measureModifiers.js.map +1 -0
- package/lib/module/renderer/noteModifiers.js +212 -0
- package/lib/module/renderer/noteModifiers.js.map +1 -0
- package/lib/module/renderer/render.js +33 -116
- package/lib/module/renderer/render.js.map +1 -1
- package/lib/module/renderer/scale.js +16 -2
- package/lib/module/renderer/scale.js.map +1 -1
- package/lib/module/renderer/scoreParsing.js +37 -199
- package/lib/module/renderer/scoreParsing.js.map +1 -1
- package/lib/module/renderer/stave.js +19 -3
- package/lib/module/renderer/stave.js.map +1 -1
- package/lib/module/renderer/useScoreRecording.js +10 -3
- package/lib/module/renderer/useScoreRecording.js.map +1 -1
- package/lib/module/renderer/vfKeys.js +72 -0
- package/lib/module/renderer/vfKeys.js.map +1 -0
- package/lib/module/state/index.js +1 -1
- package/lib/module/state/index.js.map +1 -1
- package/lib/typescript/src/base/FontManager.d.ts +3 -2
- package/lib/typescript/src/base/FontManager.d.ts.map +1 -1
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts +2 -1
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -1
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts +1 -1
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts.map +1 -1
- package/lib/typescript/src/base/index.d.ts +1 -0
- package/lib/typescript/src/base/index.d.ts.map +1 -1
- package/lib/typescript/src/base/types.d.ts +1 -1
- package/lib/typescript/src/base/types.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts +4 -2
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts +6 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts +6 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/index.d.ts +1 -0
- package/lib/typescript/src/musicxml/index.d.ts.map +1 -1
- package/lib/typescript/src/percussion/index.d.ts +4 -0
- package/lib/typescript/src/percussion/index.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScorePlayhead.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScorePlayhead.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts.map +1 -1
- package/lib/typescript/src/renderer/fixedNoteSpacing.d.ts +17 -0
- package/lib/typescript/src/renderer/fixedNoteSpacing.d.ts.map +1 -0
- package/lib/typescript/src/renderer/index.d.ts +2 -0
- package/lib/typescript/src/renderer/index.d.ts.map +1 -1
- package/lib/typescript/src/renderer/itemLayout.d.ts +23 -0
- package/lib/typescript/src/renderer/itemLayout.d.ts.map +1 -0
- package/lib/typescript/src/renderer/layout.d.ts +1 -1
- package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
- package/lib/typescript/src/renderer/measure.d.ts +3 -6
- package/lib/typescript/src/renderer/measure.d.ts.map +1 -1
- package/lib/typescript/src/renderer/measureBounds.d.ts +13 -0
- package/lib/typescript/src/renderer/measureBounds.d.ts.map +1 -0
- package/lib/typescript/src/renderer/measureModifiers.d.ts +20 -0
- package/lib/typescript/src/renderer/measureModifiers.d.ts.map +1 -0
- package/lib/typescript/src/renderer/noteModifiers.d.ts +29 -0
- package/lib/typescript/src/renderer/noteModifiers.d.ts.map +1 -0
- package/lib/typescript/src/renderer/render.d.ts +2 -27
- package/lib/typescript/src/renderer/render.d.ts.map +1 -1
- package/lib/typescript/src/renderer/scale.d.ts.map +1 -1
- package/lib/typescript/src/renderer/scoreParsing.d.ts +14 -42
- package/lib/typescript/src/renderer/scoreParsing.d.ts.map +1 -1
- package/lib/typescript/src/renderer/stave.d.ts +2 -0
- package/lib/typescript/src/renderer/stave.d.ts.map +1 -1
- package/lib/typescript/src/renderer/types.d.ts +52 -3
- package/lib/typescript/src/renderer/types.d.ts.map +1 -1
- package/lib/typescript/src/renderer/useScoreRecording.d.ts +3 -3
- package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -1
- package/lib/typescript/src/renderer/vfKeys.d.ts +17 -0
- package/lib/typescript/src/renderer/vfKeys.d.ts.map +1 -0
- package/lib/typescript/src/state/index.d.ts +1 -1
- package/lib/typescript/src/state/index.d.ts.map +1 -1
- package/lib/typescript/src/state/types.d.ts +23 -5
- package/lib/typescript/src/state/types.d.ts.map +1 -1
- package/package.json +31 -17
- package/src/base/FontManager.ts +5 -11
- package/src/base/TextMeasureContext.ts +1 -1
- package/src/base/VexflowCanvas.tsx +1 -1
- package/src/base/VexflowRecordingContext.ts +2 -4
- package/src/base/VexflowRecordingReplay.ts +1 -1
- package/src/base/index.ts +1 -0
- package/src/base/types.ts +1 -1
- package/src/musicxml/MusicXmlParser/InternalTypes.ts +5 -2
- package/src/musicxml/MusicXmlParser/MeasureParser.ts +36 -7
- package/src/musicxml/MusicXmlParser/MusicXmlDirections.ts +25 -8
- package/src/musicxml/MusicXmlParser/Spanners.ts +27 -4
- package/src/musicxml/MusicXmlParser/mappers.ts +7 -0
- package/src/musicxml/index.ts +1 -0
- package/src/percussion/index.ts +7 -0
- package/src/renderer/Layout/VerticalSpacing.ts +1 -1
- package/src/renderer/ScoreRenderer/ScoreOverlayPicture.tsx +4 -7
- package/src/renderer/ScoreRenderer/ScorePlayhead.tsx +1 -1
- package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +5 -7
- package/src/renderer/ScoreRenderer/types.ts +1 -4
- package/src/renderer/ScoreRenderer/utils.ts +1 -1
- package/src/renderer/fixedNoteSpacing.ts +78 -0
- package/src/renderer/index.ts +8 -0
- package/src/renderer/itemLayout.ts +137 -0
- package/src/renderer/layout.ts +1 -1
- package/src/renderer/measure.tsx +84 -186
- package/src/renderer/measureBounds.ts +109 -0
- package/src/renderer/measureModifiers.ts +133 -0
- package/src/renderer/noteModifiers.ts +298 -0
- package/src/renderer/render.tsx +59 -169
- package/src/renderer/scale.ts +21 -1
- package/src/renderer/scoreParsing.tsx +77 -288
- package/src/renderer/stave.ts +22 -3
- package/src/renderer/types.ts +66 -3
- package/src/renderer/useScoreRecording.ts +12 -4
- package/src/renderer/vfKeys.ts +88 -0
- package/src/state/index.ts +1 -1
- package/src/state/types.ts +30 -5
- package/lib/module/musicxml/testfiles/lg-8102429.xml +0 -79620
- package/lib/module/state/constants.js.map +0 -1
- package/lib/typescript/src/state/constants.d.ts +0 -4
- package/lib/typescript/src/state/constants.d.ts.map +0 -1
- package/src/musicxml/testfiles/lg-8102429.xml +0 -79620
- package/src/state/constants.ts +0 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Direction,
|
|
2
|
-
import type { ParserState } from './InternalTypes';
|
|
1
|
+
import type { Direction, Tempo } from '../../state';
|
|
2
|
+
import type { ParserState, PendingDynamic } from './InternalTypes';
|
|
3
3
|
import { dynamicsFromElement, otherDynamicsText } from './mappers';
|
|
4
4
|
import {
|
|
5
5
|
attr,
|
|
@@ -10,12 +10,22 @@ import {
|
|
|
10
10
|
type XmlElement,
|
|
11
11
|
} from './XmlOrder';
|
|
12
12
|
|
|
13
|
+
export type ParsedDirection = {
|
|
14
|
+
/** 0-based; unvalidated, NaN for a non-numeric `<staff>`. */
|
|
15
|
+
staffIndex: number;
|
|
16
|
+
directions: Direction[];
|
|
17
|
+
};
|
|
18
|
+
|
|
13
19
|
export function parseDirection(
|
|
14
20
|
direction: XmlElement,
|
|
15
21
|
state: ParserState
|
|
16
|
-
):
|
|
17
|
-
const
|
|
18
|
-
|
|
22
|
+
): ParsedDirection {
|
|
23
|
+
const explicitPlacement = attr(direction, 'placement');
|
|
24
|
+
const dynamicPlacement =
|
|
25
|
+
explicitPlacement === 'above' || explicitPlacement === 'below'
|
|
26
|
+
? explicitPlacement
|
|
27
|
+
: undefined;
|
|
28
|
+
const placement = dynamicPlacement ?? 'above';
|
|
19
29
|
const staffNumber = childText(direction, 'staff') ?? '1';
|
|
20
30
|
const directions: Direction[] = [];
|
|
21
31
|
const soundTempo = optionalChild(direction, 'sound')?.attributes.tempo;
|
|
@@ -40,7 +50,14 @@ export function parseDirection(
|
|
|
40
50
|
const otherText = otherDynamicsText(dynamics);
|
|
41
51
|
|
|
42
52
|
if (parsedDynamics.length) {
|
|
43
|
-
addPendingDynamics(
|
|
53
|
+
addPendingDynamics(
|
|
54
|
+
state,
|
|
55
|
+
staffNumber,
|
|
56
|
+
parsedDynamics.map((dynamic) => ({
|
|
57
|
+
dynamic,
|
|
58
|
+
placement: dynamicPlacement,
|
|
59
|
+
}))
|
|
60
|
+
);
|
|
44
61
|
}
|
|
45
62
|
|
|
46
63
|
if (otherText) {
|
|
@@ -64,7 +81,7 @@ export function parseDirection(
|
|
|
64
81
|
});
|
|
65
82
|
}
|
|
66
83
|
|
|
67
|
-
return directions;
|
|
84
|
+
return { staffIndex: Number(staffNumber) - 1, directions };
|
|
68
85
|
}
|
|
69
86
|
|
|
70
87
|
function parseTempo(value: string): Tempo {
|
|
@@ -77,7 +94,7 @@ function parseTempo(value: string): Tempo {
|
|
|
77
94
|
function addPendingDynamics(
|
|
78
95
|
state: ParserState,
|
|
79
96
|
staffNumber: string,
|
|
80
|
-
dynamics:
|
|
97
|
+
dynamics: PendingDynamic[]
|
|
81
98
|
) {
|
|
82
99
|
const pending = state.pendingDynamics.get(staffNumber) ?? [];
|
|
83
100
|
state.pendingDynamics.set(staffNumber, [...pending, ...dynamics]);
|
|
@@ -11,32 +11,55 @@ import {
|
|
|
11
11
|
type XmlElement,
|
|
12
12
|
} from './XmlOrder';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* `pitchIndex` is the chord-tone position of `note` inside its owner chord
|
|
16
|
+
* (undefined for a standalone note): a chord tone's articulation joins the
|
|
17
|
+
* owner's existing same-articulation attachment instead of adding a glyph.
|
|
18
|
+
*/
|
|
14
19
|
export function applyNoteAttachments(
|
|
15
20
|
note: XmlElement,
|
|
16
21
|
itemId: string,
|
|
17
22
|
staffNumber: string,
|
|
18
23
|
voiceId: string,
|
|
19
|
-
state: ParserState
|
|
24
|
+
state: ParserState,
|
|
25
|
+
pitchIndex?: number
|
|
20
26
|
) {
|
|
21
27
|
const notations = optionalChild(note, 'notations');
|
|
22
28
|
const pendingDynamics = state.pendingDynamics.get(staffNumber) ?? [];
|
|
23
29
|
|
|
24
|
-
pendingDynamics.forEach((
|
|
30
|
+
pendingDynamics.forEach((pending, index) => {
|
|
25
31
|
state.attachments.push({
|
|
26
32
|
id: `${itemId}-dynamic-${index.toString()}`,
|
|
27
33
|
ownerId: itemId,
|
|
28
34
|
type: 'dynamic',
|
|
29
|
-
|
|
35
|
+
...pending,
|
|
30
36
|
});
|
|
31
37
|
});
|
|
32
38
|
state.pendingDynamics.delete(staffNumber);
|
|
33
39
|
|
|
34
40
|
articulationsFromNotations(notations).forEach((articulation, index) => {
|
|
41
|
+
if (pitchIndex !== undefined) {
|
|
42
|
+
const existing = state.attachments.find(
|
|
43
|
+
(attachment) =>
|
|
44
|
+
attachment.ownerId === itemId &&
|
|
45
|
+
attachment.type === 'articulation' &&
|
|
46
|
+
attachment.articulation === articulation
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (existing?.type === 'articulation') {
|
|
50
|
+
existing.pitchIndices = [...(existing.pitchIndices ?? [0]), pitchIndex];
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
35
55
|
state.attachments.push({
|
|
36
|
-
id: `${itemId}-articulation-${index.toString()}
|
|
56
|
+
id: `${itemId}-articulation-${index.toString()}${
|
|
57
|
+
pitchIndex === undefined ? '' : `-${pitchIndex.toString()}`
|
|
58
|
+
}`,
|
|
37
59
|
ownerId: itemId,
|
|
38
60
|
type: 'articulation',
|
|
39
61
|
articulation,
|
|
62
|
+
...(pitchIndex === undefined ? {} : { pitchIndices: [pitchIndex] }),
|
|
40
63
|
});
|
|
41
64
|
});
|
|
42
65
|
|
package/src/musicxml/index.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo } from 'react';
|
|
2
|
-
import { Picture, type SkPicture } from '
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
useDerivedValue,
|
|
6
|
-
useSharedValue,
|
|
7
|
-
} from 'react-native-reanimated';
|
|
2
|
+
import { Picture, type SkPicture } from 'react-native-skia';
|
|
3
|
+
import { useDerivedValue, useSharedValue } from 'react-native-reanimated';
|
|
4
|
+
import { scheduleOnUI } from 'react-native-worklets';
|
|
8
5
|
|
|
9
6
|
import type { VexflowRecordingCommand } from '../../base';
|
|
10
7
|
import { isVexflowNativeDebugEnabled } from '../../shared/debug';
|
|
@@ -110,7 +107,7 @@ export default function ScoreOverlayPicture({
|
|
|
110
107
|
|
|
111
108
|
useEffect(() => {
|
|
112
109
|
return () => {
|
|
113
|
-
|
|
110
|
+
scheduleOnUI(disposeOverlayPictures, disposal);
|
|
114
111
|
};
|
|
115
112
|
}, [disposal]);
|
|
116
113
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { RoundedRect, Skia, type SkRRect } from '
|
|
2
|
+
import { RoundedRect, Skia, type SkRRect } from 'react-native-skia';
|
|
3
3
|
import { useDerivedValue, type SharedValue } from 'react-native-reanimated';
|
|
4
4
|
|
|
5
5
|
import type {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
Canvas,
|
|
5
|
-
Group,
|
|
6
|
-
Picture,
|
|
7
|
-
Skia,
|
|
8
|
-
useCanvasRef,
|
|
9
|
-
} from '@shopify/react-native-skia';
|
|
3
|
+
import { Canvas, Group, Picture, Skia, useCanvasRef } from 'react-native-skia';
|
|
10
4
|
import { StyleSheet, View, type LayoutChangeEvent } from 'react-native';
|
|
11
5
|
import { GestureDetector } from 'react-native-gesture-handler';
|
|
12
6
|
import { useDerivedValue } from 'react-native-reanimated';
|
|
@@ -40,6 +34,8 @@ const ScoreRenderer: React.FC<ScoreRendererProps> = ({
|
|
|
40
34
|
fontManager,
|
|
41
35
|
colorScheme,
|
|
42
36
|
itemStyleOverrides,
|
|
37
|
+
decorateItem,
|
|
38
|
+
onDrawItem,
|
|
43
39
|
options: userOptions = EMPTY_OPTIONS,
|
|
44
40
|
scrollEnabled = true,
|
|
45
41
|
showScrollbars = true,
|
|
@@ -101,10 +97,12 @@ const ScoreRenderer: React.FC<ScoreRendererProps> = ({
|
|
|
101
97
|
layoutPlan,
|
|
102
98
|
itemsLayout,
|
|
103
99
|
} = useScoreRecording({
|
|
100
|
+
decorateItem,
|
|
104
101
|
defaultFont,
|
|
105
102
|
enabled: hasViewportSize,
|
|
106
103
|
fontManager,
|
|
107
104
|
colorScheme: resolvedColorScheme,
|
|
105
|
+
onDrawItem,
|
|
108
106
|
options,
|
|
109
107
|
rendererType: effectiveRendererType,
|
|
110
108
|
score,
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SkPicture,
|
|
3
|
-
SkTypefaceFontProvider,
|
|
4
|
-
} from '@shopify/react-native-skia';
|
|
1
|
+
import type { SkPicture, SkTypefaceFontProvider } from 'react-native-skia';
|
|
5
2
|
import type { GestureType } from 'react-native-gesture-handler';
|
|
6
3
|
import type { SharedValue } from 'react-native-reanimated';
|
|
7
4
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Stave } from 'vexflow';
|
|
2
|
+
import type { Formatter, Voice as VFVoice } from 'vexflow';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Re-positions every tick context at its time-proportional x inside the note
|
|
6
|
+
* area, overriding the formatter's duration-weighted spacing. Runs after
|
|
7
|
+
* `formatToStave` (the same post-format `setX` mechanism the formatter's own
|
|
8
|
+
* tuning uses), so beams, tuplets and modifiers pick the final positions up
|
|
9
|
+
* at draw time. The lattice follows VexFlow's own convention for its first
|
|
10
|
+
* tick: it starts at that context's left-modifier width (`totalLeftPx`), so a
|
|
11
|
+
* grace group or accidental on beat 1 hangs inside the note area instead of
|
|
12
|
+
* over the clef. The proportional span is clamped only by that inset and the
|
|
13
|
+
* LAST context's width — with a spacer voice on the lattice the latter is
|
|
14
|
+
* constant, so the mapping stays a pure function of time and of what hangs
|
|
15
|
+
* left of beat 1.
|
|
16
|
+
*/
|
|
17
|
+
export function applyFixedNoteSpacing(
|
|
18
|
+
formatter: Formatter,
|
|
19
|
+
voices: VFVoice[],
|
|
20
|
+
stave: Stave
|
|
21
|
+
) {
|
|
22
|
+
const contexts = formatter.getTickContexts();
|
|
23
|
+
const lastTickKey = contexts?.list[contexts.list.length - 1];
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
!contexts ||
|
|
27
|
+
voices.length === 0 ||
|
|
28
|
+
lastTickKey === undefined ||
|
|
29
|
+
lastTickKey <= 0
|
|
30
|
+
) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const totalTicks = voices[0]?.getTotalTicks().value() ?? 0;
|
|
35
|
+
|
|
36
|
+
if (!(totalTicks > 0)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Tick context keys are ticks × the formatter's resolution multiplier (the
|
|
41
|
+
// lcm that keeps tuplet ticks integral: 3 with triplets, 5 with
|
|
42
|
+
// quintuplets…), while getTotalTicks() is in plain ticks. Compare in plain
|
|
43
|
+
// ticks, or every position scales by the multiplier and the overflow
|
|
44
|
+
// correction below crushes the last tick flush against the note end.
|
|
45
|
+
const multiplier = contexts.resolutionMultiplier || 1;
|
|
46
|
+
const lastTick = lastTickKey / multiplier;
|
|
47
|
+
|
|
48
|
+
// Tick context x is relative to noteStartX + the stave's left note padding
|
|
49
|
+
// (see Tickable.getAbsoluteX), so the usable span ends at noteEndX. The
|
|
50
|
+
// padding is derived from Stave statics because the `Metrics` module is not
|
|
51
|
+
// re-exported by every vexflow build.
|
|
52
|
+
const stavePadding = Stave.defaultPadding - Stave.rightPadding;
|
|
53
|
+
const noteAreaWidth =
|
|
54
|
+
stave.getNoteEndX() - stave.getNoteStartX() - stavePadding;
|
|
55
|
+
const firstLeft = contexts.map[contexts.list[0]!]!.getMetrics().totalLeftPx;
|
|
56
|
+
let span = noteAreaWidth - firstLeft;
|
|
57
|
+
|
|
58
|
+
const lastContext = contexts.map[lastTickKey]!;
|
|
59
|
+
const lastOverflow =
|
|
60
|
+
firstLeft +
|
|
61
|
+
(lastTick / totalTicks) * span +
|
|
62
|
+
lastContext.getWidth() -
|
|
63
|
+
noteAreaWidth;
|
|
64
|
+
|
|
65
|
+
if (lastOverflow > 0) {
|
|
66
|
+
span -= (lastOverflow * totalTicks) / lastTick;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!(span > 0)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const tickKey of contexts.list) {
|
|
74
|
+
contexts.map[tickKey]!.setX(
|
|
75
|
+
firstLeft + (tickKey / multiplier / totalTicks) * span
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
package/src/renderer/index.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
export { default as ScoreRenderer } from './ScoreRenderer';
|
|
2
2
|
export * from './colorScheme';
|
|
3
3
|
export * from './types';
|
|
4
|
+
export {
|
|
5
|
+
Annotation,
|
|
6
|
+
Articulation,
|
|
7
|
+
Modifier,
|
|
8
|
+
Ornament,
|
|
9
|
+
StaveNote,
|
|
10
|
+
} from 'vexflow';
|
|
11
|
+
export type { RenderContext } from 'vexflow';
|
|
4
12
|
|
|
5
13
|
export {
|
|
6
14
|
isVexflowNativeDebugEnabled,
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Parenthesis } from 'vexflow';
|
|
2
|
+
import type { BoundingBox, GraceNoteGroup, Modifier } from 'vexflow';
|
|
3
|
+
|
|
4
|
+
import { noteheadWidth } from './scoreParsing';
|
|
5
|
+
import type { VFVoiceNote } from './scoreParsing';
|
|
6
|
+
import type { ScoreItemBounds, ScoreItemLayout } from './types';
|
|
7
|
+
|
|
8
|
+
function hasGraceNotes(
|
|
9
|
+
modifier: Modifier
|
|
10
|
+
): modifier is Modifier & Pick<GraceNoteGroup, 'getGraceNotes'> {
|
|
11
|
+
return 'getGraceNotes' in modifier;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parenthesis draws at its anchor offset without moving itself, so its box
|
|
16
|
+
* is re-anchored where `Parenthesis.draw()` places it.
|
|
17
|
+
*/
|
|
18
|
+
function modifierBoundingBox(note: VFVoiceNote, modifier: Modifier) {
|
|
19
|
+
const box = modifier.getBoundingBox();
|
|
20
|
+
|
|
21
|
+
if (modifier.getCategory() !== Parenthesis.CATEGORY) {
|
|
22
|
+
return box;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const start = note.getModifierStartXY(
|
|
26
|
+
modifier.getPosition(),
|
|
27
|
+
modifier.checkIndex(),
|
|
28
|
+
{ forceFlagRight: true }
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return box.move(start.x, start.y);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Union box of a drawn note's modifiers; must run after `draw()` because
|
|
36
|
+
* modifiers take their position from it. undefined without modifiers or when
|
|
37
|
+
* none could be measured.
|
|
38
|
+
*/
|
|
39
|
+
export function computeModifierBounds(
|
|
40
|
+
note: VFVoiceNote
|
|
41
|
+
): ScoreItemBounds | undefined {
|
|
42
|
+
let bounds: ScoreItemBounds | undefined;
|
|
43
|
+
|
|
44
|
+
for (const modifier of note.getModifiers()) {
|
|
45
|
+
if (hasGraceNotes(modifier)) {
|
|
46
|
+
for (const graceNote of modifier.getGraceNotes()) {
|
|
47
|
+
bounds = mergeBox(bounds, graceNote.getBoundingBox());
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
bounds = mergeBox(bounds, modifierBoundingBox(note, modifier));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return bounds;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function mergeBox(
|
|
58
|
+
bounds: ScoreItemBounds | undefined,
|
|
59
|
+
box: BoundingBox
|
|
60
|
+
): ScoreItemBounds | undefined {
|
|
61
|
+
const left = box.getX();
|
|
62
|
+
const top = box.getY();
|
|
63
|
+
const right = left + box.getW();
|
|
64
|
+
const bottom = top + box.getH();
|
|
65
|
+
|
|
66
|
+
if (![left, top, right, bottom].every(Number.isFinite)) {
|
|
67
|
+
return bounds;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!bounds) {
|
|
71
|
+
return { left, right, top, bottom };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
left: Math.min(bounds.left, left),
|
|
76
|
+
right: Math.max(bounds.right, right),
|
|
77
|
+
top: Math.min(bounds.top, top),
|
|
78
|
+
bottom: Math.max(bounds.bottom, bottom),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Detected structurally because `GhostNote`s lack these getters. */
|
|
83
|
+
type NoteHeadSpan = {
|
|
84
|
+
getNoteHeadBeginX?: () => number;
|
|
85
|
+
getNoteHeadEndX?: () => number;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Center of a formatted note's visual notehead span. When the getters are
|
|
90
|
+
* missing (GhostNotes) the fallback is the center of a NOTIONAL notehead at
|
|
91
|
+
* the block's left edge, capped by the block width — so a `spacer` rest
|
|
92
|
+
* anchors where a real note's head would sit on the same tick, and external
|
|
93
|
+
* UI aligned to it does not hop when the note appears. Zero-width `hidden`
|
|
94
|
+
* rests keep anchoring at their tick x.
|
|
95
|
+
*/
|
|
96
|
+
export function resolveItemHeadCenterX(
|
|
97
|
+
note: VFVoiceNote,
|
|
98
|
+
x: number,
|
|
99
|
+
width: number
|
|
100
|
+
): number {
|
|
101
|
+
const { getNoteHeadBeginX, getNoteHeadEndX } = note as NoteHeadSpan;
|
|
102
|
+
|
|
103
|
+
if (
|
|
104
|
+
typeof getNoteHeadBeginX === 'function' &&
|
|
105
|
+
typeof getNoteHeadEndX === 'function'
|
|
106
|
+
) {
|
|
107
|
+
const center =
|
|
108
|
+
(getNoteHeadBeginX.call(note) + getNoteHeadEndX.call(note)) / 2;
|
|
109
|
+
|
|
110
|
+
if (Number.isFinite(center) && center > x && center <= x + width) {
|
|
111
|
+
return center;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return x + Math.min(width, noteheadWidth()) / 2;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Geometry of a drawn item; must run after `draw()` because modifiers only
|
|
120
|
+
* take their position there.
|
|
121
|
+
*/
|
|
122
|
+
export function itemLayoutOf(
|
|
123
|
+
note: VFVoiceNote,
|
|
124
|
+
measureIndex: number
|
|
125
|
+
): ScoreItemLayout {
|
|
126
|
+
const x = note.getAbsoluteX();
|
|
127
|
+
const width = note.getWidth();
|
|
128
|
+
const modifierBounds = computeModifierBounds(note);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
x,
|
|
132
|
+
width,
|
|
133
|
+
headCenterX: resolveItemHeadCenterX(note, x, width),
|
|
134
|
+
measureIndex,
|
|
135
|
+
...(modifierBounds ? { modifierBounds } : {}),
|
|
136
|
+
};
|
|
137
|
+
}
|
package/src/renderer/layout.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
type ResolvedMeasureState,
|
|
18
18
|
} from './scoreParsing';
|
|
19
19
|
import type { MeasuredScore } from './measure';
|
|
20
|
-
import type { StaffVerticalBounds } from './
|
|
20
|
+
import type { StaffVerticalBounds } from './measureBounds';
|
|
21
21
|
import type {
|
|
22
22
|
RendererRect,
|
|
23
23
|
RendererSize,
|