UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

65 lines (64 loc) 1.72 kB
export class Pedal { config; log; phase; pedalType; pedalMarkType; constructor(config, log, phase, pedalType, pedalMarkType) { this.config = config; this.log = log; this.phase = phase; this.pedalType = pedalType; this.pedalMarkType = pedalMarkType; } static create(config, log, musicXML) { let phase; switch (musicXML.pedal.getType()) { case 'start': phase = 'start'; break; case 'stop': phase = 'stop'; break; default: phase = 'continue'; break; } let pedalType; const line = musicXML.pedal.line(); const sign = musicXML.pedal.sign(); if (line && sign) { pedalType = 'mixed'; } else if (line) { pedalType = 'bracket'; } else if (sign) { pedalType = 'text'; } else { pedalType = 'bracket'; } let pedalMarkType; switch (musicXML.pedal.getType()) { case 'change': pedalMarkType = 'change'; break; default: pedalMarkType = 'default'; break; } return new Pedal(config, log, phase, pedalType, pedalMarkType); } parse(voiceCtx) { if (this.phase === 'start') { voiceCtx.beginPedal(this.pedalType); } if (this.phase === 'continue') { voiceCtx.primeNextPedalMark(this.pedalMarkType); } if (this.phase === 'stop') { voiceCtx.closePedal(); } } }