vexflow 5.4.0 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +1740 -372
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +565 -258
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow.js +2 -2
  10. package/build/cjs/vexflow.js.map +1 -1
  11. package/build/esm/src/annotation.js +2 -1
  12. package/build/esm/src/continuouslayout.js +107 -16
  13. package/build/esm/src/continuousspan.js +9 -1
  14. package/build/esm/src/easyscore/composition.js +83 -18
  15. package/build/esm/src/factory.js +2 -9
  16. package/build/esm/src/formatter.js +1 -1
  17. package/build/esm/src/fretdiagram.js +6 -2
  18. package/build/esm/src/gracenotegroup.js +4 -3
  19. package/build/esm/src/guitarmodifiers.js +4 -1
  20. package/build/esm/src/metrics.js +24 -5
  21. package/build/esm/src/note.js +1 -0
  22. package/build/esm/src/notehead.js +21 -10
  23. package/build/esm/src/phraselayout.js +13 -5
  24. package/build/esm/src/publication.js +10 -5
  25. package/build/esm/src/publicationview.js +3 -2
  26. package/build/esm/src/stave.js +4 -2
  27. package/build/esm/src/stavenote.js +56 -13
  28. package/build/esm/src/stavesection.js +15 -10
  29. package/build/esm/src/stavetie.js +3 -2
  30. package/build/esm/src/strokes.js +1 -1
  31. package/build/esm/src/svgcontext.js +11 -3
  32. package/build/esm/src/tabnote.js +6 -8
  33. package/build/esm/src/tabtie.js +3 -0
  34. package/build/esm/src/version.js +3 -3
  35. package/build/esm/tests/chordsymbol_tests.js +4 -1
  36. package/build/esm/tests/demo_petzold_tests.js +26 -14
  37. package/build/esm/tests/demo_repertoire_tests.js +5 -1
  38. package/build/esm/tests/demos/ballade.js +15 -0
  39. package/build/esm/tests/demos/electric.js +1 -3
  40. package/build/esm/tests/demos/fugue.js +19 -0
  41. package/build/esm/tests/demos/greensleeves.js +1 -2
  42. package/build/esm/tests/demos/kesh.js +2 -3
  43. package/build/esm/tests/demos/saints.js +17 -5
  44. package/build/esm/tests/engraving/continuous-studies.mjs +24 -0
  45. package/build/esm/tests/engraving/publication-studies.mjs +30 -0
  46. package/build/esm/tests/font_tests.js +8 -0
  47. package/build/esm/tests/gracenote_tests.js +1 -1
  48. package/build/esm/tests/gracetabnote_tests.js +19 -3
  49. package/build/esm/tests/node/chord-kerning-tests.mjs +2 -2
  50. package/build/esm/tests/node/continuous-score-tests.mjs +157 -2
  51. package/build/esm/tests/node/easyscore-tests.mjs +38 -0
  52. package/build/esm/tests/node/engraving-layout-tests.mjs +33 -0
  53. package/build/esm/tests/node/instrument-profile-tests.mjs +40 -0
  54. package/build/esm/tests/node/local-engraving-tests.mjs +58 -0
  55. package/build/esm/tests/node/metrics-tests.mjs +2 -0
  56. package/build/esm/tests/node/phrase-layout-tests.mjs +58 -5
  57. package/build/esm/tests/node/publication-tests.mjs +158 -2
  58. package/build/esm/tests/node/svg-export-tests.mjs +50 -21
  59. package/build/esm/tests/scores/ballade.js +399 -0
  60. package/build/esm/tests/scores/drums.js +93 -0
  61. package/build/esm/tests/scores/electric.js +83 -0
  62. package/build/esm/tests/scores/falseta.js +46 -0
  63. package/build/esm/tests/scores/fugue.js +366 -0
  64. package/build/esm/tests/scores/guitar.js +32 -0
  65. package/build/esm/tests/scores/kesh.js +146 -0
  66. package/build/esm/tests/scores/prelude.js +84 -0
  67. package/build/esm/tests/scores/quartertones.js +78 -0
  68. package/build/esm/tests/scores/saints.js +70 -0
  69. package/build/esm/tests/scores/sumer.js +126 -0
  70. package/build/esm/tests/scores/viewer.js +162 -0
  71. package/build/esm/tests/tabnote_tests.js +43 -0
  72. package/build/esm/tests/vexflow_test_helpers.js +1 -0
  73. package/build/esm/tools/explorer/catalog/expression.mjs +16 -6
  74. package/build/esm/tools/explorer/catalog/guitar.mjs +2 -2
  75. package/build/types/src/continuouslayout.d.ts +4 -0
  76. package/build/types/src/continuousspan.d.ts +10 -2
  77. package/build/types/src/easyscore/composition.d.ts +19 -0
  78. package/build/types/src/fretdiagram.d.ts +2 -0
  79. package/build/types/src/instrumentprofile.d.ts +4 -0
  80. package/build/types/src/note.d.ts +2 -0
  81. package/build/types/src/notehead.d.ts +2 -0
  82. package/build/types/src/publication.d.ts +3 -1
  83. package/build/types/src/stave.d.ts +4 -2
  84. package/build/types/src/stavenote.d.ts +10 -0
  85. package/build/types/src/stavesection.d.ts +3 -0
  86. package/build/types/src/svgcontext.d.ts +2 -0
  87. package/build/types/src/typeguard.d.ts +1 -0
  88. package/changelog/CHANGELOG.md +16 -0
  89. package/package.json +4 -1
  90. package/tests/all.html +9 -0
  91. package/tests/demo_petzold_tests.ts +30 -16
  92. package/tests/demos/ballade.ts +36 -0
  93. package/tests/demos/ballade.webp +0 -0
  94. package/tests/demos/electric.ts +1 -3
  95. package/tests/demos/electric.webp +0 -0
  96. package/tests/demos/fugue.ts +27 -0
  97. package/tests/demos/fugue.webp +0 -0
  98. package/tests/demos/greensleeves.ts +1 -3
  99. package/tests/demos/greensleeves.webp +0 -0
  100. package/tests/demos/kesh.ts +2 -4
  101. package/tests/demos/kesh.webp +0 -0
  102. package/tests/demos/saints.ts +20 -7
  103. package/tests/demos/saints.webp +0 -0
  104. package/tests/flow.html +165 -52
  105. package/tests/minuet.webp +0 -0
  106. package/tests/scores/ballade.js +445 -0
  107. package/tests/scores/drums.js +101 -0
  108. package/tests/scores/drums.webp +0 -0
  109. package/tests/scores/electric.js +93 -0
  110. package/tests/scores/electric.webp +0 -0
  111. package/tests/scores/falseta.js +53 -0
  112. package/tests/scores/falseta.webp +0 -0
  113. package/tests/scores/fugue.js +433 -0
  114. package/tests/scores/guitar.js +34 -0
  115. package/tests/scores/index.html +48 -0
  116. package/tests/scores/kesh.js +171 -0
  117. package/tests/scores/kesh.webp +0 -0
  118. package/tests/scores/prelude.js +90 -0
  119. package/tests/scores/prelude.webp +0 -0
  120. package/tests/scores/quartertones.js +83 -0
  121. package/tests/scores/quartertones.webp +0 -0
  122. package/tests/scores/saints.js +85 -0
  123. package/tests/scores/saints.webp +0 -0
  124. package/tests/scores/sumer.js +139 -0
  125. package/tests/scores/sumer.webp +0 -0
  126. package/tests/scores/viewer.css +132 -0
  127. package/tests/scores/viewer.js +150 -0
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ (() => {
3
+ const title = 'Narrow Steps';
4
+ const credit = 'Example piece · Solo viola in 24 equal divisions of the octave';
5
+ const intro = 'Read the motif twice. In the second phrase the signature raises D and lowers E by a quarter tone. The natural cancels the raised D. Parentheses remind the player of the lowered E.';
6
+ const focus = 'viola-3-2';
7
+ const action = 'Find the cancellation';
8
+ const motif = [
9
+ [
10
+ ['d/4', '+'],
11
+ ['e/4', 'd'],
12
+ ['d/4', 'n'],
13
+ ['e/4', 'd'],
14
+ ],
15
+ [
16
+ ['f/4', 'n'],
17
+ ['e/4', 'd'],
18
+ ['d/4', '+'],
19
+ ['c/4', 'n'],
20
+ ],
21
+ [
22
+ ['c/4', 'n'],
23
+ ['d/4', '+'],
24
+ ['e/4', 'd'],
25
+ ['d/4', '+'],
26
+ ],
27
+ ];
28
+ function create(VF, score) {
29
+ const measures = [...motif, ...motif].map((bar, m) => ({
30
+ voices: [
31
+ {
32
+ autoBeam: true,
33
+ notes: bar.map(([key, sign], i) => ({
34
+ id: 'viola-' + m + '-' + i,
35
+ note: {
36
+ keys: [key],
37
+ duration: i === 3 ? 'q' : '8',
38
+ clef: 'alto',
39
+ notation: [
40
+ {
41
+ kind: 'accidental',
42
+ id: sign,
43
+ label: { '+': 'quarter sharp', d: 'quarter flat', n: 'natural' }[sign],
44
+ },
45
+ ],
46
+ },
47
+ })),
48
+ },
49
+ ],
50
+ }));
51
+ return {
52
+ spec: {
53
+ staves: [{ id: 'Viola', clef: 'alto', time: '5/8', measures }],
54
+ continuous: { boundaries: [{ measure: 4, breakBefore: 'force' }] },
55
+ },
56
+ decorate(c) {
57
+ for (let m = 0; m < 6; m++) {
58
+ const signed = m >= 3;
59
+ const state = new VF.WrittenAccidentalState(signed ? { d: '+', e: 'd' } : {});
60
+ motif[m % 3].forEach(([key, sign], i) => {
61
+ const courtesy = m === 3 && i === 3;
62
+ const printed = state.sign(key, sign, courtesy);
63
+ if (printed) {
64
+ const mark = score.make.accidental({ type: printed });
65
+ c.getNote('viola-' + m + '-' + i).addModifier(courtesy ? mark.setAsCautionary() : mark);
66
+ }
67
+ });
68
+ if (signed)
69
+ c.staves[m][0].addModifier(new VF.KeySignature('C').setOrdered([
70
+ { type: '+', line: 1.5 },
71
+ { type: 'd', line: 1 },
72
+ ]));
73
+ }
74
+ },
75
+ };
76
+ }
77
+ window.FeaturedScores.quartertones = { title, credit, intro, focus, action, create };
78
+ })();
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ (() => {
3
+ const title = 'When the Saints Go Marching In';
4
+ const credit = 'Traditional African American spiritual · Petaluma lead sheet';
5
+ const intro = 'Follow the held “in.” Compare the traditional dominant with the D♭7(♭9) turnaround, then narrow the page to carry the lyric across a system.';
6
+ const choices = ['Reharmonized', 'Traditional'];
7
+ const control = 'Harmony';
8
+ const focus = 'v6-0';
9
+ const fonts = ['Petaluma', 'Academico'];
10
+ const bars = [
11
+ ['C4/q, E4, F4', 'Oh when the', '', ''],
12
+ ['G4/w', 'saints', 'C', 'C:6/9'],
13
+ ['B4/q/r, C4/q, E4, F4', '_ go march- ing', 'C', 'Am:7'],
14
+ ['G4/w', 'in', 'C', 'Dm:11'],
15
+ ['B4/q/r, C4/q, E4, F4', '_ Oh when the', 'C', 'G:13'],
16
+ ['G4/q, E4, C4, E4', 'saints go march- ing', 'C', 'C:maj9'],
17
+ ['D4/w', 'in', 'G:7', 'Am:11'],
18
+ ['D4/w', '', 'G:7', 'D:9'],
19
+ ['B4/q/r, E4/q, E4, D4', '_ Oh Lord I', 'G:7', 'G:13'],
20
+ ['C4/h, C4/q, E4', 'want to be', 'C', 'Gm:13'],
21
+ ['G4/h, G4/q, G4', 'in that num-', 'C:7', 'C:9'],
22
+ ['F4/w', 'ber', 'F', 'F:maj9'],
23
+ ['B4/q/r, C4/q, E4, F4', '_ Oh when the', 'F', 'Fm:maj7'],
24
+ ['G4/h, E4/q, C4', 'saints go march-', 'C', 'Em:7'],
25
+ ['D4/w', 'ing', 'G:7', 'Db:7b9'],
26
+ ['C4/w', 'in', 'C', 'C:6/9'],
27
+ ['C4/q', '', '', ''],
28
+ ];
29
+ function create(VF, score, choice) {
30
+ const measures = bars.map(([music], m) => ({
31
+ span: m === 0 ? '3/4' : m === 16 ? '1/4' : undefined,
32
+ voices: [
33
+ {
34
+ notes: music
35
+ .split(',')
36
+ .map((token, i) => token.trim() + '[id="v' + m + '-' + i + '"]')
37
+ .join(', '),
38
+ },
39
+ ],
40
+ }));
41
+ const heldBars = [6, 15];
42
+ const spans = heldBars.flatMap((m) => ['lyric', 'tie'].map((kind) => (Object.assign({ id: kind + m, kind, from: 'v' + m + '-0', to: 'v' + (m + 1) + '-0' }, (kind === 'lyric' ? { syllableId: 'held-in-' + m } : {})))));
43
+ return {
44
+ spec: { staves: [{ id: 'Voice', time: '4/4', measures }], continuous: { spans } },
45
+ decorate(composition) {
46
+ bars.forEach((bar, m) => {
47
+ const harmony = bar[choice === 'Traditional' ? 2 : 3];
48
+ if (harmony) {
49
+ const [root, extension] = harmony.split(':');
50
+ const symbol = score.make.chordSymbol().addGlyphOrText(root);
51
+ if (extension)
52
+ symbol.addGlyphOrText(extension, { symbolModifier: VF.ChordSymbol.symbolModifiers.SUPERSCRIPT });
53
+ composition.getNote('v' + m + '-0').addModifier(symbol);
54
+ }
55
+ const syllables = bar[1]
56
+ .split(' ')
57
+ .flatMap((text, i) => text && text !== '_' ? [{ text, note: composition.getNote('v' + m + '-' + i) }] : []);
58
+ if (syllables.length) {
59
+ const words = composition.systems[m].getPhraseLayout().addVerse(composition.staves[m][0], syllables, {
60
+ baselineSpaces: 7.5,
61
+ });
62
+ if (heldBars.includes(m))
63
+ words[0].setAttribute('id', 'held-in-' + m);
64
+ }
65
+ });
66
+ },
67
+ };
68
+ }
69
+ window.FeaturedScores.saints = { title, credit, intro, choices, control, focus, fonts, create };
70
+ })();
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ (() => {
3
+ const title = 'Sumer is icumen in';
4
+ const credit = 'Anonymous · English rota, 13th century';
5
+ const intro = 'Enter two bars after the previous singer. Read one line alone, then reveal the four overlapping entries and the two repeating bass parts, the pes.';
6
+ const choices = ['Singer 1', 'Full ensemble', 'Singer 2', 'Singer 3', 'Singer 4', 'Pes 1', 'Pes 2'];
7
+ const control = 'Vocal part';
8
+ const tune = [
9
+ ['F5/q, E5/8, D5/q, E5/8', 'Su- mer is i-'],
10
+ ['F5/q, F5/8, E5/8, D5, C5', 'cum- en in _ _'],
11
+ ['A4/q, A4/8, Bb4/q, G4/8', 'Lhu- de sing cuc-'],
12
+ ['A4/q., B4/q/r.', 'cu _'],
13
+ ['F4/q, A4/8, G4/q, Bb4/8', 'Grow- eth sed and'],
14
+ ['A4/q, A4/8, G4/q, F4/8', 'blow- eth med and'],
15
+ ['A4/q, C5/8, D5/q, D5/8', 'springth the wu- de'],
16
+ ['C5/q., B4/q/r.', 'nu _'],
17
+ ['F5/q., D5/q.', 'Sing cuc-'],
18
+ ['F5/q., B4/q/r.', 'cu _'],
19
+ ['C5/q, A4/8, Bb4/q, G4/8', 'A- we ble- teth'],
20
+ ['A4/q, C5/8, Bb4/q, A4/8', 'af- ter lomb _'],
21
+ ['F4/q, A4/8, G4/q, E4/8', 'Lhouth af- ter calve'],
22
+ ['F4/q., B4/q/r.', 'cu _'],
23
+ ['A4/q, A4/8, G4/q, Bb4/8', 'Bul- luc ster- teth'],
24
+ ['C5/q, C5/8, D5/q, E5/8', 'buck- e ver- teth'],
25
+ ['F5/q, E5/8, D5/q, E5/8', 'mu- rie sing cuc-'],
26
+ ['F5/q., B4/q/r.', 'cu _'],
27
+ ['C5/q., D5/q.', 'Cuc- cu'],
28
+ ['C5/q., Bb4/q, A4/8', 'cuc- cu _'],
29
+ ['F4/q, A4/8, Bb4/q, G4/8', 'Wel sing- es thu'],
30
+ ['A4/q., Bb4/q, C5/8', 'cuc- cu _'],
31
+ ['A4/q, C5/8, G4/q, E4/8', 'Ne swik thu na-ver'],
32
+ ['F4/q., B4/q/r.', 'nu _'],
33
+ ];
34
+ const bass = [
35
+ ['F3/q., G3/q.', 'Sing cuc-'],
36
+ ['F3/q., G3/q, A3/8', 'cu nu _'],
37
+ ['C4/q., Bb3/q.', 'Sing cuc-'],
38
+ ['C4/q., D3/q/r.', 'cu _'],
39
+ ];
40
+ const silence = ['B4/h/r.', '_'];
41
+ function create(VF, score, choice) {
42
+ const verses = [];
43
+ const staves = [];
44
+ const spans = [];
45
+ for (const [voice, name] of ['Singer 1', 'Singer 2', 'Singer 3', 'Singer 4', 'Pes 1', 'Pes 2'].entries()) {
46
+ if (choice !== 'Full ensemble' && choice !== name)
47
+ continue;
48
+ const id = 'part' + voice;
49
+ if (voice < 4) {
50
+ const anchor = (bar, note) => [id, voice * 2 + bar, note].join('-');
51
+ for (const [bar, first, last] of [
52
+ [1, 2, 4],
53
+ [11, 2, 3],
54
+ [19, 1, 2],
55
+ ]) {
56
+ spans.push({ id: id + '-melisma-' + bar, kind: 'slur', from: anchor(bar, first), to: anchor(bar, last) });
57
+ }
58
+ spans.push({ id: id + '-swell', kind: 'crescendo', side: 'above', from: anchor(4, 0), to: anchor(5, 3) });
59
+ }
60
+ const measures = Array.from({ length: tune.length + 6 }, (_, m) => {
61
+ var _a;
62
+ const [music, text] = voice < 4 ? ((_a = tune[m - voice * 2]) !== null && _a !== void 0 ? _a : silence) : bass[(m + (voice - 4) * 2) % 4];
63
+ const syllables = [];
64
+ const notes = music
65
+ .split(',')
66
+ .map((token, n) => {
67
+ const event = [id, m, n].join('-');
68
+ const syllable = text.split(' ')[n];
69
+ if (syllable && syllable !== '_')
70
+ syllables.push([event, syllable]);
71
+ return token.trim() + '[id="' + event + '"]';
72
+ })
73
+ .join(', ');
74
+ if (syllables.length)
75
+ verses.push({ m, staff: staves.length, syllables });
76
+ return { voices: [{ notes, autoBeam: true }] };
77
+ });
78
+ staves.push({
79
+ id,
80
+ name,
81
+ shortName: voice < 4 ? 'V' + (voice + 1) : name,
82
+ clef: voice < 4 ? 'treble' : 'bass',
83
+ key: 'F',
84
+ time: '6/8',
85
+ measures,
86
+ });
87
+ }
88
+ return {
89
+ spec: { staves, accidentals: 'key-aware', continuous: { measureNumbers: true, compressRests: true, spans } },
90
+ decorate(c) {
91
+ c.staves[0][0].setTempo({ name: 'With a lilt', duration: 'q', dots: 1, bpm: 76 }, -35);
92
+ for (const { id } of staves) {
93
+ const voice = Number(id.slice(4));
94
+ const note = (bar, i = 0) => c.getNote([id, bar + (voice < 4 ? 2 * voice : 0), i].join('-'));
95
+ const dynamic = (bar, text) => note(bar).addModifier(score.make
96
+ .annotation({
97
+ text: [...text].map((letter) => VF.TextDynamics.GLYPHS[letter]).join(''),
98
+ vJustify: 'top',
99
+ })
100
+ .setFont('Bravura', 24)
101
+ .setYShift(-6));
102
+ if (voice >= 4) {
103
+ dynamic(0, 'p');
104
+ for (let bar = 0; bar < 30; bar += 4)
105
+ note(bar).addModifier(score.make.articulation({ type: 'tenuto', position: 'above' }));
106
+ continue;
107
+ }
108
+ dynamic(0, 'mp');
109
+ dynamic(6, 'mf');
110
+ dynamic(18, 'p');
111
+ for (const bar of [2, 8, 16])
112
+ note(bar, bar === 8 ? 1 : 3).addModifier(score.make.articulation({ type: 'accent', position: 'above' }));
113
+ for (const bar of [3, 13])
114
+ note(bar).addModifier(score.make.ornament('mordent'));
115
+ note(23).addModifier(score.make.articulation({ type: 'a@a', position: 'above' }));
116
+ }
117
+ for (const { m, staff, syllables } of verses) {
118
+ const stave = c.staves[m][staff];
119
+ const words = c.systems[m].getPhraseLayout().addVerse(stave, syllables.map(([id, text]) => ({ note: c.getNote(id), text })), { baselineSpaces: 7.75 });
120
+ words.forEach((word) => word.setConnectorPadding(stave.space(0.2)));
121
+ }
122
+ },
123
+ };
124
+ }
125
+ window.FeaturedScores.sumer = { title, credit, intro, choices, control, create };
126
+ })();
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ (() => {
12
+ const el = (id) => document.getElementById(id);
13
+ const pieces = ['saints', 'electric', 'kesh', 'falseta', 'sumer', 'prelude', 'drums', 'quartertones'];
14
+ let selected, navigation, edition, composition, score, spec, renderedWidth;
15
+ function highlight() {
16
+ const region = navigation.regions.find((r) => r.kind === 'event' && r.id === selected);
17
+ const box = el('highlight');
18
+ box.hidden = !region;
19
+ if (region) {
20
+ const svg = el('score').querySelector('svg');
21
+ const matrix = svg.getScreenCTM();
22
+ const point = new DOMPoint(region.x, region.y).matrixTransform(matrix);
23
+ const frame = el('frame').getBoundingClientRect();
24
+ Object.assign(box.style, {
25
+ left: point.x - frame.left - 2 + 'px',
26
+ top: point.y - frame.top - 2 + 'px',
27
+ width: region.w * matrix.a + 4 + 'px',
28
+ height: region.h * matrix.d + 4 + 'px',
29
+ });
30
+ }
31
+ }
32
+ function reflow() {
33
+ var _a;
34
+ if (!composition)
35
+ return;
36
+ const width = Math.min(el('page').clientWidth, el('width').value === 'Narrow' ? 390 : 1100);
37
+ if (width === renderedWidth)
38
+ return;
39
+ renderedWidth = width;
40
+ const sheet = composition.sheet;
41
+ sheet.setWidth(Math.max(210, width - 34)).format();
42
+ const ctx = score.factory.getContext();
43
+ const height = Math.ceil(sheet.getHeight() + 90);
44
+ ctx.resize(width, height);
45
+ ctx.clear();
46
+ score.draw({ retain: true });
47
+ const svg = el('score').querySelector('svg');
48
+ const ink = svg.getBBox();
49
+ const x = Math.min(0, ink.x - 8), y = Math.min(0, ink.y - 8);
50
+ const w = Math.max(width, ink.x + ink.width + 8) - x, h = ink.y + ink.height + 12 - y;
51
+ svg.setAttribute('viewBox', [x, y, w, h].join(' '));
52
+ svg.style.width = '100%';
53
+ svg.style.height = (width * h) / w + 'px';
54
+ el('score').style.width = '100%';
55
+ el('frame').style.width = width + 'px';
56
+ navigation = new VexFlow.ScoreNavigation(composition, spec.staves);
57
+ const events = navigation.events;
58
+ selected = events.some((e) => e.id === selected) ? selected : (_a = events[0]) === null || _a === void 0 ? void 0 : _a.id;
59
+ el('events').replaceChildren(...events.map((e) => new Option(e.label, e.id)));
60
+ el('events').value = selected;
61
+ highlight();
62
+ }
63
+ function render() {
64
+ var _a, _b;
65
+ const choice = el('edition').value;
66
+ el('score').replaceChildren();
67
+ if (edition.publication) {
68
+ const { spec, options } = edition.publication(choice, VexFlow);
69
+ new VexFlow.Publication(spec).render(el('score'), options);
70
+ el('frame').className = 'publication';
71
+ return;
72
+ }
73
+ score = VexFlow.EasyScore.create({ renderer: { elementId: 'score', width: 700, height: 300 } });
74
+ const music = edition.create(VexFlow, score, choice);
75
+ spec = music.spec;
76
+ spec.sheet = { width: 700, x: 16, y: 42, rowGap: 26, measurePadding: 18 };
77
+ composition = score.compose(spec);
78
+ (_a = music.decorate) === null || _a === void 0 ? void 0 : _a.call(music, composition);
79
+ el('legend').textContent = (_b = music.legend) !== null && _b !== void 0 ? _b : '';
80
+ el('legend').hidden = !music.legend;
81
+ renderedWidth = undefined;
82
+ reflow();
83
+ }
84
+ function loadScript(name) {
85
+ return new Promise((resolve, reject) => {
86
+ const script = document.createElement('script');
87
+ script.src = './' + name + '.js';
88
+ script.onload = resolve;
89
+ script.onerror = () => reject(Error('Unable to load ' + name + '.js'));
90
+ document.head.append(script);
91
+ });
92
+ }
93
+ function open() {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ var _a, _b;
96
+ const id = new URLSearchParams(location.search).get('piece');
97
+ if (!pieces.includes(id))
98
+ throw Error('Choose a score from the gallery.');
99
+ window.FeaturedScores = {};
100
+ if (id === 'electric' || id === 'falseta')
101
+ yield loadScript('guitar');
102
+ yield loadScript(id);
103
+ edition = window.FeaturedScores[id];
104
+ document.title = edition.title + ' · VexFlow';
105
+ for (const key of ['title', 'credit', 'intro'])
106
+ el(key).textContent = edition[key];
107
+ el('source').href = './' + id + '.js';
108
+ el('source').hidden = false;
109
+ const fonts = (_a = edition.fonts) !== null && _a !== void 0 ? _a : ['Bravura', 'Academico'];
110
+ VexFlow.setFonts(...fonts);
111
+ yield Promise.all(fonts.map((name) => document.fonts.load('16px "' + name + '"')));
112
+ if (edition.choices) {
113
+ el('edition-label').hidden = false;
114
+ el('edition-label').firstElementChild.textContent = edition.control + ' ';
115
+ el('edition').replaceChildren(...edition.choices.map((c) => new Option(c, c)));
116
+ }
117
+ selected = edition.focus;
118
+ render();
119
+ el('edition').onchange = render;
120
+ el('width').onchange = reflow;
121
+ el('print').hidden = !edition.publication;
122
+ el('print').onclick = () => window.print();
123
+ el('width-label').hidden = !!edition.publication;
124
+ el('reading').hidden = !!edition.publication;
125
+ el('events').onchange = () => {
126
+ selected = el('events').value;
127
+ highlight();
128
+ if (!el('highlight').hidden)
129
+ el('highlight').scrollIntoView({ block: 'nearest' });
130
+ };
131
+ if (edition.focus) {
132
+ el('action').hidden = false;
133
+ el('action').textContent = (_b = edition.action) !== null && _b !== void 0 ? _b : 'Follow the held “in”';
134
+ el('action').onclick = () => {
135
+ selected = edition.focus;
136
+ el('events').value = selected;
137
+ highlight();
138
+ el('highlight').scrollIntoView({ block: 'center' });
139
+ };
140
+ }
141
+ el('frame').onclick = (e) => {
142
+ if (!navigation)
143
+ return;
144
+ const matrix = el('score').querySelector('svg').getScreenCTM();
145
+ const point = new DOMPoint(e.clientX, e.clientY).matrixTransform(matrix.inverse());
146
+ const hit = navigation.hitTest(point.x, point.y);
147
+ if ((hit === null || hit === void 0 ? void 0 : hit.kind) === 'event') {
148
+ selected = hit.id;
149
+ el('events').value = selected;
150
+ highlight();
151
+ }
152
+ };
153
+ el('tools').hidden = false;
154
+ el('status').textContent = '';
155
+ new ResizeObserver(reflow).observe(el('page'));
156
+ });
157
+ }
158
+ open().catch((error) => {
159
+ el('status').textContent = error.message;
160
+ console.error(error);
161
+ });
162
+ })();
@@ -3,6 +3,7 @@ import { VexFlowTests } from './vexflow_test_helpers.js';
3
3
  import { Dot } from '../src/dot.js';
