UNPKG

vexflow-musicxml

Version:

MusicXml Parser for vexflow

94 lines (72 loc) 3.19 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: src/vex/Key.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/vex/Key.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>import Vex from 'vexflow'; const Flow = Vex.Flow; export class Key { /** * * From the docs: * Traditional key signatures are represented by the number * of flats and sharps, plus an optional mode for major/ * minor/mode distinctions. Negative numbers are used for * flats and positive numbers for sharps, reflecting the * key's placement within the circle of fifths (hence the * element name). * @param {xmlKey} Key MusicXml object to be translated * @returns {VexKey} Vex object */ constructor(xmlKey) { this.xmlKey = xmlKey; this.keySpec = []; // Create a lookup table of key names ("C", "B", etc.) that map to key objects for (const k in Flow.keySignature.keySpecs) { if ({}.hasOwnProperty.call(Flow.keySignature.keySpecs, k)) { const newEntry = Flow.keySignature.keySpecs[k]; newEntry.name = k; this.keySpec.push(newEntry); } } } get VexKey() { let filteredKeys = this.keySpec.filter(k => k.num === Math.abs(this.xmlKey.Fifths)); const mode = this.xmlKey.Mode === 'major' ? 0 : 1; if (this.xmlKey.Fifth &lt; 0) { filteredKeys = filteredKeys.filter(k => k.acc === 'b'); } else if (this.xmlKey.Fifths > 0) { filteredKeys = filteredKeys.filter(k => k.acc === '#'); } const entry = filteredKeys[mode].name; return entry; } } </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>