abcjs
abcjs copied to clipboard
Extra key signature incorrectly inserted
If your abc has a key change at the beginning of a line, the renderer incorrectly shows the updated key signature at the end of the previous line.
For example, for the abc:
X:1
L:1/4
M:C
K:A
e f g a | !4!b a g f | e f g a | !4!b a g f | e f g a | !4!b a !4!b a | !4!b a !4!b a | !4!b a g f | e4 |]
[K:G] D E F G | !4!A G F E | D E F G | !4!A G F E | D E F G | A G !4!A G | A G A G | !4!A G F E | D4 |]
it's rendered like:

Is there any way to stop the duplicate key signature from being rendered?
This is by design.
In "Behind Bars" on page 93: "When a key change coincides with a system break, then cancelling naturals and the new key signature go at the end of the first system".
I've never seen this behavior in any real sheet music, nor even in any other abc renderers. The "|]" terminator implies an end of the bar, so the next bar is a completely separate piece of music. That means there's no key change happening that needs to be incrementally denoted.
If I had used a "||" or some other separator, I'd agree with you. But these two lines are logically completely separate, so duplicating the key signature is necessary.
For jquery a hack,
var keySignatureLast = false
$('#cheatsheet_music svg g').map(function(k,v) {
if ($(v).hasClass('abcjs-key-signature')) {
if (keySignatureLast) {
$(v).remove()
keySignatureLast = false
} else {
keySignatureLast = true
}
} else {
keySignatureLast = false
}
return true
})