vexflow 5.0.0-alpha.4 → 5.0.0-beta.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.
- package/README.md +6 -6
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +1546 -1393
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +600 -549
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/annotation.js +0 -2
- package/build/esm/src/barnote.js +3 -3
- package/build/esm/src/beam.js +2 -4
- package/build/esm/src/bend.js +11 -3
- package/build/esm/src/chordsymbol.js +0 -4
- package/build/esm/src/clef.js +0 -2
- package/build/esm/src/curve.js +8 -5
- package/build/esm/src/element.js +11 -17
- package/build/esm/src/factory.js +4 -4
- package/build/esm/src/flag.js +20 -0
- package/build/esm/src/formatter.js +4 -4
- package/build/esm/src/glyphnote.js +0 -2
- package/build/esm/src/gracenote.js +0 -2
- package/build/esm/src/gracenotegroup.js +17 -8
- package/build/esm/src/index.js +1 -0
- package/build/esm/src/keysignature.js +38 -31
- package/build/esm/src/keysignote.js +1 -1
- package/build/esm/src/metrics.js +55 -7
- package/build/esm/src/modifier.js +4 -2
- package/build/esm/src/notehead.js +6 -1
- package/build/esm/src/ornament.js +0 -2
- package/build/esm/src/pedalmarking.js +33 -41
- package/build/esm/src/stave.js +10 -16
- package/build/esm/src/stavebarline.js +2 -3
- package/build/esm/src/stavehairpin.js +1 -1
- package/build/esm/src/staveline.js +0 -4
- package/build/esm/src/stavemodifier.js +0 -2
- package/build/esm/src/stavenote.js +16 -28
- package/build/esm/src/staverepetition.js +3 -2
- package/build/esm/src/stavesection.js +13 -15
- package/build/esm/src/stavetempo.js +3 -2
- package/build/esm/src/stavetext.js +2 -2
- package/build/esm/src/stavetie.js +0 -4
- package/build/esm/src/stavevolta.js +3 -2
- package/build/esm/src/stem.js +0 -4
- package/build/esm/src/stemmablenote.js +5 -6
- package/build/esm/src/stringnumber.js +0 -2
- package/build/esm/src/svgcontext.js +0 -1
- package/build/esm/src/tabnote.js +2 -8
- package/build/esm/src/textbracket.js +0 -3
- package/build/esm/src/textnote.js +0 -2
- package/build/esm/src/timesignature.js +2 -4
- package/build/esm/src/timesignote.js +2 -0
- package/build/esm/src/tuplet.js +37 -30
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +6 -2
- package/build/esm/tests/accidental_tests.js +30 -17
- package/build/esm/tests/annotation_tests.js +12 -12
- package/build/esm/tests/articulation_tests.js +13 -13
- package/build/esm/tests/auto_beam_formatting_tests.js +33 -33
- package/build/esm/tests/beam_tests.js +1 -1
- package/build/esm/tests/bend_tests.js +7 -7
- package/build/esm/tests/chordsymbol_tests.js +8 -8
- package/build/esm/tests/curve_tests.js +34 -0
- package/build/esm/tests/{bach_tests.js → demo_petzold_tests.js} +7 -7
- package/build/esm/tests/dot_tests.js +4 -4
- package/build/esm/tests/formatter_tests.js +25 -25
- package/build/esm/tests/gracenote_tests.js +2 -1
- package/build/esm/tests/gracetabnote_tests.js +1 -1
- package/build/esm/tests/index.js +1 -1
- package/build/esm/tests/key_clef_tests.js +6 -6
- package/build/esm/tests/keysignature_tests.js +20 -17
- package/build/esm/tests/notehead_tests.js +10 -7
- package/build/esm/tests/offscreencanvas_tests.js +1 -1
- package/build/esm/tests/ornament_tests.js +8 -8
- package/build/esm/tests/pedalmarking_tests.js +27 -0
- package/build/esm/tests/percussion_tests.js +6 -3
- package/build/esm/tests/renderer_tests.js +1 -1
- package/build/esm/tests/rests_tests.js +26 -26
- package/build/esm/tests/rhythm_tests.js +15 -15
- package/build/esm/tests/stave_tests.js +44 -43
- package/build/esm/tests/staveconnector_tests.js +73 -73
- package/build/esm/tests/stavehairpin_tests.js +1 -1
- package/build/esm/tests/stavemodifier_tests.js +3 -3
- package/build/esm/tests/stavenote_tests.js +29 -29
- package/build/esm/tests/stringnumber_tests.js +1 -1
- package/build/esm/tests/strokes_tests.js +1 -1
- package/build/esm/tests/style_tests.js +1 -1
- package/build/esm/tests/tabnote_tests.js +7 -7
- package/build/esm/tests/tabslide_tests.js +6 -6
- package/build/esm/tests/tabstave_tests.js +1 -1
- package/build/esm/tests/tabtie_tests.js +8 -8
- package/build/esm/tests/textnote_tests.js +1 -1
- package/build/esm/tests/threevoice_tests.js +2 -2
- package/build/esm/tests/timesignature_tests.js +23 -13
- package/build/esm/tests/vibrato_tests.js +3 -3
- package/build/esm/tests/voice_tests.js +1 -1
- package/build/types/src/bend.d.ts +6 -0
- package/build/types/src/curve.d.ts +5 -4
- package/build/types/src/element.d.ts +10 -11
- package/build/types/src/factory.d.ts +2 -2
- package/build/types/src/flag.d.ts +12 -0
- package/build/types/src/frethandfinger.d.ts +1 -1
- package/build/types/src/index.d.ts +1 -0
- package/build/types/src/keysignature.d.ts +7 -7
- package/build/types/src/metrics.d.ts +5 -0
- package/build/types/src/modifier.d.ts +1 -1
- package/build/types/src/pedalmarking.d.ts +2 -2
- package/build/types/src/stave.d.ts +1 -3
- package/build/types/src/stavebarline.d.ts +1 -1
- package/build/types/src/staveline.d.ts +1 -1
- package/build/types/src/stavemodifier.d.ts +0 -1
- package/build/types/src/staverepetition.d.ts +1 -1
- package/build/types/src/stavesection.d.ts +3 -4
- package/build/types/src/stavetempo.d.ts +1 -2
- package/build/types/src/stavetext.d.ts +1 -2
- package/build/types/src/stavevolta.d.ts +1 -2
- package/build/types/src/stemmablenote.d.ts +2 -3
- package/build/types/src/tuplet.d.ts +2 -12
- package/build/types/src/typeguard.d.ts +1 -0
- package/package.json +32 -28
package/build/esm/src/metrics.js
CHANGED
|
@@ -1,11 +1,41 @@
|
|
|
1
1
|
export class Metrics {
|
|
2
|
+
static clear(key) {
|
|
3
|
+
if (key) {
|
|
4
|
+
this.cacheFont.delete(key);
|
|
5
|
+
this.cacheStyle.delete(key);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
this.cacheFont.clear();
|
|
9
|
+
this.cacheStyle.clear();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
2
12
|
static getFontInfo(key) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
let font = this.cacheFont.get(key);
|
|
14
|
+
if (!font) {
|
|
15
|
+
font = {
|
|
16
|
+
family: Metrics.get(`${key}.fontFamily`),
|
|
17
|
+
size: Metrics.get(`${key}.fontSize`) * Metrics.get(`${key}.fontScale`),
|
|
18
|
+
weight: Metrics.get(`${key}.fontWeight`),
|
|
19
|
+
style: Metrics.get(`${key}.fontStyle`),
|
|
20
|
+
};
|
|
21
|
+
this.cacheFont.set(key, font);
|
|
22
|
+
}
|
|
23
|
+
return structuredClone(font);
|
|
24
|
+
}
|
|
25
|
+
static getStyle(key) {
|
|
26
|
+
let style = this.cacheStyle.get(key);
|
|
27
|
+
if (!style) {
|
|
28
|
+
style = {
|
|
29
|
+
fillStyle: Metrics.get(`${key}.fillStyle`),
|
|
30
|
+
strokeStyle: Metrics.get(`${key}.strokeStyle`),
|
|
31
|
+
lineWidth: Metrics.get(`${key}.lineWidth`),
|
|
32
|
+
lineDash: Metrics.get(`${key}.lineDash`),
|
|
33
|
+
shadowBlur: Metrics.get(`${key}.shadowBlur`),
|
|
34
|
+
shadowColor: Metrics.get(`${key}.shadowColor`),
|
|
35
|
+
};
|
|
36
|
+
this.cacheStyle.set(key, style);
|
|
37
|
+
}
|
|
38
|
+
return structuredClone(style);
|
|
9
39
|
}
|
|
10
40
|
static get(key, defaultValue) {
|
|
11
41
|
var _a;
|
|
@@ -26,6 +56,8 @@ export class Metrics {
|
|
|
26
56
|
return retVal;
|
|
27
57
|
}
|
|
28
58
|
}
|
|
59
|
+
Metrics.cacheStyle = new Map();
|
|
60
|
+
Metrics.cacheFont = new Map();
|
|
29
61
|
export const MetricsDefaults = {
|
|
30
62
|
fontFamily: 'Bravura,Academico',
|
|
31
63
|
fontSize: 30,
|
|
@@ -37,7 +69,7 @@ export const MetricsDefaults = {
|
|
|
37
69
|
fontSize: 20,
|
|
38
70
|
},
|
|
39
71
|
grace: {
|
|
40
|
-
fontSize:
|
|
72
|
+
fontSize: 20,
|
|
41
73
|
},
|
|
42
74
|
noteheadAccidentalPadding: 1,
|
|
43
75
|
leftPadding: 2,
|
|
@@ -48,6 +80,10 @@ export const MetricsDefaults = {
|
|
|
48
80
|
},
|
|
49
81
|
Bend: {
|
|
50
82
|
fontSize: 10,
|
|
83
|
+
line: {
|
|
84
|
+
strokeStyle: '#777777',
|
|
85
|
+
lineWidth: 1,
|
|
86
|
+
},
|
|
51
87
|
},
|
|
52
88
|
ChordSymbol: {
|
|
53
89
|
fontSize: 12,
|
|
@@ -91,6 +127,7 @@ export const MetricsDefaults = {
|
|
|
91
127
|
},
|
|
92
128
|
},
|
|
93
129
|
Stave: {
|
|
130
|
+
strokeStyle: '#999999',
|
|
94
131
|
fontSize: 8,
|
|
95
132
|
padding: 12,
|
|
96
133
|
endPaddingMax: 10,
|
|
@@ -108,6 +145,9 @@ export const MetricsDefaults = {
|
|
|
108
145
|
StaveSection: {
|
|
109
146
|
fontSize: 10,
|
|
110
147
|
fontWeight: 'bold',
|
|
148
|
+
lineWidth: 2,
|
|
149
|
+
padding: 2,
|
|
150
|
+
strokeStyle: 'black',
|
|
111
151
|
},
|
|
112
152
|
StaveTempo: {
|
|
113
153
|
fontSize: 14,
|
|
@@ -124,6 +164,9 @@ export const MetricsDefaults = {
|
|
|
124
164
|
StaveTie: {
|
|
125
165
|
fontSize: 10,
|
|
126
166
|
},
|
|
167
|
+
Stem: {
|
|
168
|
+
strokeStyle: 'black',
|
|
169
|
+
},
|
|
127
170
|
StringNumber: {
|
|
128
171
|
fontSize: 10,
|
|
129
172
|
fontWeight: 'bold',
|
|
@@ -150,6 +193,7 @@ export const MetricsDefaults = {
|
|
|
150
193
|
fontWeight: 'bold',
|
|
151
194
|
},
|
|
152
195
|
TabStave: {
|
|
196
|
+
strokeStyle: '#999999',
|
|
153
197
|
fontSize: 8,
|
|
154
198
|
},
|
|
155
199
|
TabTie: {
|
|
@@ -167,6 +211,10 @@ export const MetricsDefaults = {
|
|
|
167
211
|
Tremolo: {
|
|
168
212
|
spacing: 7,
|
|
169
213
|
},
|
|
214
|
+
Tuplet: {
|
|
215
|
+
yOffset: 0,
|
|
216
|
+
textYOffset: 2,
|
|
217
|
+
},
|
|
170
218
|
Volta: {
|
|
171
219
|
fontSize: 9,
|
|
172
220
|
fontWeight: 'bold',
|
|
@@ -104,11 +104,13 @@ export class Modifier extends Element {
|
|
|
104
104
|
this.checkContext();
|
|
105
105
|
throw new RuntimeError('NotImplemented', 'draw() not implemented for this modifier.');
|
|
106
106
|
}
|
|
107
|
-
alignSubNotesWithNote(subNotes, note) {
|
|
107
|
+
alignSubNotesWithNote(subNotes, note, position = Modifier.Position.LEFT) {
|
|
108
108
|
const tickContext = note.getTickContext();
|
|
109
109
|
const metrics = tickContext.getMetrics();
|
|
110
110
|
const stave = note.getStave();
|
|
111
|
-
const subNoteXOffset =
|
|
111
|
+
const subNoteXOffset = position === Modifier.Position.RIGHT
|
|
112
|
+
? tickContext.getX() + this.getSpacingFromNextModifier() * subNotes.length + 10
|
|
113
|
+
: tickContext.getX() - metrics.modLeftPx - metrics.modRightPx + this.getSpacingFromNextModifier();
|
|
112
114
|
subNotes.forEach((subNote) => {
|
|
113
115
|
const subTickContext = subNote.getTickContext();
|
|
114
116
|
if (stave)
|
|
@@ -10,6 +10,7 @@ export class NoteHead extends Note {
|
|
|
10
10
|
return "NoteHead";
|
|
11
11
|
}
|
|
12
12
|
constructor(noteStruct) {
|
|
13
|
+
var _a;
|
|
13
14
|
super(noteStruct);
|
|
14
15
|
this.customGlyph = false;
|
|
15
16
|
this.ledger = {
|
|
@@ -34,7 +35,7 @@ export class NoteHead extends Note {
|
|
|
34
35
|
this.customGlyph = true;
|
|
35
36
|
this.text = noteStruct.customGlyphCode;
|
|
36
37
|
}
|
|
37
|
-
this.setStyle(noteStruct.style);
|
|
38
|
+
this.setStyle((_a = noteStruct.style) !== null && _a !== void 0 ? _a : {});
|
|
38
39
|
this.slashed = noteStruct.slashed || false;
|
|
39
40
|
this.renderOptions = Object.assign({}, this.renderOptions);
|
|
40
41
|
}
|
|
@@ -72,11 +73,15 @@ export class NoteHead extends Note {
|
|
|
72
73
|
return this;
|
|
73
74
|
}
|
|
74
75
|
draw() {
|
|
76
|
+
var _a;
|
|
75
77
|
const ctx = this.checkContext();
|
|
76
78
|
this.setRendered();
|
|
79
|
+
ctx.openGroup('notehead', this.getAttribute('id'));
|
|
77
80
|
L("Drawing note head '", this.noteType, this.duration, "' at", this.x, this.y);
|
|
78
81
|
this.x = this.getAbsoluteX();
|
|
79
82
|
this.renderText(ctx, 0, 0);
|
|
83
|
+
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.drawModifiers(this);
|
|
84
|
+
ctx.closeGroup();
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
NoteHead.DEBUG = false;
|
|
@@ -135,7 +135,6 @@ export class Ornament extends Modifier {
|
|
|
135
135
|
const note = this.checkAttachedNote();
|
|
136
136
|
this.setRendered();
|
|
137
137
|
const stave = note.checkStave();
|
|
138
|
-
this.applyStyle();
|
|
139
138
|
ctx.openGroup('ornament', this.getAttribute('id'));
|
|
140
139
|
const start = note.getModifierStartXY(this.position, this.index);
|
|
141
140
|
let glyphX = start.x;
|
|
@@ -186,7 +185,6 @@ export class Ornament extends Modifier {
|
|
|
186
185
|
this.accidentalUpper.renderText(ctx, glyphX + this.xShift - this.accidentalUpper.getWidth() * 0.5, glyphY + this.yShift - this.accidentalUpper.getTextMetrics().actualBoundingBoxDescent);
|
|
187
186
|
}
|
|
188
187
|
ctx.closeGroup();
|
|
189
|
-
this.restoreStyle();
|
|
190
188
|
}
|
|
191
189
|
}
|
|
192
190
|
Ornament.DEBUG = false;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { Element } from './element.js';
|
|
2
2
|
import { Glyphs } from './glyphs.js';
|
|
3
3
|
import { Metrics } from './metrics.js';
|
|
4
|
-
import { Tables } from './tables.js';
|
|
5
4
|
import { log, RuntimeError } from './util.js';
|
|
6
5
|
function L(...args) {
|
|
7
6
|
if (PedalMarking.DEBUG)
|
|
8
7
|
log('VexFlow.PedalMarking', args);
|
|
9
8
|
}
|
|
10
|
-
function drawPedalGlyph(name, ctx, x, y) {
|
|
11
|
-
var _a;
|
|
12
|
-
const glyph = new Element(PedalMarking.CATEGORY);
|
|
13
|
-
glyph.setText((_a = PedalMarking.GLYPHS[name]) !== null && _a !== void 0 ? _a : name);
|
|
14
|
-
glyph.renderText(ctx, x - (glyph.getWidth() - Tables.STAVE_LINE_DISTANCE) / 2, y);
|
|
15
|
-
}
|
|
16
9
|
export class PedalMarking extends Element {
|
|
17
10
|
static get CATEGORY() {
|
|
18
11
|
return "PedalMarking";
|
|
@@ -38,8 +31,8 @@ export class PedalMarking extends Element {
|
|
|
38
31
|
this.notes = notes;
|
|
39
32
|
this.type = PedalMarking.type.TEXT;
|
|
40
33
|
this.line = 0;
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
34
|
+
this.depressText = PedalMarking.GLYPHS.pedalDepress;
|
|
35
|
+
this.releaseText = PedalMarking.GLYPHS.pedalRelease;
|
|
43
36
|
this.renderOptions = {
|
|
44
37
|
bracketHeight: 10,
|
|
45
38
|
textMarginRight: 6,
|
|
@@ -55,8 +48,9 @@ export class PedalMarking extends Element {
|
|
|
55
48
|
return this;
|
|
56
49
|
}
|
|
57
50
|
setCustomText(depress, release) {
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
51
|
+
this.depressText = depress || '';
|
|
52
|
+
this.releaseText = release || '';
|
|
53
|
+
this.setFont(Metrics.getFontInfo('PedalMarking.text'));
|
|
60
54
|
return this;
|
|
61
55
|
}
|
|
62
56
|
setLine(line) {
|
|
@@ -68,7 +62,9 @@ export class PedalMarking extends Element {
|
|
|
68
62
|
let isPedalDepressed = false;
|
|
69
63
|
let prevX;
|
|
70
64
|
let prevY;
|
|
65
|
+
let textWidth = 0;
|
|
71
66
|
this.notes.forEach((note, index, notes) => {
|
|
67
|
+
var _a, _b, _c, _d;
|
|
72
68
|
isPedalDepressed = !isPedalDepressed;
|
|
73
69
|
const x = note.getAbsoluteX();
|
|
74
70
|
const y = note.checkStave().getYForBottomText(this.line + 3);
|
|
@@ -81,15 +77,9 @@ export class PedalMarking extends Element {
|
|
|
81
77
|
if (isPedalDepressed) {
|
|
82
78
|
xShift = prevNoteIsSame ? 5 : 0;
|
|
83
79
|
if (this.type === PedalMarking.type.MIXED && !prevNoteIsSame) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
xShift = textWidth / 2 + this.renderOptions.textMarginRight;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
drawPedalGlyph('pedalDepress', ctx, x, y);
|
|
91
|
-
xShift = 20 + this.renderOptions.textMarginRight;
|
|
92
|
-
}
|
|
80
|
+
textWidth = ctx.measureText(this.depressText).width;
|
|
81
|
+
ctx.fillText(this.depressText, x, y);
|
|
82
|
+
xShift = textWidth + this.renderOptions.textMarginRight;
|
|
93
83
|
}
|
|
94
84
|
else {
|
|
95
85
|
ctx.beginPath();
|
|
@@ -100,11 +90,17 @@ export class PedalMarking extends Element {
|
|
|
100
90
|
}
|
|
101
91
|
}
|
|
102
92
|
else {
|
|
103
|
-
|
|
93
|
+
const noteNdx = note.getVoice().getTickables().indexOf(note);
|
|
94
|
+
const voiceNotes = note.getVoice().getTickables().length;
|
|
95
|
+
const noteEndX = noteNdx + 1 < voiceNotes
|
|
96
|
+
?
|
|
97
|
+
note.getVoice().getTickables()[noteNdx + 1].getAbsoluteX()
|
|
98
|
+
:
|
|
99
|
+
((_b = (_a = note.getStave()) === null || _a === void 0 ? void 0 : _a.getX()) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = note.getStave()) === null || _c === void 0 ? void 0 : _c.getWidth()) !== null && _d !== void 0 ? _d : 0);
|
|
104
100
|
ctx.beginPath();
|
|
105
101
|
ctx.moveTo(prevX, prevY);
|
|
106
|
-
ctx.lineTo(x
|
|
107
|
-
ctx.lineTo(x, y - this.renderOptions.bracketHeight);
|
|
102
|
+
ctx.lineTo(nextNoteIsSame ? x - 5 : noteEndX - 5, y);
|
|
103
|
+
ctx.lineTo(nextNoteIsSame ? x : noteEndX - 5, y - this.renderOptions.bracketHeight);
|
|
108
104
|
ctx.stroke();
|
|
109
105
|
ctx.closePath();
|
|
110
106
|
}
|
|
@@ -115,39 +111,36 @@ export class PedalMarking extends Element {
|
|
|
115
111
|
drawText() {
|
|
116
112
|
const ctx = this.checkContext();
|
|
117
113
|
let isPedalDepressed = false;
|
|
114
|
+
let textWidth = 0;
|
|
118
115
|
this.notes.forEach((note) => {
|
|
116
|
+
var _a, _b, _c, _d;
|
|
119
117
|
isPedalDepressed = !isPedalDepressed;
|
|
120
118
|
const stave = note.checkStave();
|
|
121
119
|
const x = note.getAbsoluteX();
|
|
122
120
|
const y = stave.getYForBottomText(this.line + 3);
|
|
123
|
-
let textWidth = 0;
|
|
124
121
|
if (isPedalDepressed) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
ctx.fillText(this.customDepressText, x - textWidth / 2, y);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
drawPedalGlyph('pedalDepress', ctx, x, y);
|
|
131
|
-
}
|
|
122
|
+
textWidth = ctx.measureText(this.depressText).width;
|
|
123
|
+
ctx.fillText(this.depressText, x, y);
|
|
132
124
|
}
|
|
133
125
|
else {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
126
|
+
const noteNdx = note.getVoice().getTickables().indexOf(note);
|
|
127
|
+
const voiceNotes = note.getVoice().getTickables().length;
|
|
128
|
+
const noteEndX = noteNdx + 1 < voiceNotes
|
|
129
|
+
?
|
|
130
|
+
note.getVoice().getTickables()[noteNdx + 1].getAbsoluteX()
|
|
131
|
+
:
|
|
132
|
+
((_b = (_a = note.getStave()) === null || _a === void 0 ? void 0 : _a.getX()) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = note.getStave()) === null || _c === void 0 ? void 0 : _c.getWidth()) !== null && _d !== void 0 ? _d : 0);
|
|
133
|
+
textWidth = ctx.measureText(this.releaseText).width;
|
|
134
|
+
ctx.fillText(this.releaseText, noteEndX - textWidth, y);
|
|
141
135
|
}
|
|
142
136
|
});
|
|
143
137
|
}
|
|
144
138
|
draw() {
|
|
145
139
|
const ctx = this.checkContext();
|
|
146
140
|
this.setRendered();
|
|
147
|
-
ctx.save();
|
|
148
141
|
ctx.setStrokeStyle(this.renderOptions.color);
|
|
149
142
|
ctx.setFillStyle(this.renderOptions.color);
|
|
150
|
-
ctx.setFont(
|
|
143
|
+
ctx.setFont(this.font);
|
|
151
144
|
L('Rendering Pedal Marking');
|
|
152
145
|
if (this.type === PedalMarking.type.BRACKET || this.type === PedalMarking.type.MIXED) {
|
|
153
146
|
ctx.setLineWidth(this.renderOptions.bracketLineWidth);
|
|
@@ -156,7 +149,6 @@ export class PedalMarking extends Element {
|
|
|
156
149
|
else if (this.type === PedalMarking.type.TEXT) {
|
|
157
150
|
this.drawText();
|
|
158
151
|
}
|
|
159
|
-
ctx.restore();
|
|
160
152
|
}
|
|
161
153
|
}
|
|
162
154
|
PedalMarking.DEBUG = false;
|
package/build/esm/src/stave.js
CHANGED
|
@@ -48,7 +48,7 @@ export class Stave extends Element {
|
|
|
48
48
|
this.measure = 0;
|
|
49
49
|
this.clef = 'treble';
|
|
50
50
|
this.endClef = undefined;
|
|
51
|
-
this.options = Object.assign({ verticalBarWidth: 10, numLines: 5,
|
|
51
|
+
this.options = Object.assign({ verticalBarWidth: 10, numLines: 5, leftBar: true, rightBar: true, spacingBetweenLinesPx: Tables.STAVE_LINE_DISTANCE, spaceAboveStaffLn: 4, spaceBelowStaffLn: 4, topTextPosition: 1, bottomTextPosition: 4, lineConfig: [] }, options);
|
|
52
52
|
this.bounds = { x: this.x, y: this.y, w: this.width, h: 0 };
|
|
53
53
|
this.defaultLedgerLineStyle = { strokeStyle: '#444', lineWidth: 1.4 };
|
|
54
54
|
this.resetLines();
|
|
@@ -103,10 +103,12 @@ export class Stave extends Element {
|
|
|
103
103
|
return this;
|
|
104
104
|
}
|
|
105
105
|
getTopLineTopY() {
|
|
106
|
-
|
|
106
|
+
var _a;
|
|
107
|
+
return this.getYForLine(0) - ((_a = this.getStyle().lineWidth) !== null && _a !== void 0 ? _a : 1) / 2;
|
|
107
108
|
}
|
|
108
109
|
getBottomLineBottomY() {
|
|
109
|
-
|
|
110
|
+
var _a;
|
|
111
|
+
return this.getYForLine(this.getNumLines() - 1) + ((_a = this.getStyle().lineWidth) !== null && _a !== void 0 ? _a : 1) / 2;
|
|
110
112
|
}
|
|
111
113
|
setX(x) {
|
|
112
114
|
const shift = x - this.x;
|
|
@@ -126,9 +128,6 @@ export class Stave extends Element {
|
|
|
126
128
|
this.endX = this.x + width;
|
|
127
129
|
return this;
|
|
128
130
|
}
|
|
129
|
-
getStyle() {
|
|
130
|
-
return Object.assign({ fillStyle: this.options.fillStyle, strokeStyle: this.options.fillStyle, lineWidth: Tables.STAVE_LINE_THICKNESS }, super.getStyle());
|
|
131
|
-
}
|
|
132
131
|
setMeasure(measure) {
|
|
133
132
|
this.measure = measure;
|
|
134
133
|
return this;
|
|
@@ -164,11 +163,11 @@ export class Stave extends Element {
|
|
|
164
163
|
return this;
|
|
165
164
|
}
|
|
166
165
|
setSection(section, y, xOffset = 0, fontSize, drawRect = true) {
|
|
167
|
-
const staveSection = new StaveSection(section
|
|
166
|
+
const staveSection = new StaveSection(section).setYShift(y).setXShift(xOffset).setDrawRect(drawRect);
|
|
168
167
|
if (fontSize) {
|
|
169
168
|
staveSection.setFontSize(fontSize);
|
|
170
169
|
}
|
|
171
|
-
this.
|
|
170
|
+
this.addModifier(staveSection);
|
|
172
171
|
return this;
|
|
173
172
|
}
|
|
174
173
|
setTempo(tempo, y) {
|
|
@@ -452,7 +451,6 @@ export class Stave extends Element {
|
|
|
452
451
|
draw() {
|
|
453
452
|
const ctx = this.checkContext();
|
|
454
453
|
this.setRendered();
|
|
455
|
-
this.applyStyle();
|
|
456
454
|
ctx.openGroup('stave', this.getAttribute('id'));
|
|
457
455
|
if (!this.formatted)
|
|
458
456
|
this.format();
|
|
@@ -470,22 +468,18 @@ export class Stave extends Element {
|
|
|
470
468
|
}
|
|
471
469
|
}
|
|
472
470
|
ctx.closeGroup();
|
|
473
|
-
this.restoreStyle();
|
|
474
471
|
for (let i = 0; i < this.modifiers.length; i++) {
|
|
475
472
|
const modifier = this.modifiers[i];
|
|
476
|
-
modifier.
|
|
477
|
-
modifier.
|
|
478
|
-
modifier.
|
|
473
|
+
modifier.setContext(ctx);
|
|
474
|
+
modifier.setStave(this);
|
|
475
|
+
modifier.drawWithStyle();
|
|
479
476
|
}
|
|
480
477
|
if (this.measure > 0) {
|
|
481
|
-
ctx.save();
|
|
482
478
|
ctx.setFont(this.fontInfo);
|
|
483
479
|
const textWidth = ctx.measureText('' + this.measure).width;
|
|
484
480
|
y = this.getYForTopText(0) + 3;
|
|
485
481
|
ctx.fillText('' + this.measure, this.x - textWidth / 2, y);
|
|
486
|
-
ctx.restore();
|
|
487
482
|
}
|
|
488
|
-
return this;
|
|
489
483
|
}
|
|
490
484
|
getVerticalBarWidth() {
|
|
491
485
|
return this.options.verticalBarWidth;
|
|
@@ -104,10 +104,10 @@ export class Barline extends StaveModifier {
|
|
|
104
104
|
this.setLayoutMetrics(this.layoutMetricsMap[this.type]);
|
|
105
105
|
return this;
|
|
106
106
|
}
|
|
107
|
-
draw(
|
|
107
|
+
draw() {
|
|
108
|
+
const stave = this.checkStave();
|
|
108
109
|
const ctx = stave.checkContext();
|
|
109
110
|
this.setRendered();
|
|
110
|
-
this.applyStyle(ctx);
|
|
111
111
|
ctx.openGroup('stavebarline', this.getAttribute('id'));
|
|
112
112
|
switch (this.type) {
|
|
113
113
|
case BarlineType.SINGLE:
|
|
@@ -136,7 +136,6 @@ export class Barline extends StaveModifier {
|
|
|
136
136
|
break;
|
|
137
137
|
}
|
|
138
138
|
ctx.closeGroup();
|
|
139
|
-
this.restoreStyle(ctx);
|
|
140
139
|
}
|
|
141
140
|
drawVerticalBar(stave, x, doubleBar) {
|
|
142
141
|
const staveCtx = stave.checkContext();
|
|
@@ -142,7 +142,6 @@ export class StaveLine extends Element {
|
|
|
142
142
|
const firstNote = this.firstNote;
|
|
143
143
|
const lastNote = this.lastNote;
|
|
144
144
|
const renderOptions = this.renderOptions;
|
|
145
|
-
ctx.save();
|
|
146
145
|
this.applyLineStyle();
|
|
147
146
|
let startPosition = { x: 0, y: 0 };
|
|
148
147
|
let endPosition = { x: 0, y: 0 };
|
|
@@ -166,7 +165,6 @@ export class StaveLine extends Element {
|
|
|
166
165
|
endPosition.y += upwardsSlope ? 2 : 0;
|
|
167
166
|
this.drawArrowLine(ctx, startPosition, endPosition);
|
|
168
167
|
});
|
|
169
|
-
ctx.restore();
|
|
170
168
|
const textWidth = this.width;
|
|
171
169
|
const justification = renderOptions.textJustification;
|
|
172
170
|
let x = 0;
|
|
@@ -192,8 +190,6 @@ export class StaveLine extends Element {
|
|
|
192
190
|
const color = renderOptions.color;
|
|
193
191
|
this.applyStyle(ctx, { fillStyle: color, strokeStyle: color });
|
|
194
192
|
this.renderText(ctx, x, y);
|
|
195
|
-
this.restoreStyle(ctx);
|
|
196
|
-
return this;
|
|
197
193
|
}
|
|
198
194
|
}
|
|
199
195
|
StaveLine.TextVerticalPosition = {
|
|
@@ -300,7 +300,7 @@ export class StaveNote extends StemmableNote {
|
|
|
300
300
|
return this;
|
|
301
301
|
}
|
|
302
302
|
buildStem() {
|
|
303
|
-
this.setStem(new Stem({ hide:
|
|
303
|
+
this.setStem(new Stem({ hide: this.isRest() }));
|
|
304
304
|
return this;
|
|
305
305
|
}
|
|
306
306
|
buildNoteHeads() {
|
|
@@ -349,7 +349,7 @@ export class StaveNote extends StemmableNote {
|
|
|
349
349
|
line: noteProps.line,
|
|
350
350
|
});
|
|
351
351
|
notehead.fontInfo = this.fontInfo;
|
|
352
|
-
this.
|
|
352
|
+
this.addChild(notehead);
|
|
353
353
|
this._noteHeads[this.sortedKeyProps[i].index] = notehead;
|
|
354
354
|
}
|
|
355
355
|
return this._noteHeads;
|
|
@@ -388,7 +388,7 @@ export class StaveNote extends StemmableNote {
|
|
|
388
388
|
lastLine = line;
|
|
389
389
|
}
|
|
390
390
|
else {
|
|
391
|
-
if (Math.abs(lastLine - line)
|
|
391
|
+
if (Math.abs(lastLine - line) < 1) {
|
|
392
392
|
this.displaced = true;
|
|
393
393
|
props.displaced = true;
|
|
394
394
|
if (this.keyProps.length > 0) {
|
|
@@ -410,17 +410,16 @@ export class StaveNote extends StemmableNote {
|
|
|
410
410
|
boundingBox.mergeWith(notehead.getBoundingBox());
|
|
411
411
|
});
|
|
412
412
|
const { yTop, yBottom } = this.getNoteHeadBounds();
|
|
413
|
-
const noteStemHeight = this.stem.getHeight();
|
|
414
|
-
const flagX = this.getStemX() - Tables.STEM_WIDTH / 2;
|
|
415
|
-
const flagY = this.getStemDirection() === Stem.DOWN
|
|
416
|
-
? yTop - noteStemHeight - this.flag.getTextMetrics().actualBoundingBoxDescent
|
|
417
|
-
: yBottom - noteStemHeight + this.flag.getTextMetrics().actualBoundingBoxAscent;
|
|
418
413
|
if (!this.isRest() && this.hasStem()) {
|
|
419
|
-
|
|
414
|
+
const noteStemHeight = this.stem.getHeight();
|
|
415
|
+
const stemY = this.getStemDirection() === Stem.DOWN
|
|
416
|
+
? yTop - noteStemHeight - this.flag.getTextMetrics().actualBoundingBoxDescent
|
|
417
|
+
: yBottom - noteStemHeight + this.flag.getTextMetrics().actualBoundingBoxAscent;
|
|
418
|
+
boundingBox.mergeWith(new BoundingBox(this.getAbsoluteX(), stemY, 0, 0));
|
|
420
419
|
}
|
|
421
420
|
if (this.hasFlag()) {
|
|
422
421
|
const bbFlag = this.flag.getBoundingBox();
|
|
423
|
-
boundingBox.mergeWith(bbFlag
|
|
422
|
+
boundingBox.mergeWith(bbFlag);
|
|
424
423
|
}
|
|
425
424
|
for (let i = 0; i < this.modifiers.length; i++) {
|
|
426
425
|
boundingBox.mergeWith(this.modifiers[i].getBoundingBox());
|
|
@@ -584,10 +583,10 @@ export class StaveNote extends StemmableNote {
|
|
|
584
583
|
return this.ledgerLineStyle;
|
|
585
584
|
}
|
|
586
585
|
setFlagStyle(style) {
|
|
587
|
-
this.
|
|
586
|
+
this.flag.setStyle(style);
|
|
588
587
|
}
|
|
589
588
|
getFlagStyle() {
|
|
590
|
-
return this.
|
|
589
|
+
return this.flag.getStyle();
|
|
591
590
|
}
|
|
592
591
|
getGlyphWidth() {
|
|
593
592
|
return this.noteHeads[0].getWidth();
|
|
@@ -714,6 +713,7 @@ export class StaveNote extends StemmableNote {
|
|
|
714
713
|
ctx.stroke();
|
|
715
714
|
};
|
|
716
715
|
const style = Object.assign(Object.assign({}, stave.getDefaultLedgerLineStyle()), this.getLedgerLineStyle());
|
|
716
|
+
ctx.save();
|
|
717
717
|
this.applyStyle(ctx, style);
|
|
718
718
|
for (let line = 6; line <= highestLine; ++line) {
|
|
719
719
|
const normal = nonDisplacedX !== undefined && line <= highestNonDisplacedLine;
|
|
@@ -725,7 +725,7 @@ export class StaveNote extends StemmableNote {
|
|
|
725
725
|
const displaced = lowestDisplacedLine !== undefined && line >= lowestDisplacedLine;
|
|
726
726
|
drawLedgerLine(stave.getYForNote(line), normal, displaced);
|
|
727
727
|
}
|
|
728
|
-
|
|
728
|
+
ctx.restore();
|
|
729
729
|
}
|
|
730
730
|
drawModifiers(noteheadParam) {
|
|
731
731
|
const ctx = this.checkContext();
|
|
@@ -734,11 +734,8 @@ export class StaveNote extends StemmableNote {
|
|
|
734
734
|
const index = modifier.checkIndex();
|
|
735
735
|
const notehead = this._noteHeads[index];
|
|
736
736
|
if (notehead === noteheadParam) {
|
|
737
|
-
const noteheadStyle = notehead.getStyle();
|
|
738
|
-
notehead.applyStyle(ctx, noteheadStyle);
|
|
739
737
|
modifier.setContext(ctx);
|
|
740
738
|
modifier.drawWithStyle();
|
|
741
|
-
notehead.restoreStyle(ctx, noteheadStyle);
|
|
742
739
|
}
|
|
743
740
|
}
|
|
744
741
|
}
|
|
@@ -762,20 +759,13 @@ export class StaveNote extends StemmableNote {
|
|
|
762
759
|
yTop - noteStemHeight - this.flag.getTextMetrics().actualBoundingBoxDescent
|
|
763
760
|
:
|
|
764
761
|
yBottom - noteStemHeight + this.flag.getTextMetrics().actualBoundingBoxAscent;
|
|
765
|
-
this.
|
|
766
|
-
this.flag.renderText(ctx, flagX, flagY);
|
|
767
|
-
this.restoreStyle(ctx, this.flagStyle);
|
|
762
|
+
this.flag.setContext(ctx).setX(flagX).setY(flagY).drawWithStyle();
|
|
768
763
|
}
|
|
769
764
|
}
|
|
770
765
|
drawNoteHeads() {
|
|
771
766
|
const ctx = this.checkContext();
|
|
772
767
|
this._noteHeads.forEach((notehead) => {
|
|
773
|
-
notehead.
|
|
774
|
-
ctx.openGroup('notehead', notehead.getAttribute('id'));
|
|
775
|
-
notehead.setContext(ctx).draw();
|
|
776
|
-
this.drawModifiers(notehead);
|
|
777
|
-
ctx.closeGroup();
|
|
778
|
-
notehead.restoreStyle(ctx);
|
|
768
|
+
notehead.setContext(ctx).drawWithStyle();
|
|
779
769
|
});
|
|
780
770
|
}
|
|
781
771
|
drawStem(stemOptions) {
|
|
@@ -787,7 +777,7 @@ export class StaveNote extends StemmableNote {
|
|
|
787
777
|
this.stem.adjustHeightForFlag();
|
|
788
778
|
}
|
|
789
779
|
if (this.stem) {
|
|
790
|
-
this.stem.setContext(ctx).
|
|
780
|
+
this.stem.setContext(ctx).drawWithStyle();
|
|
791
781
|
}
|
|
792
782
|
}
|
|
793
783
|
getStemExtension() {
|
|
@@ -833,7 +823,6 @@ export class StaveNote extends StemmableNote {
|
|
|
833
823
|
this.stem.setNoteHeadXBounds(stemX, stemX);
|
|
834
824
|
}
|
|
835
825
|
L('Rendering ', this.isChord() ? 'chord :' : 'note :', this.keys);
|
|
836
|
-
this.applyStyle();
|
|
837
826
|
ctx.openGroup('stavenote', this.getAttribute('id'));
|
|
838
827
|
this.drawLedgerLines();
|
|
839
828
|
if (shouldRenderStem)
|
|
@@ -843,7 +832,6 @@ export class StaveNote extends StemmableNote {
|
|
|
843
832
|
const bb = this.getBoundingBox();
|
|
844
833
|
ctx.pointerRect(bb.getX(), bb.getY(), bb.getW(), bb.getH());
|
|
845
834
|
ctx.closeGroup();
|
|
846
|
-
this.restoreStyle();
|
|
847
835
|
this.setRendered();
|
|
848
836
|
}
|
|
849
837
|
}
|
|
@@ -20,7 +20,9 @@ export class Repetition extends StaveModifier {
|
|
|
20
20
|
this.yShift = y;
|
|
21
21
|
return this;
|
|
22
22
|
}
|
|
23
|
-
draw(
|
|
23
|
+
draw() {
|
|
24
|
+
const stave = this.checkStave();
|
|
25
|
+
const x = stave.getModifierXShift(this.getPosition());
|
|
24
26
|
this.setRendered();
|
|
25
27
|
switch (this.symbolType) {
|
|
26
28
|
case Repetition.type.CODA_RIGHT:
|
|
@@ -62,7 +64,6 @@ export class Repetition extends StaveModifier {
|
|
|
62
64
|
default:
|
|
63
65
|
break;
|
|
64
66
|
}
|
|
65
|
-
return this;
|
|
66
67
|
}
|
|
67
68
|
drawCodaFixed(stave, x) {
|
|
68
69
|
const y = stave.getYForTopText(stave.getNumLines());
|