UNPKG

react-orchestra

Version:

A toolbox to build interactive and smart instruments on the web and mobile.

99 lines (79 loc) 4.25 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: helpers/getScaleNotes.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: helpers/getScaleNotes.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/* mod */ import reOrderNotes from './reOrderNotes'; import isInHigherOctave from './isInHigherOctave'; import SCALES from '../constants/SCALES'; import NOTES from '../constants/NOTES'; /** * getScaleNotes - Get notes for a given scale for _count_ octaves at _startOctave_ * * @param {string} note noteName without octave * @param {string} scale scaleName must be one defined in constants/SCALES * @param {number} startOctave starting octave * @param {number} count Number of octaves * @returns {array} Array of note names with octave */ const getScaleNotes = (note, scale, startOctave, count) => { const startingNoteIndex = NOTES.indexOf(note); if (startingNoteIndex === -1) { throw new Error('NOTE IS NOT RECOGNIZED'); } if (SCALES[scale] == null) { throw new Error('SCALE IS NOT RECOGNIZED'); } const scaleSequence = SCALES[scale].sequence; const notes = reOrderNotes(note); const scaleNotes = scaleSequence.map(interval => notes[interval]); // scaleNotes = Musician.reOrderNotes('C', scaleNotes); let currentOctave = startOctave; let scaleNotesWithInterval = []; for (let i = startOctave; i &lt; startOctave + count; i += 1) { let previousNote = scaleNotes[0]; const currentNotes = scaleNotes.map((currentNote, j) => { if (j === 0 &amp;&amp; i === startOctave) { previousNote = currentNote; return `${currentNote}${currentOctave}`; } if (isInHigherOctave(previousNote, currentNote)) { currentOctave += 1; } previousNote = currentNote; return `${currentNote}${currentOctave}`; }); scaleNotesWithInterval = [...scaleNotesWithInterval, ...currentNotes]; } return scaleNotesWithInterval; }; export default getScaleNotes; </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Instrument.html">Instrument</a></li><li><a href="Note.html">Note</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addOctaveToNoteName">addOctaveToNoteName</a></li><li><a href="global.html#getInterval">getInterval</a></li><li><a href="global.html#getIntervalPermutationsFromNoteNames">getIntervalPermutationsFromNoteNames</a></li><li><a href="global.html#getJSONFromMidiURL">getJSONFromMidiURL</a></li><li><a href="global.html#getNoteNamesFromChordName">getNoteNamesFromChordName</a></li><li><a href="global.html#getNoteNamesFromIntervals">getNoteNamesFromIntervals</a></li><li><a href="global.html#getScaleNotes">getScaleNotes</a></li><li><a href="global.html#getScalesFromNoteNames">getScalesFromNoteNames</a></li><li><a href="global.html#getTracksAndMetaFromParsedMidi">getTracksAndMetaFromParsedMidi</a></li><li><a href="global.html#getTracksAndMetaFromUrl">getTracksAndMetaFromUrl</a></li><li><a href="global.html#getUniqueNoteNames">getUniqueNoteNames</a></li><li><a href="global.html#getUniqueNoteNamesNoOctave">getUniqueNoteNamesNoOctave</a></li><li><a href="global.html#isInHigherOctave">isInHigherOctave</a></li><li><a href="global.html#removeOctaveFromNoteName">removeOctaveFromNoteName</a></li><li><a href="global.html#reOrderNotes">reOrderNotes</a></li><li><a href="global.html#updateTempo">updateTempo</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Sun Nov 20 2016 16:43:09 GMT+0200 (EET) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>