xxxxxxxxxx
66
// Play a syncopated 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;
// Try different values between 0 and 1.
Tone.Transport.swing = 0.5;
// Try applying the swing to different subdivisions ("4n", "2n", etc).
// The default value is "16n"
// Tone.Transport.swingSubdivision = "2n";
// Create a loop: call playBeat every quarter note
// Use Tone.Loop this time (instead of scheduleRepeat)
let loop = new Tone.Loop(playBeat, "4n").start(0);
// If we set humanize to true: +/- 0.01s to the scheduled time.
// loop.humanize = true;
// Or we can give it a time value:
// loop.humanize = "0.1s";
// You can also 'humanize' the timing of your audio loop callback:
// drift by +/- a 16nth-note
// audioLoop.humanize = "1n";
// Audio playback loop
function playBeat(time) {
let beat = Tone.Transport.position.split(":")[1];
console.log(beat);
if (beat == 0) {
// Push back
kit.get("kick").start(time + Tone.Time("16n"));
// Push forward
//kit.get("kick").start(time - Tone.Time("16n"));
} 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() {
}