Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
balandinodidonato committed May 26, 2017
2 parents 1dfa5e3 + f682196 commit e65a46d
Show file tree
Hide file tree
Showing 11 changed files with 3,753 additions and 756 deletions.
78 changes: 59 additions & 19 deletions LeapMapper/Leap.pde
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import de.voidplus.leapmotion.*;
LeapMotion leap;

int hand_id = 2;
int fps;
float framerate;
int hand_id;
int finger_id;
PVector hand_position, finger_stabilized;
float hand_grab, hand_pinch;
boolean hand_is_left, hand_is_right;
PVector f0, f1, f2, f3, f4 = new PVector(0, 0, 0);

void setupLeap() {
leap = new LeapMotion(this);
}

void leap() {
int fps = leap.getFrameRate();

// ========= HANDS =========

for (Hand hand : leap.getHands ()) {

Expand All @@ -25,12 +24,8 @@ void leap() {
hand_grab = hand.getGrabStrength();
hand_pinch = hand.getPinchStrength();

handIdMapping();
handMapping();
if(osc){
OSChands();
OSCgestures();
}
handIdMapping();
handMapping();

Finger finger_thumb = hand.getThumb();
Finger finger_index = hand.getIndexFinger();
Expand All @@ -40,16 +35,61 @@ void leap() {

for (Finger finger : hand.getFingers()) {

// or hand.getOutstretchedFingers();
// or hand.getOutstretchedFingersByAngle();

int fingerId = finger.getId();
PVector fingerPosition = finger.getPosition();
PVector fingerStabilized = finger.getStabilizedPosition();
PVector fingerVelocity = finger.getVelocity();
PVector fingerDirection = finger.getDirection();
float fingerTime = finger.getTimeVisible();

finger_id = finger.getId();
finger_stabilized = finger.getStabilizedPosition();
fingerMapping();
if(osc)OSCfingers();
}

// ----- DRAWING -----
hand.draw();
if(midi)MIDImessages();
// ------------------------------------------------
// Drawing

// Drawing:
// finger.draw(); // Executes drawBones() and drawJoints()
// finger.drawBones();
// finger.drawJoints();

// ------------------------------------------------
// Selection

switch(finger.getType()) {
case 0:
f0 = finger.getStabilizedPosition();
finger0mapping();
break;
case 1:
f1 = finger.getStabilizedPosition();
finger1mapping();
break;
case 2:
f2 = finger.getStabilizedPosition();
finger2mapping();
break;
case 3:
f3 = finger.getStabilizedPosition();
finger3mapping();
break;
case 4:
f4 = finger.getStabilizedPosition();
finger4mapping();
break;
}
}

if(osc){
OSCsend();
}
if(midi)MIDImessages();

hand.draw();


// ========= DEVICES =========

for (Device device : leap.getDevices ()) {
Expand All @@ -58,4 +98,4 @@ void leap() {
float device_range = device.getRange();
}
}
}
}
9 changes: 5 additions & 4 deletions LeapMapper/LeapMapper.pde
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
// and send them to thirth party applications able to receive MIDI and/or OSC messages.
// Leap Mapper is developped by Balandino Di Donato at Integra Lab using Leap Motion For Processing library.
// For more info about it please visit balandinodidonato.com/LeapMapper or integra.io.
// © Balandino Di Donato 2016
// © Balandino Di Donato 2017

void setup(){
setupLeap();
setupToggle();
setUpMIDI();
oscSetup();
size(int(displayWidth*0.5), int(displayHeight*0.5), OPENGL);
size(600, 400, OPENGL);
frameRate(15);
}

void draw(){
background(175);
leap();
}
leap();
}
35 changes: 31 additions & 4 deletions LeapMapper/MIDI.pde
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,43 @@ import themidibus.*;

MidiBus myBus; // The MidiBus

int nDati = 20;
int[][] leapMIDI = new int[2][20];

void setUpMIDI(){
myBus.list();
myBus = new MidiBus(this, 2, 1);
myBus = new MidiBus(this, 1, 1);
}

