Last active
December 27, 2015 13:09
-
-
Save pianosnake/7331148 to your computer and use it in GitHub Desktop.
This is the code it takes to display one note using the JS VexFlow library (http://www.vexflow.com/) Takes a note with an octave and a name like 'g#'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function drawVexNote(note){ | |
var renderer = new Vex.Flow.Renderer("note-canvas", Vex.Flow.Renderer.Backends.CANVAS); | |
var ctx = renderer.getContext(); | |
ctx.clear(); | |
var stave = new Vex.Flow.Stave(0, 0, 100); | |
stave.addClef("treble").setContext(ctx).draw(); | |
var vexNote = new Vex.Flow.StaveNote({ keys: [note.name+"/"+note.octave], duration: "w" }) | |
if(note.name.charAt(1) == "b"){ | |
vexNote.addAccidental(0, new Vex.Flow.Accidental("b")) | |
}elseif(note.name.charAt(1) == "#"){ | |
vexNote.addAccidental(0, new Vex.Flow.Accidental("#")) | |
} | |
Vex.Flow.Formatter.FormatAndDraw(ctx, stave, [vexNote]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment