VexFlow Sandbox
Chord Changes Theory
by ronyeh
HTML
<script src="https://unpkg.com/[email protected]/build/cjs/vexflow-debug.js"></script>
<div id="output"></div>
CSS
@font-face {
font-family: 'petalumaScript';
src: url('https://aarondavidnewman.github.io/Smoosic/build/styles/fonts/petalumascript-webfont.woff2') format('woff2'),
url('https://aarondavidnewman.github.io/Smoosic/build/styles/fonts/petalumascript-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'robotoSlab';
src: url('https://aarondavidnewman.github.io/Smoosic/build/styles/fonts/robotoslab-webfont.woff2') format('woff2'),
url('https://aarondavidnewman.github.io/Smoosic/build/styles/fonts/robotoslab-webfont.woff') format('woff');
font-weight: 500;
font-style: normal;
}
JavaScript
const { Renderer, Font, Stave, StaveNote, ChordSymbol, Formatter, Accidental } = Vex.Flow;
Font.loadWebFonts();
Vex.Flow.setMusicFont('Bravura', 'Gonville', 'Custom');
// 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(800, 500);
const context = renderer.getContext();
context.scale(1.5, 1.5);
context.setFont('Arial', 10);
// Create a stave of width 400 at position 10, 40 on the canvas.
let stave = new Stave(10, 40, 500);
// 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: ['c/4', 'f/4', 'a/4'],
duration: 'q',
}),
// A quarter-note D.
new StaveNote({
keys: ['c/4', 'e/4', 'b/4'],
duration: 'q',
}).addModifier(new Accidental('b'), 2),
new StaveNote({
keys: ['c/4', 'e/4', 'g/4'],
duration: 'q',
}),
new StaveNote({
keys: ['c/4', 'f/4', 'a/4'],
duration: 'q',
}).addModifier(new Accidental('#'), 1),
];
let chords = [];
chords.push(new ChordSymbol().setVertical('bottom').addText('I').addTextSuperscript('6').addTextSubscript('4'));
chords.push(new ChordSymbol().setVertical('bottom').addGlyphOrText('V'));
chords.push(new ChordSymbol().addLine(12).setVertical('bottom'));
chords.push(new ChordSymbol().addGlyphOrText('V/V').setVertical('bottom'));
for (let i = 0; i < notes.length; ++i) {
notes[i].addModifier(chords[i], 0);
}
Formatter.FormatAndDraw(context, stave, notes);
Vex.Flow.setMusicFont('Petaluma', 'Gonville', 'Custom');
stave = new Stave(10, 150, 500);
// 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 = [
new StaveNote({
keys:...