void MIDImessages(){

leapMIDI[hand_id][0] = int(handPositionMIDI.x);
leapMIDI[hand_id][1] = int(handPositionMIDI.y);
leapMIDI[hand_id][2] = int(handPositionMIDI.z);
leapMIDI[hand_id][3] = int(handGrabMIDI);
leapMIDI[hand_id][4] = int(handPinchMIDI);

leapMIDI[hand_id][5] = int(finger0mappedMIDI.x);
leapMIDI[hand_id][6] = int(finger1mappedMIDI.x);
leapMIDI[hand_id][7] = int(finger2mappedMIDI.x);
leapMIDI[hand_id][8] = int(finger3mappedMIDI.x);
leapMIDI[hand_id][9] = int(finger4mappedMIDI.x);

leapMIDI[hand_id][10] = int(finger0mappedMIDI.y);
leapMIDI[hand_id][11] = int(finger1mappedMIDI.y);
leapMIDI[hand_id][12] = int(finger2mappedMIDI.y);
leapMIDI[hand_id][13] = int(finger3mappedMIDI.y);
leapMIDI[hand_id][14] = int(finger4mappedMIDI.y);

leapMIDI[hand_id][15] = int(finger0mappedMIDI.z);
leapMIDI[hand_id][16] = int(finger1mappedMIDI.z);
leapMIDI[hand_id][17] = int(finger2mappedMIDI.z);
leapMIDI[hand_id][18] = int(finger3mappedMIDI.z);
leapMIDI[hand_id][19] = int(finger4mappedMIDI.z);

for(int i=0; i<2; i++){
for(int z=0; z<nDati; z++){
myBus.sendControllerChange(i, z+1, leapMIDI[i][z]);
myBus.sendControllerChange(i, z, leapMIDI[i][z]);
}
}
}

}
63 changes: 40 additions & 23 deletions LeapMapper/OSC.pde
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,48 @@ void oscSetup(){
myRemoteLocation = new NetAddress("127.0.0.1",5432); // IP address and Port
}