4
4
  import { Formatter } from '../src/formatter.js';
5
5
  import { Metrics } from '../src/metrics.js';
6
+ import { ModifierPosition } from '../src/modifier.js';
6
7
  import { Stave } from '../src/stave.js';
7
8
  import { TabNote } from '../src/tabnote.js';
8
9
  import { TabStave } from '../src/tabstave.js';
@@ -15,6 +16,7 @@ const TabNoteTests = {
15
16
  QUnit.test('TabStave Line', tabStaveLine);
16
17
  QUnit.test('Width', width);
17
18
  const run = VexFlowTests.runTests;
19
+ run('Fret size and string clearance', fretClearance, undefined, ['Bravura']);
18
20
  run('TabNote Draw', draw);
19
21
  run('TabNote Stems Up', drawStemsUp);
20
22
  run('TabNote Stems Down', drawStemsDown);
@@ -61,6 +63,47 @@ function width(assert) {
61
63
  });
62
64
  assert.throws(() => note.getWidth(), /UnformattedNote/, 'Unformatted note should have no width');
63
65
  }
66
+ function fretClearance({ assert, elementId }, contextBuilder) {
67
+ const ctx = contextBuilder(elementId, 280, 140);
68
+ const stave = new TabStave(10, 10, 260).addTabGlyph().setContext(ctx).drawWithStyle();
69
+ const positions = [0, 12, 10, 15, 13, 11].map((fret, i) => ({ str: i + 1, fret }));
70
+ class TestChord extends TabNote {
71
+ get frets() {
72
+ return this.fretElement;
73
+ }
74
+ }
75
+ const chord = new TestChord({ duration: 'q', positions });
76
+ const small = new TestChord({ duration: 'q', positions }).setFontSize(9);
77
+ const gaps = [];
78
+ const clearRect = ctx.clearRect.bind(ctx);
79
+ ctx.clearRect = (x, y, w, h) => {
80
+ gaps.push({ left: x, right: x + w, centerY: y + h / 2 });
81
+ return clearRect(x, y, w, h);
82
+ };
83
+ Formatter.FormatAndDraw(ctx, stave, [chord, small]);
84
+ assert.equal(gaps.length, positions.length * 2, 'Each fret clears its own string');
85
+ assert.ok(chord.getWidth() > small.getWidth(), 'Formatting reserves the measured fret width');
86
+ for (const [index, note] of [chord, small].entries()) {
87
+ let previousBottom = -Infinity;
88
+ const leftAnchor = note.getModifierStartXY(ModifierPosition.LEFT, 0).x;
89
+ const rightAnchor = note.getModifierStartXY(ModifierPosition.RIGHT, 0).x;
90
+ assert.equal(note.getModifierStartXY(ModifierPosition.ABOVE, 0).x, note.getStemX());
91
+ for (const [i, fret] of note.frets.entries()) {
92
+ const ink = fret.getTextMetrics();
93
+ const { left, right, centerY } = gaps[index * positions.length + i];
94
+ assert.ok(leftAnchor <= left + 0.01 && rightAnchor >= right - 0.01, 'Side markings clear every string gap');
95
+ const x = note.getAbsoluteX() - fret.getWidth() / 2;
96
+ const baseline = note.getYs()[i] + fret.getYShift();
97
+ const top = baseline - ink.actualBoundingBoxAscent;
98
+ const bottom = baseline + ink.actualBoundingBoxDescent;
99
+ assert.equal(fret.fontSizeInPoints, index === 0 ? 11 : 9);
100
+ assert.ok(Math.abs((bottom + top) / 2 - centerY) < 0.01, 'Ink centers on the cleared string');
101
+ assert.ok(x - ink.actualBoundingBoxLeft >= left + 1 && x + ink.actualBoundingBoxRight <= right - 1);
102
+ assert.ok(top >= previousBottom + 2, 'Adjacent strings have at least two pixels of clear space');
103
+ previousBottom = bottom;
104
+ }
105
+ }
106
+ }
64
107
  function draw(options, contextBuilder) {
65
108
  const ctx = contextBuilder(options.elementId, 600, 140);
66
109
  ctx.font = '10pt Arial';
@@ -280,6 +280,7 @@ VexFlowTests.FONT_STACKS = {
280
280
  Leipzig: ['Leipzig', 'Academico'],
281
281
  MuseJazz: ['MuseJazz', 'MuseJazz Text'],
282
282
  Petaluma: ['Petaluma', 'Petaluma Script'],
283
+ 'Petaluma with Academico': ['Petaluma', 'Academico'],
283
284
  Sebastian: ['Sebastian', 'Nepomuk'],
284
285
  };
285
286
  VexFlowTests.NEXT_TEST_ID = 0;
@@ -1,10 +1,19 @@
1
1
  import { example as e, number, select, setup, staff, text } from './helpers.mjs';
2
2
  const group = 'Marks & expression';
3
3
  export const expression = [
4
- e('annotations', 'Lyrics & annotations', group, 'Align lyrics below notes or annotations above them.', 'Annotation', staff("score.notes('C5/q, E5, G5, C6')", `// Pair each word with the note at the same position in the melody.
5
- params.words.split(' ').slice(0, notes.length).forEach((word, i) => {
6
- notes[i].addModifier(factory.Annotation({ text: word, vJustify: params.position }), 0);
7
- });`), [text('words', 'Words', 'One two three four'), select('position', 'Position', 'bottom', ['bottom', 'top'])]),
4
+ e('annotations', 'Lyrics & annotations', group, 'Align lyrics below notes or annotations above them.', 'Annotation', `${setup}
5
+
6
+ const notes = score.notes('C5/q, E5, G5, C6');
7
+ const system = factory.System({ x: 30, y: 65, width: width - 60 });
8
+ const stave = system.addStave({ voices: [score.voice(notes)] }).addClef('treble');
9
+
10
+ // Give each sung word a note. The verse shares a baseline and uses the score's lyric size.
11
+ const words = params.words.trim().split(/\\s+/).filter(Boolean).slice(0, notes.length);
12
+ if (words.length) {
13
+ const verse = words.map((text, i) => ({ text, note: notes[i] }));
14
+ system.getPhraseLayout().addVerse(stave, verse, { side: params.position === 'top' ? 'above' : 'below' });
15
+ }
16
+ factory.draw();`, [text('words', 'Words', 'One two three four'), select('position', 'Position', 'bottom', ['bottom', 'top'])]),
8
17
  e('chord-symbols', 'Chord symbols', group, 'Build harmonic labels from text, accidentals, and superscripts.', 'ChordSymbol', staff("score.notes('C5/h, G4')", `// Build the label in reading order. Raise the flat ninth on the second symbol.
9
18
  notes[0].addModifier(factory.ChordSymbol().addText(params.root).addGlyphOrText('maj7'), 0);
10
19
  notes[1].addModifier(factory.ChordSymbol().addText('G').addGlyphOrText('7').addGlyphOrText('b9', { symbolModifier: VF.ChordSymbol.symbolModifiers.SUPERSCRIPT }), 0);`), [text('root', 'Root', 'C')]),
@@ -31,7 +40,8 @@ const sub = { symbolModifier: VF.ChordSymbol.symbolModifiers.SUBSCRIPT };
31
40
  .addStave({ voices: [voice] }).addClef('treble');
32
41
  });
