Newbie here, I'm trying to make a Javascript metronome, but I'm stuck on making the sound play according to the current bpm of the project
Here's where I think the problem lies, when I press play, it sounds, but in a fixed bpm, that is not the one being inputted in the bpm variable:
//VARIABLES
let bpm = 150;
let soundInterval = (60/bpm)*1000;
//FUNCTIONS
//START METRONOME
let startStopMetronome = startButton.addEventListener('click', () => {
startMetronome(soundInterval);
})
function startMetronome(si) {
setTimeout(() => {
primaryBeat.play();
startMetronome(si);
},si);
}
UPDATE:
I´ve tried making the soundInterval
update with a function, but it still does the same, and plays the same fixed interval no matter the bpm changes
//VARIABLES
let bpm = 150;
let soundInterval;
//FUNCTIONS
//START METRONOME
let startStopMetronome = startButton.addEventListener('click', () => {
soundInterval = calculateSoundInterval();
startMetronome(soundInterval);
})
function startMetronome(si) {
setTimeout(() => {
primaryBeat.play();
startMetronome(si);
},si);
}
let calculateSoundInterval = () => {
return (60/bpm)*1000;
}
let updateBpmInDisplay = display.addEventListener('change', ()=> {
soundInterval = calculateSoundInterval();
})