How to play the music notes on stave generated by vexflow

343 views
Skip to first unread message

Anas Shaikhany

unread,
Feb 26, 2018, 12:35:22 PM2/26/18
to vexflow

I want to play the past music notes that was generated by the vexflow library:
here's the code that generated the notes:
            VF = Vex.Flow;

           
var div = document.getElementById("render-music");
           
var renderer = new VF.Renderer(div, VF.Renderer.Backends.SVG);

            renderer
.resize(500, 500);

           
var context = renderer.getContext();

           
var stave = new VF.Stave(10, 40, 400);
            stave
.addClef("treble").addTimeSignature("4/4");

            stave
.setContext(context);

            stave
.draw();
           
           
var notes = [
             
// A quarter-note C.
             
new VF.StaveNote({clef: "treble", keys: ["c/4"], duration: "q" }),

             
// A quarter-note D.
             
new VF.StaveNote({clef: "treble", keys: ["d/4"], duration: "q" }),

             
// A quarter-note rest. Note that the key (b/4) specifies the vertical
             
// position of the rest.
             
new VF.StaveNote({clef: "treble", keys: ["b/4"], duration: "qr" }),

             
// A C-Major chord.
             
new VF.StaveNote({clef: "treble", keys: ["c/4", "e/4", "g/4"], duration: "q" })
           
];

           
// Create a voice in 4/4 and add above notes
           
var voice = new VF.Voice({num_beats: 4,  beat_value: 4});
            voice
.addTickables(notes);

           
// Format and justify the notes to 400 pixels.
           
var formatter = new VF.Formatter().joinVoices([voice]).format([voice], 400);

           
// Render voice
            voice
.draw(context, stave);


I have read the vexflow wiki tutorial, and searched through the other pages in the wiki, but none of that seems to help me in playing the notes
anybody can help please?

Reply all
Reply to author
Forward
0 new messages