vexflow 5.0.0-beta.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/LICENSE +3 -3
  2. package/README.md +32 -50
  3. package/build/cjs/vexflow-bravura.js +2 -2
  4. package/build/cjs/vexflow-bravura.js.map +1 -1
  5. package/build/cjs/vexflow-core.js +2 -2
  6. package/build/cjs/vexflow-core.js.map +1 -1
  7. package/build/cjs/vexflow-debug-with-tests.js +3685 -1386
  8. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  9. package/build/cjs/vexflow-debug.js +2443 -980
  10. package/build/cjs/vexflow-debug.js.map +1 -1
  11. package/build/cjs/vexflow.js +2 -2
  12. package/build/cjs/vexflow.js.map +1 -1
  13. package/build/esm/src/accidental.js +1 -0
  14. package/build/esm/src/annotation.js +31 -8
  15. package/build/esm/src/beam.js +4 -2
  16. package/build/esm/src/chordsymbol.js +3 -1
  17. package/build/esm/src/clef.js +3 -1
  18. package/build/esm/src/curve.js +68 -11
  19. package/build/esm/src/easyscore.js +40 -1
  20. package/build/esm/src/element.js +42 -9
  21. package/build/esm/src/factory.js +46 -9
  22. package/build/esm/src/flag.js +3 -1
  23. package/build/esm/src/font.js +17 -0
  24. package/build/esm/src/formatter.js +34 -36
  25. package/build/esm/src/fraction.js +4 -1
  26. package/build/esm/src/glyphnote.js +3 -1
  27. package/build/esm/src/gracenotegroup.js +18 -1
  28. package/build/esm/src/index.js +2 -0
  29. package/build/esm/src/keysignature.js +3 -1
  30. package/build/esm/src/metrics.js +55 -1
  31. package/build/esm/src/modifiercontext.js +15 -1
  32. package/build/esm/src/note.js +2 -2
  33. package/build/esm/src/notehead.js +3 -1
  34. package/build/esm/src/ornament.js +3 -1
  35. package/build/esm/src/pedalmarking.js +44 -5
  36. package/build/esm/src/registry.js +16 -6
  37. package/build/esm/src/rendercontext.js +10 -0
  38. package/build/esm/src/sheet.js +117 -0
  39. package/build/esm/src/stave.js +13 -8
  40. package/build/esm/src/stavebarline.js +53 -1
  41. package/build/esm/src/staveline.js +2 -0
  42. package/build/esm/src/stavenote.js +54 -19
  43. package/build/esm/src/stavetie.js +3 -1
  44. package/build/esm/src/stem.js +2 -1
  45. package/build/esm/src/stemmablenote.js +9 -0
  46. package/build/esm/src/stringnumber.js +0 -1
  47. package/build/esm/src/strokes.js +10 -0
  48. package/build/esm/src/svgcontext.js +14 -4
  49. package/build/esm/src/svgexport.js +68 -0
  50. package/build/esm/src/system.js +14 -0
  51. package/build/esm/src/tables.js +69 -37
  52. package/build/esm/src/tabnote.js +20 -1
  53. package/build/esm/src/textbracket.js +5 -4
  54. package/build/esm/src/textdynamics.js +5 -0
  55. package/build/esm/src/textnote.js +3 -3
  56. package/build/esm/src/tickable.js +56 -22
  57. package/build/esm/src/timesignature.js +30 -9
  58. package/build/esm/src/timesignote.js +3 -1
  59. package/build/esm/src/tuning.js +2 -2
  60. package/build/esm/src/tuplet.js +79 -29
  61. package/build/esm/src/util.js +1 -0
  62. package/build/esm/src/version.js +3 -3
  63. package/build/esm/src/vexflow.js +14 -2
  64. package/build/esm/src/voice.js +44 -8
  65. package/build/esm/tests/accidental_tests.js +52 -0
  66. package/build/esm/tests/annotation_tests.js +38 -0
  67. package/build/esm/tests/articulation_tests.js +34 -0
  68. package/build/esm/tests/beam_tests.js +17 -0
  69. package/build/esm/tests/curve_tests.js +81 -0
  70. package/build/esm/tests/font_tests.js +32 -1
  71. package/build/esm/tests/formatter_tests.js +58 -23
  72. package/build/esm/tests/gracenote_tests.js +58 -0
  73. package/build/esm/tests/gracetabnote_tests.js +40 -0
  74. package/build/esm/tests/keysignature_tests.js +14 -3
  75. package/build/esm/tests/node/package-input-tests.mjs +149 -0
  76. package/build/esm/tests/node/render-metrics-tests.mjs +78 -0
  77. package/build/esm/tests/node/rendering-tests.mjs +75 -0
  78. package/build/esm/tests/node/sheet-tests.mjs +202 -0
  79. package/build/esm/tests/node/svg-export-tests.mjs +182 -0
  80. package/build/esm/tests/pedalmarking_tests.js +25 -0
  81. package/build/esm/tests/rests_tests.js +6 -0
  82. package/build/esm/tests/stave_tests.js +6 -3
  83. package/build/esm/tests/stavenote_tests.js +100 -55
  84. package/build/esm/tests/strokes_tests.js +19 -5
  85. package/build/esm/tests/timesignature_tests.js +19 -0
  86. package/build/esm/tests/tuplet_tests.js +273 -12
  87. package/build/esm/tests/unison_tests.js +13 -13
  88. package/build/esm/tests/voice_tests.js +34 -0
  89. package/build/esm/tools/render-metrics.mjs +49 -0
  90. package/build/esm/tools/score-fixtures.mjs +94 -0
  91. package/build/esm/tools/sheet-fixture.mjs +90 -0
  92. package/build/esm/tools/visual-regression.mjs +106 -0
  93. package/build/types/src/annotation.d.ts +17 -1
  94. package/build/types/src/curve.d.ts +24 -7
  95. package/build/types/src/easyscore.d.ts +8 -0
  96. package/build/types/src/element.d.ts +5 -0
  97. package/build/types/src/factory.d.ts +18 -1
  98. package/build/types/src/font.d.ts +2 -0
  99. package/build/types/src/formatter.d.ts +23 -14
  100. package/build/types/src/gracenotegroup.d.ts +5 -0
  101. package/build/types/src/index.d.ts +2 -0
  102. package/build/types/src/metrics.d.ts +2 -0
  103. package/build/types/src/modifiercontext.d.ts +4 -0
  104. package/build/types/src/pedalmarking.d.ts +4 -1
  105. package/build/types/src/registry.d.ts +2 -0
  106. package/build/types/src/rendercontext.d.ts +12 -0
  107. package/build/types/src/sheet.d.ts +49 -0
  108. package/build/types/src/stave.d.ts +4 -4
  109. package/build/types/src/stavebarline.d.ts +10 -0
  110. package/build/types/src/stavenote.d.ts +11 -0
  111. package/build/types/src/strokes.d.ts +4 -0
  112. package/build/types/src/svgcontext.d.ts +5 -0
  113. package/build/types/src/svgexport.d.ts +22 -0
  114. package/build/types/src/system.d.ts +4 -0
  115. package/build/types/src/tables.d.ts +9 -0
  116. package/build/types/src/tabnote.d.ts +4 -0
  117. package/build/types/src/textbracket.d.ts +1 -1
  118. package/build/types/src/textdynamics.d.ts +3 -0
  119. package/build/types/src/tickable.d.ts +27 -10
  120. package/build/types/src/timesignature.d.ts +4 -0
  121. package/build/types/src/tuplet.d.ts +8 -0
  122. package/build/types/src/util.d.ts +1 -0
  123. package/build/types/src/vexflow.d.ts +8 -1
  124. package/build/types/src/voice.d.ts +6 -0
  125. package/changelog/CHANGELOG.md +94 -0
  126. package/package.json +42 -26
  127. package/tests/flow.html +15 -7
