diff --git a/app.js b/app.js index fa032a8..2c4a093 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,45 @@ -const vf = new Vex.Flow.Factory({renderer: {elementId: 'main'}}); -const score = vf.EasyScore(); -const system = vf.System(); +const VF = Vex.Flow; -system.addStave({ - voices: [score.voice(score.notes('C#5/q, B4, A4, G#4'))] -}).addClef('treble').addTimeSignature('4/4'); +// Create an SVG renderer and attach it to the DIV element named "boo". +var div = document.querySelector("body") +var renderer = new VF.Renderer(div, VF.Renderer.Backends.SVG); -vf.draw(); +// Size our SVG: +renderer.resize(500, 500); + +// And get a drawing context: +var context = renderer.getContext(); + +// Create a stave at position 10, 40 of width 400 on the canvas. +var stave = new VF.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(); + +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 the notes from above +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); diff --git a/index.html b/index.html index 5d765b4..37277cd 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ - +