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.
Files changed (189) hide show
  1. package/README.md +2 -0
  2. package/build/cjs/vexflow-bravura.js +2 -2
  3. package/build/cjs/vexflow-bravura.js.map +1 -1
  4. package/build/cjs/vexflow-core.js +2 -2
  5. package/build/cjs/vexflow-core.js.map +1 -1
  6. package/build/cjs/vexflow-debug-with-tests.js +6502 -1708
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +5622 -1618
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow.js +2 -2
  11. package/build/cjs/vexflow.js.map +1 -1
  12. package/build/esm/src/accidental.js +10 -3
  13. package/build/esm/src/alternatingtremolo.js +68 -0
  14. package/build/esm/src/annotation.js +19 -3
  15. package/build/esm/src/articulation.js +28 -6
  16. package/build/esm/src/beam.js +171 -28
  17. package/build/esm/src/bend.js +79 -23
  18. package/build/esm/src/clef.js +3 -0
  19. package/build/esm/src/continuouslayout.js +681 -0
  20. package/build/esm/src/continuousspan.js +159 -0
  21. package/build/esm/src/curve.js +48 -55
  22. package/build/esm/src/dot.js +13 -4
  23. package/build/esm/src/easyscore/composition.js +52 -2
  24. package/build/esm/src/easyscore/policies.js +39 -8
  25. package/build/esm/src/element.js +4 -0
  26. package/build/esm/src/engravinggeometry.js +157 -0
  27. package/build/esm/src/engravingprofile.js +44 -0
  28. package/build/esm/src/factory.js +31 -11
  29. package/build/esm/src/font.js +9 -1
  30. package/build/esm/src/formatter.js +9 -1
  31. package/build/esm/src/fretdiagram.js +77 -0
  32. package/build/esm/src/gracenote.js +43 -38
  33. package/build/esm/src/gracenotegroup.js +53 -56
  34. package/build/esm/src/guitargesture.js +33 -0
  35. package/build/esm/src/guitarmodifiers.js +26 -0
  36. package/build/esm/src/index.js +10 -0
  37. package/build/esm/src/instrumentprofile.js +123 -0
  38. package/build/esm/src/keysignature.js +24 -2
  39. package/build/esm/src/modifiercontext.js +11 -0
  40. package/build/esm/src/notationspelling.js +73 -0
  41. package/build/esm/src/note.js +3 -0
  42. package/build/esm/src/notehead.js +11 -6
  43. package/build/esm/src/ornament.js +43 -18
  44. package/build/esm/src/pagebreaks.js +58 -0
  45. package/build/esm/src/pedalmarking.js +39 -17
  46. package/build/esm/src/phraselayout.js +503 -0
  47. package/build/esm/src/phraseribbon.js +28 -0
  48. package/build/esm/src/proportionalformatter.js +54 -6
  49. package/build/esm/src/publication.js +402 -0
  50. package/build/esm/src/publicationview.js +114 -0
  51. package/build/esm/src/scorenavigation.js +172 -0
  52. package/build/esm/src/sheet.js +14 -2
  53. package/build/esm/src/stave.js +33 -16
  54. package/build/esm/src/stavebarline.js +5 -7
  55. package/build/esm/src/staveconnector.js +1 -0
  56. package/build/esm/src/stavehairpin.js +53 -27
  57. package/build/esm/src/stavenote.js +134 -116
  58. package/build/esm/src/stavetie.js +66 -9
  59. package/build/esm/src/stem.js +26 -11
  60. package/build/esm/src/strokes.js +4 -0
  61. package/build/esm/src/system.js +19 -4
  62. package/build/esm/src/systembreaks.js +42 -0
  63. package/build/esm/src/tabnote.js +6 -1
  64. package/build/esm/src/textbracket.js +24 -5
  65. package/build/esm/src/tickcontext.js +19 -0
  66. package/build/esm/src/timesignature.js +20 -6
  67. package/build/esm/src/tuplet.js +58 -17
  68. package/build/esm/src/version.js +3 -3
  69. package/build/esm/src/vexflow.js +20 -0
  70. package/build/esm/src/voice.js +7 -3
  71. package/build/esm/tests/bend_tests.js +14 -1
  72. package/build/esm/tests/curve_tests.js +14 -4
  73. package/build/esm/tests/demo_repertoire_tests.js +27 -0
  74. package/build/esm/tests/demos/drums.js +54 -0
  75. package/build/esm/tests/demos/electric.js +63 -0
  76. package/build/esm/tests/demos/greensleeves.js +90 -0
  77. package/build/esm/tests/demos/joy.js +61 -0
  78. package/build/esm/tests/demos/kesh.js +80 -0
  79. package/build/esm/tests/demos/prelude.js +59 -0
  80. package/build/esm/tests/demos/quartertones.js +50 -0
  81. package/build/esm/tests/demos/saints.js +65 -0
  82. package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
  83. package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
  84. package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
  85. package/build/esm/tests/engraving/publication-studies.mjs +87 -0
  86. package/build/esm/tests/engraving/score-layout.mjs +75 -0
  87. package/build/esm/tests/engraving/score-persistence.mjs +262 -0
  88. package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
  89. package/build/esm/tests/engraving/studies.mjs +367 -0
  90. package/build/esm/tests/formatter_tests.js +10 -1
  91. package/build/esm/tests/index.js +1 -0
  92. package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
  93. package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
  94. package/build/esm/tests/node/easyscore-tests.mjs +71 -0
  95. package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
  96. package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
  97. package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
  98. package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
  99. package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
  100. package/build/esm/tests/node/publication-tests.mjs +219 -0
  101. package/build/esm/tests/node/rendering-tests.mjs +6 -2
  102. package/build/esm/tests/threevoice_tests.js +11 -1
  103. package/build/esm/tests/vexflow_test_helpers.js +19 -10
  104. package/build/esm/tools/audit-dependencies.mjs +61 -0
  105. package/build/esm/tools/easyscore-structure.mjs +1 -1
  106. package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
  107. package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
  108. package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
  109. package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
  110. package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
  111. package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
  112. package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
  113. package/build/esm/tools/score-fixtures.mjs +23 -6
  114. package/build/types/src/accidental.d.ts +4 -0
  115. package/build/types/src/alternatingtremolo.d.ts +13 -0
  116. package/build/types/src/annotation.d.ts +9 -0
  117. package/build/types/src/articulation.d.ts +9 -1
  118. package/build/types/src/beam.d.ts +16 -0
  119. package/build/types/src/bend.d.ts +8 -0
  120. package/build/types/src/clef.d.ts +3 -0
  121. package/build/types/src/continuouslayout.d.ts +103 -0
  122. package/build/types/src/continuousspan.d.ts +60 -0
  123. package/build/types/src/curve.d.ts +20 -0
  124. package/build/types/src/dot.d.ts +5 -0
  125. package/build/types/src/easyscore/composition.d.ts +27 -0
  126. package/build/types/src/easyscore/policies.d.ts +1 -1
  127. package/build/types/src/element.d.ts +2 -0
  128. package/build/types/src/engravinggeometry.d.ts +31 -0
  129. package/build/types/src/engravingprofile.d.ts +20 -0
  130. package/build/types/src/factory.d.ts +6 -1
  131. package/build/types/src/formatter.d.ts +3 -3
  132. package/build/types/src/fretdiagram.d.ts +23 -0
  133. package/build/types/src/gracenote.d.ts +7 -0
  134. package/build/types/src/gracenotegroup.d.ts +7 -2
  135. package/build/types/src/guitargesture.d.ts +26 -0
  136. package/build/types/src/guitarmodifiers.d.ts +3 -0
  137. package/build/types/src/index.d.ts +12 -0
  138. package/build/types/src/instrumentprofile.d.ts +124 -0
  139. package/build/types/src/keysignature.d.ts +9 -0
  140. package/build/types/src/modifiercontext.d.ts +4 -0
  141. package/build/types/src/notationspelling.d.ts +25 -0
  142. package/build/types/src/note.d.ts +15 -0
  143. package/build/types/src/notehead.d.ts +5 -0
  144. package/build/types/src/ornament.d.ts +10 -1
  145. package/build/types/src/pagebreaks.d.ts +26 -0
  146. package/build/types/src/pedalmarking.d.ts +9 -0
  147. package/build/types/src/phraselayout.d.ts +87 -0
  148. package/build/types/src/phraseribbon.d.ts +7 -0
  149. package/build/types/src/proportionalformatter.d.ts +11 -2
  150. package/build/types/src/publication.d.ts +61 -0
  151. package/build/types/src/publicationview.d.ts +27 -0
  152. package/build/types/src/scorenavigation.d.ts +33 -0
  153. package/build/types/src/sheet.d.ts +5 -0
  154. package/build/types/src/stave.d.ts +13 -0
  155. package/build/types/src/stavehairpin.d.ts +18 -0
  156. package/build/types/src/stavenote.d.ts +20 -2
  157. package/build/types/src/stavetie.d.ts +9 -0
  158. package/build/types/src/stem.d.ts +10 -1
  159. package/build/types/src/system.d.ts +8 -1
  160. package/build/types/src/systembreaks.d.ts +9 -0
  161. package/build/types/src/textbracket.d.ts +7 -0
  162. package/build/types/src/tickcontext.d.ts +5 -0
  163. package/build/types/src/timesignature.d.ts +6 -0
  164. package/build/types/src/tuplet.d.ts +5 -48
  165. package/build/types/src/vexflow.d.ts +20 -0
  166. package/build/types/src/voice.d.ts +2 -0
  167. package/changelog/CHANGELOG.md +25 -0
  168. package/package.json +15 -3
  169. package/tests/all.html +277 -0
  170. package/tests/demo_petzold_tests.ts +435 -0
  171. package/tests/demos/drums.ts +55 -0
  172. package/tests/demos/drums.webp +0 -0
  173. package/tests/demos/electric.ts +70 -0
  174. package/tests/demos/electric.webp +0 -0
  175. package/tests/demos/greensleeves.ts +97 -0
  176. package/tests/demos/greensleeves.webp +0 -0
  177. package/tests/demos/joy.ts +65 -0
  178. package/tests/demos/joy.webp +0 -0
  179. package/tests/demos/kesh.ts +86 -0
  180. package/tests/demos/kesh.webp +0 -0
  181. package/tests/demos/prelude.ts +65 -0
  182. package/tests/demos/prelude.webp +0 -0
  183. package/tests/demos/quartertones.ts +51 -0
  184. package/tests/demos/quartertones.webp +0 -0
  185. package/tests/demos/saints.ts +70 -0
  186. package/tests/demos/saints.webp +0 -0
  187. package/tests/flow.html +550 -239
  188. package/tests/fonts.css +493 -0
  189. package/tests/minuet.webp +0 -0
