@stringsync/vexml
Version:
MusicXML to Vexflow
39 lines (38 loc) • 1.19 kB
JavaScript
import { TIME_SYMBOLS } from './enums';
/**
* Time represents a time signature element.
*
* See https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/time/
*/
export class Time {
element;
constructor(element) {
this.element = element;
}
/** Returns the stave number this time belongs to. Defaults to null. */
getStaveNumber() {
return this.element.attr('number').int();
}
/** Returns the beats of the time. */
getBeats() {
return this.element
.all('beats')
.map((beats) => beats.content().str())
.filter((content) => typeof content === 'string');
}
/** Returns the beat types of the time. */
getBeatTypes() {
return this.element
.all('beat-type')
.map((beatType) => beatType.content().str())
.filter((content) => typeof content === 'string');
}
/** Returns whether the time signature is hidden. */
isHidden() {
return !!this.element.first('senza-misura');
}
/** Returns the symbol of the time. */
getSymbol() {
return this.element.attr('symbol').enum(TIME_SYMBOLS) ?? null;
}
}