xxxxxxxxxx
25
const notes = [60, 67, 68, 67]; // Put your sequence of notes here
let i = 0;
let octave = 0;
function setup() {
osc = new p5.Oscillator('sawtooth'); // Also try sine, triangle, square
frameRate(3); // Change the “tempo” if you like
}
function draw() {
if (frameCount == 1)
osc.start(0);
const note = notes[i] + (octave + 1) * 12;
const freq = midiToFreq(note);
osc.freq(freq);
i = (i + 1) % notes.length;
}
function keyPressed() {
if (key == 'ArrowUp')
++octave;
else if (key == 'ArrowDown')
--octave;
}