SoundCipher sc = new SoundCipher(this);
float lastMouseX, lastMouseY;
int ELECTRIC_GUITAR = 27;
void setup() {
frameRate(60);
size (480, 360);
ellipseMode(CENTER);
noStroke();
background(255);
textAlign(CENTER);
fill(0);
text("Louder", width / 2, 20);
text("Quieter", width / 2, height - 20);
text("Lower", 20, height / 2);
text("Higher", width - 20, height / 2);
text("Click to Make Sound!", width / 2, height / 2);
}
void mousePressed() {
if (lastMouseX == 0) {
lastMouseX = mouseX; //Insures last mouse position isn't undefined/0 when first ran.
lastMouseY = mouseY; //^
}
stroke(map(mouseY, 0, height, 0, 200), map(mouseX, 0, height, 0, 200), map(mouseY, 0, height, 0, 200));
line(lastMouseX, lastMouseY, mouseX, mouseY);
noStroke();
fill(map(mouseY, 0, height, 0, 200), map(mouseX, 0, height, 0, 200), map(mouseY, 0, height, 0, 200));
ellipse(mouseX, mouseY, 10, 10);
int note = (int)map(mouseX, 0, width, 22, 100); //maps note value between 22 & 100 based off mouseX
int dynamic = (int)map(mouseY, height, 0, 25, 75); //maps dynamic value between 25 & 75 based off mouseY
sc.playNote(note, dynamic, 0.5); //plays given note with specified dynamic (loudness) and duration: playNote(NOTE, DYNAMIC, DURATION)
lastMouseX = mouseX; //Updates last mouse position
lastMouseY = mouseY; //^
}