vexflow-musicxml
Version:
MusicXml Parser for vexflow
103 lines (77 loc) • 3.56 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: src/xml/MusicXml.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: src/xml/MusicXml.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>// import { Vex } from 'vexflow';
import { XmlSerializer } from './XmlSerializer.js';
import { XmlObject } from './XmlObject.js';
import { MusicXmlError } from './Errors.js';
import { Identification } from './Identification.js';
import { Part } from './Part.js';
/**
* @fileOverview
* @author {@link mailto:neumann.benni@gmail.com|neumann.benni@gmail.com}
* @version 0.1
*/
export class MusicXml extends XmlObject {
constructor(xDocString) {
if (xDocString === undefined) {
super();
throw new MusicXmlError('NoInputXML', 'No XML string has been given as input file');
}
const serializer = new XmlSerializer(xDocString);
const { xDoc } = serializer;
super(xDoc.getElementsByTagName('score-partwise')[0]);
this.Version = this.getAttribute('version');
this.Identification = undefined;
if (this.childExists('identification')) {
this.Identification = new Identification(this.getChild('identification'));
}
this.Title = this.getText('movement-title');
const parts = this.getChildren('part');
const partInfo = this.getChildren('part-list')[0];
const names = partInfo.getElementsByTagName('part-name');
this.Parts = [...parts].map(p => new Part(p));
this.Parts.forEach((p, i) => { p.Name = names[i].textContent; });
}
getMeasuresFromPart(partNumber) {
if (partNumber >= this.Parts.length) {
throw new MusicXmlError('PartOutOfBounds', 'The part item you are trying to get is out of bounds');
}
return this.Parts[partNumber].Measures;
}
getStavesPerSystem() {
return this.Parts
.map(p => p.getAllStaves()) // get all the staves in a part
.reduce((e, ne) => e + ne); // sum them up
}
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Test.html">Test</a></li></ul><h3>Classes</h3><ul><li><a href="ClefVisitor.html">ClefVisitor</a></li><li><a href="Key_Key.html">Key</a></li><li><a href="KeyVisitor.html">KeyVisitor</a></li><li><a href="Measure.html">Measure</a></li><li><a href="MeasureVisitor.html">MeasureVisitor</a></li><li><a href="MusicXmlRenderer.html">MusicXmlRenderer</a></li><li><a href="Note.html">Note</a></li><li><a href="NoteVisitor.html">NoteVisitor</a></li><li><a href="Part.html">Part</a></li><li><a href="TimeSignatureVisitor.html">TimeSignatureVisitor</a></li><li><a href="TimeVisitor.html">TimeVisitor</a></li><li><a href="XmlObject.html">XmlObject</a></li><li><a href="XmlSerializer_XmlSerializer.html">XmlSerializer</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Nov 20 2017 21:30:34 GMT+0100 (CET)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>