Automatically add accidentals

255 views
Skip to first unread message

Sascha Alexander Kerschhofer

unread,
Dec 10, 2021, 7:52:49 PM12/10/21
to vexflow
Amazing how far VF has come! But here is a question:
 This jsfiddle is a one liner in D-Major. That means an F and C without a natural should is actually a F# or C#. Is there a way to automatically print the natural - and vice versa print accidentals where they should be printed - e.g. if I add a G# ?

VF = Vex.Flow;
var div = document.getElementById("boo")
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, 300);
stave.addClef("treble").addKeySignature('D')
stave.setContext(context).draw();
var notes = [
  new VF.StaveNote({ keys: ["c/4", "f/4", "a/4", "c/5"], duration: "h" }),
  new VF.StaveNote({ keys: ["c#/4", "f#/4", "a/4", "d#/5"], duration: "h" }),
];
var voice = new VF.Voice().addTickables(notes);
var formatter = new VF.Formatter().joinVoices([voice]).format([voice], 300);
voice.draw(context, stave);


Thanks
Sascha

Rodrigo Vilar

unread,
Dec 20, 2021, 1:09:31 AM12/20/21
to vexflow
Have a look at Accidental.applyAccidentals.

Reply all
Reply to author
Forward
0 new messages