xxxxxxxxxx
41
let startButton;
let stopButton;
const notes = ["C3", "D3", "G3", "A3", "C4", "D4", "E4", "G4", "A4", "C5", "G5"];
let note;
let randomNum;
let offset = 0;
Tone.Transport.bpm.value = 120;
const myLoop = new Tone.Loop((time) => {
note = notes[randomNum]
monoSynth.triggerAttackRelease(note, "16n", time);
}, "16n").start(0);
function setup() {
createCanvas(400, 400);
startButton = createButton("start transport");
stopButton = createButton("stop transport");
startButton.mousePressed(startTransport);
stopButton.mousePressed(stopTransport);
textSize(24);
}
function draw() {
background("goldenrod");
fill(0);
text(note, width / 2 - 10, height / 2);
offset = offset + 0.03;
randomNum = floor(noise(offset) * notes.length);
}
function startTransport() {
Tone.start();
// start the transport
Tone.Transport.start();
}
function stopTransport() {
// stop the transport
Tone.Transport.stop();
}