diff --git a/app.js b/app.js index 80ae672..da44a82 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,6 @@ const generateToneButton = document.querySelector('#generate-tone > button:nth-of-type(1)') -const generateNoteButton = document.querySelector('#generate-tone > button:nth-of-type(2)') -const playButton = document.querySelector('#generate-tone > button:nth-of-type(3)') -const stopButton = document.querySelector('#generate-tone > button:nth-of-type(4)') +const playButton = document.querySelector('#generate-tone > button:nth-of-type(2)') +const stopButton = document.querySelector('#generate-tone > button:nth-of-type(3)') const toneDisplay = document.querySelector('#generate-tone dd') const minInput = document.querySelector('#generate-tone input:nth-of-type(1)') const maxInput = document.querySelector('#generate-tone input:nth-of-type(2)') @@ -31,32 +30,32 @@ maxInput.setAttribute('placeholder', highest) generateToneButton.addEventListener('click', () => { Tone.start() - const minFreq = teoria.note(lowest).fq() - const maxFreq = teoria.note(highest).fq() - newTone = (Math.random() * (maxFreq - minFreq)) + minFreq - toneDisplay.innerHTML = newTone -}) + if(!document.querySelector('[type="checkbox"]').checked) { + + const minFreq = teoria.note(lowest).fq() + const maxFreq = teoria.note(highest).fq() + newTone = (Math.random() * (maxFreq - minFreq)) + minFreq -generateNoteButton.addEventListener('click', () => { - Tone.start() + } else { - const lowOctave = parseInt(lowest.charAt(lowest.length - 1)) * 12 - const lowNote = notes.findIndex(enharmonics => enharmonics.includes(lowest.substring(0, lowest.length-1))) - const highOctave = parseInt(highest.charAt(highest.length - 1)) * 12 - const highNote = notes.findIndex(enharmonics => enharmonics.includes(highest.substring(0, highest.length-1))) + const lowOctave = parseInt(lowest.charAt(lowest.length - 1)) * 12 + const highOctave = parseInt(highest.charAt(highest.length - 1)) * 12 + const lowNote = notes.findIndex(enharmonics => enharmonics.includes(lowest.substring(0, lowest.length-1))) + const highNote = notes.findIndex(enharmonics => enharmonics.includes(highest.substring(0, highest.length-1))) - const lowPitch = lowOctave + lowNote - const highPitch = highOctave + highNote - const pitchSpread = highPitch - lowPitch - const randomAddedPitches = Math.floor(Math.random() * (pitchSpread + 1) ) - const randomPitch = lowPitch + randomAddedPitches + const lowPitch = lowOctave + lowNote + const highPitch = highOctave + highNote + const pitchSpread = highPitch - lowPitch + const randomAddedPitches = Math.floor(Math.random() * (pitchSpread + 1) ) + const randomPitch = lowPitch + randomAddedPitches - const randomPitchOctave = Math.floor(randomPitch / 12) - const randomPitchNote = randomPitch % 12 + const randomPitchOctave = Math.floor(randomPitch / 12) + const randomPitchNote = randomPitch % 12 - newTone = notes[randomPitchNote][0] + randomPitchOctave - newTone = teoria.note(newTone).fq() + newTone = notes[randomPitchNote][0] + randomPitchOctave + newTone = teoria.note(newTone).fq() + } toneDisplay.innerHTML = newTone }) diff --git a/index.html b/index.html index 5a7da1b..8ad476b 100644 --- a/index.html +++ b/index.html @@ -24,8 +24,9 @@ + + -