vexflow 4.0.1-alpha.2 → 4.0.1-beta.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 (76) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +345 -115
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +247 -78
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow-font-bravura.js +1 -1
  10. package/build/cjs/vexflow-font-bravura.js.map +1 -1
  11. package/build/cjs/vexflow-font-gonville.js +1 -1
  12. package/build/cjs/vexflow-font-gonville.js.map +1 -1
  13. package/build/cjs/vexflow-font-petaluma.js +1 -1
  14. package/build/cjs/vexflow-font-petaluma.js.map +1 -1
  15. package/build/cjs/vexflow-gonville.js +2 -2
  16. package/build/cjs/vexflow-gonville.js.map +1 -1
  17. package/build/cjs/vexflow-petaluma.js +2 -2
  18. package/build/cjs/vexflow-petaluma.js.map +1 -1
  19. package/build/cjs/vexflow.js +2 -2
  20. package/build/cjs/vexflow.js.map +1 -1
  21. package/build/esm/src/accidental.js +1 -1
  22. package/build/esm/src/annotation.js +24 -5
  23. package/build/esm/src/articulation.js +5 -2
  24. package/build/esm/src/beam.js +4 -0
  25. package/build/esm/src/fonts/bravura_metrics.js +8 -5
  26. package/build/esm/src/fonts/gonville_glyphs.js +4 -4
  27. package/build/esm/src/fonts/gonville_metrics.js +8 -2
  28. package/build/esm/src/fonts/petaluma_metrics.js +8 -5
  29. package/build/esm/src/gracenote.js +2 -0
  30. package/build/esm/src/note.js +1 -1
  31. package/build/esm/src/stavenote.js +88 -22
  32. package/build/esm/src/staverepetition.js +8 -8
  33. package/build/esm/src/stavetie.js +2 -0
  34. package/build/esm/src/stemmablenote.js +4 -2
  35. package/build/esm/src/tables.js +36 -0
  36. package/build/esm/src/tabnote.js +12 -9
  37. package/build/esm/src/version.js +3 -3
  38. package/build/esm/tests/articulation_tests.js +11 -24
  39. package/build/esm/tests/formatter_tests.js +2 -2
  40. package/build/esm/tests/gracenote_tests.js +43 -0
  41. package/build/esm/tests/ornament_tests.js +0 -1
  42. package/build/esm/tests/stavenote_tests.js +32 -0
  43. package/build/types/entry/vexflow-font-bravura.d.ts +8 -5
  44. package/build/types/entry/vexflow-font-gonville.d.ts +8 -2
  45. package/build/types/entry/vexflow-font-petaluma.d.ts +8 -5
  46. package/build/types/src/fonts/bravura_metrics.d.ts +8 -5
  47. package/build/types/src/fonts/gonville_metrics.d.ts +8 -2
  48. package/build/types/src/fonts/petaluma_metrics.d.ts +8 -5
  49. package/build/types/src/glyph.d.ts +4 -0
  50. package/build/types/src/note.d.ts +1 -0
  51. package/build/types/src/stavenote.d.ts +2 -0
  52. package/build/types/src/stem.d.ts +4 -1
  53. package/build/types/src/stemmablenote.d.ts +4 -1
  54. package/build/types/src/tabnote.d.ts +4 -1
  55. package/package.json +1 -1
  56. package/src/accidental.ts +1 -1
  57. package/src/annotation.ts +27 -6
  58. package/src/articulation.ts +8 -2
  59. package/src/beam.ts +4 -0
  60. package/src/fonts/bravura_metrics.ts +8 -5
  61. package/src/fonts/gonville_glyphs.ts +4 -4
  62. package/src/fonts/gonville_metrics.ts +8 -2
  63. package/src/fonts/petaluma_metrics.ts +8 -5
  64. package/src/glyph.ts +4 -0
  65. package/src/gracenote.ts +4 -1
  66. package/src/note.ts +2 -2
  67. package/src/stavenote.ts +97 -21
  68. package/src/staverepetition.ts +8 -8
  69. package/src/stavetie.ts +8 -0
  70. package/src/stem.ts +1 -1
  71. package/src/stemmablenote.ts +6 -4
  72. package/src/tables.ts +36 -0
  73. package/src/tabnote.ts +16 -13
  74. package/build/esm/src/publicpath.js +0 -1
  75. package/build/types/src/publicpath.d.ts +0 -0
  76. package/src/publicpath.ts +0 -0