@@ -0,0 +1,273 @@
1
+ export function makeInstrumentStudy(VF, f, kind) {
2
+ var _a, _b, _c, _d, _e, _f;
3
+ const score = f.EasyScore();
4
+ const row = (y, width = 650, x = 22) => f.System({ width, x, y, spaceBetweenStaves: 12 });
5
+ const voice = (notes) => score.voice(notes, { mode: 'soft' });
6
+ const note = (keys, duration = 'q', extra = {}) => f.StaveNote(Object.assign({ keys, duration }, extra));
7
+ const text = (n, label, above = false) => n.addModifier(f.Annotation({ text: label, vJustify: above ? 'top' : 'bottom' }), 0);
8
+ const identity = (kind, id, label) => [{ kind, id, label }];
9
+ const study = { notes: [] };
10
+ if (kind === 'kit' || kind === 'line') {
11
+ const single = kind === 'line';
12
+ const entries = single
13
+ ? [{ id: 'snare', label: 'Side drum', line: 3, stem: 'up' }]
14
+ : [
15
+ { id: 'kick', label: 'Bass drum', line: 1.5, stem: 'down' },
16
+ { id: 'snare', label: 'Snare drum', line: 3.5, stem: 'up' },
17
+ { id: 'hat', label: 'Closed hi-hat', line: 5.5, stem: 'up', head: 'cross' },
18
+ ];
19
+ const map = VF.PercussionMap && new VF.PercussionMap(entries);
20
+ const legacy = { kick: 'f/4', snare: single ? 'b/4' : 'c/5', hat: 'g/5/X' };
21
+ const make = (ids, duration, stem = 'up') => f.StaveNote(map
22
+ ? map.note(ids, duration, stem)
23
+ : { keys: ids.map((id) => legacy[id]), duration, clef: 'percussion', stemDirection: stem === 'up' ? 1 : -1 });
24
+ const notes = (single
25
+ ? [['snare'], ['snare'], ['snare'], ['snare'], ['snare'], ['snare']]
26
+ : [['hat'], ['hat'], ['snare', 'hat'], ['hat'], ['hat'], ['snare', 'hat']]).map((ids, i) => make(ids, ['8', '8', 'q', '8', '8', 'q'][i]));
27
+ f.Beam({ notes: notes.slice(0, 2) });
28
+ f.Beam({ notes: notes.slice(3, 5) });
29
+ notes[2].addModifier(new VF.Tremolo(single ? 3 : 1), 0);
30
+ if (single)
31
+ notes.forEach((n, i) => text(n, ['R', 'L', 'R', 'L', 'R', 'L'][i]));
32
+ const voices = [voice(notes)];
33
+ if (!single)
34
+ voices.push(voice([make(['kick'], 'h', 'down'), make(['kick'], 'h', 'down')]));
35
+ const staff = row(22)
36
+ .addStave({ voices, options: single ? { barlineSpan: { top: 1, bottom: 3 } } : {} })
37
+ .addClef('percussion')
38
+ .addTimeSignature('4/4');
39
+ if (single) {
40
+ [0, 1, 3, 4].forEach((i) => staff.setConfigForLine(i, { visible: false }));
41
+ }
42
+ else {
43
+ const legend = entries.map((e) => make([e.id], 'q', e.stem));
44
+ const legendSystem = row(142, 590, 58);
45
+ const legendStaff = legendSystem.addStave({ voices: [voice(legend)] }).addClef('percussion');
46
+ const layout = (_a = legendSystem.getPhraseLayout) === null || _a === void 0 ? void 0 : _a.call(legendSystem);
47
+ if (layout)
48
+ layout.addVerse(legendStaff, legend.map((note, i) => ({ note, text: entries[i].label })));
49
+ else
50
+ legend.forEach((n, i) => text(n, entries[i].label));
51
+ }
52
+ study.notes = notes;
53
+ }
54
+ else if (kind === 'lead') {
55
+ const upper = row(71, 320);
56
+ const lower = row(71, 325, 342);
57
+ const keys = ['e/4', 'g/4', 'a/4', 'g/4', 'f/4', 'e/4', 'd/4', 'c/4'];
58
+ const harmonies = [
59
+ ['C', 'maj9', 'E'],
60
+ ['A', '7(b9)', ''],
61
+ ['D', 'm9', ''],
62
+ ['G', '7(#11)', 'B'],
63
+ ];
64
+ const notes = keys.map((key, i) => {
65
+ const chord = harmonies[i / 2];
66
+ return note([key], 'q', chord ? { notation: identity('harmony', chord.join('-'), chord.filter(Boolean).join(' ')) } : {});
67
+ });
68
+ harmonies.forEach(([root, quality, bass], i) => {
69
+ const chord = f
70
+ .ChordSymbol({ hJustify: 'left' })
71
+ .addText(root)
72
+ .addGlyphOrText(quality, { symbolModifier: VF.ChordSymbol.symbolModifiers.SUPERSCRIPT });
73
+ if (bass)
74
+ chord.addText('/' + bass);
75
+ notes[i * 2].addModifier(chord, 0);
76
+ });
77
+ [upper, lower].forEach((sys, j) => {
78
+ const melody = notes.slice(j * 4, j * 4 + 4);
79
+ const staff = sys.addStave({ voices: [voice(melody)] });
80
+ if (!j)
81
+ staff.addClef('treble').setSection('A', -2).setBegBarType(VF.Barline.type.REPEAT_BEGIN);
82
+ else
83
+ staff.setVoltaType(VF.Volta.type.BEGIN_END, '1.', -20).setEndBarType(VF.Barline.type.REPEAT_END);
84
+ const words = j ? ['turn', 'with', 'the', 'tide'] : ['Draw', 'in', 'the', 'sail'];
85
+ melody.forEach((n, i) => text(n, words[i]));
86
+ });
87
+ const slashes = ['1', 'vi', 'ii', 'V', 'N.C.'].map((label) => {
88
+ const n = note(['b/4'], 'q', { type: 's', notation: identity('harmony', label, label) });
89
+ n.addModifier(f.ChordSymbol().addText(label), 0);
90
+ return n;
91
+ });
92
+ row(202)
93
+ .addStave({ voices: [voice(slashes)] })
94
+ .addClef('treble');
95
+ study.notes = notes;
96
+ }
97
+ else if (kind === 'guitar') {
98
+ const instrument = VF.FrettedInstrument && new VF.FrettedInstrument('dropd', 2);
99
+ const tuning = new VF.Tuning('dropd');
100
+ const positions = [
101
+ { str: 6, fret: 0 },
102
+ { str: 3, fret: 2 },
103
+ { str: 2, fret: 3 },
104
+ { str: 2, fret: 5 },
105
+ ];
106
+ const pairs = positions.map((p) => {
107
+ var _a;
108
+ return (_a = instrument === null || instrument === void 0 ? void 0 : instrument.attack([p], 'q')) !== null && _a !== void 0 ? _a : {
109
+ note: { keys: [tuning.getNoteForFret(p.fret + 2, p.str)], duration: 'q' },
110
+ tab: { positions: [p], duration: 'q' },
111
+ };
112
+ });
113
+ const notes = pairs.map((p) => f.StaveNote(p.note));
114
+ const tabs = pairs.map((p) => f.TabNote(p.tab));
115
+ const sys = row(29, 525);
116
+ sys.addStave({ voices: [voice(notes)] }).addClef('treble');
117
+ const addSigns = (n) => n.getKeys().forEach((key, i) => {
118
+ if (key.split('/')[0].includes('#'))
119
+ n.addModifier(new VF.Accidental('#'), i);
120
+ });
121
+ notes.forEach(addSigns);
122
+ text(notes[0], 'Drop D · capo 2', true);
123
+ sys.addStave({ stave: f.TabStave({ x: 22, y: 150, width: 525 }), voices: [voice(tabs)] }).addTabGlyph();
124
+ const phrase = VF.Bend.HOLD !== undefined
125
+ ? [
126
+ { type: VF.Bend.PREBEND, text: 'full' },
127
+ { type: VF.Bend.HOLD, text: '' },
128
+ { type: VF.Bend.DOWN, text: '' },
129
+ ]
130
+ : [
131
+ { type: VF.Bend.UP, text: 'full' },
132
+ { type: VF.Bend.DOWN, text: '' },
133
+ ];
134
+ tabs[1].addModifier(new VF.Bend(phrase), 0);
135
+ tabs[2].addModifier(new VF.GraceNoteGroup([new VF.GraceTabNote({ positions: [{ str: 2, fret: 2 }], duration: '8' })]), 0);
136
+ f.TabSlide({ firstNote: tabs[2], lastNote: tabs[3], firstIndexes: [0], lastIndexes: [0] });
137
+ if (VF.FretDiagram) {
138
+ const frame = new VF.FretDiagram({ frets: ['x', 0, 2, 2, 2, 0], barre: { fret: 2, from: 4, to: 2 } });
139
+ f.adopt(frame.setX(562).setY(57).setContext(f.getContext()), 'drawable');
140
+ }
141
+ study.notes = notes;
142
+ }
143
+ else if (kind === 'techniques') {
144
+ const makeEnd = (keys) => {
145
+ const data = { keys, duration: 'h', stemDirection: 1 };
146
+ return f.StaveNote(VF.AlternatingTremolo
147
+ ? VF.AlternatingTremolo.endpoint(data, 3)
148
+ : Object.assign(Object.assign({}, data), { durationOverride: new VF.Fraction(1, 4) }));
149
+ };
150
+ const notes = [
151
+ makeEnd(['c/4', 'e/4']),
152
+ makeEnd(['d/4', 'f/4']),
153
+ note(['g/4'], 'q', { notation: identity('technique', 'harmonic', 'Natural harmonic') }),
154
+ note(['f/4'], 'q', { notation: identity('technique', 'down-bow', 'Down bow') }),
155
+ ];
156
+ const sys = row(24);
157
+ sys.addStave({ voices: [voice(notes)] }).addClef('treble');
158
+ if (VF.AlternatingTremolo)
159
+ f.adopt(new VF.AlternatingTremolo(notes[0], notes[1], 3).setContext(f.getContext()), 'drawable');
160
+ else
161
+ notes.slice(0, 2).forEach((n) => n.addModifier(new VF.Tremolo(3), 0));
162
+ notes[2].addModifier(f.Articulation({ type: 'ah', position: 'above' }), 0);
163
+ notes[3].addModifier(f.Articulation({ type: 'am', position: 'above' }), 0);
164
+ const labels = [
165
+ ['pedal', 'Ped.'],
166
+ ['finger-2', '2'],
167
+ ['breath', 'Breath'],
168
+ ['sons-etouffes', 'sons étouffés'],
169
+ ];
170
+ const lower = ['c/3', 'e/3', 'g/3', 'c/4'].map((key, i) => note([key], 'q', { clef: 'bass', notation: identity('technique', ...labels[i]) }));
171
+ sys.addStave({ voices: [voice(lower)] }).addClef('bass');
172
+ f.PedalMarking({ notes: [lower[0], lower[1]], options: { style: 'bracket' } });
173
+ lower[1].addModifier(new VF.FretHandFinger('2').setPosition(VF.Modifier.Position.LEFT), 0);
174
+ lower[2].addModifier(f.Articulation({ type: VF.Glyphs.breathMarkComma, position: 'above' }), 0);
175
+ text(lower[3], labels[3][1], true);
176
+ study.notes = [...notes, ...lower];
177
+ }
178
+ else if (kind === 'micro') {
179
+ for (const [j, signs, labels] of [
180
+ [0, ['+', 'd'], ['Quarter sharp', 'Quarter flat']],
181
+ [1, ['o', 'k'], ['Sori', 'Koron']],
182
+ ]) {
183
+ const sys = row(20 + j * 128);
184
+ const notes = ['g/4', 'a/4', 'g/4', 'a/4'].map((key, i) => note([key], 'q', {
185
+ notation: identity('accidental', i === 2 ? 'n' : signs[i % 2], i === 2 ? 'Natural' : labels[i % 2]),
186
+ }));
187
+ const staff = sys.addStave({ voices: [voice(notes)] }).addClef('treble');
188
+ const sig = new VF.KeySignature('C');
189
+ if (sig.setOrdered)
190
+ staff.addModifier(sig.setOrdered([
191
+ { type: signs[1], line: 2.5 },
192
+ { type: signs[0], line: 3 },
193
+ ]));
194
+ else
195
+ notes.slice(0, 2).forEach((n, i) => n.addModifier(new VF.Accidental(signs[i])));
196
+ if (VF.WrittenAccidentalState) {
197
+ const state = new VF.WrittenAccidentalState({ g: signs[0], a: signs[1] });
198
+ notes.forEach((n, i) => {
199
+ const printed = state.sign(n.getKeys()[0], i === 2 ? 'n' : signs[i % 2], i === 3);
200
+ if (printed) {
201
+ const mark = new VF.Accidental(printed);
202
+ n.addModifier(i === 3 ? mark.setAsCautionary() : mark);
203
+ }
204
+ });
205
+ }
206
+ else {
207
+ notes[2].addModifier(new VF.Accidental('n'));
208
+ notes[3].addModifier(new VF.Accidental(signs[1]).setAsCautionary());
209
+ }
210
+ study.notes.push(...notes);
211
+ }
212
+ }
213
+ else if (kind === 'spelling') {
214
+ const segments = (_c = (_b = VF.NotationSpelling) === null || _b === void 0 ? void 0 : _b.rhythm(48, 40, [64, 80])) !== null && _c !== void 0 ? _c : [
215
+ { duration: '4' },
216
+ { duration: '4' },
217
+ { duration: '8' },
218
+ ];
219
+ const written = (_e = (_d = VF.NotationSpelling) === null || _d === void 0 ? void 0 : _d.transpose('b/4', 2, 1)) !== null && _e !== void 0 ? _e : 'c#/5';
220
+ const notes = segments.map((seg) => note([written], seg.duration));
221
+ const rest = note(['b/4'], '8r');
222
+ const finish = ['c/5', 'd/5'].map((key) => note([key], 'q'));
223
+ notes[0].addModifier(new VF.Accidental('#'));
224
+ row(35, 155)
225
+ .addStave({ voices: [voice([notes[0]])] })
226
+ .addClef('treble')
227
+ .addTimeSignature('4/4');
228
+ row(35, 490, 177).addStave({ voices: [voice([...notes.slice(1), rest, ...finish])] });
229
+ finish[0].addModifier(new VF.Accidental('n'));
230
+ for (let i = 1; i < notes.length; i++)
231
+ f.StaveTie({ from: notes[i - 1], to: notes[i] });
232
+ text(notes[0], 'B♭ clarinet', true);
233
+ text(finish[0], 'to flute', true);
234
+ study.notes = [...notes, ...finish];
235
+ }
236
+ else if (kind === 'meter') {
237
+ const sys = row(12);
238
+ const upper = Array.from({ length: 6 }, (_, i) => note([['c/5', 'b/4', 'a/4'][i % 3]]));
239
+ const lower = Array.from({ length: 6 }, (_, i) => note([['c/3', 'g/3'][i % 2]], 'q', { clef: 'bass' }));
240
+ const top = sys
241
+ .addStave({ voices: [voice(upper)] })
242
+ .addClef('treble')
243
+ .addTimeSignature('3/4');
244
+ const bottom = sys
245
+ .addStave({ voices: [voice(lower)] })
246
+ .addClef('bass')
247
+ .addTimeSignature('2/4');
248
+ study.bars = [
249
+ [top, upper, 3],
250
+ [bottom, lower, 2],
251
+ [bottom, lower, 4],
252
+ ].map(([staff, notes, index]) => {
253
+ const bar = new VF.Barline(VF.Barline.type.SINGLE).setStave(staff);
254
+ return { bar, before: notes[index - 1], after: notes[index] };
255
+ });
256
+ const free = row(254);
257
+ const cadenza = score.notes('G4/8,A4/8,C5/8,D5/8,E5/q', { stem: 'up' });
258
+ f.Beam({ notes: cadenza.slice(0, 4) });
259
+ const upperFree = voice(cadenza);
260
+ free.addStave({ voices: [upperFree] }).addClef('treble');
261
+ text(cadenza[0], 'Cadenza', true);
262
+ const short = [note(['c/3'], 'h', { clef: 'bass' }), f.GhostNote({ duration: 'q' })];
263
+ const lowerFree = voice(short);
264
+ free.addStave({ voices: [lowerFree] }).addClef('bass');
265
+ study.freeVoices = [upperFree, lowerFree];
266
+ study.notes = [...upper, ...lower];
267
+ }
268
+ f.draw();
269
+ for (const { bar, before, after } of (_f = study.bars) !== null && _f !== void 0 ? _f : []) {
270
+ bar.setX((before.getAbsoluteX() + after.getAbsoluteX()) / 2).draw();
271
+ }
272
+ return study;
273
+ }
@@ -0,0 +1,63 @@
1
+ export function makePhraseStudy(VF, f, kind, width = 615) {
2
+ var _a;
3
+ const score = f.EasyScore();
4
+ const system = f.System({ width, y: 45, spaceBetweenStaves: 7 });
5
+ const layout = (_a = system.getPhraseLayout) === null || _a === void 0 ? void 0 : _a.call(system);
6
+ const soft = (notes) => score.voice(notes, { mode: 'soft' });
7
+ if (kind === 'choir') {
8
+ const notes = score.notes('G4/q, A4/8, B4/8, C5/q, B4/q, A4/h', { stem: 'up' });
9
+ const lower = score.notes('E4/h, F4/q, G4/q, E4/h', { stem: 'down' });
10
+ const staff = system.addStave({ voices: [soft(notes)] }).addClef('treble');
11
+ const bass = system.addStave({ voices: [soft(lower)] }).addClef('treble');
12
+ f.Beam({ notes: notes.slice(1, 3) });
13
+ const verses = [
14
+ [
15
+ { note: notes[0], text: 'Sum', hyphenAfter: true },
16
+ { note: notes[2], text: 'mer', extendTo: notes[3] },
17
+ { note: notes[4], text: 'is' },
18
+ { note: notes[5], text: 'here' },
19
+ ],
20
+ [
21
+ { note: notes[0], text: 'É', hyphenAfter: true },
22
+ { note: notes[1], text: 'cou', hyphenAfter: true },
23
+ { note: notes[3], text: 'tez', extendTo: notes[4] },
24
+ { note: notes[5], text: 'bien' },
25
+ ],
26
+ ];
27
+ const lyrics = verses.map((syllables) => layout
28
+ ? layout.addVerse(staff, syllables)
29
+ : syllables.map((s) => {
30
+ const mark = f.Annotation({ text: s.text });
31
+ s.note.addModifier(mark, 0);
32
+ return mark;
33
+ }));
34
+ return { system, layout, notes, lower, staff, bass, lyrics };
35
+ }
36
+ const notes = score.notes('G4/q, C5/q, B4/q, A4/q, G4/q', { stem: 'down' });
37
+ const lower = score.notes('C3/h, E3/h, G3/q', { clef: 'bass', stem: 'up' });
38
+ const staff = system.addStave({ voices: [soft(notes)] }).addClef('treble');
39
+ const bass = system.addStave({ voices: [soft(lower)] }).addClef('bass');
40
+ const slur = f.Curve({ from: notes[0], to: notes[4], options: { openingDirection: 'down' } });
41
+ const accent = f.Articulation({ type: 'a>', position: 'above' });
42
+ notes[1].addModifier(accent, 0);
43
+ const dot = f.Articulation({ type: 'a.', position: 'above' });
44
+ notes[2].addModifier(dot, 0);
45
+ const dynamics = [
46
+ ['dynamicPiano', 0],
47
+ ['dynamicForte', 4],
48
+ ].map(([glyph, i]) => {
49
+ const mark = f.Annotation({ text: VF.Glyphs[glyph] }).setFont(notes[i].fontInfo);
50
+ notes[i].addModifier(mark, 0);
51
+ return mark;
52
+ });
53
+ const hairpin = f.StaveHairpin({ from: notes[0], to: notes[4], type: VF.StaveHairpin.type.CRESC });
54
+ const pedal = f.PedalMarking({ notes: [lower[0], lower[2]], options: { style: 'bracket' } });
55
+ const octave = f.TextBracket({
56
+ from: notes[0],
57
+ to: notes[3],
58
+ text: '8',
59
+ options: { superscript: 'va', position: 'top' },
60
+ });
61
+ layout === null || layout === void 0 ? void 0 : layout.route(slur).addLane(staff, [...dynamics, hairpin]).addLane(bass, [pedal]).addLane(staff, [octave], { side: 'above' });
62
+ return { system, layout, notes, lower, staff, bass, slur, dynamics, hairpin, pedal, octave };
63
+ }
@@ -0,0 +1,87 @@
1
+ export function publicationStudy(part, paper) {
2
+ const count = 26;
3
+ const melody = [
4
+ ['g/4', 'b/4', 'd/5'],
5
+ ['e/5', 'd/5', 'b/4'],
6
+ ['a/4', 'c/5', 'b/4'],
7
+ ['g/4', 'a/4', 'd/5'],
8
+ ['d/5', 'c/5', 'a/4'],
9
+ ['b/4', 'a/4', 'g/4'],
10
+ ['e/4', 'g/4', 'a/4'],
11
+ ['d/5', 'b/4', 'g/4'],
12
+ ];
13
+ const bass = ['g/2', 'e/3', 'a/2', 'd/3', 'b/2', 'g/2', 'c/3', 'd/3'];
14
+ const middle = ['b/3', 'g/3', 'e/4', 'a/3', 'd/4', 'b/3', 'c/4', 'a/3'];
15
+ const make = (id, name, shortName, clef) => ({
16
+ id,
17
+ name,
18
+ shortName,
19
+ clef,
20
+ key: 'G',
21
+ time: '3/4',
22
+ measures: Array.from({ length: count }, (_, i) => {
23
+ let keys, ds;
24
+ if (id === 'fl') {
25
+ keys = melody[i % melody.length];
26
+ ds = i % 3 === 0 ? ['q', '8', '8', 'q'] : ['q', 'q', 'q'];
27
+ }
28
+ else if (id === 'va') {
29
+ keys = [middle[i % 8], middle[(i + 2) % 8]];
30
+ ds = ['h', 'q'];
31
+ }
32
+ else {
33
+ keys = [bass[i % 8], bass[(i + 3) % 8]];
34
+ ds = i === 15 || i === 17 ? ['hr', 'qr'] : i % 3 === 0 ? ['q', '8', '8', 'q'] : ['h', 'q'];
35
+ }
36
+ if (i === count - 1) {
37
+ keys = [id === 'fl' ? 'g/4' : id === 'va' ? 'b/3' : 'g/2'];
38
+ ds = ['h', 'q'];
39
+ }
40
+ return {
41
+ voices: [
42
+ {
43
+ autoBeam: true,
44
+ notes: ds.map((d, j) => ({
45
+ id: id + '-' + (i + 1) + '-' + (j + 1),
46
+ note: { keys: [keys[j % keys.length]], duration: d },
47
+ })),
48
+ },
49
+ ],
50
+ };
51
+ }),
52
+ });
53
+ const source = {
54
+ staves: [
55
+ make('fl', 'Flute', 'Fl.', 'treble'),
56
+ make('va', 'Viola', 'Va.', 'alto'),
57
+ make('vc', 'Violoncello', 'Vc.', 'bass'),
58
+ ],
59
+ accidentals: 'key-aware',
60
+ continuous: {
61
+ measureNumbers: true,
62
+ spans: [
63
+ { id: 'opening', kind: 'slur', from: 'fl-1-1', to: 'fl-2-3', side: 'above' },
64
+ { id: 'cello-swell', kind: 'crescendo', from: 'vc-9-1', to: 'vc-12-2' },
65
+ ],
66
+ boundaries: [
67
+ { measure: 9, rehearsal: 'B' },
68
+ { measure: 19, rehearsal: 'C' },
69
+ ],
70
+ groups: [{ first: 'fl', last: 'vc', type: 'bracket' }],
71
+ },
72
+ };
73
+ const options = Object.assign({ paper, title: 'Andante in G', subtitle: part ? 'Violoncello' : 'Flute, viola and violoncello', header: part ? 'Andante in G · Violoncello' : 'Andante in G · Score', footer: 'Andante in G', staffSize: part ? 7.2 : 7.8, systemGap: part ? 6 : 7, maxExtraGap: 8, systemBreaks: part
74
+ ? [3, 6, 9, 12, 14, 17, 19, 21, 23, 25]
75
+ : Array.from({ length: count }, (_, i) => i + 1).filter((n) => n > 1 && (n - 1) % 4 === 0) }, (part
76
+ ? {
77
+ staves: ['vc'],
78
+ preferredTurns: [16],
79
+ forbiddenTurns: [13],
80
+ regions: [
81
+ { kind: 'cue', staff: 'fl', measure: 16, label: 'Flute cue' },
82
+ { kind: 'ossia', staff: 'va', measure: 21, label: 'Ossia · viola' },
83
+ ],
84
+ }
85
+ : {}));
86
+ return { source, options };
87
+ }
@@ -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
+ }