UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

34 lines (33 loc) 1.24 kB
import * as util from '../../util'; import { Voice } from './voice'; import { StaveContext } from './contexts'; export class Stave { config; log; number; partId; signature; voices; constructor(config, log, number, partId, signature, voices) { this.config = config; this.log = log; this.number = number; this.partId = partId; this.signature = signature; this.voices = voices; } static create(config, log, number, partId, signature, events) { const voiceEvents = events.filter((event) => typeof event.voiceId === 'string'); const voices = util.unique(voiceEvents.map((event) => event.voiceId)).map((voiceId) => Voice.create(config, log, voiceId, voiceEvents.filter((e) => e.voiceId === voiceId))); return new Stave(config, log, number, partId, signature, voices); } parse(partCtx) { const staveCtx = new StaveContext(partCtx, this.number); return { type: 'stave', signature: this.signature.asStaveSignature(this.partId, this.number).parse(), voices: this.voices.map((voice) => voice.parse(staveCtx)), multiRestCount: staveCtx.getMultiRestCount(), }; } }