As it is, you have to keep one hand completely still while the other moves. If you only use one hand, it will only update the tone when the hand fully leaves and reenters the controller's view. I'm wondering if anyone can tell me why this is happening, and what I can do to make it update with the hand's position consistently.
Here's the code:
Code: Select all
import processing.sound.*;
import de.voidplus.leapmotion.*;
LeapMotion leap;
ArrayList<PVector> points;
PVector fp;
float freq;
float amp;
TriOsc tri;
SinOsc sin;
SqrOsc sqr;
SawOsc saw;
void setup () {
size(640,800);
leap = new LeapMotion(this);
points = new ArrayList<PVector>();
tri = new TriOsc(this);
sin = new SinOsc(this);
sqr = new SqrOsc(this);
saw = new SawOsc(this);
}
void leapOnInit() {
// println("Leap Motion Init");
}
void leapOnConnect() {
// println("Leap Motion Connect");
}
void leapOnFrame() {
// println("Leap Motion Frame");
}
void leapOnDisconnect() {
// println("Leap Motion Disconnect");
}
void leapOnExit() {
// println("Leap Motion Exit");
}
void draw() {
tri.freq(freq);
tri.amp(amp);
tri.play();
for (Hand hand : leap.getHands()) {
fp = hand.getPosition();
if (fp.z <= 30) {
points = new ArrayList<PVector>();
}
else if (fp.z > 30) {
points.add(new PVector(fp.x, fp.y));
}
}
for (int i = points.size()-1; i >= 0; i--) {
PVector p = points.get(i);
amp = map(width-p.x, 0, width, 1, .01); //Volume based on x-axis
freq = map(height-p.y, 0, height, 40, 880); //Pitch based on y-axis
}
}