@stringsync/vexml
Version:
MusicXML to Vexflow
70 lines (69 loc) • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JumpGroup = void 0;
class JumpGroup {
config;
log;
jumps;
constructor(config, log, jumps) {
this.config = config;
this.log = log;
this.jumps = jumps;
}
static create(config, log, measureIndex, musicXML) {
const barlines = musicXML.scorePartwise
.getParts()
.map((part) => part.getMeasures())
.map((measures) => measures[measureIndex])
.flatMap((measure) => measure.getBarlines());
const jumps = new Array();
const leftBarlines = barlines.filter((barline) => barline.getRepeatDirection() === 'forward' || barline.getLocation() === 'left');
const rightBarlines = barlines.filter((barline) => barline.getRepeatDirection() === 'backward' || barline.getLocation() === 'right');
if (leftBarlines.some((barline) => barline.isRepeat())) {
jumps.push({ type: 'repeatstart' });
}
const leftEnding = leftBarlines.find((barline) => barline.isEnding());
const rightEnding = rightBarlines.find((barline) => barline.isEnding());
const repeatEnd = rightBarlines.find((barline) => barline.isRepeat());
if (leftEnding || rightEnding) {
const hasStart = leftEnding?.getEndingType() === 'start';
const hasStop = rightEnding?.getEndingType() === 'stop';
let endingBracketType = 'mid';
if (hasStart && hasStop) {
endingBracketType = 'both';
}
else if (hasStart) {
endingBracketType = 'begin';
}
else if (hasStop) {
endingBracketType = 'end';
}
const label = leftEnding?.getEndingText() ||
rightEnding?.getEndingText() ||
leftEnding?.getEndingNumber() ||
rightEnding?.getEndingNumber() ||
'';
let times = 0;
if (repeatEnd) {
times = repeatEnd.getRepeatTimes() ?? 1;
}
jumps.push({ type: 'repeatending', times, label, endingBracketType });
}
else if (repeatEnd) {
jumps.push({ type: 'repeatend', times: repeatEnd.getRepeatTimes() ?? 1 });
}
return new JumpGroup(config, log, jumps);
}
getStartBarlineStyle() {
return this.jumps.some((jump) => jump.type === 'repeatstart') ? 'repeatstart' : null;
}
getEndBarlineStyle() {
return this.jumps.some((jump) => jump.type === 'repeatend' || (jump.type === 'repeatending' && jump.times > 0))
? 'repeatend'
: null;
}
parse() {
return this.jumps;
}
}
exports.JumpGroup = JumpGroup;