-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeviDemo.ck
More file actions
182 lines (145 loc) · 3.03 KB
/
deviDemo.ck
File metadata and controls
182 lines (145 loc) · 3.03 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
////////////////////
// Global Setup
// Robot server
OscOut out;
("chuckServer.local", 50000) => out.dest;
////////////////////
// Functions and Composition
// Send notes to MahaDeviBot
fun void deviPlay(int note, int vel){
out.start("/devibot");
out.add(note);
out.add(vel);
out.send();
}
fun void drumPlay(int note, int vel){
out.start("/drumBot");
out.add(note);
out.add(vel);
out.send();
}
120 => int bpm;
(60.0/bpm)::second => dur quarter;
4::quarter => dur measure;
// Print Title
chout <= "\n\tMahaDeviBot Demo" <= IO.newline();
chout <= "\tTempo:" + bpm + "\n" <= IO.newline();
[1, 4, 5, 6, 7, 8, 10, 11] @=> int drums[];
// test working drums
// for(0 => int i; i<drums.size(); i++){
// <<< drums[i] >>>;
// deviPlay(drums[i],127);
// 1::second => now;
// }
int songForm;
int bellPattern[8];
fun float velRandom_pow2(){
return Math.pow(Math.random2f(0,1),2);
}
fun float velRandom_pow3(){
return Math.pow(Math.random2f(0,1),3);
}
fun float velRandom_pow4(){
return Math.pow(Math.random2f(0,1),4);
}
fun float velCos_pow2(){
return Math.pow(Math.cos(now/1::second*2*Math.PI),2);
}
fun void bellGen() {
string pattern;
for(0 => int i; i<bellPattern.size(); i++){
Math.random2(0,1) => bellPattern[i];
(Std.itoa(bellPattern[i]) + " ") +=> pattern;
}
// <<< "Bell pattern:", pattern >>>;
}
fun void drumPattern1(){
while(true){
if(songForm == 0){
((1-velRandom_pow2())*24+5) $ int => int vel1;
(velRandom_pow4()*40+20) $ int => int vel2;
deviPlay(10, vel1);
deviPlay(11, vel2);
.25::quarter => now;
} else {
.25::quarter => now;
}
}
}
int newPat;
fun void bell1(){
bellGen();
while(true){
if(songForm == 0){
0 => newPat;
for(0 => int i; i<bellPattern.size(); i++){
(velRandom_pow3()*80+20) $ int => int nextVel;
if(bellPattern[i]) deviPlay(5, nextVel);
1::quarter => now;
}
} else {
if(!newPat) {
bellGen();
1 => newPat;
}
1::quarter => now;
}
}
}
fun void drumPattern2(){
while(true){
if(songForm == 1){
(velRandom_pow2()*127) $ int => int vel1;
(velCos_pow2()*127) $ int => int vel2;
deviPlay(10, vel1);
deviPlay(11, vel2);
.25::quarter => now;
} else {
.25::quarter => now;
}
}
}
fun void tambourine2(){
while(true){
if(songForm == 1) {
deviPlay(7,Math.random2(80,100));
1::quarter => now;
} else {
1::quarter => now;
}
}
}
fun void bassDrum2(){
while(true){
if(songForm == 1){
drumPlay(1,Math.random2(30,35));
.75::quarter => now;
drumPlay(1,Math.random2(27,30));
.25::quarter => now;
drumPlay(0,Math.random2(50,55));
2::quarter => now;
drumPlay(0,Math.random2(53,60));
1::quarter => now;
} else 2::quarter => now;
}
}
fun void crash2(){
while(true){
if(songForm == 1){
drumPlay(8,127);
4::measure => now;
} else 4::measure => now;
}
}
spork ~ drumPattern1();
spork ~ bell1();
spork ~ drumPattern2();
spork ~ tambourine2();
spork ~ bassDrum2();
spork ~ crash2();
repeat(2) {
0 => songForm;
8::measure => now;
1 => songForm;
8::measure => now;
}