├── README.md ├── sahliquidities.scd ├── ringmod.scd ├── organ.scd ├── creepybell.scd ├── strum.scd ├── marimba.scd ├── LeapOSC └── LeapOSC.pde └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # Leap Motion + SuperCollider instruments 2 | 3 | A series of SuperCollider sound instruments controlled by the Leap Motion hand tracker. 4 | 5 | Pre-requisities: 6 | * [SuperCollider](http://supercollider.sf.net/) 7 | * [Processing](http://www.processing.org) 8 | * [Leap Motion](http://www.leapmotion.com) 9 | * [LeapMotion Processing library](http://www.onformative.com/lab/leapmotionp5/) 10 | 11 | ## Example 12 | 13 | [![ScreenShot](https://secure-b.vimeocdn.com/ts/451/183/451183088_640.jpg)](https://vimeo.com/76401096) 14 | 15 | ## Usage 16 | 17 | First, run the included Processing sketch LeapOSC, which will transmit the Leap data to SuperCollider via OSC. Then run through any of the included SuperCollider files to get sound. Keep the Processing sketch as the active window to control the audio and view hand movements. 18 | -------------------------------------------------------------------------------- /sahliquidities.scd: -------------------------------------------------------------------------------- 1 | // Variation on sample and hold liquidities from SuperCollider book, run through Comb filter. 2 | // -> http://ecmc.rochester.edu/ecmc/docs/supercollider/scexamples.1.html 3 | // finger x and y position controls the pitch and clock rate respectively. 4 | 5 | 6 | /////////////////////////////////// 7 | ///// 1) SETUP BUSSES 8 | ( 9 | ~h1x = Bus.control(s, 1); // leap motion, first finger x position 10 | ~h1y = Bus.control(s, 1); // leap motion, first finger y position 11 | ) 12 | 13 | 14 | /////////////////////////////////// 15 | ///// 2) SETUP SYNTH 16 | ( 17 | SynthDef(\sahliquid, { 18 | arg out = 0, gate = 1, atk = 5.0; 19 | var env, clockRate, clockTime, clock, centerFreq, freq, panPos, patch; 20 | env = EnvGen.kr(Env.adsr(atk, 1, 1), gate, doneAction: 2); 21 | centerFreq = 8000 * 2.asWarp.map(In.kr(~h1x)) + 100; 22 | clockRate = 300 * In.kr(~h1y) + 1; 23 | clockTime = 2.0*clockRate.reciprocal; 24 | clock = Impulse.kr(clockRate, 0.4); 25 | freq = Latch.kr(WhiteNoise.kr(centerFreq * 0.5, centerFreq), clock); 26 | panPos = Latch.kr(WhiteNoise.kr, clock); 27 | patch = CombN.ar( 28 | Pan2.ar( 29 | SinOsc.ar(freq, 0, Decay2.kr(clock, 0.1 * clockTime, 0.9 * clockTime)), 30 | panPos 31 | ), 0.3, 0.3, 2); 32 | Out.ar(out, env * patch); 33 | }).add; 34 | ) 35 | 36 | /////////////////////////////////// 37 | ///// 3) LAUNCH SYNTH 38 | 39 | ~sahliquid = Synth(\sahliquid); 40 | 41 | 42 | /////////////////////////////////// 43 | ///// 4) SETUP OSC CONTROL 44 | 45 | // first finger position 46 | ( 47 | OSCFunc({ 48 | |msg| 49 | ~h1x.set(msg[1]); 50 | ~h1y.set(msg[2]); 51 | }, '/h1/', nil); 52 | ) -------------------------------------------------------------------------------- /ringmod.scd: -------------------------------------------------------------------------------- 1 | // Filtered Ring Modulator 2 | // a ring modulator going through an allpass filter with variable delay time 3 | // first setup busses, synths, and osc control. 4 | // then, using the Processing leap OSC sketch, the x, y, and z position of 5 | // your first finger control the carrier freq, modulator freq, and allpass delay 6 | // time respectively. be careful, can get loud 7 | 8 | 9 | /////////////////////////////////// 10 | ///// 1) SETUP BUSSES 11 | ( 12 | ~h1x = Bus.control(s, 1); // leap motion, first finger x position 13 | ~h1y = Bus.control(s, 1); // leap motion, first finger y position 14 | ~h1z = Bus.control(s, 1); // leap motion, first finger z position 15 | ) 16 | 17 | 18 | /////////////////////////////////// 19 | ///// 2) SETUP SYNTH 20 | ( 21 | SynthDef(\ringMod, { 22 | arg outBus = 0, gate = 1, atk = 5.0; 23 | var env, freq, ratio, modulator, carrier, sig; 24 | env = EnvGen.kr(Env.adsr(atk, 1, 1), gate, doneAction: 2); 25 | freq = LFNoise0.kr(65*In.kr(~h1x)+5, 80, 60).round(24).midicps; 26 | ratio = -2.0+14.0*In.kr(~h1z); 27 | modulator = SinOsc.ar(freq * ratio, 0, 4.0); 28 | carrier = SinOsc.ar(freq, modulator, 0.5); 29 | sig = carrier!2; 30 | //8.do({ out = AllpassC.ar(out, 0.5, { Rand(0.001, 0.03) }.dup, 8)}); 31 | 2.do({ sig = AllpassC.ar(sig, 0.5, DC.kr(Rand()).range(0.001, 0.5*(3.asWarp.map(In.kr(~h1y)+0.001))), 8)}); 32 | Out.ar(outBus, 0.2 * env * sig); 33 | }).add; 34 | ) 35 | 36 | /////////////////////////////////// 37 | ///// 3) LAUNCH SYNTH 38 | 39 | ~ringmod = Synth(\ringMod); 40 | 41 | 42 | /////////////////////////////////// 43 | ///// 4) SETUP OSC CONTROL 44 | 45 | // first finger position 46 | ( 47 | OSCFunc({ 48 | |msg| 49 | ~h1x.set(msg[1]); 50 | ~h1y.set(msg[2]); 51 | ~h1z.set(msg[3]); 52 | }, '/h1/', nil); 53 | ) -------------------------------------------------------------------------------- /organ.scd: -------------------------------------------------------------------------------- 1 | // Three voice organ-like sounding instrument using DynKlank 2 | // Move hand around and each of the x, y, and z postiion affect the pitch 3 | // of one of the three voices 4 | 5 | 6 | /////////////////////////////////// 7 | ///// 1) SETUP BUSSES 8 | ( 9 | ~h1x = Bus.control(s, 1); // leap motion, first finger x position 10 | ~h1y = Bus.control(s, 1); // leap motion, first finger y position 11 | ~h1z = Bus.control(s, 1); // leap motion, first finger z position 12 | ) 13 | 14 | 15 | /////////////////////////////////// 16 | ///// 2) SETUP SYNTH 17 | ( 18 | SynthDef(\organ, { 19 | arg outBus = 0, gate = 1, atk = 5.0; 20 | var env, klank1, klank2, klank3, n, harm, amp, ring, pitches, freq1, freq2, freq3, cnoiseMul; 21 | env = EnvGen.kr(Env.adsr(atk, 1, 1), gate, doneAction: 2); 22 | //pitches = [0, 3, 5, 7, 10, 12, 17, 22]; 23 | pitches = [0, 3, 5, 7, 10, 12, 17, 22, 24, 29, 34]; 24 | n = pitches.size; 25 | cnoiseMul = 0.006; //-44, -20, 4 26 | freq1 = Select.kr(In.kr(~h1x)*n, 55+pitches).midicps; 27 | freq2 = Select.kr(In.kr(~h1y)*n, 31+pitches).midicps; 28 | freq3 = Select.kr(In.kr(~h1z)*n, 7+pitches).midicps; 29 | harm = Control.names(\harm).kr(Array.series(4,1,1)); 30 | amp = Control.names(\amp).kr(Array.fill(4,0.05)); 31 | ring = Control.names(\ring).kr(Array.fill(4,1)); 32 | klank1 = DynKlank.ar(`[harm,amp,ring], {ClipNoise.ar(cnoiseMul)}.dup, freq1); 33 | klank2 = DynKlank.ar(`[harm,amp,ring], {ClipNoise.ar(cnoiseMul)}.dup, freq2); 34 | klank3 = DynKlank.ar(`[harm,amp,ring], {ClipNoise.ar(cnoiseMul)}.dup, freq3); 35 | Out.ar(outBus, env * (klank1 + klank2 + klank3)); 36 | }).add; 37 | ) 38 | 39 | /////////////////////////////////// 40 | ///// 3) LAUNCH SYNTH 41 | 42 | ~organ = Synth(\organ); 43 | 44 | 45 | /////////////////////////////////// 46 | ///// 4) SETUP OSC CONTROL 47 | 48 | // first finger position 49 | ( 50 | OSCFunc({ 51 | |msg| 52 | ~h1x.set(msg[1]); 53 | ~h1y.set(msg[2]); 54 | ~h1z.set(msg[2]); 55 | }, '/h1/', nil); 56 | ) -------------------------------------------------------------------------------- /creepybell.scd: -------------------------------------------------------------------------------- 1 | // CreepyBell 2 | // variation of weird bell code example from the SuperCollider book: 3 | // -> http://ecmc.rochester.edu/ecmc/docs/supercollider/scbook/ 4 | // opening hand triggers a glitchy bell. closing and opening again triggers another 5 | // first finger x position messes with the delay 6 | 7 | 8 | /////////////////////////////////// 9 | ///// 1) SETUP BUSSES 10 | ( 11 | ~h1x = Bus.control(s, 1); // leap motion, first finger x position 12 | ~h1y = Bus.control(s, 1); // leap motion, first finger y position 13 | ~h1z = Bus.control(s, 1); // leap motion, first finger z position 14 | ~h1thresh = Bus.control(s, 1); // leap motion, hand opening threshold 15 | ) 16 | 17 | 18 | /////////////////////////////////// 19 | ///// 2) SETUP SYNTH 20 | ( 21 | SynthDef(\creepyBell, { 22 | arg outBus = 0, gate = 1, atk = 5.0; 23 | var env, burst, burstEnv, bell, delay, dry, burstFreq = 500, freqs, amps, rings; 24 | env = EnvGen.kr(Env.adsr(atk, 1, 1), gate, doneAction: 2); 25 | burstEnv = EnvGen.kr(Env.perc(0, 0.05), In.kr(~h1thresh), 0.4); 26 | burst = SinOsc.ar(freq: burstFreq, mul: burstEnv); 27 | amps = Array.fill(10, {rrand(0.01, 0.1)}); 28 | rings = Array.fill(10, {rrand(1.0, 6.0)}); 29 | if ([true,false].choose, freqs = [100, 200, 800, 400, 1600, 3200, 6400], freqs = Array.fill(10, {exprand(100, 1100)}) ); 30 | bell = Pan2.ar( 31 | Klank.ar(`[freqs, amps, rings], burst), 32 | rrand(-1.0, 1.0)); 33 | delay = AllpassN.ar(bell, 2.5, 34 | [LFNoise1.kr(10*In.kr(~h1x), 1.5, 1.6), LFNoise1.kr(10*In.kr(~h1x), 1.5, 1.6)], 1, mul: 0.8); 35 | Out.ar(outBus, env * (bell + delay)); 36 | }).add; 37 | ) 38 | 39 | /////////////////////////////////// 40 | ///// 3) LAUNCH SYNTH 41 | 42 | ~creepybell = Synth(\creepyBell); 43 | 44 | 45 | /////////////////////////////////// 46 | ///// 4) SETUP OSC CONTROL 47 | 48 | // first finger position and hand opening thresholds for triggering 49 | ( 50 | OSCFunc({ 51 | |msg| 52 | ~h1x.set(msg[1]); 53 | ~h1y.set(msg[2]); 54 | }, '/h1/', nil); 55 | 56 | OSCFunc({ 57 | |msg| ~h1thresh.set(1); 58 | }, '/h1thresh1/', nil); 59 | 60 | OSCFunc({ 61 | |msg| ~h1thresh.set(0); 62 | }, '/h1thresh0/', nil); 63 | 64 | ) -------------------------------------------------------------------------------- /strum.scd: -------------------------------------------------------------------------------- 1 | // variation on classic plucked string model, adapted 2 | // from Nick Collins's examples 3 | // -> http://www.sussex.ac.uk/Users/nc81/modules/cm1/scfiles/4.1 Interaction 1.html 4 | // swipe your finger from left to right to pluck the strings 5 | 6 | 7 | /////////////////////////////////// 8 | ///// 1) SETUP BUSSES 9 | ( 10 | ~h1x = Bus.control(s, 1); // leap motion, first finger x position 11 | ~h1y = Bus.control(s, 1); // leap motion, first finger y position 12 | ~h1z = Bus.control(s, 1); // leap motion, first finger z position 13 | ) 14 | 15 | 16 | /////////////////////////////////// 17 | ///// 2) SETUP SYNTH 18 | ( 19 | SynthDef(\strum, { 20 | arg outBus = 0, gate = 1, atk = 5.0, z = 1; 21 | var env, pitch1, pitch2, strum, sig, decayTime, cDecayTime; 22 | env = EnvGen.kr(Env.adsr(atk, 1, 1), gate, doneAction: 2); 23 | pitch1 = [ 52, 57, 62, 67, 71, 76, 81, 86 ]; 24 | pitch2 = pitch1 + 12; 25 | 26 | strum = In.kr(~h1x); 27 | 28 | decayTime = 5.asWarp.map(In.kr(~h1x)); 29 | cDecayTime = 10.0 * In.kr(~h1z); 30 | 31 | sig = Mix.arFill(pitch1.size, { arg i; 32 | var trigger, pluck1, pluck2, period1, period2, string1, string2, pitchHop; 33 | // place trigger points from 0.25 to 0.75 34 | pitchHop = 0.5 / pitch1.size; 35 | trigger = HPZ1.kr(strum > (0.25 + (i * pitchHop))); 36 | 37 | pluck1 = PinkNoise.ar(Decay.kr(trigger.max(0), decayTime)); 38 | period1 = pitch1.at(i).midicps.reciprocal; 39 | string1 = CombL.ar(pluck1, period1, period1, cDecayTime); 40 | 41 | pluck2 = BrownNoise.ar(Decay.kr(trigger.neg.max(0), decayTime)); 42 | period2 = pitch2.at(i).midicps.reciprocal; 43 | string2 = CombL.ar(pluck2, period2, period2, -1*cDecayTime); 44 | 45 | Pan2.ar(string1 + string2, i * 0.2 - 0.5); 46 | }); 47 | sig = LeakDC.ar(LPF.ar(sig, 12000)); 48 | Out.ar(outBus, env * sig); 49 | }).add; 50 | ) 51 | 52 | /////////////////////////////////// 53 | ///// 3) LAUNCH SYNTH 54 | 55 | ~strum = Synth(\strum); 56 | 57 | 58 | /////////////////////////////////// 59 | ///// 4) SETUP OSC CONTROL 60 | 61 | // first finger position 62 | ( 63 | OSCFunc({ 64 | |msg| 65 | ~h1x.set(msg[1]); 66 | ~h1y.set(msg[2]); 67 | ~h1z.set(msg[2]); 68 | }, '/h1/', nil); 69 | ) -------------------------------------------------------------------------------- /marimba.scd: -------------------------------------------------------------------------------- 1 | // Marimba clusters 2 | // a variation from code by eli.fieldsteel found: http://sccode.org/1-4SB 3 | // first setup busses, synths, and osc control. 4 | // opening your hand (fingers spread apart) fires a single cluster, 5 | // and swiping your hand will silence all active clusters. 6 | 7 | 8 | /////////////////////////////////// 9 | ///// 1) SETUP BUSSES 10 | ( 11 | ~h1y = Bus.control(s, 1); // leap motion, first finger y position 12 | ~h1d = Bus.control(s, 1); // used to measure "openness" of hand 13 | ~busMarimba = Bus.audio(s,2); 14 | ) 15 | 16 | 17 | /////////////////////////////////// 18 | ///// 2) SETUP SYNTHS 19 | 20 | ( 21 | // last step: add reverb to clusters 22 | SynthDef(\reverb_ef, { 23 | arg amp=1, mix=0.085, revTime=1.8, preDel=0.1, lpfFreq=4500, outBus=0; 24 | var sig, verbSig, totalSig, outSig; 25 | mix = In.kr(~h1y).clip(0, 1); 26 | sig = In.ar(~busMarimba, 2); 27 | preDel = 0.5; 28 | verbSig = DelayN.ar(sig, preDel, preDel); //pre-delay 29 | totalSig = 0; 30 | 12.do{ 31 | verbSig = AllpassN.ar(verbSig, 0.06, {Rand(0.001,0.06)}!2, revTime); 32 | verbSig = LPF.ar(verbSig, lpfFreq); 33 | totalSig = totalSig + verbSig; 34 | }; 35 | totalSig = XFade2.ar(sig, totalSig, mix.linlin(0,1,-1,1)); //dry/wet mix 36 | outSig = totalSig * amp; 37 | Out.ar(outBus, outSig); 38 | }).add; 39 | 40 | // a single note 41 | SynthDef(\filtSaw, { 42 | arg freq=440, detune=3.0, atk=6, rel=6, curve1=1, curve2=(-1), 43 | minCf=30, maxCf=6000, minRq=0.005, maxRq=0.04, 44 | minBpfHz=0.02, maxBpfHz=0.25, 45 | lowShelf=220, rs=0.85, db=6, 46 | gate=1, amp=1, spread=1.0, out; 47 | var sig, env; 48 | env = EnvGen.kr(Env.adsr(atk, rel, amp), gate, doneAction: 2); 49 | sig = Saw.ar(freq + 50 | LFNoise1.kr({LFNoise1.kr(0.5).range(0.15,0.4)}!8).range(detune.neg,detune)); 51 | sig = BPF.ar(sig, 52 | LFNoise1.kr({LFNoise1.kr(0.13).exprange(minBpfHz,maxBpfHz)}!8).exprange(minCf, maxCf), 53 | LFNoise1.kr({LFNoise1.kr(0.08).exprange(0.08,0.35)}!8).range(minRq, maxRq)); 54 | sig = BLowShelf.ar(sig, lowShelf, rs, db); 55 | sig = SplayAz.ar(4, sig, spread); 56 | sig = sig * env * 8; 57 | Out.ar(~busMarimba, sig); 58 | }).add; 59 | 60 | // generate a cluster of notes 61 | ~cluster = { 62 | var trnsp; 63 | trnsp = rrand(-7,7); 64 | Array.fill(exprand(4,14).round, {[1,2,3,4,6,8,12,16].wchoose([7,6,5,4,3,3,1].normalizeSum)}).do{ 65 | arg i; 66 | var cfLo = (([23,35,47,50,52,59,61,63,64,76,78].choose) + trnsp).midicps * ((1..8).choose); 67 | Synth(\filtSaw, [ 68 | \freq, i, 69 | \detune, 0, 70 | \minBpfHz, 0.01, 71 | \maxBpfHz,i.expexp(1.0,16.0,0.1,16.0), 72 | \minRq, 0.003, 73 | \maxRq, exprand(0.008,0.08), 74 | \minCf, cfLo, 75 | \maxCf, cfLo * [1,1.1,1.5].wchoose([0.87,0.1,0.03]), 76 | \amp, exprand(0.15,0.25), 77 | \atk, exprand(0.2,0.5), 78 | \rel, 0.8, 79 | \spread, exprand(1.5,8.0), 80 | \out, ~busMarimba, 81 | ], ~clusters 82 | )}}; 83 | ) 84 | 85 | 86 | /////////////////////////////////// 87 | ///// 3) LAUNCH SYNTHS 88 | 89 | ~synth = Synth(\reverb_ef); // this sets up the final reverb synth 90 | ~clusters = Group.before(~synth); // a group of clusters that go to the reverb 91 | 92 | // how to playback: 93 | ~cluster.value; // this launchs a single cluster. try running several times 94 | ~clusters.set(\gate, -5); // this silences all the clusters with a 5 second fadeout 95 | 96 | 97 | /////////////////////////////////// 98 | ///// 4) SETUP OSC CONTROL 99 | 100 | // sending an OSC message to /h1thresh1/ (open hand) will start a cluster 101 | // sending an OSC message to /h1swipe/ (swipe) will silence all clusters 102 | ( 103 | OSCFunc({ 104 | |msg| ~h1y.set(msg[2]); 105 | }, '/h1/', nil); 106 | 107 | OSCFunc({ 108 | |msg| 109 | ~cluster.value; 110 | "cluster start".postln; 111 | }, '/h1thresh1/', nil); 112 | 113 | OSCFunc({ 114 | |msg| 115 | ~clusters.set(\gate, -5); 116 | "silence".postln; 117 | }, '/h1swipe/', nil); 118 | ) 119 | 120 | -------------------------------------------------------------------------------- /LeapOSC/LeapOSC.pde: -------------------------------------------------------------------------------- 1 | import de.voidplus.leapmotion.*; 2 | import oscP5.*; 3 | import netP5.*; 4 | 5 | // PARAMETERS 6 | 7 | // which data to send OSC 8 | boolean OSC_HAND = true; 9 | boolean OSC_HAND_AXIS = true; 10 | boolean OSC_FINGERS = true; 11 | boolean OSC_HAND_SIZE = true; 12 | boolean OSC_HAND_SIZE_TRIGGER = true; 13 | 14 | // if sending hand trigger, bounding sizes 15 | float HAND_THRESH_MIN = 0.15; 16 | float HAND_THRESH_MAX = 0.45; 17 | 18 | LeapMotion leap; 19 | OscP5 oscP5; 20 | NetAddress myRemoteLocation; 21 | float[] handSize; 22 | boolean[] handThresh = new boolean[]{false, false}; 23 | int[] alph = new int[]{0, 0}; 24 | PVector viewAngle = new PVector(); 25 | PVector[] handPosition = new PVector[2]; 26 | float SIZE_BOX = 400; 27 | 28 | void setup() { 29 | size(900, 680, P3D); 30 | frameRate(60); 31 | oscP5 = new OscP5(this, 12000); 32 | myRemoteLocation = new NetAddress("127.0.0.1", 57120); 33 | 34 | // setup leap + osc 35 | leap = new LeapMotion(this); 36 | leap.allowGestures(); 37 | 38 | oscP5 = new OscP5(this, 12000); 39 | myRemoteLocation = new NetAddress("127.0.0.1", 57120); 40 | } 41 | 42 | void leapOnInit() { 43 | println("Leap Motion Init"); 44 | } 45 | void leapOnConnect() { 46 | println("Leap Motion Connect"); 47 | } 48 | void leapOnFrame() { 49 | //println("Leap Motion Frame"); 50 | } 51 | void leapOnDisconnect() { 52 | println("Leap Motion Disconnect"); 53 | } 54 | void leapOnExit() { 55 | println("Leap Motion Exit"); 56 | } 57 | 58 | void draw() 59 | { 60 | background(255); 61 | pushMatrix(); 62 | 63 | // draw finger box frame 64 | noFill(); 65 | stroke(0, 150); 66 | translate((width-100)/2, height/2, 0); 67 | rotateX(viewAngle.y); 68 | rotateY(viewAngle.x); 69 | box(SIZE_BOX); 70 | 71 | // get leap data on hands/fingers 72 | handSize = new float[]{0, 0}; 73 | 74 | ArrayList hands = leap.getHands(); 75 | for (int h=0; h(); 96 | //fingers.add(hand.getThumb()); 97 | //fingers.add(hand.getIndexFinger()); 98 | //fingers.add(hand.getMiddleFinger()); 99 | //fingers.add(hand.getRingFinger()); 100 | //fingers.add(hand.getPinkyFinger()); 101 | 102 | ArrayList fingers = hand.getFingers(); 103 | 104 | PVector minFinger = new PVector(1,1,1); 105 | PVector maxFinger = new PVector(0,0,0); 106 | PVector[] fingerPos = new PVector[fingers.size()]; 107 | for (int f=0; f maxFinger.x) maxFinger.x = fingerPos[f].x; 115 | if (fingerPos[f].x < minFinger.x) minFinger.x = fingerPos[f].x; 116 | if (fingerPos[f].y > maxFinger.y) maxFinger.y = fingerPos[f].y; 117 | if (fingerPos[f].y < minFinger.y) minFinger.y = fingerPos[f].y; 118 | if (fingerPos[f].z > maxFinger.z) maxFinger.z = fingerPos[f].z; 119 | if (fingerPos[f].z < minFinger.z) minFinger.z = fingerPos[f].z; 120 | 121 | // send OSC finger positions 122 | if (OSC_FINGERS) 123 | sendOSCMessage("/h"+(h+1)+"f"+(f+1)+"/", new float[]{fingerPos[f].x, fingerPos[f].y, fingerPos[f].z}); 124 | } 125 | 126 | // get hand size and send thresholding data 127 | if (fingers.size() > 1) 128 | handSize[h] = PVector.dist(minFinger, maxFinger); 129 | if (OSC_HAND_SIZE) 130 | sendOSCMessage("/h"+(h+1)+"d/", new float[]{handSize[h]}); 131 | if (OSC_HAND_SIZE_TRIGGER) { 132 | if (handThresh[h]) { 133 | if (handSize[h] < HAND_THRESH_MIN) 134 | handThresh[h] = false; 135 | sendOSCMessage("/h"+(h+1)+"thresh0/"); 136 | } else { 137 | if (handSize[h] > HAND_THRESH_MAX) { 138 | sendOSCMessage("/h"+(h+1)+"thresh1/"); 139 | handThresh[h] = true; 140 | alph[h] = frameCount; 141 | } 142 | } 143 | } 144 | 145 | // draw bounding box 146 | if (fingers.size() > 0) { 147 | minFinger.set( 148 | map(minFinger.x, 0, 1, -SIZE_BOX/2, SIZE_BOX/2), 149 | map(minFinger.y, 1, 0, -SIZE_BOX/2, SIZE_BOX/2), 150 | map(minFinger.z, 0, 1, -SIZE_BOX/2, SIZE_BOX/2)); 151 | maxFinger.set( 152 | map(maxFinger.x, 0, 1, -SIZE_BOX/2, SIZE_BOX/2), 153 | map(maxFinger.y, 1, 0, -SIZE_BOX/2, SIZE_BOX/2), 154 | map(maxFinger.z, 0, 1, -SIZE_BOX/2, SIZE_BOX/2)); 155 | pushStyle(); 156 | if (handThresh[h]) 157 | strokeWeight(1+20*sin(map(constrain(frameCount-alph[h], 0, 20), 0, 20, 0, PI))); 158 | stroke(255-255*h, 255*h, 30, 180); 159 | noFill(); 160 | 161 | PVector p = PVector.lerp(minFinger, maxFinger, 0.5); 162 | float d = PVector.dist(minFinger, maxFinger)/2; 163 | pushMatrix(); 164 | translate(p.x, p.y, p.z); 165 | box(maxFinger.x-minFinger.x, maxFinger.y-minFinger.y, maxFinger.z-minFinger.z); 166 | popMatrix(); 167 | popStyle(); 168 | } 169 | 170 | // draw hand center 171 | pushStyle(); 172 | noStroke(); 173 | fill(100, 180, 100, 180); 174 | pushMatrix(); 175 | translate(map(handPosition[h].x, 0, 1, -SIZE_BOX/2, SIZE_BOX/2), 176 | map(handPosition[h].y, 1, 0, -SIZE_BOX/2, SIZE_BOX/2), 177 | map(handPosition[h].z, 0, 1, -SIZE_BOX/2, SIZE_BOX/2)); 178 | sphere(10); 179 | 180 | // draw palm axis 181 | rotateX(-pitch); 182 | rotateY(-yaw); 183 | rotateZ(-roll); 184 | strokeWeight(3); 185 | stroke(255, 0, 0); 186 | line(0, 0, 0, 0, 100, 0); 187 | stroke(0, 255, 0); 188 | line(0, 0, 0, 0, 0, 100); 189 | stroke(0, 0, 255); 190 | line(0, 0, 0, 100, 0, 0); 191 | popMatrix(); 192 | 193 | // draw fingers 194 | noStroke(); 195 | fill(50, 50, 90, 180); 196 | for (int f=0; f 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------