VexFlow Sandbox
Chord Changes Stacked
by ronyeh
HTML
<script src="https://unpkg.com/[email protected]/build/cjs/vexflow-debug.js"></script>
<div id="output"></div>
JavaScript
const {
Accidental,
ChordSymbol,
Flow,
Font,
Formatter,
Renderer,
Stave,
StaveNote,
SymbolModifiers
} = Vex;
Font.loadWebFonts().then(() => {});
Flow.setMusicFont('Bravura');
// Create an SVG renderer and attach it to the DIV element named "boo".
const div = document.getElementById('output');
const renderer = new Renderer(div, Renderer.Backends.SVG);
// Configure the rendering context.
renderer.resize(650, 500);
const context = renderer.getContext();
context.scale(1.5, 1.5);
// Create a stave of width 400 at position 10, 40 on the canvas.
let stave = new Stave(10, 40, 400);
// Add a clef and time signature.
stave.addClef('treble').addTimeSignature('4/4');
// Connect it to the rendering context and draw!
stave.setContext(context).draw();
let notes = [
// A quarter-note C.
new StaveNote({
keys: ['f/4'],
duration: 'h'
}),
// A quarter-note D.
new StaveNote({
keys: ['b/4'],
duration: 'h'
}).addModifier(new Accidental('b')),
];
let chord1 = new ChordSymbol()
.addGlyphOrText('F')
.addGlyphOrText('7', {
symbolModifier: SymbolModifiers.SUPERSCRIPT
})
.addGlyphOrText('b5', {
symbolModifier: SymbolModifiers.SUBSCRIPT
})
.setFontSize(14);
let chord2 = new ChordSymbol()
.addGlyphOrText('Bb7')
.addGlyphOrText('#11', {
symbolModifier: SymbolModifiers.SUPERSCRIPT
})
.addGlyphOrText('b9', {
symbolModifier: SymbolModifiers.SUBSCRIPT
})
.setFontSize(14);
notes[0].addModifier(chord1);
notes[1].addModifier(chord2);
Formatter.FormatAndDraw(context, stave, notes);
Flow.setMusicFont('Petaluma');
stave = new Stave(10, 140, 400);
// Add a clef and time signature.
stave.addClef('treble').addTimeSignature('4/4');
// Connect it to the rendering context and draw!
stave.setContext(context).draw();
notes = [
// A quarter-note C.
new StaveNote({
keys: ['f/4'],
duration: 'h'
}),
// A quarter-note D.
new StaveNote({
keys: ['b/4'],
duration: 'h'
}).addModifier(new...