vexflow 4.0.1-beta.2 → 4.0.2

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 (94) hide show
  1. package/README.md +48 -65
  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 +729 -698
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +553 -614
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow-gonville.js +2 -2
  11. package/build/cjs/vexflow-gonville.js.map +1 -1
  12. package/build/cjs/vexflow-petaluma.js +2 -2
  13. package/build/cjs/vexflow-petaluma.js.map +1 -1
  14. package/build/cjs/vexflow.js +2 -2
  15. package/build/cjs/vexflow.js.map +1 -1
  16. package/build/esm/entry/vexflow-bravura.js +1 -2
  17. package/build/esm/entry/vexflow-core.js +1 -2
  18. package/build/esm/entry/vexflow-debug-with-tests.js +9 -2
  19. package/build/esm/entry/vexflow-debug.js +7 -2
  20. package/build/esm/entry/vexflow-gonville.js +1 -2
  21. package/build/esm/entry/vexflow-petaluma.js +1 -2
  22. package/build/esm/entry/vexflow.js +1 -2
  23. package/build/esm/src/annotation.js +10 -4
  24. package/build/esm/src/beam.js +20 -6
  25. package/build/esm/src/factory.js +6 -1
  26. package/build/esm/src/flow.js +27 -14
  27. package/build/esm/src/font.js +0 -2
  28. package/build/esm/src/formatter.js +21 -4
  29. package/build/esm/src/glyph.js +6 -0
  30. package/build/esm/src/index.js +1 -3
  31. package/build/esm/src/note.js +1 -1
  32. package/build/esm/src/stave.js +2 -2
  33. package/build/esm/src/staveconnector.js +6 -3
  34. package/build/esm/src/staveline.js +2 -5
  35. package/build/esm/src/stavenote.js +19 -6
  36. package/build/esm/src/stavesection.js +9 -6
  37. package/build/esm/src/stavetext.js +3 -3
  38. package/build/esm/src/system.js +1 -8
  39. package/build/esm/src/textnote.js +12 -14
  40. package/build/esm/src/version.js +3 -3
  41. package/build/esm/tests/annotation_tests.js +14 -1
  42. package/build/esm/tests/beam_tests.js +19 -0
  43. package/build/esm/tests/easyscore_tests.js +5 -2
  44. package/build/esm/tests/formatter_tests.js +62 -10
  45. package/build/esm/tests/stave_tests.js +4 -4
  46. package/build/types/entry/vexflow-bravura.d.ts +1 -2
  47. package/build/types/entry/vexflow-core.d.ts +1 -2
  48. package/build/types/entry/vexflow-debug.d.ts +1 -2
  49. package/build/types/entry/vexflow-gonville.d.ts +1 -2
  50. package/build/types/entry/vexflow-petaluma.d.ts +1 -2
  51. package/build/types/entry/vexflow.d.ts +1 -2
  52. package/build/types/src/annotation.d.ts +1 -0
  53. package/build/types/src/beam.d.ts +30 -1
  54. package/build/types/src/easyscore.d.ts +4 -0
  55. package/build/types/src/factory.d.ts +6 -3
  56. package/build/types/src/flow.d.ts +27 -12
  57. package/build/types/src/font.d.ts +0 -1
  58. package/build/types/src/glyph.d.ts +2 -0
  59. package/build/types/src/index.d.ts +1 -3
  60. package/build/types/src/note.d.ts +1 -0
  61. package/build/types/src/stave.d.ts +1 -1
  62. package/build/types/src/staveconnector.d.ts +13 -15
  63. package/build/types/src/staveline.d.ts +2 -5
  64. package/build/types/src/stavesection.d.ts +2 -1
  65. package/build/types/src/system.d.ts +2 -2
  66. package/build/types/src/textnote.d.ts +4 -4
  67. package/entry/vexflow-bravura.ts +3 -3
  68. package/entry/vexflow-core.ts +3 -3
  69. package/entry/vexflow-debug-with-tests.ts +16 -2
  70. package/entry/vexflow-debug.ts +11 -3
  71. package/entry/vexflow-gonville.ts +3 -3
  72. package/entry/vexflow-petaluma.ts +3 -3
  73. package/entry/vexflow.ts +3 -3
  74. package/package.json +3 -1
  75. package/releases/vexflow-debug.js +30441 -0
  76. package/releases/vexflow-min.js +6 -0
  77. package/src/annotation.ts +15 -4
  78. package/src/beam.ts +55 -6
  79. package/src/easyscore.ts +11 -1
  80. package/src/factory.ts +18 -4
  81. package/src/flow.ts +35 -20
  82. package/src/font.ts +0 -4
  83. package/src/formatter.ts +24 -8
  84. package/src/glyph.ts +8 -0
  85. package/src/index.ts +2 -7
  86. package/src/note.ts +2 -1
  87. package/src/stave.ts +2 -2
  88. package/src/staveconnector.ts +43 -9
  89. package/src/staveline.ts +2 -5
  90. package/src/stavenote.ts +20 -10
  91. package/src/stavesection.ts +10 -6
  92. package/src/stavetext.ts +3 -3
  93. package/src/system.ts +3 -9
  94. package/src/textnote.ts +9 -11
