vexflow 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- 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 +91 -19
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +37 -16
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow-gonville.js +2 -2
- package/build/cjs/vexflow-gonville.js.map +1 -1
- package/build/cjs/vexflow-petaluma.js +2 -2
- package/build/cjs/vexflow-petaluma.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/beam.js +2 -0
- package/build/esm/src/stave.js +2 -2
- package/build/esm/src/staveconnector.js +6 -3
- package/build/esm/src/stavenote.js +9 -1
- package/build/esm/src/stavesection.js +9 -6
- package/build/esm/src/version.js +3 -3
- package/build/esm/tests/formatter_tests.js +53 -2
- package/build/esm/tests/stave_tests.js +1 -1
- package/build/types/src/factory.d.ts +2 -2
- package/build/types/src/stave.d.ts +1 -1
- package/build/types/src/staveconnector.d.ts +13 -15
- package/build/types/src/stavesection.d.ts +2 -1
- package/build/types/src/system.d.ts +2 -2
- package/package.json +3 -1
- package/releases/vexflow-debug.js +30441 -0
- package/releases/vexflow-min.js +6 -0
- package/src/beam.ts +2 -0
- package/src/factory.ts +2 -2
- package/src/stave.ts +2 -2
- package/src/staveconnector.ts +43 -9
- package/src/stavenote.ts +7 -1
- package/src/stavesection.ts +10 -6
- package/src/system.ts +2 -2
package/build/esm/src/beam.js
CHANGED
|
@@ -574,6 +574,8 @@ export class Beam extends Element {
|
|
|
574
574
|
this.notes.forEach((note) => {
|
|
575
575
|
const stem = note.getStem();
|
|
576
576
|
if (stem) {
|
|
577
|
+
const stem_x = note.getStemX();
|
|
578
|
+
stem.setNoteHeadXBounds(stem_x, stem_x);
|
|
577
579
|
ctx.openGroup('stem', note.getAttribute('id') + '-stem');
|
|
578
580
|
stem.setContext(ctx).draw();
|
|
579
581
|
ctx.closeGroup();
|
package/build/esm/src/stave.js
CHANGED
|
@@ -179,8 +179,8 @@ export class Stave extends Element {
|
|
|
179
179
|
this.modifiers.push(new Volta(type, number_t, this.x, y));
|
|
180
180
|
return this;
|
|
181
181
|
}
|
|
182
|
-
setSection(section, y, xOffset = 0, fontSize) {
|
|
183
|
-
const staveSection = new StaveSection(section, this.x + xOffset, y);
|
|
182
|
+
setSection(section, y, xOffset = 0, fontSize, drawRect = true) {
|
|
183
|
+
const staveSection = new StaveSection(section, this.x + xOffset, y, drawRect);
|
|
184
184
|
if (fontSize)
|
|
185
185
|
staveSection.setFontSize(fontSize);
|
|
186
186
|
this.modifiers.push(staveSection);
|
|
@@ -33,12 +33,15 @@ export class StaveConnector extends Element {
|
|
|
33
33
|
return "StaveConnector";
|
|
34
34
|
}
|
|
35
35
|
setType(type) {
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
this.type =
|
|
36
|
+
const newType = typeof type === 'string' ? StaveConnector.typeString[type] : type;
|
|
37
|
+
if (Object.values(StaveConnector.type).includes(newType)) {
|
|
38
|
+
this.type = newType;
|
|
39
39
|
}
|
|
40
40
|
return this;
|
|
41
41
|
}
|
|
42
|
+
getType() {
|
|
43
|
+
return this.type;
|
|
44
|
+
}
|
|
42
45
|
setText(text, options = {}) {
|
|
43
46
|
this.texts.push({
|
|
44
47
|
content: text,
|
|
@@ -177,7 +177,7 @@ export class StaveNote extends StemmableNote {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
else {
|
|
180
|
+
else if (lineDiff < 1) {
|
|
181
181
|
xShift = voiceXShift + 2;
|
|
182
182
|
if (noteU.stemDirection === noteL.stemDirection) {
|
|
183
183
|
noteU.note.setXShift(xShift);
|
|
@@ -186,6 +186,14 @@ export class StaveNote extends StemmableNote {
|
|
|
186
186
|
noteL.note.setXShift(xShift);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
+
else if (noteU.note.hasStem()) {
|
|
190
|
+
noteU.stemDirection = -noteU.note.getStemDirection();
|
|
191
|
+
noteU.note.setStemDirection(noteU.stemDirection);
|
|
192
|
+
}
|
|
193
|
+
else if (noteL.note.hasStem()) {
|
|
194
|
+
noteL.stemDirection = -noteL.note.getStemDirection();
|
|
195
|
+
noteL.note.setStemDirection(noteL.stemDirection);
|
|
196
|
+
}
|
|
189
197
|
}
|
|
190
198
|
}
|
|
191
199
|
state.right_shift += xShift;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Font, FontStyle, FontWeight } from './font.js';
|
|
2
2
|
import { StaveModifier } from './stavemodifier.js';
|
|
3
3
|
export class StaveSection extends StaveModifier {
|
|
4
|
-
constructor(section, x, shift_y) {
|
|
4
|
+
constructor(section, x, shift_y, drawRect = true) {
|
|
5
5
|
super();
|
|
6
6
|
this.setWidth(16);
|
|
7
7
|
this.section = section;
|
|
8
8
|
this.x = x;
|
|
9
9
|
this.shift_x = 0;
|
|
10
10
|
this.shift_y = shift_y;
|
|
11
|
+
this.drawRect = drawRect;
|
|
11
12
|
this.resetFont();
|
|
12
13
|
}
|
|
13
14
|
static get CATEGORY() {
|
|
@@ -39,12 +40,14 @@ export class StaveSection extends StaveModifier {
|
|
|
39
40
|
const textHeight = textMeasurements.height;
|
|
40
41
|
const width = textWidth + 2 * paddingX;
|
|
41
42
|
const height = textHeight + 2 * paddingY;
|
|
42
|
-
const y = stave.getYForTopText(
|
|
43
|
+
const y = stave.getYForTopText(1.5) + this.shift_y;
|
|
43
44
|
const x = this.x + shift_x;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
if (this.drawRect) {
|
|
46
|
+
ctx.beginPath();
|
|
47
|
+
ctx.setLineWidth(rectWidth);
|
|
48
|
+
ctx.rect(x, y + textMeasurements.y - paddingY, width, height);
|
|
49
|
+
ctx.stroke();
|
|
50
|
+
}
|
|
48
51
|
ctx.fillText(this.section, x + paddingX, y);
|
|
49
52
|
ctx.restore();
|
|
50
53
|
return this;
|
package/build/esm/src/version.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const VERSION = '4.0.
|
|
2
|
-
export const ID = '
|
|
3
|
-
export const DATE = '2022-
|
|
1
|
+
export const VERSION = '4.0.2';
|
|
2
|
+
export const ID = 'a968cfa5453a34ff0f8bb8bc882d08ef44f62cea';
|
|
3
|
+
export const DATE = '2022-04-28T00:14:05.094Z';
|
|
@@ -26,6 +26,7 @@ const FormatterTests = {
|
|
|
26
26
|
QUnit.module('Formatter');
|
|
27
27
|
test('TickContext Building', buildTickContexts);
|
|
28
28
|
const run = VexFlowTests.runTests;
|
|
29
|
+
run('Penultimate Note Padding', penultimateNote);
|
|
29
30
|
run('Whitespace and justify', rightJustify);
|
|
30
31
|
run('Notehead padding', noteHeadPadding);
|
|
31
32
|
run('Justification and alignment with accidentals', accidentalJustification);
|
|
@@ -85,7 +86,7 @@ function buildTickContexts() {
|
|
|
85
86
|
ok(tickables1[1].getX() < tickables2[1].getX(), 'Second note of voice 2 is to the right of the second note of voice 1');
|
|
86
87
|
}
|
|
87
88
|
function rightJustify(options) {
|
|
88
|
-
const f = VexFlowTests.makeFactory(options, 1200,
|
|
89
|
+
const f = VexFlowTests.makeFactory(options, 1200, 150);
|
|
89
90
|
const getTickables = (time, n, duration, duration2) => {
|
|
90
91
|
const tickar = [];
|
|
91
92
|
let i = 0;
|
|
@@ -97,7 +98,7 @@ function rightJustify(options) {
|
|
|
97
98
|
};
|
|
98
99
|
const renderTest = (time, n, duration, duration2, x, width) => {
|
|
99
100
|
const formatter = f.Formatter();
|
|
100
|
-
const stave = f.Stave({ x, y:
|
|
101
|
+
const stave = f.Stave({ x, y: 20, width });
|
|
101
102
|
const voice = getTickables(time, n, duration, duration2);
|
|
102
103
|
formatter.joinVoices([voice]).formatToStave([voice], stave);
|
|
103
104
|
stave.draw();
|
|
@@ -109,6 +110,54 @@ function rightJustify(options) {
|
|
|
109
110
|
renderTest({ num_beats: 3, beat_value: 4, resolution: 4 * 4096 }, 6, '8', '8', 910, 300);
|
|
110
111
|
ok(true);
|
|
111
112
|
}
|
|
113
|
+
function penultimateNote(options) {
|
|
114
|
+
const f = VexFlowTests.makeFactory(options, 500, 550);
|
|
115
|
+
const score = f.EasyScore();
|
|
116
|
+
const staffWidth = 310;
|
|
117
|
+
let system = undefined;
|
|
118
|
+
let voices = [];
|
|
119
|
+
let notes = [];
|
|
120
|
+
let note = undefined;
|
|
121
|
+
let stave = undefined;
|
|
122
|
+
let y = 10;
|
|
123
|
+
const draw = (softmax) => {
|
|
124
|
+
system = f.System({
|
|
125
|
+
width: staffWidth,
|
|
126
|
+
y,
|
|
127
|
+
formatOptions: { align_rests: true },
|
|
128
|
+
details: { softmaxFactor: softmax },
|
|
129
|
+
});
|
|
130
|
+
notes = [];
|
|
131
|
+
voices = [];
|
|
132
|
+
note = score.notes('C4/8/r', { clef: 'bass' })[0];
|
|
133
|
+
notes.push(note);
|
|
134
|
+
note = score.notes('A3/8', { stem: 'up', clef: 'bass' })[0];
|
|
135
|
+
notes.push(note);
|
|
136
|
+
note = score.notes('C4/4', { stem: 'up', clef: 'bass' })[0];
|
|
137
|
+
notes.push(note);
|
|
138
|
+
voices.push(score.voice(notes).setMode(2));
|
|
139
|
+
notes = [];
|
|
140
|
+
note = score.notes('( F3 A3 )/4', { stem: 'down', clef: 'bass' })[0];
|
|
141
|
+
notes.push(note);
|
|
142
|
+
note = score.notes('B4/4/r', {})[0];
|
|
143
|
+
notes.push(note);
|
|
144
|
+
voices.push(score.voice(notes).setMode(2));
|
|
145
|
+
notes = [];
|
|
146
|
+
stave = system.addStave({ voices: voices });
|
|
147
|
+
stave.addClef('bass');
|
|
148
|
+
stave.addTimeSignature('2/4');
|
|
149
|
+
voices = [];
|
|
150
|
+
f.draw();
|
|
151
|
+
f.getContext().fillText(`softmax: ${softmax.toString()}`, staffWidth + 20, y + 50);
|
|
152
|
+
y += 100;
|
|
153
|
+
};
|
|
154
|
+
draw(100);
|
|
155
|
+
draw(10);
|
|
156
|
+
draw(5);
|
|
157
|
+
draw(2);
|
|
158
|
+
draw(1.5);
|
|
159
|
+
ok(true);
|
|
160
|
+
}
|
|
112
161
|
function noteHeadPadding(options) {
|
|
113
162
|
const registry = new Registry();
|
|
114
163
|
Registry.enableDefaultRegistry(registry);
|
|
@@ -474,6 +523,7 @@ function proportional(options) {
|
|
|
474
523
|
}
|
|
475
524
|
function softMax(options) {
|
|
476
525
|
const f = VexFlowTests.makeFactory(options, 550, 500);
|
|
526
|
+
const textX = 450 / 0.8;
|
|
477
527
|
f.getContext().scale(0.8, 0.8);
|
|
478
528
|
function draw(y, factor) {
|
|
479
529
|
const score = f.EasyScore();
|
|
@@ -495,6 +545,7 @@ function softMax(options) {
|
|
|
495
545
|
.addClef('treble')
|
|
496
546
|
.addTimeSignature('5/4');
|
|
497
547
|
f.draw();
|
|
548
|
+
f.getContext().fillText(`softmax: ${factor.toString()}`, textX, y + 50);
|
|
498
549
|
ok(true);
|
|
499
550
|
}
|
|
500
551
|
draw(50, 1);
|
|
@@ -97,7 +97,7 @@ function drawMultipleMeasures(options, contextBuilder) {
|
|
|
97
97
|
const staveBar1 = new Stave(10, 50, 200);
|
|
98
98
|
staveBar1.setBegBarType(BarlineType.REPEAT_BEGIN);
|
|
99
99
|
staveBar1.setEndBarType(BarlineType.DOUBLE);
|
|
100
|
-
staveBar1.setSection('A', 0, 0, (_a = options.params) === null || _a === void 0 ? void 0 : _a.fontSize);
|
|
100
|
+
staveBar1.setSection('A', 0, 0, (_a = options.params) === null || _a === void 0 ? void 0 : _a.fontSize, false);
|
|
101
101
|
staveBar1.addClef('treble').setContext(ctx).draw();
|
|
102
102
|
const notesBar1 = [
|
|
103
103
|
new StaveNote({ keys: ['c/4'], duration: 'q' }),
|
|
@@ -26,7 +26,7 @@ import { RenderContext } from './rendercontext';
|
|
|
26
26
|
import { RepeatNote } from './repeatnote';
|
|
27
27
|
import { Stave, StaveOptions } from './stave';
|
|
28
28
|
import { BarlineType } from './stavebarline';
|
|
29
|
-
import { StaveConnector } from './staveconnector';
|
|
29
|
+
import { StaveConnector, StaveConnectorType } from './staveconnector';
|
|
30
30
|
import { StaveLine } from './staveline';
|
|
31
31
|
import { StaveNote, StaveNoteStruct } from './stavenote';
|
|
32
32
|
import { StaveTie } from './stavetie';
|
|
@@ -186,7 +186,7 @@ export declare class Factory {
|
|
|
186
186
|
StaveConnector(params: {
|
|
187
187
|
top_stave: Stave;
|
|
188
188
|
bottom_stave: Stave;
|
|
189
|
-
type:
|
|
189
|
+
type: StaveConnectorType;
|
|
190
190
|
}): StaveConnector;
|
|
191
191
|
Formatter(options?: FormatterOptions): Formatter;
|
|
192
192
|
Tuplet(params?: {
|
|
@@ -73,7 +73,7 @@ export declare class Stave extends Element {
|
|
|
73
73
|
/** Coda & Segno Symbol functions */
|
|
74
74
|
setRepetitionType(type: number, yShift?: number): this;
|
|
75
75
|
setVoltaType(type: number, number_t: string, y: number): this;
|
|
76
|
-
setSection(section: string, y: number, xOffset?: number, fontSize?: number): this;
|
|
76
|
+
setSection(section: string, y: number, xOffset?: number, fontSize?: number, drawRect?: boolean): this;
|
|
77
77
|
setTempo(tempo: StaveTempoOptions, y: number): this;
|
|
78
78
|
setText(text: string, position: number, options?: {
|
|
79
79
|
shift_x?: number;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Element } from './element';
|
|
2
2
|
import { FontInfo } from './font';
|
|
3
3
|
import { Stave } from './stave';
|
|
4
|
+
/**
|
|
5
|
+
* see {@link StaveConnector.type} & {@link StaveConnector.typeString}
|
|
6
|
+
*/
|
|
7
|
+
export declare type StaveConnectorType = 'singleRight' | 'singleLeft' | 'single' | 'double' | 'brace' | 'bracket' | 'boldDoubleLeft' | 'boldDoubleRight' | 'thinDouble' | 'none' | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
4
8
|
/** StaveConnector implements the connector lines between staves of a system. */
|
|
5
9
|
export declare class StaveConnector extends Element {
|
|
6
10
|
static get CATEGORY(): string;
|
|
@@ -10,18 +14,7 @@ export declare class StaveConnector extends Element {
|
|
|
10
14
|
* with older versions of vexflow which didn't have right sided
|
|
11
15
|
* stave connectors.
|
|
12
16
|
*/
|
|
13
|
-
static readonly type:
|
|
14
|
-
SINGLE_RIGHT: number;
|
|
15
|
-
SINGLE_LEFT: number;
|
|
16
|
-
SINGLE: number;
|
|
17
|
-
DOUBLE: number;
|
|
18
|
-
BRACE: number;
|
|
19
|
-
BRACKET: number;
|
|
20
|
-
BOLD_DOUBLE_LEFT: number;
|
|
21
|
-
BOLD_DOUBLE_RIGHT: number;
|
|
22
|
-
THIN_DOUBLE: number;
|
|
23
|
-
NONE: number;
|
|
24
|
-
};
|
|
17
|
+
static readonly type: Record<string, Exclude<StaveConnectorType, string>>;
|
|
25
18
|
/**
|
|
26
19
|
* Connector type:
|
|
27
20
|
* * "singleRight"
|
|
@@ -35,7 +28,7 @@ export declare class StaveConnector extends Element {
|
|
|
35
28
|
* * "thinDouble"
|
|
36
29
|
* * "none"
|
|
37
30
|
*/
|
|
38
|
-
static readonly typeString: Record<
|
|
31
|
+
static readonly typeString: Record<Exclude<StaveConnectorType, number>, Exclude<StaveConnectorType, string>>;
|
|
39
32
|
protected width: number;
|
|
40
33
|
protected texts: {
|
|
41
34
|
content: string;
|
|
@@ -44,7 +37,7 @@ export declare class StaveConnector extends Element {
|
|
|
44
37
|
shift_y: number;
|
|
45
38
|
};
|
|
46
39
|
}[];
|
|
47
|
-
protected type:
|
|
40
|
+
protected type: typeof StaveConnector['type'][keyof typeof StaveConnector['type']];
|
|
48
41
|
readonly top_stave: Stave;
|
|
49
42
|
readonly bottom_stave: Stave;
|
|
50
43
|
readonly thickness: number;
|
|
@@ -54,7 +47,12 @@ export declare class StaveConnector extends Element {
|
|
|
54
47
|
* Set type.
|
|
55
48
|
* @param type see {@link StaveConnector.type} & {@link StaveConnector.typeString}
|
|
56
49
|
*/
|
|
57
|
-
setType(type:
|
|
50
|
+
setType(type: StaveConnectorType): this;
|
|
51
|
+
/**
|
|
52
|
+
* Get type.
|
|
53
|
+
* @returns number {@link StaveConnector.type}
|
|
54
|
+
*/
|
|
55
|
+
getType(): number;
|
|
58
56
|
/** Set optional associated Text. */
|
|
59
57
|
setText(text: string, options?: {
|
|
60
58
|
shift_x?: number;
|
|
@@ -7,7 +7,8 @@ export declare class StaveSection extends StaveModifier {
|
|
|
7
7
|
protected section: string;
|
|
8
8
|
protected shift_x: number;
|
|
9
9
|
protected shift_y: number;
|
|
10
|
-
|
|
10
|
+
protected drawRect: boolean;
|
|
11
|
+
constructor(section: string, x: number, shift_y: number, drawRect?: boolean);
|
|
11
12
|
setStaveSection(section: string): this;
|
|
12
13
|
setShiftX(x: number): this;
|
|
13
14
|
setShiftY(y: number): this;
|
|
@@ -3,7 +3,7 @@ import { Factory } from './factory';
|
|
|
3
3
|
import { FormatParams, Formatter, FormatterOptions } from './formatter';
|
|
4
4
|
import { RenderContext } from './rendercontext';
|
|
5
5
|
import { Stave, StaveOptions } from './stave';
|
|
6
|
-
import { StaveConnector } from './staveconnector';
|
|
6
|
+
import { StaveConnector, StaveConnectorType } from './staveconnector';
|
|
7
7
|
import { Voice } from './voice';
|
|
8
8
|
export interface SystemFormatterOptions extends FormatterOptions {
|
|
9
9
|
alpha?: number;
|
|
@@ -69,7 +69,7 @@ export declare class System extends Element {
|
|
|
69
69
|
* Add connector between staves.
|
|
70
70
|
* @param type see {@link StaveConnector.typeString}
|
|
71
71
|
*/
|
|
72
|
-
addConnector(type?:
|
|
72
|
+
addConnector(type?: StaveConnectorType): StaveConnector;
|
|
73
73
|
/**
|
|
74
74
|
* Add a stave to the system.
|
|
75
75
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vexflow",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "A JavaScript library for rendering music notation and guitar tablature.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -72,6 +72,8 @@
|
|
|
72
72
|
"tests/flow.html",
|
|
73
73
|
"tests/flow.css",
|
|
74
74
|
"tests/support",
|
|
75
|
+
"releases/vexflow-min.js",
|
|
76
|
+
"releases/vexflow-debug.js",
|
|
75
77
|
"AUTHORS.md"
|
|
76
78
|
],
|
|
77
79
|
"bugs": {
|