-
Notifications
You must be signed in to change notification settings - Fork 0
/
theremin.ck
executable file
·92 lines (79 loc) · 2.75 KB
/
theremin.ck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//theremin.ck
//Recieve hand data
OscRecv orec;
6447 => orec.port;
// start listening (launch thread)
orec.listen();
//listen for left, right hand position oscEvent
orec.event("/hand/right/pos, f f f") @=> OscEvent righthpos;
//currently unused
orec.event("/hand/left/pos, f f f") @=> OscEvent lefthpos;
//theremin with TriOsc
TriOsc sound => NRev rev => dac;
0.1 => rev.mix;
0 => sound.freq;
SinOsc vib;
vib => blackhole;
0 => vib.freq;
fun void right(){
while(true)
{
righthpos => now; // wait for events to arrive.
// grab the next message from the queue
while( righthpos.nextMsg() != 0 )
{
//get left palm pos
righthpos.getFloat() => float rightx;
righthpos.getFloat() => float righty;
righthpos.getFloat() => float rightz;
//<<<righty>>>;
/*
// Simple y pos to note conversion
//Std.ftom(righty*2) $ int => int note;
Std.ftom(righty*2) => float note;
<<<note>>>;
if(rightz>50) {Math.fabs(rightz*(0.05)) => vib.freq;}
else {0 => vib.freq;}
Std.mtof(note) + (vib.last() * 20) => sound.freq;
*/
// custom scale - 6 note
6 => int notes;
300/notes => int inter;
[73,75,78,80,82,85] @=> int scale[];
// d major[62,64,66,67,69,71,73] @=> int scale[];
float freq;
if(righty<100+inter) {Std.mtof(scale[0]) => freq;}
else if(100+inter<righty&&righty<100+inter*2) {Std.mtof(scale[1]) => freq;}
else if(100+inter*2<righty&&righty<100+inter*3) {Std.mtof(scale[2]) => freq;}
else if(100+inter*3<righty&&righty<100+inter*4) {Std.mtof(scale[3]) => freq;}
else if(100+inter*4<righty&&righty<100+inter*5) {Std.mtof(scale[4]) => freq;}
else if(100+inter*5<righty) {Std.mtof(scale[5]) => freq;}
if(rightz>50) {Math.fabs(rightz*(0.05)) => vib.freq;}
else {0 => vib.freq;}
freq + vib.last()*20 => sound.freq;
}
}
}
fun void left(){
while(true)
{
lefthpos => now;
while(lefthpos.nextMsg()!= 0)
{
lefthpos.getFloat() => float leftx;
lefthpos.getFloat() => float lefty;
lefthpos.getFloat() => float leftz;
if(lefty > 150)
{
Math.fabs(lefty*(0.001)) => sound.gain;
}
else
{
0 => sound.gain;
}
}
}
}
spork ~ right();
spork ~ left();
while(true) 1::second=>now;