Now I want to make when use key play the music if the leap motion move to right square will output Right,contrary be wrong. How can I do that?
Here is my code.
import com.onformative.leap.*;
import com.leapmotion.leap.Finger;
import ddf.minim.*;
LeapMotionP5 leap;
Minim minim;
/////////////////// here is + music
AudioPlayer Bongo;
AudioPlayer cello;
AudioPlayer drumset;
AudioPlayer flute;
AudioPlayer Guitar;
AudioPlayer handbells;
AudioPlayer harmonica;
AudioPlayer Harp;
AudioPlayer marimba;
AudioPlayer oboe;
AudioPlayer piano;
AudioPlayer saxphone;
AudioPlayer Trombone;
AudioPlayer trumpet;
AudioPlayer Tuba;
AudioPlayer violin;
void setup()
{
size(1280, 720, P3D);
minim = new Minim(this);
leap = new LeapMotionP5(this);
Bongo = minim.loadFile("Bongo.wav");
cello = minim.loadFile("cello.wav");
drumset = minim.loadFile("drumset.wav");
flute = minim.loadFile("flute.wav");
Guitar = minim.loadFile("Guitar.wav");
handbells = minim.loadFile("handbells.wav");
harmonica = minim.loadFile("harmonica.wav");
Harp = minim.loadFile("Harp.wav");
marimba = minim.loadFile("marimba.wav");
oboe = minim.loadFile("oboe.wav");
piano = minim.loadFile("piano.wav");
saxphone = minim.loadFile("saxphone.wav");
Trombone = minim.loadFile("Trombone.wav");
trumpet = minim.loadFile("trumpet.wav");
Tuba = minim.loadFile("Tuba.wav");
violin = minim.loadFile("violin.wav");
}
void draw() {
background(200, 200, 200);
text("Press r to reset.", 10, 20 );
fill (255);
for (Finger f : leap.getFingerList()) {
PVector position = leap.getTip(leap.getFinger(1));
if (position.x > 250 && position.x <400 && position.y > 150 && position.y < 250)
{
Bongo.play();
} else
Bongo.pause();
if (position.x > 650 && position.x <800 && position.y > 150 && position.y < 250) {
cello.play();
} else
cello.pause();
if (position.x > 1050 && position.x <1200 && position.y > 150 && position.y < 250) {
drumset.play();
} else
drumset.pause();
if (position.x > 1450 && position.x <1600 && position.y > 150 && position.y < 250) {
flute.play();
} else
flute.pause();
if (position.x > 250 && position.x <400 && position.y > 350 && position.y < 500) {
Guitar.play();
} else
Guitar.pause();
if (position.x > 650 && position.x <800 && position.y > 350 && position.y < 500) {
handbells.play();
} else
handbells.pause();
if (position.x > 1050 && position.x <1200 && position.y > 350 && position.y < 500) {
harmonica.play();
} else
harmonica.pause();
if (position.x > 1450 && position.x <1600 && position.y > 350 && position.y < 500) {
Harp.play();
} else
Harp.pause();
if (position.x > 250 && position.x <400 && position.y > 550 && position.y < 750) {
marimba.play();
} else
marimba.pause();
if (position.x > 650 && position.x <800 && position.y > 550 && position.y < 750) {
oboe.play();
} else
oboe.pause();
if (position.x > 1050 && position.x <1200 && position.y > 550 && position.y < 750) {
piano.play();
} else
piano.pause();
if (position.x > 1450 && position.x <1600 && position.y > 550 && position.y < 750) {
saxphone.play();
} else
saxphone.pause();
if (position.x > 250 && position.x <400 && position.y > 750 && position.y < 950) {
Trombone.play();
} else
Trombone.pause();
if (position.x > 650 && position.x <800 && position.y > 750 && position.y < 950) {
trumpet.play();
} else
trumpet.pause();
if (position.x > 1050 && position.x <1200 && position.y > 750 && position.y < 950) {
Tuba.play();
} else
Tuba.pause();
if (position.x > 1450 && position.x <1600 && position.y > 750 && position.y < 950) {
violin.play();
} else
violin.pause();
stroke(0);
strokeWeight(5);
ellipse(position.x, position.y, 20, 20);
}
// Here is draw 16 square
stroke(0, 0, 0); // square
strokeWeight(5);
fill(255, 255, 255);
rect(250, 100, 150, 150);
fill(255, 255, 255);
rect(650, 100, 150, 150);
fill(255, 255, 255);
rect(1050, 100, 150, 150);
fill(255, 255, 255);
rect(1450, 100, 150, 150);
//-----------------------------------------------------------
fill(255, 255, 255);
rect(250, 350, 150, 150);
fill(255, 255, 255);
rect(650, 350, 150, 150);
fill(255, 255, 255);
rect(1050, 350, 150, 150);
fill(255, 255, 255);
rect(1450, 350, 150, 150);
//-----------------------------------------------------------
fill(255, 255, 255);
rect(250, 600, 150, 150);
fill(255, 255, 255);
rect(650, 600, 150, 150);
fill(255, 255, 255);
rect(1050, 600, 150, 150);
fill(255, 255, 255);
rect(1450, 600, 150, 150);
//-----------------------------------------------------------
fill(255, 255, 255);
rect(250, 850, 150, 150);
fill(255, 255, 255);
rect(650, 850, 150, 150);
fill(255, 255, 255);
rect(1050, 850, 150, 150);
fill(255, 255, 255);
rect(1450, 850, 150, 150);
}
void keyPressed()
{
if ( key == 'r' ) {
Bongo.rewind();
cello.rewind();
drumset.rewind();
flute.rewind();
Guitar.rewind();
handbells.rewind();
harmonica.rewind();
Harp.rewind();
marimba.rewind();
oboe.rewind();
piano.rewind();
saxphone.rewind();
Trombone.rewind();
trumpet.rewind();
Tuba.rewind();
violin.rewind();
if ( key == 'z' ) {
Bongo.play();
} else {
Bongo.pause();
}
if ( key == 'x' ) {
cello.play();
} else {
cello.pause();
}
if ( key == 'c' ) {
drumset.play();
} else {
drumset.pause();
}
if ( key == 'v' ) {
flute.play();
} else {
flute.pause();
}
if ( key == 'b' ) {
Guitar.play();
} else {
Guitar.pause();
}
if ( key == 'n' ) {
handbells.play();
} else {
handbells.pause();
}
if ( key == 'm' ) {
harmonica.play();
} else {
harmonica.pause();
}
if ( key == 'a' ) {
Harp.play();
} else {
Harp.pause();
}
if ( key == 's' ) {
marimba.play();
} else {
marimba.pause();
}
if ( key == 'd' ) {
oboe.play();
} else {
oboe.pause();
}
if ( key == 'f' ) {
piano.play();
} else {
piano.pause();
}
if ( key == 'g' ) {
saxphone.play();
} else {
saxphone.pause();
}
if ( key == 'h' ) {
Trombone.play();
} else {
Trombone.pause();
}
if ( key == 'j' ) {
trumpet.play();
} else {
trumpet.pause();
}
if ( key == 'k' ) {
Tuba.play();
} else {
Tuba.pause();
}
if ( key == 'l' ) {
violin.play();
} else {
violin.pause();
}
}
}