Key Signatures and Clefs

598 views
Skip to first unread message

Jon

unread,
Oct 13, 2011, 1:50:43 PM10/13/11
to vexflow
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


Mohit Muthanna

unread,
Oct 13, 2011, 2:47:45 PM10/13/11
to vex...@googlegroups.com
Hey Jon,

Thanks for making these changes -- this is something that was overlooked. Mind sending me a pull request on github?

Thanks,
Mohit.



--
You received this message because you are subscribed to the Google
Groups "vexflow" group.
To post to this group, send email to vex...@googlegroups.com
To unsubscribe from this group, send email to
vexflow+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/vexflow?hl=en



--
Mohit Muthanna [mohit (at) muthanna (uhuh) com]

Jon

unread,
Oct 15, 2011, 8:36:11 PM10/15/11
to vexflow
Mohit,
I've sent the pull request. The code is a bit tighter than above. I
decided to try to keep the changes to a minimum, so removed the
changes to Clef, and removed the getter/setter in Stave (the clef
property gets set directly in the addClef() method).

Jon

Jon

unread,
Oct 16, 2011, 9:01:37 PM10/16/11
to vexflow
Closed that re

Jon

unread,
Oct 16, 2011, 9:02:44 PM10/16/11
to vexflow
I've closed the request and will re-submit a cleaner one. Still
getting used to Github.

Jon

Mohit Muthanna

unread,
Oct 16, 2011, 9:03:36 PM10/16/11
to vex...@googlegroups.com
No problem. Thanks.

--
You received this message because you are subscribed to the Google
Groups "vexflow" group.
To post to this group, send email to vex...@googlegroups.com
To unsubscribe from this group, send email to
vexflow+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/vexflow?hl=en
Reply all
Reply to author
Forward
0 new messages