@stringsync/vexml
Version:
MusicXML to Vexflow
52 lines (51 loc) • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScorePartwise = void 0;
const defaults_1 = require("./defaults");
const part_1 = require("./part");
/**
* ScorePartwise is the entrypoint of a MusicXML document.
*
* See https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/score-partwise/
*/
class ScorePartwise {
element;
constructor(element) {
this.element = element;
}
/** Returns the part count in the score. */
getPartCount() {
return this.element.all('score-part').length;
}
/** Returns an array of part IDs in the score in the order they appear. Each part ID should be unique. */
getPartIds() {
return this.element
.all('score-part')
.map((element) => element.attr('id').str())
.filter((id) => typeof id === 'string');
}
/** Returns an array of part names in the score in the order they appear. Part names can be duplicated. */
getPartDetails() {
const result = new Array();
for (const scorePart of this.element.all('score-part')) {
const id = scorePart.attr('id').withDefault('').str();
const name = scorePart.first('part-name')?.content().str() ?? '';
result.push({ id, name });
}
return result;
}
/** Returns an array of parts in the order they appear. */
getParts() {
return this.element.all('part').map((element) => new part_1.Part(element));
}
/** Returns the defaults of the score. */
getDefaults() {
const defaults = this.element.first('defaults');
return defaults ? new defaults_1.Defaults(defaults) : null;
}
/** Returns the title of the score */
getTitle() {
return this.element.first('movement-title')?.content().str()?.trim() ?? '';
}
}
exports.ScorePartwise = ScorePartwise;