VexFlow Sandbox

Chord Changes Good Fonts

by ronyeh

HTML

<script src="https://unpkg.com/[email protected]/build/cjs/vexflow-debug.js"></script>
<div id="output"></div>

JavaScript

const {
  Font,
  Renderer,
  SymbolModifiers,
  ChordSymbol,
  StaveNote,
  Stave,
  Accidental,
  Formatter
} = Vex;

Font.loadWebFonts().then(() => {
  // FONTS ARE NOW READY!
});

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(700, 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()
  .setFontSize(14)
  .addText('B')
  .addGlyph('b')
  .addText('7', {
    symbolModifier: SymbolModifiers.SUPERSCRIPT,
  })
  .addGlyph('(', {
    symbolModifier: SymbolModifiers.SUPERSCRIPT,
  })
  .addGlyph('b', {
    symbolModifier: SymbolModifiers.SUPERSCRIPT,
  })
  .addText('5', {
    symbolModifier: SymbolModifiers.SUPERSCRIPT,
  })
  .addGlyph(')', {
    symbolModifier: SymbolModifiers.SUPERSCRIPT,
  });

let chord2 = new ChordSymbol().setFontSize(10).addGlyphOrText('Bb').addGlyphOrText('(7b5)', {
  symbolModifier: SymbolModifiers.SUPERSCRIPT,
});
notes[0].addModifier(chord1);
notes[1].addModifier(chord2);

Formatter.FormatAndDraw(context, stave, notes);

Vex.Flow.setMusicFont('Petaluma', 'Gonville', 'Custom');

stave = new Stave(10, 120, 400);

// Add a clef and time signature.
stave.addClef('treble').addTimeSignature('4/4');

// Connect it to the rendering context and...