xxxxxxxxxx
56
//"ah" vocal samples limited to the pentatonic scale
//pitch controlled by mouse
let h;
let y;
let noteY;
let prevNoteY;
let n=6;
let notes = [];
let tone;
function preload() {
for(i=0;i<6;i++){
let array = [str(i+1),'wav'];
let separator = '.';
let file = join(array, separator);
// file=str(i)
//console.log(file);
notes[i]=loadSound(file);
}
console.log(notes);
}
function setup() {
createCanvas(800, 600);
h=height/n;
tone=notes[0];
}
function draw() {
background(100);
strokeWeight(4);
stroke(25,10,40);
for (i=0;i<n;i++) {
line(0,i*h,width,i*h);
}
y=map(mouseY,height,0,1,6);
noteY=round(y);
//console.log(y);
noStroke();
fill(200,0,220)
ellipse(mouseX,h+(height)-noteY*h-h/2,h,h)
if(noteY!=prevNoteY) {
playTone();
}
prevNoteY=noteY;
}
function playTone() {
tone.stop();
tone=notes[noteY-1];
tone.play();
}