#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Using LEAP motion - Controlling sound with two different hands

edited March 2017

We are using the code of someone else https://forum.processing.org/two/discussion/20409/newbie-seeking-help-re-combining-example-code-using-a-leapmotion

What we would like to do is having your left AND your right hand control two seperate sounds and their frequency's. We are thinking of dividing the screen in two halves. And changing everything that's X axis to pitch the frequency into Z axis. And we need to let a seperate code of tone and frequency correspond with the right hand.

I'm not sure where to begin to tackle this problem, we highly appreciate it if there is someone who can give us any advice on where to look to solve this problem :)

Tagged:

• Thanks :) Got everything working now!

• Great! Could you post your solution if you don't mind please?

Kf

• No problem. This is how our code works, it's a bit of an adaption, using the example as inspiration, but build from scratch.

import de.voidplus.leapmotion.*; import processing.sound.*;

LeapMotion leap; SinOsc sine; Hand leftHand; Hand rightHand;

float freq; float amp; float pos; PVector hL; PVector hR;

void setup() { size(displayWidth, 700);

leap = new LeapMotion(this); sine = new SinOsc(this);

//Start the Sine Oscillator. sine.play(); sine.amp(amp); }

void draw() { background(255); smooth();

for (Hand hand : leap.getHands()) { boolean handIsLeft = hand.isLeft(); boolean handIsRight = hand.isRight();

``````leftHand = leap.getLeftHand();
hL   = leftHand.getPosition();
rightHand = leap.getRightHand();
hR   = rightHand.getPosition();
//----------------------- LEFT HAND ----------------------------------

if (handIsLeft) {
text("leftHand-X=" +hL.x, 10, 15); //shows hL.x in sketch
text("leftHand-Y=" +hL.y, 10, 30); //shows hL.y in sketch
text("leftHand-Z=" +hL.z, 10, 45); //shows hL.z in sketch
text("volume(in %)= " +nf(amp*100, 1, -3), 10, 60);

leftHand.draw();
// Map leftHandY van 0.0 to 1.0 voor amplitude (volume)
amp=map(hL.y, 0, height, 1.0, 0.0);
}

sine.amp(amp);

//----------------------- RIGHT HAND ----------------------------------
if (handIsRight) {
text("rightHand-X= " +hR.x, width-160, 15); //shows hL.x in sketch
text("rightHand-Y= " +hR.y, width-160, 30); //shows hL.y in sketch
text("rightHand-Z= " +hR.z, width-160, 45); //shows hL.z in sketch
text("freq(in Hz)= " +nf(freq, 3, -3), width-160, 60);

rightHand.draw();
// Map rightHandX van 100Hz to 800Hz voor frequency
freq=map(hR.x, 0, width, 100.0, 800.0);
}
if (!handIsLeft && handIsRight) {
amp = 0;
}
sine.freq(freq);
``````

} }