void OSChands(){
OscMessage handPosition = new OscMessage("/handPosition");
handPosition.add(hand_id);
handPosition.add(hand_position.x);
handPosition.add(hand_position.y);
handPosition.add(hand_position.z);
void OSCsend(){
OscMessage handPosition = new OscMessage("/hand"+hand_id+"/position");
handPosition.add(handPositionOSC.x);
handPosition.add(handPositionOSC.y);
handPosition.add(handPositionOSC.z);
oscP5.send(handPosition, myRemoteLocation);
}
void OSCfingers(){
OscMessage fingerPosition = new OscMessage("/fingerPosition");
fingerPosition.add(hand_id);
fingerPosition.add(finger_id);
fingerPosition.add(hand_position.x);
fingerPosition.add(hand_position.y);
fingerPosition.add(hand_position.z);
oscP5.send(fingerPosition, myRemoteLocation);
}

void OSCgestures(){
OscMessage pinch = new OscMessage("/pinch");
OscMessage grab = new OscMessage("/grab");
pinch.add(hand_id);
OscMessage fingerPositionf0 = new OscMessage("/hand"+hand_id+"/finger0/position");
fingerPositionf0.add(finger0mappedOSC.x);
fingerPositionf0.add(finger0mappedOSC.y);
fingerPositionf0.add(finger0mappedOSC.z);
oscP5.send(fingerPositionf0, myRemoteLocation);

OscMessage fingerPositionf1 = new OscMessage("/hand"+hand_id+"/finger1/position");
fingerPositionf1.add(finger1mappedOSC.x);
fingerPositionf1.add(finger1mappedOSC.y);
fingerPositionf1.add(finger1mappedOSC.z);
oscP5.send(fingerPositionf1, myRemoteLocation);
//<>//
OscMessage fingerPositionf2 = new OscMessage("/hand"+hand_id+"/finger2/position");
fingerPositionf2.add(finger2mappedOSC.x);
fingerPositionf2.add(finger2mappedOSC.y);
fingerPositionf2.add(finger2mappedOSC.z);
oscP5.send(fingerPositionf2, myRemoteLocation);

OscMessage fingerPositionf3 = new OscMessage("/hand"+hand_id+"/finger3/position");
fingerPositionf3.add(finger3mappedOSC.x);
fingerPositionf3.add(finger3mappedOSC.y);
fingerPositionf3.add(finger3mappedOSC.z);
oscP5.send(fingerPositionf3, myRemoteLocation);

OscMessage fingerPositionf4 = new OscMessage("/hand"+hand_id+"/finger4/position");
fingerPositionf4.add(finger4mappedOSC.x);
fingerPositionf4.add(finger4mappedOSC.y);
fingerPositionf4.add(finger4mappedOSC.z);
oscP5.send(fingerPositionf4, myRemoteLocation);

OscMessage pinch = new OscMessage("/hand"+hand_id+"/pinch");
pinch.add(hand_pinch);
grab.add(hand_id);
grab.add(hand_grab);
oscP5.send(pinch, myRemoteLocation);

OscMessage grab = new OscMessage("/hand"+hand_id+"/grab");
grab.add(hand_grab);
oscP5.send(grab, myRemoteLocation);
}
}
115 changes: 99 additions & 16 deletions LeapMapper/mapping.pde
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
int nDati = 20;
int[][] leapMIDI = new int[2][nDati];
PVector finger0mappedOSC = new PVector(0, 0, 0);
PVector finger0mappedMIDI = new PVector(0, 0, 0);
PVector finger1mappedOSC = new PVector(0, 0, 0);
PVector finger1mappedMIDI = new PVector(0, 0, 0);
PVector finger2mappedOSC = new PVector(0, 0, 0);
PVector finger2mappedMIDI = new PVector(0, 0, 0);
PVector finger3mappedOSC = new PVector(0, 0, 0);
PVector finger3mappedMIDI = new PVector(0, 0, 0);
PVector finger4mappedOSC = new PVector(0, 0, 0);
PVector finger4mappedMIDI = new PVector(0, 0, 0);

PVector handPositionOSC = new PVector(0, 0, 0);
PVector handPositionMIDI = new PVector(0, 0, 0);

float handGrabMIDI = 0;
float handPinchMIDI = 0;

