vexflow 4.0.2 → 4.0.3

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 (67) hide show
  1. package/README.md +3 -1
  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 +508 -265
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +232 -127
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow-font-bravura.js +1 -1
  11. package/build/cjs/vexflow-font-bravura.js.map +1 -1
  12. package/build/cjs/vexflow-font-gonville.js +1 -1
  13. package/build/cjs/vexflow-font-gonville.js.map +1 -1
  14. package/build/cjs/vexflow-font-petaluma.js +1 -1
  15. package/build/cjs/vexflow-font-petaluma.js.map +1 -1
  16. package/build/cjs/vexflow-gonville.js +2 -2
  17. package/build/cjs/vexflow-gonville.js.map +1 -1
  18. package/build/cjs/vexflow-petaluma.js +2 -2
  19. package/build/cjs/vexflow-petaluma.js.map +1 -1
  20. package/build/cjs/vexflow.js +2 -2
  21. package/build/cjs/vexflow.js.map +1 -1
  22. package/build/esm/src/annotation.js +1 -1
  23. package/build/esm/src/chordsymbol.js +33 -9
  24. package/build/esm/src/element.js +10 -0
  25. package/build/esm/src/factory.js +20 -2
  26. package/build/esm/src/flow.js +6 -0
  27. package/build/esm/src/fonts/bravura_metrics.js +12 -12
  28. package/build/esm/src/fonts/gonville_metrics.js +8 -8
  29. package/build/esm/src/fonts/petaluma_metrics.js +8 -8
  30. package/build/esm/src/formatter.js +1 -1
  31. package/build/esm/src/gracenotegroup.js +3 -2
  32. package/build/esm/src/ornament.js +6 -2
  33. package/build/esm/src/stavenote.js +34 -9
  34. package/build/esm/src/stemmablenote.js +1 -0
  35. package/build/esm/src/stringnumber.js +12 -5
  36. package/build/esm/src/tables.js +1 -0
  37. package/build/esm/src/version.js +3 -3
  38. package/build/esm/src/voice.js +4 -2
  39. package/build/esm/tests/chordsymbol_tests.js +91 -9
  40. package/build/esm/tests/ornament_tests.js +98 -94
  41. package/build/esm/tests/stavenote_tests.js +36 -0
  42. package/build/esm/tests/stringnumber_tests.js +28 -23
  43. package/build/types/src/chordsymbol.d.ts +1 -0
  44. package/build/types/src/element.d.ts +4 -1
  45. package/build/types/src/factory.d.ts +8 -4
  46. package/build/types/src/flow.d.ts +2 -0
  47. package/build/types/src/ornament.d.ts +1 -0
  48. package/build/types/src/stringnumber.d.ts +3 -1
  49. package/build/types/src/tables.d.ts +1 -0
  50. package/build/types/src/voice.d.ts +1 -3
  51. package/package.json +1 -1
  52. package/src/annotation.ts +1 -1
  53. package/src/chordsymbol.ts +35 -10
  54. package/src/element.ts +13 -1
  55. package/src/factory.ts +30 -3
  56. package/src/flow.ts +8 -0
  57. package/src/fonts/bravura_metrics.ts +12 -12
  58. package/src/fonts/gonville_metrics.ts +8 -8
  59. package/src/fonts/petaluma_metrics.ts +8 -8
  60. package/src/formatter.ts +1 -1
  61. package/src/gracenotegroup.ts +5 -2
  62. package/src/ornament.ts +6 -2
  63. package/src/stavenote.ts +36 -8
  64. package/src/stemmablenote.ts +1 -0
  65. package/src/stringnumber.ts +15 -6
  66. package/src/tables.ts +1 -0
  67. package/src/voice.ts +2 -3
@@ -21,6 +21,7 @@ import { ModifierContext } from './modifiercontext';
21
21
  import { MultiMeasureRest, MultimeasureRestRenderOptions } from './multimeasurerest';
22
22
  import { Note, NoteStruct } from './note';
23
23
  import { NoteSubGroup } from './notesubgroup';
24
+ import { Ornament } from './ornament';
24
25
  import { PedalMarking } from './pedalmarking';
25
26
  import { RenderContext } from './rendercontext';
26
27
  import { RepeatNote } from './repeatnote';
@@ -160,6 +161,12 @@ export declare class Factory {
160
161
  type?: string;
161
162
  position?: string | number;
162
163
  }): Articulation;
