-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_LiSaHID.ck
74 lines (67 loc) · 1.53 KB
/
06_LiSaHID.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
// LiSa HID
// sound chain
adc => LiSa mic => dac;
Hid hi;
HidMsg msg;
0 => int device;
if (!hi.openKeyboard(device)) me.exit();
<<< hi.name() + " is fully operational.", "">>>;
// variables
8::second => dur measureTime;
dur recTime;
int recOff, playOff;
while (true) {
hi => now;
while (hi.recv(msg)) {
if (msg.isButtonDown()) {
if (msg.ascii == 96) {
0 => recOff;
1 => playOff;
spork ~ record();
}
if (msg.ascii == 49) {
0 => playOff;
spork ~ play();
}
}
}
if (msg.isButtonUp()) {
if (msg.ascii == 96) {
1 => recOff;
}
if (msg.ascii == 49) {
1 => playOff;
}
}
}
// recording function
fun void record() {
measureTime => mic.duration;
1 => mic.record;
<<< "Recording", "" >>>;
now => time past;
while (recOff == 0) {
1::samp => now;
}
now => time present;
present - past => recTime;
0 => mic.record;
<<< "Recorded for", recTime/second, "seconds." >>>;
<<< "------------------------------", "" >>>;
}
fun void play() {
// notice that I am not setting the playPos
<<< "Playing", "" >>>;
<<< "------------------------------", "" >>>;
// turns on looping
mic.loop(1);
// turns on bidirectionality
mic.bi(0);
// sets end of loop, REQUIRED
mic.loopEnd(recTime);
mic.play(1);
while (playOff == 0) {
1::samp => now;
}
mic.play(0);
}