We want to make a project.We want to leapmotion for the recognition of the gesture into the processing, when the fingers across different areas of different sounds, when the fingers leave the area will not have a sound, but the finger into the area again will be issued a sound. But we now no matter how many times the fingers across the region, the sound only play once. But add loop function and pause function, will lead to the sound of can't stop,always loop.
We are very grateful to you for taking the time to look at our program.
Here's our code:
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector []pos=new PVector[10];
AudioPlayer player,player1,player2,player3,player4,player5,player6;
Minim minim;
void setup(){
size(700,700);
smooth();
leap = new LeapMotion(this);
minim = new Minim(this);
player = minim.loadFile("c.mp3",1024);
player1 = minim.loadFile("d.mp3",1024);
player2 = minim.loadFile("e.mp3",1024);
player3 = minim.loadFile("f.mp3",1024);
player4 = minim.loadFile("g.mp3",1024);
player5 = minim.loadFile("a.mp3",1024);
player6 = minim.loadFile("b.mp3",1024);
for(int i=0;i<10;i++) pos[i]=new PVector(0,0,0);
}
void draw(){
background(255);
//*************get finger******************************
for(Hand hand : leap.getHands()){
Finger finger_index = hand.getIndexFinger();
pos[0]=finger_index.getPosition();
if(pos!=null){
for(int i=9;i>0;i--){
strokeWeight(5);
stroke(150,150,255);
line(pos[i].x,pos[i].y,pos[i-1].x,pos[i-1].y);
pos[i]=pos[i-1];
}
fill(150,50,255);
ellipse(pos[0].x,pos[0].y,15,15);
//*********voide play**********************************
switch (int(pos[0].y/100)){
case 0 :
player.loop();
break;
case 1 :
player1.loop();
if ( player1.isPlaying()&&pos==null )
{
player1.pause();
}
else
{
player1.loop();
}
break;
case 2 :
player2.loop();
break;
case 3 :
player3.loop();
break;
case 4 :
player4.loop();
break;
case 5 :
player5.loop();
break;
case 6 : player6.loop();
break;
}
}
}
}
}