UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

96 lines (95 loc) 3.44 kB
import * as util from '../util'; import { DirectionType, } from './directiontype'; import { ABOVE_BELOW } from './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/ */ export 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(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(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; } }