UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

134 lines (133 loc) 5.03 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Ornaments = void 0; const util = __importStar(require("../util")); const accidentalmark_1 = require("./accidentalmark"); const wavyline_1 = require("./wavyline"); const trillmark_1 = require("./trillmark"); const turn_1 = require("./turn"); const delayedturn_1 = require("./delayedturn"); const invertedturn_1 = require("./invertedturn"); const mordent_1 = require("./mordent"); const invertedmordent_1 = require("./invertedmordent"); const tremolo_1 = require("./tremolo"); /** * Ornaments can be any of several types, followed optionally by accidentals. * * See https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/ornaments/. */ class Ornaments { element; constructor(element) { this.element = element; } /** Returns trill mark entries. Defaults to an empty array. */ getTrillMarks() { return this.getEntries('trill-mark').map((entry) => ({ ...entry, value: new trillmark_1.TrillMark(entry.value), })); } /** Returns turn entries. Defaults to an empty array. */ getTurns() { return this.getEntries('turn').map((entry) => ({ ...entry, value: new turn_1.Turn(entry.value), })); } /** Returns the wavy lines of the ornaments. Defaults to an empty array. */ getWavyLines() { return this.getEntries('wavy-line').map((entry) => ({ ...entry, value: new wavyline_1.WavyLine(entry.value), })); } /** Returns the delayed turns of the ornaments. Defaults to an empty array. */ getDelayedTurns() { return this.getEntries('delayed-turn').map((entry) => ({ ...entry, value: new delayedturn_1.DelayedTurn(entry.value), })); } /** Returns the inverted turns of the ornaments. Defaults to an empty array. */ getInvertedTurns() { return this.getEntries('inverted-turn').map((entry) => ({ ...entry, value: new invertedturn_1.InvertedTurn(entry.value), })); } /** Returns the mordents of the ornaments. Defaults to an empty array. */ getMordents() { return this.getEntries('mordent').map((entry) => ({ ...entry, value: new mordent_1.Mordent(entry.value), })); } /** Returns the inverted mordents of the ornaments. Defaults to an empty array. */ getInvertedMordents() { return this.getEntries('inverted-mordent').map((entry) => ({ ...entry, value: new invertedmordent_1.InvertedMordent(entry.value), })); } getTremolos() { return this.getEntries('tremolo').map((entry) => ({ ...entry, value: new tremolo_1.Tremolo(entry.value), })); } getEntries(name) { const entries = new Array(); function startEntry(value) { entries.push({ value, accidentalMarks: [] }); } function addAccidentalMark(accidentalMark) { // Based on the `<ornament>` spec, we should always have an entry to add the accidental mark to. Otherwise, we // silently ignore it. util.last(entries)?.accidentalMarks.push(accidentalMark); } for (const child of this.element.children()) { if (child.isNamed(name)) { startEntry(child); } if (child.isNamed('accidental-mark')) { addAccidentalMark(new accidentalmark_1.AccidentalMark(child)); } } return entries; } } exports.Ornaments = Ornaments;