VexFlow Sandbox
Experiment with VexFlow
by ronyeh
HTML
<script src="https://unpkg.com/[email protected]/build/cjs/vexflow-debug.js"></script>
<div id="output"></div>
JavaScript
const { Accidental, Formatter, Renderer, Stave, StaveNote } = Vex.Flow;
// 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(500, 500);
const context = renderer.getContext();
context.setFont('Arial', 10);
// Create a stave of width 400 at position 10, 40 on the canvas.
const 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();
const notes = [
new StaveNote({ keys: ['g/4', 'b/4', 'cb/5', 'e/5', 'g#/5', 'b/5'], duration: 'h' })
.addModifier(new Accidental('bb'), 0)
.addModifier(new Accidental('b'), 1)
.addModifier(new Accidental('#'), 2)
.addModifier(new Accidental('n'), 3)
.addModifier(new Accidental('b'), 4)
.addModifier(new Accidental('##'), 5),
new StaveNote({ keys: ['c/4'], duration: 'h' }),
];
// Helper function to justify and draw a 4/4 voice.
Formatter.FormatAndDraw(context, stave, notes);