UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

52 lines (51 loc) 1.94 kB
import { BARLINE_LOCATIONS, BAR_STYLES, START_STOP_DISCONTINUE, REPEAT_DIRECTIONS, } from './enums'; /** * Barline includes information about repeats, endings, and graphical bar styles. * * See https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/barline/ */ export class Barline { element; constructor(element) { this.element = element; } /** Returns the bar style of the barline. Defaults to 'regular'. */ getBarStyle() { return this.element.first('bar-style')?.content().enum(BAR_STYLES) ?? 'regular'; } /** Whether or not the barline is a repeat. Defaults to false. */ isRepeat() { return this.element.all('repeat').length > 0; } /** Returns the number of times the repeat should be played. Defaults to null. */ getRepeatTimes() { return this.element.first('repeat')?.attr('times').int() ?? null; } /** Returns the repeat direction. Defaults to null. */ getRepeatDirection() { return this.element.first('repeat')?.attr('direction').enum(REPEAT_DIRECTIONS) ?? null; } /** Returns the location of the barline. Defaults to 'right'. */ getLocation() { return this.element .attr('location') .withDefault('right') .enum(BARLINE_LOCATIONS); } /** Whether or not the barline is an ending */ isEnding() { return this.element.all('ending').length > 0; } /** Returns the ending text. Defaults to empty string. */ getEndingText() { return this.element.first('ending')?.content().str() ?? ''; } /** Returns the ending number. Defaults to '1'. */ getEndingNumber() { return this.element.first('ending')?.attr('number').str() ?? '1'; } /** Returns the ending type. Defaults to 'start'. */ getEndingType() { return this.element.first('ending')?.attr('type').enum(START_STOP_DISCONTINUE) ?? 'start'; } }