vexflow 5.1.1 → 5.2.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 +8 -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 +2916 -484
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +2761 -451
- 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/accidental.js +3 -0
- package/build/esm/src/articulation.js +27 -14
- package/build/esm/src/beam.js +12 -2
- package/build/esm/src/chordkerning.js +98 -0
- package/build/esm/src/chordsymbol.js +108 -27
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/clefnote.js +5 -1
- package/build/esm/src/dot.js +1 -1
- package/build/esm/src/easyscore/composition.js +297 -0
- package/build/esm/src/easyscore/elementindex.js +81 -0
- package/build/esm/src/easyscore/elements.js +324 -0
- package/build/esm/src/easyscore/policies.js +69 -0
- package/build/esm/src/easyscore/rhythm.js +42 -0
- package/build/esm/src/easyscore.js +448 -26
- package/build/esm/src/element.js +13 -2
- package/build/esm/src/factory.js +256 -60
- package/build/esm/src/formatter.js +32 -4
- package/build/esm/src/keysignature.js +9 -1
- package/build/esm/src/keysignote.js +2 -2
- package/build/esm/src/note.js +5 -0
- package/build/esm/src/parenthesis.js +1 -1
- package/build/esm/src/parser.js +6 -1
- package/build/esm/src/proportionalformatter.js +186 -0
- package/build/esm/src/registry.js +27 -0
- package/build/esm/src/sheet.js +20 -3
- package/build/esm/src/stave.js +9 -2
- package/build/esm/src/stavenote.js +12 -12
- package/build/esm/src/stemmablenote.js +6 -1
- package/build/esm/src/tickable.js +5 -0
- package/build/esm/src/tuplet.js +3 -2
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +2 -1
- package/build/esm/tests/beam_tests.js +35 -0
- package/build/esm/tests/easyscore_tests.js +40 -0
- package/build/esm/tests/easyscore_types.js +65 -0
- package/build/esm/tests/formatter_tests.js +41 -0
- package/build/esm/tests/node/chord-kerning-tests.mjs +173 -0
- package/build/esm/tests/node/easyscore-rendering-tests.mjs +332 -0
- package/build/esm/tests/node/easyscore-tests.mjs +953 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +214 -0
- package/build/esm/tests/node/tool-security-tests.mjs +85 -0
- package/build/esm/tools/easyscore-api-audit.mjs +58 -0
- package/build/esm/tools/easyscore-composition.mjs +62 -0
- package/build/esm/tools/easyscore-example.mjs +16 -0
- package/build/esm/tools/easyscore-families.mjs +61 -0
- package/build/esm/tools/easyscore-references-example.mjs +26 -0
- package/build/esm/tools/easyscore-rhythm.mjs +58 -0
- package/build/esm/tools/easyscore-structure.mjs +88 -0
- package/build/esm/tools/explorer/catalog/entries.mjs +6 -0
- package/build/esm/tools/explorer/catalog/expression.mjs +68 -0
- package/build/esm/tools/explorer/catalog/helpers.mjs +29 -0
- package/build/esm/tools/explorer/catalog/layout.mjs +109 -0
- package/build/esm/tools/explorer/catalog/notes.mjs +61 -0
- package/build/esm/tools/explorer/catalog/staves.mjs +85 -0
- package/build/esm/tools/explorer/catalog/strings.mjs +25 -0
- package/build/esm/tools/explorer/catalog.mjs +14 -0
- package/build/types/src/accidental.d.ts +2 -0
- package/build/types/src/articulation.d.ts +6 -0
- package/build/types/src/beam.d.ts +2 -0
- package/build/types/src/chordkerning.d.ts +42 -0
- package/build/types/src/chordsymbol.d.ts +19 -0
- package/build/types/src/clef.d.ts +2 -0
- package/build/types/src/easyscore/composition.d.ts +107 -0
- package/build/types/src/easyscore/elementindex.d.ts +30 -0
- package/build/types/src/easyscore/elements.d.ts +156 -0
- package/build/types/src/easyscore/policies.d.ts +12 -0
- package/build/types/src/easyscore/rhythm.d.ts +9 -0
- package/build/types/src/easyscore.d.ts +153 -11
- package/build/types/src/element.d.ts +5 -1
- package/build/types/src/factory.d.ts +91 -8
- package/build/types/src/formatter.d.ts +7 -1
- package/build/types/src/keysignature.d.ts +3 -0
- package/build/types/src/keysignote.d.ts +1 -1
- package/build/types/src/note.d.ts +2 -0
- package/build/types/src/parser.d.ts +5 -0
- package/build/types/src/proportionalformatter.d.ts +30 -0
- package/build/types/src/registry.d.ts +4 -0
- package/build/types/src/stave.d.ts +2 -0
- package/build/types/src/stavenote.d.ts +1 -1
- package/build/types/src/stemmablenote.d.ts +6 -1
- package/build/types/src/tickable.d.ts +2 -0
- package/build/types/src/vexflow.d.ts +2 -1
- package/changelog/CHANGELOG.md +57 -0
- package/package.json +19 -7
- package/tests/flow.html +10 -3
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export function renderEasyScoreStructure(VF, renderer, kind = 'tab', ink = '#24312c') {
|
|
2
|
+
const score = VF.EasyScore.create({ renderer });
|
|
3
|
+
score.setStyle({ fillStyle: ink, strokeStyle: ink });
|
|
4
|
+
const marks = [];
|
|
5
|
+
let notes = [];
|
|
6
|
+
const system = score.system({ x: 20, y: 75, width: renderer.width - 40 });
|
|
7
|
+
const tab = ['tab', 'grace-tab'].includes(kind);
|
|
8
|
+
const bounds = { x: 20, width: renderer.width - 40 };
|
|
9
|
+
const stave = tab ? score.make.tabStave(bounds) : score.make.stave(bounds);
|
|
10
|
+
const attach = (mark, position) => {
|
|
11
|
+
score.attachToStave(stave, mark, position);
|
|
12
|
+
marks.push(mark);
|
|
13
|
+
};
|
|
14
|
+
if (tab) {
|
|
15
|
+
notes = [3, 5, 7, 7].map((fret) => score.make.tabNote({ positions: [{ str: 2, fret }], duration: 'q' }));
|
|
16
|
+
attach(score.make.clef('tab'));
|
|
17
|
+
if (kind === 'tab') {
|
|
18
|
+
const bend = score.make.bend([
|
|
19
|
+
{ type: VF.Bend.UP, text: 'Full' },
|
|
20
|
+
{ type: VF.Bend.DOWN, text: '' },
|
|
21
|
+
]);
|
|
22
|
+
score.attach(notes[0], bend);
|
|
23
|
+
marks.push(bend);
|
|
24
|
+
marks.push(score.make.tabSlide({ firstNote: notes[1], lastNote: notes[2] }));
|
|
25
|
+
marks.push(score.make.tabTie({ firstNote: notes[2], lastNote: notes[3] }, 'H'));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const grace = score.make.graceTabNote({ positions: [{ str: 2, fret: 2 }], duration: '16' });
|
|
29
|
+
const group = score.make.graceNoteGroup({ notes: [grace], slur: true });
|
|
30
|
+
score.attach(notes[0], group);
|
|
31
|
+
marks.push(group);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (kind === 'rest') {
|
|
35
|
+
attach(score.make.clef('treble'));
|
|
36
|
+
marks.push(score.make.multiMeasureRest({ numberOfMeasures: 8, useSymbols: true }).setStave(stave));
|
|
37
|
+
}
|
|
38
|
+
else if (kind === 'inline') {
|
|
39
|
+
notes = score.sequence([
|
|
40
|
+
'C5/q',
|
|
41
|
+
score.make.barNote(),
|
|
42
|
+
score.make.clefNote({ type: 'bass', options: { size: 'small' } }),
|
|
43
|
+
score.make.keySigNote({ key: 'G' }),
|
|
44
|
+
score.make.timeSigNote({ time: '3/4' }),
|
|
45
|
+
...score.notes('G3/q, A3, B3', { clef: 'bass' }),
|
|
46
|
+
]);
|
|
47
|
+
attach(score.make.clef('treble'));
|
|
48
|
+
}
|
|
49
|
+
else if (kind === 'repeat') {
|
|
50
|
+
notes = [
|
|
51
|
+
score.make.repeatNote('slash'),
|
|
52
|
+
score.make.repeatNote('slash'),
|
|
53
|
+
score.make.glyphNote('\uE047', { duration: 'h' }, { line: 2 }),
|
|
54
|
+
];
|
|
55
|
+
attach(score.make.clef('percussion'));
|
|
56
|
+
const annotation = score.make.annotation({ text: 'sim.', vJustify: 'top' });
|
|
57
|
+
score.attach(notes[2], annotation);
|
|
58
|
+
marks.push(annotation);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
notes = score.notes('C5/q, D5, E5, F5');
|
|
62
|
+
attach(score.make.clef('treble'));
|
|
63
|
+
attach(score.make.keySignature('G'));
|
|
64
|
+
attach(score.make.timeSignature('4/4'));
|
|
65
|
+
attach(score.make.barline(VF.Barline.type.REPEAT_END), VF.StaveModifier.Position.END);
|
|
66
|
+
if (kind === 'labels') {
|
|
67
|
+
attach(score.make.section('A', 0, -15));
|
|
68
|
+
attach(score.make.tempo({ duration: 'q', bpm: 96 }, 100, -15));
|
|
69
|
+
attach(score.make.staveText('dolce', VF.StaveModifier.Position.BELOW));
|
|
70
|
+
}
|
|
71
|
+
else if (kind !== 'connector') {
|
|
72
|
+
attach(score.make.volta(VF.Volta.type.BEGIN_END, '1.', 0, 0));
|
|
73
|
+
attach(score.make.repetition(VF.Repetition.type.DC, 0, 0));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
system.addStave({ stave, voices: notes.length ? [score.voice(notes)] : [] });
|
|
77
|
+
if (kind === 'connector') {
|
|
78
|
+
const lowerNotes = score.notes('C3/w', { clef: 'bass' });
|
|
79
|
+
const lower = score.make.stave(bounds);
|
|
80
|
+
score.attachToStave(lower, score.make.clef('bass'));
|
|
81
|
+
system.addStave({ stave: lower, voices: [score.voice(lowerNotes)] });
|
|
82
|
+
marks.push(score.make.connector({ topStave: stave, bottomStave: lower, type: 'brace' }));
|
|
83
|
+
notes.push(...lowerNotes);
|
|
84
|
+
score.factory.getContext().resize(renderer.width, 350);
|
|
85
|
+
}
|
|
86
|
+
score.draw({ retain: true });
|
|
87
|
+
return { score, notes, marks, system };
|
|
88
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { expression } from './expression.mjs';
|
|
2
|
+
import { layout } from './layout.mjs';
|
|
3
|
+
import { notes } from './notes.mjs';
|
|
4
|
+
import { staves } from './staves.mjs';
|
|
5
|
+
import { strings } from './strings.mjs';
|
|
6
|
+
export const entries = [...notes, ...staves, ...expression, ...strings, ...layout];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { example as e, number, select, setup, staff, text } from './helpers.mjs';
|
|
2
|
+
const group = 'Marks & expression';
|
|
3
|
+
export const expression = [
|
|
4
|
+
e('annotations', 'Lyrics & annotations', group, 'Align lyrics below notes or annotations above them.', 'Annotation', staff("score.notes('C5/q, E5, G5, C6')", `params.words.split(' ').slice(0, notes.length).forEach((word, i) => {
|
|
5
|
+
notes[i].addModifier(factory.Annotation({ text: word, vJustify: params.position }), 0);
|
|
6
|
+
});`), [text('words', 'Words', 'One two three four'), select('position', 'Position', 'bottom', ['bottom', 'top'])]),
|
|
7
|
+
e('chord-symbols', 'Chord symbols', group, 'Build harmonic labels from text, accidentals, and superscripts.', 'ChordSymbol', staff("score.notes('C5/h, G4')", `notes[0].addModifier(factory.ChordSymbol().addText(params.root).addGlyphOrText('maj7'), 0);
|
|
8
|
+
notes[1].addModifier(factory.ChordSymbol().addText('G').addGlyphOrText('7').addGlyphOrText('b9', { symbolModifier: VF.ChordSymbol.symbolModifiers.SUPERSCRIPT }), 0);`), [text('root', 'Root', 'C')]),
|
|
9
|
+
e('chord-kerning', 'Chord kerning', group, 'Compare default spacing with opt-in font-specific kerning and stacked scripts.', 'ChordSymbol', `${setup}
|
|
10
|
+
// The two rows use identical notes and chord content. Only the kerning mode changes.
|
|
11
|
+
const ctx = factory.getContext();
|
|
12
|
+
ctx.resize(width, 360);
|
|
13
|
+
const chords = [];
|
|
14
|
+
const sup = { symbolModifier: VF.ChordSymbol.symbolModifiers.SUPERSCRIPT };
|
|
15
|
+
const sub = { symbolModifier: VF.ChordSymbol.symbolModifiers.SUBSCRIPT };
|
|
16
|
+
['none', 'auto'].forEach((mode, row) => {
|
|
17
|
+
const notes = score.notes('C5/q, D5, E5, G5');
|
|
18
|
+
const make = () => factory.ChordSymbol({ fontSize: params.size, hJustify: 'left' }).setKerning(mode);
|
|
19
|
+
const symbols = [
|
|
20
|
+
make().addText(params.root).addGlyph('diminished', sup),
|
|
21
|
+
make().addGlyphOrText('C#7'),
|
|
22
|
+
make().addText('F7').addGlyphOrText('b9', sup).addGlyphOrText('#11', sub),
|
|
23
|
+
make().addText(params.root).addGlyph('majorSeventh', sup),
|
|
24
|
+
];
|
|
25
|
+
notes.forEach((note, i) => note.addModifier(symbols[i], 0));
|
|
26
|
+
chords.push(...symbols);
|
|
27
|
+
const voice = factory.Voice().addTickables(notes);
|
|
28
|
+
factory.System({ x: 30, y: 70 + row * 150, width: width - 60 })
|
|
29
|
+
.addStave({ voices: [voice] }).addClef('treble');
|
|
30
|
+
});
|
|
31
|
+
factory.draw();
|
|
32
|
+
ctx.setFont('sans-serif', 10);
|
|
33
|
+
ctx.fillText('Default: none', 30, 22);
|
|
34
|
+
ctx.fillText('Opt-in: auto', 30, 172);
|
|
35
|
+
// Inspect the complete chord's ink bounds, including both script rows.
|
|
36
|
+
if (params.bounds === 'yes') {
|
|
37
|
+
ctx.save().setStrokeStyle('#b74632').setLineWidth(0.5);
|
|
38
|
+
chords.forEach(chord => {
|
|
39
|
+
const box = chord.getBoundingBox();
|
|
40
|
+
ctx.beginPath().rect(box.x, box.y, box.w, box.h).stroke();
|
|
41
|
+
});
|
|
42
|
+
ctx.restore();
|
|
43
|
+
}`, [
|
|
44
|
+
text('root', 'Root', 'A'),
|
|
45
|
+
number('size', 'Font size (pt)', 18, 10, 28),
|
|
46
|
+
select('bounds', 'Chord bounds', 'no', ['no', 'yes']),
|
|
47
|
+
], 'Auto supports regular Academico/Bravura and Petaluma Script/Petaluma. Other font combinations keep the default layout. Set the chord font before formatting.'),
|
|
48
|
+
e('dynamics', 'Dynamics', group, 'From pianissimo to fortissimo, draw music-font dynamic marks.', 'TextDynamics', `${setup}
|
|
49
|
+
const dynamics = ['pp', 'p', 'mp', 'mf', 'f', 'ff'].map(text => factory.TextDynamics({ text, duration: 'q' }));
|
|
50
|
+
const voice = factory.Voice().setMode(VF.Voice.Mode.SOFT).addTickables(dynamics);
|
|
51
|
+
factory.System({ x: 30, y: 55, width: width - 60 }).addStave({ voices: [voice] });
|
|
52
|
+
factory.draw();`),
|
|
53
|
+
e('text-notes', 'Text notes', group, 'Place rhythmically aligned text alongside music.', 'TextNote', `${setup}
|
|
54
|
+
const notes = ['dolce', 'poco', 'a', 'poco'].map(text => factory.TextNote({ text, duration: 'q', line: params.line }));
|
|
55
|
+
const voice = factory.Voice().addTickables(notes);
|
|
56
|
+
factory.System({ x: 30, y: 65, width: width - 60 }).addStave({ voices: [voice] });
|
|
57
|
+
factory.draw();`, [number('line', 'Text line', 2, -2, 6)]),
|
|
58
|
+
e('ties', 'Ties', group, 'Connect the same pitch across successive notes. Chord ties can select individual keys.', 'StaveTie', staff("score.notes('(C5 E5)/h, (C5 E5)')", 'factory.StaveTie({ from: notes[0], to: notes[1], firstIndexes: [0, 1], lastIndexes: [0, 1] });')),
|
|
59
|
+
e('slurs', 'Slurs & curves', group, 'Connect notes with a slur and adjust its thickness.', 'Curve', staff("score.notes('C5/q, D5, E5, G5')", 'factory.Curve({ from: notes[0], to: notes[3], options: { thickness: params.thickness } });'), [number('thickness', 'Thickness', 2, 1, 6, 0.5)]),
|
|
60
|
+
e('hairpins', 'Hairpins', group, 'Draw crescendo and decrescendo hairpins below the staff.', 'StaveHairpin', staff("score.notes('C5/q, D5, E5, G5')", '', `new VF.StaveHairpin({ firstNote: notes[0], lastNote: notes[3] }, params.direction === 'crescendo' ? 1 : 2)
|
|
61
|
+
.setPosition(VF.Modifier.Position.BELOW)
|
|
62
|
+
.setStyle({ fillStyle: ink, strokeStyle: ink })
|
|
63
|
+
.setContext(factory.getContext()).drawWithStyle();`), [select('direction', 'Direction', 'crescendo', ['crescendo', 'decrescendo'])]),
|
|
64
|
+
e('pedal', 'Pedal markings', group, 'Choose between text, brackets, and a mixture of the two.', 'PedalMarking', staff("score.notes('C5/q, E5, G5, C6')", 'factory.PedalMarking({ notes: [notes[0], notes[3]], options: { style: params.style } });'), [select('style', 'Style', 'mixed', ['mixed', 'bracket', 'text'])]),
|
|
65
|
+
e('octaves', 'Octave brackets', group, 'An octave instruction spans a passage without changing its written pitches.', 'TextBracket', staff("score.notes('C5/q, E5, G5, C6')", "factory.TextBracket({ from: notes[0], to: notes[3], text: params.text, options: { superscript: 'va', position: 'top', line: 2 } });"), [select('text', 'Interval', '8', ['8', '15'])]),
|
|
66
|
+
e('glissando', 'Glissando lines', group, 'Draw a line between selected pitches and add a label.', 'StaveLine', staff("score.notes('C4/h, C6')", "factory.StaveLine({ from: notes[0], to: notes[1], firstIndexes: [0], lastIndexes: [0], options: { text: 'gliss.' } });")),
|
|
67
|
+
e('vibrato-bracket', 'Vibrato brackets', group, 'Draw a vibrato bracket spanning several notes.', 'VibratoBracket', staff("score.notes('C5/q, D5, E5, G5')", 'factory.VibratoBracket({ from: notes[0], to: notes[3], options: { line: 2 } });')),
|
|
68
|
+
];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const select = (key, label, value, choices) => ({ key, label, value, choices });
|
|
2
|
+
export const number = (key, label, value, min, max, step = 1) => ({ key, label, value, min, max, step });
|
|
3
|
+
export const text = (key, label, value) => ({ key, label, value });
|
|
4
|
+
export const setup = `// Render into the score container. Dimensions and ink come from the controls.
|
|
5
|
+
const factory = new VF.Factory({
|
|
6
|
+
renderer: { elementId: 'score', width, height }
|
|
7
|
+
});
|
|
8
|
+
factory.setStyle({ fillStyle: ink, strokeStyle: ink });
|
|
9
|
+
|
|
10
|
+
// EasyScore parses pitch/duration strings such as C5/q or (C4 E4 G4)/h.
|
|
11
|
+
const score = factory.EasyScore({ throwOnError: true });`;
|
|
12
|
+
export function staff(notes, modifications = '', after = '', stave = ".addClef('treble')") {
|
|
13
|
+
return `${setup}
|
|
14
|
+
|
|
15
|
+
const notes = ${notes};
|
|
16
|
+
${modifications}
|
|
17
|
+
|
|
18
|
+
// SOFT mode allows incomplete measures while experimenting with durations.
|
|
19
|
+
const voice = factory.Voice().setMode(VF.Voice.Mode.SOFT).addTickables(notes);
|
|
20
|
+
const system = factory.System({ x: 30, y: 65, width: width - 60 });
|
|
21
|
+
system.addStave({ voices: [voice] })${stave};
|
|
22
|
+
|
|
23
|
+
// Format and draw the objects registered with the factory.
|
|
24
|
+
factory.draw();
|
|
25
|
+
${after ? '\n// Draw this additional mark after note positions have been calculated.\n' + after : ''}`.trim();
|
|
26
|
+
}
|
|
27
|
+
export function example(id, title, group, description, api, code, controls = [], tips = '') {
|
|
28
|
+
return { id, title, group, description, api: api.split(' '), code, controls, tips };
|
|
29
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { renderEasyScoreComposition } from '../../easyscore-composition.mjs';
|
|
2
|
+
import { createEasyScoreExample } from '../../easyscore-example.mjs';
|
|
3
|
+
import { renderEasyScoreFamilies } from '../../easyscore-families.mjs';
|
|
4
|
+
import { createEasyScoreReferencesExample } from '../../easyscore-references-example.mjs';
|
|
5
|
+
import { renderEasyScoreStructure } from '../../easyscore-structure.mjs';
|
|
6
|
+
import { renderEasyScoreRhythm } from '../../easyscore-rhythm.mjs';
|
|
7
|
+
import { example as e, number, select, setup, staff, text } from './helpers.mjs';
|
|
8
|
+
const group = 'Layout & composition';
|
|
9
|
+
export const layout = [
|
|
10
|
+
e('easyscore-first-score', 'EasyScore: first score', group, 'Create notes, an annotation, a tie, a voice, and a system through EasyScore.', 'EasyScore Annotation StaveTie Voice System', `// The function body is shared with the tested user-guide example.
|
|
11
|
+
(${createEasyScoreExample.toString()})(VF, { elementId: 'score', width, height }, ink);`, [], 'EasyScore.create() validates before construction. Helpers return native VexFlow objects. Typed helpers cover all notation families; native setters remain available.'),
|
|
12
|
+
e('easyscore-references', 'EasyScore: references & extensions', group, 'Resolve named notes, adopt native extensions, and click parsed notes to select their source.', 'EasyScore getElement getNote getSource adopt Annotation StaveTie Curve', `// Click either C4 note to select its notation in this editor.
|
|
13
|
+
(${createEasyScoreReferencesExample.toString()})(VF, { elementId: 'score', width, height }, ink);`, [], 'IDs are local to each score. Adopted notes and drawables share the normal retained lifecycle. Native objects have no notation source. Inspector selection requires one unescaped matching literal; computed or ambiguous input is shown without guessing an editor location.'),
|
|
14
|
+
e('easyscore-families', 'EasyScore: notes & modifiers', group, 'Typed notes, percussion heads, native modifiers, and grace groups through one score.', 'EasyScore StaveNote Accidental Articulation Ornament Tremolo Vibrato Parenthesis Dot ChordSymbol GraceNoteGroup NoteSubGroup Stroke TextNote', `(${renderEasyScoreFamilies.toString()})(VF, { elementId: 'score', width, height }, params.family, ink);`, [select('family', 'Family', 'modifiers', ['modifiers', 'accidentals', 'text', 'grace', 'percussion', 'sequence'])], 'Typed notes preserve native fields and head codes. Grace/subnote groups own their children. Set note duration dots explicitly; a Dot modifier alone changes only the appearance.'),
|
|
15
|
+
e('easyscore-rhythm', 'EasyScore: rhythm & relationships', group, 'Odd-meter voices, nested tuplets, owned spans, partial endpoints, and timed dynamics.', 'EasyScore Beam Tuplet StaveTie Curve StaveHairpin StaveLine TextBracket VibratoBracket PedalMarking TextDynamics Crescendo', `(${renderEasyScoreRhythm.toString()})(VF, { elementId: 'score', width, height }, params.family, ink);`, [
|
|
16
|
+
select('family', 'Family', 'odd-meter', [
|
|
17
|
+
'odd-meter',
|
|
18
|
+
'tuplets',
|
|
19
|
+
'ties',
|
|
20
|
+
'curves',
|
|
21
|
+
'hairpins',
|
|
22
|
+
'lines',
|
|
23
|
+
'brackets',
|
|
24
|
+
'pedal',
|
|
25
|
+
'partial-spans',
|
|
26
|
+
'dynamics',
|
|
27
|
+
]),
|
|
28
|
+
], 'Beam groups use exact Fractions and preserve explicit stems by default. Create tuplets before voices. Spans draw through the score; row-break segments remain explicit.'),
|
|
29
|
+
e('easyscore-structure', 'EasyScore: tablature & staff structure', group, 'Tablature, bends, grace groups, inline changes, rests, repeats, and staff markings.', 'EasyScore TabNote GraceTabNote TabSlide TabTie Bend Stave Clef KeySignature TimeSignature MultiMeasureRest RepeatNote GlyphNote', `(${renderEasyScoreStructure.toString()})(VF, { elementId: 'score', width, height }, params.family, ink);`, [
|
|
30
|
+
select('family', 'Family', 'tab', [
|
|
31
|
+
'tab',
|
|
32
|
+
'grace-tab',
|
|
33
|
+
'rest',
|
|
34
|
+
'inline',
|
|
35
|
+
'repeat',
|
|
36
|
+
'labels',
|
|
37
|
+
'endings',
|
|
38
|
+
'connector',
|
|
39
|
+
]),
|
|
40
|
+
], 'Staff modifiers draw through their stave. Inline clefs and signatures change appearance; update note options explicitly. Tab tuning stays a separate native utility.'),
|
|
41
|
+
e('easyscore-composition', 'EasyScore: responsive composition', group, 'A grand staff with pickup, opposing voices, triplets, changing meter, key-aware accidentals, and inline state.', 'EasyScore compose Sheet System Voice Fraction Accidental', `(${renderEasyScoreComposition.toString()})(VF, { elementId: 'score', width: params.sheetWidth, height }, params.spacing, ink);`, [
|
|
42
|
+
number('sheetWidth', 'Width', 640, 320, 1000, 20),
|
|
43
|
+
select('spacing', 'Spacing', 'engraving', ['engraving', 'proportional']),
|
|
44
|
+
], 'Each measure is a native System. Tuplets precede voices; all voices share the actual span. Signatures repeat at every measure here, so any measure can begin a row. Use Sheet.getRows() to inspect overflow.'),
|
|
45
|
+
e('proportional-spacing', 'Proportional spacing', group, 'Compare engraving spacing with an exact musical-time grid. Equal durations occupy equal widths.', 'Formatter Voice TickContext System Tuplet', `${setup}
|
|
46
|
+
const ctx = factory.getContext();
|
|
47
|
+
// Auto width preserves the chosen scale. Resize the surface to fit both rows.
|
|
48
|
+
const systems = [];
|
|
49
|
+
const rows = [];
|
|
50
|
+
['engraving', 'proportional'].forEach((mode, row) => {
|
|
51
|
+
const notes = score.notes('C5/16, D5, E5, F5, G5/8, A5, B5/q, C6', { stem: 'up' });
|
|
52
|
+
score.beam(notes.slice(0, 4));
|
|
53
|
+
score.beam(notes.slice(4, 6));
|
|
54
|
+
const voices = [score.voice(notes)];
|
|
55
|
+
if (params.voices === 'two') {
|
|
56
|
+
voices.push(score.voice(score.notes('C4/q, E4, G4, E4', { stem: 'down' })));
|
|
57
|
+
}
|
|
58
|
+
const spacing = mode === 'proportional'
|
|
59
|
+
? { mode: 'proportional', pixelsPerQuarter: params.scale }
|
|
60
|
+
: undefined;
|
|
61
|
+
const system = factory.System({
|
|
62
|
+
x: 30, y: 45 + row * 155,
|
|
63
|
+
...(mode === 'engraving' ? { width: params.scale * 4 + 100 } : {}),
|
|
64
|
+
details: { spacing },
|
|
65
|
+
});
|
|
66
|
+
system.addStave({ voices }).addClef('treble').addTimeSignature('4/4');
|
|
67
|
+
system.format();
|
|
68
|
+
systems.push(system);
|
|
69
|
+
rows.push(notes);
|
|
70
|
+
});
|
|
71
|
+
ctx.resize(Math.max(width, ...systems.map(system => system.getWidth() + 60)), 360);
|
|
72
|
+
factory.draw();
|
|
73
|
+
ctx.setFont('sans-serif', 10);
|
|
74
|
+
ctx.fillText('Default engraving', 30, 20);
|
|
75
|
+
ctx.fillText('Strict proportional spacing', 30, 175);
|
|
76
|
+
// Guides mark quarter-note onsets, plus the end of the four-beat span.
|
|
77
|
+
const origin = rows[1][0].getAbsoluteX();
|
|
78
|
+
ctx.save().setStrokeStyle('#b6c4c0').setLineWidth(0.5);
|
|
79
|
+
for (let beat = 0; beat <= 4; beat++) {
|
|
80
|
+
const x = origin + beat * params.scale;
|
|
81
|
+
ctx.beginPath().moveTo(x, 210).lineTo(x, 310).stroke();
|
|
82
|
+
}
|
|
83
|
+
ctx.restore();`, [number('scale', 'Pixels per quarter', 140, 120, 180, 10), select('voices', 'Voices', 'two', ['one', 'two'])], 'Set spacing on Formatter, or System.details. Omit pixelsPerQuarter to fit a supplied width. Crowded notation reports the minimum scale and width instead of moving notes off the grid.'),
|
|
84
|
+
e('voices', 'Multiple voices', group, 'Independent voices share a staff and align at common musical times.', 'Voice Formatter ModifierContext TickContext', `${setup}
|
|
85
|
+
const upper = score.voice(score.notes('C5/h, D5', { stem: 'up' }));
|
|
86
|
+
const lower = score.voice(score.notes('G4/q, A4, B4, A4', { stem: 'down' }));
|
|
87
|
+
factory.System({ x: 30, y: 65, width: width - 60 })
|
|
88
|
+
.addStave({ voices: [upper, lower] }).addClef('treble');
|
|
89
|
+
factory.draw();`),
|
|
90
|
+
e('sheet', 'Responsive sheets', group, 'Wrap measures into rows at a configurable width.', 'Sheet System Factory', `${setup}
|
|
91
|
+
const sheet = factory.Sheet({ width: Math.min(params.rowWidth, width - 60), x: 30, y: 25, rowGap: 15 });
|
|
92
|
+
for (const notes of score.measures('C5/h, E5 | G5/q, E5, D5, C5 | E5/h, G5 | C5/w')) {
|
|
93
|
+
sheet.addSystem().addStave({ voices: [score.voice(notes)] }).addClef('treble');
|
|
94
|
+
}
|
|
95
|
+
// Format first so the renderer can use the height of the wrapped rows.
|
|
96
|
+
sheet.format();
|
|
97
|
+
factory.getContext().resize(width, sheet.getHeight() + 30);
|
|
98
|
+
factory.draw();`, [number('rowWidth', 'Row width', 620, 200, 900, 20)]),
|
|
99
|
+
e('styles', 'Color & highlighting', group, 'Set a foreground for the score and keep individual highlights.', 'Element Factory', staff("score.notes('C5/q, E5, G5, C6')", 'notes[params.index].setStyle({ fillStyle: params.color, strokeStyle: params.color });'), [number('index', 'Note index', 1, 0, 3), text('color', 'Highlight color', '#b74632')]),
|
|
100
|
+
e('ghosts', 'Ghost notes', group, 'An invisible tickable reserves rhythmic space without drawing a note.', 'GhostNote', staff("[...score.notes('C5/q'), factory.GhostNote({ duration: 'q' }), ...score.notes('E5/q, G5')]"), [], 'The empty second beat is intentional. GhostNote contributes time and spacing without a visible notehead.'),
|
|
101
|
+
e('repeat-notes', 'Measure-repeat symbols', group, 'A repeat glyph can stand in for a repeated measure.', 'RepeatNote', staff("[factory.RepeatNote(params.type, { duration: 'w' })]"), [select('type', 'Repeat', '1', ['1', '2', '4', 'slash'])]),
|
|
102
|
+
e('glyph-notes', 'Glyph notes', group, 'Use a music glyph as a rhythmically positioned note.', 'GlyphNote', staff("[factory.GlyphNote(VF.Glyphs.segno, { duration: 'h' }), factory.GlyphNote(VF.Glyphs.coda, { duration: 'h' })]")),
|
|
103
|
+
e('subgroups', 'Note subgroups', group, 'Attach a small inline group, such as a clef change, to a note.', 'NoteSubGroup ClefNote', staff("score.notes('C5/q, E5, G5, C6')", "notes[1].addModifier(factory.NoteSubGroup({ notes: [new VF.ClefNote('bass', 'small')] }), 0);")),
|
|
104
|
+
e('crescendo-note', 'Rhythmic crescendo', group, 'A crescendo can occupy musical time inside a voice.', 'Crescendo', `${setup}
|
|
105
|
+
const crescendo = new VF.Crescendo({ duration: 'w' }).setLine(params.line);
|
|
106
|
+
const voice = factory.Voice().addTickables([crescendo]);
|
|
107
|
+
factory.System({ x: 30, y: 60, width: width - 60 }).addStave({ voices: [voice] });
|
|
108
|
+
factory.draw();`, [number('line', 'Line', 2, 0, 6)]),
|
|
109
|
+
];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { example as e, number, select, setup, staff, text } from './helpers.mjs';
|
|
2
|
+
const group = 'Notes & rhythm';
|
|
3
|
+
export const notes = [
|
|
4
|
+
e('notes', 'Notes & stems', group, 'Create notes from pitch and duration strings. Adjust stem direction.', 'StaveNote Stem Flag EasyScore', staff('score.notes(params.phrase, { stem: params.stem })'), [
|
|
5
|
+
text('phrase', 'Phrase', 'C5/q, D5/8, E5, G5/q, E5'),
|
|
6
|
+
select('stem', 'Stem direction', 'auto', ['auto', 'up', 'down']),
|
|
7
|
+
], 'EasyScore uses scientific pitch names. /q, /8, and /h select quarter, eighth, and half notes. Omitted durations carry forward.'),
|
|
8
|
+
e('rests', 'Rests', group, 'Compare whole, half, quarter, eighth, and sixteenth rests.', 'StaveNote EasyScore', staff("score.notes('B4/w/r, B4/h/r, B4/q/r, B4/8/r, B4/16/r')")),
|
|
9
|
+
e('chords', 'Chords & seconds', group, 'Stack pitches and inspect how adjacent noteheads shift to avoid one another.', 'StaveNote NoteHead', staff('score.notes(params.phrase, { stem: params.stem })'), [
|
|
10
|
+
text('phrase', 'Chords', '(C4 E4 G4)/q, (D4 E4 F4), (C5 D5 E5), (G4 B4 D5)'),
|
|
11
|
+
select('stem', 'Stems', 'up', ['up', 'down']),
|
|
12
|
+
]),
|
|
13
|
+
e('noteheads', 'Notehead shapes', group, 'Compare cross, diamond, triangle, and slash noteheads.', 'StaveNote NoteHead', staff("['c/4', 'd/4', 'e/4', 'f/4'].map(key => factory.StaveNote({ keys: [key + '/' + params.shape], duration: 'q' }))"), [select('shape', 'Shape', 'D', ['D', 'X0', 'X1', 'X2', 'T0', 'S1'])]),
|
|
14
|
+
e('dots', 'Dotted notes', group, 'Render single and double augmentation dots beside noteheads.', 'Dot StaveNote', staff("score.notes('C5/q., D5/8, E5/q.., G5/16')")),
|
|
15
|
+
e('beams', 'Beams', group, 'Group eighth notes under a beam. Edit pitches to change its slope.', 'Beam StemmableNote', staff('score.notes(params.phrase)', '// Automatic stems are resolved for the complete group.\nscore.beam(notes);'), [text('phrase', 'Eighth notes', 'C5/8, D5, E5, G5, A5, G5, E5, D5')]),
|
|
16
|
+
e('beamed-tuplets', 'Beamed tuplets', group, 'Keep all seven stems on the same side of a 7:4 beam, including when pitches cross the middle line.', 'Tuplet Beam EasyScore Formatter', `${setup}
|
|
17
|
+
const phrase = params.phrase === 'ascending'
|
|
18
|
+
? 'C4/8, D4, E4, F4, G4, A4, B4'
|
|
19
|
+
: 'A5/8, G5, F5, E5, D5, C5, A4';
|
|
20
|
+
const notes = score.notes(phrase);
|
|
21
|
+
score.tuplet(notes, { numNotes: 7, notesOccupied: 4, ratioed: true });
|
|
22
|
+
// EasyScore resolves the automatic stems for the complete beam.
|
|
23
|
+
score.beam(notes);
|
|
24
|
+
const details = params.spacing === 'proportional'
|
|
25
|
+
? { spacing: { mode: 'proportional', pixelsPerQuarter: 140 } }
|
|
26
|
+
: {};
|
|
27
|
+
factory.System({ x: 30, y: 65, width: width - 60, details })
|
|
28
|
+
.addStave({ voices: [score.voice(notes, { time: '2/4' })] }).addClef('treble');
|
|
29
|
+
factory.draw();`, [
|
|
30
|
+
select('phrase', 'Phrase', 'ascending', ['ascending', 'descending']),
|
|
31
|
+
select('spacing', 'Spacing', 'proportional', ['proportional', 'engraving']),
|
|
32
|
+
], 'Automatic stems use a shared direction. Explicit stem choices are preserved. Use beam options autoStem: false for intentional mixed automatic stems.'),
|
|
33
|
+
e('tuplets', 'Tuplets', group, 'Fit a group of notes into a different rhythmic span.', 'Tuplet', staff("score.notes('C5/8, D5, E5, G5, E5, D5')", 'factory.Tuplet({ notes, options: { numNotes: 6, notesOccupied: params.occupied, ratioed: true, bracketed: true } });'), [select('occupied', 'Notes occupied', 4, [2, 4, 8])]),
|
|
34
|
+
e('grace', 'Grace notes', group, 'Small notes lead into a full-sized note, with an optional slur.', 'GraceNote GraceNoteGroup', staff("score.notes('C5/q, E5, G5, C6')", `const grace = ['d/5', 'e/5'].map(key => factory.GraceNote({ keys: [key], duration: '16', slash: params.slash === 'yes' }));
|
|
35
|
+
notes[0].addModifier(factory.GraceNoteGroup({ notes: grace, slur: true }), 0);`), [select('slash', 'Slash', 'yes', ['yes', 'no'])]),
|
|
36
|
+
e('accidentals', 'Accidentals', 'Marks & expression', 'Alter a pitch with sharps, flats, naturals, or a cautionary accidental.', 'Accidental', staff("score.notes('C5/q, D5, E5, F5')", `notes.forEach((note, index) => {
|
|
37
|
+
const accidental = factory.Accidental({ type: params.type });
|
|
38
|
+
if (index === 3) accidental.setAsCautionary();
|
|
39
|
+
note.addModifier(accidental, 0);
|
|
40
|
+
});`), [select('type', 'Accidental', '#', ['#', 'b', 'n', '##', 'bb'])]),
|
|
41
|
+
e('microtones', 'Microtonal accidentals', 'Marks & expression', 'Explore quarter-tone and other microtonal pitch marks.', 'Accidental', staff("score.notes('C5/q, D5, E5, F5')", "['+', '++', 'db', 'bbs'].forEach((type, i) => notes[i].addModifier(factory.Accidental({ type }), 0));")),
|
|
42
|
+
e('articulations', 'Articulations', 'Marks & expression', 'Small marks describe the attack and length of a note.', 'Articulation', staff("score.notes('C5/q, D5, E5, G5')", 'notes.forEach(note => note.addModifier(factory.Articulation({ type: params.type, position: params.position }), 0));'), [
|
|
43
|
+
select('type', 'Articulation', 'a.', ['a.', 'a-', 'a>', 'a^', 'a@a', 'a@u']),
|
|
44
|
+
select('position', 'Position', 'above', ['above', 'below']),
|
|
45
|
+
]),
|
|
46
|
+
e('ornaments', 'Ornaments', 'Marks & expression', 'Attach turns, mordents, trills, and other ornaments to notes.', 'Ornament', staff("score.notes('C5/q, D5, E5, G5')", 'notes.forEach(note => note.addModifier(factory.Ornament(params.type), 0));'), [
|
|
47
|
+
select('type', 'Ornament', 'tr', [
|
|
48
|
+
'tr',
|
|
49
|
+
'mordent',
|
|
50
|
+
'mordentInverted',
|
|
51
|
+
'turn',
|
|
52
|
+
'turnInverted',
|
|
53
|
+
'upprall',
|
|
54
|
+
'doit',
|
|
55
|
+
'fall',
|
|
56
|
+
]),
|
|
57
|
+
]),
|
|
58
|
+
e('tremolo', 'Tremolo', 'Marks & expression', 'Repeated strokes across a stem indicate rapid repetition.', 'Tremolo', staff("score.notes('C5/h, E5, G5')", 'notes.forEach(note => note.addModifier(new VF.Tremolo(params.strokes), 0));'), [number('strokes', 'Strokes', 3, 1, 4)]),
|
|
59
|
+
e('fingering', 'Fingerings', 'Marks & expression', 'Place a finger number beside each pitch of a chord.', 'FretHandFinger', staff("score.notes('(C5 E5 G5)/h, (D5 F5 A5)')", "notes.forEach(note => ['1', '3', '5'].forEach((number, i) => note.addModifier(factory.Fingering({ number, position: params.position }), i)));"), [select('position', 'Position', 'left', ['left', 'right', 'above', 'below'])]),
|
|
60
|
+
e('parentheses', 'Parentheses', 'Marks & expression', 'Parenthesize a pitch to indicate an optional or editorial note.', 'Parenthesis', staff("score.notes('C5/q, D5, E5, G5')", 'VF.Parenthesis.buildAndAttach([notes[1], notes[3]]);')),
|
|
61
|
+
];
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { example as e, number, select, setup, staff, text } from './helpers.mjs';
|
|
2
|
+
const group = 'Staves & structure';
|
|
3
|
+
export const staves = [
|
|
4
|
+
e('clefs', 'Clefs', group, 'Compare clefs and their positions on the staff.', 'Stave Clef', `${setup}
|
|
5
|
+
const stave = factory.Stave({ x: 35, y: 65, width: width - 70 });
|
|
6
|
+
stave.addClef(params.clef);
|
|
7
|
+
factory.draw();`, [
|
|
8
|
+
select('clef', 'Clef', 'treble', [
|
|
9
|
+
'treble',
|
|
10
|
+
'bass',
|
|
11
|
+
'alto',
|
|
12
|
+
'tenor',
|
|
13
|
+
'soprano',
|
|
14
|
+
'mezzo-soprano',
|
|
15
|
+
'baritone-c',
|
|
16
|
+
'baritone-f',
|
|
17
|
+
'percussion',
|
|
18
|
+
'tab',
|
|
19
|
+
]),
|
|
20
|
+
]),
|
|
21
|
+
e('stave', 'Staff lines', group, 'Change the number and spacing of lines, from a percussion staff to a conventional stave.', 'Stave', `${setup}
|
|
22
|
+
factory.Stave({ x: 35, y: 65, width: width - 70,
|
|
23
|
+
options: { numLines: params.lines, spacingBetweenLinesPx: params.spacing }
|
|
24
|
+
});
|
|
25
|
+
factory.draw();`, [number('lines', 'Lines', 5, 1, 8), number('spacing', 'Spacing', 10, 5, 20)]),
|
|
26
|
+
e('keys', 'Key signatures', group, 'Render sharp and flat key signatures.', 'KeySignature Stave', staff("score.notes('C5/q, D5, E5, G5')", '', '', ".addClef('treble').addKeySignature(params.key)"), [select('key', 'Key', 'D', ['C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#', 'F', 'Bb', 'Eb', 'Ab', 'Db', 'Gb', 'Cb'])]),
|
|
27
|
+
e('meter', 'Time signatures', group, 'Show simple, compound, common, and cut time.', 'TimeSignature', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').addTimeSignature(params.time)"), [select('time', 'Meter', '4/4', ['2/4', '3/4', '4/4', '6/8', '9/8', '12/8', 'C', 'C|'])]),
|
|
28
|
+
e('barlines', 'Barlines & repeats', group, 'Draw boundaries, endings, and repeat marks on a staff.', 'Barline Stave', `${setup}
|
|
29
|
+
const stave = factory.Stave({ x: 35, y: 65, width: width - 70 }).addClef('treble');
|
|
30
|
+
stave.setBegBarType(VF.Barline.type.REPEAT_BEGIN);
|
|
31
|
+
stave.setEndBarType(VF.Barline.type[params.ending]);
|
|
32
|
+
factory.draw();`, [
|
|
33
|
+
select('ending', 'End barline', 'REPEAT_END', [
|
|
34
|
+
'SINGLE',
|
|
35
|
+
'DOUBLE',
|
|
36
|
+
'END',
|
|
37
|
+
'REPEAT_BEGIN',
|
|
38
|
+
'REPEAT_END',
|
|
39
|
+
'REPEAT_BOTH',
|
|
40
|
+
'NONE',
|
|
41
|
+
]),
|
|
42
|
+
]),
|
|
43
|
+
e('connectors', 'Staff connectors', group, 'Connect multiple staves with braces, brackets, or a shared barline.', 'StaveConnector System', `${setup}
|
|
44
|
+
const system = factory.System({ x: 45, y: 30, width: width - 80, spaceBetweenStaves: 9 });
|
|
45
|
+
system.addStave({ voices: [score.voice(score.notes('C5/w'))] }).addClef('treble');
|
|
46
|
+
system.addStave({ voices: [score.voice(score.notes('C3/w', { clef: 'bass' }))] }).addClef('bass');
|
|
47
|
+
system.addConnector(params.connector);
|
|
48
|
+
factory.draw();`, [
|
|
49
|
+
select('connector', 'Connector', 'brace', [
|
|
50
|
+
'brace',
|
|
51
|
+
'bracket',
|
|
52
|
+
'singleLeft',
|
|
53
|
+
'singleRight',
|
|
54
|
+
'double',
|
|
55
|
+
'thinDouble',
|
|
56
|
+
]),
|
|
57
|
+
]),
|
|
58
|
+
e('tempo', 'Tempo markings', group, 'Combine a tempo name with a metronome mark.', 'StaveTempo', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').setTempo({ name: params.name, duration: 'q', bpm: params.bpm }, 0)"), [text('name', 'Tempo', 'Andante'), number('bpm', 'BPM', 76, 30, 220)]),
|
|
59
|
+
e('rehearsal', 'Rehearsal marks & text', group, 'Add a section label and a short instruction to the staff.', 'StaveSection StaveText', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').setSection(params.section, 0).setText(params.instruction, VF.Modifier.Position.BELOW)"), [text('section', 'Section', 'A'), text('instruction', 'Instruction', 'dolce')]),
|
|
60
|
+
e('volta', 'Volta endings', group, 'Bracket an alternate ending above a repeated section.', 'Volta', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').setVoltaType(VF.Volta.type.BEGIN_END, params.label, 0)"), [text('label', 'Ending label', '1.')]),
|
|
61
|
+
e('repetition', 'Repeat instructions', group, 'Coda, segno, and textual repeat instructions guide the reader through a score.', 'Repetition', staff("score.notes('C5/q, E5, G5, C6')", '', '', ".addClef('treble').setRepetitionType(VF.Repetition.type[params.mark], 0)"), [
|
|
62
|
+
select('mark', 'Instruction', 'CODA_RIGHT', [
|
|
63
|
+
'CODA_RIGHT',
|
|
64
|
+
'SEGNO_LEFT',
|
|
65
|
+
'DC',
|
|
66
|
+
'DC_AL_CODA',
|
|
67
|
+
'DS_AL_FINE',
|
|
68
|
+
'FINE',
|
|
69
|
+
]),
|
|
70
|
+
]),
|
|
71
|
+
e('changes', 'Changes within a measure', group, 'Insert a clef, key, or meter change into a sequence of tickables.', 'ClefNote KeySigNote TimeSigNote BarNote', `${setup}
|
|
72
|
+
const notes = [
|
|
73
|
+
...score.notes('C5/h'), factory.BarNote(),
|
|
74
|
+
factory.ClefNote({ type: 'bass', options: { size: 'small' } }),
|
|
75
|
+
factory.KeySigNote({ key: 'F' }), factory.TimeSigNote({ time: '3/4' }),
|
|
76
|
+
...score.notes('F3/h', { clef: 'bass' })
|
|
77
|
+
];
|
|
78
|
+
const voice = score.voice(notes).setMode(VF.Voice.Mode.SOFT);
|
|
79
|
+
factory.System({ x: 30, y: 65, width: width - 60 }).addStave({ voices: [voice] }).addClef('treble');
|
|
80
|
+
factory.draw();`),
|
|
81
|
+
e('multirests', 'Multi-measure rests', group, 'Render multi-measure rests as a bar or rest symbols.', 'MultiMeasureRest', `${setup}
|
|
82
|
+
const stave = factory.Stave({ x: 35, y: 65, width: width - 70 }).addClef('treble');
|
|
83
|
+
factory.MultiMeasureRest({ numberOfMeasures: params.measures, useSymbols: params.style === 'symbols' }).setStave(stave);
|
|
84
|
+
factory.draw();`, [number('measures', 'Measures', 8, 1, 32), select('style', 'Style', 'bar', ['bar', 'symbols'])]),
|
|
85
|
+
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { example as e, number, select, setup, staff } from './helpers.mjs';
|
|
2
|
+
const group = 'Strings & tablature';
|
|
3
|
+
function tab(modifications = '', after = '') {
|
|
4
|
+
return `${setup}
|
|
5
|
+
const notes = [3, 5, 7, 8].map(fret => factory.TabNote({ positions: [{ str: params.string ?? 2, fret }], duration: 'q' }));
|
|
6
|
+
${modifications}
|
|
7
|
+
const stave = factory.TabStave({ x: 30, y: 60, width: width - 60 }).addClef('tab');
|
|
8
|
+
const voice = factory.Voice().setStave(stave).addTickables(notes);
|
|
9
|
+
// Align the voice to the available space between the stave margins.
|
|
10
|
+
factory.Formatter().joinVoices([voice]).formatToStave([voice], stave);
|
|
11
|
+
factory.draw();
|
|
12
|
+
${after ? '\n// Draw the connection after the fret positions have been calculated.\n' + after : ''}`.trim();
|
|
13
|
+
}
|
|
14
|
+
export const strings = [
|
|
15
|
+
e('tablature', 'Tablature', group, 'Render fret numbers on a six-string tablature staff.', 'TabNote TabStave', tab(), [number('string', 'String', 2, 1, 6)]),
|
|
16
|
+
e('bends', 'Bends', group, 'Bend a string up to a target pitch, then release it.', 'Bend', tab("notes[0].addModifier(new VF.Bend([{ type: VF.Bend.UP, text: 'Full' }, { type: VF.Bend.DOWN, text: '' }]), 0);")),
|
|
17
|
+
e('vibrato', 'Vibrato', group, 'Attach a vibrato mark to a tablature note and adjust its width.', 'Vibrato', tab('notes[1].addModifier(new VF.Vibrato().setVibratoWidth(params.length), 0);'), [number('length', 'Wave length', 45, 15, 90)]),
|
|
18
|
+
e('tab-slides', 'Tab slides', group, 'Connect frets with an ascending slide.', 'TabSlide', tab('', `new VF.TabSlide({ firstNote: notes[0], lastNote: notes[1], firstIndexes: [0], lastIndexes: [0] }, 1)
|
|
19
|
+
.setContext(factory.getContext()).setStyle({ strokeStyle: ink }).drawWithStyle();`)),
|
|
20
|
+
e('tab-ties', 'Hammer-ons & pull-offs', group, 'Label a tablature tie as a hammer-on or pull-off.', 'TabTie', tab('', `new VF.TabTie({ firstNote: notes[0], lastNote: notes[1], firstIndexes: [0], lastIndexes: [0] }, params.label)
|
|
21
|
+
.setContext(factory.getContext()).setStyle({ fillStyle: ink, strokeStyle: ink }).drawWithStyle();`), [select('label', 'Gesture', 'H', ['H', 'P'])]),
|
|
22
|
+
e('grace-tab', 'Grace tablature', group, 'Lead into a fretted note with a small grace-note group.', 'GraceTabNote GraceNoteGroup', tab("const grace = new VF.GraceTabNote({ positions: [{ str: 2, fret: 2 }], duration: '8' });\nnotes[0].addModifier(new VF.GraceNoteGroup([grace], true), 0);")),
|
|
23
|
+
e('string-numbers', 'String numbers', group, 'Circled string numbers sit beside pitches on a conventional staff.', 'StringNumber', staff("score.notes('C5/q, D5, E5, G5')", "notes.forEach((note, i) => note.addModifier(factory.StringNumber({ number: String(i + 1), position: 'above' }), 0));")),
|
|
24
|
+
e('strokes', 'Arpeggios & brush strokes', group, 'Spread the notes of a chord with a directional stroke.', 'Stroke', staff("score.notes('(C4 E4 G4 C5)/h, (D4 F4 A4 D5)')", 'notes.forEach(note => note.addModifier(new VF.Stroke(params.type), 0));'), [select('type', 'Stroke type', 3, [1, 2, 3, 4, 5, 6])]),
|
|
25
|
+
];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { entries } from './catalog/entries.mjs';
|
|
2
|
+
export const groups = [
|
|
3
|
+
'Notes & rhythm',
|
|
4
|
+
'Staves & structure',
|
|
5
|
+
'Marks & expression',
|
|
6
|
+
'Strings & tablature',
|
|
7
|
+
'Layout & composition',
|
|
8
|
+
];
|
|
9
|
+
export const examples = [...entries].sort((a, b) => groups.indexOf(a.group) - groups.indexOf(b.group));
|
|
10
|
+
export const defaults = (example) => Object.fromEntries(example.controls.map((control) => [control.key, control.value]));
|
|
11
|
+
export const searchExamples = (query) => {
|
|
12
|
+
const words = query.toLowerCase().trim().split(/\s+/);
|
|
13
|
+
return examples.filter((example) => words.every((word) => `${example.title} ${example.group} ${example.description} ${example.api.join(' ')}`.toLowerCase().includes(word)));
|
|
14
|
+
};
|
|
@@ -54,6 +54,8 @@ export declare class Accidental extends Modifier {
|
|
|
54
54
|
setNote(note: Note): this;
|
|
55
55
|
/** If called, draws parenthesis around accidental. */
|
|
56
56
|
setAsCautionary(): this;
|
|
57
|
+
/** Identify explicit cautionary signs without inspecting protected engraving state. */
|
|
58
|
+
isCautionary(): boolean;
|
|
57
59
|
/** Render accidental onto canvas. */
|
|
58
60
|
draw(): void;
|
|
59
61
|
}
|
|
@@ -58,6 +58,12 @@ export declare class Articulation extends Modifier {
|
|
|
58
58
|
* is far from this ideal.
|
|
59
59
|
*/
|
|
60
60
|
static format(articulations: Articulation[], state: ModifierContextState): boolean;
|
|
61
|
+
/** Resolve EasyScore aliases, native codes, or named SMuFL glyphs without constructing a modifier. */
|
|
62
|
+
static parseEasyScore(articulations: string): {
|
|
63
|
+
type: string;
|
|
64
|
+
position?: number;
|
|
65
|
+
}[];
|
|
66
|
+
/** Attach validated EasyScore articulations once, after note construction. */
|
|
61
67
|
static easyScoreHook({ articulations }: {
|
|
62
68
|
articulations: string;
|
|
63
69
|
}, note: StemmableNote, builder: Builder): void;
|
|
@@ -86,6 +86,8 @@ export declare class Beam extends Element {
|
|
|
86
86
|
secondaryBreaks?: string;
|
|
87
87
|
showStemlets?: boolean;
|
|
88
88
|
maintainStemDirections?: boolean;
|
|
89
|
+
/** Optional facade policy. Omitted preserves the native generator's historical behavior. */
|
|
90
|
+
stemPolicy?: 'auto' | 'explicit' | 'preserve';
|
|
89
91
|
beamMiddleOnly?: boolean;
|
|
90
92
|
beamRests?: boolean;
|
|
91
93
|
groups?: Fraction[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FontInfo } from './font';
|
|
2
|
+
/** Script position relative to the parent chord's baseline. */
|
|
3
|
+
export type ChordSymbolPosition = 'baseline' | 'superscript' | 'subscript';
|
|
4
|
+
/** A boundary adjustment in parent-font em units. Characters are literal Unicode values. */
|
|
5
|
+
export interface ChordSymbolKerningPair {
|
|
6
|
+
left: string;
|
|
7
|
+
right: string;
|
|
8
|
+
position: ChordSymbolPosition;
|
|
9
|
+
adjustmentEm: number;
|
|
10
|
+
}
|
|
11
|
+
/** Exact faces and style for a calibrated pair table. Custom profiles are per chord. */
|
|
12
|
+
export interface ChordSymbolKerningProfile {
|
|
13
|
+
textFont: string;
|
|
14
|
+
musicFont: string;
|
|
15
|
+
weight?: string | number;
|
|
16
|
+
style?: string;
|
|
17
|
+
pairs: readonly ChordSymbolKerningPair[];
|
|
18
|
+
}
|
|
19
|
+
/** Text stays together until a music glyph or script boundary changes the font run. */
|
|
20
|
+
export interface ChordSymbolText {
|
|
21
|
+
text: string;
|
|
22
|
+
position: ChordSymbolPosition;
|
|
23
|
+
}
|
|
24
|
+
/** A measured run, in unscaled score coordinates, shared by Canvas and SVG. */
|
|
25
|
+
export interface ChordSymbolRun extends ChordSymbolText {
|
|
26
|
+
font: FontInfo;
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
metrics: TextMetrics;
|
|
30
|
+
}
|
|
31
|
+
/** Match explicit leading faces, not a guess about which fallback face supplied a glyph. */
|
|
32
|
+
export declare function chordKerningProfile(font: FontInfo, custom?: ChordSymbolKerningProfile): ChordSymbolKerningProfile | undefined;
|
|
33
|
+
/** Rebuild positions on every format pass. No accumulated shifts or separate SVG-only corrections. */
|
|
34
|
+
export declare function layoutChordRuns(blocks: readonly ChordSymbolText[], font: FontInfo, profile: ChordSymbolKerningProfile, options: {
|
|
35
|
+
spacing: number;
|
|
36
|
+
ratio: number;
|
|
37
|
+
superscript: number;
|
|
38
|
+
subscript: number;
|
|
39
|
+
}, measure: (text: string, font: FontInfo) => TextMetrics): {
|
|
40
|
+
runs: ChordSymbolRun[];
|
|
41
|
+
width: number;
|
|
42
|
+
};
|