UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

46 lines (45 loc) 1.46 kB
import { Voice } from './voice'; import { Fraction } from '../util'; export class Stave { config; log; document; staveRender; voices; constructor(config, log, document, staveRender, voices) { this.config = config; this.log = log; this.document = document; this.staveRender = staveRender; this.voices = voices; } static create(config, log, document, staveRender) { const voices = staveRender.voiceRenders.map((voiceRender) => Voice.create(config, log, document, voiceRender)); return new Stave(config, log, document, staveRender, voices); } /** The name of the element, which can be used as a type discriminant. */ name = 'stave'; /** Returns the bounding box of the element. */ rect() { return this.staveRender.rect; } /** Returns the intrinsic rect of the stave. */ intrinsicRect() { return this.staveRender.intrinsicRect; } /** Returns the playable rect of the stave. */ playableRect() { return this.staveRender.playableRect; } /** Returns the voices of the stave. */ getVoices() { return this.voices; } /** Returns the start measure beat for the stave. */ getStartMeasureBeat() { return (this.voices .map((voice) => voice.getStartMeasureBeat()) .sort((a, b) => a.toDecimal() - b.toDecimal()) .at(0) ?? Fraction.zero()); } }