Hello,
Thanks for VexFlow. It's a great project!
I've been experimenting with VexFlow key signatures. Currently the
default key signature for VexFlow works only for Treble (G) clef. I
made a few changes to Vex.Flow.Stave, Vex.Flow.Clef, and
Vex.Flow.KeySignature in order to get the correct placement of key
signature accidentals if the clef is set to bass, alto, or tenor.
In Vex.Flow.Clef.prototype.init I added a property:
this.clefName = clef
and in the addModifier function:
Vex.Flow.Clef.prototype.addModifier = function(stave) {
var glyph = new Vex.Flow.Glyph(this.clef.code, this.clef.point);
this.placeGlyphOnLine(glyph, stave, this.clef.line);
stave.addGlyph(glyph);
stave.setClef(this.clefName); // this is the new
line of code
}
In Vex.Flow.Stave I added a property:
this.clef = "treble"; //default
and getter/setters:
Vex.Flow.Stave.prototype.getClef = function() {
return this.clef;
}
Vex.Flow.Stave.prototype.setClef = function(clef) {
this.clef = clef;
return this;
}
In Vex.Flow.KeySignature
Added a new function:
Vex.Flow.KeySignature.prototype.setAccLines = function(stave, accList)
{
//convert accList line properties if necessary
}
which converts the line number properties for the accidental List
based on the current clef.
This function is called from here:
Vex.Flow.KeySignature.prototype.addModifier = function(stave) {
this.setAccLines(stave, this.accList); //
this is the new line of code
for (var i = 0; i < this.accList.length; ++i) {
this.addAccToStave(stave, this.accList[i]);
}
}
And here's a modified test page that tests these clef-key signature
changes (the first tests are unchanged / without clefs):
http://www.pedaplus.com/vexflow/tests/flow_clef_ks.html
Jon