UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

133 lines (132 loc) 4.97 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.Direction = void 0; const util = __importStar(require("../util")); const directiontype_1 = require("./directiontype"); const enums_1 = require("./enums"); /** * A direction is a musical indication that is not necessarily attached to a specific note. * * See https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/direction/ */ class Direction { element; constructor(element) { this.element = element; } /** * Returns the type of direction. * * There should be at least one, but will default to an empty array. */ getTypes() { return this.element.all('direction-type').map((node) => new directiontype_1.DirectionType(node)); } /** Returns the segnos of the direction. */ getSegnos() { return this.getTypes() .map((type) => type.getContent()) .filter((content) => content.type === 'segno') .flatMap((content) => content.segnos); } /** Returns the codas of the direction. */ getCodas() { return this.getTypes() .map((type) => type.getContent()) .filter((content) => content.type === 'coda') .flatMap((content) => content.codas); } /** Returns the octave shifts of the direction. */ getOctaveShifts() { return this.getTypes() .map((type) => type.getContent()) .filter((content) => content.type === 'octaveshift') .map((content) => content.octaveShift); } /** Returns the dynamics of the direction. */ getDynamics() { return this.getTypes() .map((type) => type.getContent()) .filter((content) => content.type === 'dynamics') .flatMap((content) => content.dynamics); } /** Returns the metronomes of the direction. */ getMetronome() { return util.first(this.getTypes() .map((type) => type.getContent()) .filter((content) => content.type === 'metronome') .flatMap((content) => content.metronome)); } /** Returns the tokens of the direction. */ getTokens() { return this.getTypes() .map((type) => type.getContent()) .filter((content) => content.type === 'tokens') .flatMap((content) => content.tokens); } /** Returns the wedges of the direction. */ getWedges() { return this.getTypes() .map((type) => type.getContent()) .filter((content) => content.type === 'wedge') .map((content) => content.wedge); } /** Returns the pedals of the direction. */ getPedals() { return this.getTypes() .map((type) => type.getContent()) .filter((content) => content.type === 'pedal') .map((content) => content.pedal); } /** * Returns the placement of the direction. Defaults to null. * * This is not universally applicable to all `<direction>` children. When a child specifies a placement, it overrides * this specification. */ getPlacement() { return this.element.attr('placement').enum(enums_1.ABOVE_BELOW); } /** Returns the voice this direction belongs to. Defaults to null. */ getVoice() { return this.element.first('voice')?.content().str() ?? null; } /** Returns the staff this direction belongs to. Defaults to null. */ getStaveNumber() { return this.element.first('staff')?.content().int() ?? null; } } exports.Direction = Direction;