UNPKG

vexflow-musicxml

Version:

MusicXml Parser for vexflow

129 lines (105 loc) 4.09 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: src/xml/Part.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/Part.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>import { XmlObject } from './XmlObject.js'; import { Attributes } from './Attributes.js'; import { Measure } from './Measure.js'; /** * Class representation of a part * @extends XmlObject */ export class Part extends XmlObject { /** * Create a part from an XML node * @param {NodeObject} node - the XML Node representing the part */ constructor(node) { super(node); const measures = this.getChildren('measure'); this.Measures = []; this.Id = parseInt(this.getAttribute('id').match(/[0-9]+/)[0], 10); let lastAttributes = new Attributes(this.Node.getElementsByTagName('attributes')[0]); for (let m = 0; m &lt; measures.length; m++) { const options = { lastAttributes, part: this.Id, }; const curMeasure = new Measure(measures[m], options); if (m > 0) { curMeasure.lastMeasure = this.Measures[m - 1]; } this.Measures.push(curMeasure); lastAttributes = curMeasure.Attributes; } } /** * Get the number of all staves in all measures * * @returns {Array} Array of staves in measure */ getAllStaves() { return this.Measures[0].getStaves(); } /** * Get all clefs in all measure * * @returns {Array} Array of clefs in all measures */ getAllClefs() { return this.Measures.map(m => m.getAllClefs()); } /** * Get all the notes belonging to the given staff. The staff number * can be retrieved from {@link getStaves} * @param {Number} Number of the staff. * @returns {Note} A Note class object * @see {@link getStaves} */ getNotesByStaff(index) { const a = []; this.Measures.map(key => a.push(...this.Measures[key].getNotesByStaff(index))); // for (var key in this.Measures) { // a.push(...this.Measures[key].getNotesByStaff(index)); // } return a; } /** * Gets all measures that have keys. This can be used for checking if we still * have the same keys as in the measure before * @deprecated This function will always return all measures because all measures have attributes (with keys) * @returns {Key} A Key class object */ getAllMeasuresWithKeys() { return this.Measures.filter(m => m.Attributes.Key !== undefined); } } </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>