xxxxxxxxxx
47
// Add a snare drum sound
// Play a kick/snare pattern
// SOUNDS
// Create a Players object and load the "kick.mp3" and "snare.mp3" files
let kit = new Tone.Players({
"kick": "samples/505/kick.mp3",
"snare": "samples/505/snare.mp3"
});
// Connect the player output to the computer's audio output
kit.toMaster();
Tone.Transport.bpm.value = 120;
// Create a loop: call playBeat every quarter note
Tone.Transport.scheduleRepeat(playBeat, "4n");
// Audio playback loop
function playBeat(time) {
let beat = Tone.Transport.position.split(":")[1];
// Try changing the time signature, and notice what happens
// How would you create a kick-snare-snare pattern?
if (beat == 0) {
kit.get("kick").start(time);
} else {
kit.get("snare").start(time);
}
}
// Once all audio files have been loaded, start the Tone playhead
Tone.Buffer.on('load', start);
function start() {
Tone.Transport.start();
}
function setup() {
}
function draw() {
}