UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

65 lines (64 loc) 1.5 kB
// Conversions to milliseconds const ms = (v) => v; const sec = (v) => ms(v * 1000); const min = (v) => sec(v * 60); export class Duration { static zero() { return new Duration(0); } static ms(v) { return new Duration(ms(v)); } static sec(v) { return new Duration(sec(v)); } static minutes(v) { return new Duration(min(v)); } static sum(durations) { return Duration.ms(durations.reduce((acc, duration) => acc + duration.ms, 0)); } static max(...durations) { return Duration.ms(Math.max(...durations.map((duration) => duration.ms))); } _ms; constructor(ms) { this._ms = ms; } isEqual(duration) { return this.ms === duration.ms; } add(duration) { return Duration.ms(duration.ms + this.ms); } isGreaterThan(duration) { return this.ms > duration.ms; } isGreaterThanOrEqual(duration) { return this.ms >= duration.ms; } isLessThan(duration) { return this.ms < duration.ms; } isLessThanOrEqualTo(duration) { return this.ms <= duration.ms; } compare(duration) { if (this.isLessThan(duration)) { return -1; } if (this.isGreaterThan(duration)) { return 1; } return 0; } get ms() { return this._ms; } get sec() { return this.ms / 1000; } get minutes() { return this.sec / 60; } }