The assignment is to create four ellipses that each have a different sound, and to make the code run so that each ellipse plays its sound when clicked (mousepressed). I have managed to get the top two ellipses to work; however, I cannot get the other two to work so I would really appreciate some help. (Down at the very end with my if/else if/else statements).
// import Minim
import ddf.minim.*;
Minim minim;
AudioSample d1;
AudioSample d2;
AudioSample d3;
AudioSample d4;
AudioOutput out;
// track when a drum has been struck
boolean drum1struck;
boolean drum2struck;
boolean drum3struck;
boolean drum4struck;
void setup() {
// initialize the screen
size(400, 400);
smooth();
// initialize sound
minim = new Minim(this);
out = minim.getLineOut();
d1 = minim.loadSample("bongo1.wav");
d2 = minim.loadSample("bongo7.wav");
d3 = minim.loadSample("tom1.wav");
d4 = minim.loadSample("tom2.wav");
// set boolean variables to initialize the graphics
drum1struck = false;
drum2struck = false;
drum3struck = false;
drum4struck = false;
}
void draw() {
background(255);
// draw the drums: if a drum has just been struck
// then fill its ellipse with color as visual feedback for the user
// drum 1
if (drum1struck == true) {
fill(255,0,0);
drum1struck = false;
}
else
{
fill(255);
}
ellipse(50, 55, 100, 100);
// drum 2
if (drum2struck == true) {
fill(255,0,0);
drum2struck = false;
} else {
fill(255);
}
ellipse(160, 55, 100, 100);
//drum 3
if (drum3struck == true) {
fill(255,0,0);
drum3struck = false;
}
else {
fill(255);
}
ellipse(50, 165, 100, 100);
//drum 4
if (drum4struck == true) {
fill(255,0,0);
drum4struck = false;
} else {
fill(255);
}
ellipse(160, 165, 100, 100);
}
void keyPressed() {
if (key == 'a' || key == 'A') { //note you may have to retype the
drum1struck = true; //single quote marks after copying
d1.trigger();
}
else if (key == 'b' || key == 'B') {
drum2struck = true;
d2.trigger();
}
else if (key == 'c' || key == 'C') {
drum3struck = true;
d3.trigger();
}
else if (key == 'd' || key == 'D') {
drum4struck = true;
d4.trigger();
}
}
void mousePressed() {
if (mouseX<105)
{
d1.trigger();
//set Boolean for drum1 to true
drum1struck = true;
}
else if (mouseX>105)
{d2.trigger();
//set Boolean for drum1 to true
drum2struck = true;
}
else if (mouseY<-200)
{
d3.trigger();
//set Boolean for drum1 to true
drum3struck = true;
}
else {
d4.trigger();
//set Boolean for drum1 to true
drum4struck = true;
}
}