33
42
  factory.draw();
34
- ctx.setFont('sans-serif', 10);
43
+ // Match the captions to the score’s selected text face.
44
+ ctx.setFont(VF.getTextFonts().join(','), 10);
35
45
  ctx.fillText('Default: none', 30, 22);
36
46
  ctx.fillText('Opt-in: auto', 30, 172);
37
47
  // Inspect the complete chord's ink bounds, including both script rows.
@@ -44,7 +54,7 @@ if (params.bounds === 'yes') {
44
54
  ctx.restore();
45
55
  }`, [
46
56
  text('root', 'Root', 'A'),
47
- number('size', 'Font size (pt)', 18, 10, 28),
57
+ number('size', 'Font size (pt)', 14, 10, 28),
48
58
  select('bounds', 'Chord bounds', 'no', ['no', 'yes']),
49
59
  ], 'Auto supports regular Academico/Bravura and Petaluma Script/Petaluma. Other font combinations keep the default layout. Set the chord font before formatting.'),
50
60
  e('dynamics', 'Dynamics', group, 'From pianissimo to fortissimo, draw music-font dynamic marks.', 'TextDynamics', `${setup}
@@ -36,8 +36,8 @@ const fan = guitar.rasgueado(
36
36
  roll: i === 6,
37
37
  }))
