@stringsync/vexml
Version:
MusicXML to Vexflow
53 lines (52 loc) • 1.99 kB
JavaScript
import * as conversions from './conversions';
export class Metronome {
config;
log;
playbackBpm;
opts;
constructor(config, log, playbackBpm, opts) {
this.config = config;
this.log = log;
this.playbackBpm = playbackBpm;
this.opts = opts;
}
static default(config, log) {
return new Metronome(config, log, config.DEFAULT_PLAYBACK_BPM, {});
}
static create(config, log, musicXML) {
const parenthesis = musicXML.metronome.parentheses() ?? undefined;
const duration = conversions.fromNoteTypeToDurationType(musicXML.mark.left.unit) ?? undefined;
const dots = musicXML.mark.left.dotCount;
switch (musicXML.mark.right.type) {
case 'note':
const duration2 = conversions.fromNoteTypeToDurationType(musicXML.mark.right.unit) ?? undefined;
const dots2 = musicXML.mark.right.dotCount;
return new Metronome(config, log, config.DEFAULT_PLAYBACK_BPM, {
parenthesis,
duration,
dots,
duration2,
dots2,
});
case 'bpm':
const displayBpm = musicXML.mark.right.bpm;
return new Metronome(config, log, displayBpm, { parenthesis, duration, dots, displayBpm });
}
}
parse() {
return {
type: 'metronome',
playbackBpm: this.playbackBpm,
...this.opts,
};
}
isEqual(metronome) {
return (this.opts.name === metronome.opts.name &&
this.opts.parenthesis === metronome.opts.parenthesis &&
this.opts.duration === metronome.opts.duration &&
this.opts.dots === metronome.opts.dots &&
this.opts.displayBpm === metronome.opts.displayBpm &&
this.opts.duration2 === metronome.opts.duration2 &&
this.opts.dots2 === metronome.opts.dots2);
}
}