UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

60 lines (59 loc) 1.74 kB
/** A state machine for calculating the text that should come from a <lyric> element. */ export class TextStateMachine { state = 'INITIAL'; parts = new Array(); process(component) { switch (this.state) { case 'INITIAL': this.processInitial(component); break; case 'IN_SYLLABLE': this.processInSyllable(component); break; case 'AFTER_SYLLABLE': this.processAfterSyllable(component); break; } } getText() { return this.parts.join(''); } processInitial(component) { switch (component.type) { case 'syllabic': switch (component.value) { case 'begin': case 'middle': this.state = 'IN_SYLLABLE'; break; } break; case 'text': this.parts.push(component.value); break; } } processInSyllable(component) { switch (component.type) { case 'syllabic': switch (component.value) { case 'single': case 'end': this.state = 'AFTER_SYLLABLE'; break; } break; case 'text': this.parts.push(component.value); break; } } processAfterSyllable(component) { switch (component.type) { case 'elision': this.parts.push(component.value); this.state = 'INITIAL'; break; } } }