set min/max for tone generation

master
Matthew Huntington 1 year ago
parent 3dc6ffcd76
commit cc8f0986ab

@ -1,17 +1,22 @@
const lowest = 27.5
const highest = 4186
const range = highest - lowest
const generateButton = document.querySelector('#generate-tone > button:nth-of-type(1)') const generateButton = document.querySelector('#generate-tone > button:nth-of-type(1)')
const playButton = document.querySelector('#generate-tone > button:nth-of-type(2)') const playButton = document.querySelector('#generate-tone > button:nth-of-type(2)')
const stopButton = document.querySelector('#generate-tone > button:nth-of-type(3)') const stopButton = document.querySelector('#generate-tone > button:nth-of-type(3)')
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 maxInput = document.querySelector('#generate-tone input:nth-of-type(2)')
const synth = new Tone.Synth().toDestination() const synth = new Tone.Synth().toDestination()
let newTone let newTone
let lowest = 27.5
let highest = 4186
minInput.setAttribute('placeholder', lowest)
maxInput.setAttribute('placeholder', highest)
generateButton.addEventListener('click', () => { generateButton.addEventListener('click', () => {
Tone.start() Tone.start()
newTone = Math.random() * range + lowest newTone = (Math.random() * (highest - lowest)) + lowest
toneDisplay.innerHTML = newTone toneDisplay.innerHTML = newTone
}) })
@ -23,3 +28,10 @@ stopButton.addEventListener('click', ()=>{
synth.triggerRelease() synth.triggerRelease()
}) })
minInput.addEventListener('change', ()=>{
lowest = parseFloat(minInput.value)
})
maxInput.addEventListener('change', ()=>{
highest = parseFloat(maxInput.value)
})

@ -15,6 +15,8 @@
<dt>Tone:</dt> <dt>Tone:</dt>
<dd></dd> <dd></dd>
</dl> </dl>
<input type="number" />
<input type="number" />
<button>Generate Tone</button> <button>Generate Tone</button>
<button>Play</button> <button>Play</button>
<button>Stop</button> <button>Stop</button>

Loading…
Cancel
Save