@mcqj/vexflow 0.0.1-alpha.4 → 0.0.1-alpha.5
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/build/cjs/vexflow-bravura.js +1 -1
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +1 -1
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +81 -10
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +26 -10
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +1 -1
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/formatter.js +12 -5
- package/build/esm/src/tickcontext.js +7 -2
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/voice.js +8 -0
- package/build/esm/tests/formatter_tests.js +37 -0
- package/build/types/src/tickcontext.d.ts +2 -1
- package/build/types/src/voice.d.ts +5 -0
- package/package.json +3 -2
|
@@ -6,13 +6,16 @@ import { Stave } from './stave.js';
|
|
|
6
6
|
import { StaveConnector } from './staveconnector.js';
|
|
7
7
|
import { Tables } from './tables.js';
|
|
8
8
|
import { TickContext } from './tickcontext.js';
|
|
9
|
-
import { isNote, isStaveNote } from './typeguard.js';
|
|
9
|
+
import { isCategory, isNote, isStaveNote } from './typeguard.js';
|
|
10
10
|
import { defined, log, midLine, RuntimeError, sumArray } from './util.js';
|
|
11
11
|
import { Voice } from './voice.js';
|
|
12
12
|
function L(...args) {
|
|
13
13
|
if (Formatter.DEBUG)
|
|
14
14
|
log('VexFlow.Formatter', args);
|
|
15
15
|
}
|
|
16
|
+
function isBarNote(tickable) {
|
|
17
|
+
return isCategory(tickable, "BarNote");
|
|
18
|
+
}
|
|
16
19
|
function getRestLineForNextNoteGroup(notes, currRestLine, currNoteIndex, compare) {
|
|
17
20
|
let nextRestLine = currRestLine;
|
|
18
21
|
for (let noteIndex = currNoteIndex + 1; noteIndex < notes.length; noteIndex++) {
|
|
@@ -249,7 +252,9 @@ export class Formatter {
|
|
|
249
252
|
staveTickToContextMap[integerTicks] = newContext;
|
|
250
253
|
}
|
|
251
254
|
tickable.addToModifierContext(staveTickToContextMap[integerTicks]);
|
|
252
|
-
|
|
255
|
+
if (!isBarNote(tickable)) {
|
|
256
|
+
ticksUsed.add(tickable.getTicks());
|
|
257
|
+
}
|
|
253
258
|
});
|
|
254
259
|
});
|
|
255
260
|
this.modifierContexts.push({
|
|
@@ -282,8 +287,10 @@ export class Formatter {
|
|
|
282
287
|
tickList.push(integerTicks);
|
|
283
288
|
}
|
|
284
289
|
const tickContext = tickToContextMap[integerTicks];
|
|
285
|
-
tickContext.addTickable(tickable, voiceIndex);
|
|
286
|
-
|
|
290
|
+
tickContext.addTickable(tickable, voiceIndex, voice.isDependent());
|
|
291
|
+
if (!isBarNote(tickable)) {
|
|
292
|
+
ticksUsed.add(tickable.getTicks());
|
|
293
|
+
}
|
|
287
294
|
});
|
|
288
295
|
});
|
|
289
296
|
const contexts = {
|
|
@@ -349,7 +356,7 @@ export class Formatter {
|
|
|
349
356
|
const backVoices = backTick.getTickablesByVoice();
|
|
350
357
|
const matchingVoices = [];
|
|
351
358
|
Object.keys(voices).forEach((v) => {
|
|
352
|
-
if (backVoices[v]) {
|
|
359
|
+
if (backVoices[v] && !voices[v].getVoice().isDependent()) {
|
|
353
360
|
matchingVoices.push(v);
|
|
354
361
|
}
|
|
355
362
|
});
|
|
@@ -22,6 +22,7 @@ export class TickContext {
|
|
|
22
22
|
this.xBase = 0;
|
|
23
23
|
this.xOffset = 0;
|
|
24
24
|
this.tickables = [];
|
|
25
|
+
this.dependentTickables = new Set();
|
|
25
26
|
this.tickablesByVoice = {};
|
|
26
27
|
this.notePx = 0;
|
|
27
28
|
this.glyphPx = 0;
|
|
@@ -115,11 +116,11 @@ export class TickContext {
|
|
|
115
116
|
this.currentTick = tick;
|
|
116
117
|
this.preFormatted = false;
|
|
117
118
|
}
|
|
118
|
-
addTickable(tickable, voiceIndex) {
|
|
119
|
+
addTickable(tickable, voiceIndex, dependent = false) {
|
|
119
120
|
if (!tickable) {
|
|
120
121
|
throw new RuntimeError('BadArgument', 'Invalid tickable added.');
|
|
121
122
|
}
|
|
122
|
-
if (!tickable.shouldIgnoreTicks()) {
|
|
123
|
+
if (!dependent && !tickable.shouldIgnoreTicks()) {
|
|
123
124
|
const ticks = tickable.getTicks();
|
|
124
125
|
if (ticks.greaterThan(this.maxTicks)) {
|
|
125
126
|
this.maxTicks = ticks.clone();
|
|
@@ -136,6 +137,8 @@ export class TickContext {
|
|
|
136
137
|
}
|
|
137
138
|
tickable.setTickContext(this);
|
|
138
139
|
this.tickables.push(tickable);
|
|
140
|
+
if (dependent)
|
|
141
|
+
this.dependentTickables.add(tickable);
|
|
139
142
|
this.tickablesByVoice[voiceIndex !== null && voiceIndex !== void 0 ? voiceIndex : 0] = tickable;
|
|
140
143
|
this.preFormatted = false;
|
|
141
144
|
return this;
|
|
@@ -147,6 +150,8 @@ export class TickContext {
|
|
|
147
150
|
for (let i = 0; i < this.tickables.length; ++i) {
|
|
148
151
|
const tickable = this.tickables[i];
|
|
149
152
|
tickable.preFormat();
|
|
153
|
+
if (this.dependentTickables.has(tickable))
|
|
154
|
+
continue;
|
|
150
155
|
const metrics = tickable.getMetrics();
|
|
151
156
|
this.leftDisplacedHeadPx = Math.max(this.leftDisplacedHeadPx, metrics.leftDisplacedHeadPx);
|
|
152
157
|
this.rightDisplacedHeadPx = Math.max(this.rightDisplacedHeadPx, metrics.rightDisplacedHeadPx);
|
package/build/esm/src/version.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const VERSION = '0.0.1-alpha.
|
|
2
|
-
export const ID = '
|
|
3
|
-
export const DATE = '2026-09-
|
|
1
|
+
export const VERSION = '0.0.1-alpha.5';
|
|
2
|
+
export const ID = 'a4bb5ff157f4570b2d6149b7199b0baa4c7e3775';
|
|
3
|
+
export const DATE = '2026-09-14T15:08:25.126Z';
|
package/build/esm/src/voice.js
CHANGED
|
@@ -20,6 +20,7 @@ export class Voice extends Element {
|
|
|
20
20
|
this.resolutionMultiplier = 1;
|
|
21
21
|
this.mode = VoiceMode.STRICT;
|
|
22
22
|
this.preFormatted = false;
|
|
23
|
+
this.dependent = false;
|
|
23
24
|
this.ticksUsed = new Fraction(0, 1);
|
|
24
25
|
this.largestTickWidth = 0;
|
|
25
26
|
this.tickables = [];
|
|
@@ -65,6 +66,13 @@ export class Voice extends Element {
|
|
|
65
66
|
this.mode = mode;
|
|
66
67
|
return this;
|
|
67
68
|
}
|
|
69
|
+
setDependent(dependent) {
|
|
70
|
+
this.dependent = dependent;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
isDependent() {
|
|
74
|
+
return this.dependent;
|
|
75
|
+
}
|
|
68
76
|
getResolutionMultiplier() {
|
|
69
77
|
return this.resolutionMultiplier;
|
|
70
78
|
}
|
|
@@ -3,6 +3,7 @@ import { VexFlowTests } from './vexflow_test_helpers.js';
|
|
|
3
3
|
import { Accidental } from '../src/accidental.js';
|
|
4
4
|
import { Annotation, AnnotationVerticalJustify } from '../src/annotation.js';
|
|
5
5
|
import { Articulation } from '../src/articulation.js';
|
|
6
|
+
import { BarNote } from '../src/barnote.js';
|
|
6
7
|
import { Beam } from '../src/beam.js';
|
|
7
8
|
import { Bend } from '../src/bend.js';
|
|
8
9
|
import { Dot } from '../src/dot.js';
|
|
@@ -10,6 +11,7 @@ import { Element } from '../src/element.js';
|
|
|
10
11
|
import { FontWeight } from '../src/font.js';
|
|
11
12
|
import { Formatter } from '../src/formatter.js';
|
|
12
13
|
import { FretHandFinger } from '../src/frethandfinger.js';
|
|
14
|
+
import { GhostNote } from '../src/ghostnote.js';
|
|
13
15
|
import { Glyphs } from '../src/glyphs.js';
|
|
14
16
|
import { Metrics } from '../src/metrics.js';
|
|
15
17
|
import { ModifierPosition } from '../src/modifier.js';
|
|
@@ -20,6 +22,7 @@ import { StaveConnector } from '../src/staveconnector.js';
|
|
|
20
22
|
import { StaveNote } from '../src/stavenote.js';
|
|
21
23
|
import { Stem } from '../src/stem.js';
|
|
22
24
|
import { StringNumber } from '../src/stringnumber.js';
|
|
25
|
+
import { TextNote } from '../src/textnote.js';
|
|
23
26
|
import { Tuplet } from '../src/tuplet.js';
|
|
24
27
|
import { Voice } from '../src/voice.js';
|
|
25
28
|
import { MockTickable } from './mocks.js';
|
|
@@ -68,6 +71,8 @@ const FormatterTests = {
|
|
|
68
71
|
run('Tight', tightNotes1);
|
|
69
72
|
run('Tight 2', tightNotes2);
|
|
70
73
|
run('Annotations', annotations);
|
|
74
|
+
VexFlowTests.test('Ignored bar notes preserve lyric tick alignment', ignoredBarNotesPreserveLyricTickAlignment);
|
|
75
|
+
VexFlowTests.test('Dependent voices do not affect music layout', dependentVoicesDoNotAffectMusicLayout);
|
|
71
76
|
run('Proportional Formatting - No Tuning', proportional, { debug: true, iterations: 0 });
|
|
72
77
|
run('Proportional Formatting - No Justification', proportional, { justify: false, debug: true, iterations: 0 });
|
|
73
78
|
run('Proportional Formatting (20 iterations)', proportional, { debug: true, iterations: 20, alpha: 0.5 });
|
|
@@ -78,6 +83,38 @@ function getGlyphWidth(glyph) {
|
|
|
78
83
|
el.setText(glyph);
|
|
79
84
|
return el.getWidth();
|
|
80
85
|
}
|
|
86
|
+
function ignoredBarNotesPreserveLyricTickAlignment(assert) {
|
|
87
|
+
const musicNotes = Array.from({ length: 12 }, () => new StaveNote({ keys: ['c/4'], duration: '8' }));
|
|
88
|
+
const when = new TextNote({ text: 'When', duration: '8' });
|
|
89
|
+
const lyricNotes = [
|
|
90
|
+
...Array.from({ length: 6 }, () => new GhostNote({ duration: '8' })),
|
|
91
|
+
new BarNote(),
|
|
92
|
+
when,
|
|
93
|
+
...Array.from({ length: 5 }, () => new TextNote({ text: '', duration: '8' })),
|
|
94
|
+
];
|
|
95
|
+
const musicVoice = new Voice({ numBeats: 6, beatValue: 4 }).addTickables(musicNotes);
|
|
96
|
+
const lyricVoice = new Voice({ numBeats: 6, beatValue: 4 }).addTickables(lyricNotes);
|
|
97
|
+
new Formatter().joinVoices([musicVoice, lyricVoice]).format([musicVoice, lyricVoice], 500);
|
|
98
|
+
assert.strictEqual(when.getTickContext(), musicNotes[6].getTickContext());
|
|
99
|
+
}
|
|
100
|
+
function dependentVoicesDoNotAffectMusicLayout(assert) {
|
|
101
|
+
const makeMusicNotes = () => Array.from({ length: 4 }, () => new StaveNote({ keys: ['c/4'], duration: '4' }));
|
|
102
|
+
const baselineNotes = makeMusicNotes();
|
|
103
|
+
const baselineVoice = new Voice('4/4').addTickables(baselineNotes);
|
|
104
|
+
new Formatter().joinVoices([baselineVoice]).format([baselineVoice], 500);
|
|
105
|
+
const musicNotes = makeMusicNotes();
|
|
106
|
+
const musicVoice = new Voice('4/4').addTickables(musicNotes);
|
|
107
|
+
const lyric = new TextNote({ text: 'A much wider lyric', duration: '4' });
|
|
108
|
+
const lyricVoice = new Voice('4/4').setDependent(true).addTickables([
|
|
109
|
+
new GhostNote({ duration: '4' }),
|
|
110
|
+
lyric,
|
|
111
|
+
new GhostNote({ duration: '2' }),
|
|
112
|
+
]);
|
|
113
|
+
new Formatter().joinVoices([musicVoice, lyricVoice]).format([musicVoice, lyricVoice], 500);
|
|
114
|
+
assert.strictEqual(lyric.getTickContext(), musicNotes[1].getTickContext());
|
|
115
|
+
assert.strictEqual(lyric.getX(), musicNotes[1].getX());
|
|
116
|
+
musicNotes.forEach((note, index) => assert.strictEqual(note.getX(), baselineNotes[index].getX()));
|
|
117
|
+
}
|
|
81
118
|
function getResolutionMultiplier(assert) {
|
|
82
119
|
const [voice1, voice2] = getTestVoices();
|
|
83
120
|
assert.equal(voice1.getResolutionMultiplier(), voice2.getResolutionMultiplier(), 'Voices with same smallest duration have the same resolution multiplier');
|
|
@@ -17,6 +17,7 @@ export interface TickContextOptions {
|
|
|
17
17
|
export declare class TickContext {
|
|
18
18
|
protected readonly tickID: number;
|
|
19
19
|
protected readonly tickables: Tickable[];
|
|
20
|
+
protected readonly dependentTickables: Set<Tickable>;
|
|
20
21
|
protected readonly tickablesByVoice: Record<string, Tickable>;
|
|
21
22
|
protected currentTick: Fraction;
|
|
22
23
|
protected maxTicks: Fraction;
|
|
@@ -76,7 +77,7 @@ export declare class TickContext {
|
|
|
76
77
|
getMetrics(): TickContextMetrics;
|
|
77
78
|
getCurrentTick(): Fraction;
|
|
78
79
|
setCurrentTick(tick: Fraction): void;
|
|
79
|
-
addTickable(tickable: Tickable, voiceIndex?: number): this;
|
|
80
|
+
addTickable(tickable: Tickable, voiceIndex?: number, dependent?: boolean): this;
|
|
80
81
|
preFormat(): this;
|
|
81
82
|
postFormat(): this;
|
|
82
83
|
getFormatterMetrics(): {
|
|
@@ -36,6 +36,7 @@ export declare class Voice extends Element {
|
|
|
36
36
|
protected options: {
|
|
37
37
|
softmaxFactor: number;
|
|
38
38
|
};
|
|
39
|
+
protected dependent: boolean;
|
|
39
40
|
protected readonly totalTicks: Fraction;
|
|
40
41
|
protected readonly ticksUsed: Fraction;
|
|
41
42
|
protected readonly largestTickWidth: number;
|
|
@@ -59,6 +60,10 @@ export declare class Voice extends Element {
|
|
|
59
60
|
* @param mode value from `VoiceMode` or Voice.Mode
|
|
60
61
|
*/
|
|
61
62
|
setMode(mode: number): this;
|
|
63
|
+
/** Mark this voice as dependent on the layout established by other voices. */
|
|
64
|
+
setDependent(dependent: boolean): this;
|
|
65
|
+
/** Return whether this voice follows another voice's layout. */
|
|
66
|
+
isDependent(): boolean;
|
|
62
67
|
/** Get the resolution multiplier for the voice. */
|
|
63
68
|
getResolutionMultiplier(): number;
|
|
64
69
|
/** Get the actual tick resolution for the voice. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcqj/vexflow",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.5",
|
|
4
4
|
"description": "A JavaScript library for rendering music notation and guitar tablature.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "mcqj",
|
|
@@ -114,6 +114,7 @@
|
|
|
114
114
|
"allowScripts": {
|
|
115
115
|
"canvas@3.2.3": true,
|
|
116
116
|
"core-js@3.50.0": true,
|
|
117
|
-
"fsevents@2.3.3": true
|
|
117
|
+
"fsevents@2.3.3": true,
|
|
118
|
+
"unrs-resolver@1.12.2": true
|
|
118
119
|
}
|
|
119
120
|
}
|