@@ -1,4 +1,3 @@
1
- import { Vex } from '../src/vex.js';
2
1
  import { Flow } from '../src/flow.js';
3
2
  import { loadBravura } from '../src/fonts/load_bravura.js';
4
3
  import { loadCustom } from '../src/fonts/load_custom.js';
@@ -8,4 +7,4 @@ loadCustom();
8
7
  Flow.setMusicFont('Bravura', 'Custom');
9
8
  loadTextFonts();
10
9
  export * from '../src/index.js';
11
- export default Vex;
10
+ export * as default from '../src/index.js';
@@ -7,7 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Vex } from '../src/vex.js';
11
10
  import { Flow } from '../src/flow.js';
12
11
  import { Font } from '../src/font.js';
13
12
  import { loadTextFonts } from '../src/fonts/textfonts.js';
@@ -51,4 +50,4 @@ Flow.fetchMusicFont = (fontName, fontModuleOrPath) => __awaiter(void 0, void 0,
51
50
  });
52
51
  loadTextFonts();
53
52
  export * from '../src/index.js';
54
- export default Vex;
53
+ export * as default from '../src/index.js';
@@ -1,4 +1,11 @@
1
- import { Vex } from './vexflow.js';
1
+ import * as VexSrc from '../src/index.js';
2
+ import * as VexTests from '../tests/index.js';
3
+ import { Flow } from '../src/flow.js';
4
+ import { loadAllMusicFonts } from '../src/fonts/load_all.js';
5
+ import { loadTextFonts } from '../src/fonts/textfonts.js';
6
+ loadAllMusicFonts();
7
+ Flow.setMusicFont('Bravura', 'Gonville', 'Custom');
8
+ loadTextFonts();
2
9
  export * from '../src/index.js';
3
10
  export * from '../tests/index.js';
4
- export default Vex;
11
+ export default Object.assign(Object.assign({}, VexSrc), VexTests);
@@ -1,3 +1,8 @@
1
- import { Vex } from './vexflow.js';
1
+ import { Flow } from '../src/flow.js';
2
+ import { loadAllMusicFonts } from '../src/fonts/load_all.js';
3
+ import { loadTextFonts } from '../src/fonts/textfonts.js';
4
+ loadAllMusicFonts();
5
+ Flow.setMusicFont('Bravura', 'Gonville', 'Custom');
6
+ loadTextFonts();
2
7
  export * from '../src/index.js';
3
- export default Vex;
8
+ export * as default from '../src/index.js';
@@ -1,4 +1,3 @@
1
- import { Vex } from '../src/vex.js';
2
1
  import { Flow } from '../src/flow.js';
3
2
  import { loadCustom } from '../src/fonts/load_custom.js';
4
3
  import { loadGonville } from '../src/fonts/load_gonville.js';
@@ -8,4 +7,4 @@ loadCustom();
8
7
  Flow.setMusicFont('Gonville', 'Custom');
9
8
  loadTextFonts();
10
9
  export * from '../src/index.js';
11
- export default Vex;
10
+ export * as default from '../src/index.js';
@@ -1,4 +1,3 @@
1
- import { Vex } from '../src/vex.js';
2
1
  import { Flow } from '../src/flow.js';
3
2
  import { loadCustom } from '../src/fonts/load_custom.js';
4
3
  import { loadPetaluma } from '../src/fonts/load_petaluma.js';
@@ -8,4 +7,4 @@ loadCustom();
8
7
  Flow.setMusicFont('Petaluma', 'Custom');
9
8
  loadTextFonts();
10
9
  export * from '../src/index.js';
11
- export default Vex;
10
+ export * as default from '../src/index.js';
@@ -1,4 +1,3 @@
1
- import { Vex } from '../src/vex.js';
2
1
  import { Flow } from '../src/flow.js';
3
2
  import { loadAllMusicFonts } from '../src/fonts/load_all.js';
4
3
  import { loadTextFonts } from '../src/fonts/textfonts.js';
@@ -6,4 +5,4 @@ loadAllMusicFonts();
6
5
  Flow.setMusicFont('Bravura', 'Gonville', 'Custom');
7
6
  loadTextFonts();
8
7
  export * from '../src/index.js';
