vexflow 5.3.0 → 5.4.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 +2 -0
- 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 +4189 -772
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +4323 -906
- 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/alternatingtremolo.js +68 -0
- package/build/esm/src/annotation.js +19 -3
- package/build/esm/src/articulation.js +5 -1
- package/build/esm/src/beam.js +13 -0
- package/build/esm/src/bend.js +57 -6
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/continuouslayout.js +681 -0
- package/build/esm/src/continuousspan.js +159 -0
- package/build/esm/src/curve.js +21 -2
- package/build/esm/src/easyscore/composition.js +13 -2
- package/build/esm/src/easyscore/policies.js +6 -3
- package/build/esm/src/engravinggeometry.js +8 -1
- package/build/esm/src/factory.js +16 -4
- package/build/esm/src/font.js +9 -1
- package/build/esm/src/fretdiagram.js +77 -0
- package/build/esm/src/guitargesture.js +33 -0
- package/build/esm/src/guitarmodifiers.js +26 -0
- package/build/esm/src/index.js +8 -0
- package/build/esm/src/instrumentprofile.js +123 -0
- package/build/esm/src/keysignature.js +23 -1
- package/build/esm/src/notationspelling.js +73 -0
- package/build/esm/src/note.js +3 -0
- package/build/esm/src/ornament.js +5 -0
- package/build/esm/src/pagebreaks.js +58 -0
- package/build/esm/src/pedalmarking.js +39 -17
- package/build/esm/src/phraselayout.js +503 -0
- package/build/esm/src/phraseribbon.js +28 -0
- package/build/esm/src/publication.js +402 -0
- package/build/esm/src/publicationview.js +114 -0
- package/build/esm/src/scorenavigation.js +172 -0
- package/build/esm/src/sheet.js +14 -2
- package/build/esm/src/stave.js +33 -16
- package/build/esm/src/stavebarline.js +5 -7
- package/build/esm/src/staveconnector.js +1 -0
- package/build/esm/src/stavehairpin.js +53 -27
- package/build/esm/src/stavenote.js +6 -1
- package/build/esm/src/stavetie.js +27 -2
- package/build/esm/src/strokes.js +4 -0
- package/build/esm/src/system.js +19 -4
- package/build/esm/src/systembreaks.js +42 -0
- package/build/esm/src/tabnote.js +6 -1
- package/build/esm/src/textbracket.js +24 -5
- package/build/esm/src/timesignature.js +15 -6
- package/build/esm/src/tuplet.js +1 -0
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +16 -0
- package/build/esm/src/voice.js +7 -3
- package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
- package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
- package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
- package/build/esm/tests/engraving/publication-studies.mjs +87 -0
- package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
- package/build/esm/tests/engraving/studies.mjs +88 -0
- package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
- package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
- package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
- package/build/esm/tests/node/publication-tests.mjs +219 -0
- package/build/esm/tools/easyscore-structure.mjs +1 -1
- package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
- package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
- package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
- package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
- package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
- package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
- package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
- package/build/types/src/alternatingtremolo.d.ts +13 -0
- package/build/types/src/annotation.d.ts +9 -0
- package/build/types/src/articulation.d.ts +3 -0
- package/build/types/src/beam.d.ts +2 -0
- package/build/types/src/bend.d.ts +8 -0
- package/build/types/src/clef.d.ts +3 -0
- package/build/types/src/continuouslayout.d.ts +103 -0
- package/build/types/src/continuousspan.d.ts +60 -0
- package/build/types/src/curve.d.ts +11 -0
- package/build/types/src/easyscore/composition.d.ts +8 -0
- package/build/types/src/easyscore/policies.d.ts +1 -1
- package/build/types/src/fretdiagram.d.ts +23 -0
- package/build/types/src/guitargesture.d.ts +26 -0
- package/build/types/src/guitarmodifiers.d.ts +3 -0
- package/build/types/src/index.d.ts +10 -0
- package/build/types/src/instrumentprofile.d.ts +124 -0
- package/build/types/src/keysignature.d.ts +9 -0
- package/build/types/src/notationspelling.d.ts +25 -0
- package/build/types/src/note.d.ts +15 -0
- package/build/types/src/ornament.d.ts +3 -1
- package/build/types/src/pagebreaks.d.ts +26 -0
- package/build/types/src/pedalmarking.d.ts +9 -0
- package/build/types/src/phraselayout.d.ts +87 -0
- package/build/types/src/phraseribbon.d.ts +7 -0
- package/build/types/src/publication.d.ts +61 -0
- package/build/types/src/publicationview.d.ts +27 -0
- package/build/types/src/scorenavigation.d.ts +33 -0
- package/build/types/src/sheet.d.ts +5 -0
- package/build/types/src/stave.d.ts +13 -0
- package/build/types/src/stavehairpin.d.ts +18 -0
- package/build/types/src/stavetie.d.ts +5 -0
- package/build/types/src/system.d.ts +8 -1
- package/build/types/src/systembreaks.d.ts +9 -0
- package/build/types/src/textbracket.d.ts +7 -0
- package/build/types/src/timesignature.d.ts +4 -0
- package/build/types/src/vexflow.d.ts +16 -0
- package/build/types/src/voice.d.ts +2 -0
- package/changelog/CHANGELOG.md +8 -0
- package/package.json +9 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function chooseSystemBreaks(units, width, gap, indent, mode) {
|
|
2
|
+
var _a;
|
|
3
|
+
const n = units.length;
|
|
4
|
+
const next = Array(n);
|
|
5
|
+
const costs = Array(n + 1).fill(Infinity);
|
|
6
|
+
const clipped = Array(n + 1).fill(Infinity);
|
|
7
|
+
costs[n] = 0;
|
|
8
|
+
clipped[n] = 0;
|
|
9
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
10
|
+
let body = indent(i) + units[i].start;
|
|
11
|
+
let found = false;
|
|
12
|
+
for (let j = i; j < n; j++) {
|
|
13
|
+
if (j > i && units[j].breakBefore === 'force')
|
|
14
|
+
break;
|
|
15
|
+
body += units[j].width + (j > i ? gap : 0);
|
|
16
|
+
if (((_a = units[j + 1]) === null || _a === void 0 ? void 0 : _a.breakBefore) === 'keep')
|
|
17
|
+
continue;
|
|
18
|
+
const spare = width - body - units[j].end;
|
|
19
|
+
if (spare < 0 && found) {
|
|
20
|
+
if (body >= width)
|
|
21
|
+
break;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const overflow = Math.max(0, -spare);
|
|
25
|
+
const cost = costs[j + 1] + width * width * 0.12 + (spare >= 0 ? spare * spare : width * width + 16 * overflow * overflow);
|
|
26
|
+
const clippedWidth = overflow + clipped[j + 1];
|
|
27
|
+
const improves = clippedWidth < clipped[i] || (clippedWidth === clipped[i] && cost <= costs[i]);
|
|
28
|
+
if (!found || (mode === 'greedy' ? spare >= 0 : improves)) {
|
|
29
|
+
clipped[i] = clippedWidth;
|
|
30
|
+
next[i] = j + 1;
|
|
31
|
+
costs[i] = cost;
|
|
32
|
+
}
|
|
33
|
+
found = true;
|
|
34
|
+
if (body >= width)
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const rows = [];
|
|
39
|
+
for (let i = 0; i < n; i = next[i])
|
|
40
|
+
rows.push(Array.from({ length: next[i] - i }, (_, k) => i + k));
|
|
41
|
+
return rows;
|
|
42
|
+
}
|
package/build/esm/src/tabnote.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Element } from './element.js';
|
|
2
2
|
import { Font } from './font.js';
|
|
3
3
|
import { Glyphs } from './glyphs.js';
|
|
4
|
+
import { attachGuitarGestures } from './guitarmodifiers.js';
|
|
4
5
|
import { Metrics } from './metrics.js';
|
|
5
6
|
import { Modifier } from './modifier.js';
|
|
6
7
|
import { Note } from './note.js';
|
|
@@ -90,6 +91,8 @@ export class TabNote extends StemmableNote {
|
|
|
90
91
|
}
|
|
91
92
|
this.ghost = false;
|
|
92
93
|
this.updateWidth();
|
|
94
|
+
if (this.notation.length)
|
|
95
|
+
attachGuitarGestures(this);
|
|
93
96
|
}
|
|
94
97
|
reset() {
|
|
95
98
|
super.reset();
|
|
@@ -279,7 +282,9 @@ export class TabNote extends StemmableNote {
|
|
|
279
282
|
this.setRendered();
|
|
280
283
|
const renderStem = this.beam === undefined && this.renderOptions.drawStem;
|
|
281
284
|
const clsAttribute = this.getAttribute('class');
|
|
282
|
-
ctx.openGroup('tabnote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
285
|
+
const group = ctx.openGroup('tabnote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
286
|
+
if (this.notation.length)
|
|
287
|
+
group === null || group === void 0 ? void 0 : group.setAttribute('aria-label', this.notation.map((entry) => entry.label).join(', '));
|
|
283
288
|
this.drawPositions();
|
|
284
289
|
this.drawStemThrough();
|
|
285
290
|
if (this.stem && renderStem) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BoundingBox } from './boundingbox.js';
|
|
1
2
|
import { Element } from './element.js';
|
|
2
3
|
import { Font } from './font.js';
|
|
3
4
|
import { Renderer } from './renderer.js';
|
|
@@ -69,9 +70,11 @@ export class TextBracket extends Element {
|
|
|
69
70
|
this.line = line;
|
|
70
71
|
return this;
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
setLayoutBaseline(y) {
|
|
74
|
+
this.layoutBaseline = y;
|
|
75
|
+
}
|
|
76
|
+
geometry() {
|
|
77
|
+
var _a;
|
|
75
78
|
let y = 0;
|
|
76
79
|
switch (this.position) {
|
|
77
80
|
case TextBracketPosition.TOP:
|
|
@@ -83,15 +86,14 @@ export class TextBracket extends Element {
|
|
|
83
86
|
default:
|
|
84
87
|
throw new RuntimeError('InvalidPosition', `The position ${this.position} is invalid.`);
|
|
85
88
|
}
|
|
89
|
+
y = (_a = this.layoutBaseline) !== null && _a !== void 0 ? _a : y;
|
|
86
90
|
const start = { x: this.start.getAbsoluteX(), y };
|
|
87
91
|
const stop = { x: this.stop.getAbsoluteX(), y };
|
|
88
92
|
L('Rendering TextBracket: start:', start, 'stop:', stop, 'y:', y);
|
|
89
93
|
const bracketHeight = this.renderOptions.bracketHeight * this.position;
|
|
90
|
-
this.textElement.renderText(ctx, start.x, start.y);
|
|
91
94
|
const mainWidth = this.textElement.getWidth();
|
|
92
95
|
const mainHeight = this.textElement.getHeight();
|
|
93
96
|
const superY = start.y - mainHeight / 2.5;
|
|
94
|
-
this.superscriptElement.renderText(ctx, start.x + mainWidth + 1, superY);
|
|
95
97
|
const superWidth = this.superscriptElement.getWidth();
|
|
96
98
|
const superHeight = this.superscriptElement.getHeight();
|
|
97
99
|
let startX = start.x;
|
|
@@ -108,6 +110,23 @@ export class TextBracket extends Element {
|
|
|
108
110
|
startX += superWidth;
|
|
109
111
|
}
|
|
110
112
|
}
|
|
113
|
+
return { start, superX: start.x + mainWidth + 1, superY, startX, endX, lineY, bracketHeight };
|
|
114
|
+
}
|
|
115
|
+
getBoundingBox() {
|
|
116
|
+
const { start, superX, superY, startX, endX, lineY, bracketHeight } = this.geometry();
|
|
117
|
+
const pad = this.renderOptions.lineWidth / 2;
|
|
118
|
+
const height = this.renderOptions.showBracket ? bracketHeight : 0;
|
|
119
|
+
return this.textElement
|
|
120
|
+
.getTextInk(start.x, start.y)
|
|
121
|
+
.mergeWith(this.superscriptElement.getTextInk(superX, superY))
|
|
122
|
+
.mergeWith(new BoundingBox(Math.min(startX, endX) - pad, Math.min(lineY, lineY + height) - pad, Math.abs(endX - startX) + 2 * pad, Math.abs(height) + 2 * pad));
|
|
123
|
+
}
|
|
124
|
+
draw() {
|
|
125
|
+
const ctx = this.checkContext();
|
|
126
|
+
this.setRendered();
|
|
127
|
+
const { start, superX, superY, startX, endX, lineY, bracketHeight } = this.geometry();
|
|
128
|
+
this.textElement.renderText(ctx, start.x, start.y);
|
|
129
|
+
this.superscriptElement.renderText(ctx, superX, superY);
|
|
111
130
|
if (this.renderOptions.dashed) {
|
|
112
131
|
Renderer.drawDashedLine(ctx, startX, lineY, endX, lineY, this.renderOptions.dash);
|
|
113
132
|
if (this.renderOptions.showBracket) {
|
|
@@ -140,12 +140,7 @@ export class TimeSignature extends StaveModifier {
|
|
|
140
140
|
this.setRendered();
|
|
141
141
|
if (this.isNumeric) {
|
|
142
142
|
let startX = x + this.topStartX;
|
|
143
|
-
|
|
144
|
-
this.topRenderY = stave.getYForLine(this.topLine - this.lineShift);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
this.topRenderY = (stave.getYForLine(this.topLine) + stave.getYForLine(this.bottomLine)) / 2;
|
|
148
|
-
}
|
|
143
|
+
this.topRenderY = this.topBaseline(stave);
|
|
149
144
|
this.topText.renderText(ctx, startX, this.topRenderY);
|
|
150
145
|
startX = x + this.botStartX;
|
|
151
146
|
this.botRenderY = stave.getYForLine(this.bottomLine + this.lineShift);
|
|
@@ -155,6 +150,20 @@ export class TimeSignature extends StaveModifier {
|
|
|
155
150
|
this.renderText(ctx, x - this.x, stave.getYForLine(this.line));
|
|
156
151
|
}
|
|
157
152
|
}
|
|
153
|
+
topBaseline(stave) {
|
|
154
|
+
return this.botText.getText().length
|
|
155
|
+
? stave.getYForLine(this.topLine - this.lineShift)
|
|
156
|
+
: (stave.getYForLine(this.topLine) + stave.getYForLine(this.bottomLine)) / 2;
|
|
157
|
+
}
|
|
158
|
+
getInkBounds() {
|
|
159
|
+
const stave = this.checkStave();
|
|
160
|
+
if (!this.isNumeric)
|
|
161
|
+
return this.getTextInk(this.x, stave.getYForLine(this.line));
|
|
162
|
+
const top = this.topText.getTextInk(this.x + this.topStartX, this.topBaseline(stave));
|
|
163
|
+
return this.botText.getText().length
|
|
164
|
+
? top.mergeWith(this.botText.getTextInk(this.x + this.botStartX, stave.getYForLine(this.bottomLine + this.lineShift)))
|
|
165
|
+
: top;
|
|
166
|
+
}
|
|
158
167
|
getBoundingBox() {
|
|
159
168
|
if (this.isNumeric) {
|
|
160
169
|
const topBoundingBox = this.topText.getBoundingBox();
|
package/build/esm/src/tuplet.js
CHANGED
|
@@ -208,6 +208,7 @@ export class Tuplet extends Element {
|
|
|
208
208
|
const annotations = (_c = (_b = note.getModifierContext()) === null || _b === void 0 ? void 0 : _b.getMembers("Annotation")) !== null && _c !== void 0 ? _c : [];
|
|
209
209
|
for (const mark of annotations) {
|
|
210
210
|
if (!isAnnotation(mark) ||
|
|
211
|
+
mark.phraseManaged ||
|
|
211
212
|
mark.getVerticalJustification() !== side ||
|
|
212
213
|
mark.checkAttachedNote().getStave() !== note.getStave())
|
|
213
214
|
continue;
|
package/build/esm/src/version.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const VERSION = '5.
|
|
2
|
-
export const ID = '
|
|
3
|
-
export const DATE = '2026-11-
|
|
1
|
+
export const VERSION = '5.4.0';
|
|
2
|
+
export const ID = '30054199edf019f97dcea2f2939430198f387f49';
|
|
3
|
+
export const DATE = '2026-11-19T00:43:30.372Z';
|
package/build/esm/src/vexflow.js
CHANGED
|
@@ -8,6 +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 { AlternatingTremolo } from './alternatingtremolo.js';
|
|
11
12
|
import { Annotation, AnnotationHorizontalJustify, AnnotationVerticalJustify } from './annotation.js';
|
|
12
13
|
import { Articulation } from './articulation.js';
|
|
13
14
|
import { BarNote } from './barnote.js';
|
|
@@ -29,6 +30,7 @@ import { Factory } from './factory.js';
|
|
|
29
30
|
import { Font, FontStyle, FontWeight } from './font.js';
|
|
30
31
|
import { Formatter } from './formatter.js';
|
|
31
32
|
import { Fraction } from './fraction.js';
|
|
33
|
+
import { FretDiagram } from './fretdiagram.js';
|
|
32
34
|
import { FretHandFinger } from './frethandfinger.js';
|
|
33
35
|
import { GhostNote } from './ghostnote.js';
|
|
34
36
|
import { GlyphNote } from './glyphnote.js';
|
|
@@ -36,6 +38,7 @@ import { Glyphs } from './glyphs.js';
|
|
|
36
38
|
import { GraceNote } from './gracenote.js';
|
|
37
39
|
import { GraceNoteGroup } from './gracenotegroup.js';
|
|
38
40
|
import { GraceTabNote } from './gracetabnote.js';
|
|
41
|
+
import { FrettedInstrument, PercussionMap } from './instrumentprofile.js';
|
|
39
42
|
import { KeyManager } from './keymanager.js';
|
|
40
43
|
import { KeySignature } from './keysignature.js';
|
|
41
44
|
import { KeySigNote } from './keysignote.js';
|
|
@@ -44,6 +47,7 @@ import { Modifier, ModifierPosition } from './modifier.js';
|
|
|
44
47
|
import { ModifierContext } from './modifiercontext.js';
|
|
45
48
|
import { MultiMeasureRest } from './multimeasurerest.js';
|
|
46
49
|
import { Music } from './music.js';
|
|
50
|
+
import { NotationSpelling, WrittenAccidentalState } from './notationspelling.js';
|
|
47
51
|
import { Note } from './note.js';
|
|
48
52
|
import { NoteHead } from './notehead.js';
|
|
49
53
|
import { NoteSubGroup } from './notesubgroup.js';
|
|
@@ -51,10 +55,13 @@ import { Ornament } from './ornament.js';
|
|
|
51
55
|
import { Parenthesis } from './parenthesis.js';
|
|
52
56
|
import { Parser } from './parser.js';
|
|
53
57
|
import { PedalMarking } from './pedalmarking.js';
|
|
58
|
+
import { PhraseLayout } from './phraselayout.js';
|
|
59
|
+
import { Publication } from './publication.js';
|
|
54
60
|
import { Registry } from './registry.js';
|
|
55
61
|
import { RenderContext } from './rendercontext.js';
|
|
56
62
|
import { Renderer, RendererBackends, RendererLineEndType } from './renderer.js';
|
|
57
63
|
import { RepeatNote } from './repeatnote.js';
|
|
64
|
+
import { ScoreNavigation } from './scorenavigation.js';
|
|
58
65
|
import { Sheet } from './sheet.js';
|
|
59
66
|
import { Stave } from './stave.js';
|
|
60
67
|
import { Barline, BarlineType, RepeatBracketType } from './stavebarline.js';
|
|
@@ -222,6 +229,7 @@ VexFlow.BUILD = {
|
|
|
222
229
|
INFO: '',
|
|
223
230
|
};
|
|
224
231
|
VexFlow.measureEngraving = measureEngraving;
|
|
232
|
+
VexFlow.PhraseLayout = PhraseLayout;
|
|
225
233
|
VexFlow.EngravingProfile = EngravingProfile;
|
|
226
234
|
VexFlow.Accidental = Accidental;
|
|
227
235
|
VexFlow.Annotation = Annotation;
|
|
@@ -284,7 +292,15 @@ VexFlow.StringNumber = StringNumber;
|
|
|
284
292
|
VexFlow.Stroke = Stroke;
|
|
285
293
|
VexFlow.SVGContext = SVGContext;
|
|
286
294
|
VexFlow.System = System;
|
|
295
|
+
VexFlow.ScoreNavigation = ScoreNavigation;
|
|
287
296
|
VexFlow.Sheet = Sheet;
|
|
297
|
+
VexFlow.FrettedInstrument = FrettedInstrument;
|
|
298
|
+
VexFlow.PercussionMap = PercussionMap;
|
|
299
|
+
VexFlow.FretDiagram = FretDiagram;
|
|
300
|
+
VexFlow.AlternatingTremolo = AlternatingTremolo;
|
|
301
|
+
VexFlow.WrittenAccidentalState = WrittenAccidentalState;
|
|
302
|
+
VexFlow.NotationSpelling = NotationSpelling;
|
|
303
|
+
VexFlow.Publication = Publication;
|
|
288
304
|
VexFlow.TabNote = TabNote;
|
|
289
305
|
VexFlow.TabSlide = TabSlide;
|
|
290
306
|
VexFlow.TabStave = TabStave;
|
package/build/esm/src/voice.js
CHANGED
|
@@ -24,6 +24,7 @@ export class Voice extends Element {
|
|
|
24
24
|
this.ticksUsed = new Fraction(0, 1);
|
|
25
25
|
this.largestTickWidth = 0;
|
|
26
26
|
this.tickables = [];
|
|
27
|
+
this.preserveStaveAssignments = false;
|
|
27
28
|
this.options = {
|
|
28
29
|
softmaxFactor: Tables.SOFTMAX_FACTOR,
|
|
29
30
|
};
|
|
@@ -199,12 +200,15 @@ export class Voice extends Element {
|
|
|
199
200
|
return defined(this.stave, 'NoStave', 'No stave attached to instance.');
|
|
200
201
|
}
|
|
201
202
|
draw(context = this.checkContext(), stave) {
|
|
202
|
-
|
|
203
|
+
const override = stave !== null && stave !== void 0 ? stave : (this.preserveStaveAssignments ? undefined : this.stave);
|
|
203
204
|
this.setRendered();
|
|
204
205
|
for (let i = 0; i < this.tickables.length; ++i) {
|
|
205
206
|
const tickable = this.tickables[i];
|
|
206
|
-
if (
|
|
207
|
-
tickable.setStave(
|
|
207
|
+
if (override) {
|
|
208
|
+
tickable.setStave(override);
|
|
209
|
+
}
|
|
210
|
+
else if (this.preserveStaveAssignments && !tickable.getStave() && this.stave) {
|
|
211
|
+
tickable.setStave(this.stave);
|
|
208
212
|
}
|
|
209
213
|
defined(tickable.getStave(), 'MissingStave', 'The voice cannot draw tickables without staves.');
|
|
210
214
|
tickable.setContext(context);
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export function makeContinuousStudy(VF, factory, kind, width, mode = 'balanced') {
|
|
2
|
+
const score = factory.EasyScore();
|
|
3
|
+
const measure = (notes, changes = {}) => (Object.assign(Object.assign({}, changes), { voices: [{ notes }] }));
|
|
4
|
+
const event = (key, duration, id, stave, clef) => ({
|
|
5
|
+
note: Object.assign({ keys: Array.isArray(key) ? key : [key], duration }, (clef ? { clef } : {})),
|
|
6
|
+
id,
|
|
7
|
+
stave,
|
|
8
|
+
});
|
|
9
|
+
const main = typeof VF.Sheet.prototype.getContinuousLayout === 'function';
|
|
10
|
+
let staves, spans = [], boundaries = [], groups = [];
|
|
11
|
+
if (kind === 'choir') {
|
|
12
|
+
const pitches = [
|
|
13
|
+
['g/4', 'a/4'],
|
|
14
|
+
['b/4', 'a/4'],
|
|
15
|
+
['g/4', 'e/4'],
|
|
16
|
+
['a/4', 'b/4'],
|
|
17
|
+
['a/4', 'g/4'],
|
|
18
|
+
['f#/4', 'g/4'],
|
|
19
|
+
];
|
|
20
|
+
staves = [
|
|
21
|
+
{
|
|
22
|
+
id: 'voice',
|
|
23
|
+
name: 'Voice',
|
|
24
|
+
shortName: 'V.',
|
|
25
|
+
measures: pitches.map((p, i) => measure(p.map((k, j) => event(k, 'h', 'v' + i + j)), i === 2 ? { key: 'D' } : {})),
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
spans = [
|
|
29
|
+
{ id: 'sung-word', kind: 'lyric', text: 'Sing', from: 'v00', to: 'v51' },
|
|
30
|
+
{ id: 'phrase', kind: 'slur', from: 'v00', to: 'v51', side: 'above' },
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
else if (kind === 'keyboard') {
|
|
34
|
+
const upper = [
|
|
35
|
+
['e/5', 'd/5'],
|
|
36
|
+
['c/5', 'b/4'],
|
|
37
|
+
['a/4', 'g/4'],
|
|
38
|
+
['f/4', 'e/4'],
|
|
39
|
+
];
|
|
40
|
+
const lower = ['c/3', 'e/3', 'f/3', 'c/3'];
|
|
41
|
+
staves = [
|
|
42
|
+
{
|
|
43
|
+
id: 'right',
|
|
44
|
+
name: 'Piano',
|
|
45
|
+
shortName: 'Pno.',
|
|
46
|
+
measures: upper.map((p, i) => measure(p.map((k, j) => event(k, 'h', 'r' + i + j)))),
|
|
47
|
+
},
|
|
48
|
+
{ id: 'left', clef: 'bass', measures: lower.map((k, i) => measure([event(k, 'w', 'l' + i)])) },
|
|
49
|
+
];
|
|
50
|
+
staves[0].measures[0].voices = [
|
|
51
|
+
{
|
|
52
|
+
autoBeam: true,
|
|
53
|
+
stem: 'down',
|
|
54
|
+
notes: [
|
|
55
|
+
event('e/5', '8', 'r00'),
|
|
56
|
+
event('b/3', '8', 'cross', 'left', 'bass'),
|
|
57
|
+
event('d/5', 'q', 'r01'),
|
|
58
|
+
event('c/5', 'h', 'rch'),
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
spans = [
|
|
63
|
+
{ id: 'swell', kind: 'crescendo', from: 'r01', to: 'r31' },
|
|
64
|
+
{ id: 'sustain', kind: 'pedal', from: 'l0', to: 'l3' },
|
|
65
|
+
];
|
|
66
|
+
groups = [{ first: 'right', last: 'left', type: 'brace', barlines: true }];
|
|
67
|
+
boundaries = [{ measure: 3, breakBefore: 'force', rehearsal: 'B' }];
|
|
68
|
+
}
|
|
69
|
+
else if (kind === 'chord') {
|
|
70
|
+
const part = (staff, clef, pitches) => ({
|
|
71
|
+
id: staff,
|
|
72
|
+
clef,
|
|
73
|
+
measures: pitches.map((pair, i) => measure(pair.map((key, k) => ({ id: staff + i + k, note: { keys: [key], duration: 'h', stemDirection: 1 } })))),
|
|
74
|
+
});
|
|
75
|
+
staves = [
|
|
76
|
+
part('rh', 'treble', [
|
|
77
|
+
['e/4', 'g/4'],
|
|
78
|
+
['a/4', 'b/4'],
|
|
79
|
+
]),
|
|
80
|
+
part('lh', 'bass', [
|
|
81
|
+
['c/3', 'e/3'],
|
|
82
|
+
['f/3', 'g/3'],
|
|
83
|
+
]),
|
|
84
|
+
];
|
|
85
|
+
groups = [{ first: 'rh', last: 'lh', type: 'brace', barlines: true }];
|
|
86
|
+
}
|
|
87
|
+
else if (kind === 'ensemble') {
|
|
88
|
+
const rest = () => measure([event('b/4', 'wr')]);
|
|
89
|
+
const make = (staff, pitches) => pitches.map((p, i) => (p ? measure([event(p, 'w', staff + i)]) : rest()));
|
|
90
|
+
staves = [
|
|
91
|
+
{ id: 'fl', name: 'Flute', shortName: 'Fl.', measures: make('fl', ['e/5', null, null, null, 'd/5', 'e/5']) },
|
|
92
|
+
{
|
|
93
|
+
id: 'vc',
|
|
94
|
+
clef: 'bass',
|
|
95
|
+
name: 'Cello',
|
|
96
|
+
shortName: 'Vc.',
|
|
97
|
+
measures: make('vc', [null, null, null, null, 'g/2', 'c/3']),
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
boundaries = [
|
|
101
|
+
{ measure: 5, breakBefore: 'force', rehearsal: 'B', repeatStart: true },
|
|
102
|
+
{ measure: 6, repeatEnd: true },
|
|
103
|
+
];
|
|
104
|
+
groups = [{ first: 'fl', last: 'vc', type: 'bracket' }];
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const content = ['C4/q, D4/q, E4/q, F4/q', 'G4/w', 'F4/w', 'E4/w', 'D4/w', 'C4/w', 'G4/w'];
|
|
108
|
+
staves = [{ id: 'line', measures: content.map((n) => measure(n)) }];
|
|
109
|
+
}
|
|
110
|
+
const result = score.compose({
|
|
111
|
+
sheet: { width, x: 12, y: 8, rowGap: 14, measurePadding: 14 },
|
|
112
|
+
system: { spaceBetweenStaves: 8 },
|
|
113
|
+
accidentals: 'key-aware',
|
|
114
|
+
staves,
|
|
115
|
+
continuous: {
|
|
116
|
+
mode,
|
|
117
|
+
groups,
|
|
118
|
+
spans,
|
|
119
|
+
boundaries,
|
|
120
|
+
measureNumbers: true,
|
|
121
|
+
hideEmptyStaves: kind === 'ensemble',
|
|
122
|
+
splitChords: kind === 'chord' ? [{ id: 'split', upper: 'rh00', lower: 'lh00' }] : [],
|
|
123
|
+
compressRests: kind === 'ensemble',
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
if (kind === 'chord') {
|
|
127
|
+
const arpeggio = factory
|
|
128
|
+
.Stroke(VF.Stroke.Type.ARPEGGIO_DIRECTIONLESS, { allVoices: false })
|
|
129
|
+
.addEndNote(result.getNote('lh00'));
|
|
130
|
+
result.getNote('rh00').addModifier(arpeggio, 0);
|
|
131
|
+
}
|
|
132
|
+
if (kind === 'keyboard') {
|
|
133
|
+
const cross = result.getNote('cross'), beam = cross.getBeam();
|
|
134
|
+
if (beam)
|
|
135
|
+
cross.setStemDirection(1).setBeam(beam);
|
|
136
|
+
}
|
|
137
|
+
if (!main && kind === 'choir')
|
|
138
|
+
result.getNote('v00').addModifier(factory.Annotation({ text: 'Sing' }), 0);
|
|
139
|
+
return result;
|
|
140
|
+
}
|