@stringsync/vexml
Version:
MusicXML to Vexflow
32 lines (31 loc) • 869 B
JavaScript
import * as vexflow from 'vexflow';
const ADDITIONAL_CLEF_WIDTH = 10;
export class Clef {
config;
log;
document;
key;
constructor(config, log, document, key) {
this.config = config;
this.log = log;
this.document = document;
this.key = key;
}
render() {
const clef = this.document.getStave(this.key).signature.clef;
let annotation;
if (clef.octaveShift) {
const direction = clef.octaveShift > 0 ? 'va' : 'vb';
annotation = `8${direction}`;
}
const vexflowClef = new vexflow.Clef(clef.sign, 'default', annotation);
const width = vexflowClef.getWidth() + ADDITIONAL_CLEF_WIDTH;
return {
type: 'clef',
key: this.key,
width,
sign: clef.sign,
vexflowClef,
};
}
}