Skip to content

Commit

Permalink
Merge pull request #1606 from AaronDavidNewman/master
Browse files Browse the repository at this point in the history
issue #1603 - key signature on non-treble stave, no glyph
  • Loading branch information
AaronDavidNewman authored Jan 6, 2024
2 parents 7e7eb97 + 770015f commit 8ddc8fa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/stave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 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,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 };

0 comments on commit 8ddc8fa

Please sign in to comment.