diff --git a/src/stave.ts b/src/stave.ts index 193f890a1b..943366ef67 100644 --- a/src/stave.ts +++ b/src/stave.ts @@ -444,6 +444,14 @@ export class Stave extends Element { return this; } + /** + * treat the stave as if the clef is clefSpec, but don't display the clef + */ + setClefLines(clefSpec: string) { + this.clef = clefSpec; + return this; + } + setClef(clefSpec: string, size?: string, annotation?: string, position?: number): this { if (position === undefined) { position = StaveModifierPosition.BEGIN; diff --git a/tests/keysignature_tests.ts b/tests/keysignature_tests.ts index 41bf1a7dae..3eba25eea9 100644 --- a/tests/keysignature_tests.ts +++ b/tests/keysignature_tests.ts @@ -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); }, }; @@ -370,5 +371,33 @@ function changeKey(options: TestOptions): void { options.assert.ok(true, 'all pass'); } +function clefKeySignature(options: TestOptions): void { + const f = VexFlowTests.makeFactory(options, 900); + 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', clef: 'bass' }), + f.BarNote(), + f.KeySigNote({ key: 'D', cancelKey: 'Bb' }), + f.StaveNote({ keys: ['c/4'], duration: '1', clef: 'bass' }), + f.BarNote(), + f.KeySigNote({ key: 'Bb' }), + f.StaveNote({ keys: ['c/4'], duration: '1', clef: 'bass' }), + f.BarNote(), + f.KeySigNote({ key: 'D', alterKey: ['b', 'n'] }), + f.StaveNote({ keys: ['c/4'], duration: '1', clef: 'bass' }), + ]); + + f.Formatter().joinVoices([voice]).formatToStave([voice], stave); + + f.draw(); + + options.assert.ok(true, 'all pass'); +} + VexFlowTests.register(KeySignatureTests); export { KeySignatureTests };