vexflow 5.3.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 (115) 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 +4189 -772
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +4323 -906
  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/alternatingtremolo.js +68 -0
  13. package/build/esm/src/annotation.js +19 -3
  14. package/build/esm/src/articulation.js +5 -1
  15. package/build/esm/src/beam.js +13 -0
  16. package/build/esm/src/bend.js +57 -6
  17. package/build/esm/src/clef.js +3 -0
  18. package/build/esm/src/continuouslayout.js +681 -0
  19. package/build/esm/src/continuousspan.js +159 -0
  20. package/build/esm/src/curve.js +21 -2
  21. package/build/esm/src/easyscore/composition.js +13 -2
  22. package/build/esm/src/easyscore/policies.js +6 -3
  23. package/build/esm/src/engravinggeometry.js +8 -1
  24. package/build/esm/src/factory.js +16 -4
  25. package/build/esm/src/font.js +9 -1
  26. package/build/esm/src/fretdiagram.js +77 -0
  27. package/build/esm/src/guitargesture.js +33 -0
  28. package/build/esm/src/guitarmodifiers.js +26 -0
  29. package/build/esm/src/index.js +8 -0
  30. package/build/esm/src/instrumentprofile.js +123 -0
  31. package/build/esm/src/keysignature.js +23 -1
  32. package/build/esm/src/notationspelling.js +73 -0
  33. package/build/esm/src/note.js +3 -0
  34. package/build/esm/src/ornament.js +5 -0
  35. package/build/esm/src/pagebreaks.js +58 -0
  36. package/build/esm/src/pedalmarking.js +39 -17
  37. package/build/esm/src/phraselayout.js +503 -0
  38. package/build/esm/src/phraseribbon.js +28 -0
  39. package/build/esm/src/publication.js +402 -0
  40. package/build/esm/src/publicationview.js +114 -0
  41. package/build/esm/src/scorenavigation.js +172 -0
  42. package/build/esm/src/sheet.js +14 -2
  43. package/build/esm/src/stave.js +33 -16
  44. package/build/esm/src/stavebarline.js +5 -7
  45. package/build/esm/src/staveconnector.js +1 -0
  46. package/build/esm/src/stavehairpin.js +53 -27
  47. package/build/esm/src/stavenote.js +6 -1
  48. package/build/esm/src/stavetie.js +27 -2
  49. package/build/esm/src/strokes.js +4 -0
  50. package/build/esm/src/system.js +19 -4
  51. package/build/esm/src/systembreaks.js +42 -0
  52. package/build/esm/src/tabnote.js +6 -1
  53. package/build/esm/src/textbracket.js +24 -5
  54. package/build/esm/src/timesignature.js +15 -6
  55. package/build/esm/src/tuplet.js +1 -0
  56. package/build/esm/src/version.js +3 -3
  57. package/build/esm/src/vexflow.js +16 -0
  58. package/build/esm/src/voice.js +7 -3
  59. package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
  60. package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
  61. package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
  62. package/build/esm/tests/engraving/publication-studies.mjs +87 -0
  63. package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
  64. package/build/esm/tests/engraving/studies.mjs +88 -0
  65. package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
  66. package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
  67. package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
  68. package/build/esm/tests/node/publication-tests.mjs +219 -0
  69. package/build/esm/tools/easyscore-structure.mjs +1 -1
  70. package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
  71. package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
  72. package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
  73. package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
  74. package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
  75. package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
  76. package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
  77. package/build/types/src/alternatingtremolo.d.ts +13 -0
  78. package/build/types/src/annotation.d.ts +9 -0
  79. package/build/types/src/articulation.d.ts +3 -0
  80. package/build/types/src/beam.d.ts +2 -0
  81. package/build/types/src/bend.d.ts +8 -0
  82. package/build/types/src/clef.d.ts +3 -0
  83. package/build/types/src/continuouslayout.d.ts +103 -0
  84. package/build/types/src/continuousspan.d.ts +60 -0
  85. package/build/types/src/curve.d.ts +11 -0
  86. package/build/types/src/easyscore/composition.d.ts +8 -0
  87. package/build/types/src/easyscore/policies.d.ts +1 -1
  88. package/build/types/src/fretdiagram.d.ts +23 -0
  89. package/build/types/src/guitargesture.d.ts +26 -0
  90. package/build/types/src/guitarmodifiers.d.ts +3 -0
  91. package/build/types/src/index.d.ts +10 -0
  92. package/build/types/src/instrumentprofile.d.ts +124 -0
  93. package/build/types/src/keysignature.d.ts +9 -0
  94. package/build/types/src/notationspelling.d.ts +25 -0
  95. package/build/types/src/note.d.ts +15 -0
  96. package/build/types/src/ornament.d.ts +3 -1
  97. package/build/types/src/pagebreaks.d.ts +26 -0
  98. package/build/types/src/pedalmarking.d.ts +9 -0
  99. package/build/types/src/phraselayout.d.ts +87 -0
  100. package/build/types/src/phraseribbon.d.ts +7 -0
  101. package/build/types/src/publication.d.ts +61 -0
  102. package/build/types/src/publicationview.d.ts +27 -0
  103. package/build/types/src/scorenavigation.d.ts +33 -0
  104. package/build/types/src/sheet.d.ts +5 -0
  105. package/build/types/src/stave.d.ts +13 -0
  106. package/build/types/src/stavehairpin.d.ts +18 -0
  107. package/build/types/src/stavetie.d.ts +5 -0
  108. package/build/types/src/system.d.ts +8 -1
  109. package/build/types/src/systembreaks.d.ts +9 -0
  110. package/build/types/src/textbracket.d.ts +7 -0
  111. package/build/types/src/timesignature.d.ts +4 -0
  112. package/build/types/src/vexflow.d.ts +16 -0
  113. package/build/types/src/voice.d.ts +2 -0
  114. package/changelog/CHANGELOG.md +8 -0
  115. package/package.json +9 -2
