I'm trying to play a sample in Tone.js and have it quantized to the global transport.
Here's my code:
// global bpm
Tone.Transport.bpm.value = 125;
// declare sounds
const sampler = new Tone.Sampler({
"C3" : "./sounds/mainloop.mp3",
"D3" : "./sounds/909CLAP.wav",
}).toMaster();
// declare all elements
const startBtn = document.querySelector('.start-btn');
const playLoopBtn = document.querySelector('.play-loop-btn');
const playClapBtn = document.querySelector('.play-clap-btn');
// quantize playback to transport ???
startBtn.addEventListener('click', ()=>{
Tone.Transport.toggle();
sampler.triggerAttackRelease('C3', '16m', '@16n');
});
playClapBtn.addEventListener('click', ()=>{
sampler.triggerAttackRelease('D3', '8n', '@16n');
})
Right now what is happening is the Clap is able to be played in 16th notes, but it is starting in a different spot than the mainloop.mp3. I want the mainloop.mp3 and 909CLAP.wav to be aligned so that I can play the 909CLAP.wav perfectly on the 16th notes of mainloop.mp3.
Any help would be appreciated!