UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

56 lines (55 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Lyric = void 0; const enums_1 = require("./enums"); /** * The <lyric> element represents text underlays for lyrics. * * https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/lyric/ */ class Lyric { element; constructor(element) { this.element = element; } /** Returns the verse number the lyric belongs to. Defaults to 1. */ getVerseNumber() { return this.element.attr('number').withDefault(1).int(); } /** * Returns the components of the lyric. * * This method assumes that the lyric children adhere to the MusicXML spec — it does not coerc values. */ getComponents() { const components = new Array(); for (const element of this.element.children('syllabic', 'text', 'elision')) { if (element.isNamed('syllabic')) { components.push(this.createSyllabic(element)); } else if (element.isNamed('text')) { components.push(this.createText(element)); } else if (element.isNamed('elision')) { components.push(this.createElision(element)); } } return components; } createSyllabic(syllabic) { const value = syllabic .content() .withDefault('single') .enum(enums_1.SYLLABIC_TYPES); return { type: 'syllabic', value }; } createText(text) { const value = text.content().withDefault('').str(); return { type: 'text', value }; } createElision(elision) { const value = elision.content().withDefault('').str(); return { type: 'elision', value }; } } exports.Lyric = Lyric;