Hand Position Not Updating As Expected - Leap Motion on Processing

Share your theremin experience: tips, tricks, techniques, favorite theremin moments.
Post Reply
CarolDelgado
Posts: 1
Joined: Sat Dec 21, 2019 5:37 am

Hand Position Not Updating As Expected - Leap Motion on Processing

Post by CarolDelgado » Mon Dec 23, 2019 5:54 am

I'm trying to make a theremin using a Leap Motion controller through Processing (Java). So far, I've come very close. I am able to make the pitch and amplitude change by keeping one hand very still over the controller, while the other moves. I was hoping to make it so that either one hand is able to do that, or the left hand controls amplitude while the right controls pitch.

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
  }
}

Post Reply