xxxxxxxxxx
39
let osc;
// change notes for scale
// Add 12 to each note to bring it up an octave then put that note at the end
let notes = [60, 64, 66, 67, 71,72];
function setup() {
createCanvas(400, 400);
osc = new p5.Oscillator();
}
function draw() {
background(220);
let numRects = notes.length;
let rectWidth = width / numRects; // change width to height
for (let i = 0; i < numRects; i++) {
fill("white");
// change mouseX to mouseY
if (mouseX > i * rectWidth && mouseX < i * rectWidth + rectWidth) {
fill("red");
let noteFreq = midiToFreq(notes[i]);
osc.freq(noteFreq);
}
// rearrange arguments to align rectangles vertically
rect(i * rectWidth, 0, rectWidth, height);
}
}
function mousePressed() {
osc.start();
}
function mouseReleased() {
osc.stop();
}