@@ -3,6 +3,8 @@ import { Glyphs } from './glyphs.js';
3
3
  import { RuntimeError } from './util.js';
4
4
  const RESOLUTION = 16384;
5
5
  const durations = {
6
+ '1/8': RESOLUTION * 8,
7
+ '1/4': RESOLUTION * 4,
6
8
  '1/2': RESOLUTION * 2,
7
9
  1: RESOLUTION / 1,
8
10
  2: RESOLUTION / 2,
@@ -13,45 +15,28 @@ const durations = {
13
15
  64: RESOLUTION / 64,
14
16
  128: RESOLUTION / 128,
15
17
  256: RESOLUTION / 256,
18
+ 512: RESOLUTION / 512,
19
+ 1024: RESOLUTION / 1024,
16
20
  };
17
21
  const durationAliases = {
22
+ m: '1/8',
23
+ l: '1/4',
18
24
  w: '1',
19
25
  h: '2',
20
26
  q: '4',
21
27
  b: '256',
22
28
  };
23
- const keySignatures = {
24
- C: { num: 0 },
25
- Am: { num: 0 },
26
- F: { accidental: 'b', num: 1 },
27
- Dm: { accidental: 'b', num: 1 },
28
- Bb: { accidental: 'b', num: 2 },
29
- Gm: { accidental: 'b', num: 2 },
30
- Eb: { accidental: 'b', num: 3 },
31
- Cm: { accidental: 'b', num: 3 },
32
- Ab: { accidental: 'b', num: 4 },
33
- Fm: { accidental: 'b', num: 4 },
34
- Db: { accidental: 'b', num: 5 },
35
- Bbm: { accidental: 'b', num: 5 },
36
- Gb: { accidental: 'b', num: 6 },
37
- Ebm: { accidental: 'b', num: 6 },
38
- Cb: { accidental: 'b', num: 7 },
39
- Abm: { accidental: 'b', num: 7 },
40
- G: { accidental: '#', num: 1 },
41
- Em: { accidental: '#', num: 1 },
42
- D: { accidental: '#', num: 2 },
43
- Bm: { accidental: '#', num: 2 },
44
- A: { accidental: '#', num: 3 },
45
- 'F#m': { accidental: '#', num: 3 },
46
- E: { accidental: '#', num: 4 },
47
- 'C#m': { accidental: '#', num: 4 },
48
- B: { accidental: '#', num: 5 },
49
- 'G#m': { accidental: '#', num: 5 },
50
- 'F#': { accidental: '#', num: 6 },
51
- 'D#m': { accidental: '#', num: 6 },
52
- 'C#': { accidental: '#', num: 7 },
53
- 'A#m': { accidental: '#', num: 7 },
29
+ const generateKeySignatures = () => {
30
+ const keySignatures = {};
31
+ for (let i = 1; i <= 14; i++) {
32
+ keySignatures[`flats_${i}`] = { accidental: 'b', num: i };
33
+ keySignatures[`sharps_${i}`] = { accidental: '#', num: i };
34
+ }
35
+ keySignatures['flats_0'] = { num: 0 };
36
+ keySignatures['sharps_0'] = { num: 0 };
37
+ return keySignatures;
54
38
  };
39
+ const keySignatures = Object.assign(Object.assign({}, generateKeySignatures()), { C: { num: 0 }, Am: { num: 0 }, F: { accidental: 'b', num: 1 }, Dm: { accidental: 'b', num: 1 }, Bb: { accidental: 'b', num: 2 }, Gm: { accidental: 'b', num: 2 }, Eb: { accidental: 'b', num: 3 }, Cm: { accidental: 'b', num: 3 }, Ab: { accidental: 'b', num: 4 }, Fm: { accidental: 'b', num: 4 }, Db: { accidental: 'b', num: 5 }, Bbm: { accidental: 'b', num: 5 }, Gb: { accidental: 'b', num: 6 }, Ebm: { accidental: 'b', num: 6 }, Cb: { accidental: 'b', num: 7 }, Abm: { accidental: 'b', num: 7 }, Dbm: { accidental: 'b', num: 8 }, Gbm: { accidental: 'b', num: 9 }, G: { accidental: '#', num: 1 }, Em: { accidental: '#', num: 1 }, D: { accidental: '#', num: 2 }, Bm: { accidental: '#', num: 2 }, A: { accidental: '#', num: 3 }, 'F#m': { accidental: '#', num: 3 }, E: { accidental: '#', num: 4 }, 'C#m': { accidental: '#', num: 4 }, B: { accidental: '#', num: 5 }, 'G#m': { accidental: '#', num: 5 }, 'F#': { accidental: '#', num: 6 }, 'D#m': { accidental: '#', num: 6 }, 'C#': { accidental: '#', num: 7 }, 'A#m': { accidental: '#', num: 7 }, 'G#': { accidental: '#', num: 8 }, 'D#': { accidental: '#', num: 9 }, 'A#': { accidental: '#', num: 10 } });
55
40
  const clefs = {
56
41
  treble: { lineShift: 0 },
57
42
  bass: { lineShift: 6 },
@@ -354,12 +339,17 @@ export class Tables {
354
339
  '#': [0, 1.5, -0.5, 1, 2.5, 0.5, 2],
355
340
  };
356
341
  const notes = accidentalList[keySpec.accidental];
357
- const accList = [];
358
- for (let i = 0; i < keySpec.num; ++i) {
359
- const line = notes[i];
360
- accList.push({ type: keySpec.accidental, line });
361
- }
362
- return accList;
342
+ const accidentalCount = Math.min(keySpec.num, 7);
343
+ const doubleAccidentalCount = Math.max(keySpec.num - 7, 0);
344
+ const regularAccidentals = notes.slice(doubleAccidentalCount, accidentalCount).map((line) => ({
345
+ type: `${keySpec.accidental}`,
346
+ line,
347
+ }));
348
+ const doubleAccidentals = notes.slice(0, doubleAccidentalCount).map((line) => ({
349
+ type: `${keySpec.accidental}${keySpec.accidental}`,
350
+ line,
351
+ }));
352
+ return [...regularAccidentals, ...doubleAccidentals];
363
353
  }
364
354
  static getKeySignatures() {
365
355
  return keySignatures;
@@ -544,6 +534,10 @@ export class Tables {
544
534
  }
545
535
  case 'R':
546
536
  switch (duration) {
537
+ case '1/8':
538
+ return Glyphs.restMaxima;
539
+ case '1/4':
540
+ return Glyphs.restLonga;
547
541
  case '1/2':
548
542
  return Glyphs.restDoubleWhole;
549
543
  case '1':
@@ -562,6 +556,12 @@ export class Tables {
562
556
  return Glyphs.rest64th;
563
557
  case '128':
564
558
  return Glyphs.rest128th;
559
+ case '256':
560
+ return Glyphs.rest256th;
561
+ case '512':
562
+ return Glyphs.rest512th;
563
+ case '1024':
564
+ return Glyphs.rest1024th;
565
565
  }
566
566
  break;
567
567
  case 'S':
@@ -577,6 +577,10 @@ export class Tables {
577
577
  }
578
578
  default:
579
579
  switch (duration) {
580
+ case '1/8':
581
+ return Glyphs.mensuralNoteheadMaximaBlack;
582
+ case '1/4':
583
+ return Glyphs.mensuralNoteheadLongaBlack;
580
584
  case '1/2':
581
585
  return Glyphs.noteheadDoubleWhole;
582
586
  case '1':
@@ -598,6 +602,12 @@ Tables.STAVE_LINE_THICKNESS = 1;
598
602
  Tables.RENDER_PRECISION_PLACES = 3;
599
603
  Tables.RESOLUTION = RESOLUTION;
600
604
  Tables.durationCodes = {
605
+ '1/8': {
606
+ stem: true,
607
+ },
608
+ '1/4': {
609
+ stem: false,
610
+ },
601
611
  '1/2': {
602
612
  stem: false,
603
613
  },
@@ -640,11 +650,33 @@ Tables.durationCodes = {
640
650
  stem: true,
641
651
  codeFlagUp: Glyphs.flag128thUp,
642
652
  },
653
+ 256: {
654
+ beamCount: 6,
655
+ stemBeamExtension: 25,
656
+ stem: true,
657
+ codeFlagUp: Glyphs.flag256thUp,
658
+ },
659
+ 512: {
660
+ beamCount: 7,
661
+ stemBeamExtension: 27.5,
662
+ stem: true,
663
+ codeFlagUp: Glyphs.flag512thUp,
664
+ },
665
+ 1024: {
666
+ beamCount: 8,
667
+ stemBeamExtension: 30,
668
+ stem: true,
669
+ codeFlagUp: Glyphs.flag1024thUp,
670
+ },
643
671
  };
644
672
  Tables.NOTATION_FONT_SCALE = 39;
645
673
  Tables.TABLATURE_FONT_SCALE = 39;
646
674
  Tables.SLASH_NOTEHEAD_WIDTH = 15;
647
675
  Tables.STAVE_LINE_DISTANCE = 10;
676
+ Tables.noteHeadStemYOffsets = {
677
+ [Glyphs.noteheadXBlack]: { up: 0.444, down: -0.44 },
678
+ [Glyphs.noteheadXHalf]: { up: 0.412, down: -0.412 },
679
+ };
648
680
  Tables.TEXT_HEIGHT_OFFSET_HACK = 1;
649
681
  Tables.accidentalColumnsTable = accidentalColumns;
650
682
  Tables.unicode = {
@@ -1,5 +1,7 @@
1
1
  import { Element } from './element.js';
2
+ import { Font } from './font.js';
2
3
  import { Glyphs } from './glyphs.js';
4
+ import { Metrics } from './metrics.js';
3
5
  import { Modifier } from './modifier.js';
4
6
  import { Note } from './note.js';
5
7
  import { Stem } from './stem.js';
@@ -124,6 +126,14 @@ export class TabNote extends StemmableNote {
124
126
  }
125
127
  return el;
126
128
  }
129
+ setFontSize(size) {
130
+ super.setFontSize(size);
131
+ this.fretFontSize = size;
132
+ if (this.positions)
133
+ this.updateWidth();
134
+ this.preFormatted = false;
135
+ return this;
136
+ }
127
137
  updateWidth() {
128
138
  this.fretElement = [];
129
139
  this.width = 0;
@@ -132,6 +142,13 @@ export class TabNote extends StemmableNote {
132
142
  if (this.ghost)
133
143
  fret = '(' + fret + ')';
134
144
  const el = TabNote.tabToElement(fret.toString());
145
+ const defaultSize = Font.convertSizeToPointValue(Metrics.getFontInfo('TabNote.text').size);
146
+ const size = this.fretFontSize === undefined
147
+ ? defaultSize * this.getFontScale()
148
+ : Font.convertSizeToPointValue(this.fretFontSize);
149
+ el.setFontSize((Font.convertSizeToPointValue(el.fontInfo.size) * size) / defaultSize);
150
+ const metrics = el.getTextMetrics();
151
+ el.setYShift((metrics.actualBoundingBoxAscent - metrics.actualBoundingBoxDescent) / 2);
135
152
  this.fretElement.push(el);
136
153
  this.width = Math.max(el.getWidth(), this.width);
137
154
  }
@@ -261,7 +278,8 @@ export class TabNote extends StemmableNote {
261
278
  }
262
279
  this.setRendered();
263
280
  const renderStem = this.beam === undefined && this.renderOptions.drawStem;
264
- ctx.openGroup('tabnote', this.getAttribute('id'));
281
+ const clsAttribute = this.getAttribute('class');
282
+ ctx.openGroup('tabnote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
265
283
  this.drawPositions();
266
284
  this.drawStemThrough();
267
285
  if (this.stem && renderStem) {
@@ -271,6 +289,7 @@ export class TabNote extends StemmableNote {
271
289
  }
272
290
  this.drawFlag();
273
291
  this.drawModifiers();
292
+ this.drawPointerRect();
274
293
  ctx.closeGroup();
275
294
  }
276
295
  }
@@ -40,7 +40,6 @@ export class TextBracket extends Element {
40
40
  this.renderOptions = {
41
41
  dashed: true,
42
42
  dash: [5],
43
- color: 'black',
44
43
  lineWidth: 1,
45
44
  showBracket: true,
46
45
  bracketHeight: 8,
@@ -53,10 +52,12 @@ export class TextBracket extends Element {
53
52
  const smallerFontSize = Font.scaleSize(size, 0.714286);
54
53
  this.superscriptElement.setFont(family, smallerFontSize, weight, style);
55
54
  const options = this.renderOptions;
56
- ctx.setStrokeStyle(options.color);
57
- ctx.setFillStyle(options.color);
55
+ if (options.color !== undefined) {
56
+ ctx.setStrokeStyle(options.color);
57
+ ctx.setFillStyle(options.color);
58
+ }
58
59
  ctx.setLineWidth(options.lineWidth);
59
- return this;
60
+ return super.applyStyle(ctx);
60
61
  }
61
62
  setDashed(dashed, dash) {
62
63
  this.renderOptions.dashed = dashed;
@@ -1,3 +1,4 @@
1
+ import { BoundingBox } from './boundingbox.js';
1
2
  import { Glyphs } from './glyphs.js';
2
3
  import { Note } from './note.js';
3
4
  import { log, RuntimeError } from './util.js';
@@ -42,6 +43,10 @@ export class TextDynamics extends Note {
42
43
  this.preFormatted = true;
43
44
  return this;
44
45
  }
46
+ getBoundingBox() {
47
+ const metrics = this.getTextMetrics();
48
+ return new BoundingBox(this.getAbsoluteX() + this.x + this.xShift, this.checkStave().getYForLine(this.line - 3) + this.y + this.yShift - metrics.actualBoundingBoxAscent, this.getWidth(), this.getHeight());
49
+ }
45
50
  draw() {
46
51
  this.setRendered();
47
52
  const x = this.getAbsoluteX();
@@ -47,16 +47,16 @@ export class TextNote extends Note {
47
47
  this.setFont(noteStruct.font);
48
48
  }
49
49
  else if (noteStruct.glyph === undefined) {
50
- this.setFont(Metrics.getFontInfo('TextNote.text.fontSize'));
50
+ this.setFont(Metrics.getFontInfo('TextNote.text'));
51
51
  }
52
52
  const smallerFontSize = Font.convertSizeToPointValue(this.fontInfo.size) * 0.769231;
53
53
  if (noteStruct.superscript) {
54
- this.superscript = new Element('TexNote.subSuper');
54
+ this.superscript = new Element('TextNote.text');
55
55
  this.superscript.setText(noteStruct.superscript);
56
56
  this.superscript.setFontSize(smallerFontSize);
57
57
  }
58
58
  if (noteStruct.subscript) {
59
- this.subscript = new Element('TexNote.subSuper');
59
+ this.subscript = new Element('TextNote.text');
60
60
  this.subscript.setText(noteStruct.subscript);
61
61
  this.subscript.setFontSize(smallerFontSize);
62
62
  }
@@ -39,7 +39,9 @@ export class Tickable extends Element {
39
39
  return this.ignoreTicks;
40
40
  }
41
41
  setIgnoreTicks(flag) {
42
+ var _a;
42
43
  this.ignoreTicks = flag;
44
+ (_a = this.voice) === null || _a === void 0 ? void 0 : _a.invalidateTicks();
43
45
  return this;
44
46
  }
45
47
  getWidth() {
@@ -79,40 +81,66 @@ export class Tickable extends Element {
79
81
  this.voice = voice;
80
82
  }
81
83
  getTuplet() {
82
- return this.tuplet;
84
+ return this.tupletStack.at(-1);
83
85
  }
84
86
  getTupletStack() {
85
87
  return this.tupletStack;
86
88
  }
89
+ removeTuplet(tuplet) {
90
+ const i = this.tupletStack.indexOf(tuplet);
91
+ if (i === -1) {
92
+ throw new RuntimeError('BadArguments', 'Tuplet is not found in this tickable');
93
+ }
94
+ this.tupletStack.splice(i, 1);
95
+ const noteCount = tuplet.getNoteCount();
96
+ const notesOccupied = tuplet.getNotesOccupied();
97
+ this.applyTickMultiplier(noteCount, notesOccupied);
98
+ return this;
99
+ }
100
+ clearTuplets() {
101
+ var _a;
102
+ if (!this.tupletStack.length) {
103
+ return this;
104
+ }
105
+ this.tupletStack = [];
106
+ this.tickMultiplier = new Fraction(1, 1);
107
+ this.ticks = new Fraction(this.intrinsicTicks, 1);
108
+ (_a = this.voice) === null || _a === void 0 ? void 0 : _a.invalidateTicks();
109
+ return this;
110
+ }
87
111
  resetTuplet(tuplet) {
88
- let noteCount;
89
- let notesOccupied;
90
112
  if (tuplet) {
91
- const i = this.tupletStack.indexOf(tuplet);
92
- if (i !== -1) {
93
- this.tupletStack.splice(i, 1);
94
- noteCount = tuplet.getNoteCount();
95
- notesOccupied = tuplet.getNotesOccupied();
96
- this.applyTickMultiplier(noteCount, notesOccupied);
113
+ try {
114
+ this.removeTuplet(tuplet);
115
+ }
116
+ catch (_a) {
97
117
  }
98
- return this;
99
118
  }
100
- while (this.tupletStack.length) {
101
- tuplet = this.tupletStack.pop();
102
- noteCount = tuplet.getNoteCount();
103
- notesOccupied = tuplet.getNotesOccupied();
104
- this.applyTickMultiplier(noteCount, notesOccupied);
119
+ else {
120
+ this.clearTuplets();
105
121
  }
106
122
  return this;
107
123
  }
108
124
  setTuplet(tuplet) {
109
- if (tuplet) {
110
- this.tupletStack.push(tuplet);
111
- const noteCount = tuplet.getNoteCount();
112
- const notesOccupied = tuplet.getNotesOccupied();
113
- this.applyTickMultiplier(notesOccupied, noteCount);
125
+ if (this.tupletStack.length) {
126
+ this.clearTuplets();
127
+ }
128
+ return this.addTuplet(tuplet);
129
+ }
130
+ addTuplet(tuplet) {
131
+ if (this.tupletStack.includes(tuplet))
132
+ return this;
133
+ this.tupletStack.push(tuplet);
134
+ const noteCount = tuplet.getNoteCount();
135
+ const notesOccupied = tuplet.getNotesOccupied();
136
+ this.applyTickMultiplier(notesOccupied, noteCount);
137
+ return this;
138
+ }
139
+ setTupletStack(tupletStack) {
140
+ this.clearTuplets();
141
+ for (const tup of tupletStack) {
142
+ this.addTuplet(tup);
114
143
  }
115
- this.tuplet = tuplet;
116
144
  return this;
117
145
  }
118
146
  addToModifierContext(mc) {
@@ -170,20 +198,26 @@ export class Tickable extends Element {
170
198
  return this.intrinsicTicks;
171
199
  }
172
200
  setIntrinsicTicks(intrinsicTicks) {
201
+ var _a;
173
202
  this.intrinsicTicks = intrinsicTicks;
174
203
  this.ticks = this.tickMultiplier.clone().multiply(this.intrinsicTicks);
204
+ (_a = this.voice) === null || _a === void 0 ? void 0 : _a.invalidateTicks();
175
205
  }
176
206
  getTickMultiplier() {
177
207
  return this.tickMultiplier;
178
208
  }
179
209
  applyTickMultiplier(numerator, denominator) {
210
+ var _a;
180
211
  this.tickMultiplier.multiply(numerator, denominator);
181
212
  this.ticks = this.tickMultiplier.clone().multiply(this.intrinsicTicks);
213
+ (_a = this.voice) === null || _a === void 0 ? void 0 : _a.invalidateTicks();
182
214
  }
183
215
  setDuration(duration) {
216
+ var _a;
184
217
  const ticks = duration.numerator * (Tables.RESOLUTION / duration.denominator);
185
218
  this.ticks = this.tickMultiplier.clone().multiply(ticks);
186
- this.intrinsicTicks = this.ticks.value();
219
+ this.intrinsicTicks = ticks;
220
+ (_a = this.voice) === null || _a === void 0 ? void 0 : _a.invalidateTicks();
187
221
  }
188
222
  getAbsoluteX() {
189
223
  const tickContext = this.checkTickContext(`Can't getAbsoluteX() without a TickContext.`);
@@ -16,6 +16,8 @@ export class TimeSignature extends StaveModifier {
16
16
  }
17
17
  constructor(timeSpec = '4/4', customPadding = 15, validateArgs = true) {
18
18
  super();
19
+ this.topRenderY = 0;
20
+ this.botRenderY = 0;
19
21
  this.timeSpec = '4/4';
20
22
  this.line = 0;
21
23
  this.isNumeric = true;
@@ -123,26 +125,45 @@ export class TimeSignature extends StaveModifier {
123
125
  const stave = this.checkStave();
124
126
  const ctx = stave.checkContext();
125
127
  this.setRendered();
126
- ctx.openGroup('timesignature', this.getAttribute('id'));
128
+ const clsAttribute = this.getAttribute('class');
129
+ ctx.openGroup('timesignature' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
127
130
  this.drawAt(ctx, stave, this.x);
131
+ this.drawPointerRect();
128
132
  ctx.closeGroup();
129
133
  }
130
134
  drawAt(ctx, stave, x) {
131
135
  this.setRendered();
132
136
  if (this.isNumeric) {
133
137
  let startX = x + this.topStartX;
134
- let y = 0;
135
- if (this.botText.getText().length > 0)
136
- y = stave.getYForLine(this.topLine - this.lineShift);
137
- else
138
- y = (stave.getYForLine(this.topLine) + stave.getYForLine(this.bottomLine)) / 2;
139
- this.topText.renderText(ctx, startX, y);
138
+ if (this.botText.getText().length > 0) {
139
+ this.topRenderY = stave.getYForLine(this.topLine - this.lineShift);
140
+ }
141
+ else {
142
+ this.topRenderY = (stave.getYForLine(this.topLine) + stave.getYForLine(this.bottomLine)) / 2;
143
+ }
144
+ this.topText.renderText(ctx, startX, this.topRenderY);
140
145
  startX = x + this.botStartX;
141
- y = stave.getYForLine(this.bottomLine + this.lineShift);
142
- this.botText.renderText(ctx, startX, y);
146
+ this.botRenderY = stave.getYForLine(this.bottomLine + this.lineShift);
147
+ this.botText.renderText(ctx, startX, this.botRenderY);
143
148
  }
144
149
  else {
145
150
  this.renderText(ctx, x - this.x, stave.getYForLine(this.line));
146
151
  }
147
152
  }
153
+ getBoundingBox() {
154
+ if (this.isNumeric) {
155
+ const topBoundingBox = this.topText.getBoundingBox();
156
+ const botBoundingBox = this.botText.getBoundingBox();
157
+ topBoundingBox.move(this.x + this.topStartX, this.topRenderY);
158
+ botBoundingBox.move(this.x + this.botStartX, this.botRenderY);
159
+ const mergedBox = topBoundingBox.mergeWith(botBoundingBox);
160
+ return mergedBox;
161
+ }
162
+ else {
163
+ const stave = this.checkStave();
164
+ const textBoundingBox = super.getBoundingBox();
165
+ textBoundingBox.move(0, stave.getYForLine(this.line));
166
+ return textBoundingBox;
167
+ }
168
+ }
148
169
  }
@@ -21,8 +21,10 @@ export class TimeSigNote extends Note {
21
21
  const stave = this.checkStave();
22
22
  const ctx = this.checkContext();
23
23
  this.setRendered();
24
- ctx.openGroup('timesignote', this.getAttribute('id'));
24
+ const clsAttribute = this.getAttribute('class');
25
+ ctx.openGroup('timesignote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
25
26
  this.timeSig.drawAt(ctx, stave, this.getAbsoluteX());
27
+ this.drawPointerRect();
26
28
  ctx.closeGroup();
27
29
  }
28
30
  }
@@ -19,11 +19,11 @@ export class Tuning {
19
19
  return (_a = Tables.keyProperties(noteString).intValue) !== null && _a !== void 0 ? _a : -1;
20
20
  }
21
21
  setTuning(tuningString) {
22
- if (Tuning.names[tuningString]) {
22
+ if (Object.prototype.hasOwnProperty.call(Tuning.names, tuningString)) {
23
23
  tuningString = Tuning.names[tuningString];
24
24
  }
25
25
  this.tuningValues = [];
26
- const keys = tuningString.split(/\s*,\s*/);
26
+ const keys = tuningString.split(',').map((key) => key.trim());
27
27
  if (keys.length === 0) {
28
28
  throw new RuntimeError('BadArguments', `Invalid tuning string: ${tuningString}`);
29
29
  }