@@ -47,7 +47,7 @@ export class Accidental extends Modifier {
47
47
  const props = note.getKeyProps()[index];
48
48
  if (note !== prevNote) {
49
49
  for (let n = 0; n < note.keys.length; ++n) {
50
- shiftL = Math.max(note.getLeftDisplacedHeadPx(), shiftL);
50
+ shiftL = Math.max(note.getLeftDisplacedHeadPx() - note.getXShift(), shiftL);
51
51
  }
52
52
  prevNote = note;
53
53
  }
@@ -38,13 +38,32 @@ export class Annotation extends Modifier {
38
38
  static format(annotations, state) {
39
39
  if (!annotations || annotations.length === 0)
40
40
  return false;
41
- let width = 0;
41
+ let leftWidth = 0;
42
+ let rightWidth = 0;
43
+ let maxLeftGlyphWidth = 0;
44
+ let maxRightGlyphWidth = 0;
42
45
  for (let i = 0; i < annotations.length; ++i) {
43
46
  const annotation = annotations[i];
44
47
  const textFormatter = TextFormatter.create(annotation.textFont);
45
48
  const textLines = (5 + textFormatter.maxHeight) / Tables.STAVE_LINE_DISTANCE;
46
49
  let verticalSpaceNeeded = textLines;
47
50
  const note = annotation.checkAttachedNote();
51
+ const glyphWidth = note.getGlyph().getWidth();
52
+ const textWidth = textFormatter.getWidthForTextInPx(annotation.text);
53
+ if (annotation.horizontalJustification === AnnotationHorizontalJustify.LEFT) {
54
+ maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
55
+ leftWidth = Math.max(leftWidth, textWidth);
56
+ }
57
+ else if (annotation.horizontalJustification === AnnotationHorizontalJustify.RIGHT) {
58
+ maxRightGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
59
+ rightWidth = Math.max(rightWidth, textWidth);
60
+ }
61
+ else {
62
+ leftWidth = Math.max(leftWidth, textWidth / 2);
63
+ rightWidth = Math.max(rightWidth, textWidth / 2);
64
+ maxLeftGlyphWidth = Math.max(glyphWidth / 2, maxLeftGlyphWidth);
65
+ maxRightGlyphWidth = Math.max(glyphWidth / 2, maxRightGlyphWidth);
66
+ }
48
67
  const stave = note.getStave();
49
68
  const stemDirection = note.hasStem() ? note.getStemDirection() : Stem.UP;
50
69
  let stemHeight = 0;
@@ -69,8 +88,6 @@ export class Annotation extends Modifier {
69
88
  if (stave) {
70
89
  lines = stave.getNumLines();
71
90
  }
72
- const textWidth = textFormatter.getWidthForTextInPx(annotation.text);
73
- width = Math.max(width, textWidth);
74
91
  if (annotation.verticalJustification === this.VerticalJustify.TOP) {
75
92
  let noteLine = note.getLineNumber(true);
76
93
  if (isTabNote(note)) {
@@ -113,8 +130,10 @@ export class Annotation extends Modifier {
113
130
  annotation.setTextLine(state.text_line);
114
131
  }
115
132
  }
116
- state.left_shift += width / 2;
117
- state.right_shift += width / 2;
133
+ const rightOverlap = Math.min(Math.max(rightWidth - maxRightGlyphWidth, 0), Math.max(rightWidth - state.right_shift, 0));
134
+ 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;
118
137
  return true;
119
138
  }
120
139
  setVerticalJustification(just) {
@@ -144,9 +144,11 @@ export class Articulation extends Modifier {
144
144
  if (!articulations || articulations.length === 0)
145
145
  return false;
146
146
  const margin = 0.5;
147
+ let maxGlyphWidth = 0;
147
148
  const getIncrement = (articulation, line, position) => roundToNearestHalf(getRoundingFunction(line, position), defined(articulation.glyph.getMetrics().height) / 10 + margin);
148
149
  articulations.forEach((articulation) => {
149
150
  const note = articulation.checkAttachedNote();
151
+ maxGlyphWidth = Math.max(note.getGlyph().getWidth(), maxGlyphWidth);
150
152
  let lines = 5;
151
153
  const stemDirection = note.hasStem() ? note.getStemDirection() : Stem.UP;
152
154
  let stemHeight = 0;
@@ -190,8 +192,9 @@ export class Articulation extends Modifier {
190
192
  const width = articulations
191
193
  .map((articulation) => articulation.getWidth())
192
194
  .reduce((maxWidth, articWidth) => Math.max(articWidth, maxWidth));
193
- state.left_shift += width / 2;
194
- state.right_shift += width / 2;
195
+ const overlap = Math.min(Math.max(width - maxGlyphWidth, 0), Math.max(width - (state.left_shift + state.right_shift), 0));
196
+ state.left_shift += overlap / 2;
197
+ state.right_shift += overlap / 2;
195
198
  return true;
196
199
  }
197
200
  static easyScoreHook({ articulations }, note, builder) {
@@ -562,7 +562,9 @@ export class Beam extends Element {
562
562
  this.notes.forEach((note) => {
563
563
  const stem = note.getStem();
564
564
  if (stem) {
565
+ ctx.openGroup('stem', note.getAttribute('id') + '-stem');
565
566
  stem.setContext(ctx).draw();
567
+ ctx.closeGroup();
566
568
  }
567
569
  }, this);
568
570
  }
@@ -582,6 +584,7 @@ export class Beam extends Element {
582
584
  const lastBeamX = beam_line.end;
583
585
  if (lastBeamX) {
584
586
  const lastBeamY = this.getSlopeY(lastBeamX, firstStemX, beamY, this.slope);
587
+ this.setAttribute('el', ctx.openGroup('beam'));
585
588
  ctx.beginPath();
586
589
  ctx.moveTo(startBeamX, startBeamY);
587
590
  ctx.lineTo(startBeamX, startBeamY + beamThickness);
@@ -589,6 +592,7 @@ export class Beam extends Element {
589
592
  ctx.lineTo(lastBeamX + 1, lastBeamY);
590
593
  ctx.closePath();
591
594
  ctx.fill();
595
+ ctx.closeGroup();
592
596
  }
593
597
  else {
594
598
  throw new RuntimeError('NoLastBeamX', 'lastBeamX undefined.');
@@ -124,11 +124,17 @@ export const BravuraMetrics = {
124
124
  },
125
125
  },
126
126
  staveRepetition: {
127
- default: {
127
+ symbolText: {
128
+ offsetX: 12,
128
129
  offsetY: 25,
129
- offsetSymbol: 12,
130
130
  spacing: 5,
131
131
  },
132
+ coda: {
133
+ offsetY: 25,
134
+ },
135
+ segno: {
136
+ offsetY: 10,
137
+ },
132
138
  },
133
139
  stem: {
134
140
  heightAdjustmentForFlag: -3,
@@ -182,9 +188,6 @@ export const BravuraMetrics = {
182
188
  },
183
189
  flag: {
184
190
  shiftX: -0.75,
185
- tabStem: {
186
- shiftX: -1.75,
187
- },
188
191
  staveTempo: {
189
192
  shiftX: -1,
190
193
  },
@@ -697,10 +697,10 @@ export const GonvilleFont = {
697
697
  o: 'm -413 173 b -408 174 -412 174 -409 174 b -397 173 -404 174 -400 173 b -308 86 -394 172 -374 151 b -223 0 -261 37 -223 0 b -153 84 -223 0 -191 37 b -77 174 -83 173 -84 172 b -72 174 -76 174 -74 174 b -62 173 -68 174 -63 173 b 25 86 -59 172 -39 151 b 112 0 73 37 111 0 b 181 84 112 0 144 37 b 257 174 251 173 251 172 b 262 174 258 174 261 174 b 273 173 266 174 270 173 b 436 9 276 172 347 101 l 447 -1 l 477 36 b 522 79 511 79 513 79 l 522 79 b 552 51 533 79 539 73 b 596 -112 582 6 596 -51 b 567 -262 596 -161 586 -213 b 539 -322 558 -287 544 -316 b 524 -327 534 -326 529 -327 b 504 -315 515 -327 507 -323 b 503 -308 503 -312 503 -309 b 511 -285 503 -302 504 -297 b 555 -113 540 -227 555 -169 b 544 -34 555 -86 551 -59 b 522 19 540 -16 530 8 l 521 22 l 481 -26 l 405 -122 b 353 -176 366 -172 362 -176 b 349 -176 352 -176 351 -176 b 253 -87 341 -176 347 -180 b 167 0 206 -38 167 0 b 99 -86 167 0 136 -38 b 21 -174 27 -174 28 -173 b 17 -176 20 -176 19 -176 b 6 -174 13 -176 9 -174 b -81 -87 4 -173 -14 -152 b -167 0 -129 -38 -167 0 b -236 -86 -167 0 -198 -38 b -313 -174 -307 -174 -306 -173 b -318 -176 -314 -176 -315 -176 b -328 -174 -321 -176 -325 -174 b -491 -12 -330 -173 -367 -137 l -503 0 l -530 -34 b -570 -77 -562 -73 -564 -76 b -577 -79 -571 -79 -574 -79 b -597 -58 -588 -79 -597 -69 b -596 -49 -597 -55 -597 -52 b -417 172 -593 -43 -423 167 b -413 173 -417 172 -415 173 ',
698
698
  },
699
699
  stringsDownBow: {
700
- x_min: -149.71875,
701
- x_max: 148.359375,
702
- ha: 151,
703
- o: 'm -9 215 b 0 217 -6 217 -4 217 b 19 205 8 217 14 213 b 20 142 20 202 20 201 l 20 84 l 23 84 b 144 -27 81 74 129 30 b 148 -66 147 -40 148 -54 b 36 -213 148 -134 103 -197 b 0 -219 24 -217 12 -219 b -145 -104 -68 -219 -129 -173 b -149 -68 -148 -91 -149 -79 b -24 84 -149 6 -98 74 l -21 84 l -21 142 b -19 205 -20 201 -20 202 b -9 215 -17 209 -13 213 m -21 -15 b -23 41 -21 37 -21 41 b -23 41 -23 41 -23 41 b -76 11 -35 40 -62 26 b -108 -65 -98 -11 -108 -38 b -1 -176 -108 -122 -65 -176 b 107 -65 63 -176 107 -122 b 74 11 107 -38 96 -11 b 20 41 61 26 32 41 b 20 -15 20 41 20 15 b 19 -74 20 -72 20 -72 b 0 -87 14 -83 6 -87 b -19 -74 -8 -87 -16 -83 b -21 -15 -20 -72 -20 -72 ',
700
+ x_min: -228.671875,
701
+ x_max: 227.3125,
702
+ ha: 232,
703
+ o: 'm -217 487 l -213 488 l 0 488 l 212 488 l 216 487 b 225 476 220 484 224 480 l 227 473 l 227 244 l 227 15 l 225 12 b 206 0 223 4 215 0 b 197 1 204 0 200 0 b 187 12 193 4 189 6 l 186 15 l 186 138 l 186 262 l -1 262 l -187 262 l -187 138 l -187 15 l -189 12 b -208 0 -193 4 -200 0 b -227 12 -216 0 -223 4 l -228 15 l -228 244 l -228 473 l -227 476 b -217 487 -225 480 -221 484 ',
704
704
  },
705
705
  stringsUpBow: {
706
706
  x_min: -149.71875,
@@ -114,11 +114,17 @@ export const GonvilleMetrics = {
114
114
  },
115
115
  },
116
116
  staveRepetition: {
117
- default: {
117
+ symbolText: {
118
+ offsetX: 12,
118
119
  offsetY: 25,
119
- offsetSymbol: 12,
120
120
  spacing: 5,
121
121
  },
122
+ coda: {
123
+ offsetY: 25,
124
+ },
125
+ segno: {
126
+ offsetY: 0,
127
+ },
122
128
  },
123
129
  stem: {
124
130
  heightAdjustmentForFlag: -3,
@@ -124,11 +124,17 @@ export const PetalumaMetrics = {
124
124
  },
125
125
  },
126
126
  staveRepetition: {
127
- default: {
127
+ symbolText: {
128
+ offsetX: 12,
128
129
  offsetY: 25,
129
- offsetSymbol: 12,
130
130
  spacing: 5,
131
131
  },
132
+ coda: {
133
+ offsetY: 25,
134
+ },
135
+ segno: {
136
+ offsetY: 10,
137
+ },
132
138
  },
133
139
  noteHead: {
134
140
  displaced: {
@@ -211,9 +217,6 @@ export const PetalumaMetrics = {
211
217
  flag128thDown: {
212
218
  shiftX: -1.2,
213
219
  },
214
- tabStem: {
215
- shiftX: -1.75,
216
- },
217
220
  staveTempo: {
218
221
  shiftX: -1,
219
222
  },
@@ -63,8 +63,10 @@ export class GraceNote extends StaveNote {
63
63
  let y = stem_direction === Stem.DOWN
64
64
  ? noteHeadBounds.y_top - noteStemHeight
65
65
  : noteHeadBounds.y_bottom - noteStemHeight;
66
+ const defaultStemExtention = stem_direction === Stem.DOWN ? this.glyph.stem_down_extension : this.glyph.stem_up_extension;
66
67
  let defaultOffsetY = Tables.STEM_HEIGHT;
67
68
  defaultOffsetY -= defaultOffsetY / 2.8;
69
+ defaultOffsetY += defaultStemExtention;
68
70
  y += defaultOffsetY * staveNoteScale * stem_direction;
69
71
  const offsets = stem_direction === Stem.UP
70
72
  ? {
@@ -282,7 +282,7 @@ export class Note extends Tickable {
282
282
  return this;
283
283
  }
284
284
  getModifiersByType(type) {
285
- return this.checkModifierContext().getMembers(type);
285
+ return this.modifiers.filter((modifier) => modifier.getCategory() === type);
286
286
  }
287
287
  getModifierStartXY(position, index, options) {
288
288
  if (!this.preFormatted) {
@@ -115,7 +115,7 @@ export class StaveNote extends StemmableNote {
115
115
  const voiceXShift = Math.max(noteU.voice_shift, noteL.voice_shift);
116
116
  let xShift = 0;
117
117
  if (voices === 2) {
118
- const lineSpacing = noteU.stemDirection === noteL.stemDirection ? 0.0 : 0.5;
118
+ const lineSpacing = noteU.note.hasStem() && noteL.note.hasStem() && noteU.stemDirection === noteL.stemDirection ? 0.0 : 0.5;
119
119
  if (noteU.minLine <= noteL.maxLine + lineSpacing) {
120
120
  if (noteU.isrest) {
121
121
  shiftRestVertical(noteU, noteL, 1);
@@ -123,13 +123,66 @@ export class StaveNote extends StemmableNote {
123
123
  else if (noteL.isrest) {
124
124
  shiftRestVertical(noteL, noteU, -1);
125
125
  }
126
- else if (noteU.stemDirection === noteL.stemDirection) {
127
- xShift = voiceXShift + 2;
128
- noteU.note.setXShift(xShift);
129
- }
130
126
  else {
131
- xShift = voiceXShift + 2;
132
- noteL.note.setXShift(xShift);
127
+ const lineDiff = Math.abs(noteU.line - noteL.line);
128
+ if (noteU.note.hasStem() && noteL.note.hasStem()) {
129
+ let whiteNoteHeadCount = 0;
130
+ let blackNoteHeadCount = 0;
131
+ if (Tables.durationToNumber(noteU.note.duration) === 2) {
132
+ whiteNoteHeadCount++;
133
+ }
134
+ else if (Tables.durationToNumber(noteU.note.duration) > 2) {
135
+ blackNoteHeadCount++;
136
+ }
137
+ if (Tables.durationToNumber(noteL.note.duration) === 2) {
138
+ whiteNoteHeadCount++;
139
+ }
140
+ else if (Tables.durationToNumber(noteL.note.duration) > 2) {
141
+ blackNoteHeadCount++;
142
+ }
143
+ if ((whiteNoteHeadCount !== 2 && blackNoteHeadCount !== 2) ||
144
+ noteU.note.getModifiersByType("Dot").length !== noteL.note.getModifiersByType("Dot").length) {
145
+ xShift = voiceXShift + 2;
146
+ if (noteU.stemDirection === noteL.stemDirection) {
147
+ noteU.note.setXShift(xShift);
148
+ }
149
+ else {
150
+ noteL.note.setXShift(xShift);
151
+ }
152
+ }
153
+ else if (lineDiff < 1 && lineDiff > 0) {
154
+ xShift = voiceXShift + 2;
155
+ if (noteU.stemDirection === noteL.stemDirection) {
156
+ noteU.note.setXShift(xShift);
157
+ }
158
+ else {
159
+ noteL.note.setXShift(xShift);
160
+ }
161
+ }
162
+ else if (noteU.note.voice !== noteL.note.voice) {
163
+ if (noteU.stemDirection === noteL.stemDirection) {
164
+ if (noteU.line != noteL.line) {
165
+ xShift = voiceXShift + 2;
166
+ noteU.note.setXShift(xShift);
167
+ }
168
+ else {
169
+ if (noteL.stemDirection === 1) {
170
+ noteL.stemDirection = -1;
171
+ noteL.note.setStemDirection(-1);
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+ else {
178
+ xShift = voiceXShift + 2;
179
+ if (noteU.stemDirection === noteL.stemDirection) {
180
+ noteU.note.setXShift(xShift);
181
+ }
182
+ else {
183
+ noteL.note.setXShift(xShift);
184
+ }
185
+ }
133
186
  }
134
187
  }
135
188
  state.right_shift += xShift;
@@ -500,15 +553,16 @@ export class StaveNote extends StemmableNote {
500
553
  };
501
554
  }
502
555
  setStyle(style) {
503
- var _a;
504
556
  super.setStyle(style);
505
557
  this._noteHeads.forEach((notehead) => notehead.setStyle(style));
506
- (_a = this.stem) === null || _a === void 0 ? void 0 : _a.setStyle(style);
558
+ if (this.stem)
559
+ this.stem.setStyle(style);
507
560
  return this;
508
561
  }
509
562
  setStemStyle(style) {
510
563
  const stem = this.getStem();
511
- stem === null || stem === void 0 ? void 0 : stem.setStyle(style);
564
+ if (stem)
565
+ stem.setStyle(style);
512
566
  return this;
513
567
  }
514
568
  getStemStyle() {
@@ -688,7 +742,7 @@ export class StaveNote extends StemmableNote {
688
742
  return hasStem && hasFlag && hasNoBeam;
689
743
  }
690
744
  drawFlag() {
691
- var _a;
745
+ var _a, _b, _c, _d, _e;
692
746
  const ctx = this.checkContext();
693
747
  if (!ctx) {
694
748
  throw new RuntimeError('NoCanvasContext', "Can't draw without a canvas context.");
@@ -697,15 +751,22 @@ export class StaveNote extends StemmableNote {
697
751
  const { y_top, y_bottom } = this.getNoteHeadBounds();
698
752
  const noteStemHeight = this.stem.getHeight();
699
753
  const flagX = this.getStemX();
700
- const extension = this.flag !== undefined ? this.flag.checkMetrics().y_shift : 0;
701
754
  const flagY = this.getStemDirection() === Stem.DOWN
702
755
  ?
703
- y_top - noteStemHeight + 2 - extension
756
+ y_top -
757
+ noteStemHeight +
758
+ 2 -
759
+ (this.glyph ? this.glyph.stem_down_extension : 0) * this.getStaveNoteScale() -
760
+ ((_b = (_a = this.flag) === null || _a === void 0 ? void 0 : _a.getMetrics().y_shift) !== null && _b !== void 0 ? _b : 0) * (1 - this.getStaveNoteScale())
704
761
  :
705
- y_bottom - noteStemHeight - 2 - extension;
762
+ y_bottom -
763
+ noteStemHeight -
764
+ 2 +
765
+ (this.glyph ? this.glyph.stem_up_extension : 0) * this.getStaveNoteScale() -
766
+ ((_d = (_c = this.flag) === null || _c === void 0 ? void 0 : _c.getMetrics().y_shift) !== null && _d !== void 0 ? _d : 0) * (1 - this.getStaveNoteScale());
706
767
  ctx.openGroup('flag', undefined, { pointerBBox: true });
707
768
  this.applyStyle(ctx, this.getFlagStyle());
708
- (_a = this.flag) === null || _a === void 0 ? void 0 : _a.render(ctx, flagX, flagY);
769
+ (_e = this.flag) === null || _e === void 0 ? void 0 : _e.render(ctx, flagX, flagY);
709
770
  this.restoreStyle(ctx, this.getFlagStyle());
710
771
  ctx.closeGroup();
711
772
  }
@@ -719,7 +780,6 @@ export class StaveNote extends StemmableNote {
719
780
  });
720
781
  }
721
782
  drawStem(stemOptions) {
722
- var _a;
723
783
  const ctx = this.checkContext();
724
784
  if (stemOptions) {
725
785
  this.setStem(new Stem(stemOptions));
@@ -727,9 +787,14 @@ export class StaveNote extends StemmableNote {
727
787
  if (this.shouldDrawFlag() && this.stem) {
728
788
  this.stem.adjustHeightForFlag();
729
789
  }
730
- ctx.openGroup('stem', undefined, { pointerBBox: true });
731
- (_a = this.stem) === null || _a === void 0 ? void 0 : _a.setContext(ctx).draw();
732
- ctx.closeGroup();
790
+ if (this.stem) {
791
+ ctx.openGroup('stem', undefined, { pointerBBox: true });
792
+ this.stem.setContext(ctx).draw();
793
+ ctx.closeGroup();
794
+ }
795
+ }
796
+ getStaveNoteScale() {
797
+ return 1.0;
733
798
  }
734
799
  getStemExtension() {
735
800
  const super_stem_extension = super.getStemExtension();
@@ -760,7 +825,6 @@ export class StaveNote extends StemmableNote {
760
825
  return super_stem_extension + lines_over_octave_from_mid_line * spacing_between_lines;
761
826
  }
762
827
  draw() {
763
- var _a;
764
828
  if (this.ys.length === 0) {
765
829
  throw new RuntimeError('NoYValues', "Can't draw note without Y values.");
766
830
  }
@@ -768,8 +832,10 @@ export class StaveNote extends StemmableNote {
768
832
  const xBegin = this.getNoteHeadBeginX();
769
833
  const shouldRenderStem = this.hasStem() && !this.beam;
770
834
  this._noteHeads.forEach((notehead) => notehead.setX(xBegin));
771
- const stemX = this.getStemX();
772
- (_a = this.stem) === null || _a === void 0 ? void 0 : _a.setNoteHeadXBounds(stemX, stemX);
835
+ if (this.stem) {
836
+ const stemX = this.getStemX();
837
+ this.stem.setNoteHeadXBounds(stemX, stemX);
838
+ }
773
839
  L('Rendering ', this.isChord() ? 'chord :' : 'note :', this.keys);
774
840
  this.applyStyle();
775
841
  this.setAttribute('el', ctx.openGroup('stavenote', this.getAttribute('id')));
@@ -68,12 +68,12 @@ export class Repetition extends StaveModifier {
68
68
  }
69
69
  drawCodaFixed(stave, x) {
70
70
  const y = stave.getYForTopText(stave.getNumLines()) + this.y_shift;
71
- Glyph.renderGlyph(stave.checkContext(), this.x + x + this.x_shift, y + Tables.currentMusicFont().lookupMetric('staveRepetition.default.offsetY'), 40, 'coda', { category: 'coda' });
71
+ Glyph.renderGlyph(stave.checkContext(), this.x + x + this.x_shift, y + Tables.currentMusicFont().lookupMetric('staveRepetition.coda.offsetY'), 40, 'coda', { category: 'coda' });
72
72
  return this;
73
73
  }
74
74
  drawSignoFixed(stave, x) {
75
75
  const y = stave.getYForTopText(stave.getNumLines()) + this.y_shift;
76
- Glyph.renderGlyph(stave.checkContext(), this.x + x + this.x_shift, y + Tables.currentMusicFont().lookupMetric('staveRepetition.default.offsetY'), 30, 'segno', { category: 'segno' });
76
+ Glyph.renderGlyph(stave.checkContext(), this.x + x + this.x_shift, y + Tables.currentMusicFont().lookupMetric('staveRepetition.segno.offsetY'), 30, 'segno', { category: 'segno' });
77
77
  return this;
78
78
  }
79
79
  drawSymbolText(stave, x, text, draw_coda) {
@@ -89,7 +89,7 @@ export class Repetition extends StaveModifier {
89
89
  symbol_x =
90
90
  text_x +
91
91
  ctx.measureText(text).width +
92
- Tables.currentMusicFont().lookupMetric('staveRepetition.default.offsetSymbol');
92
+ Tables.currentMusicFont().lookupMetric('staveRepetition.symbolText.offsetX');
93
93
  break;
94
94
  case Repetition.type.DC:
95
95
  case Repetition.type.DC_AL_FINE:
@@ -101,7 +101,7 @@ export class Repetition extends StaveModifier {
101
101
  x +
102
102
  this.x_shift +
103
103
  stave.getWidth() -
104
- Tables.currentMusicFont().lookupMetric('staveRepetition.default.spacing') -
104
+ Tables.currentMusicFont().lookupMetric('staveRepetition.symbolText.spacing') -
105
105
  modifierWidth -
106
106
  ctx.measureText(text).width;
107
107
  break;
@@ -111,19 +111,19 @@ export class Repetition extends StaveModifier {
111
111
  x +
112
112
  this.x_shift +
113
113
  stave.getWidth() -
114
- Tables.currentMusicFont().lookupMetric('staveRepetition.default.spacing') -
114
+ Tables.currentMusicFont().lookupMetric('staveRepetition.symbolText.spacing') -
115
115
  modifierWidth -
116
116
  ctx.measureText(text).width -
117
- Tables.currentMusicFont().lookupMetric('staveRepetition.default.offsetSymbol');
117
+ Tables.currentMusicFont().lookupMetric('staveRepetition.symbolText.offsetX');
118
118
  symbol_x =
119
119
  text_x +
120
120
  ctx.measureText(text).width +
121
- Tables.currentMusicFont().lookupMetric('staveRepetition.default.offsetSymbol');
121
+ Tables.currentMusicFont().lookupMetric('staveRepetition.symbolText.offsetX');
122
122
  break;
123
123
  }
124
124
  const y = stave.getYForTopText(stave.getNumLines()) +
125
125
  this.y_shift +
126
- Tables.currentMusicFont().lookupMetric('staveRepetition.default.offsetY');
126
+ Tables.currentMusicFont().lookupMetric('staveRepetition.symbolText.offsetY');
127
127
  if (draw_coda) {
128
128
  Glyph.renderGlyph(ctx, symbol_x, y, 40, 'coda', { category: 'coda' });
129
129
  }
@@ -67,12 +67,14 @@ export class StaveTie extends Element {
67
67
  }
68
68
  const top_cp_y = (first_y_px + last_y_px) / 2 + cp1 * params.direction;
69
69
  const bottom_cp_y = (first_y_px + last_y_px) / 2 + cp2 * params.direction;
70
+ this.setAttribute('el', ctx.openGroup('stavetie'));
70
71
  ctx.beginPath();
71
72
  ctx.moveTo(params.first_x_px + first_x_shift, first_y_px);
72
73
  ctx.quadraticCurveTo(cp_x, top_cp_y, params.last_x_px + last_x_shift, last_y_px);
73
74
  ctx.quadraticCurveTo(cp_x, bottom_cp_y, params.first_x_px + first_x_shift, first_y_px);
74
75
  ctx.closePath();
75
76
  ctx.fill();
77
+ ctx.closeGroup();
76
78
  }
77
79
  }
78
80
  renderText(first_x_px, last_x_px) {
@@ -136,8 +136,10 @@ export class StemmableNote extends Note {
136
136
  if (this.beam) {
137
137
  return glyph.stem_beam_extension;
138
138
  }
139
- const flagCode = this.getStemDirection() === Stem.DOWN ? this.glyph.code_flag_downstem : this.glyph.code_flag_upstem;
140
- return Math.abs(Tables.currentMusicFont().lookupMetric(`glyphs.flag.${flagCode}.shiftY`, 0));
139
+ if (glyph) {
140
+ return this.getStemDirection() === Stem.UP ? glyph.stem_up_extension : glyph.stem_down_extension;
141
+ }
142
+ return 0;
141
143
  }
142
144
  setStemLength(height) {
143
145
  this.stem_extension_override = height - Stem.HEIGHT;
@@ -715,6 +715,10 @@ const durationCodes = {
715
715
  stem: false,
716
716
  stem_offset: 0,
717
717
  flag: false,
718
+ stem_up_extension: -Tables.STEM_HEIGHT,
719
+ stem_down_extension: -Tables.STEM_HEIGHT,
720
+ tabnote_stem_up_extension: -Tables.STEM_HEIGHT,
721
+ tabnote_stem_down_extension: -Tables.STEM_HEIGHT,
718
722
  dot_shiftY: 0,
719
723
  line_above: 0,
720
724
  line_below: 0,
@@ -750,6 +754,10 @@ const durationCodes = {
750
754
  stem: false,
751
755
  stem_offset: 0,
752
756
  flag: false,
757
+ stem_up_extension: -Tables.STEM_HEIGHT,
758
+ stem_down_extension: -Tables.STEM_HEIGHT,
759
+ tabnote_stem_up_extension: -Tables.STEM_HEIGHT,
760
+ tabnote_stem_down_extension: -Tables.STEM_HEIGHT,
753
761
  dot_shiftY: 0,
754
762
  line_above: 0,
755
763
  line_below: 0,
@@ -785,6 +793,10 @@ const durationCodes = {
785
793
  stem: true,
786
794
  stem_offset: 0,
787
795
  flag: false,
796
+ stem_up_extension: 0,
797
+ stem_down_extension: 0,
798
+ tabnote_stem_up_extension: 0,
799
+ tabnote_stem_down_extension: 0,
788
800
  dot_shiftY: 0,
789
801
  line_above: 0,
790
802
  line_below: 0,
@@ -821,6 +833,10 @@ const durationCodes = {
821
833
  stem: true,
822
834
  stem_offset: 0,
823
835
  flag: false,
836
+ stem_up_extension: 0,
837
+ stem_down_extension: 0,
838
+ tabnote_stem_up_extension: 0,
839
+ tabnote_stem_down_extension: 0,
824
840
  dot_shiftY: 0,
825
841
  line_above: 0,
826
842
  line_below: 0,
@@ -862,6 +878,10 @@ const durationCodes = {
862
878
  stem_beam_extension: 0,
863
879
  code_flag_upstem: 'flag8thUp',
864
880
  code_flag_downstem: 'flag8thDown',
881
+ stem_up_extension: 0,
882
+ stem_down_extension: 0,
883
+ tabnote_stem_up_extension: 0,
884
+ tabnote_stem_down_extension: 0,
865
885
  dot_shiftY: 0,
866
886
  line_above: 0,
867
887
  line_below: 0,
@@ -904,6 +924,10 @@ const durationCodes = {
904
924
  flag: true,
905
925
  code_flag_upstem: 'flag16thUp',
906
926
  code_flag_downstem: 'flag16thDown',
927
+ stem_up_extension: 0,
928
+ stem_down_extension: 0,
929
+ tabnote_stem_up_extension: 0,
930
+ tabnote_stem_down_extension: 0,
907
931
  dot_shiftY: 0,
908
932
  line_above: 0,
909
933
  line_below: 0,
@@ -946,6 +970,10 @@ const durationCodes = {
946
970
  flag: true,
947
971
  code_flag_upstem: 'flag32ndUp',
948
972
  code_flag_downstem: 'flag32ndDown',
973
+ stem_up_extension: 9,
974
+ stem_down_extension: 9,
975
+ tabnote_stem_up_extension: 9,
976
+ tabnote_stem_down_extension: 9,
949
977
  dot_shiftY: 0,
950
978
  line_above: 0,
951
979
  line_below: 0,
@@ -988,6 +1016,10 @@ const durationCodes = {
988
1016
  flag: true,
989
1017
  code_flag_upstem: 'flag64thUp',
990
1018
  code_flag_downstem: 'flag64thDown',
1019
+ stem_up_extension: 13,
1020
+ stem_down_extension: 13,
1021
+ tabnote_stem_up_extension: 13,
1022
+ tabnote_stem_down_extension: 13,
991
1023
  dot_shiftY: 0,
992
1024
  line_above: 0,
993
1025
  line_below: 0,
@@ -1030,6 +1062,10 @@ const durationCodes = {
1030
1062
  flag: true,
1031
1063
  code_flag_upstem: 'flag128thUp',
1032
1064
  code_flag_downstem: 'flag128thDown',
1065
+ stem_up_extension: 22,
1066
+ stem_down_extension: 22,
1067
+ tabnote_stem_up_extension: 22,
1068
+ tabnote_stem_down_extension: 22,
1033
1069
  dot_shiftY: 0,
1034
1070
  line_above: 0,
1035
1071
  line_below: 0,
@@ -106,11 +106,12 @@ export class TabNote extends StemmableNote {
106
106
  return false;
107
107
  }
108
108
  getStemExtension() {
109
+ const glyph = this.getGlyph();
109
110
  if (this.stem_extension_override != null) {
110
111
  return this.stem_extension_override;
111
112
  }
112
- if (this.flag) {
113
- return this.getStemDirection() === 1 ? -this.flag.checkMetrics().y_shift : this.flag.checkMetrics().y_shift;
113
+ if (glyph) {
114
+ return this.getStemDirection() === Stem.UP ? glyph.tabnote_stem_up_extension : glyph.tabnote_stem_down_extension;
114
115
  }
115
116
  return 0;
116
117
  }
@@ -204,16 +205,18 @@ export class TabNote extends StemmableNote {
204
205
  return this.checkStem().getExtents();
205
206
  }
206
207
  drawFlag() {
207
- const { beam, glyph, stem_direction, render_options: { draw_stem, glyph_font_scale }, } = this;
208
+ var _a;
209
+ const { beam, glyph, render_options: { draw_stem }, } = this;
208
210
  const context = this.checkContext();
209
211
  const shouldDrawFlag = beam == undefined && draw_stem;
210
212
  if (glyph.flag && shouldDrawFlag) {
211
- const flag_x = this.getStemX() + 1;
212
- const flag_y = this.getStemY() - this.checkStem().getHeight();
213
- const flag_code = stem_direction === Stem.DOWN
214
- ? glyph.code_flag_downstem
215
- : glyph.code_flag_upstem;
216
- Glyph.renderGlyph(context, flag_x, flag_y, glyph_font_scale, flag_code, { category: 'flag.tabStem' });
213
+ const flag_x = this.getStemX();
214
+ const flag_y = this.getStemDirection() === Stem.DOWN
215
+ ?
216
+ this.getStemY() - this.checkStem().getHeight() - (this.glyph ? this.glyph.stem_down_extension : 0)
217
+ :
218
+ this.getStemY() - this.checkStem().getHeight() + (this.glyph ? this.glyph.stem_up_extension : 0);
219
+ (_a = this.flag) === null || _a === void 0 ? void 0 : _a.render(context, flag_x, flag_y);
217
220
  }
218
221
  }
219
222
  drawModifiers() {