Created
January 18, 2013 22:21
-
-
Save jordanorelli/4569165 to your computer and use it in GitHub Desktop.
polyphonic theremin for LEAP with Python and ChucK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Voice { | |
int id; // id of the finger on the leapmotion | |
OscRecv in; // inbound communication | |
ADSR env => Pan2 pan => dac; // setup an ADSR envelope | |
Osc @ osc; // reference to the current oscillator | |
float x; | |
float y; | |
float z; | |
0 => int state; | |
// start in the off position | |
env.keyOff(); | |
env.set(20::ms, 40::ms, 0.6, 40::ms); | |
5::ms => dur beat; | |
fun static Voice Voice(OscRecv _in, int _id) { | |
Voice v; | |
_id => v.id; | |
_in @=> v.in; | |
new SinOsc @=> v.osc => v.env; | |
spork ~ v.listen(); | |
spork ~ v.play(); | |
return v; | |
} | |
fun void listen() { | |
in.event("/leap/finger/" + id, "fff") @=> OscEvent e; | |
while(true) { | |
e => now; | |
while(e.nextMsg() != 0) { | |
e.getFloat() => x; | |
e.getFloat() => y; | |
e.getFloat() => z; | |
} | |
} | |
} | |
// loop continuously | |
fun void play() { | |
while(true) { | |
beat - (now % beat) => now; | |
if(x != 0 && y != 0 && z != 0) { | |
update(); | |
0 => x; | |
0 => y; | |
0 => z; | |
} else if(state == 1) { | |
off(); | |
} | |
} | |
} | |
fun void update() { | |
if(state == 0) { | |
on(); | |
} | |
x / 256.0 => pan.pan; | |
y => osc.freq; | |
} | |
fun void on() { | |
env.keyOn(); | |
1 => state; | |
} | |
fun void off() { | |
env.keyOff(); | |
0 => state; | |
} | |
} | |
OscRecv recv; | |
9000 => recv.port; | |
recv.listen(); | |
for (0 => int i; i < 30; i++) { | |
Voice.Voice(recv, i) @=> Voice v; | |
} | |
while(true) { 1::minute => now; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Leap, sys, liblo | |
class Listener(Leap.Listener): | |
def __init__(self): | |
super(Listener, self).__init__() | |
self.target = liblo.Address(9000) | |
def on_frame(self, controller): | |
frame = controller.frame() | |
for hand in frame.hands: | |
for finger in hand.fingers: | |
self.send_finger(finger) | |
def send_finger(self, finger): | |
msg = liblo.Message("/leap/finger/%d" % finger.id) | |
msg.add( | |
finger.tip_position.x, | |
finger.tip_position.y, | |
finger.tip_position.z, | |
) | |
liblo.send(self.target, msg) | |
l, c = Listener(), Leap.Controller() | |
c.add_listener(l) | |
print "Press Enter to quit..." | |
sys.stdin.readline() | |
c.remove_listener(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! What is the module liblo? I tried running it, and it said no module named liblo. Help?