vexflow 5.2.0 → 5.4.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 +2 -0
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +6502 -1708
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +5622 -1618
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/accidental.js +10 -3
- package/build/esm/src/alternatingtremolo.js +68 -0
- package/build/esm/src/annotation.js +19 -3
- package/build/esm/src/articulation.js +28 -6
- package/build/esm/src/beam.js +171 -28
- package/build/esm/src/bend.js +79 -23
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/continuouslayout.js +681 -0
- package/build/esm/src/continuousspan.js +159 -0
- package/build/esm/src/curve.js +48 -55
- package/build/esm/src/dot.js +13 -4
- package/build/esm/src/easyscore/composition.js +52 -2
- package/build/esm/src/easyscore/policies.js +39 -8
- package/build/esm/src/element.js +4 -0
- package/build/esm/src/engravinggeometry.js +157 -0
- package/build/esm/src/engravingprofile.js +44 -0
- package/build/esm/src/factory.js +31 -11
- package/build/esm/src/font.js +9 -1
- package/build/esm/src/formatter.js +9 -1
- package/build/esm/src/fretdiagram.js +77 -0
- package/build/esm/src/gracenote.js +43 -38
- package/build/esm/src/gracenotegroup.js +53 -56
- package/build/esm/src/guitargesture.js +33 -0
- package/build/esm/src/guitarmodifiers.js +26 -0
- package/build/esm/src/index.js +10 -0
- package/build/esm/src/instrumentprofile.js +123 -0
- package/build/esm/src/keysignature.js +24 -2
- package/build/esm/src/modifiercontext.js +11 -0
- package/build/esm/src/notationspelling.js +73 -0
- package/build/esm/src/note.js +3 -0
- package/build/esm/src/notehead.js +11 -6
- package/build/esm/src/ornament.js +43 -18
- package/build/esm/src/pagebreaks.js +58 -0
- package/build/esm/src/pedalmarking.js +39 -17
- package/build/esm/src/phraselayout.js +503 -0
- package/build/esm/src/phraseribbon.js +28 -0
- package/build/esm/src/proportionalformatter.js +54 -6
- package/build/esm/src/publication.js +402 -0
- package/build/esm/src/publicationview.js +114 -0
- package/build/esm/src/scorenavigation.js +172 -0
- package/build/esm/src/sheet.js +14 -2
- package/build/esm/src/stave.js +33 -16
- package/build/esm/src/stavebarline.js +5 -7
- package/build/esm/src/staveconnector.js +1 -0
- package/build/esm/src/stavehairpin.js +53 -27
- package/build/esm/src/stavenote.js +134 -116
- package/build/esm/src/stavetie.js +66 -9
- package/build/esm/src/stem.js +26 -11
- package/build/esm/src/strokes.js +4 -0
- package/build/esm/src/system.js +19 -4
- package/build/esm/src/systembreaks.js +42 -0
- package/build/esm/src/tabnote.js +6 -1
- package/build/esm/src/textbracket.js +24 -5
- package/build/esm/src/tickcontext.js +19 -0
- package/build/esm/src/timesignature.js +20 -6
- package/build/esm/src/tuplet.js +58 -17
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +20 -0
- package/build/esm/src/voice.js +7 -3
- package/build/esm/tests/bend_tests.js +14 -1
- package/build/esm/tests/curve_tests.js +14 -4
- package/build/esm/tests/demo_repertoire_tests.js +27 -0
- package/build/esm/tests/demos/drums.js +54 -0
- package/build/esm/tests/demos/electric.js +63 -0
- package/build/esm/tests/demos/greensleeves.js +90 -0
- package/build/esm/tests/demos/joy.js +61 -0
- package/build/esm/tests/demos/kesh.js +80 -0
- package/build/esm/tests/demos/prelude.js +59 -0
- package/build/esm/tests/demos/quartertones.js +50 -0
- package/build/esm/tests/demos/saints.js +65 -0
- package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
- package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
- package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
- package/build/esm/tests/engraving/publication-studies.mjs +87 -0
- package/build/esm/tests/engraving/score-layout.mjs +75 -0
- package/build/esm/tests/engraving/score-persistence.mjs +262 -0
- package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
- package/build/esm/tests/engraving/studies.mjs +367 -0
- package/build/esm/tests/formatter_tests.js +10 -1
- package/build/esm/tests/index.js +1 -0
- package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
- package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
- package/build/esm/tests/node/easyscore-tests.mjs +71 -0
- package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
- package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
- package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
- package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
- package/build/esm/tests/node/publication-tests.mjs +219 -0
- package/build/esm/tests/node/rendering-tests.mjs +6 -2
- package/build/esm/tests/threevoice_tests.js +11 -1
- package/build/esm/tests/vexflow_test_helpers.js +19 -10
- package/build/esm/tools/audit-dependencies.mjs +61 -0
- package/build/esm/tools/easyscore-structure.mjs +1 -1
- package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
- package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
- package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
- package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
- package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
- package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
- package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
- package/build/esm/tools/score-fixtures.mjs +23 -6
- package/build/types/src/accidental.d.ts +4 -0
- package/build/types/src/alternatingtremolo.d.ts +13 -0
- package/build/types/src/annotation.d.ts +9 -0
- package/build/types/src/articulation.d.ts +9 -1
- package/build/types/src/beam.d.ts +16 -0
- package/build/types/src/bend.d.ts +8 -0
- package/build/types/src/clef.d.ts +3 -0
- package/build/types/src/continuouslayout.d.ts +103 -0
- package/build/types/src/continuousspan.d.ts +60 -0
- package/build/types/src/curve.d.ts +20 -0
- package/build/types/src/dot.d.ts +5 -0
- package/build/types/src/easyscore/composition.d.ts +27 -0
- package/build/types/src/easyscore/policies.d.ts +1 -1
- package/build/types/src/element.d.ts +2 -0
- package/build/types/src/engravinggeometry.d.ts +31 -0
- package/build/types/src/engravingprofile.d.ts +20 -0
- package/build/types/src/factory.d.ts +6 -1
- package/build/types/src/formatter.d.ts +3 -3
- package/build/types/src/fretdiagram.d.ts +23 -0
- package/build/types/src/gracenote.d.ts +7 -0
- package/build/types/src/gracenotegroup.d.ts +7 -2
- package/build/types/src/guitargesture.d.ts +26 -0
- package/build/types/src/guitarmodifiers.d.ts +3 -0
- package/build/types/src/index.d.ts +12 -0
- package/build/types/src/instrumentprofile.d.ts +124 -0
- package/build/types/src/keysignature.d.ts +9 -0
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/notationspelling.d.ts +25 -0
- package/build/types/src/note.d.ts +15 -0
- package/build/types/src/notehead.d.ts +5 -0
- package/build/types/src/ornament.d.ts +10 -1
- package/build/types/src/pagebreaks.d.ts +26 -0
- package/build/types/src/pedalmarking.d.ts +9 -0
- package/build/types/src/phraselayout.d.ts +87 -0
- package/build/types/src/phraseribbon.d.ts +7 -0
- package/build/types/src/proportionalformatter.d.ts +11 -2
- package/build/types/src/publication.d.ts +61 -0
- package/build/types/src/publicationview.d.ts +27 -0
- package/build/types/src/scorenavigation.d.ts +33 -0
- package/build/types/src/sheet.d.ts +5 -0
- package/build/types/src/stave.d.ts +13 -0
- package/build/types/src/stavehairpin.d.ts +18 -0
- package/build/types/src/stavenote.d.ts +20 -2
- package/build/types/src/stavetie.d.ts +9 -0
- package/build/types/src/stem.d.ts +10 -1
- package/build/types/src/system.d.ts +8 -1
- package/build/types/src/systembreaks.d.ts +9 -0
- package/build/types/src/textbracket.d.ts +7 -0
- package/build/types/src/tickcontext.d.ts +5 -0
- package/build/types/src/timesignature.d.ts +6 -0
- package/build/types/src/tuplet.d.ts +5 -48
- package/build/types/src/vexflow.d.ts +20 -0
- package/build/types/src/voice.d.ts +2 -0
- package/changelog/CHANGELOG.md +25 -0
- package/package.json +15 -3
- package/tests/all.html +277 -0
- package/tests/demo_petzold_tests.ts +435 -0
- package/tests/demos/drums.ts +55 -0
- package/tests/demos/drums.webp +0 -0
- package/tests/demos/electric.ts +70 -0
- package/tests/demos/electric.webp +0 -0
- package/tests/demos/greensleeves.ts +97 -0
- package/tests/demos/greensleeves.webp +0 -0
- package/tests/demos/joy.ts +65 -0
- package/tests/demos/joy.webp +0 -0
- package/tests/demos/kesh.ts +86 -0
- package/tests/demos/kesh.webp +0 -0
- package/tests/demos/prelude.ts +65 -0
- package/tests/demos/prelude.webp +0 -0
- package/tests/demos/quartertones.ts +51 -0
- package/tests/demos/quartertones.webp +0 -0
- package/tests/demos/saints.ts +70 -0
- package/tests/demos/saints.webp +0 -0
- package/tests/flow.html +550 -239
- package/tests/fonts.css +493 -0
- package/tests/minuet.webp +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
const setup = `// Draw into the guide's score container at the available width.
|
|
2
|
+
const score = VF.EasyScore.create({
|
|
3
|
+
renderer: { elementId: 'score', width, height },
|
|
4
|
+
});`;
|
|
5
|
+
function example(id, title, description, code, api) {
|
|
6
|
+
return {
|
|
7
|
+
id,
|
|
8
|
+
title,
|
|
9
|
+
description,
|
|
10
|
+
code,
|
|
11
|
+
api: api.split(' '),
|
|
12
|
+
group: 'Strings & tablature',
|
|
13
|
+
controls: [],
|
|
14
|
+
tips: description,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export const guitar = [
|
|
18
|
+
example('rasgueado-golpe', 'Rasgueado with a simultaneous golpe', 'Play a measured rasgueado, reverse the arrow convention and keep the golpe on beat two.', `${setup}
|
|
19
|
+
const guitar = new VF.FrettedInstrument();
|
|
20
|
+
const grip = [
|
|
21
|
+
{ str: 4, fret: 2 },
|
|
22
|
+
{ str: 3, fret: 1 },
|
|
23
|
+
{ str: 2, fret: 0 },
|
|
24
|
+
{ str: 1, fret: 0 },
|
|
25
|
+
];
|
|
26
|
+
// A physical downstroke travels bass to treble. Try 'hand' to reverse the printed arrows.
|
|
27
|
+
const arrows = 'strings';
|
|
28
|
+
const fan = guitar.rasgueado(
|
|
29
|
+
grip,
|
|
30
|
+
['a', 'm', 'i', 'i', 'i', 'p', 'i'].map((finger, i) => ({
|
|
31
|
+
finger,
|
|
32
|
+
duration: i < 4 ? '16' : 'q',
|
|
33
|
+
direction: i === 3 ? 'treble-to-bass' : 'bass-to-treble',
|
|
34
|
+
arrows,
|
|
35
|
+
golpe: i === 4,
|
|
36
|
+
roll: i === 6,
|
|
37
|
+
}))
|
|
38
|
+
);
|
|
39
|
+
// Fit the entire one-bar fan, even on a phone.
|
|
40
|
+
const logicalWidth = Math.max(width, 480);
|
|
41
|
+
const spec = {
|
|
42
|
+
sheet: { width: logicalWidth - 32, x: 16, y: 35 },
|
|
43
|
+
continuous: {},
|
|
44
|
+
accidentals: 'key-aware',
|
|
45
|
+
staves: ['staff', 'tab'].map((view) => ({
|
|
46
|
+
id: view,
|
|
47
|
+
kind: view === 'tab' ? 'tab' : 'stave',
|
|
48
|
+
time: '4/4',
|
|
49
|
+
spaceAbove: view === 'tab' ? 5 : 0,
|
|
50
|
+
measures: [
|
|
51
|
+
{
|
|
52
|
+
voices: [
|
|
53
|
+
{
|
|
54
|
+
autoBeam: true,
|
|
55
|
+
notes: fan.map((p, i) =>
|
|
56
|
+
view === 'tab'
|
|
57
|
+
? { id: 'tab-' + i, tab: p.tab, drawStem: true }
|
|
58
|
+
: { id: 'staff-' + i, note: p.note }
|
|
59
|
+
),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
})),
|
|
65
|
+
};
|
|
66
|
+
const composition = score.compose(spec);
|
|
67
|
+
for (const view of ['staff', 'tab']) {
|
|
68
|
+
score.attach(composition.getNote(view + '-4'), score.make.articulation({ type: 'a>', position: 'above' }), 0);
|
|
69
|
+
}
|
|
70
|
+
composition.sheet.format();
|
|
71
|
+
const scale = width / logicalWidth;
|
|
72
|
+
const ctx = score.factory.getContext();
|
|
73
|
+
ctx.resize(width, Math.ceil((composition.sheet.getHeight() + 70) * scale)).scale(scale, scale);
|
|
74
|
+
ctx.save().setFont('Arial', 12);
|
|
75
|
+
ctx.fillText('a ring · m middle · i index · p thumb · + golpe = tap', 16, 15);
|
|
76
|
+
ctx.fillText(
|
|
77
|
+
arrows === 'strings'
|
|
78
|
+
? '↑ bass to treble · ↓ treble to bass'
|
|
79
|
+
: '↓ bass to treble · ↑ treble to bass',
|
|
80
|
+
16,
|
|
81
|
+
32
|
|
82
|
+
);
|
|
83
|
+
ctx.restore();
|
|
84
|
+
score.draw({ retain: true });`, 'FrettedInstrument Stroke ScoreNavigation'),
|
|
85
|
+
example('string-mute-bend', 'Drop D pedal and timed unison bend', 'Follow the palm mute on string 6 across a break and bend string 3 against a stationary E.', `${setup}
|
|
86
|
+
const guitar = new VF.FrettedInstrument('dropd');
|
|
87
|
+
const play = (str, fret, duration) => guitar.attack([{ str, fret }], duration);
|
|
88
|
+
const pedal = () => play(6, 0, '8');
|
|
89
|
+
const ringing = guitar.attack(
|
|
90
|
+
[
|
|
91
|
+
{ str: 3, fret: 2 },
|
|
92
|
+
{ str: 2, fret: 3 },
|
|
93
|
+
],
|
|
94
|
+
'h'
|
|
95
|
+
);
|
|
96
|
+
// Reach E halfway through the quarter, hold to three quarters, then release to D.
|
|
97
|
+
const bend = guitar.bentAttack(
|
|
98
|
+
[
|
|
99
|
+
{ str: 3, fret: 7 },
|
|
100
|
+
{ str: 2, fret: 5 },
|
|
101
|
+
],
|
|
102
|
+
'q',
|
|
103
|
+
{
|
|
104
|
+
string: 3,
|
|
105
|
+
semitones: 2,
|
|
106
|
+
rise: [1, 2],
|
|
107
|
+
hold: [3, 4],
|
|
108
|
+
release: [1, 1],
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
const lead = [7, 12, 7, 10].map((fret) => play(1, fret, '16'));
|
|
112
|
+
const measures = [
|
|
113
|
+
[[ringing], [pedal(), pedal(), pedal(), pedal()]],
|
|
114
|
+
[
|
|
115
|
+
[...lead, bend],
|
|
116
|
+
[pedal(), '8', 'q'],
|
|
117
|
+
],
|
|
118
|
+
];
|
|
119
|
+
const spec = {
|
|
120
|
+
sheet: { width: width - 32, x: 16, y: 35, rowGap: 25 },
|
|
121
|
+
continuous: {
|
|
122
|
+
spans: [{ kind: 'palmMute', id: 'mute-six', strings: [6], from: 'tab-0-1-0', to: 'tab-1-1-0' }],
|
|
123
|
+
},
|
|
124
|
+
staves: ['staff', 'tab'].map((view) => ({
|
|
125
|
+
id: view,
|
|
126
|
+
kind: view === 'tab' ? 'tab' : 'stave',
|
|
127
|
+
time: '2/4',
|
|
128
|
+
spaceAbove: view === 'tab' ? 6 : 0,
|
|
129
|
+
measures: measures.map((bar, m) => ({
|
|
130
|
+
voices: bar.map((events, v) => ({
|
|
131
|
+
notes: events.map((e, i) => {
|
|
132
|
+
const id = [view, m, v, i].join('-'),
|
|
133
|
+
stemDirection = v === 0 ? 1 : -1;
|
|
134
|
+
if (typeof e === 'string')
|
|
135
|
+
return view === 'tab'
|
|
136
|
+
? score.make.ghostNote({ duration: e })
|
|
137
|
+
: { keys: ['b/4'], duration: e + 'r', stemDirection };
|
|
138
|
+
return view === 'tab'
|
|
139
|
+
? { id, tab: { ...e.tab, stemDirection }, drawStem: true }
|
|
140
|
+
: { id, note: { ...e.note, stemDirection } };
|
|
141
|
+
}),
|
|
142
|
+
})),
|
|
143
|
+
})),
|
|
144
|
+
})),
|
|
145
|
+
};
|
|
146
|
+
const composition = score.compose(spec);
|
|
147
|
+
for (const view of ['staff', 'tab']) {
|
|
148
|
+
const get = (m, v, i) => composition.getNote([view, m, v, i].join('-'));
|
|
149
|
+
score.beam([get(0, 1, 0), get(0, 1, 1)]);
|
|
150
|
+
score.beam([get(0, 1, 2), get(0, 1, 3)]);
|
|
151
|
+
score.beam([0, 1, 2, 3].map((i) => get(1, 0, i)));
|
|
152
|
+
score.attach(get(0, 0, 0), score.make.annotation({ text: 'let ring', vJustify: 'top' }), 0);
|
|
153
|
+
score.attach(get(1, 0, 1), score.make.annotation({ text: 'T', vJustify: 'top' }), 0);
|
|
154
|
+
}
|
|
155
|
+
for (const [from, to, text] of [
|
|
156
|
+
[1, 2, 'P'],
|
|
157
|
+
[2, 3, 'H'],
|
|
158
|
+
]) {
|
|
159
|
+
score.make.tabTie(
|
|
160
|
+
{
|
|
161
|
+
firstNote: composition.getNote('tab-1-0-' + from),
|
|
162
|
+
lastNote: composition.getNote('tab-1-0-' + to),
|
|
163
|
+
firstIndexes: [0],
|
|
164
|
+
lastIndexes: [0],
|
|
165
|
+
},
|
|
166
|
+
text
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
composition.sheet.format();
|
|
170
|
+
score.factory.getContext().resize(width, composition.sheet.getHeight() + 70);
|
|
171
|
+
score.draw({ retain: true });`, 'FrettedInstrument Bend ContinuousLayout'),
|
|
172
|
+
example('bossa-anticipation', 'Bossa nova bass and tied anticipation', 'Keep the bass sounding under the tied anticipation and the muted upper-string attack.', `${setup}
|
|
173
|
+
const guitar = new VF.FrettedInstrument();
|
|
174
|
+
const chord = [
|
|
175
|
+
{ str: 3, fret: 0 },
|
|
176
|
+
{ str: 2, fret: 1 },
|
|
177
|
+
{ str: 1, fret: 0 },
|
|
178
|
+
];
|
|
179
|
+
const struck = () => guitar.attack(chord, '8');
|
|
180
|
+
const dead = guitar.attack(
|
|
181
|
+
chord.map((p, i) => ({ str: p.str, fret: 'X', displayKey: ['g/4', 'c/5', 'e/5'][i] })),
|
|
182
|
+
'8'
|
|
183
|
+
);
|
|
184
|
+
const bass = (str, d) => guitar.attack([{ str, fret: 0 }], d);
|
|
185
|
+
const bars = [
|
|
186
|
+
[['rest', struck(), 'rest', struck()], [bass(5, 'h')]],
|
|
187
|
+
[
|
|
188
|
+
[struck(), dead, 'rest', struck()],
|
|
189
|
+
[bass(6, 'q'), bass(5, 'q')],
|
|
190
|
+
],
|
|
191
|
+
];
|
|
192
|
+
// Keep the two ends of the native three-head tie on one system.
|
|
193
|
+
const logicalWidth = Math.max(width, 420);
|
|
194
|
+
const spec = {
|
|
195
|
+
sheet: { width: logicalWidth - 32, x: 16, y: 35 },
|
|
196
|
+
staves: ['staff', 'tab'].map((view) => ({
|
|
197
|
+
id: view,
|
|
198
|
+
kind: view === 'tab' ? 'tab' : 'stave',
|
|
199
|
+
time: '2/4',
|
|
200
|
+
spaceAbove: view === 'tab' ? 5 : 0,
|
|
201
|
+
measures: bars.map((bar, m) => ({
|
|
202
|
+
voices: bar.map((events, v) => ({
|
|
203
|
+
notes: events.map((e, i) => {
|
|
204
|
+
const id = [view, m, v, i].join('-'),
|
|
205
|
+
stemDirection = v === 0 ? 1 : -1;
|
|
206
|
+
if (e === 'rest')
|
|
207
|
+
return view === 'tab'
|
|
208
|
+
? score.make.ghostNote({ duration: '8' })
|
|
209
|
+
: { keys: ['b/4'], duration: '8r' };
|
|
210
|
+
return view === 'tab'
|
|
211
|
+
? { id, tab: { ...e.tab, stemDirection }, drawStem: true }
|
|
212
|
+
: { id, note: { ...e.note, stemDirection } };
|
|
213
|
+
}),
|
|
214
|
+
})),
|
|
215
|
+
})),
|
|
216
|
+
})),
|
|
217
|
+
};
|
|
218
|
+
const composition = score.compose(spec);
|
|
219
|
+
for (const view of ['staff', 'tab']) {
|
|
220
|
+
const firstNote = composition.getNote(view + '-0-0-3'),
|
|
221
|
+
lastNote = composition.getNote(view + '-1-0-0');
|
|
222
|
+
const indices = [0, 1, 2];
|
|
223
|
+
if (view === 'tab')
|
|
224
|
+
score.make.tabTie({ firstNote, lastNote, firstIndexes: indices, lastIndexes: indices });
|
|
225
|
+
else
|
|
226
|
+
score.make.tie({
|
|
227
|
+
from: firstNote,
|
|
228
|
+
to: lastNote,
|
|
229
|
+
firstIndexes: indices,
|
|
230
|
+
lastIndexes: indices,
|
|
231
|
+
options: { direction: -1 },
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
composition.sheet.format();
|
|
235
|
+
const scale = width / logicalWidth;
|
|
236
|
+
score.factory.getContext().resize(width, Math.ceil((composition.sheet.getHeight() + 70) * scale)).scale(scale, scale);
|
|
237
|
+
score.draw({ retain: true });`, 'FrettedInstrument TabTie StaveTie'),
|
|
238
|
+
];
|
|
@@ -7,7 +7,7 @@ import { renderEasyScoreRhythm } from '../../easyscore-rhythm.mjs';
|
|
|
7
7
|
import { example as e, number, select, setup, staff, text } from './helpers.mjs';
|
|
8
8
|
const group = 'Layout & composition';
|
|
9
9
|
export const layout = [
|
|
10
|
-
e('easyscore-first-score', 'EasyScore: first score', group, 'Create notes, an annotation, a tie, a voice, and a system through EasyScore.', 'EasyScore Annotation StaveTie Voice System', `//
|
|
10
|
+
e('easyscore-first-score', 'EasyScore: first score', group, 'Create notes, an annotation, a tie, a voice, and a system through EasyScore.', 'EasyScore Annotation StaveTie Voice System', `// Follow the lowest C from chord to chord. Head index zero on both ends ties only that pitch.
|
|
11
11
|
(${createEasyScoreExample.toString()})(VF, { elementId: 'score', width, height }, ink);`, [], 'EasyScore.create() validates before construction. Helpers return native VexFlow objects. Typed helpers cover all notation families; native setters remain available.'),
|
|
12
12
|
e('easyscore-references', 'EasyScore: references & extensions', group, 'Resolve named notes, adopt native extensions, and click parsed notes to select their source.', 'EasyScore getElement getNote getSource adopt Annotation StaveTie Curve', `// Click either C4 note to select its notation in this editor.
|
|
13
13
|
(${createEasyScoreReferencesExample.toString()})(VF, { elementId: 'score', width, height }, ink);`, [], 'IDs are local to each score. Adopted notes and drawables share the normal retained lifecycle. Native objects have no notation source. Inspector selection requires one unescaped matching literal; computed or ambiguous input is shown without guessing an editor location.'),
|
|
@@ -82,6 +82,7 @@ for (let beat = 0; beat <= 4; beat++) {
|
|
|
82
82
|
}
|
|
83
83
|
ctx.restore();`, [number('scale', 'Pixels per quarter', 140, 120, 180, 10), select('voices', 'Voices', 'two', ['one', 'two'])], 'Set spacing on Formatter, or System.details. Omit pixelsPerQuarter to fit a supplied width. Crowded notation reports the minimum scale and width instead of moving notes off the grid.'),
|
|
84
84
|
e('voices', 'Multiple voices', group, 'Independent voices share a staff and align at common musical times.', 'Voice Formatter ModifierContext TickContext', `${setup}
|
|
85
|
+
// Opposite stems make it possible to read the two independent rhythms on one stave.
|
|
85
86
|
const upper = score.voice(score.notes('C5/h, D5', { stem: 'up' }));
|
|
86
87
|
const lower = score.voice(score.notes('G4/q, A4, B4, A4', { stem: 'down' }));
|
|
87
88
|
factory.System({ x: 30, y: 65, width: width - 60 })
|
|
@@ -96,12 +97,13 @@ for (const notes of score.measures('C5/h, E5 | G5/q, E5, D5, C5 | E5/h, G5 | C5/
|
|
|
96
97
|
sheet.format();
|
|
97
98
|
factory.getContext().resize(width, sheet.getHeight() + 30);
|
|
98
99
|
factory.draw();`, [number('rowWidth', 'Row width', 620, 200, 900, 20)]),
|
|
99
|
-
e('styles', 'Color & highlighting', group, 'Set a foreground for the score and keep individual highlights.', 'Element Factory', staff("score.notes('C5/q, E5, G5, C6')", '
|
|
100
|
-
e('ghosts', 'Ghost notes', group, 'An invisible tickable reserves rhythmic space without drawing a note.', 'GhostNote', staff("[...score.notes('C5/q'), factory.GhostNote({ duration: 'q' }), ...score.notes('E5/q, G5')]"), [], 'The empty second beat is intentional. GhostNote contributes time and spacing without a visible notehead.'),
|
|
101
|
-
e('repeat-notes', 'Measure-repeat symbols', group, 'A repeat glyph can stand in for a repeated measure.', 'RepeatNote', staff("[factory.RepeatNote(params.type, { duration: 'w' })]"), [select('type', 'Repeat', '1', ['1', '2', '4', 'slash'])]),
|
|
102
|
-
e('glyph-notes', 'Glyph notes', group, 'Use a music glyph as a rhythmically positioned note.', 'GlyphNote', staff("[factory.GlyphNote(VF.Glyphs.segno, { duration: 'h' }), factory.GlyphNote(VF.Glyphs.coda, { duration: 'h' })]")),
|
|
103
|
-
e('subgroups', 'Note subgroups', group, 'Attach a small inline group, such as a clef change, to a note.', 'NoteSubGroup ClefNote', staff("score.notes('C5/q, E5, G5, C6')", "
|
|
100
|
+
e('styles', 'Color & highlighting', group, 'Set a foreground for the score and keep individual highlights.', 'Element Factory', staff("score.notes('C5/q, E5, G5, C6')", '// Only the selected note overrides the shared ink. The index starts at zero.\nnotes[params.index].setStyle({ fillStyle: params.color, strokeStyle: params.color });'), [number('index', 'Note index', 1, 0, 3), text('color', 'Highlight color', '#b74632')]),
|
|
101
|
+
e('ghosts', 'Ghost notes', group, 'An invisible tickable reserves rhythmic space without drawing a note.', 'GhostNote', staff("[...score.notes('C5/q'), factory.GhostNote({ duration: 'q' }), ...score.notes('E5/q, G5')]", '// Look for the empty second beat between C and E. It still counts toward the bar.'), [], 'The empty second beat is intentional. GhostNote contributes time and spacing without a visible notehead.'),
|
|
102
|
+
e('repeat-notes', 'Measure-repeat symbols', group, 'A repeat glyph can stand in for a repeated measure.', 'RepeatNote', staff("[factory.RepeatNote(params.type, { duration: 'w' })]", '// The whole-note duration reserves the bar for its repeat symbol.'), [select('type', 'Repeat', '1', ['1', '2', '4', 'slash'])]),
|
|
103
|
+
e('glyph-notes', 'Glyph notes', group, 'Use a music glyph as a rhythmically positioned note.', 'GlyphNote', staff("[factory.GlyphNote(VF.Glyphs.segno, { duration: 'h' }), factory.GlyphNote(VF.Glyphs.coda, { duration: 'h' })]", '// The segno and coda each take two beats, so their horizontal positions come from the voice.')),
|
|
104
|
+
e('subgroups', 'Note subgroups', group, 'Attach a small inline group, such as a clef change, to a note.', 'NoteSubGroup ClefNote', staff("score.notes('C5/q, E5, G5, C6')", "// Give the small clef to the second note so the formatter leaves space just before it.\nnotes[1].addModifier(factory.NoteSubGroup({ notes: [new VF.ClefNote('bass', 'small')] }), 0);")),
|
|
104
105
|
e('crescendo-note', 'Rhythmic crescendo', group, 'A crescendo can occupy musical time inside a voice.', 'Crescendo', `${setup}
|
|
106
|
+
// This wedge has its own whole-note duration in the voice.
|
|
105
107
|
const crescendo = new VF.Crescendo({ duration: 'w' }).setLine(params.line);
|
|
106
108
|
const voice = factory.Voice().addTickables([crescendo]);
|
|
107
109
|
factory.System({ x: 30, y: 60, width: width - 60 }).addStave({ voices: [voice] });
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { example as e, number, select, setup, staff, text } from './helpers.mjs';
|
|
2
2
|
const group = 'Notes & rhythm';
|
|
3
3
|
export const notes = [
|
|
4
|
-
e('notes', 'Notes & stems', group, 'Create notes from pitch and duration strings. Adjust stem direction.', 'StaveNote Stem Flag EasyScore', staff('score.notes(params.phrase, { stem: params.stem })'), [
|
|
4
|
+
e('notes', 'Notes & stems', group, 'Create notes from pitch and duration strings. Adjust stem direction.', 'StaveNote Stem Flag EasyScore', staff('score.notes(params.phrase, { stem: params.stem })', '// Edit the first /q or /8 in the Phrase control to move the next attack.'), [
|
|
5
5
|
text('phrase', 'Phrase', 'C5/q, D5/8, E5, G5/q, E5'),
|
|
6
6
|
select('stem', 'Stem direction', 'auto', ['auto', 'up', 'down']),
|
|
7
7
|
], 'EasyScore uses scientific pitch names. /q, /8, and /h select quarter, eighth, and half notes. Omitted durations carry forward.'),
|
|
8
|
-
e('rests', 'Rests', group, 'Compare whole, half, quarter, eighth, and sixteenth rests.', 'StaveNote EasyScore', staff("score.notes('B4/w/r, B4/h/r, B4/q/r, B4/8/r, B4/16/r')")),
|
|
9
|
-
e('chords', 'Chords & seconds', group, 'Stack pitches and inspect how adjacent noteheads shift to avoid one another.', 'StaveNote NoteHead', staff('score.notes(params.phrase, { stem: params.stem })'), [
|
|
8
|
+
e('rests', 'Rests', group, 'Compare whole, half, quarter, eighth, and sixteenth rests.', 'StaveNote EasyScore', staff("score.notes('B4/w/r, B4/h/r, B4/q/r, B4/8/r, B4/16/r')", '// Remove /r from one entry to see a B with the same duration as the rest.')),
|
|
9
|
+
e('chords', 'Chords & seconds', group, 'Stack pitches and inspect how adjacent noteheads shift to avoid one another.', 'StaveNote NoteHead', staff('score.notes(params.phrase, { stem: params.stem })', '// Put two neighboring pitches inside the same parentheses and look for the displaced head.'), [
|
|
10
10
|
text('phrase', 'Chords', '(C4 E4 G4)/q, (D4 E4 F4), (C5 D5 E5), (G4 B4 D5)'),
|
|
11
11
|
select('stem', 'Stems', 'up', ['up', 'down']),
|
|
12
12
|
]),
|
|
13
|
-
e('noteheads', 'Notehead shapes', group, 'Compare cross, diamond, triangle, and slash noteheads.', 'StaveNote NoteHead', staff("['c/4', 'd/4', 'e/4', 'f/4'].map(key => factory.StaveNote({ keys: [key + '/' + params.shape], duration: 'q' }))"), [select('shape', 'Shape', 'D', ['D', 'X0', 'X1', 'X2', 'T0', 'S1'])]),
|
|
14
|
-
e('dots', 'Dotted notes', group, 'Render single and double augmentation dots beside noteheads.', 'Dot StaveNote', staff("score.notes('C5/q., D5/8, E5/q.., G5/16')")),
|
|
13
|
+
e('noteheads', 'Notehead shapes', group, 'Compare cross, diamond, triangle, and slash noteheads.', 'StaveNote NoteHead', staff("['c/4', 'd/4', 'e/4', 'f/4'].map(key => factory.StaveNote({ keys: [key + '/' + params.shape], duration: 'q' }))", '// The suffix after the octave selects the head shape. Remove it to compare a normal head.'), [select('shape', 'Shape', 'D', ['D', 'X0', 'X1', 'X2', 'T0', 'S1'])]),
|
|
14
|
+
e('dots', 'Dotted notes', group, 'Render single and double augmentation dots beside noteheads.', 'Dot StaveNote', staff("score.notes('C5/q., D5/8, E5/q.., G5/16')", '// One dot adds half the original duration. A second adds another quarter of the original.')),
|
|
15
15
|
e('beams', 'Beams', group, 'Group eighth notes under a beam. Edit pitches to change its slope.', 'Beam StemmableNote', staff('score.notes(params.phrase)', '// Automatic stems are resolved for the complete group.\nscore.beam(notes);'), [text('phrase', 'Eighth notes', 'C5/8, D5, E5, G5, A5, G5, E5, D5')]),
|
|
16
16
|
e('beamed-tuplets', 'Beamed tuplets', group, 'Keep all seven stems on the same side of a 7:4 beam, including when pitches cross the middle line.', 'Tuplet Beam EasyScore Formatter', `${setup}
|
|
17
17
|
const phrase = params.phrase === 'ascending'
|
|
@@ -30,20 +30,22 @@ factory.draw();`, [
|
|
|
30
30
|
select('phrase', 'Phrase', 'ascending', ['ascending', 'descending']),
|
|
31
31
|
select('spacing', 'Spacing', 'proportional', ['proportional', 'engraving']),
|
|
32
32
|
], 'Automatic stems use a shared direction. Explicit stem choices are preserved. Use beam options autoStem: false for intentional mixed automatic stems.'),
|
|
33
|
-
e('tuplets', 'Tuplets', group, 'Fit a group of notes into a different rhythmic span.', 'Tuplet', staff("score.notes('C5/8, D5, E5, G5, E5, D5')", '
|
|
34
|
-
e('grace', 'Grace notes', group, 'Small notes lead into a full-sized note, with an optional slur.', 'GraceNote GraceNoteGroup', staff("score.notes('C5/q, E5, G5, C6')",
|
|
33
|
+
e('tuplets', 'Tuplets', group, 'Fit a group of notes into a different rhythmic span.', 'Tuplet', staff("score.notes('C5/8, D5, E5, G5, E5, D5')", '// All six notes share the time selected by the Notes occupied control.\nfactory.Tuplet({ notes, options: { numNotes: 6, notesOccupied: params.occupied, ratioed: true, bracketed: true } });'), [select('occupied', 'Notes occupied', 4, [2, 4, 8])]),
|
|
34
|
+
e('grace', 'Grace notes', group, 'Small notes lead into a full-sized note, with an optional slur.', 'GraceNote GraceNoteGroup', staff("score.notes('C5/q, E5, G5, C6')", `// The small D and E lead into the first C. They belong to that note as a group.
|
|
35
|
+
const grace = ['d/5', 'e/5'].map(key => factory.GraceNote({ keys: [key], duration: '16', slash: params.slash === 'yes' }));
|
|
35
36
|
notes[0].addModifier(factory.GraceNoteGroup({ notes: grace, slur: true }), 0);`), [select('slash', 'Slash', 'yes', ['yes', 'no'])]),
|
|
36
|
-
e('accidentals', 'Accidentals', 'Marks & expression', 'Alter a pitch with sharps, flats, naturals, or a cautionary accidental.', 'Accidental', staff("score.notes('C5/q, D5, E5, F5')",
|
|
37
|
+
e('accidentals', 'Accidentals', 'Marks & expression', 'Alter a pitch with sharps, flats, naturals, or a cautionary accidental.', 'Accidental', staff("score.notes('C5/q, D5, E5, F5')", `// Each head needs its own sign. Put parentheses around the last one as a reminder.
|
|
38
|
+
notes.forEach((note, index) => {
|
|
37
39
|
const accidental = factory.Accidental({ type: params.type });
|
|
38
40
|
if (index === 3) accidental.setAsCautionary();
|
|
39
41
|
note.addModifier(accidental, 0);
|
|
40
42
|
});`), [select('type', 'Accidental', '#', ['#', 'b', 'n', '##', 'bb'])]),
|
|
41
|
-
e('microtones', 'Microtonal accidentals', 'Marks & expression', 'Explore quarter-tone and other microtonal pitch marks.', 'Accidental', staff("score.notes('C5/q, D5, E5, F5')", "['+', '++', 'db', 'bbs'].forEach((type, i) => notes[i].addModifier(factory.Accidental({ type }), 0));")),
|
|
42
|
-
e('articulations', 'Articulations', 'Marks & expression', 'Small marks describe the attack and length of a note.', 'Articulation', staff("score.notes('C5/q, D5, E5, G5')", '
|
|
43
|
+
e('microtones', 'Microtonal accidentals', 'Marks & expression', 'Explore quarter-tone and other microtonal pitch marks.', 'Accidental', staff("score.notes('C5/q, D5, E5, F5')", "// Each sign is a different accidental glyph. Attach one per note to compare their shapes.\n['+', '++', 'db', 'bbs'].forEach((type, i) => notes[i].addModifier(factory.Accidental({ type }), 0));")),
|
|
44
|
+
e('articulations', 'Articulations', 'Marks & expression', 'Small marks describe the attack and length of a note.', 'Articulation', staff("score.notes('C5/q, D5, E5, G5')", '// Attach a fresh mark to head zero of each note so it follows that note when spaced.\nnotes.forEach(note => note.addModifier(factory.Articulation({ type: params.type, position: params.position }), 0));'), [
|
|
43
45
|
select('type', 'Articulation', 'a.', ['a.', 'a-', 'a>', 'a^', 'a@a', 'a@u']),
|
|
44
46
|
select('position', 'Position', 'above', ['above', 'below']),
|
|
45
47
|
]),
|
|
46
|
-
e('ornaments', 'Ornaments', 'Marks & expression', 'Attach turns, mordents, trills, and other ornaments to notes.', 'Ornament', staff("score.notes('C5/q, D5, E5, G5')", '
|
|
48
|
+
e('ornaments', 'Ornaments', 'Marks & expression', 'Attach turns, mordents, trills, and other ornaments to notes.', 'Ornament', staff("score.notes('C5/q, D5, E5, G5')", '// A trill or turn belongs to one note. Give each note its own ornament.\nnotes.forEach(note => note.addModifier(factory.Ornament(params.type), 0));'), [
|
|
47
49
|
select('type', 'Ornament', 'tr', [
|
|
48
50
|
'tr',
|
|
49
51
|
'mordent',
|
|
@@ -55,7 +57,7 @@ notes[0].addModifier(factory.GraceNoteGroup({ notes: grace, slur: true }), 0);`)
|
|
|
55
57
|
'fall',
|
|
56
58
|
]),
|
|
57
59
|
]),
|
|
58
|
-
e('tremolo', 'Tremolo', 'Marks & expression', 'Repeated strokes across a stem indicate rapid repetition.', 'Tremolo', staff("score.notes('C5/h, E5, G5')", '
|
|
59
|
-
e('fingering', 'Fingerings', 'Marks & expression', 'Place a finger number beside each pitch of a chord.', 'FretHandFinger', staff("score.notes('(C5 E5 G5)/h, (D5 F5 A5)')", "
|
|
60
|
-
e('parentheses', 'Parentheses', 'Marks & expression', 'Parenthesize a pitch to indicate an optional or editorial note.', 'Parenthesis', staff("score.notes('C5/q, D5, E5, G5')", '
|
|
60
|
+
e('tremolo', 'Tremolo', 'Marks & expression', 'Repeated strokes across a stem indicate rapid repetition.', 'Tremolo', staff("score.notes('C5/h, E5, G5')", '// Change the stroke count to change the subdivision shown on each stem.\nnotes.forEach(note => note.addModifier(new VF.Tremolo(params.strokes), 0));'), [number('strokes', 'Strokes', 3, 1, 4)]),
|
|
61
|
+
e('fingering', 'Fingerings', 'Marks & expression', 'Place a finger number beside each pitch of a chord.', 'FretHandFinger', staff("score.notes('(C5 E5 G5)/h, (D5 F5 A5)')", "// Match each finger number to its own head in the chord using the same index.\nnotes.forEach(note => ['1', '3', '5'].forEach((number, i) => note.addModifier(factory.Fingering({ number, position: params.position }), i)));"), [select('position', 'Position', 'left', ['left', 'right', 'above', 'below'])]),
|
|
62
|
+
e('parentheses', 'Parentheses', 'Marks & expression', 'Parenthesize a pitch to indicate an optional or editorial note.', 'Parenthesis', staff("score.notes('C5/q, D5, E5, G5')", '// Mark just the second and fourth notes as optional.\nVF.Parenthesis.buildAndAttach([notes[1], notes[3]]);')),
|
|
61
63
|
];
|
|
@@ -3,6 +3,7 @@ const group = 'Staves & structure';
|
|
|
3
3
|
export const staves = [
|
|
4
4
|
e('clefs', 'Clefs', group, 'Compare clefs and their positions on the staff.', 'Stave Clef', `${setup}
|
|
5
5
|
const stave = factory.Stave({ x: 35, y: 65, width: width - 70 });
|
|
6
|
+
// The clef is attached to the stave and reserves space before the first note.
|
|
6
7
|
stave.addClef(params.clef);
|
|
7
8
|
factory.draw();`, [
|
|
8
9
|
select('clef', 'Clef', 'treble', [
|
|
@@ -19,14 +20,16 @@ factory.draw();`, [
|
|
|
19
20
|
]),
|
|
20
21
|
]),
|
|
21
22
|
e('stave', 'Staff lines', group, 'Change the number and spacing of lines, from a percussion staff to a conventional stave.', 'Stave', `${setup}
|
|
23
|
+
// Change the line count for percussion, or the gap to give each line more room.
|
|
22
24
|
factory.Stave({ x: 35, y: 65, width: width - 70,
|
|
23
25
|
options: { numLines: params.lines, spacingBetweenLinesPx: params.spacing }
|
|
24
26
|
});
|
|
25
27
|
factory.draw();`, [number('lines', 'Lines', 5, 1, 8), number('spacing', 'Spacing', 10, 5, 20)]),
|
|
26
|
-
e('keys', 'Key signatures', group, 'Render sharp and flat key signatures.', 'KeySignature Stave', staff("score.notes('C5/q, D5, E5, G5')", '', '', ".addClef('treble').addKeySignature(params.key)"), [select('key', 'Key', 'D', ['C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#', 'F', 'Bb', 'Eb', 'Ab', 'Db', 'Gb', 'Cb'])]),
|
|
27
|
-
e('meter', 'Time signatures', group, 'Show simple, compound, common, and cut time.', 'TimeSignature', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').addTimeSignature(params.time)"), [select('time', 'Meter', '4/4', ['2/4', '3/4', '4/4', '6/8', '9/8', '12/8', 'C', 'C|'])]),
|
|
28
|
+
e('keys', 'Key signatures', group, 'Render sharp and flat key signatures.', 'KeySignature Stave', staff("score.notes('C5/q, D5, E5, G5')", '// Changing the signature changes which sharps or flats the player sees at the start.', '', ".addClef('treble').addKeySignature(params.key)"), [select('key', 'Key', 'D', ['C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#', 'F', 'Bb', 'Eb', 'Ab', 'Db', 'Gb', 'Cb'])]),
|
|
29
|
+
e('meter', 'Time signatures', group, 'Show simple, compound, common, and cut time.', 'TimeSignature', staff("score.notes('C5/q, E5, G5, C6')", '// The control changes the printed signature. The sample phrase stays the same.', '', ".addClef('treble').addTimeSignature(params.time)"), [select('time', 'Meter', '4/4', ['2/4', '3/4', '4/4', '6/8', '9/8', '12/8', 'C', 'C|'])]),
|
|
28
30
|
e('barlines', 'Barlines & repeats', group, 'Draw boundaries, endings, and repeat marks on a staff.', 'Barline Stave', `${setup}
|
|
29
31
|
const stave = factory.Stave({ x: 35, y: 65, width: width - 70 }).addClef('treble');
|
|
32
|
+
// The beginning repeat stays fixed while the control changes the other end.
|
|
30
33
|
stave.setBegBarType(VF.Barline.type.REPEAT_BEGIN);
|
|
31
34
|
stave.setEndBarType(VF.Barline.type[params.ending]);
|
|
32
35
|
factory.draw();`, [
|
|
@@ -44,6 +47,7 @@ factory.draw();`, [
|
|
|
44
47
|
const system = factory.System({ x: 45, y: 30, width: width - 80, spaceBetweenStaves: 9 });
|
|
45
48
|
system.addStave({ voices: [score.voice(score.notes('C5/w'))] }).addClef('treble');
|
|
46
49
|
system.addStave({ voices: [score.voice(score.notes('C3/w', { clef: 'bass' }))] }).addClef('bass');
|
|
50
|
+
// Add the brace after both staves exist so it can span from one to the other.
|
|
47
51
|
system.addConnector(params.connector);
|
|
48
52
|
factory.draw();`, [
|
|
49
53
|
select('connector', 'Connector', 'brace', [
|
|
@@ -55,10 +59,10 @@ factory.draw();`, [
|
|
|
55
59
|
'thinDouble',
|
|
56
60
|
]),
|
|
57
61
|
]),
|
|
58
|
-
e('tempo', 'Tempo markings', group, 'Combine a tempo name with a metronome mark.', 'StaveTempo', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').setTempo({ name: params.name, duration: 'q', bpm: params.bpm }, 0)"), [text('name', 'Tempo', 'Andante'), number('bpm', 'BPM', 76, 30, 220)]),
|
|
59
|
-
e('rehearsal', 'Rehearsal marks & text', group, 'Add a section label and a short instruction to the staff.', 'StaveSection StaveText', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').setSection(params.section, 0).setText(params.instruction, VF.Modifier.Position.BELOW)"), [text('section', 'Section', 'A'), text('instruction', 'Instruction', 'dolce')]),
|
|
60
|
-
e('volta', 'Volta endings', group, 'Bracket an alternate ending above a repeated section.', 'Volta', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').setVoltaType(VF.Volta.type.BEGIN_END, params.label, 0)"), [text('label', 'Ending label', '1.')]),
|
|
61
|
-
e('repetition', 'Repeat instructions', group, 'Coda, segno, and textual repeat instructions guide the reader through a score.', 'Repetition', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').setRepetitionType(VF.Repetition.type[params.mark], 0)"), [
|
|
62
|
+
e('tempo', 'Tempo markings', group, 'Combine a tempo name with a metronome mark.', 'StaveTempo', staff("score.notes('C5/q, E5, G5, C6')", '// The q makes the quarter note the unit counted by the metronome.', '', ".addClef('treble').setTempo({ name: params.name, duration: 'q', bpm: params.bpm }, 0)"), [text('name', 'Tempo', 'Andante'), number('bpm', 'BPM', 76, 30, 220)]),
|
|
63
|
+
e('rehearsal', 'Rehearsal marks & text', group, 'Add a section label and a short instruction to the staff.', 'StaveSection StaveText', staff("score.notes('C5/q, E5, G5, C6')", '// The section letter belongs to the whole stave, so it stays in place when pitches change.', '', ".addClef('treble').setSection(params.section, 0).setText(params.instruction, VF.Modifier.Position.BELOW)"), [text('section', 'Section', 'A'), text('instruction', 'Instruction', 'dolce')]),
|
|
64
|
+
e('volta', 'Volta endings', group, 'Bracket an alternate ending above a repeated section.', 'Volta', staff("score.notes('C5/q, E5, G5, C6')", '// The label tells the player which pass uses this ending.', '', ".addClef('treble').setVoltaType(VF.Volta.type.BEGIN_END, params.label, 0)"), [text('label', 'Ending label', '1.')]),
|
|
65
|
+
e('repetition', 'Repeat instructions', group, 'Coda, segno, and textual repeat instructions guide the reader through a score.', 'Repetition', staff("score.notes('C5/q, E5, G5, C6')", '// A repeat instruction is printed on the stave at its designated side.', '', ".addClef('treble').setRepetitionType(VF.Repetition.type[params.mark], 0)"), [
|
|
62
66
|
select('mark', 'Instruction', 'CODA_RIGHT', [
|
|
63
67
|
'CODA_RIGHT',
|
|
64
68
|
'SEGNO_LEFT',
|
|
@@ -69,6 +73,7 @@ factory.draw();`, [
|
|
|
69
73
|
]),
|
|
70
74
|
]),
|
|
71
75
|
e('changes', 'Changes within a measure', group, 'Insert a clef, key, or meter change into a sequence of tickables.', 'ClefNote KeySigNote TimeSigNote BarNote', `${setup}
|
|
76
|
+
// Put the clef before the lower F and construct that note with its new bass clef.
|
|
72
77
|
const notes = [
|
|
73
78
|
...score.notes('C5/h'), factory.BarNote(),
|
|
74
79
|
factory.ClefNote({ type: 'bass', options: { size: 'small' } }),
|
|
@@ -80,6 +85,7 @@ factory.System({ x: 30, y: 65, width: width - 60 }).addStave({ voices: [voice] }
|
|
|
80
85
|
factory.draw();`),
|
|
81
86
|
e('multirests', 'Multi-measure rests', group, 'Render multi-measure rests as a bar or rest symbols.', 'MultiMeasureRest', `${setup}
|
|
82
87
|
const stave = factory.Stave({ x: 35, y: 65, width: width - 70 }).addClef('treble');
|
|
88
|
+
// The count above the resting bar tells the player how many measures to wait.
|
|
83
89
|
factory.MultiMeasureRest({ numberOfMeasures: params.measures, useSymbols: params.style === 'symbols' }).setStave(stave);
|
|
84
90
|
factory.draw();`, [number('measures', 'Measures', 8, 1, 32), select('style', 'Style', 'bar', ['bar', 'symbols'])]),
|
|
85
91
|
];
|
|
@@ -2,6 +2,7 @@ import { example as e, number, select, setup, staff } from './helpers.mjs';
|
|
|
2
2
|
const group = 'Strings & tablature';
|
|
3
3
|
function tab(modifications = '', after = '') {
|
|
4
4
|
return `${setup}
|
|
5
|
+
// Keep one string fixed so you can follow the fretting hand as the numbers rise.
|
|
5
6
|
const notes = [3, 5, 7, 8].map(fret => factory.TabNote({ positions: [{ str: params.string ?? 2, fret }], duration: 'q' }));
|
|
6
7
|
${modifications}
|
|
7
8
|
const stave = factory.TabStave({ x: 30, y: 60, width: width - 60 }).addClef('tab');
|
|
@@ -13,13 +14,15 @@ ${after ? '\n// Draw the connection after the fret positions have been calculate
|
|
|
13
14
|
}
|
|
14
15
|
export const strings = [
|
|
15
16
|
e('tablature', 'Tablature', group, 'Render fret numbers on a six-string tablature staff.', 'TabNote TabStave', tab(), [number('string', 'String', 2, 1, 6)]),
|
|
16
|
-
e('bends', 'Bends', group, 'Bend a string up to a target pitch, then release it.', 'Bend', tab("
|
|
17
|
-
e('vibrato', 'Vibrato', group, 'Attach a vibrato mark to a tablature note and adjust its width.', 'Vibrato', tab('
|
|
18
|
-
e('tab-slides', 'Tab slides', group, 'Connect frets with an ascending slide.', 'TabSlide', tab('',
|
|
17
|
+
e('bends', 'Bends', group, 'Bend a string up to a target pitch, then release it.', 'Bend', tab("// Read the bend in two stages. Raise the pitch a full step, then release it.\nnotes[0].addModifier(new VF.Bend([{ type: VF.Bend.UP, text: 'Full' }, { type: VF.Bend.DOWN, text: '' }]), 0);")),
|
|
18
|
+
e('vibrato', 'Vibrato', group, 'Attach a vibrato mark to a tablature note and adjust its width.', 'Vibrato', tab('// The wave begins at the second fret number. Its width controls the length of the printed mark.\nnotes[1].addModifier(new VF.Vibrato().setVibratoWidth(params.length), 0);'), [number('length', 'Wave length', 45, 15, 90)]),
|
|
19
|
+
e('tab-slides', 'Tab slides', group, 'Connect frets with an ascending slide.', 'TabSlide', tab('', `// The line climbs from fret 3 to fret 5 on the same string.
|
|
20
|
+
new VF.TabSlide({ firstNote: notes[0], lastNote: notes[1], firstIndexes: [0], lastIndexes: [0] }, 1)
|
|
19
21
|
.setContext(factory.getContext()).setStyle({ strokeStyle: ink }).drawWithStyle();`)),
|
|
20
|
-
e('tab-ties', 'Hammer-ons & pull-offs', group, 'Label a tablature tie as a hammer-on or pull-off.', 'TabTie', tab('',
|
|
22
|
+
e('tab-ties', 'Hammer-ons & pull-offs', group, 'Label a tablature tie as a hammer-on or pull-off.', 'TabTie', tab('', `// H tells the player to hammer on. For a pull-off, choose P and make the second fret lower.
|
|
23
|
+
new VF.TabTie({ firstNote: notes[0], lastNote: notes[1], firstIndexes: [0], lastIndexes: [0] }, params.label)
|
|
21
24
|
.setContext(factory.getContext()).setStyle({ fillStyle: ink, strokeStyle: ink }).drawWithStyle();`), [select('label', 'Gesture', 'H', ['H', 'P'])]),
|
|
22
|
-
e('grace-tab', 'Grace tablature', group, 'Lead into a fretted note with a small grace-note group.', 'GraceTabNote GraceNoteGroup', tab("
|
|
23
|
-
e('string-numbers', 'String numbers', group, 'Circled string numbers sit beside pitches on a conventional staff.', 'StringNumber', staff("score.notes('C5/q, D5, E5, G5')", "
|
|
24
|
-
e('strokes', 'Arpeggios & brush strokes', group, 'Spread the notes of a chord with a directional stroke.', 'Stroke', staff("score.notes('(C4 E4 G4 C5)/h, (D4 F4 A4 D5)')", '
|
|
25
|
+
e('grace-tab', 'Grace tablature', group, 'Lead into a fretted note with a small grace-note group.', 'GraceTabNote GraceNoteGroup', tab("// Lead into the first full-sized fret with a small fret 2 on the same string.\nconst grace = new VF.GraceTabNote({ positions: [{ str: 2, fret: 2 }], duration: '8' });\nnotes[0].addModifier(new VF.GraceNoteGroup([grace], true), 0);")),
|
|
26
|
+
e('string-numbers', 'String numbers', group, 'Circled string numbers sit beside pitches on a conventional staff.', 'StringNumber', staff("score.notes('C5/q, D5, E5, G5')", "// Place a circled string number by each pitch to suggest where to play it.\nnotes.forEach((note, i) => note.addModifier(factory.StringNumber({ number: String(i + 1), position: 'above' }), 0));")),
|
|
27
|
+
e('strokes', 'Arpeggios & brush strokes', group, 'Spread the notes of a chord with a directional stroke.', 'Stroke', staff("score.notes('(C4 E4 G4 C5)/h, (D4 F4 A4 D5)')", '// The mark belongs to the whole chord and suggests the order in which to strike its strings.\nnotes.forEach(note => note.addModifier(new VF.Stroke(params.type), 0));'), [select('type', 'Stroke type', 3, [1, 2, 3, 4, 5, 6])]),
|
|
25
28
|
];
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
export const scoreKinds = ['chorale', 'piano', 'chamber', 'lead-sheet', 'percussion', 'tab'];
|
|
1
2
|
export function renderScore({ kind = 'chorale', systems = 4, containerId = 'score' } = {}) {
|
|
2
3
|
var _a;
|
|
3
4
|
const VF = globalThis.VexFlow;
|
|
4
5
|
document.documentElement.style.cssText = 'background:white;color:black;color-scheme:light';
|
|
5
6
|
const container = document.getElementById(containerId);
|
|
6
7
|
container.replaceChildren();
|
|
7
|
-
const
|
|
8
|
+
const singleStaff = ['lead-sheet', 'percussion', 'tab'].includes(kind);
|
|
9
|
+
const staffCount = singleStaff ? 1 : kind === 'chamber' ? 3 : 2;
|
|
8
10
|
const systemHeight = staffCount * 150 + 40;
|
|
9
11
|
const renderer = new VF.Renderer(container, VF.Renderer.Backends.SVG);
|
|
10
12
|
renderer.resize(1100, systems * systemHeight);
|
|
@@ -16,8 +18,13 @@ export function renderScore({ kind = 'chorale', systems = 4, containerId = 'scor
|
|
|
16
18
|
for (let system = 0; system < systems; system++) {
|
|
17
19
|
for (let bar = 0; bar < 4; bar++) {
|
|
18
20
|
for (let staff = 0; staff < staffCount; staff++) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
let clef = !singleStaff && staff === staffCount - 1 ? 'bass' : 'treble';
|
|
22
|
+
if (kind === 'percussion')
|
|
23
|
+
clef = 'percussion';
|
|
24
|
+
if (kind === 'tab')
|
|
25
|
+
clef = 'tab';
|
|
26
|
+
const Staff = kind === 'tab' ? VF.TabStave : VF.Stave;
|
|
27
|
+
const stave = new Staff(15 + bar * 267, system * systemHeight + staff * 150 + 35, 267);
|
|
21
28
|
if (bar === 0)
|
|
22
29
|
stave.addClef(clef).addTimeSignature('4/4');
|
|
23
30
|
const voices = [];
|
|
@@ -25,11 +32,21 @@ export function renderScore({ kind = 'chorale', systems = 4, containerId = 'scor
|
|
|
25
32
|
const tuplets = [];
|
|
26
33
|
const ties = [];
|
|
27
34
|
const notes = [];
|
|
28
|
-
const count = kind === 'chorale' ? 4 : kind === '
|
|
35
|
+
const count = kind === 'chorale' ? 4 : kind === 'chamber' ? 12 : 8;
|
|
29
36
|
for (let beat = 0; beat < count; beat++) {
|
|
30
37
|
const key = clef === 'bass' ? ['c/3', 'g/2', 'a/2', 'f/2'][(bar + beat) % 4] : melody[(bar + beat) % 8];
|
|
31
38
|
const keys = kind === 'piano' && staff === 1 ? [key, 'e/3', 'g/3'] : [key];
|
|
32
|
-
|
|
39
|
+
let note;
|
|
40
|
+
if (kind === 'tab') {
|
|
41
|
+
note = new VF.TabNote({ positions: [{ str: 1 + (beat % 3), fret: (beat + bar) % 8 }], duration: '8' }, true);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const pitches = kind === 'percussion' ? (beat % 2 ? ['g/5/x2'] : ['c/5', 'g/5/x2']) : keys;
|
|
45
|
+
note = new VF.StaveNote({ keys: pitches, clef, duration: count === 4 ? 'q' : '8', stemDirection: 1 });
|
|
46
|
+
}
|
|
47
|
+
if (kind === 'lead-sheet' && beat === 0) {
|
|
48
|
+
note.addModifier(new VF.ChordSymbol().addText(['Cmaj7', 'Am7', 'Dm7', 'G7'][bar]), 0);
|
|
49
|
+
}
|
|
33
50
|
if (kind === 'chorale' && staff === 0) {
|
|
34
51
|
const lyric = new VF.Annotation(['Sing', 'with', 'gentle', 'voices'][beat]).setVerticalJustification(VF.Annotation.VerticalJustify.BOTTOM);
|
|
35
52
|
(_a = lyric.setTextBaseline) === null || _a === void 0 ? void 0 : _a.call(lyric, system * systemHeight + 162);
|
|
@@ -44,7 +61,7 @@ export function renderScore({ kind = 'chorale', systems = 4, containerId = 'scor
|
|
|
44
61
|
}
|
|
45
62
|
notes[0].addModifier(new VF.Ornament('tr'), 0);
|
|
46
63
|
}
|
|
47
|
-
else if (kind === 'piano') {
|
|
64
|
+
else if (kind === 'piano' || singleStaff) {
|
|
48
65
|
for (let i = 0; i < notes.length; i += 4)
|
|
49
66
|
beams.push(new VF.Beam(notes.slice(i, i + 4)));
|
|
50
67
|
}
|
|
@@ -57,6 +57,10 @@ export declare class Accidental extends Modifier {
|
|
|
57
57
|
/** Identify explicit cautionary signs without inspecting protected engraving state. */
|
|
58
58
|
isCautionary(): boolean;
|
|
59
59
|
/** Render accidental onto canvas. */
|
|
60
|
+
/** Place the glyph using the same coordinates for measurement and drawing. */
|
|
61
|
+
private positionGlyph;
|
|
62
|
+
/** Visible glyph after formatting, including cautionary or authored shifts. */
|
|
63
|
+
getInkBounds(): import("./boundingbox").BoundingBox;
|
|
60
64
|
draw(): void;
|
|
61
65
|
}
|
|
62
66
|
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Element } from './element';
|
|
2
|
+
import { StaveNote, StaveNoteStruct } from './stavenote';
|
|
3
|
+
/** Same-staff alternating tremolo between adjacent quarter or half notes or chords. */
|
|
4
|
+
export declare class AlternatingTremolo extends Element {
|
|
5
|
+
readonly first: StaveNote;
|
|
6
|
+
readonly last: StaveNote;
|
|
7
|
+
readonly strokes: number;
|
|
8
|
+
constructor(first: StaveNote, last: StaveNote, strokes: number);
|
|
9
|
+
/** Call before building the voice. Each endpoint consumes half its printed duration. */
|
|
10
|
+
static endpoint(note: StaveNoteStruct, strokes: number): StaveNoteStruct;
|
|
11
|
+
/** Draw between stems after formatting. A change of staff or unsupported pair is an explicit error. */
|
|
12
|
+
draw(): void;
|
|
13
|
+
}
|
|
@@ -57,6 +57,15 @@ export declare class Annotation extends Modifier {
|
|
|
57
57
|
* @param just value in `Annotation.Justify`.
|
|
58
58
|
*/
|
|
59
59
|
setJustification(just: string | AnnotationHorizontalJustify): this;
|
|
60
|
+
/** A phrase lane places this mark outside local tuplets. */
|
|
61
|
+
phraseManaged: boolean;
|
|
62
|
+
private layoutBaseline?;
|
|
63
|
+
private connectorPadding;
|
|
64
|
+
/** Space reserved on both sides for a syllable connector during horizontal formatting. */
|
|
65
|
+
setConnectorPadding(px: number): this;
|
|
66
|
+
/** An authored baseline always takes precedence over automatic phrase placement. */
|
|
67
|
+
getTextBaseline(): number | undefined;
|
|
68
|
+
setLayoutBaseline(y?: number): void;
|
|
60
69
|
/** Use an absolute text baseline. Pass undefined to restore automatic placement. */
|
|
61
70
|
setTextBaseline(y?: number): this;
|
|
62
71
|
/** Compute horizontal placement after formatting, without drawing or changing position. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BoundingBox } from './boundingbox';
|
|
1
2
|
import { Builder } from './easyscore';
|
|
2
3
|
import { Modifier } from './modifier';
|
|
3
4
|
import { ModifierContextState } from './modifiercontext';
|
|
@@ -76,9 +77,16 @@ export declare class Articulation extends Modifier {
|
|
|
76
77
|
* - Odd codes will be positioned BELOW
|
|
77
78
|
*/
|
|
78
79
|
constructor(type: string);
|
|
80
|
+
private betweenLinesOverride?;
|
|
79
81
|
protected reset(): void;
|
|
80
82
|
/** Set if articulation should be rendered between lines. */
|
|
81
83
|
setBetweenLines(betweenLines?: boolean): this;
|
|
82
|
-
|
|
84
|
+
private layoutShiftY;
|
|
85
|
+
/** Derived clearance from neighboring attacks, recomputed at each phrase layout. */
|
|
86
|
+
setLayoutShiftY(y: number): void;
|
|
87
|
+
/** Resolve the glyph origin after its owner and modifier context have been formatted. */
|
|
88
|
+
private getPlacement;
|
|
89
|
+
/** Get visible glyph ink without mutating its alignment or drawing coordinates. */
|
|
90
|
+
getInkBounds(): BoundingBox;
|
|
83
91
|
draw(): void;
|
|
84
92
|
}
|