UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

64 lines (63 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextStateMachine = void 0; /** A state machine for calculating the text that should come from a <lyric> element. */ 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; } } } exports.TextStateMachine = TextStateMachine;