@stringsync/vexml
Version:
MusicXML to Vexflow
46 lines (45 loc) • 1.43 kB
JavaScript
import { Note } from './note';
import { Rest } from './rest';
export class Voice {
config;
log;
document;
voiceRender;
entries;
constructor(config, log, document, voiceRender, entries) {
this.config = config;
this.log = log;
this.document = document;
this.voiceRender = voiceRender;
this.entries = entries;
}
static create(config, log, document, voiceRender) {
const entries = voiceRender.entryRenders
.map((entryRender) => {
switch (entryRender.type) {
case 'note':
return Note.create(config, log, document, entryRender);
case 'rest':
return Rest.create(config, log, document, entryRender);
default:
return null;
}
})
.filter((entry) => entry !== null);
return new Voice(config, log, document, voiceRender, entries);
}
/** The name of the element, which can be used as a type discriminant. */
name = 'voice';
/** Returns the bounding box of the element. */
rect() {
return this.voiceRender.rect;
}
/** Returns the entries of the voice. */
getEntries() {
return this.entries;
}
/** Returns the start measure beat for the voice. */
getStartMeasureBeat() {
return this.voiceRender.startMeasureBeat;
}
}