diff --git a/app.js b/app.js index f98ca4e..c277b92 100644 --- a/app.js +++ b/app.js @@ -11,7 +11,20 @@ const synth = new Tone.Synth().toDestination() let newTone let lowest = 'a0' let highest = 'c8' -const notes = ['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'a#', 'b' ] +const notes = [ + ['c'], + ['c#','db'], + ['d'], + ['d#', 'eb'], + ['e'], + ['f'], + ['f#','gb'], + ['g'], + ['g#', 'ab'], + ['a'], + ['a#', 'bb'], + ['b'] +] minInput.setAttribute('placeholder', lowest) maxInput.setAttribute('placeholder', highest) @@ -28,9 +41,9 @@ generateNoteButton.addEventListener('click', () => { Tone.start() const lowOctave = parseInt(lowest.charAt(1)) * 12 - const lowNote = notes.indexOf(lowest.charAt(0)) + const lowNote = notes.findIndex(enharmonics => enharmonics.includes(lowest.charAt(0))) const highOctave = parseInt(highest.charAt(1)) * 12 - const highNote = notes.indexOf(highest.charAt(0)) + const highNote = notes.findIndex(enharmonics => enharmonics.includes(highest.charAt(0))) const lowPitch = lowOctave + lowNote const highPitch = highOctave + highNote @@ -41,7 +54,7 @@ generateNoteButton.addEventListener('click', () => { const randomPitchOctave = Math.floor(randomPitch / 12) const randomPitchNote = randomPitch % 12 - newTone = notes[randomPitchNote] + randomPitchOctave + newTone = notes[randomPitchNote][0] + randomPitchOctave toneDisplay.innerHTML = newTone })