From ca853a15ad37cfbf647d1422896a20c55b8c2104 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 27 Jul 2020 07:18:10 -0400 Subject: [PATCH] multiple measures --- app.js | 61 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/app.js b/app.js index 07553f7..371701c 100644 --- a/app.js +++ b/app.js @@ -10,31 +10,36 @@ renderer.resize(1000, 1000); // 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, 800); - -// Add a clef and time signature. -stave.addClef("treble").addTimeSignature("7/8"); - -// Connect it to the rendering context and draw! -stave.setContext(context).draw(); - -var notes = [ - new VF.StaveNote({clef: "treble", keys: ["c/4"], duration: "8" }), - new VF.StaveNote({clef: "treble", keys: ["d/4"], duration: "8" }), - new VF.StaveNote({clef: "treble", keys: ["b/4"], duration: "8" }), - new VF.StaveNote({clef: "treble", keys: ["d/4"], duration: "8" }), - new VF.StaveNote({clef: "treble", keys: ["d/4"], duration: "8" }), - new VF.StaveNote({clef: "treble", keys: ["d/4"], duration: "8" }), - new VF.StaveNote({clef: "treble", keys: ["d/4"], duration: "8" }), -]; - -// Create a voice in 4/4 and add the notes from above -var voice = new VF.Voice({num_beats: 7, beat_value: 8}); -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); + +const drawNotes = (measureNum) => { + // Create a stave at position 10, 40 of width 400 on the canvas. + var stave = new VF.Stave(10+(measureNum*400), 40, 400); + + // Add a clef and time signature. + if(measureNum === 0){ + stave.addClef("treble").addTimeSignature("4/4"); + } + + // Connect it to the rendering context and draw! + stave.setContext(context).draw(); + + var notes = [ + new VF.StaveNote({clef: "treble", keys: ["c/4"], duration: "4" }), + new VF.StaveNote({clef: "treble", keys: ["d/4"], duration: "4" }), + new VF.StaveNote({clef: "treble", keys: ["b/4"], duration: "4" }), + new VF.StaveNote({clef: "treble", keys: ["d/4"], duration: "4" }), + ]; + + // 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); +} + +drawNotes(0); +drawNotes(1);