38
38
  );
39
- // Fit the entire one-bar fan, even on a phone.
40
- const logicalWidth = Math.max(width, 480);
39
+ // Give the arrows, 11 pt finger labels, and chord grips room before scaling this single bar to a phone.
40
+ const logicalWidth = Math.max(width, 520);
41
41
  const spec = {
42
42
  sheet: { width: logicalWidth - 32, x: 16, y: 35 },
43
43
  continuous: {},
@@ -74,6 +74,8 @@ export declare class ContinuousLayout {
74
74
  private readonly splitChords;
75
75
  private readonly spelledSpans;
76
76
  private readonly options;
77
+ /** A leading tab fret needs room for the incoming tie after the repeated clef. */
78
+ private readonly tabTiePadding;
77
79
  private readonly arrivals;
78
80
  constructor(score: EasyScoreComposition, spec: EasyScoreCompositionSpec, starts: State[][], ends: State[][], placed?: Set<Accidental>);
79
81
  /** Only undecorated, wholly resting measures can disappear into a numbered rest. */
@@ -94,6 +96,8 @@ export declare class ContinuousLayout {
94
96
  private alignStaves;
95
97
  /** Reconcile staff envelopes across all measures in a row, then translate the entire solved row once. */
96
98
  private layoutRow;
99
+ /** Carry the source syllable's distance from its top staff line to each continuation. */
100
+ private lyricBaseline;
97
101
  /** Keep continuation hooks and labels on the correct end when a span crosses a row. */
98
102
  private addFragment;
99
103
  /** Add labels, connectors and numbered rests after all native positions have settled. */
@@ -1,3 +1,4 @@
1
+ import type { Annotation } from './annotation';
1
2
  import { Bounds } from './boundingbox';
2
3
  import { Element } from './element';
3
4
  import { Note } from './note';
@@ -6,17 +7,23 @@ import { Stave } from './stave';
6
7
  export type ContinuousSpanKind = 'tie' | 'slur' | 'crescendo' | 'diminuendo' | 'pedal' | 'lyric' | 'hyphen' | 'volta' | 'ottava' | 'trill' | 'tuplet' | 'palmMute';
7
8
  export interface ContinuousSpan {
8
9
  kind: ContinuousSpanKind;
10
+ /** One-based string of a tab tie. Defaults to the string of the selected chord position. */
11
+ string?: number;
9
12
  /** Required for palmMute. String numbers are one-based. */
10
13
  strings?: readonly number[];
11
14
  id: string;
12
15
  from: string;
13
16
  to: string;
14
- /** Optional chord-head indices for each end of a tie or slur. */
17
+ /** Optional zero-based chord-head indices. On a tab tie these index the positions arrays. */
15
18
  fromHead?: number;
16
19
  toHead?: number;
17
20
  side?: 'above' | 'below';
18
21
  /** Syllable, ending number, tuplet ratio or octave label, according to kind. */
19
22
  text?: string;
23
+ /** Optional type size for this label, in points. Measured before system breaks are chosen. */
24
+ labelFontSize?: number;
25
+ /** For a lyric extender, take the baseline and ink edge from this Annotation on the source note. */
26
+ syllableId?: string;
20
27
  }
21
28
  export interface SpanAnchor {
22
29
  measure: number;
@@ -28,6 +35,7 @@ export interface ResolvedSpan {
28
35
  first: SpanAnchor;
29
36
  last: SpanAnchor;
30
37
  label?: Element;
38
+ syllable?: Annotation;
31
39
  }
32
40
  export interface SpanFragment {
33
41
  id: string;
@@ -40,7 +48,7 @@ export interface SpanFragment {
40
48
  y2: number;
41
49
  /** Fraction of the drawn span used to interpolate the aperture across a system break. */
42
50
  progress: [number, number];
43
- /** String numbers covered by a palm-mute fragment. */
51
+ /** String numbers covered by a tab tie or palm-mute fragment. */
44
52
  strings?: readonly number[];
45
53
  /** Authored TAB endpoints appear on the fragments containing them. */
46
54
  from?: string;