-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclappersDemo.ck
143 lines (114 loc) · 3.18 KB
/
clappersDemo.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
////////////////////
// Global Setup
// Robot server
OscOut out;
("chuckServer.local", 50000) => out.dest;
// Available clapper notes
[0, 1, 2, 4, 7, 17] @=> int clapper_notes[];
// Clapper status array (playing or idle)
int clapper_status[clapper_notes.size()];
for(int i; i < clapper_status.size(); i++){
0 => clapper_status[i];
}
// Set tempo
BPM.tempo(Math.random2(100, 160));
// Print Title
chout <= "\n\tClappers Demo" <= IO.newline();
chout <= "\tTempo:" + BPM.bpm + "\n" <= IO.newline();
// Print clapper status (debugging)
// spork ~ print_status();
////////////////////
// Composition
start_clappers();
section_A();
section_B();
section_C();
section_B();
mahaDeviBot(8, Math.random2(80, 127));
// DemoMan stop command
DemoMan.clappersDemo.broadcast();
0 => DemoMan.clappers_playing;
// Print End Message
chout <= "\n\tEnd of Demo" <= IO.newline();
////////////////////
// Functions
// Send note to clappers
fun void clappers(int note, int vel){
out.start("/clappers");
out.add(note);
out.add(vel);
out.send();
}
// Initialize all clappers
fun void start_clappers(){
for(0 => int i; i < clapper_notes.size(); i++){
Math.random2(2, BPM.figures.size()-2) => int rand_fig;
(rand_fig == 2 ? Math.random2(1, 4) : Math.random2(1, 8)) => int rand_mod;
spork ~ clap_rhythm(i, rand_fig , rand_mod);
}
}
// Set clapper rhythm
fun void clap_rhythm(int idx, int rhy_idx, int mod){
0 => int counter;
while(true){
if(clapper_status[idx]){
if(counter % mod == 0){
clappers(clapper_notes[idx], Math.random2(10, (127.0/mod) $int));
}
}
BPM.figures[rhy_idx] => now;
counter++;
}
}
// Section A: Play some clappers
fun void section_A(){
chout <= "\n\tSection A" <= IO.newline();
1 => clapper_status[0];
for(1 => int i; i < clapper_notes.size(); i++){
if(maybe){
1 => clapper_status[i];
}
}
mahaDeviBot(8, Math.random2(64, 80));
4::BPM.measure => now;
}
// Section B: Play all clappers
fun void section_B(){
chout <= "\n\tSection B" <= IO.newline();
for(int i; i< clapper_status.size(); i++){
if(!clapper_status[i]){
1 => clapper_status[i];
}
}
4::BPM.measure => now;
}
// Section C: Stop some clappers
fun void section_C(){
chout <= "\n\tSection C" <= IO.newline();
for(int i; i < Math.random2(2, clapper_status.size()-3); i++){
Math.random2(0, clapper_status.size()-1) => int which;
while(!clapper_status[which])
Math.random2(0, clapper_status.size()-1) => which;
0 => clapper_status[which];
}
mahaDeviBot(8, Math.random2(64, 80));
4::BPM.measure => now;
}
// Print clapper status (debugging)
fun void print_status(){
while(true) {
"Playing: " => string status;
for(int i; i < clapper_status.size(); i++){
Std.itoa(clapper_status[i]) +=> status;
}
<<< status >>>;
BPM.quarterNote => now;
}
}
// Send notes to MahaDeviBot
fun void mahaDeviBot(int note, int vel){
out.start("/devibot");
out.add(note);
out.add(vel);
out.send();
}