vexflow 5.2.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) 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 +2759 -1382
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +1814 -1227
  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/accidental.js +10 -3
  12. package/build/esm/src/articulation.js +24 -6
  13. package/build/esm/src/beam.js +158 -28
  14. package/build/esm/src/bend.js +24 -19
  15. package/build/esm/src/curve.js +27 -53
  16. package/build/esm/src/dot.js +13 -4
  17. package/build/esm/src/easyscore/composition.js +40 -1
  18. package/build/esm/src/easyscore/policies.js +34 -6
  19. package/build/esm/src/element.js +4 -0
  20. package/build/esm/src/engravinggeometry.js +150 -0
  21. package/build/esm/src/engravingprofile.js +44 -0
  22. package/build/esm/src/factory.js +15 -7
  23. package/build/esm/src/formatter.js +9 -1
  24. package/build/esm/src/gracenote.js +43 -38
  25. package/build/esm/src/gracenotegroup.js +53 -56
  26. package/build/esm/src/index.js +2 -0
  27. package/build/esm/src/keysignature.js +1 -1
  28. package/build/esm/src/modifiercontext.js +11 -0
  29. package/build/esm/src/notehead.js +11 -6
  30. package/build/esm/src/ornament.js +38 -18
  31. package/build/esm/src/proportionalformatter.js +54 -6
  32. package/build/esm/src/stavenote.js +128 -115
  33. package/build/esm/src/stavetie.js +39 -7
  34. package/build/esm/src/stem.js +26 -11
  35. package/build/esm/src/tickcontext.js +19 -0
  36. package/build/esm/src/timesignature.js +5 -0
  37. package/build/esm/src/tuplet.js +57 -17
  38. package/build/esm/src/version.js +3 -3
  39. package/build/esm/src/vexflow.js +4 -0
  40. package/build/esm/tests/bend_tests.js +14 -1
  41. package/build/esm/tests/curve_tests.js +14 -4
  42. package/build/esm/tests/demo_repertoire_tests.js +27 -0
  43. package/build/esm/tests/demos/drums.js +54 -0
  44. package/build/esm/tests/demos/electric.js +63 -0
  45. package/build/esm/tests/demos/greensleeves.js +90 -0
  46. package/build/esm/tests/demos/joy.js +61 -0
  47. package/build/esm/tests/demos/kesh.js +80 -0
  48. package/build/esm/tests/demos/prelude.js +59 -0
  49. package/build/esm/tests/demos/quartertones.js +50 -0
  50. package/build/esm/tests/demos/saints.js +65 -0
  51. package/build/esm/tests/engraving/score-layout.mjs +75 -0
  52. package/build/esm/tests/engraving/score-persistence.mjs +262 -0
  53. package/build/esm/tests/engraving/studies.mjs +279 -0
  54. package/build/esm/tests/formatter_tests.js +10 -1
  55. package/build/esm/tests/index.js +1 -0
  56. package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
  57. package/build/esm/tests/node/easyscore-tests.mjs +71 -0
  58. package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
  59. package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
  60. package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
  61. package/build/esm/tests/node/rendering-tests.mjs +6 -2
  62. package/build/esm/tests/threevoice_tests.js +11 -1
  63. package/build/esm/tests/vexflow_test_helpers.js +19 -10
  64. package/build/esm/tools/audit-dependencies.mjs +61 -0
  65. package/build/esm/tools/score-fixtures.mjs +23 -6
  66. package/build/types/src/accidental.d.ts +4 -0
  67. package/build/types/src/articulation.d.ts +6 -1
  68. package/build/types/src/beam.d.ts +14 -0
  69. package/build/types/src/curve.d.ts +9 -0
  70. package/build/types/src/dot.d.ts +5 -0
  71. package/build/types/src/easyscore/composition.d.ts +19 -0
  72. package/build/types/src/easyscore/policies.d.ts +1 -1
  73. package/build/types/src/element.d.ts +2 -0
  74. package/build/types/src/engravinggeometry.d.ts +31 -0
  75. package/build/types/src/engravingprofile.d.ts +20 -0
  76. package/build/types/src/factory.d.ts +6 -1
  77. package/build/types/src/formatter.d.ts +3 -3
  78. package/build/types/src/gracenote.d.ts +7 -0
  79. package/build/types/src/gracenotegroup.d.ts +7 -2
  80. package/build/types/src/index.d.ts +2 -0
  81. package/build/types/src/modifiercontext.d.ts +4 -0
  82. package/build/types/src/notehead.d.ts +5 -0
  83. package/build/types/src/ornament.d.ts +7 -0
  84. package/build/types/src/proportionalformatter.d.ts +11 -2
  85. package/build/types/src/stavenote.d.ts +20 -2
  86. package/build/types/src/stavetie.d.ts +4 -0
  87. package/build/types/src/stem.d.ts +10 -1
  88. package/build/types/src/tickcontext.d.ts +5 -0
  89. package/build/types/src/timesignature.d.ts +2 -0
  90. package/build/types/src/tuplet.d.ts +5 -48
  91. package/build/types/src/vexflow.d.ts +4 -0
  92. package/changelog/CHANGELOG.md +17 -0
  93. package/package.json +7 -2
  94. package/tests/all.html +277 -0
  95. package/tests/demo_petzold_tests.ts +435 -0
  96. package/tests/demos/drums.ts +55 -0
  97. package/tests/demos/drums.webp +0 -0
  98. package/tests/demos/electric.ts +70 -0
  99. package/tests/demos/electric.webp +0 -0
  100. package/tests/demos/greensleeves.ts +97 -0
  101. package/tests/demos/greensleeves.webp +0 -0
  102. package/tests/demos/joy.ts +65 -0
  103. package/tests/demos/joy.webp +0 -0
  104. package/tests/demos/kesh.ts +86 -0
  105. package/tests/demos/kesh.webp +0 -0
  106. package/tests/demos/prelude.ts +65 -0
  107. package/tests/demos/prelude.webp +0 -0
  108. package/tests/demos/quartertones.ts +51 -0
  109. package/tests/demos/quartertones.webp +0 -0
  110. package/tests/demos/saints.ts +70 -0
  111. package/tests/demos/saints.webp +0 -0
  112. package/tests/flow.html +550 -239
  113. package/tests/fonts.css +493 -0
  114. package/tests/minuet.webp +0 -0
