UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

44 lines (43 loc) 1.4 kB
import * as vexflow from 'vexflow'; import * as util from '../util'; import { Rect } from '../spatial'; export class Tuplet { config; log; document; key; registry; constructor(config, log, document, key, registry) { this.config = config; this.log = log; this.document = document; this.key = key; this.registry = registry; } render() { const tuplet = this.document.getTuplet(this.key); const voiceEntryRenders = this.registry.get(tuplet.id); util.assertDefined(voiceEntryRenders); util.assert(voiceEntryRenders.length > 1, 'Tuplet must have more than one voice entry'); let vexflowTupletLocation; switch (tuplet.placement) { case 'above': vexflowTupletLocation = vexflow.Tuplet.LOCATION_TOP; break; case 'below': vexflowTupletLocation = vexflow.Tuplet.LOCATION_BOTTOM; break; } const vexflowStaveNotes = voiceEntryRenders.map((entry) => entry.vexflowNote); const vexflowTuplet = new vexflow.Tuplet(vexflowStaveNotes, { location: vexflowTupletLocation, ratioed: tuplet.showNumber, }); return { type: 'tuplet', key: this.key, rect: Rect.empty(), vexflowTuplet, }; } }