Skip to content

Commit

Permalink
fix bug 1603 - key signature on non-treble stave, no glyph
Browse files Browse the repository at this point in the history
None of our test cases had clef with non-default clef (e.g. bass) and a key signature, without the clef symbol displayed.  I added a test case and created a 'addClefLines' that adds the logical clef (e.g. the lines match the clef) but without the glyph.
  • Loading branch information
AaronDavidNewman committed Dec 10, 2023
1 parent 7e7eb97 commit 7d9bb0d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/stave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,14 @@ export class Stave extends Element {
}
return this;
}

/**
* treat the stave as if the clef is clefSpec, but don't display the clef
* @param clefSpec
*/
setClefLines(clefSpec: string) {
this.clef = clefSpec;
return this;
}
setClef(clefSpec: string, size?: string, annotation?: string, position?: number): this {
if (position === undefined) {
position = StaveModifierPosition.BEGIN;
Expand Down
30 changes: 30 additions & 0 deletions tests/keysignature_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const KeySignatureTests = {
run('Altered key test', majorKeysAltered);
run('End key with clef test', endKeyWithClef);
run('Key Signature Change test', changeKey);
run('Key Signature with/without clef symbol', clefKeySignature);
},
};

Expand Down Expand Up @@ -370,5 +371,34 @@ function changeKey(options: TestOptions): void {
options.assert.ok(true, 'all pass');
}

function clefKeySignature(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 900);

// The previous code was buggy: f.Stave(10, 10, 800), even though Factory.Stave() only accepts 1 argument.
const stave = f.Stave({ x: 10, y: 10, width: 800 }).addClef('bass').addTimeSignature('C|').setClefLines('bass');

const voice = f
.Voice()
.setStrict(false)
.addTickables([
f.KeySigNote({ key: 'Bb' }),
f.StaveNote({ keys: ['c/4'], duration: '1' }),
f.BarNote(),
f.KeySigNote({ key: 'D', cancelKey: 'Bb' }),
f.StaveNote({ keys: ['c/4'], duration: '1' }),
f.BarNote(),
f.KeySigNote({ key: 'Bb' }),
f.StaveNote({ keys: ['c/4'], duration: '1' }),
f.BarNote(),
f.KeySigNote({ key: 'D', alterKey: ['b', 'n'] }), // TODO: alterKey needs to be a string[]
f.StaveNote({ keys: ['c/4'], duration: '1' }),
]);

f.Formatter().joinVoices([voice]).formatToStave([voice], stave);

f.draw();

options.assert.ok(true, 'all pass');
}
VexFlowTests.register(KeySignatureTests);
export { KeySignatureTests };

0 comments on commit 7d9bb0d

Please sign in to comment.