Code viewer for World: midi keyboard
var osc;
var pitch = 0;
var vol = 0.05;
var note = 0; // Start at C4

function setup() {
 createCanvas(650, 400);

 osc = new p5.Oscillator(0,'square');
 osc.start();

}


function draw() {
 background(220);

 fill(250);
 rect(0, 0, 50, 400); //C4
 rect(100, 0, 50, 400);//D4
 rect(200, 0, 50, 400);//E4
 rect(250, 0, 50, 400);//F4
 rect(350, 0, 50, 400);//G4
 rect(450, 0, 50, 400);//A4
 rect(550, 0, 50, 400);//B4
 rect(600, 0, 50, 400);//C5
  
 fill(0);
 rect(50, 0, 50, 400);//C#4
 rect(150, 0, 50, 400);//D#4
 rect(300, 0, 50, 400);//F#4
 rect(400, 0, 50, 400);//G#4
 rect(500, 0, 50, 400);//A#4
 
 fill(0);
 textSize(30);
  
 text('C4',5,350)
 text('D4',105,350)
 text('E4',205,350)
 text('F4',255,350)
 text('G4',355,350)
 text('A4',455,350)
 text('B4',555,350)
 text('C5',605,350)
  
 fill(255);
 text('C#4',50,350)
 text('D#4',150,350)
 text('F#4',300,350)
 text('G#4',400,350)
 text('A#5',500,350)
  
  
  
 if (mouseX < 50 && mouseX > 1) {
  note = 60;
  print("This is C4");
  fill(52,155,235);
  rect(0, 0, 50, 400);
 }else if (mouseX< 100){
  note = 61;
  print("This is C#4");
  fill(52,155,235);
  rect(50, 0, 50, 400);
 }else if (mouseX< 150){
  note = 62;
  print("This is D4");
  fill(52,155,235);
  rect(100, 0, 50, 400);
 }else if (mouseX< 200){
  note = 63;
  print("This is D#4");
  fill(52,155,235);
  rect(150, 0, 50, 400);
 }else if (mouseX< 250){
  note = 64;
  print("This is E4");
  fill(52,155,235);
  rect(200, 0, 50, 400);
 }else if (mouseX< 300){
  note = 65;
  print("This is F4");
  fill(52,155,235);
  rect(250, 0, 50, 400);
 }else if (mouseX< 350){
  note = 66;
  print("This is F#4");
  fill(52,155,235);
  rect(300, 0, 50, 400);
 }else if (mouseX< 400){
  note = 67;
  print("This is G4");
  fill(52,155,235);
  rect(350, 0, 50, 400);
 }else if (mouseX< 450){
  note = 68;
  print("This is G#4");
  fill(52,155,235);
  rect(400, 0, 50, 400);
 }else if (mouseX< 500){
  note = 69;
  print("This is A4");
  fill(52,155,235);
  rect(450, 0, 50, 400);
 }else if (mouseX< 550){
  note = 70;
  print("This is A#4");
  fill(52,155,235);
  rect(500, 0, 50, 400);
 }else if (mouseX< 600){
  note = 71;
  print("This is B4");
  fill(52,155,235);
  rect(550, 0, 50, 400);
 }else if (mouseX< 650){
  note = 72;
  print("This is C5");
  fill(52,155,235);
  rect(600, 0, 50, 400);
 }

  
 pitch = midiToFreq(note);
 osc.freq(pitch);
 osc.amp(0);
  
  
  if (mouseIsPressed) {
  osc.amp(0.1);
 } else {
  osc.amp(0)
 }

}