xxxxxxxxxx
46
let startButton;
let stopButton;
Tone.Transport.bpm.value = 120;
let noteText;
// "random", "up","down"
const pattern = new Tone.Pattern(
(time, note) => {
monoSynth.triggerAttackRelease(note, "16n", time);
noteText = note;
},
["C2", "D4", "E5", "A6"],
"upDown"
).start(0);
pattern.interval = "16n";
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(noteText, width / 2 - 10, height / 2);
}
function startTransport() {
Tone.start();
// start the transport
Tone.Transport.start();
}
function stopTransport() {
// stop the transport
Tone.Transport.stop();
}