xxxxxxxxxx
55
// Create a Player object and load the "kick.mp3" file
let kick = new Tone.Player("samples/505/kick.mp3");
// Connect the player output to the computer's audio output
kick.toMaster();
// Set the tempo to 120 beats per minute
Tone.Transport.bpm.value = 60;
// Set the time signature to 4/4.
// See documentation: https://github.com/Tonejs/Tone.js/wiki/Transport
Tone.Transport.timeSignature = [3,4];
// Changhing the time signature will not affect the sound,
// It affects the _counting_. See the console.log in the draw loop.
// Create a loop: call the function playBeat every quarter note
Tone.Transport.scheduleRepeat(playBeat, "4n");
let slider;
function setup() {
}
function draw() {
console.log(Tone.Transport.position)
// Take a look at the middle number. It corresponds to the current beat.
// Changing the time signature to 3/4 or 4/4 does not change the sound
// But it changes the counting
// 4/4 means we count 0, 1, 2, 3 beats before going to the next measure
// 3/4 means we count 0, 1, 2 before going to the next measure
// We can then use this counting to treat each beat in a measure differently
// Maybe we'll play the first beat of a measure louder (if beat == 0),
// Or maybe it will be an entirely different type of drum.
// Question: Why do we see beats repeated if they are only played once? Where should we put the console.log message if we wanted to see each beat printed only once?
}
// Audio playback loop
function playBeat(time){
// Play sound file
kick.start(time);
}
// Once all audio files have been loaded, start the Tone playhead
Tone.Buffer.on('load', start);
function start() {
Tone.Transport.start();
}