9
- export default Vex;
8
+ export * as default from '../src/index.js';
@@ -35,6 +35,10 @@ export class Annotation extends Modifier {
35
35
  static get CATEGORY() {
36
36
  return "Annotation";
37
37
  }
38
+ static get minAnnotationPadding() {
39
+ const musicFont = Tables.currentMusicFont();
40
+ return musicFont.lookupMetric('glyphs.noteHead.minPadding');
41
+ }
38
42
  static format(annotations, state) {
39
43
  if (!annotations || annotations.length === 0)
40
44
  return false;
@@ -52,14 +56,14 @@ export class Annotation extends Modifier {
52
56
  const textWidth = textFormatter.getWidthForTextInPx(annotation.text);
53
57
  if (annotation.horizontalJustification === AnnotationHorizontalJustify.LEFT) {
54
58
  maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
55
- leftWidth = Math.max(leftWidth, textWidth);
59
+ leftWidth = Math.max(leftWidth, textWidth) + Annotation.minAnnotationPadding;
56
60
  }
57
61
  else if (annotation.horizontalJustification === AnnotationHorizontalJustify.RIGHT) {
58
62
  maxRightGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
59
63
  rightWidth = Math.max(rightWidth, textWidth);
60
64
  }
61
65
  else {
62
- leftWidth = Math.max(leftWidth, textWidth / 2);
66
+ leftWidth = Math.max(leftWidth, textWidth / 2) + Annotation.minAnnotationPadding;
63
67
  rightWidth = Math.max(rightWidth, textWidth / 2);
64
68
  maxLeftGlyphWidth = Math.max(glyphWidth / 2, maxLeftGlyphWidth);
65
69
  maxRightGlyphWidth = Math.max(glyphWidth / 2, maxRightGlyphWidth);
@@ -132,8 +136,8 @@ export class Annotation extends Modifier {
132
136
  }
133
137
  const rightOverlap = Math.min(Math.max(rightWidth - maxRightGlyphWidth, 0), Math.max(rightWidth - state.right_shift, 0));
134
138
  const leftOverlap = Math.min(Math.max(leftWidth - maxLeftGlyphWidth, 0), Math.max(leftWidth - state.left_shift, 0));
135
- state.left_shift += leftOverlap / 2;
136
- state.right_shift += rightOverlap / 2;
139
+ state.left_shift += leftOverlap;
140
+ state.right_shift += rightOverlap;
137
141
  return true;
138
142
  }
139
143
  setVerticalJustification(just) {
@@ -155,6 +159,7 @@ export class Annotation extends Modifier {
155
159
  const start = note.getModifierStartXY(ModifierPosition.ABOVE, this.index);
156
160
  this.setRendered();
157
161
  ctx.save();
162
+ this.applyStyle();
158
163
  const classString = Object.keys(this.getAttribute('classes')).join(' ');
159
164
  ctx.openGroup(classString, this.getAttribute('id'));
160
165
  ctx.setFont(this.textFont);
@@ -209,6 +214,7 @@ export class Annotation extends Modifier {
209
214
  L('Rendering annotation: ', this.text, x, y);
210
215
  ctx.fillText(this.text, x, y);
211
216
  ctx.closeGroup();
217
+ this.restoreStyle();
212
218
  ctx.restore();
213
219
  }
214
220
  }
@@ -25,14 +25,15 @@ function getStemSlope(firstNote, lastNote) {
25
25
  const lastStemX = lastNote.getStemX();
26
26
  return (lastStemTipY - firstStemTipY) / (lastStemX - firstStemX);
27
27
  }
28
- const BEAM_LEFT = 'L';
29
- const BEAM_RIGHT = 'R';
30
- const BEAM_BOTH = 'B';
28
+ export const BEAM_LEFT = 'L';
29
+ export const BEAM_RIGHT = 'R';
30
+ export const BEAM_BOTH = 'B';
31
31
  export class Beam extends Element {
32
32
  constructor(notes, auto_stem = false) {
33
33
  super();
34
34
  this.slope = 0;
35
35
  this.y_shift = 0;
36
+ this.forcedPartialDirections = {};
36
37
  if (!notes || notes.length === 0) {
37
38
  throw new RuntimeError('BadArguments', 'No notes provided for beam.');
38
39
  }
@@ -343,6 +344,14 @@ export class Beam extends Element {
343
344
  this.break_on_indices = indices;
344
345
  return this;
345
346
  }
347
+ setPartialBeamSideAt(noteIndex, side) {
348
+ this.forcedPartialDirections[noteIndex] = side;
349
+ return this;
350
+ }
351
+ unsetPartialBeamSideAt(noteIndex) {
352
+ delete this.forcedPartialDirections[noteIndex];
353
+ return this;
354
+ }
346
355
  getSlopeY(x, first_x_px, first_y_px, slope) {
347
356
  return first_y_px + (x - first_x_px) * slope;
348
357
  }
@@ -460,10 +469,13 @@ export class Beam extends Element {
460
469
  }
461
470
  }
462
471
  }
463
- lookupBeamDirection(duration, prev_tick, tick, next_tick) {
472
+ lookupBeamDirection(duration, prev_tick, tick, next_tick, noteIndex) {
464
473
  if (duration === '4') {
465
474
  return BEAM_LEFT;
466
475
  }
476
+ const forcedBeamDirection = this.forcedPartialDirections[noteIndex];
477
+ if (forcedBeamDirection)
478
+ return forcedBeamDirection;
467
479
  const lookup_duration = `${Tables.durationToNumber(duration) / 2}`;
468
480
  const prev_note_gets_beam = prev_tick < Tables.durationToTicks(lookup_duration);
469
481
  const next_note_gets_beam = next_tick < Tables.durationToTicks(lookup_duration);
@@ -477,7 +489,7 @@ export class Beam extends Element {
477
489
  else if (!prev_note_gets_beam && next_note_gets_beam && note_gets_beam) {
478
490
  return BEAM_RIGHT;
479
491
  }
480
- return this.lookupBeamDirection(lookup_duration, prev_tick, tick, next_tick);
492
+ return this.lookupBeamDirection(lookup_duration, prev_tick, tick, next_tick, noteIndex);
481
493
  }
482
494
  getBeamLines(duration) {
483
495
  const tick_of_duration = Tables.durationToTicks(duration);
@@ -524,7 +536,7 @@ export class Beam extends Element {
524
536
  const prev_tick = prev_note.getIntrinsicTicks();
525
537
  const next_tick = next_note.getIntrinsicTicks();
526
538
  const tick = note.getIntrinsicTicks();
527
- const beam_direction = this.lookupBeamDirection(duration, prev_tick, tick, next_tick);
539
+ const beam_direction = this.lookupBeamDirection(duration, prev_tick, tick, next_tick, i);
528
540
  if ([BEAM_LEFT, BEAM_BOTH].includes(beam_direction)) {
529
541
  current_beam.end = current_beam.start - partial_beam_length;
530
542
  }
@@ -562,6 +574,8 @@ export class Beam extends Element {
562
574
  this.notes.forEach((note) => {
563
575
  const stem = note.getStem();
564
576
  if (stem) {
577
+ const stem_x = note.getStemX();
578
+ stem.setNoteHeadXBounds(stem_x, stem_x);
565
579
  ctx.openGroup('stem', note.getAttribute('id') + '-stem');
566
580
  stem.setContext(ctx).draw();
567
581
  ctx.closeGroup();
@@ -327,9 +327,14 @@ export class Factory {
327
327
  return tuplet;
328
328
  }
329
329
  Beam(params) {
330
- var _a, _b, _c;
330
+ var _a, _b, _c, _d, _e;
331
331
  const beam = new Beam(params.notes, (_a = params.options) === null || _a === void 0 ? void 0 : _a.autoStem).setContext(this.context);
332
332
  beam.breakSecondaryAt((_c = (_b = params.options) === null || _b === void 0 ? void 0 : _b.secondaryBeamBreaks) !== null && _c !== void 0 ? _c : []);
333
+ if ((_d = params.options) === null || _d === void 0 ? void 0 : _d.partialBeamDirections) {
334
+ Object.entries((_e = params.options) === null || _e === void 0 ? void 0 : _e.partialBeamDirections).forEach(([noteIndex, direction]) => {
335
+ beam.setPartialBeamSideAt(Number(noteIndex), direction);
336
+ });
337
+ }
333
338
  this.renderQ.push(beam);
334
339
  return beam;
335
340
  }
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { Accidental } from './accidental.js';
11
- import { Annotation } from './annotation.js';
11
+ import { Annotation, AnnotationHorizontalJustify, AnnotationVerticalJustify } from './annotation.js';
12
12
  import { Articulation } from './articulation.js';
13
13
  import { BarNote } from './barnote.js';
14
14
  import { Beam } from './beam.js';
@@ -16,16 +16,16 @@ import { Bend } from './bend.js';
16
16
  import { BoundingBox } from './boundingbox.js';
17
17
  import { BoundingBoxComputation } from './boundingboxcomputation.js';
18
18
  import { CanvasContext } from './canvascontext.js';
19
- import { ChordSymbol } from './chordsymbol.js';
19
+ import { ChordSymbol, ChordSymbolHorizontalJustify, ChordSymbolVerticalJustify, SymbolModifiers, SymbolTypes, } from './chordsymbol.js';
20
20
  import { Clef } from './clef.js';
21
21
  import { ClefNote } from './clefnote.js';
22
22
  import { Crescendo } from './crescendo.js';
23
- import { Curve } from './curve.js';
23
+ import { Curve, CurvePosition } from './curve.js';
24
24
  import { Dot } from './dot.js';
25
25
  import { EasyScore } from './easyscore.js';
26
26
  import { Element } from './element.js';
27
27
  import { Factory } from './factory.js';
28
- import { Font } from './font.js';
28
+ import { Font, FontStyle, FontWeight } from './font.js';
29
29
  import { Formatter } from './formatter.js';
30
30
  import { Fraction } from './fraction.js';
31
31
  import { FretHandFinger } from './frethandfinger.js';
@@ -51,20 +51,20 @@ import { Parser } from './parser.js';
51
51
  import { PedalMarking } from './pedalmarking.js';
52
52
  import { Registry } from './registry.js';
53
53
  import { RenderContext } from './rendercontext.js';
54
- import { Renderer } from './renderer.js';
54
+ import { Renderer, RendererBackends, RendererLineEndType } from './renderer.js';
55
55
  import { RepeatNote } from './repeatnote.js';
56
56
  import { Stave } from './stave.js';
57
57
  import { Barline, BarlineType } from './stavebarline.js';
58
58
  import { StaveConnector } from './staveconnector.js';
59
59
  import { StaveHairpin } from './stavehairpin.js';
60
60
  import { StaveLine } from './staveline.js';
61
- import { StaveModifier } from './stavemodifier.js';
61
+ import { StaveModifier, StaveModifierPosition } from './stavemodifier.js';
62
62
  import { StaveNote } from './stavenote.js';
63
63
  import { Repetition } from './staverepetition.js';
64
64
  import { StaveTempo } from './stavetempo.js';
65
65
  import { StaveText } from './stavetext.js';
66
66
  import { StaveTie } from './stavetie.js';
67
- import { Volta } from './stavevolta.js';
67
+ import { Volta, VoltaType } from './stavevolta.js';
68
68
  import { Stem } from './stem.js';
69
69
  import { StringNumber } from './stringnumber.js';
70
70
  import { Stroke } from './strokes.js';
@@ -75,10 +75,10 @@ import { TabNote } from './tabnote.js';
75
75
  import { TabSlide } from './tabslide.js';
76
76
  import { TabStave } from './tabstave.js';
77
77
  import { TabTie } from './tabtie.js';
78
- import { TextBracket } from './textbracket.js';
78
+ import { TextBracket, TextBracketPosition } from './textbracket.js';
79
79
  import { TextDynamics } from './textdynamics.js';
80
80
  import { TextFormatter } from './textformatter.js';
81
- import { TextNote } from './textnote.js';
81
+ import { TextJustification, TextNote } from './textnote.js';
82
82
  import { TickContext } from './tickcontext.js';
83
83
  import { TimeSignature } from './timesignature.js';
84
84
  import { TimeSigNote } from './timesignote.js';
@@ -88,7 +88,7 @@ import { Tuplet } from './tuplet.js';
88
88
  import { DATE, ID, VERSION } from './version.js';
89
89
  import { Vibrato } from './vibrato.js';
90
90
  import { VibratoBracket } from './vibratobracket.js';
91
- import { Voice } from './voice.js';
91
+ import { Voice, VoiceMode } from './voice.js';
92
92
  export class Flow {
93
93
  static get BUILD() {
94
94
  return {
@@ -97,9 +97,6 @@ export class Flow {
97
97
  DATE: DATE,
98
98
  };
99
99
  }
100
- static get Flow() {
101
- return Flow;
102
- }
103
100
  static setMusicFont(...fontNames) {
104
101
  const fonts = fontNames.map((fontName) => Font.load(fontName));
105
102
  Tables.MUSIC_FONT_STACK = fonts;
@@ -271,5 +268,21 @@ Flow.Vibrato = Vibrato;
271
268
  Flow.VibratoBracket = VibratoBracket;
272
269
  Flow.Voice = Voice;
273
270
  Flow.Volta = Volta;
274
- Flow.BarlineType = BarlineType;
271
+ Flow.AnnotationHorizontalJustify = AnnotationHorizontalJustify;
272
+ Flow.AnnotationVerticalJustify = AnnotationVerticalJustify;
273
+ Flow.ChordSymbolHorizontalJustify = ChordSymbolHorizontalJustify;
274
+ Flow.ChordSymbolVerticalJustify = ChordSymbolVerticalJustify;
275
+ Flow.SymbolTypes = SymbolTypes;
276
+ Flow.SymbolModifiers = SymbolModifiers;
277
+ Flow.CurvePosition = CurvePosition;
278
+ Flow.FontWeight = FontWeight;
279
+ Flow.FontStyle = FontStyle;
275
280
  Flow.ModifierPosition = ModifierPosition;
281
+ Flow.RendererBackends = RendererBackends;
282
+ Flow.RendererLineEndType = RendererLineEndType;
283
+ Flow.BarlineType = BarlineType;
284
+ Flow.StaveModifierPosition = StaveModifierPosition;
285
+ Flow.VoltaType = VoltaType;
286
+ Flow.TextBracketPosition = TextBracketPosition;
287
+ Flow.TextJustification = TextJustification;
288
+ Flow.VoiceMode = VoiceMode;
@@ -188,8 +188,6 @@ export class Font {
188
188
  }
189
189
  });
190
190
  }
191
- static loadTextFonts() {
192
- }
193
191
  static load(fontName, data, metrics) {
194
192
  let font = Fonts[fontName];
195
193
  if (!font) {
@@ -387,9 +387,12 @@ export class Formatter {
387
387
  const musicFont = Tables.currentMusicFont();
388
388
  const configMinPadding = musicFont.lookupMetric('stave.endPaddingMin');
389
389
  const configMaxPadding = musicFont.lookupMetric('stave.endPaddingMax');
390
+ const leftPadding = musicFont.lookupMetric('stave.padding');
390
391
  let targetWidth = adjustedJustifyWidth;
391
392
  const distances = calculateIdealDistances(targetWidth);
392
393
  let actualWidth = shiftToIdealDistances(distances);
394
+ if (contextList.length === 1)
395
+ return 0;
393
396
  const calcMinDistance = (targetWidth, distances) => {
394
397
  let mdCalc = targetWidth / 2;
395
398
  if (distances.length > 1) {
@@ -400,14 +403,28 @@ export class Formatter {
400
403
  return mdCalc;
401
404
  };
402
405
  const minDistance = calcMinDistance(targetWidth, distances);
403
- if (contextList.length === 1)
404
- return 0;
405
- const paddingMax = configMaxPadding * 2 < minDistance ? minDistance : configMaxPadding;
406
- const paddingMin = paddingMax - (configMaxPadding - configMinPadding);
406
+ const paddingMaxCalc = (curTargetWidth) => {
407
+ let lastTickablePadding = 0;
408
+ const lastTickable = lastContext && lastContext.getMaxTickable();
409
+ if (lastTickable) {
410
+ const voice = lastTickable.getVoice();
411
+ if (voice.getTicksUsed().value() > voice.getTotalTicks().value()) {
412
+ return configMaxPadding * 2 < minDistance ? minDistance : configMaxPadding;
413
+ }
414
+ const tickWidth = lastTickable.getWidth();
415
+ lastTickablePadding =
416
+ voice.softmax(lastContext.getMaxTicks().value()) * curTargetWidth - (tickWidth + leftPadding);
417
+ }
418
+ return configMaxPadding * 2 < lastTickablePadding ? lastTickablePadding : configMaxPadding;
419
+ };
420
+ let paddingMax = paddingMaxCalc(targetWidth);
421
+ let paddingMin = paddingMax - (configMaxPadding - configMinPadding);
407
422
  const maxX = adjustedJustifyWidth - paddingMin;
408
423
  let iterations = maxIterations;
409
424
  while ((actualWidth > maxX && iterations > 0) || (actualWidth + paddingMax < maxX && iterations > 1)) {
410
425
  targetWidth -= actualWidth - maxX;
426
+ paddingMax = paddingMaxCalc(targetWidth);
427
+ paddingMin = paddingMax - (configMaxPadding - configMinPadding);
411
428
  actualWidth = shiftToIdealDistances(calculateIdealDistances(targetWidth));
412
429
  iterations--;
413
430
  }
@@ -246,10 +246,16 @@ export class Glyph extends Element {
246
246
  this.stave = stave;
247
247
  return this;
248
248
  }
249
+ getXShift() {
250
+ return this.x_shift;
251
+ }
249
252
  setXShift(x_shift) {
250
253
  this.x_shift = x_shift;
251
254
  return this;
252
255
  }
256
+ getYshift() {
257
+ return this.y_shift;
258
+ }
253
259
  setYShift(y_shift) {
254
260
  this.y_shift = y_shift;
255
261
  return this;
@@ -1,4 +1,3 @@
1
- import { Vex } from './vex.js';
2
1
  export * from './accidental.js';
3
2
  export * from './annotation.js';
4
3
  export * from './articulation.js';
@@ -83,9 +82,8 @@ export * from './tuning.js';
83
82
  export * from './tuplet.js';
84
83
  export * from './typeguard.js';
85
84
  export * from './util.js';
85
+ export * from './vex.js';
86
86
  export * from './vibrato.js';
87
87
  export * from './vibratobracket.js';
88
88
  export * from './voice.js';
89
89
  export * from './web.js';
90
- export { Vex };
91
- export default Vex;
@@ -299,7 +299,7 @@ export class Note extends Tickable {
299
299
  }
300
300
  getLeftParenthesisPx(index) {
301
301
  const props = this.getKeyProps()[index];
302
- return props.displaced ? this.getLeftDisplacedHeadPx() : 0;
302
+ return props.displaced ? this.getLeftDisplacedHeadPx() - this.x_shift : -this.x_shift;
303
303
  }
304
304
  getFirstDotPx() {
305
305
  let px = this.getRightDisplacedHeadPx();
@@ -179,8 +179,8 @@ export class Stave extends Element {
179
179
  this.modifiers.push(new Volta(type, number_t, this.x, y));
180
180
  return this;
181
181
  }
182
- setSection(section, y, xOffset = 0, fontSize) {
183
- const staveSection = new StaveSection(section, this.x + xOffset, y);
182
+ setSection(section, y, xOffset = 0, fontSize, drawRect = true) {
183
+ const staveSection = new StaveSection(section, this.x + xOffset, y, drawRect);
184
184
  if (fontSize)
185
185
  staveSection.setFontSize(fontSize);
186
186
  this.modifiers.push(staveSection);
@@ -33,12 +33,15 @@ export class StaveConnector extends Element {
33
33
  return "StaveConnector";
34
34
  }
35
35
  setType(type) {
36
- type = typeof type === 'string' ? StaveConnector.typeString[type] : type;
37
- if (type >= StaveConnector.type.SINGLE_RIGHT && type <= StaveConnector.type.NONE) {
38
- this.type = type;
36
+ const newType = typeof type === 'string' ? StaveConnector.typeString[type] : type;
37
+ if (Object.values(StaveConnector.type).includes(newType)) {
38
+ this.type = newType;
39
39
  }
40
40
  return this;
41
41
  }
42
+ getType() {
43
+ return this.type;
44
+ }
42
45
  setText(text, options = {}) {
43
46
  this.texts.push({
44
47
  content: text,
@@ -1,5 +1,6 @@
1
1
  import { Element } from './element.js';
2
2
  import { Tables } from './tables.js';
3
+ import { TextJustification } from './textnote.js';
3
4
  import { RuntimeError } from './util.js';
4
5
  function drawArrowHead(ctx, x0, y0, x1, y1, x2, y2) {
5
6
  ctx.beginPath();
@@ -211,8 +212,4 @@ StaveLine.TextVerticalPosition = {
211
212
  TOP: 1,
212
213
  BOTTOM: 2,
213
214
  };
214
- StaveLine.TextJustification = {
215
- LEFT: 1,
216
- CENTER: 2,
217
- RIGHT: 3,
218
- };
215
+ StaveLine.TextJustification = TextJustification;
@@ -116,7 +116,10 @@ export class StaveNote extends StemmableNote {
116
116
  let xShift = 0;
117
117
  if (voices === 2) {
118
118
  const lineSpacing = noteU.note.hasStem() && noteL.note.hasStem() && noteU.stemDirection === noteL.stemDirection ? 0.0 : 0.5;
119
- if (noteU.minLine <= noteL.maxLine + lineSpacing) {
119
+ if (noteL.isrest && noteU.isrest && noteU.note.duration === noteL.note.duration) {
120
+ noteL.note.render_options.draw = false;
121
+ }
122
+ else if (noteU.minLine <= noteL.maxLine + lineSpacing) {
120
123
  if (noteU.isrest) {
121
124
  shiftRestVertical(noteU, noteL, 1);
122
125
  }
@@ -174,7 +177,7 @@ export class StaveNote extends StemmableNote {
174
177
  }
175
178
  }
176
179
  }
177
- else {
180
+ else if (lineDiff < 1) {
178
181
  xShift = voiceXShift + 2;
179
182
  if (noteU.stemDirection === noteL.stemDirection) {
180
183
  noteU.note.setXShift(xShift);
@@ -183,6 +186,14 @@ export class StaveNote extends StemmableNote {
183
186
  noteL.note.setXShift(xShift);
184
187
  }
185
188
  }
189
+ else if (noteU.note.hasStem()) {
190
+ noteU.stemDirection = -noteU.note.getStemDirection();
191
+ noteU.note.setStemDirection(noteU.stemDirection);
192
+ }
193
+ else if (noteL.note.hasStem()) {
194
+ noteL.stemDirection = -noteL.note.getStemDirection();
195
+ noteL.note.setStemDirection(noteL.stemDirection);
196
+ }
186
197
  }
187
198
  }
188
199
  state.right_shift += xShift;
@@ -214,16 +225,16 @@ export class StaveNote extends StemmableNote {
214
225
  }
215
226
  }
216
227
  if (noteU.isrest && noteM.isrest && noteL.isrest) {
217
- shiftRestVertical(noteU, noteM, 1);
218
- shiftRestVertical(noteL, noteM, -1);
228
+ noteU.note.render_options.draw = false;
229
+ noteL.note.render_options.draw = false;
219
230
  state.right_shift += xShift;
220
231
  return true;
221
232
  }
222
233
  if (noteM.isrest && noteU.isrest && noteM.minLine <= noteL.maxLine) {
223
- shiftRestVertical(noteM, noteL, 1);
234
+ noteM.note.render_options.draw = false;
224
235
  }
225
236
  if (noteM.isrest && noteL.isrest && noteU.minLine <= noteM.maxLine) {
226
- shiftRestVertical(noteM, noteU, -1);
237
+ noteM.note.render_options.draw = false;
227
238
  }
228
239
  if (noteU.isrest && noteU.minLine <= noteM.maxLine) {
229
240
  shiftRestVertical(noteU, noteM, 1);
@@ -825,6 +836,8 @@ export class StaveNote extends StemmableNote {
825
836
  return super_stem_extension + lines_over_octave_from_mid_line * spacing_between_lines;
826
837
  }
827
838
  draw() {
839
+ if (this.render_options.draw === false)
840
+ return;
828
841
  if (this.ys.length === 0) {
829
842
  throw new RuntimeError('NoYValues', "Can't draw note without Y values.");
830
843
  }
@@ -1,13 +1,14 @@
1
1
  import { Font, FontStyle, FontWeight } from './font.js';
2
2
  import { StaveModifier } from './stavemodifier.js';
3
3
  export class StaveSection extends StaveModifier {
4
- constructor(section, x, shift_y) {
4
+ constructor(section, x, shift_y, drawRect = true) {
5
5
  super();
6
6
  this.setWidth(16);
7
7
  this.section = section;
8
8
  this.x = x;
9
9
  this.shift_x = 0;
10
10
  this.shift_y = shift_y;
11
+ this.drawRect = drawRect;
11
12
  this.resetFont();
12
13
  }
13
14
  static get CATEGORY() {
@@ -39,12 +40,14 @@ export class StaveSection extends StaveModifier {
39
40
  const textHeight = textMeasurements.height;
40
41
  const width = textWidth + 2 * paddingX;
41
42
  const height = textHeight + 2 * paddingY;
42
- const y = stave.getYForTopText(2) + this.shift_y;
43
+ const y = stave.getYForTopText(1.5) + this.shift_y;
43
44
  const x = this.x + shift_x;
44
- ctx.beginPath();
45
- ctx.setLineWidth(rectWidth);
46
- ctx.rect(x, y + textMeasurements.y - paddingY, width, height);
47
- ctx.stroke();
45
+ if (this.drawRect) {
46
+ ctx.beginPath();
47
+ ctx.setLineWidth(rectWidth);
48
+ ctx.rect(x, y + textMeasurements.y - paddingY, width, height);
49
+ ctx.stroke();
50
+ }
48
51
  ctx.fillText(this.section, x + paddingX, y);
49
52
  ctx.restore();
50
53
  return this;
@@ -1,6 +1,6 @@
1
1
  import { Font, FontStyle, FontWeight } from './font.js';
2
2
  import { StaveModifier, StaveModifierPosition } from './stavemodifier.js';
3
- import { Justification, TextNote } from './textnote.js';
3
+ import { TextJustification, TextNote } from './textnote.js';
4
4
  import { RuntimeError } from './util.js';
5
5
  export class StaveText extends StaveModifier {
6
6
  constructor(text, position, options = {}) {
@@ -53,10 +53,10 @@ export class StaveText extends StaveModifier {
53
53
  case StaveModifierPosition.ABOVE:
54
54
  case StaveModifierPosition.BELOW:
55
55
  x = stave.getX() + this.options.shift_x;
56
- if (this.options.justification === Justification.CENTER) {
56
+ if (this.options.justification === TextJustification.CENTER) {
57
57
  x += stave.getWidth() / 2 - text_width / 2;
58
58
  }
59
- else if (this.options.justification === Justification.RIGHT) {
59
+ else if (this.options.justification === TextJustification.RIGHT) {
60
60
  x += stave.getWidth() - text_width;
61
61
  }
62
62
  if (this.position === StaveModifierPosition.ABOVE) {
@@ -62,14 +62,7 @@ export class System extends Element {
62
62
  this.parts.forEach((part) => {
63
63
  y = y + part.stave.space(part.spaceAbove);
64
64
  part.stave.setY(y);
65
- if (this.options.autoWidth) {
66
- part.voices.forEach((voice) => {
67
- formatter.joinVoices([voice]);
68
- });
69
- }
70
- else {
71
- formatter.joinVoices(part.voices);
72
- }
65
+ formatter.joinVoices(part.voices);
73
66
  y = y + part.stave.space(part.spaceBelow);
74
67
  y = y + part.stave.space(this.options.spaceBetweenStaves);
75
68
  if (part.debugNoteMetrics) {