@stringsync/vexml
Version:
MusicXML to Vexflow
69 lines (68 loc) • 2.56 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.MusicXML = void 0;
const errors = __importStar(require("../errors"));
const util_1 = require("../util");
const scorepartwise_1 = require("./scorepartwise");
/**
* A wrapper around a root node that corresponds to a MusicXML document.
*
* See https://www.w3.org/2021/06/musicxml40/
*/
class MusicXML {
root;
constructor(root) {
this.root = root;
}
/**
* Returns the first <score-partwise> of the document.
*
* @throws {errors.ParseError} when the root does not contain a <score-partwise> element. It does not check for deep validity.
*/
getScorePartwise() {
const node = this.root.getElementsByTagName('score-partwise').item(0);
if (!node) {
throw new errors.ParseError('could not find a <score-partwise> element');
}
return new scorepartwise_1.ScorePartwise(util_1.NamedElement.of(node));
}
/** Returns the string representation of the document. */
getDocumentString() {
const serializer = new XMLSerializer();
return serializer.serializeToString(this.root);
}
}
exports.MusicXML = MusicXML;