@@ -0,0 +1,90 @@
1
+ import { VexFlowTests } from '../vexflow_test_helpers.js';
2
+ import { BarlineType, Stroke } from '../../src/index.js';
3
+ const positions = {
4
+ E3: [6, 0],
5
+ F3: [6, 1],
6
+ G3: [6, 3],
7
+ A3: [5, 0],
8
+ B3: [5, 2],
9
+ C4: [5, 3],
10
+ D4: [4, 0],
11
+ E4: [4, 2],
12
+ F4: [4, 3],
13
+ G4: [3, 0],
14
+ 'G#4': [3, 1],
15
+ A4: [3, 2],
16
+ B4: [2, 0],
17
+ C5: [2, 1],
18
+ D5: [2, 3],
19
+ E5: [1, 0],
20
+ F5: [1, 1],
21
+ };
22
+ export function greensleeves(options) {
23
+ const f = VexFlowTests.makeFactory(options, 900, 486);
24
+ const score = f.EasyScore({ throwOnError: true });
25
+ const chordFont = { fontFamily: 'Arial, Helvetica, sans-serif', fontSize: 12 };
26
+ const bars = [
27
+ ['', 'A4/q'],
28
+ ['Am', 'A3+E4+A4+C5/h D5/q'],
29
+ ['C', 'C4+G4+C5+E5/q. F5/8 E5/q'],
30
+ ['G', 'G3+D4+G4+D5/h B4/q'],
31
+ ['Em', 'E3+B3+G4/q. A4/8 B4/q'],
32
+ ['Am', 'A3+E4+A4+C5/h A4/q'],
33
+ ['Dm/F', 'F3+D4+A4/q. G#4/8 A4/q'],
34
+ ['E', 'E3+E4+B4/h G#4/q'],
35
+ ['E5', 'E3+B3+E4/h'],
36
+ ];
37
+ bars.forEach(([chordName, bar], i) => {
38
+ const row = i >= 5 ? 1 : 0;
39
+ const width = row ? 218 : i === 0 ? 112 : 190;
40
+ const x = row ? 12 + (i - 5) * width : i === 0 ? 12 : 124 + (i - 1) * width;
41
+ const y = 28 + row * 230;
42
+ const events = bar.split(' ').map((token) => {
43
+ const [chord, duration] = token.split('/');
44
+ return { pitches: chord.split('+'), duration };
45
+ });
46
+ const music = events.map(({ pitches, duration }) => {
47
+ const chord = pitches.length === 1 ? pitches[0] : `(${pitches.join(' ')})`;
48
+ return `${chord}/${duration}`;
49
+ });
50
+ const notes = score.notes(music.join(', '));
51
+ if (chordName)
52
+ notes[0].addModifier(score.make.chordSymbol(chordFont).addText(chordName));
53
+ const tab = events.map(({ pitches, duration }) => score.make.tabNote({
54
+ positions: pitches.map((pitch) => {
55
+ const [str, fret] = positions[pitch];
56
+ return { str, fret };
57
+ }),
58
+ duration: duration.replace('.', ''),
59
+ dots: duration.includes('.') ? 1 : 0,
60
+ }));
61
+ if (i === 1 || i === 5) {
62
+ notes[0].addModifier(score.make.fingering({ number: '1', position: 'left' }), 3);
63
+ notes[0].addModifier(score.make.fingering({ number: '2', position: 'left' }), 1);
64
+ }
65
+ if (i === 2 || i === 8)
66
+ notes[0].addModifier(score.make.stroke(Stroke.Type.ARPEGGIO_DIRECTIONLESS));
67
+ if (i === 2 || i === 6)
68
+ score.make.curve({ from: notes[1], to: notes[2] });
69
+ const time = i === 0 ? '1/4' : i === bars.length - 1 ? '2/4' : '3/4';
70
+ const system = f.System({ x, y, width, spaceBetweenStaves: 8 });
71
+ const stave = system.addStave({ voices: [score.voice(notes, { time })], options: { topTextPosition: 3.5 } });
72
+ const tablature = system.addStave({
73
+ stave: score.make.tabStave({ x, y, width }),
74
+ voices: [score.voice(tab, { time })],
75
+ });
76
+ if (i === 0 || i === 5) {
77
+ stave.addClef('treble', 'default', '8vb');
78
+ if (i === 0)
79
+ stave.addTimeSignature('3/4');
80
+ tablature.addClef('tab');
81
+ system.addConnector('bracket');
82
+ }
83
+ if (i === bars.length - 1) {
84
+ stave.setEndBarType(BarlineType.END);
85
+ tablature.setEndBarType(BarlineType.END);
86
+ }
87
+ });
88
+ f.draw();
89
+ options.assert.ok(true, 'Chord melody and tab share the same rhythmic grid');
90
+ }
@@ -0,0 +1,61 @@
1
+ import { VexFlowTests } from '../vexflow_test_helpers.js';
2
+ import { BarlineType, StaveHairpin } from '../../src/index.js';
3
+ export function joy(options) {
4
+ const f = VexFlowTests.makeFactory(options, 900, 435);
5
+ const score = f.EasyScore({ throwOnError: true });
6
+ score.set({ clef: 'bass', time: '4/4' });
7
+ const duet = [
8
+ ['F3/q, F3, G3, A3', 'D3/h, A2'],
9
+ ['A3/q, G3, F3, E3', 'F2/h, A2'],
10
+ ['D3/q, D3, E3, F3', 'B2/h, G2'],
11
+ ['F3/q., E3/8, E3/h', 'A2/w'],
12
+ ['F3/q, F3, G3, A3', 'D3/h, A2'],
13
+ ['A3/q, G3, F3, E3', 'F2/h, A2'],
14
+ ['D3/q, D3, E3, F3', 'G2/h, A2'],
15
+ ['E3/q., D3/8, D3/h', 'A2/h, D2'],
16
+ ];
17
+ duet.forEach(([tune, bass], i) => {
18
+ const notes = score.notes(tune);
19
+ const system = f.System({
20
+ x: 24 + (i % 4) * 213,
21
+ y: 10 + Math.floor(i / 4) * 210,
22
+ width: 213,
23
+ spaceBetweenStaves: 10,
24
+ });
25
+ const voices = [score.voice(notes)];
26
+ if (i % 2 === 0) {
27
+ const dynamic = ['p', 'mf', 'mp', 'f'][i / 2];
28
+ voices.push(score.voice([score.make.textDynamics({ text: dynamic, duration: 'w', line: 10 })]));
29
+ }
30
+ const first = system.addStave({ voices });
31
+ const second = system.addStave({ voices: [score.voice(score.notes(bass))] });
32
+ if (i % 4 === 0) {
33
+ first.addClef('bass').addKeySignature('D');
34
+ second.addClef('bass').addKeySignature('D');
35
+ if (i === 0) {
36
+ first.addTimeSignature('4/4');
37
+ second.addTimeSignature('4/4');
38
+ }
39
+ system.addConnector('bracket');
40
+ }
41
+ if (i === 1 || i === 5) {
42
+ score.make.hairpin({
43
+ from: notes[0],
44
+ to: notes[3],
45
+ type: StaveHairpin.type.CRESC,
46
+ options: { height: 8, yShift: -21 },
47
+ });
48
+ }
49
+ if (i === 0 || i === 4)
50
+ notes[0].addModifier(score.make.articulation({ type: 'tenuto', position: 'above' }));
51
+ if (i === 3 || i === 7)
52
+ score.make.curve({ from: notes[0], to: notes[1] });
53
+ if (i === 7) {
54
+ first.setEndBarType(BarlineType.END);
55
+ second.setEndBarType(BarlineType.END);
56
+ }
57
+ system.addConnector('singleRight');
58
+ });
59
+ f.draw();
60
+ options.assert.ok(true, 'Two cello parts aligned through the cadence');
61
+ }
@@ -0,0 +1,80 @@
1
+ import { VexFlowTests } from '../vexflow_test_helpers.js';
2
+ import { BarlineType, VoltaType } from '../../src/index.js';
3
+ export function kesh(options) {
4
+ const f = VexFlowTests.makeFactory(options, 900, 580);
5
+ const score = f.EasyScore({ throwOnError: true });
6
+ score.set({ time: '6/8' });
7
+ const chordFont = { fontFamily: 'Arial, Helvetica, sans-serif', fontSize: 12 };
8
+ const strains = [
9
+ [
10
+ ['G4/q, G4/8', 'G4/8, A4, B4', 'G'],
11
+ ['A4/q, A4/8', 'A4/8, B4, D5', 'D'],
12
+ ['E5/8, D5, D5', 'G5/8, D5, D5', 'G'],
13
+ ['E5/8, D5, B4', 'D5/8, B4, A4', '', 'D'],
14
+ ['G4/q, G4/8', 'G4/8, A4, B4', 'G'],
15
+ ['A4/q, A4/8', 'A4/8, B4, D5', 'D'],
16
+ ['E5/8, D5, D5', 'G5/8, D5, B4', 'G'],
17
+ ['A4/8, G4, F4', 'G4/q, D4/8', 'D', 'G'],
18
+ ['A4/8, G4, F4', 'G4/q, A4/8', 'D', 'G'],
19
+ ],
20
+ [
21
+ ['B4/q, B4/8', 'D5/8, B4, D5', 'G'],
22
+ ['E5/8, G5, E5', 'D5/8, B4, G4', 'C', 'G'],
23
+ ['B4/q, B4/8', 'D5/8, B4, G4', ''],
24
+ ['A4/8, B4, A4', 'A4/8, G4, A4', 'Am'],
25
+ ['B4/8, A4, B4', 'D5/8, B4, D5', 'G'],
26
+ ['E5/8, G5, E5', 'D5/8, B4, D5', 'C', 'G'],
27
+ ['E5/q.', 'A5/8, G5, A5', 'C', 'D'],
28
+ ['B5/8, G5, G5', 'G5/q, A4/8', 'G'],
29
+ ['B5/8, G5, G5', 'G5/q', 'G'],
30
+ ],
31
+ ];
32
+ const pickupWidth = 130;
33
+ const firstY = 36;
34
+ f.System({ x: 16, y: firstY, width: pickupWidth })
35
+ .addStave({ voices: [score.voice(score.notes('D4/8'), { time: '1/8' })] })
36
+ .addClef('treble')
37
+ .addKeySignature('G')
38
+ .addTimeSignature('6/8');
39
+ strains.forEach((bars, part) => bars.forEach(([firstBeat, secondBeat, chord, nextChord], i) => {
40
+ const beats = [score.notes(firstBeat), score.notes(secondBeat)];
41
+ const notes = beats.flat();
42
+ for (const beat of beats) {
43
+ if (beat.length === 3)
44
+ score.beam(beat);
45
+ }
46
+ if (chord)
47
+ beats[0][0].addModifier(score.make.chordSymbol(chordFont).addText(chord));
48
+ if (nextChord)
49
+ beats[1][0].addModifier(score.make.chordSymbol(chordFont).addText(nextChord));
50
+ if (i === 0 || i === 4) {
51
+ const grace = score.make.graceNote({ keys: [part ? 'd/5' : 'b/4'], duration: '8', slash: true });
52
+ notes[1].addModifier(score.make.graceNoteGroup({ notes: [grace], slur: true }));
53
+ }
54
+ if (i === 2 || i === 6) {
55
+ const bow = beats[0].length === 3 ? beats[0] : beats[1];
56
+ score.make.curve({ from: bow[0], to: bow[2] });
57
+ }
58
+ const firstLine = i < 4;
59
+ const pickup = part === 0 && firstLine ? pickupWidth : 0;
60
+ const width = (868 - pickup) / (firstLine ? 4 : 5);
61
+ const x = 16 + pickup + (firstLine ? i : i - 4) * width;
62
+ const row = part * 2 + (firstLine ? 0 : 1);
63
+ const lastBar = part === 1 && i === 8;
64
+ const stave = f
65
+ .System({ x, y: firstY + row * 142, width })
66
+ .addStave({ voices: [score.voice(notes, { time: lastBar ? '5/8' : '6/8' })], options: { topTextPosition: 2 } });
67
+ if (i === 4 || (part === 1 && i === 0))
68
+ stave.addClef('treble').addKeySignature('G');
69
+ if (i === 0)
70
+ stave.setBegBarType(BarlineType.REPEAT_BEGIN).setSection(part ? 'B' : 'A', 0);
71
+ if (i === 7)
72
+ stave.setVoltaType(VoltaType.BEGIN_END, '1.', 0).setEndBarType(BarlineType.REPEAT_END);
73
+ if (i === 8)
74
+ stave.setVoltaType(VoltaType.BEGIN, '2.', 0);
75
+ if (lastBar)
76
+ stave.setEndBarType(BarlineType.END);
77
+ }));
78
+ f.draw();
79
+ options.assert.ok(true, 'Accompanied A and B strains with first and second endings');
80
+ }
@@ -0,0 +1,59 @@
1
+ import { VexFlowTests } from '../vexflow_test_helpers.js';
2
+ import { StaveHairpin } from '../../src/index.js';
3
+ export function prelude(options) {
4
+ const f = VexFlowTests.makeFactory(options, 900, 525);
5
+ const score = f.EasyScore({ throwOnError: true });
6
+ const harmonies = [
7
+ ['C4', 'E4', 'G4', 'C5', 'E5'],
8
+ ['C4', 'D4', 'A4', 'D5', 'F5'],
9
+ ['B3', 'D4', 'G4', 'D5', 'F5'],
10
+ ['C4', 'E4', 'G4', 'C5', 'E5'],
11
+ ];
12
+ harmonies.forEach(([bass, inner, a, b, c], i) => {
13
+ const system = f.System({
14
+ x: 24 + (i % 2) * 428,
15
+ y: 40 + Math.floor(i / 2) * 250,
16
+ width: 428,
17
+ spaceBetweenStaves: 9,
18
+ });
19
+ const treble = system.addStave({ voices: [] });
20
+ const dynamic = ['p', '', 'mf', 'p'][i];
21
+ const lower = system.addStave({
22
+ voices: dynamic ? [score.voice([score.make.textDynamics({ text: dynamic, line: 10, duration: 'w' })])] : [],
23
+ });
24
+ if (i % 2 === 0) {
25
+ treble.addClef('treble');
26
+ lower.addClef('bass');
27
+ system.addConnector('brace');
28
+ if (i === 0) {
29
+ treble.addTimeSignature('C').setTempo({ name: 'Andante, legato', duration: 'q', bpm: 72 }, -9);
30
+ lower.addTimeSignature('C');
31
+ }
32
+ }
33
+ const arpeggio = [];
34
+ for (let half = 0; half < 2; half++) {
35
+ const left = score.notes(`${bass}/16, ${inner}`, { clef: 'bass', stem: 'up' });
36
+ const right = score.notes(`${a}/16, ${b}`, { stem: 'down' });
37
+ const answer = score.notes(`${c}/16, ${a}, ${b}, ${c}`, { stem: 'down' });
38
+ left.forEach((note) => note.setStave(lower));
39
+ [...right, ...answer].forEach((note) => note.setStave(treble));
40
+ score.beam([...left, ...right]);
41
+ score.beam(answer);
42
+ if (half === 0 && i >= 2)
43
+ answer[0].addModifier(score.make.articulation({ type: i === 2 ? 'accent' : 'tenuto', position: 'above' }));
44
+ arpeggio.push(...left, ...right, ...answer);
45
+ }
46
+ if (i === 1 || i === 2) {
47
+ score.make.hairpin({
48
+ from: arpeggio[0],
49
+ to: arpeggio[8],
50
+ type: i === 1 ? StaveHairpin.type.CRESC : StaveHairpin.type.DECRESC,
51
+ options: { leftShiftPx: i === 2 ? 30 : 0, yShift: -6, height: 7 },
52
+ });
53
+ }
54
+ system.addVoices([score.voice(arpeggio)]);
55
+ system.addConnector('singleRight');
56
+ });
57
+ f.draw();
58
+ options.assert.ok(true, 'Both hands share a beam on beats one and three');
59
+ }
@@ -0,0 +1,50 @@
1
+ import { VexFlowTests } from '../vexflow_test_helpers.js';
2
+ import { BarlineType, StaveHairpin } from '../../src/index.js';
3
+ export function quartertones(options) {
4
+ const f = VexFlowTests.makeFactory(options, 900, 340);
5
+ const score = f.EasyScore({ throwOnError: true });
6
+ score.set({ time: '5/8', clef: 'alto' });
7
+ const bars = [
8
+ { music: 'D4/8, D4, E4, F4/q', signs: ['', '+', 'd', ''] },
9
+ { music: 'F4/8, F4, G4, A4/q', signs: ['', '+', '', 'd'] },
10
+ { music: 'A4/q., G4/q', signs: ['n', '+'] },
11
+ { music: 'G4/8, G4, F4, E4/q', signs: ['', 'd', '+', ''] },
12
+ { music: 'E4/8, E4, D4, C4/q', signs: ['', 'd', '+', '++'] },
13
+ { music: 'D4/q., D4/q', signs: ['d', 'n'] },
14
+ ];
15
+ bars.forEach(({ music, signs }, i) => {
16
+ const notes = score.notes(music);
17
+ signs.forEach((type, n) => {
18
+ if (!type)
19
+ return;
20
+ const mark = score.make.accidental({ type });
21
+ if (i === 2 && n === 0)
22
+ mark.setAsCautionary();
23
+ notes[n].addModifier(mark);
24
+ });
25
+ if (notes.length === 4) {
26
+ score.beam(notes.slice(0, 3));
27
+ score.make.curve({ from: notes[0], to: notes[2] });
28
+ }
29
+ if (i === 0 || i === 4)
30
+ score.make.hairpin({
31
+ from: notes[0],
32
+ to: notes[3],
33
+ type: i === 0 ? StaveHairpin.type.CRESC : StaveHairpin.type.DECRESC,
34
+ options: { height: 7, yShift: -4 },
35
+ });
36
+ const stave = f
37
+ .System({ x: 16 + (i % 3) * 288, y: 24 + Math.floor(i / 3) * 154, width: 288 })
38
+ .addStave({ voices: [score.voice(notes)] });
39
+ if (i % 3 === 0)
40
+ stave.addClef('alto');
41
+ if (i === 0)
42
+ stave.addTimeSignature('5/8').setTempo({ name: 'Sotto voce', duration: '8', bpm: 108 }, -4);
43
+ if (i === 5) {
44
+ notes[1].addModifier(score.make.articulation({ type: 'fermata', position: 'above' }));
45
+ stave.setEndBarType(BarlineType.END);
46
+ }
47
+ });
48
+ f.draw();
49
+ options.assert.ok(true, 'Quarter-tone inflections in two phrases of three measures');
50
+ }
@@ -0,0 +1,65 @@
1
+ import { VexFlowTests } from '../vexflow_test_helpers.js';
2
+ import { BarlineType, ChordSymbol } from '../../src/index.js';
3
+ export function saints(options) {
4
+ const factory = VexFlowTests.makeFactory(options, 900, 540);
5
+ const score = factory.EasyScore({ throwOnError: true });
6
+ const bars = [
7
+ ['G4/w', 'saints', 'C:6/9'],
8
+ ['B4/q/r, C4/q, E4, F4', '|go|march-|ing', 'Am:7'],
9
+ ['G4/w', 'in', 'Dm:11'],
10
+ ['B4/q/r, C4/q, E4, F4', '|Oh|when|the', 'G:13'],
11
+ ['G4/q, E4, C4, E4', 'saints|go|march-|ing', 'C:maj9'],
12
+ ['D4/w', 'in', 'Am:11'],
13
+ ['D4/w', '', 'D:9'],
14
+ ['B4/q/r, E4/q, E4, D4', '|Oh|Lord,|I', 'G:13'],
15
+ ['C4/h, C4/q, E4', 'want|to|be', 'Gm:13'],
16
+ ['G4/h, G4/q, G4', 'in|that|num-', 'C:9'],
17
+ ['F4/w', 'ber', 'F:maj9'],
18
+ ['B4/q/r, C4/q, E4, F4', '|Oh|when|the', 'Fm:maj7'],
19
+ ['G4/h, E4/q, C4', 'saints|go|march-', 'Em:7'],
20
+ ['D4/w', 'ing', 'Db:7b9'],
21
+ ['C4/w', 'in', 'C:6/9'],
22
+ ['C4/q', '', ''],
23
+ ];
24
+ const pickup = score.notes('C4/q, E4, F4');
25
+ const pickupLabels = ['Oh', 'when', 'the'];
26
+ pickup.forEach((note, i) => note.addModifier(factory.Annotation({ text: pickupLabels[i], vJustify: 'bottom' }).setTextBaseline(123)));
27
+ factory
28
+ .System({ x: 10, y: 16, width: 180 })
29
+ .addStave({ voices: [score.voice(pickup, { time: '3/4' })] })
30
+ .addClef('treble')
31
+ .addTimeSignature('4/4');
32
+ let sustained;
33
+ bars.forEach(([music, words, harmony], i) => {
34
+ const row = Math.floor(i / 4);
35
+ const column = i % 4;
36
+ const y = 16 + row * 130;
37
+ const width = row === 0 ? 174 : 219;
38
+ const notes = score.notes(music);
39
+ if (i === 5 || i === 14)
40
+ sustained = notes[0];
41
+ if ((i === 6 || i === 15) && sustained)
42
+ score.make.tie({ from: sustained, to: notes[0] });
43
+ words.split('|').forEach((text, n) => {
44
+ if (text)
45
+ notes[n].addModifier(factory.Annotation({ text, vJustify: 'bottom' }).setTextBaseline(y + 107));
46
+ });
47
+ if (harmony) {
48
+ const [root, extension] = harmony.split(':');
49
+ const chord = factory
50
+ .ChordSymbol()
51
+ .addGlyphOrText(root)
52
+ .addGlyphOrText(extension, { symbolModifier: ChordSymbol.symbolModifiers.SUPERSCRIPT });
53
+ notes[0].addModifier(chord);
54
+ }
55
+ const stave = factory
56
+ .System({ x: (row === 0 ? 190 : 10) + column * width, y, width })
57
+ .addStave({ voices: [score.voice(notes, { time: i === 15 ? '1/4' : '4/4' })] });
58
+ if (column === 0 && row > 0)
59
+ stave.addClef('treble');
60
+ if (i === bars.length - 1)
61
+ stave.setEndBarType(BarlineType.END);
62
+ });
63
+ factory.draw();
64
+ options.assert.ok(true, 'Petaluma lead sheet with aligned lyrics');
65
+ }
@@ -0,0 +1,75 @@
1
+ import { compositionInput } from './score-persistence.mjs';
2
+ export function passageView(VF, factory, score) {
3
+ const composition = factory.EasyScore().compose(compositionInput(score));
4
+ const bar = (id) => score.measures.findIndex((m) => m.id === id);
5
+ const staff = (id) => score.staves.findIndex((s) => s.id === id);
6
+ const dynamics = [];
7
+ for (const mark of score.marks) {
8
+ if (mark.kind === 'rehearsal')
9
+ composition.staves[bar(mark.measure)][staff(mark.staff)].setSection(mark.text, 0);
10
+ if (mark.kind === 'dynamic') {
11
+ const owner = composition.getNote(mark.event);
12
+ const glyph = factory
13
+ .Annotation({ text: VF.VexFlow.Glyphs.dynamicPiano, vJustify: 'bottom' })
14
+ .setFont(owner.fontInfo);
15
+ glyph.setYShift(mark.offset * owner.checkStave().getSpacingBetweenLines());
16
+ owner.addModifier(glyph, 0);
17
+ dynamics.push({ id: mark.id, owner, glyph });
18
+ }
19
+ }
20
+ function anchorX(anchor, stave) {
21
+ if (anchor.continuation)
22
+ return anchor.at === '0/1' ? stave.getX() : stave.getX() + stave.getWidth();
23
+ if (anchor.at === '1/1')
24
+ return stave.getX() + stave.getWidth();
25
+ const event = Object.values(score.measures[bar(anchor.measure)].voices)
26
+ .flat()
27
+ .find((e) => e.at === anchor.at);
28
+ if (!event)
29
+ throw new Error(`The M1 adapter requires a formatted attack at ${anchor.measure} ${anchor.at}`);
30
+ return composition.getNote(event.id).getAbsoluteX();
31
+ }
32
+ function drawPedal(mark, rows) {
33
+ const start = bar(mark.start.measure), end = bar(mark.end.measure);
34
+ const ctx = factory.getContext();
35
+ const fragments = [];
36
+ for (const row of rows) {
37
+ const first = Math.max(row[0], start), last = Math.min(row.at(-1), end);
38
+ if (first > last)
39
+ continue;
40
+ const left = composition.staves[first][staff(mark.staff)], right = composition.staves[last][staff(mark.staff)];
41
+ const x1 = first === start ? anchorX(mark.start, left) : left.getX();
42
+ const x2 = last === end ? anchorX(mark.end, right) : right.getX() + right.getWidth();
43
+ const y = left.getYForBottomText(2), hook = left.getSpacingBetweenLines() / 2;
44
+ const depress = first === start && !mark.start.continuation, release = last === end && !mark.end.continuation;
45
+ ctx.save();
46
+ ctx.setLineWidth(1);
47
+ ctx.beginPath();
48
+ ctx.moveTo(x1, depress ? y - hook : y);
49
+ ctx.lineTo(x1, y);
50
+ ctx.lineTo(x2, y);
51
+ if (release)
52
+ ctx.lineTo(x2, y - hook);
53
+ ctx.stroke();
54
+ ctx.restore();
55
+ fragments.push({ id: mark.id, x1, x2, y, depress, release });
56
+ }
57
+ return fragments;
58
+ }
59
+ return {
60
+ composition,
61
+ dynamics,
62
+ draw(width) {
63
+ composition.sheet.setWidth(width);
64
+ factory.getContext().clear();
65
+ factory.draw({ retain: true });
66
+ const rows = composition.sheet
67
+ .getRows()
68
+ .map((row) => row.systems.map((system) => composition.systems.indexOf(system)));
69
+ return {
70
+ rows,
71
+ fragments: score.marks.filter((mark) => mark.kind === 'pedal').flatMap((mark) => drawPedal(mark, rows)),
72
+ };
73
+ },
74
+ };
75
+ }