164
+ Ornament(type: string, params?: {
165
+ position?: string | number;
166
+ upperAccidental?: string;
167
+ lowerAccidental?: string;
168
+ delayed?: boolean;
169
+ }): Ornament;
163
170
  TextDynamics(params?: {
164
171
  text?: string;
165
172
  duration?: string;
@@ -173,15 +180,12 @@ export declare class Factory {
173
180
  StringNumber(params: {
174
181
  number: string;
175
182
  position: string;
176
- }): StringNumber;
183
+ }, drawCircle?: boolean): StringNumber;
177
184
  TickContext(): TickContext;
178
185
  ModifierContext(): ModifierContext;
179
186
  MultiMeasureRest(params: MultimeasureRestRenderOptions): MultiMeasureRest;
180
187
  Voice(params?: {
181
188
  time?: VoiceTime | string;
182
- options?: {
183
- softmaxFactor: number;
184
- };
185
189
  }): Voice;
186
190
  StaveConnector(params: {
187
191
  top_stave: Stave;
@@ -217,6 +217,8 @@ export declare class Flow {
217
217
  */
218
218
  static fetchMusicFont(fontName: string, fontModuleOrPath?: string | FontModule): Promise<void>;
219
219
  static getMusicFont(): string[];
220
+ static get SOFTMAX_FACTOR(): number;
221
+ static set SOFTMAX_FACTOR(factor: number);
220
222
  static get NOTATION_FONT_SCALE(): number;
221
223
  static set NOTATION_FONT_SCALE(value: number);
222
224
  static get TABLATURE_FONT_SCALE(): number;
@@ -13,6 +13,7 @@ export declare class Ornament extends Modifier {
13
13
  static DEBUG: boolean;
14
14
  /** Ornaments category string. */
15
15
  static get CATEGORY(): string;
16
+ static get minPadding(): number;
16
17
  protected ornament: {
17
18
  code: string;
18
19
  };
@@ -7,7 +7,8 @@ export declare class StringNumber extends Modifier {
7
7
  static TEXT_FONT: Required<FontInfo>;
8
8
  static get metrics(): any;
9
9
  static format(nums: StringNumber[], state: ModifierContextState): boolean;
10
- radius: number;
10
+ protected radius: number;
11
+ protected drawCircle: boolean;
11
12
  protected last_note?: Note;
12
13
  protected string_number: string;
13
14
  protected x_offset: number;
@@ -23,5 +24,6 @@ export declare class StringNumber extends Modifier {
23
24
  setOffsetY(y: number): this;
24
25
  setLastNote(note: Note): this;
25
26
  setDashed(dashed: boolean): this;
27
+ setDrawCircle(drawCircle: boolean): this;
26
28
  draw(): void;
27
29
  }
@@ -2,6 +2,7 @@ import { ArticulationStruct } from './articulation';
2
2
  import { Font } from './font';
3
3
  import { Fraction } from './fraction';
4
4
  export declare class Tables {
5
+ static SOFTMAX_FACTOR: number;
5
6
  static STEM_WIDTH: number;
6
7
  static STEM_HEIGHT: number;
7
8
  static STAVE_LINE_THICKNESS: number;
@@ -41,9 +41,7 @@ export declare class Voice extends Element {
41
41
  protected readonly largestTickWidth: number;
42
42
  protected readonly tickables: Tickable[];
43
43
  protected readonly time: Required<VoiceTime>;
44
- constructor(time?: VoiceTime | string, options?: {
45
- softmaxFactor: number;
46
- });
44
+ constructor(time?: VoiceTime | string);
47
45
  /** Get the total ticks in the voice. */
48
46
  getTotalTicks(): Fraction;
49
47
  /** Get the total ticks used in the voice by all the tickables. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vexflow",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "A JavaScript library for rendering music notation and guitar tablature.",
5
5
  "exports": {
6
6
  ".": {
package/src/annotation.ts CHANGED
@@ -97,7 +97,7 @@ export class Annotation extends Modifier {
97
97
  maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
98
98
  leftWidth = Math.max(leftWidth, textWidth) + Annotation.minAnnotationPadding;
99
99
  } else if (annotation.horizontalJustification === AnnotationHorizontalJustify.RIGHT) {
100
- maxRightGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
100
+ maxRightGlyphWidth = Math.max(glyphWidth, maxRightGlyphWidth);
101
101
  rightWidth = Math.max(rightWidth, textWidth);
102
102
  } else {
103
103
  leftWidth = Math.max(leftWidth, textWidth / 2) + Annotation.minAnnotationPadding;
@@ -13,10 +13,11 @@ import { Font, FontInfo, FontStyle, FontWeight } from './font';
13
13
  import { Glyph } from './glyph';
14
14
  import { Modifier } from './modifier';
15
15
  import { ModifierContextState } from './modifiercontext';
16
+ import { Note } from './note';
16
17
  import { StemmableNote } from './stemmablenote';
17
18
  import { Tables } from './tables';
18
19
  import { TextFormatter } from './textformatter';
19
- import { Category } from './typeguard';
20
+ import { Category, isStemmableNote } from './typeguard';
20
21
  import { log } from './util';
21
22
 
22
23
  // To enable logging for this class. Set `Vex.Flow.ChordSymbol.DEBUG` to `true`.
@@ -247,6 +248,10 @@ export class ChordSymbol extends Modifier {
247
248
  return block.symbolModifier !== undefined && block.symbolModifier === SymbolModifiers.SUBSCRIPT;
248
249
  }
249
250
 
251
+ static get minPadding(): number {
252
+ const musicFont = Tables.currentMusicFont();
253
+ return musicFont.lookupMetric('glyphs.noteHead.minPadding');
254
+ }
250
255
  /**
251
256
  * Estimate the width of the whole chord symbol, based on the sum of the widths of the individual blocks.
252
257
  * Estimate how many lines above/below the staff we need.
@@ -256,12 +261,17 @@ export class ChordSymbol extends Modifier {
256
261
 
257
262
  let width = 0;
258
263
  let nonSuperWidth = 0;
259
- const reportedWidths = [];
264
+ let leftWidth = 0;
265
+ let rightWidth = 0;
266
+ let maxLeftGlyphWidth = 0;
267
+ let maxRightGlyphWidth = 0;
260
268
 
261
269
  for (const symbol of symbols) {
262
270
  const fontSize = Font.convertSizeToPointValue(symbol.textFont?.size);
263
271
  const fontAdj = Font.scaleSize(fontSize, 0.05);
264
272
  const glyphAdj = fontAdj * 2;
273
+ const note: Note = symbol.checkAttachedNote();
274
+ let symbolWidth = 0;
265
275
  let lineSpaces = 1;
266
276
  let vAlign = false;
267
277
 
@@ -323,6 +333,7 @@ export class ChordSymbol extends Modifier {
323
333
  }
324
334
  block.vAlign = vAlign;
325
335
  width += block.width;
336
+ symbolWidth = width;
326
337
  }
327
338
 
328
339
  // make kerning adjustments after computing super/subscripts
@@ -336,17 +347,31 @@ export class ChordSymbol extends Modifier {
336
347
  symbol.setTextLine(state.text_line + 1);
337
348
  state.text_line += lineSpaces + 1;
338
349
  }
339
- if (symbol.getReportWidth()) {
340
- reportedWidths.push(width);
341
- } else {
342
- reportedWidths.push(0);
350
+ if (symbol.getReportWidth() && isStemmableNote(note)) {
351
+ const glyphWidth = note.getGlyph().getWidth();
352
+ if (symbol.getHorizontal() === ChordSymbolHorizontalJustify.LEFT) {
353
+ maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
354
+ leftWidth = Math.max(leftWidth, symbolWidth) + ChordSymbol.minPadding;
355
+ } else if (symbol.getHorizontal() === ChordSymbolHorizontalJustify.RIGHT) {
356
+ maxRightGlyphWidth = Math.max(glyphWidth, maxRightGlyphWidth);
357
+ rightWidth = Math.max(rightWidth, symbolWidth);
358
+ } else {
359
+ leftWidth = Math.max(leftWidth, symbolWidth / 2) + ChordSymbol.minPadding;
360
+ rightWidth = Math.max(rightWidth, symbolWidth / 2);
361
+ maxLeftGlyphWidth = Math.max(glyphWidth / 2, maxLeftGlyphWidth);
362
+ maxRightGlyphWidth = Math.max(glyphWidth / 2, maxRightGlyphWidth);
363
+ }
343
364
  }
365
+ width = 0; // reset symbol width
344
366
  }
367
+ const rightOverlap = Math.min(
368
+ Math.max(rightWidth - maxRightGlyphWidth, 0),
369
+ Math.max(rightWidth - state.right_shift, 0)
370
+ );
371
+ const leftOverlap = Math.min(Math.max(leftWidth - maxLeftGlyphWidth, 0), Math.max(leftWidth - state.left_shift, 0));
345
372
 
346
- width = reportedWidths.reduce((a, b) => a + b, 0);
347
-
348
- state.left_shift += width / 2;
349
- state.right_shift += width / 2;
373
+ state.left_shift += leftOverlap;
374
+ state.right_shift += rightOverlap;
350
375
  return true;
351
376
  }
352
377
 
package/src/element.ts CHANGED
@@ -67,6 +67,7 @@ export abstract class Element {
67
67
  return Category.Element;
68
68
  }
69
69
 
70
+ protected children: Element[] = [];
70
71
  protected static ID: number = 1000;
71
72
  protected static newID(): string {
72
73
  return `auto${Element.ID++}`;
@@ -111,7 +112,11 @@ export abstract class Element {
111
112
  Registry.getDefaultRegistry()?.register(this);
112
113
  }
113
114
 
114
- /** Get element category string. */
115
+ addChildElement(child: Element): this {
116
+ this.children.push(child);
117
+ return this;
118
+ }
119
+
115
120
  getCategory(): string {
116
121
  return (<typeof Element>this.constructor).CATEGORY;
117
122
  }
@@ -143,6 +148,13 @@ export abstract class Element {
143
148
  return this;
144
149
  }
145
150
 
151
+ /** Set the element & associated children style used for rendering. */
152
+ setGroupStyle(style: ElementStyle): this {
153
+ this.style = style;
154
+ this.children.forEach((child) => child.setGroupStyle(style));
155
+ return this;
156
+ }
157
+
146
158
  /** Get the element style used for rendering. */
147
159
  getStyle(): ElementStyle | undefined {
148
160
  return this.style;
package/src/factory.ts CHANGED
@@ -25,6 +25,7 @@ import { ModifierContext } from './modifiercontext';
25
25
  import { MultiMeasureRest, MultimeasureRestRenderOptions } from './multimeasurerest';
26
26
  import { Note, NoteStruct } from './note';
27
27
  import { NoteSubGroup } from './notesubgroup';
28
+ import { Ornament } from './ornament';
28
29
  import { PedalMarking } from './pedalmarking';
29
30
  import { RenderContext } from './rendercontext';
30
31
  import { Renderer } from './renderer';
@@ -403,6 +404,31 @@ export class Factory {
403
404
  return articulation;
404
405
  }
405
406
 
407
+ Ornament(
408
+ type: string,
409
+ params?: { position?: string | number; upperAccidental?: string; lowerAccidental?: string; delayed?: boolean }
410
+ ) {
411
+ const options = {
412
+ type,
413
+ position: 0,
414
+ accidental: '',
415
+ ...params,
416
+ };
417
+ const ornament = new Ornament(type);
418
+ ornament.setPosition(options.position);
419
+ if (options.upperAccidental) {
420
+ ornament.setUpperAccidental(options.upperAccidental);
421
+ }
422
+ if (options.lowerAccidental) {
423
+ ornament.setLowerAccidental(options.lowerAccidental);
424
+ }
425
+ if (typeof options.delayed !== 'undefined') {
426
+ ornament.setDelayed(options.delayed);
427
+ }
428
+ ornament.setContext(this.context);
429
+ return ornament;
430
+ }
431
+
406
432
  TextDynamics(params?: { text?: string; duration?: string; dots?: number; line?: number }): TextDynamics {
407
433
  const p = {
408
434
  text: 'p',
@@ -438,10 +464,11 @@ export class Factory {
438
464
  return fingering;
439
465
  }
440
466
 
441
- StringNumber(params: { number: string; position: string }): StringNumber {
467
+ StringNumber(params: { number: string; position: string }, drawCircle = true): StringNumber {
442
468
  const stringNumber = new StringNumber(params.number);
443
469
  stringNumber.setPosition(params.position);
444
470
  stringNumber.setContext(this.context);
471
+ stringNumber.setDrawCircle(drawCircle);
445
472
  return stringNumber;
446
473
  }
447
474
 
@@ -461,12 +488,12 @@ export class Factory {
461
488
  return multiMeasureRest;
462
489
  }
463
490
 
464
- Voice(params?: { time?: VoiceTime | string; options?: { softmaxFactor: number } }): Voice {
491
+ Voice(params?: { time?: VoiceTime | string }): Voice {
465
492
  const p = {
466
493
  time: '4/4',
467
494
  ...params,
468
495
  };
469
- const voice = new Voice(p.time, p.options);
496
+ const voice = new Voice(p.time);
470
497
  this.voices.push(voice);
471
498
  return voice;
472
499
  }
package/src/flow.ts CHANGED
@@ -250,6 +250,14 @@ export class Flow {
250
250
  return fonts.map((font) => font.getName());
251
251
  }
252
252
 
253
+ static get SOFTMAX_FACTOR(): number {
254
+ return Tables.SOFTMAX_FACTOR;
255
+ }
256
+
257
+ static set SOFTMAX_FACTOR(factor: number) {
258
+ Tables.SOFTMAX_FACTOR = factor;
259
+ }
260
+
253
261
  static get NOTATION_FONT_SCALE(): number {
254
262
  return Tables.NOTATION_FONT_SCALE;
255
263
  }
@@ -459,21 +459,21 @@ export const BravuraMetrics = {
459
459
  xOffset: -12,
460
460
  yOffset: 0,
461
461
  stemUpYOffset: 0,
462
- reportedWidth: 10,
462
+ reportedWidth: 20,
463
463
  },
464
464
  brassDoitMedium: {
465
465
  scale: 1.0,
466
466
  xOffset: 16,
467
467
  yOffset: 0,
468
468
  stemUpYOffset: 0,
469
- reportedWidth: 15,
469
+ reportedWidth: 22,
470
470
  },
471
471
  brassFallLipShort: {
472
472
  scale: 1.0,
473
473
  xOffset: 16,
474
474
  yOffset: 0,
475
475
  stemUpYOffset: 0,
476
- reportedWidth: 5,
476
+ reportedWidth: 15,
477
477
  },
478
478
  brassLiftMedium: {
479
479
  scale: 1.0,
@@ -513,22 +513,22 @@ export const BravuraMetrics = {
513
513
  brassFlip: {
514
514
  scale: 1.0,
515
515
  xOffset: 10,
516
- yOffset: -4,
517
- stemUpYOffset: 0,
518
- reportedWidth: 5,
516
+ yOffset: 0,
517
+ stemUpYOffset: 7,
518
+ reportedWidth: 10,
519
519
  },
520
520
  brassJazzTurn: {
521
521
  scale: 1.0,
522
- xOffset: 6,
523
- yOffset: -4,
524
- stemUpYOffset: 0,
525
- reportedWidth: 5,
522
+ xOffset: 0,
523
+ yOffset: 0,
524
+ stemUpYOffset: 8,
525
+ reportedWidth: 31,
526
526
  },
527
527
  brassSmear: {
528
528
  scale: 1.0,
529
529
  xOffset: 10,
530
- yOffset: -4,
531
- stemUpYOffset: 0,
530
+ yOffset: 0,
531
+ stemUpYOffset: 8,
532
532
  reportedWidth: 5,
533
533
  },
534
534
  },
@@ -356,21 +356,21 @@ export const GonvilleMetrics = {
356
356
  xOffset: -12,
357
357
  yOffset: 0,
358
358
  stemUpYOffset: 0,
359
- reportedWidth: 10,
359
+ reportedWidth: 15,
360
360
  },
361
361
  brassDoitMedium: {
362
362
  scale: 1.0,
363
363
  xOffset: 16,
364
364
  yOffset: 0,
365
365
  stemUpYOffset: 0,
366
- reportedWidth: 5,
366
+ reportedWidth: 22,
367
367
  },
368
368
  brassFallLipShort: {
369
369
  scale: 1.0,
370
370
  xOffset: 17,
371
371
  yOffset: 0,
372
372
  stemUpYOffset: 0,
373
- reportedWidth: 5,
373
+ reportedWidth: 15,
374
374
  },
375
375
  brassLiftMedium: {
376
376
  scale: 1.0,
@@ -411,21 +411,21 @@ export const GonvilleMetrics = {
411
411
  scale: 1.0,
412
412
  xOffset: 10,
413
413
  yOffset: -4,
414
- stemUpYOffset: 0,
414
+ stemUpYOffset: 7,
415
415
  reportedWidth: 5,
416
416
  },
417
417
  brassJazzTurn: {
418
418
  scale: 1.0,
419
- xOffset: 6,
419
+ xOffset: 3,
420
420
  yOffset: -4,
421
- stemUpYOffset: 0,
422
- reportedWidth: 5,
421
+ stemUpYOffset: 10,
422
+ reportedWidth: 28,
423
423
  },
424
424
  brassSmear: {
425
425
  scale: 1.0,
426
426
  xOffset: 10,
427
427
  yOffset: -4,
428
- stemUpYOffset: 0,
428
+ stemUpYOffset: 9,
429
429
  reportedWidth: 5,
430
430
  },
431
431
  },
@@ -487,28 +487,28 @@ export const PetalumaMetrics = {
487
487
  xOffset: -12,
488
488
  yOffset: 0,
489
489
  stemUpYOffset: 0,
490
- reportedWidth: 10,
490
+ reportedWidth: 15,
491
491
  },
492
492
  brassDoitMedium: {
493
493
  scale: 1.0,
494
494
  xOffset: 16,
495
495
  yOffset: 0,
496
496
  stemUpYOffset: 0,
497
- reportedWidth: 5,
497
+ reportedWidth: 19,
498
498
  },
499
499
  brassFallLipShort: {
500
500
  scale: 1.0,
501
501
  xOffset: 16,
502
502
  yOffset: 0,
503
503
  stemUpYOffset: 0,
504
- reportedWidth: 5,
504
+ reportedWidth: 19,
505
505
  },
506
506
  brassLiftMedium: {
507
507
  scale: 1.0,
508
508
  xOffset: 16,
509
509
  yOffset: 5,
510
510
  stemUpYOffset: 0,
511
- reportedWidth: 5,
511
+ reportedWidth: 15,
512
512
  },
513
513
  brassFallRoughMedium: {
514
514
  scale: 1.0,
@@ -542,21 +542,21 @@ export const PetalumaMetrics = {
542
542
  scale: 1.0,
543
543
  xOffset: 10,
544
544
  yOffset: -4,
545
- stemUpYOffset: 0,
545
+ stemUpYOffset: 7,
546
546
  reportedWidth: 5,
547
547
  },
548
548
  brassJazzTurn: {
549
549
  scale: 1.0,
550
550
  xOffset: 6,
551
551
  yOffset: -4,
552
- stemUpYOffset: 0,
553
- reportedWidth: 5,
552
+ stemUpYOffset: 5,
553
+ reportedWidth: 30,
554
554
  },
555
555
  brassSmear: {
556
556
  scale: 1.0,
557
557
  xOffset: 10,
558
558
  yOffset: -4,
559
- stemUpYOffset: 0,
559
+ stemUpYOffset: 5,
560
560
  reportedWidth: 5,
561
561
  },
562
562
  },
package/src/formatter.ts CHANGED
@@ -396,7 +396,7 @@ export class Formatter {
396
396
  constructor(options?: FormatterOptions) {
397
397
  this.formatterOptions = {
398
398
  globalSoftmax: false,
399
- softmaxFactor: 100,
399
+ softmaxFactor: Tables.SOFTMAX_FACTOR,
400
400
  maxIterations: 5,
401
401
  ...options,
402
402
  };
@@ -11,6 +11,7 @@ import { Modifier } from './modifier';
11
11
  import { ModifierContextState } from './modifiercontext';
12
12
  import { Note } from './note';
13
13
  import { RenderContext } from './rendercontext';
14
+ import { StaveNote } from './stavenote';
14
15
  import { StaveTie } from './stavetie';
15
16
  import { StemmableNote } from './stemmablenote';
16
17
  import { Tables } from './tables';
@@ -84,7 +85,9 @@ export class GraceNoteGroup extends Modifier {
84
85
  for (let i = 0; i < group_list.length; ++i) {
85
86
  const gracenote_group = group_list[i].gracenote_group;
86
87
  formatWidth = gracenote_group.getWidth() + group_list[i].spacing;
87
- gracenote_group.setSpacingFromNextModifier(group_shift - Math.min(formatWidth, group_shift));
88
+ gracenote_group.setSpacingFromNextModifier(
89
+ group_shift - Math.min(formatWidth, group_shift) + StaveNote.minNoteheadPadding
90
+ );
88
91
  }
89
92
 
90
93
  state.left_shift += group_shift;
@@ -150,7 +153,7 @@ export class GraceNoteGroup extends Modifier {
150
153
  }
151
154
 
152
155
  getWidth(): number {
153
- return this.width;
156
+ return this.width + StaveNote.minNoteheadPadding;
154
157
  }
155
158
 
156
159
  getGraceNotes(): Note[] {
package/src/ornament.ts CHANGED
@@ -32,6 +32,10 @@ export class Ornament extends Modifier {
32
32
  static get CATEGORY(): string {
33
33
  return Category.Ornament;
34
34
  }
35
+ static get minPadding(): number {
36
+ const musicFont = Tables.currentMusicFont();
37
+ return musicFont.lookupMetric('glyphs.noteHead.minPadding');
38
+ }
35
39
 
36
40
  protected ornament: {
37
41
  code: string;
@@ -74,8 +78,8 @@ export class Ornament extends Modifier {
74
78
  }
75
79
  if (ornament.reportedWidth && ornament.x_shift < 0) {
76
80
  left_shift += ornament.reportedWidth;
77
- } else if (ornament.reportedWidth && ornament.x_shift > 0) {
78
- right_shift += ornament.reportedWidth;
81
+ } else if (ornament.reportedWidth && ornament.x_shift >= 0) {
82
+ right_shift += ornament.reportedWidth + Ornament.minPadding;
79
83
  } else {
80
84
  width = Math.max(ornament.getWidth(), width);
81
85
  }
package/src/stavenote.ts CHANGED
@@ -164,11 +164,41 @@ export class StaveNote extends StemmableNote {
164
164
  });
165
165
  }
166
166
 
167
- const voices = notesList.length;
167
+ let voices = 0;
168
+ let noteU = undefined;
169
+ let noteM = undefined;
170
+ let noteL = undefined;
171
+ const draw = [false, false, false];
172
+
173
+ for (let i = 0; i < notesList.length; i++) {
174
+ draw[i] = notesList[i].note.render_options.draw == false ? false : true;
175
+ }
168
176
 
169
- let noteU = notesList[0];
170
- const noteM = voices > 2 ? notesList[1] : undefined;
171
- let noteL = voices > 2 ? notesList[2] : notesList[1];
177
+ if (draw[0] && draw[1] && draw[2]) {
178
+ // Three visible notes
179
+ voices = 3;
180
+ noteU = notesList[0];
181
+ noteM = notesList[1];
182
+ noteL = notesList[2];
183
+ } else if (draw[0] && draw[1]) {
184
+ // Two visible notes, 0 & 1
185
+ voices = 2;
186
+ noteU = notesList[0];
187
+ noteL = notesList[1];
188
+ } else if (draw[0] && draw[2]) {
189
+ // Two visible notes, 0 & 2
190
+ voices = 2;
191
+ noteU = notesList[0];
192
+ noteL = notesList[2];
193
+ } else if (draw[1] && draw[2]) {
194
+ // Two visible notes, 1 & 2
195
+ voices = 2;
196
+ noteU = notesList[1];
197
+ noteL = notesList[2];
198
+ } else {
199
+ // No shift required for less than 2 visible notes
200
+ return true;
201
+ }
172
202
 
173
203
  // for two voice backward compatibility, ensure upper voice is stems up
174
204
  // for three voices, the voices must be in order (upper, middle, lower)
@@ -512,6 +542,7 @@ export class StaveNote extends StemmableNote {
512
542
  line: noteProps.line,
513
543
  });
514
544
 
545
+ this.addChildElement(notehead);
515
546
  this._noteHeads[i] = notehead;
516
547
  }
517
548
  }
@@ -814,10 +845,7 @@ export class StaveNote extends StemmableNote {
814
845
  // Sets the style of the complete StaveNote, including all keys
815
846
  // and the stem.
816
847
  setStyle(style: ElementStyle): this {
817
- super.setStyle(style);
818
- this._noteHeads.forEach((notehead) => notehead.setStyle(style));
819
- if (this.stem) this.stem.setStyle(style);
820
- return this;
848
+ return super.setGroupStyle(style);
821
849
  }
822
850
 
823
851
  setStemStyle(style: ElementStyle): this {
@@ -40,6 +40,7 @@ export abstract class StemmableNote extends Note {
40
40
 
41
41
  setStem(stem: Stem): this {
42
42
  this.stem = stem;
43
+ this.addChildElement(stem);
43
44
  return this;
44
45
  }
45
46