vexflow-native 1.8.0 → 1.9.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 +33 -405
- package/lib/module/base/FontManager.js +2 -0
- package/lib/module/base/FontManager.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/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/ScoreRenderer.js +4 -0
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.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 +1 -0
- package/lib/typescript/src/base/FontManager.d.ts.map +1 -1
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts +1 -0
- package/lib/typescript/src/base/VexflowRecordingContext.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/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/ScoreRenderer.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 +51 -2
- package/lib/typescript/src/renderer/types.d.ts.map +1 -1
- package/lib/typescript/src/renderer/useScoreRecording.d.ts +2 -2
- 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 +12 -2
- package/src/base/FontManager.ts +1 -0
- package/src/base/VexflowRecordingContext.ts +1 -0
- package/src/base/index.ts +1 -0
- 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/ScoreRenderer.tsx +4 -0
- 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 +65 -2
- package/src/renderer/useScoreRecording.ts +11 -3
- package/src/renderer/vfKeys.ts +88 -0
- package/src/state/index.ts +1 -1
- package/src/state/types.ts +30 -5
- 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/state/constants.ts +0 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Clef, DurationValue, Pitch, Rest } from '../state';
|
|
2
|
+
/**
|
|
3
|
+
* Converts an internal pitch into the VexFlow key string format.
|
|
4
|
+
*/
|
|
5
|
+
export declare function pitchToVFKey(pitch: Pitch): string;
|
|
6
|
+
/**
|
|
7
|
+
* VexFlow key placing a rest on `staffLine` (0 = bottom line … 4 = top line,
|
|
8
|
+
* undefined = middle line) under `clef`. VexFlow lines are pitch-based per
|
|
9
|
+
* clef, so the key is the treble pitch of the line minus the clef's shift,
|
|
10
|
+
* counting diatonic steps from c/4 (the ledger line below a treble staff).
|
|
11
|
+
*/
|
|
12
|
+
export declare function restKeyForStaffLine(clef: Clef, staffLine: Rest['staffLine']): string;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a duration into the VexFlow duration token, including rests.
|
|
15
|
+
*/
|
|
16
|
+
export declare function durationToVF(duration: DurationValue, isRest?: boolean): string;
|
|
17
|
+
//# sourceMappingURL=vfKeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vfKeys.d.ts","sourceRoot":"","sources":["../../../../src/renderer/vfKeys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAY,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAgB3E;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAejD;AAqBD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,GAC3B,MAAM,CAOR;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAQ,GAAG,MAAM,CAW5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/state/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/state/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,cAAc,SAAS,CAAC"}
|
|
@@ -7,7 +7,7 @@ export type StemDirection = 'up' | 'down' | 'auto';
|
|
|
7
7
|
export type Notehead = 'x' | 'circle-x' | 'diamond' | 'circle' | 'square' | 'triangle' | 'triangle-down' | 'slash';
|
|
8
8
|
export type Barline = 'single' | 'double' | 'end' | 'repeat-begin' | 'repeat-end' | 'final';
|
|
9
9
|
export type Articulation = 'staccato' | 'tenuto' | 'accent' | 'marcato' | 'staccatissimo' | 'fermata' | 'open' | 'stopped';
|
|
10
|
-
export type Dynamic = 'ppp' | 'pp' | 'p' | 'mp' | 'mf' | 'f' | 'ff' | 'fff' | 'sfz';
|
|
10
|
+
export type Dynamic = 'ppp' | 'pp' | 'p' | 'mp' | 'mf' | 'f' | 'ff' | 'fff' | 'fp' | 'sf' | 'sfp' | 'sfz' | 'rf' | 'rfz' | 'fz' | 'n';
|
|
11
11
|
export type KeyMode = 'major' | 'minor' | 'dorian' | 'phrygian' | 'lydian' | 'mixolydian' | 'locrian';
|
|
12
12
|
export type VoiceTimingMode = 'strict' | 'soft' | 'free';
|
|
13
13
|
export type StaffGroupRole = 'grandStaff' | 'choir' | 'section' | 'custom';
|
|
@@ -21,9 +21,8 @@ export interface Pitch {
|
|
|
21
21
|
octave: number;
|
|
22
22
|
accidental?: Accidental;
|
|
23
23
|
notehead?: Notehead;
|
|
24
|
-
ghost
|
|
25
|
-
|
|
26
|
-
accent?: boolean;
|
|
24
|
+
/** Draws the notehead in parentheses (a ghost note). */
|
|
25
|
+
parenthesized?: boolean;
|
|
27
26
|
}
|
|
28
27
|
export interface DurationValue {
|
|
29
28
|
length: NoteLength;
|
|
@@ -37,6 +36,7 @@ export interface KeySignature {
|
|
|
37
36
|
export interface Meter {
|
|
38
37
|
beats: number;
|
|
39
38
|
beatUnit: number;
|
|
39
|
+
/** Omitted = VexFlow's default for the meter: numerators divisible by 3 group in threes, else 2/beatUnit above a quarter (5/8 → 2/8), else 1/beatUnit (5/4 → 1/4). */
|
|
40
40
|
beamGroups?: Fraction[];
|
|
41
41
|
}
|
|
42
42
|
export interface Tempo {
|
|
@@ -60,7 +60,11 @@ export interface Rest {
|
|
|
60
60
|
voiceId: Id;
|
|
61
61
|
targetStaffId?: Id;
|
|
62
62
|
kind?: 'visible' | 'spacer' | 'hidden';
|
|
63
|
-
|
|
63
|
+
/**
|
|
64
|
+
* 0 = bottom line … 4 = top line of the five-line geometry; undefined = the
|
|
65
|
+
* middle line.
|
|
66
|
+
*/
|
|
67
|
+
staffLine?: 0 | 1 | 2 | 3 | 4;
|
|
64
68
|
}
|
|
65
69
|
export interface Chord {
|
|
66
70
|
id: Id;
|
|
@@ -88,19 +92,26 @@ export interface MeasureState {
|
|
|
88
92
|
export interface MeasureLeftModifiers {
|
|
89
93
|
/** undefined = shown on the first measure only; false hides it there too. */
|
|
90
94
|
showClef?: boolean;
|
|
95
|
+
/** undefined = hidden. */
|
|
91
96
|
showMeter?: boolean;
|
|
97
|
+
/** undefined = hidden; never drawn on a percussion clef. */
|
|
92
98
|
showKeySignature?: boolean;
|
|
99
|
+
/** undefined = 'single'; only 'single' and 'repeat-begin' render here. */
|
|
93
100
|
startBarline?: Barline;
|
|
94
101
|
}
|
|
95
102
|
export interface MeasureRightModifiers {
|
|
103
|
+
/** undefined = 'single'; 'repeat-begin' draws as a single line. */
|
|
96
104
|
endBarline?: Barline;
|
|
97
105
|
}
|
|
98
106
|
export interface TextDirection {
|
|
99
107
|
id: Id;
|
|
100
108
|
type: 'text';
|
|
101
109
|
text: string;
|
|
110
|
+
/** undefined = 'above'; drawn on the measure's first drawn item of its
|
|
111
|
+
* first voice. */
|
|
102
112
|
placement?: 'above' | 'below';
|
|
103
113
|
}
|
|
114
|
+
/** Not drawn; the tempo reaches the renderer through `MeasureState`. */
|
|
104
115
|
export interface TempoDirection {
|
|
105
116
|
id: Id;
|
|
106
117
|
type: 'tempo';
|
|
@@ -159,16 +170,23 @@ export interface AttachmentBase {
|
|
|
159
170
|
export interface ArticulationAttachment extends AttachmentBase {
|
|
160
171
|
type: 'articulation';
|
|
161
172
|
articulation: Articulation;
|
|
173
|
+
/** undefined = 'above'. */
|
|
162
174
|
placement?: 'above' | 'below';
|
|
175
|
+
/** Chord pitches the mark belongs to, as indices into `Chord.pitches`;
|
|
176
|
+
* undefined = the whole owner. Engraved once per owner either way; indices
|
|
177
|
+
* on a `note` owner or out of range are tolerated and ignored. */
|
|
178
|
+
pitchIndices?: number[];
|
|
163
179
|
}
|
|
164
180
|
export interface DynamicAttachment extends AttachmentBase {
|
|
165
181
|
type: 'dynamic';
|
|
166
182
|
dynamic: Dynamic;
|
|
183
|
+
/** undefined = 'below'. */
|
|
167
184
|
placement?: 'above' | 'below';
|
|
168
185
|
}
|
|
169
186
|
export interface LyricAttachment extends AttachmentBase {
|
|
170
187
|
type: 'lyric';
|
|
171
188
|
text: string;
|
|
189
|
+
/** Verse order below the owner, ascending; undefined sorts first. */
|
|
172
190
|
verse?: number;
|
|
173
191
|
}
|
|
174
192
|
/** Free text drawn above or below the owner (a note, chord or rest), e.g. a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/state/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,EAAE,GAAG,MAAM,CAAC;AAExB,MAAM,MAAM,IAAI,GACZ,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,GACT,eAAe,GACf,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,YAAY,GACZ,KAAK,CAAC;AAEV,MAAM,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAE3D,MAAM,MAAM,UAAU,GAClB,IAAI,GACJ,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,GACJ,GAAG,GACH,cAAc,GACd,eAAe,CAAC;AAEpB,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,OAAO,GACP,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,G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GACtB,sBAAsB,GACtB,iBAAiB,GACjB,eAAe,GACf,oBAAoB,GACpB,mBAAmB,CAAC;AAExB,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,EAAE,CAAC;IACP,UAAU,EAAE,EAAE,CAAC;IACf,QAAQ,EAAE,EAAE,CAAC;CACd;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,EAAE,CAAC;IACP,UAAU,EAAE,EAAE,CAAC;IACf,QAAQ,EAAE,EAAE,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,EAAE,CAAC;IACP,OAAO,EAAE,EAAE,CAAC;IACZ,OAAO,EAAE,EAAE,EAAE,CAAC;IACd,KAAK,EAAE,QAAQ,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,EAAE,CAAC;IACP,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vexflow-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "React native backend for rendering music notation using @shopify/react-native-skia",
|
|
5
5
|
"main": "./lib/module/base/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/base/index.d.ts",
|
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
"types": "./lib/typescript/src/musicxml/index.d.ts",
|
|
26
26
|
"default": "./lib/module/musicxml/index.js"
|
|
27
27
|
},
|
|
28
|
+
"./percussion": {
|
|
29
|
+
"source": "./src/percussion/index.ts",
|
|
30
|
+
"types": "./lib/typescript/src/percussion/index.d.ts",
|
|
31
|
+
"default": "./lib/module/percussion/index.js"
|
|
32
|
+
},
|
|
28
33
|
"./package.json": "./package.json"
|
|
29
34
|
},
|
|
30
35
|
"files": [
|
|
@@ -49,8 +54,9 @@
|
|
|
49
54
|
"typecheck": "tsc",
|
|
50
55
|
"lint": "eslint src example --ext .js,.ts,.tsx",
|
|
51
56
|
"lint:fix": "yarn lint --fix",
|
|
52
|
-
"format": "prettier --write README.md package.json \"src/**/*.{ts,tsx}\"",
|
|
57
|
+
"format": "prettier --write README.md package.json \"docs/*.md\" \"src/**/*.{ts,tsx}\"",
|
|
53
58
|
"test": "jest",
|
|
59
|
+
"docs:api": "typedoc",
|
|
54
60
|
"release": "release-it --only-version"
|
|
55
61
|
},
|
|
56
62
|
"keywords": [
|
|
@@ -98,6 +104,7 @@
|
|
|
98
104
|
"react-native-worklets": "^0.7.4",
|
|
99
105
|
"release-it": "^19.0.4",
|
|
100
106
|
"turbo": "^2.5.6",
|
|
107
|
+
"typedoc": "0.28.20",
|
|
101
108
|
"typescript": "^5.9.2",
|
|
102
109
|
"vexflow": "^5.0.0"
|
|
103
110
|
},
|
|
@@ -141,6 +148,9 @@
|
|
|
141
148
|
},
|
|
142
149
|
"jest": {
|
|
143
150
|
"preset": "react-native",
|
|
151
|
+
"testMatch": [
|
|
152
|
+
"**/__tests__/**/*.test.[jt]s?(x)"
|
|
153
|
+
],
|
|
144
154
|
"modulePathIgnorePatterns": [
|
|
145
155
|
"<rootDir>/example/node_modules",
|
|
146
156
|
"<rootDir>/lib/",
|
package/src/base/FontManager.ts
CHANGED
package/src/base/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as VexflowCanvas } from './VexflowCanvas';
|
|
2
|
+
export { default as FontManager } from './FontManager';
|
|
2
3
|
export { default as VexflowRecordingContext } from './VexflowRecordingContext';
|
|
3
4
|
export { renderVexflowRecordingCommands } from './VexflowRecordingReplay';
|
|
4
5
|
export {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
DynamicAttachment,
|
|
3
3
|
GraceNote,
|
|
4
4
|
Measure,
|
|
5
5
|
NoteAttachment,
|
|
@@ -32,6 +32,8 @@ export type PendingGraceNotes = {
|
|
|
32
32
|
slash: boolean;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
export type PendingDynamic = Pick<DynamicAttachment, 'dynamic' | 'placement'>;
|
|
36
|
+
|
|
35
37
|
export type ParserState = {
|
|
36
38
|
scoreId: string;
|
|
37
39
|
divisions: number;
|
|
@@ -40,7 +42,8 @@ export type ParserState = {
|
|
|
40
42
|
ties: Tie[];
|
|
41
43
|
slurs: Slur[];
|
|
42
44
|
tuplets: TupletGroup[];
|
|
43
|
-
|
|
45
|
+
/** Keyed by MusicXML staff number; consumed by that staff's next note. */
|
|
46
|
+
pendingDynamics: Map<string, PendingDynamic[]>;
|
|
44
47
|
/** Keyed by MusicXML voice name; consumed by that voice's next note. */
|
|
45
48
|
pendingGraceNotes: Map<string, PendingGraceNotes>;
|
|
46
49
|
activeTies: Map<string, ActiveSpanner>;
|
|
@@ -60,7 +60,7 @@ export function parseMeasure(
|
|
|
60
60
|
);
|
|
61
61
|
const voiceMapsByStaff = staves.map(() => new Map<string, Voice>());
|
|
62
62
|
const voiceCursors = new Map<string, VoiceCursor>();
|
|
63
|
-
const
|
|
63
|
+
const directionsByStaff = new Map<number, Direction[]>();
|
|
64
64
|
let currentPosition = 0;
|
|
65
65
|
|
|
66
66
|
measure.children.forEach((child) => {
|
|
@@ -68,9 +68,21 @@ export function parseMeasure(
|
|
|
68
68
|
case 'attributes':
|
|
69
69
|
applyAttributes(child, measures, staves, state);
|
|
70
70
|
break;
|
|
71
|
-
case 'direction':
|
|
72
|
-
directions
|
|
71
|
+
case 'direction': {
|
|
72
|
+
const { staffIndex, directions } = parseDirection(child, state);
|
|
73
|
+
|
|
74
|
+
if (!measures[staffIndex]) {
|
|
75
|
+
throw new MusicXmlParseError(
|
|
76
|
+
`Direction references unknown staff ${(staffIndex + 1).toString()}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
directionsByStaff.set(staffIndex, [
|
|
81
|
+
...(directionsByStaff.get(staffIndex) ?? []),
|
|
82
|
+
...directions,
|
|
83
|
+
]);
|
|
73
84
|
break;
|
|
85
|
+
}
|
|
74
86
|
case 'note':
|
|
75
87
|
currentPosition = parseNote(
|
|
76
88
|
child,
|
|
@@ -114,8 +126,10 @@ export function parseMeasure(
|
|
|
114
126
|
finalizeMeasureVoices(measures[0]!, voiceCursors, state);
|
|
115
127
|
|
|
116
128
|
measures.forEach((staffMeasure, index) => {
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
const directions = directionsByStaff.get(index);
|
|
130
|
+
|
|
131
|
+
if (directions?.length) {
|
|
132
|
+
staffMeasure.directions = directions;
|
|
119
133
|
}
|
|
120
134
|
|
|
121
135
|
staffMeasure.voices = [...voiceMapsByStaff[index]!.values()].sort(
|
|
@@ -246,9 +260,14 @@ function parseNote(
|
|
|
246
260
|
const itemId = isChordTone
|
|
247
261
|
? mergeChordTone(voice, item, note)
|
|
248
262
|
: pushItem(voice, item);
|
|
263
|
+
const owner = voice.items[voice.items.length - 1];
|
|
264
|
+
const pitchIndex =
|
|
265
|
+
isChordTone && owner?.type === 'chord'
|
|
266
|
+
? owner.pitches.length - 1
|
|
267
|
+
: undefined;
|
|
249
268
|
|
|
250
269
|
attachPendingGraceNotes(itemId, voiceName, state);
|
|
251
|
-
applyNoteAttachments(note, itemId, staffNumber, voice.id, state);
|
|
270
|
+
applyNoteAttachments(note, itemId, staffNumber, voice.id, state, pitchIndex);
|
|
252
271
|
|
|
253
272
|
if (isChordTone) {
|
|
254
273
|
return currentPosition;
|
|
@@ -383,7 +402,17 @@ function parseDuration(note: XmlElement, state: ParserState): DurationValue {
|
|
|
383
402
|
}
|
|
384
403
|
|
|
385
404
|
function parsePitch(note: XmlElement): Pitch {
|
|
386
|
-
|
|
405
|
+
const pitch = mapPitch(
|
|
406
|
+
firstChild(note, 'pitch'),
|
|
407
|
+
childText(note, 'accidental')
|
|
408
|
+
);
|
|
409
|
+
const notehead = optionalChild(note, 'notehead');
|
|
410
|
+
|
|
411
|
+
if (notehead && attr(notehead, 'parentheses') === 'yes') {
|
|
412
|
+
pitch.parenthesized = true;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return pitch;
|
|
387
416
|
}
|
|
388
417
|
|
|
389
418
|
/**
|
|
@@ -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
|
@@ -40,6 +40,8 @@ const ScoreRenderer: React.FC<ScoreRendererProps> = ({
|
|
|
40
40
|
fontManager,
|
|
41
41
|
colorScheme,
|
|
42
42
|
itemStyleOverrides,
|
|
43
|
+
decorateItem,
|
|
44
|
+
onDrawItem,
|
|
43
45
|
options: userOptions = EMPTY_OPTIONS,
|
|
44
46
|
scrollEnabled = true,
|
|
45
47
|
showScrollbars = true,
|
|
@@ -101,10 +103,12 @@ const ScoreRenderer: React.FC<ScoreRendererProps> = ({
|
|
|
101
103
|
layoutPlan,
|
|
102
104
|
itemsLayout,
|
|
103
105
|
} = useScoreRecording({
|
|
106
|
+
decorateItem,
|
|
104
107
|
defaultFont,
|
|
105
108
|
enabled: hasViewportSize,
|
|
106
109
|
fontManager,
|
|
107
110
|
colorScheme: resolvedColorScheme,
|
|
111
|
+
onDrawItem,
|
|
108
112
|
options,
|
|
109
113
|
rendererType: effectiveRendererType,
|
|
110
114
|
score,
|
|
@@ -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,
|