@@ -0,0 +1,159 @@
1
+ import { Element } from './element.js';
2
+ import { Glyphs } from './glyphs.js';
3
+ import { ribbonParts } from './phraseribbon.js';
4
+ import { Tables } from './tables.js';
5
+ export function spanLabel(spec) {
6
+ var _a, _b;
7
+ const text = (_b = (_a = spec.text) !== null && _a !== void 0 ? _a : (spec.kind === 'palmMute' ? 'P.M. ' + spec.strings.join(',') : undefined)) !== null && _b !== void 0 ? _b : { volta: '1.', ottava: '8va', trill: Glyphs.ornamentTrill, tuplet: '3' }[spec.kind];
8
+ if (!text)
9
+ return;
10
+ return new Element(spec.kind === 'trill' ? 'Ornament' : 'Annotation').setText(text);
11
+ }
12
+ export function spanAbove(span) {
13
+ return span.side ? span.side === 'above' : ['slur', 'volta', 'ottava', 'trill', 'tuplet'].includes(span.kind);
14
+ }
15
+ export function continuationPitch(anchor, stave, index = 0) {
16
+ const source = anchor.note.checkStave(), key = anchor.note.getKeys()[index];
17
+ const offset = (anchor.note.getYs()[index] - source.getYForLine(0)) / source.space(1);
18
+ const clefShift = Tables.keyProperties(key, source.getClef()).line - Tables.keyProperties(key, stave.getClef()).line;
19
+ return stave.getYForLine(0) + stave.space(offset + clefShift);
20
+ }
21
+ function controls(f) {
22
+ var _a;
23
+ const lift = (f.above ? -1 : 1) * ((_a = f.rise) !== null && _a !== void 0 ? _a : Math.min(f.space * (f.kind === 'tie' ? 0.85 : 1.5), (f.x2 - f.x1) * 0.18));
24
+ return {
25
+ dx: (f.x2 - f.x1) / 3,
26
+ a: f.y1 + lift * (f.part === 'first' || f.part === 'single' ? 1 : 0.35),
27
+ b: f.y2 + lift * (f.part === 'last' || f.part === 'single' ? 1 : 0.35),
28
+ };
29
+ }
30
+ export function fitSpan(f, obstacles) {
31
+ const thickness = (f.above ? -1 : 1) * f.space * 0.22;
32
+ const initial = Math.min(f.space * (f.kind === 'tie' ? 0.85 : 1.5), (f.x2 - f.x1) * 0.18);
33
+ let best = initial, cost = Infinity;
34
+ for (let step = 0; step <= (f.kind === 'tie' ? 6 : 20); step++) {
35
+ f.rise = initial + step * f.space * 0.4;
36
+ const { dx, a, b } = controls(f);
37
+ const left = { x: f.x1, y: f.y1 }, right = { x: f.x2, y: f.y2 };
38
+ const cps = f.kind === 'tie'
39
+ ? [{ x: (f.x1 + f.x2) / 2, y: (a + b) / 2 }]
40
+ : [
41
+ { x: f.x1 + dx, y: a },
42
+ { x: f.x2 - dx, y: b },
43
+ ];
44
+ const parts = ribbonParts([left, ...cps, right], [left, ...cps.map((p) => (Object.assign(Object.assign({}, p), { y: p.y + thickness }))), right], f.space * 0.15);
45
+ const hits = parts.filter((p) => obstacles.some((o) => p.x < o.x + o.w && o.x < p.x + p.w && p.y < o.y + o.h && o.y < p.y + p.h)).length;
46
+ if (hits < cost) {
47
+ best = f.rise;
48
+ cost = hits;
49
+ }
50
+ if (!hits)
51
+ break;
52
+ }
53
+ f.rise = best;
54
+ return cost === 0;
55
+ }
56
+ export function drawSpan(ctx, f, label) {
57
+ const { kind, space, x1, x2, y1, y2, above } = f;
58
+ const start = f.part === 'single' || f.part === 'first', end = f.part === 'single' || f.part === 'last';
59
+ const sign = above ? -1 : 1;
60
+ const line = (a, b, c, d) => {
61
+ ctx.beginPath();
62
+ ctx.moveTo(a, b);
63
+ ctx.lineTo(c, d);
64
+ ctx.stroke();
65
+ };
66
+ ctx.save();
67
+ try {
68
+ if (kind === 'slur' || kind === 'tie') {
69
+ const { dx, a, b } = controls(f);
70
+ ctx.beginPath();
71
+ ctx.moveTo(x1, y1);
72
+ if (kind === 'tie') {
73
+ const x = (x1 + x2) / 2, y = (a + b) / 2;
74
+ ctx.quadraticCurveTo(x, y, x2, y2);
75
+ ctx.quadraticCurveTo(x, y + sign * space * 0.22, x1, y1);
76
+ }
77
+ else {
78
+ ctx.bezierCurveTo(x1 + dx, a, x2 - dx, b, x2, y2);
79
+ ctx.bezierCurveTo(x2 - dx, b + sign * space * 0.22, x1 + dx, a + sign * space * 0.22, x1, y1);
80
+ }
81
+ ctx.closePath();
82
+ ctx.fill();
83
+ return;
84
+ }
85
+ if (kind === 'crescendo' || kind === 'diminuendo') {
86
+ const [left, right] = f.progress.map((t) => space * 0.55 * (kind === 'crescendo' ? t : 1 - t));
87
+ line(x1, y1 - left, x2, y2 - right);
88
+ line(x1, y1 + left, x2, y2 + right);
89
+ return;
90
+ }
91
+ if (kind === 'tuplet') {
92
+ const mid = (x1 + x2) / 2, width = start && label ? label.getWidth() : 0, y = y1 + sign * space * 0.5;
93
+ if (start && label)
94
+ label.renderText(ctx, mid - width / 2, y1);
95
+ if (width) {
96
+ line(x1, y, mid - width / 2 - 2, y);
97
+ line(mid + width / 2 + 2, y, x2, y);
98
+ }
99
+ else
100
+ line(x1, y, x2, y);
101
+ if (start)
102
+ line(x1, y, x1, y - sign * space * 0.65);
103
+ if (end)
104
+ line(x2, y, x2, y - sign * space * 0.65);
105
+ return;
106
+ }
107
+ const hasLabel = label && start;
108
+ if (hasLabel)
109
+ label.renderText(ctx, x1, y1);
110
+ const left = hasLabel ? x1 + label.getWidth() + space * 0.35 : x1;
111
+ if (kind === 'hyphen') {
112
+ if (x2 - left >= space * 0.5) {
113
+ const mid = (left + x2) / 2;
114
+ line(mid - space * 0.25, y1 - space * 0.35, mid + space * 0.25, y1 - space * 0.35);
115
+ }
116
+ return;
117
+ }
118
+ if (kind === 'lyric') {
119
+ if (x2 > left)
120
+ line(left, y1 + 1, x2, y2 + 1);
121
+ return;
122
+ }
123
+ if (kind === 'trill') {
124
+ const period = space * 0.65;
125
+ ctx.beginPath();
126
+ ctx.moveTo(left, y1 - 3);
127
+ for (let x = left; x < x2;) {
128
+ const stop = Math.min(x + period, x2), d = stop - x;
129
+ ctx.bezierCurveTo(x + d / 3, y1 - space * 0.8, x + (2 * d) / 3, y1 + space * 0.2, stop, y1 - 3);
130
+ x = stop;
131
+ }
132
+ ctx.stroke();
133
+ return;
134
+ }
135
+ if (kind === 'ottava' || kind === 'palmMute')
136
+ ctx.setLineDash([space * 0.45, space * 0.35]);
137
+ const y = kind === 'ottava' ? y1 - space * 0.5 : kind === 'volta' ? y1 - space * 1.35 : y1;
138
+ if (x2 > left)
139
+ line(kind === 'volta' ? x1 : left, y, x2, y);
140
+ ctx.setLineDash([]);
141
+ if (kind === 'pedal') {
142
+ if (start)
143
+ line(x1, y, x1, y - space * 0.8);
144
+ if (end)
145
+ line(x2, y, x2, y - space * 0.8);
146
+ }
147
+ else if (kind === 'volta') {
148
+ if (start)
149
+ line(x1, y, x1, y + space * 0.65);
150
+ if (end)
151
+ line(x2, y, x2, y + space * 0.65);
152
+ }
153
+ else if ((kind === 'ottava' || kind === 'palmMute') && end)
154
+ line(x2, y, x2, y - sign * space * 0.6);
155
+ }
156
+ finally {
157
+ ctx.restore();
158
+ }
159
+ }
@@ -1,5 +1,6 @@
1
1
  import { BoundingBox } from './boundingbox.js';
