You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
743 B

const lowest = 27.5
const highest = 4186
const range = highest - lowest
const generateButton = document.querySelector('#generate-tone > button:nth-of-type(1)')
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 synth = new Tone.Synth().toDestination()
let newTone
generateButton.addEventListener('click', () => {
Tone.start()
newTone = Math.random() * range + lowest
toneDisplay.innerHTML = newTone
})
playButton.addEventListener('click', ()=>{
synth.triggerAttack(newTone)
})
stopButton.addEventListener('click', ()=>{
synth.triggerRelease()
})