void handIdMapping(){
if(hand_is_left){ hand_id = hand_id - hand_id;
Expand All @@ -8,19 +22,88 @@ void handIdMapping(){
}

void handMapping(){
leapMIDI[hand_id][0] = int(map(hand_position.x, 0, 770, 0, 127)); // Yaw
leapMIDI[hand_id][1] = int(map(hand_position.y, 58, 450, 127, 0)); // Pitch
leapMIDI[hand_id][2] = int(map(hand_position.z, 40, 60, 0, 127));// Roll
leapMIDI[hand_id][3] = int(hand_grab*127); // Grab
leapMIDI[hand_id][4] = int(hand_pinch*127); // Pinch
}
handPositionOSC.x = map(hand_position.x, -50, 420, 0, 1);
handPositionOSC.y = map(hand_position.y, 450, 0, 0, 1);
handPositionOSC.z = map(hand_position.z, 0, 90, 0, 1);

handPositionOSC.x = constrain(handPositionOSC.x, 0, 1);
handPositionOSC.y = constrain(handPositionOSC.y, 0, 1);
handPositionOSC.z = constrain(handPositionOSC.z, 0, 1);

handPositionMIDI.x = handPositionOSC.x*127;
handPositionMIDI.y = handPositionOSC.y*127;
handPositionMIDI.z = handPositionOSC.z*127;

handGrabMIDI = hand_grab*127;
handPinchMIDI = hand_pinch*127;
} //<>//

void fingerMapping(){
finger_id = finger_id % 5;
leapMIDI[hand_id][finger_id+5] = int(map(finger_stabilized.x, 0, 770, 0, 127)); // Yaw
leapMIDI[hand_id][finger_id+10] = int(map(finger_stabilized.y, 58, 450, 127, 0)); // Pitch
leapMIDI[hand_id][finger_id+15] = int(map(finger_stabilized.z, 40, 68, 0, 127));// Roll
void finger0mapping(){
finger0mappedOSC.x = map(f0.x, -100, 450, 0, 1);
finger0mappedOSC.y = map(f0.y, 490, 100, 0, 1);
finger0mappedOSC.z = map(f0.z, 25, 90, 0, 1);

finger0mappedOSC.x = constrain(finger0mappedOSC.x, 0, 1);
finger0mappedOSC.y = constrain(finger0mappedOSC.y, 0, 1);
finger0mappedOSC.z = constrain(finger0mappedOSC.z, 0, 1);

finger0mappedMIDI.x = finger0mappedOSC.x*127;
finger0mappedMIDI.y = finger0mappedOSC.y*127;
finger0mappedMIDI.z = finger0mappedOSC.z*127;
}




void finger1mapping(){
finger1mappedOSC.x = map(f1.x, -100, 450, 0, 1);
finger1mappedOSC.y = map(f1.y, 490, 100, 0, 1);
finger1mappedOSC.z = map(f1.z, 25, 90, 0, 1);

finger1mappedOSC.x = constrain(finger1mappedOSC.x, 0, 1);
finger1mappedOSC.y = constrain(finger1mappedOSC.y, 0, 1);
finger1mappedOSC.z = constrain(finger1mappedOSC.z, 0, 1);

finger1mappedMIDI.x = finger1mappedOSC.x*127; // Yaw
finger1mappedMIDI.y = finger1mappedOSC.y*127; // pitch
finger1mappedMIDI.z = finger1mappedOSC.z*127; // roll
}

void finger2mapping(){
finger2mappedOSC.x = map(f2.x, -100, 450, 0, 1);
finger2mappedOSC.y = map(f2.y, 490, 100, 0, 1);
finger2mappedOSC.z = map(f2.z, 25, 90, 0, 1);

finger2mappedOSC.x = constrain(finger2mappedOSC.x, 0, 1);
finger2mappedOSC.y = constrain(finger2mappedOSC.y, 0, 1);
finger2mappedOSC.z = constrain(finger2mappedOSC.z, 0, 1);

finger2mappedMIDI.x = finger2mappedOSC.x*127; // Yaw
finger2mappedMIDI.y = finger2mappedOSC.y*127; // pitch
finger2mappedMIDI.z = finger2mappedOSC.z*127; // roll
}

void finger3mapping(){
finger3mappedOSC.x = map(f3.x, -100, 450, 0, 1);
finger3mappedOSC.y = map(f3.y, 490, 100, 0, 1);
finger3mappedOSC.z = map(f3.z, 25, 90, 0, 1);

finger3mappedOSC.x = constrain(finger3mappedOSC.x, 0, 1);
finger3mappedOSC.y = constrain(finger3mappedOSC.y, 0, 1);
finger3mappedOSC.z = constrain(finger3mappedOSC.z, 0, 1);

finger3mappedMIDI.x = finger3mappedOSC.x*127; // Yaw
finger3mappedMIDI.y = finger3mappedOSC.y*127; // pitch
finger3mappedMIDI.z = finger3mappedOSC.z*127; // roll
}

void finger4mapping(){
finger4mappedOSC.x = map(f4.x, -100, 450, 0, 1);
finger4mappedOSC.y = map(f4.y, 490, 100, 0, 1);
finger4mappedOSC.z = map(f4.z, 25, 90, 0, 1);

finger4mappedOSC.x = constrain(finger4mappedOSC.x, 0, 1);
finger4mappedOSC.y = constrain(finger4mappedOSC.y, 0, 1);
finger4mappedOSC.z = constrain(finger4mappedOSC.z, 0, 1);

finger4mappedMIDI.x = finger4mappedOSC.x*127; // Yaw
finger4mappedMIDI.y = finger4mappedOSC.y*127; // pitch
finger4mappedMIDI.z = finger4mappedOSC.z*127; // roll
}
Loading

0 comments on commit e65a46d

Please sign in to comment.