2
2
  import { Element } from './element.js';
3
+ import { ribbonParts } from './phraseribbon.js';
3
4
  import { RuntimeError } from './util.js';
4
5
  function bezierExtrema(p0, p1, p2, p3) {
5
6
  const values = [p0, p3];
@@ -46,12 +47,29 @@ export class Curve extends Element {
46
47
  }
47
48
  constructor(from, to, options) {
48
49
  super();
50
+ this.layoutRise = 0;
49
51
  this.renderOptions = Object.assign({ thickness: 2, xShift: 0, yShift: 10, position: 'auto', positionEnd: 'auto', invert: false, cps: [
50
52
  { x: 0, y: 10 },
51
53
  { x: 0, y: 10 },
52
54
  ], openingDirection: 'auto' }, options);
55
+ this.authoredControls = (options === null || options === void 0 ? void 0 : options.cps) !== undefined;
53
56
  this.setNotes(from, to);
54
57
  }
58
+ setLayoutRise(rise) {
59
+ this.layoutRise = rise;
60
+ }
61
+ hasManualControls() {
62
+ return this.authoredControls || this.renderOptions.cps.some((p) => p.x !== 0 || p.y !== 10);
63
+ }
64
+ getNotes() {
65
+ return { firstNote: this.from, lastNote: this.to };
66
+ }
67
+ getRouteParts() {
68
+ var _a, _b;
69
+ const { first, last, cps, thicknessCps } = this.getBezierPoints(this.getRenderParams());
70
+ const outer = [first, ...cps, last];
71
+ return ribbonParts(outer, ((_a = this.style) === null || _a === void 0 ? void 0 : _a.lineDash) ? outer : [first, ...thicknessCps.reverse(), last], ((_b = this.getStyle().lineWidth) !== null && _b !== void 0 ? _b : 1) / 2);
72
+ }
55
73
  setNotes(from, to) {
56
74
  if (!from && !to) {
57
75
  throw new RuntimeError('BadArguments', 'Curve needs to have either `from` or `to` set.');
@@ -72,8 +90,9 @@ export class Curve extends Element {
72
90
  const lastY = params.lastY + yShift;
73
91
  const thickness = this.renderOptions.thickness;
74
92
  const cps = this.renderOptions.cps;
75
- const { x: cp0x, y: cp0y } = cps[0];
76
- const { x: cp1x, y: cp1y } = cps[1];
93
+ const { x: cp0x, y: y0 } = cps[0];
94
+ const { x: cp1x, y: y1 } = cps[1];
95
+ const cp0y = y0 + this.layoutRise, cp1y = y1 + this.layoutRise;
77
96
  const controlPointSpacing = (lastX - firstX) / (cps.length + 2);
78
97
  return {
79
98
  first: { x: firstX, y: firstY },
@@ -9,6 +9,7 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
+ import { ContinuousLayout } from '../continuouslayout.js';
12
13
  import { Factory } from '../factory.js';
13
14
  import { Fraction } from '../fraction.js';
14
15
  import { Modifier } from '../modifier.js';
@@ -273,7 +274,7 @@ export function compose(score, spec) {
273
274
  getElement: (id) => score.getElement(id),
274
275
  getNote: (id) => score.getNote(id),
275
276
  };
276
- if (spec.signatures !== 'every-measure')
277
+ if (!spec.continuous && spec.signatures !== 'every-measure')
277
278
  result.diagnostics.push({
278
279
  code: 'SignaturePolicy',
279
280
  message: 'Signatures appear at the first measure and explicit changes. Sheet does not repeat them at wrapped row starts.',
@@ -286,8 +287,15 @@ export function compose(score, spec) {
286
287
  time: (_c = stave.time) !== null && _c !== void 0 ? _c : '4/4',
287
288
  });
288
289
  });
290
+ const starts = [], ends = [];
291
+ const placed = spec.continuous ? new Set() : undefined;
289
292
  const noteMeasures = new Map();
290
293
  for (let index = 0; index < count; index++) {
294
+ starts.push(spec.staves.map((staff, j) => {
295
+ var _a, _b, _c;
296
+ const m = staff.measures[index], p = states[j];
297
+ return { clef: (_a = m.clef) !== null && _a !== void 0 ? _a : p.clef, key: (_b = m.key) !== null && _b !== void 0 ? _b : p.key, time: (_c = m.time) !== null && _c !== void 0 ? _c : p.time };
298
+ }));
291
299
  const system = result.sheet.addSystem(spec.system);
292
300
  result.systems.push(system);
293
301
  const parts = spec.staves.map((staff, staffIndex) => {
@@ -311,13 +319,16 @@ export function compose(score, spec) {
311
319
  });
312
320
  if (spec.accidentals === 'key-aware') {
313
321
  const generated = new Set(policies.flatMap((policy) => [...policy.generated]));
314
- policies.forEach((policy, staffIndex) => applyCompositionAccidentals(score, voices.flat(), policy.key, policy.changes, generated, staves[staffIndex], spec.graceAccidentals === 'ordered'));
322
+ policies.forEach((policy, staffIndex) => applyCompositionAccidentals(score, voices.flat(), policy.key, policy.changes, generated, staves[staffIndex], spec.graceAccidentals === 'ordered', placed));
315
323
  }
324
+ ends.push(states.slice());
316
325
  result.staves.push(staves);
317
326
  result.voices.push(voices);
318
327
  result.notes.push(notes);
319
328
  }
320
329
  result.spans = buildSpans(score, spec, noteMeasures, result.diagnostics);
330
+ if (spec.continuous)
331
+ result.sheet.setContinuousLayout(new ContinuousLayout(result, spec, starts, ends, placed));
321
332
  return result;
322
333
  });
323
334
  }
@@ -25,7 +25,7 @@ function orderedAttacks(hosts, includeGrace) {
25
25
  }
26
26
  return [...attacks.entries()].sort(([a], [b]) => a - b).map(([, notes]) => notes);
27
27
  }
28
- export function applyCompositionAccidentals(score, voices, key, changes, generated, stave, includeGrace = false) {
28
+ export function applyCompositionAccidentals(score, voices, key, changes, generated, stave, includeGrace = false, placed) {
29
29
  var _a;
30
30
  const music = new Music();
31
31
  let scale = music.createScaleMap(key);
@@ -84,8 +84,11 @@ export function applyCompositionAccidentals(score, voices, key, changes, generat
84
84
  if (!explicit.includes(mark))
85
85
  note.getModifiers().splice(note.getModifiers().indexOf(mark), 1);
86
86
  }
87
- if (!explicit.length && (previous !== pitch || ((_c = (_b = simultaneous.get(id)) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0) > 1))
88
- score.attach(note, score.make.accidental({ type: accidental }), index);
87
+ if (!explicit.length && (previous !== pitch || ((_c = (_b = simultaneous.get(id)) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0) > 1)) {
88
+ const mark = score.make.accidental({ type: accidental });
89
+ score.attach(note, mark, index);
90
+ placed === null || placed === void 0 ? void 0 : placed.add(mark);
91
+ }
89
92
  const value = explicit.some((mark) => !Music.accidentals.includes(mark.type)) ? 'microtonal' : pitch;
90
93
  const values = (_d = updates.get(id)) !== null && _d !== void 0 ? _d : new Set();
91
94
  values.add(value);
@@ -8,9 +8,12 @@ import { Dot } from './dot.js';
8
8
  import { GraceNote } from './gracenote.js';
9
9
  import { GraceNoteGroup } from './gracenotegroup.js';
10
10
  import { Ornament } from './ornament.js';
11
+ import { PedalMarking } from './pedalmarking.js';
12
+ import { StaveHairpin } from './stavehairpin.js';
11
13
  import { StaveNote } from './stavenote.js';
12
14
  import { StaveTie } from './stavetie.js';
13
15
  import { Stem } from './stem.js';
16
+ import { TextBracket } from './textbracket.js';
14
17
  import { Tuplet } from './tuplet.js';
15
18
  import { RuntimeError } from './util.js';
16
19
  function inflate(box, amount) {
@@ -88,7 +91,11 @@ export function measureEngraving(element, options = {}) {
88
91
  else if (kind === Accidental || kind === Dot) {
89
92
  shape.parts.push(owner.getInkBounds());
90
93
  }
91
- else if (kind === Tuplet || kind === Ornament) {
94
+ else if (kind === Tuplet ||
95
+ kind === Ornament ||
96
+ kind === PedalMarking ||
97
+ kind === StaveHairpin ||
98
+ kind === TextBracket) {
92
99
  shape.parts.push(owner.getBoundingBox());
93
100
  }
94
101
  else if (kind === Beam) {
@@ -682,13 +682,25 @@ export class Factory {
682
682
  if (this.retained)
683
683
  this.renderQ.forEach((element) => element.setRendered(false));
684
684
  try {
685
- this.staves.forEach((s) => s.setContext(ctx).drawWithStyle());
686
- this.voices.forEach((v) => v.setContext(ctx).drawWithStyle());
685
+ const layouts = this.sheets.flatMap((sheet) => { var _a; return (_a = sheet.getContinuousLayout()) !== null && _a !== void 0 ? _a : []; });
686
+ const hidden = new Set(layouts.flatMap((layout) => [...layout.hidden]));
687
+ this.staves.forEach((s) => {
688
+ if (!hidden.has(s))
689
+ s.setContext(ctx).drawWithStyle();
690
+ });
691
+ this.voices.forEach((v) => {
692
+ if (!hidden.has(v))
693
+ v.setContext(ctx).drawWithStyle();
694
+ });
687
695
  this.renderQ.forEach((e) => {
688
- if (!e.isRendered())
696
+ if (!hidden.has(e) && !e.isRendered())
689
697
  e.setContext(ctx).drawWithStyle();
690
698
  });
691
- this.systems.forEach((s) => s.setContext(ctx).drawWithStyle());
699
+ this.systems.forEach((s) => {
700
+ if (!hidden.has(s))
701
+ s.setContext(ctx).drawWithStyle();
702
+ });
703
+ layouts.forEach((layout) => layout.draw(ctx));
692
704
  }
693
705
  finally {
694
706
  ctx.setDefaultStyle(defaults);
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { Metrics } from './metrics.js';
11
11
  import { TextMetricsCache } from './textmetricscache.js';
12
+ import { RuntimeError } from './util.js';
12
13
  export var FontWeight;
13
14
  (function (FontWeight) {
14
15
  FontWeight["NORMAL"] = "normal";
@@ -187,7 +188,14 @@ export class Font {
187
188
  }
188
189
  fontFaceSet === null || fontFaceSet === void 0 ? void 0 : fontFaceSet.add(fontFace);
189
190
  TextMetricsCache.clear();
190
- return fontFaceLoadPromise.finally(() => TextMetricsCache.clear());
191
+ return fontFaceLoadPromise
192
+ .catch((cause) => {
193
+ throw new RuntimeError('FontLoadFailed', 'Could not load font "' +
194
+ fontName +
195
+ '". Check the font file, network response and CORS policy. ' +
196
+ String(cause));
197
+ })
198
+ .finally(() => TextMetricsCache.clear());
191
199
  });
192
200
  }
193
201
  static getURLForFont(fontName) {
@@ -0,0 +1,77 @@
1
+ import { BoundingBox } from './boundingbox.js';
2
+ import { Element } from './element.js';
3
+ import { RuntimeError } from './util.js';
4
+ export class FretDiagram extends Element {
5
+ constructor(spec) {
6
+ var _a, _b;
7
+ super();
8
+ this.frets = [...spec.frets];
9
+ this.first = (_a = spec.firstFret) !== null && _a !== void 0 ? _a : 1;
10
+ this.rows = (_b = spec.rows) !== null && _b !== void 0 ? _b : 4;
11
+ this.barre = spec.barre && Object.assign({}, spec.barre);
12
+ const visible = (n) => Number.isSafeInteger(n) && n >= this.first && n < this.first + this.rows;
13
+ if (this.frets.length < 2 ||
14
+ !Number.isSafeInteger(this.first) ||
15
+ this.first < 1 ||
16
+ !Number.isSafeInteger(this.rows) ||
17
+ this.rows < 1 ||
18
+ this.frets.some((n) => n !== 'x' && n !== 0 && !visible(n)))
19
+ throw new RuntimeError('BadArguments', 'Invalid chord frame or fret outside the displayed range.');
20
+ if (this.barre) {
21
+ const { from, to, fret } = this.barre;
22
+ if (![from, to].every((n) => Number.isSafeInteger(n) && n >= 1 && n <= this.frets.length) ||
23
+ from === to ||
24
+ !visible(fret))
25
+ throw new RuntimeError('BadArguments', 'Barre outside chord frame.');
26
+ }
27
+ }
28
+ getBoundingBox() {
29
+ return new BoundingBox(this.getX(), this.getY(), 28 + (this.frets.length - 1) * 9, 17 + this.rows * 11);
30
+ }
31
+ draw() {
32
+ const ctx = this.checkContext();
33
+ const left = this.getX() + 22, top = this.getY() + 14;
34
+ const right = left + (this.frets.length - 1) * 9;
35
+ const fretY = (fret) => top + (fret - this.first + 0.5) * 11;
36
+ const line = (x1, y1, x2, y2) => {
37
+ ctx.beginPath();
38
+ ctx.moveTo(x1, y1);
39
+ ctx.lineTo(x2, y2);
40
+ ctx.stroke();
41
+ };
42
+ ctx.save();
43
+ const group = ctx.openGroup('fret-diagram', this.getAttribute('id'));
44
+ group === null || group === void 0 ? void 0 : group.setAttribute('aria-label', 'Chord frame, low to high: ' + this.frets.join(', ') + (this.barre ? ', barre at fret ' + this.barre.fret : ''));
45
+ ctx.setFont('sans-serif', 9);
46
+ if (this.first > 1)
47
+ ctx.fillText(String(this.first), this.getX() + 2, top + 9);
48
+ for (let row = 0; row <= this.rows; row++) {
49
+ ctx.setLineWidth(row === 0 && this.first === 1 ? 2.5 : 1);
50
+ line(left, top + row * 11, right, top + row * 11);
51
+ }
52
+ this.frets.forEach((fret, i) => {
53
+ const x = left + i * 9;
54
+ line(x, top, x, top + this.rows * 11);
55
+ if (fret === 'x') {
56
+ line(x - 2.5, top - 8, x + 2.5, top - 3);
57
+ line(x + 2.5, top - 8, x - 2.5, top - 3);
58
+ }
59
+ else {
60
+ ctx.beginPath();
61
+ ctx.arc(x, fret ? fretY(fret) : top - 5.5, fret ? 3 : 2.5, 0, 2 * Math.PI, false);
62
+ if (fret)
63
+ ctx.fill();
64
+ else
65
+ ctx.stroke();
66
+ }
67
+ });
68
+ if (this.barre) {
69
+ const { from, to, fret } = this.barre;
70
+ ctx.setLineWidth(5);
71
+ line(right - (from - 1) * 9, fretY(fret), right - (to - 1) * 9, fretY(fret));
72
+ }
73
+ ctx.closeGroup();
74
+ ctx.restore();
75
+ this.setRendered();
76
+ }
77
+ }
@@ -0,0 +1,33 @@
1
+ import { RuntimeError } from './util.js';
2
+ export function bendAmount(bend) {
3
+ var _a;
4
+ return (_a = bend.label) !== null && _a !== void 0 ? _a : (bend.semitones === 2 ? 'full' : bend.semitones === 1 ? '½' : String(bend.semitones) + ' st');
5
+ }
6
+ export function copyBend(bend) {
7
+ if (!Number.isInteger(bend.string) || bend.string < 1 || !Number.isFinite(bend.semitones) || bend.semitones <= 0)
8
+ throw new RuntimeError('BadArguments', 'A timed bend needs a string and positive semitone amount.');
9
+ let previous = [0, 1];
10
+ for (const end of [bend.rise, ...(bend.hold ? [bend.hold] : []), ...(bend.release ? [bend.release] : [])]) {
11
+ if (!Array.isArray(end) ||
12
+ end.length !== 2 ||
13
+ !end.every(Number.isSafeInteger) ||
14
+ end[1] <= 0 ||
15
+ end[0] <= 0 ||
16
+ end[0] > end[1] ||
17
+ BigInt(end[0]) * BigInt(previous[1]) <= BigInt(previous[0]) * BigInt(end[1]))
18
+ throw new RuntimeError('BadArguments', 'Bend endpoints must increase within the written duration.');
19
+ previous = end;
20
+ }
21
+ return Object.assign(Object.assign({}, bend), { rise: [...bend.rise], hold: bend.hold && [...bend.hold], release: bend.release && [...bend.release] });
22
+ }
23
+ export function strokeIdentity(action) {
24
+ var _a;
25
+ if (!['p', 'i', 'm', 'a', 'e'].includes(action.finger) ||
26
+ !['bass-to-treble', 'treble-to-bass'].includes(action.direction) ||
27
+ !['hand', 'strings'].includes((_a = action.arrows) !== null && _a !== void 0 ? _a : 'strings'))
28
+ throw new RuntimeError('BadArguments', 'Invalid rasgueado finger, direction or arrow convention.');
29
+ const label = [action.roll ? 'Rolled rasgueado' : 'Rasgueado', action.finger, action.direction.replace(/-/g, ' ')];
30
+ if (action.golpe)
31
+ label.push('simultaneous golpe');
32
+ return { kind: 'technique', id: 'rasgueado', label: label.join(', '), stroke: Object.assign({}, action) };
33
+ }
@@ -0,0 +1,26 @@
1
+ import { Annotation } from './annotation.js';
2
+ import { Bend } from './bend.js';
3
+ import { Stroke } from './strokes.js';
4
+ import { isTabNote } from './typeguard.js';
5
+ import { RuntimeError } from './util.js';
6
+ function printedStroke(stroke) {
7
+ const down = (stroke.direction === 'bass-to-treble') !== (stroke.arrows === 'hand');
8
+ if (stroke.roll)
9
+ return down ? Stroke.Type.RASGUEADO_DOWN : Stroke.Type.RASGUEADO_UP;
10
+ return down ? Stroke.Type.BRUSH_DOWN : Stroke.Type.BRUSH_UP;
11
+ }
12
+ export function attachGuitarGestures(note) {
13
+ for (const entry of note.notation) {
14
+ const { stroke, bend } = entry;
15
+ if (stroke) {
16
+ note.addModifier(new Stroke(printedStroke(stroke), { allVoices: false }), 0);
17
+ note.addModifier(new Annotation(stroke.finger + (stroke.golpe ? ' + golpe' : '')).setVerticalJustification(Annotation.VerticalJustify.TOP), 0);
18
+ }
19
+ if (bend && isTabNote(note)) {
20
+ const index = note.getPositions().findIndex((p) => p.str === bend.string);
21
+ if (index < 0)
22
+ throw new RuntimeError('BadArguments', 'The bent string must occur in the chord.');
23
+ note.addModifier(Bend.timed(bend), index);
24
+ }
25
+ }
26
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './accidental.js';
2
+ export * from './alternatingtremolo.js';
2
3
  export * from './annotation.js';
3
4
  export * from './articulation.js';
4
5
  export * from './barnote.js';
@@ -18,6 +19,9 @@ export * from './engravinggeometry.js';
18
19
  export * from './engravingprofile.js';
19
20
  export * from './factory.js';
20
21
  export * from './font.js';
22
+ export * from './fretdiagram.js';
23
+ export * from './instrumentprofile.js';
24
+ export * from './notationspelling.js';
21
25
  export * from './flag.js';
22
26
  export * from './formatter.js';
23
27
  export * from './fraction.js';
@@ -42,10 +46,12 @@ export * from './ornament.js';
42
46
  export * from './parenthesis.js';
43
47
  export * from './parser.js';
44
48
  export * from './pedalmarking.js';
49
+ export * from './phraselayout.js';
45
50
  export * from './registry.js';
46
51
  export * from './rendercontext.js';
47
52
  export * from './renderer.js';
48
53
  export * from './repeatnote.js';
54
+ export * from './scorenavigation.js';
49
55
  export * from './sheet.js';
50
56
  export * from './stave.js';
51
57
  export * from './stavebarline.js';
@@ -83,6 +89,8 @@ export * from './tuning.js';
83
89
  export * from './tuplet.js';
84
90
  export * from './typeguard.js';
85
91
  export * from './util.js';
92
+ export * from './continuouslayout.js';
93
+ export * from './publication.js';
86
94
  export * from './vexflow.js';
87
95
  export * from './vibrato.js';
88
96
  export * from './vibratobracket.js';
@@ -0,0 +1,123 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { Fraction } from './fraction.js';
13
+ import { copyBend, strokeIdentity } from './guitargesture.js';
14
+ import { Tables } from './tables.js';
15
+ import { Tuning } from './tuning.js';
16
+ import { RuntimeError } from './util.js';
17
+ export class PercussionMap {
18
+ constructor(entries = PercussionMap.kit) {
19
+ if (new Set(entries.map((e) => e.id)).size !== entries.length)
20
+ throw new RuntimeError('BadArguments', 'Duplicate percussion ID.');
21
+ this.instruments = entries.map((entry) => {
22
+ if (!entry.id || !entry.label || !Number.isSafeInteger(entry.line * 2))
23
+ throw new RuntimeError('BadArguments', 'Invalid percussion entry.');
24
+ return Object.assign({}, entry);
25
+ });
26
+ }
27
+ note(ids, duration, stem) {
28
+ if (!ids.length)
29
+ throw new RuntimeError('BadArguments', 'A percussion attack needs an instrument.');
30
+ const entries = ids.map((id) => {
31
+ const entry = this.instruments.find((item) => item.id === id);
32
+ if (!entry)
33
+ throw new RuntimeError('BadArguments', 'Unknown percussion instrument: ' + id);
34
+ return entry;
35
+ });
36
+ const keys = entries.map(({ line, head }) => {
37
+ const step = 28 + 2 * line;
38
+ const key = 'cdefgab'[((step % 7) + 7) % 7] + '/' + Math.floor(step / 7);
39
+ const shape = head === 'cross' ? 'X' : head === 'circle-cross' ? 'CX' : head === 'triangle' ? 'TU' : '';
40
+ return shape ? key + '/' + shape : key;
41
+ });
42
+ return {
43
+ keys,
44
+ duration,
45
+ clef: 'percussion',
46
+ stemDirection: (stem !== null && stem !== void 0 ? stem : entries[0].stem) === 'up' ? 1 : -1,
47
+ notation: entries.map(({ id, label }, index) => ({ kind: 'unpitched', id, label, index })),
48
+ };
49
+ }
50
+ }
51
+ PercussionMap.kit = [
52
+ { id: 'kick', label: 'Bass drum', line: 1.5, stem: 'down' },
53
+ { id: 'snare', label: 'Snare drum', line: 3.5, stem: 'up' },
54
+ { id: 'hat', label: 'Closed hi-hat', line: 5.5, head: 'cross', stem: 'up' },
55
+ ];
56
+ export class FrettedInstrument {
57
+ constructor(tuning = 'standard', capo = 0) {
58
+ this.capo = capo;
59
+ if (!Number.isSafeInteger(capo) || capo < 0)
60
+ throw new RuntimeError('BadArguments', 'Invalid capo fret.');
61
+ this.tuning = new Tuning(tuning);
62
+ }
63
+ rasgueado(positions, strokes) {
64
+ if (!strokes.length)
65
+ throw new RuntimeError('BadArguments', 'A rasgueado needs at least one stroke.');
66
+ const clock = new Fraction(0, 1);
67
+ return strokes.map((_a) => {
68
+ var _b;
69
+ var { duration } = _a, stroke = __rest(_a, ["duration"]);
70
+ const event = this.attack(positions, duration);
71
+ const mark = strokeIdentity(stroke);
72
+ const offset = clock.clone().simplify();
73
+ clock.add(Tables.durationToTicks(duration), Tables.RESOLUTION);
74
+ const notation = [...((_b = event.note.notation) !== null && _b !== void 0 ? _b : []), mark];
75
+ return { offset, note: Object.assign(Object.assign({}, event.note), { notation }), tab: Object.assign(Object.assign({}, event.tab), { notation }) };
76
+ });
77
+ }
78
+ bentAttack(positions, duration, spec) {
79
+ var _a;
80
+ const event = this.attack(positions, duration);
81
+ const bend = copyBend(spec);
82
+ const index = positions.findIndex((p) => p.str === bend.string);
83
+ if (index < 0)
84
+ throw new RuntimeError('BadArguments', 'The bent string must occur in the chord.');
85
+ const label = 'String ' +
86
+ bend.string +
87
+ ', bend ' +
88
+ bend.semitones +
89
+ (bend.semitones === 1 ? ' semitone by ' : ' semitones by ') +
90
+ bend.rise.join('/') +
91
+ (bend.hold ? ', hold to ' + bend.hold.join('/') : '') +
92
+ (bend.release ? ', release to pitch by ' + bend.release.join('/') : '');
93
+ const mark = { kind: 'technique', id: 'string-bend', index, label, bend };
94
+ const notation = [...((_a = event.note.notation) !== null && _a !== void 0 ? _a : []), mark];
95
+ return { note: Object.assign(Object.assign({}, event.note), { notation }), tab: Object.assign(Object.assign({}, event.tab), { notation }) };
96
+ }
97
+ attack(positions, duration) {
98
+ if (!positions.length || new Set(positions.map((p) => p.str)).size !== positions.length)
99
+ throw new RuntimeError('BadArguments', 'A fretted attack needs distinct strings.');
100
+ const keys = positions.map((position) => {
101
+ const { str, fret } = position;
102
+ if (fret === 'X') {
103
+ this.tuning.getValueForString(str);
104
+ if (!Number.isSafeInteger(str) || !position.displayKey || !/^[a-g][bn#]*\/\d+$/i.test(position.displayKey))
105
+ throw new RuntimeError('BadArguments', 'A dead string needs a written display pitch.');
106
+ return position.displayKey + '/X';
107
+ }
108
+ if (!Number.isSafeInteger(str) || !Number.isSafeInteger(fret) || fret < 0)
109
+ throw new RuntimeError('BadArguments', 'Invalid string or fret.');
110
+ return this.tuning.getNoteForFret(fret + this.capo, str);
111
+ });
112
+ const notation = positions.map(({ str, fret }, index) => ({
113
+ kind: fret === 'X' ? 'unpitched' : 'tuning',
114
+ id: 'string-' + str,
115
+ label: fret === 'X' ? 'Muted strike on string ' + str : 'String ' + str + ', fret ' + fret + ', capo ' + this.capo,
116
+ index,
117
+ }));
118
+ return {
119
+ note: { keys, duration, notation },
120
+ tab: { positions: positions.map(({ str, fret }) => ({ str, fret })), duration, notation },
121
+ };
122
+ }
123
+ }