@stringsync/vexml
Version:
MusicXML to Vexflow
46 lines (45 loc) • 1.42 kB
JavaScript
import { Stave } from './stave';
import { Fraction } from '../util';
export class Part {
config;
log;
document;
partRender;
staves;
constructor(config, log, document, partRender, staves) {
this.config = config;
this.log = log;
this.document = document;
this.partRender = partRender;
this.staves = staves;
}
static create(config, log, document, partRender) {
const staves = partRender.staveRenders.map((staveRender) => Stave.create(config, log, document, staveRender));
return new Part(config, log, document, partRender, staves);
}
/** The name of the element, which can be used as a type discriminant. */
name = 'part';
/** Returns the bounding box of the element. */
rect() {
return this.partRender.rect;
}
/** Returns the staves of the part. */
getStaves() {
return this.staves;
}
/** Returns the part index. */
getIndex() {
return this.partRender.key.partIndex;
}
/** Returns the system index. */
getSystemIndex() {
return this.partRender.key.systemIndex;
}
/** Returns the start measure beat for the part. */
getStartMeasureBeat() {
return (this.staves
.map((stave) => stave.getStartMeasureBeat())
.sort((a, b) => a.toDecimal() - b.toDecimal())
.at(0) ?? Fraction.zero());
}
}