UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

46 lines (45 loc) 1.58 kB
import * as vexflow from 'vexflow'; import { Rect } from '../spatial'; export class Vibrato { 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 vexflowVibratoBrackets = this.renderVexflowVibratoBrackets(); return { type: 'vibrato', rect: Rect.empty(), vexflowVibratoBrackets, }; } renderVexflowVibratoBrackets() { const vibrato = this.document.getVibrato(this.key); const noteRenders = this.registry.get(vibrato.id); if (noteRenders.length < 2) { this.log.warn('cannot render vibrato with less than 2 notes, skipping', { vibratoIndex: this.key.vibratoIndex }); return []; } const vexflowVibratoBrackets = new Array(); const systemIndexes = noteRenders.map((n) => n.key.systemIndex); for (const systemIndex of systemIndexes) { const renders = noteRenders.filter((n) => n.key.systemIndex === systemIndex); if (renders.length > 1) { const vexflowVibratoBracket = new vexflow.VibratoBracket({ start: renders.at(0).vexflowNote, stop: renders.at(-1).vexflowNote, }); vexflowVibratoBrackets.push(vexflowVibratoBracket); } } return vexflowVibratoBrackets; } }