VexFlow Sandbox

Experiment with VexFlow

HTML

<script src="https://npmcdn.com/vexflow/releases/vexflow-debug.js"></script>
<div id="container">
  <div id="boo"></div>
</div>

CSS

#container {
  width: 120px;
  height: 120px;
  overflow: hidden;
  border: 1px solid deeppink;
  marging: 10px;
}

#container > div {
  width: 500px;
  height: 120px;
  white-space: nowrap;
  animation: move-score 3s linear infinite;
}

#container:hover > div {
  animation-play-state: paused;
}

@keyframes move-score {
  0% {
    margin-left: 0px;
  }
  50% {
    margin-left: -100px;
  }
  100% {
    margin-left: -200px;
  }
}

JavaScript

VF = Vex.Flow;

// Create an SVG renderer and attach it to the DIV element named "boo".
var div = document.getElementById("boo")
var renderer = new VF.Renderer(div, VF.Renderer.Backends.SVG);

// Configure the rendering context.
renderer.resize(500, 500);
var context = renderer.getContext();
context.setFont("Arial", 10, "").setBackgroundFillStyle("#eed");

// Create a stave of width 400 at position 10, 40 on the canvas.
var stave = new VF.Stave(10, 10, 400);

// Connect it to the rendering context and draw!
stave.setContext(context).draw();

var notes = [
  new VF.StaveNote({
    keys: ["e##/5"],
    duration: "8d"
  }).
  addAccidental(0, new VF.Accidental("##")).addDotToAll(),
  new VF.StaveNote({
    keys: ["b/4"],
    duration: "16"
  }).
  addAccidental(0, new VF.Accidental("b"))
];

var notes2 = [
  new VF.StaveNote({
    keys: ["c/4"],
    duration: "8"
  }),
  new VF.StaveNote({
    keys: ["d/4"],
    duration: "16"
  }),
  new VF.StaveNote({
    keys: ["e/4"],
    duration: "16"
  }).
  addAccidental(0, new VF.Accidental("b"))
];

var notes3 = [
  new VF.StaveNote({
    keys: ["d/4"],
    duration: "16"
  }),
  new VF.StaveNote({
    keys: ["e/4"],
    duration: "16"
  }).
  addAccidental(0, new VF.Accidental("#")),
  new VF.StaveNote({
    keys: ["g/4"],
    duration: "32"
  }),
  new VF.StaveNote({
    keys: ["a/4"],
    duration: "32"
  }),
  new VF.StaveNote({
    keys: ["g/4"],
    duration: "16"
  })
];

var notes4 = [new VF.StaveNote({
  keys: ["d/4"],
  duration: "q"
})];

// Create the beams
beams = [
  new VF.Beam(notes)
]

var all_notes = notes.concat(notes2).concat(notes3).concat(notes4);
Vex.Flow.Formatter.FormatAndDraw(context, stave, all_notes);
beams.forEach(function(b) {
  b.setContext(context).draw()
})