snap to note checkbox

master
Matthew Huntington 1 year ago
parent 20cedb1d52
commit b48b5a24de

@ -1,7 +1,6 @@
const generateToneButton = document.querySelector('#generate-tone > button:nth-of-type(1)') 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(2)')
const playButton = document.querySelector('#generate-tone > button:nth-of-type(3)') const stopButton = document.querySelector('#generate-tone > button:nth-of-type(3)')
const stopButton = document.querySelector('#generate-tone > button:nth-of-type(4)')
const toneDisplay = document.querySelector('#generate-tone dd') const toneDisplay = document.querySelector('#generate-tone dd')
const minInput = document.querySelector('#generate-tone input:nth-of-type(1)') const minInput = document.querySelector('#generate-tone input:nth-of-type(1)')
const maxInput = document.querySelector('#generate-tone input:nth-of-type(2)') const maxInput = document.querySelector('#generate-tone input:nth-of-type(2)')
@ -31,18 +30,17 @@ maxInput.setAttribute('placeholder', highest)
generateToneButton.addEventListener('click', () => { generateToneButton.addEventListener('click', () => {
Tone.start() Tone.start()
if(!document.querySelector('[type="checkbox"]').checked) {
const minFreq = teoria.note(lowest).fq() const minFreq = teoria.note(lowest).fq()
const maxFreq = teoria.note(highest).fq() const maxFreq = teoria.note(highest).fq()
newTone = (Math.random() * (maxFreq - minFreq)) + minFreq newTone = (Math.random() * (maxFreq - minFreq)) + minFreq
toneDisplay.innerHTML = newTone
})
generateNoteButton.addEventListener('click', () => { } else {
Tone.start()
const lowOctave = parseInt(lowest.charAt(lowest.length - 1)) * 12 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 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 highNote = notes.findIndex(enharmonics => enharmonics.includes(highest.substring(0, highest.length-1)))
const lowPitch = lowOctave + lowNote const lowPitch = lowOctave + lowNote
@ -57,6 +55,7 @@ generateNoteButton.addEventListener('click', () => {
newTone = notes[randomPitchNote][0] + randomPitchOctave newTone = notes[randomPitchNote][0] + randomPitchOctave
newTone = teoria.note(newTone).fq() newTone = teoria.note(newTone).fq()
}
toneDisplay.innerHTML = newTone toneDisplay.innerHTML = newTone
}) })

@ -24,8 +24,9 @@
</dl> </dl>
<input type="text" /> <input type="text" />
<input type="text" /> <input type="text" />
<label>Snap to notes</label>
<input type="checkbox"/>
<button>Generate Tone</button> <button>Generate Tone</button>
<button>Generate Note</button>
<button>Play</button> <button>Play</button>
<button>Stop</button> <button>Stop</button>
</section> </section>

Loading…
Cancel
Save