-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment_4_MegamanRocks.ck
346 lines (273 loc) · 9.54 KB
/
Assignment_4_MegamanRocks.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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
//Assignment 4
<<< "Assignment_4_MegamanRocks" >>>;
//Scale definition Eb mixolidian
[51, 53, 55, 56, 58, 60, 61] @=> int E_mix[];
//Duration definitions
0.6::second => dur quarter;
quarter/2 => dur eighth;
quarter/4 => dur sixteenth;
quarter*2 => dur half;
quarter*4 => dur whole;
//Function to octave midi notes
fun int octavem(int note, int oct)
{
int newnote;
note + 12*oct => newnote;
return newnote;
}
/*Function, compass execution receives an array of instruments (SawOscs) with the respective notes (represented by
it's grade on the scale) to be executed by each instrument one and the octave of each note, also receives an array
of SndBuf and the "hits" each SndBuff object shall execute, finally receives the beat, and the scale in order to
convert to Midi notes, doesn't return anything*/
fun void compass_Exe (SawOsc melo[], SndBuf perc[], int notes[][], int oct[][], int hits[][], dur beat, int scale[])
{
for(0 => int i; i < notes[0].cap(); i++)
{
for(0 => int j; j < notes.cap(); j++)
{
Std.mtof(octavem(scale[notes[j][i]], oct[j][i])) => melo[j].freq;
}
for(0 => int j; j < hits.cap(); j++)
{
if(hits[j][i] == 1) 0 => perc[j].pos;
}
beat => now;
}
}
/*Function to harmonize, Taces the length of the scale, the grades and
the octaves of the notes to be harmonized, and finally the interval
returns a two dimension array containing the new grades and octaves*/
fun int[][] harmonize (int scale_len, int sect[], int oct[], int inter)
{
int harm[2][sect.cap()];
for(0 => int i; i < sect.cap(); i++)
{
if(inter > 0)
{
if(sect[i] + inter >= scale_len)
{
sect[i] + inter - (scale_len) => harm[0][i];
oct[i] + 1 => harm[1][i];
}
else
{
sect[i] + inter => harm[0][i];
oct[i] => harm[1][i];
}
}
else
{
if(sect[i] + inter < 0)
{
scale_len + (sect[i] + inter) => harm[0][i];
oct[i] - 1 => harm[1][i];
}
else
{
sect[i] + inter => harm[0][i];
oct[i] => harm[1][i];
}
}
}
return harm;
}
// Sound network
Gain instru => Gain master => dac;
Gain perc => master;
1 => master.gain;
0.5 => instru.gain;
0.5 => perc.gain;
SawOsc mel[3];
mel[0] => Pan2 pmel1 => instru;
mel[1] => Pan2 pmel2 =>instru;
mel[2] => instru;
SndBuf drums[4];
drums[0] => Pan2 pdrums1 => perc;
drums[1] => perc;
drums[2] => Pan2 pdrums2 => perc;
drums[3] => Pan2 pdrums3 =>perc;
//Set gains for each instrument and SndBUff
1.0/3.0 => mel[0].gain;
1.0/3.0 => mel[1].gain;
1.0/3.0 => mel[2].gain;
1.0/3.0 => mel[2].gain;
1.0 => drums[0].gain;
1.0 => drums[1].gain;
1.0 => drums[2].gain;
1.0 => drums[3].gain;
//Set Panning
-1 => pmel1.pan;
1 => pmel1.pan;
0.2 => pdrums1.pan;
-0.2 => pdrums2.pan;
-0.4 => pdrums3.pan;
//Load Samples
me.dir() + "/audio/snare_01.wav" => drums[0].read;
me.dir() + "/audio/kick_01.wav" => drums[1].read;
me.dir() + "/audio/hihat_01.wav" => drums[2].read;
me.dir() + "/audio/hihat_04.wav" => drums[3].read;
//Set PlayHeads to end
drums[0].samples() => drums[0].pos;
drums[1].samples() => drums[1].pos;
drums[2].samples() => drums[2].pos;
drums[3].samples() => drums[3].pos;
//Set Rates
1 => drums[0].rate;
1 => drums[1].rate;
1 => drums[2].rate;
1 => drums[3].rate;
//Grades of the first figure for lead instruments
[0, 4, 0, 4, 0, 1, 0, 4, 0, 4, 1, 2, 0, 4, 2, 1, 0, 5, 0, 1] @=> int fl1[];
//Octaves of the first figure for lead isntruments
[2, 1, 2, 1, 2, 2, 2, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2] @=> int ol1[];
//Grades of the first figure for bass instruments
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] @=> int fb1[];
//Octaves of the first figure for bass isntruments
[0, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] @=> int ob1[];
//Hits of the snare
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] @=> int s1[];
//Hits of the kick
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] @=> int k1[];
//Hits of the closed Hihat
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0] @=> int ch1[];
//Hits of the Open hihat
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0] @=> int oh1[];
//assignation to multidimensional array in order to sedn to the function
[fl1, fl1, fb1] @=> int f[][];
[ol1, ol1, ob1] @=> int o[][];
[s1, k1, ch1, oh1] @=> int d[][];
//Execute the first figure twice
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//Harmonize the lead of the first figure
harmonize(E_mix.cap(), fl1, ol1, 2) @=> int fh1[][];
//Assign the harmony to the multidimensional array
fh1[0] @=> f[1];
fh1[1] @=> o[1];
//kill bass
0 => mel[2].gain;
//change drum pattern, use of random "because i have to..."
[Math.random2(0,1), 0, 0, 0, 0, 0, 0, 0, Math.random2(0,1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] @=> s1;
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] @=> k1;
[1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0] @=> ch1;
[Math.random2(0,1), 0, 0, 0, 0, 0, 0, 0, Math.random2(0,1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] @=> oh1;
//Assign to multidimensional array
[s1, k1, ch1, oh1] @=> d;
//Execute figure with harmony and changed drum pattern twice
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//-----FIGURE 2-----
//Second lead figure, for first lead instrument
[2, 1, 0, 6, 5, 4, 6, 0, 6, 2, 2, 1, 0, 6, 5, 4, 6, 0, 6, 2] @=> fl1;
[2, 2, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2, 1, 1] @=> ol1;
//Arpeggios for second lead instrument
[2, 6, 2, 3, 6, 3, 2, 6, 2, 2, 2, 6, 2, 3, 6, 3, 2, 6, 2, 2] @=> int fl2[];
[0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0] @=> int ol2[];
//New bass line
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] @=> fb1;
[-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0] @=> ob1;
//Bring back the bass
1.0/3.0 => mel[2].gain;
//Assign to multidimensional array
[fl1, fl2, fb1] @=> f;
[ol1, ol2, ob1] @=> o;
//Change drum pattern
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0] @=> s1;
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] @=> k1;
[0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1] @=> ch1;
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0] @=> oh1;
//Assign to multidimensional array
[s1, k1, ch1, oh1] @=> d;
//execute the figure
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//Bring WHOLE Figure 2 a fourth up
harmonize(E_mix.cap(), fl1, ol1, 3) @=> fh1;
fh1[0] @=> f[0];
fh1[1] @=> o[0];
harmonize(E_mix.cap(), fl2, ol2, 3) @=> fh1;
fh1[0] @=> f[1];
fh1[1] @=> o[1];
harmonize(E_mix.cap(), fb1, ob1, 3) @=> fh1;
fh1[0] @=> f[2];
fh1[1] @=> o[2];
//Execute the melody a fourth up
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//Bring WHOLE Figure 2 a secondth up
harmonize(E_mix.cap(), fl1, ol1, 1) @=> fh1;
fh1[0] @=> f[0];
fh1[1] @=> o[0];
harmonize(E_mix.cap(), fl2, ol2, 1) @=> fh1;
fh1[0] @=> f[1];
fh1[1] @=> o[1];
harmonize(E_mix.cap(), fb1, ob1, 1) @=> fh1;
fh1[0] @=> f[2];
fh1[1] @=> o[2];
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//Bring WHOLE Figure 2 a fifth up
harmonize(E_mix.cap(), fl1, ol1, 4) @=> fh1;
fh1[0] @=> f[0];
fh1[1] @=> o[0];
harmonize(E_mix.cap(), fl2, ol2, 4) @=> fh1;
fh1[0] @=> f[1];
fh1[1] @=> o[1];
harmonize(E_mix.cap(), fb1, ob1, 4) @=> fh1;
fh1[0] @=> f[2];
fh1[1] @=> o[2];
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//change Bass line
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] @=> fb1;
[-1, -1, 0, -1, 0, -1, -1, 0, -1, 0, -1, -1, 0, -1, 0, -1, -1, 0, -1, 0] @=> ob1;
[fl1, fl2, fb1] @=> f;
[ol1, ol2, ob1] @=> o;
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] @=> s1;
[1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1] @=> k1;
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0] @=> ch1;
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0] @=> oh1;
[s1, k1, ch1, oh1] @=> d;
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//Same process as before
harmonize(E_mix.cap(), fl1, ol1, 3) @=> fh1;
fh1[0] @=> f[0];
fh1[1] @=> o[0];
harmonize(E_mix.cap(), fl2, ol2, 3) @=> fh1;
fh1[0] @=> f[1];
fh1[1] @=> o[1];
harmonize(E_mix.cap(), fb1, ob1, 3) @=> fh1;
fh1[0] @=> f[2];
fh1[1] @=> o[2];
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//-------------------------------------------------
harmonize(E_mix.cap(), fl1, ol1, 1) @=> fh1;
fh1[0] @=> f[0];
fh1[1] @=> o[0];
harmonize(E_mix.cap(), fl2, ol2, 1) @=> fh1;
fh1[0] @=> f[1];
fh1[1] @=> o[1];
harmonize(E_mix.cap(), fb1, ob1, 1) @=> fh1;
fh1[0] @=> f[2];
fh1[1] @=> o[2];
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//-------------------------------------------------
harmonize(E_mix.cap(), fl1, ol1, 4) @=> fh1;
fh1[0] @=> f[0];
fh1[1] @=> o[0];
harmonize(E_mix.cap(), fl2, ol2, 4) @=> fh1;
fh1[0] @=> f[1];
fh1[1] @=> o[1];
harmonize(E_mix.cap(), fb1, ob1, 4) @=> fh1;
fh1[0] @=> f[2];
fh1[1] @=> o[2];
compass_Exe(mel, drums, f, o, d, sixteenth, E_mix);
//set last note
Std.mtof(octavem(E_mix[0], 3)) => mel[0].freq;
Std.mtof(octavem(E_mix[0], 2)) => mel[1].freq;
Std.mtof(octavem(E_mix[0], 0)) => mel[2].freq;
0 => drums[0].pos;
0 => drums[1].pos;
0 => drums[2].pos;
//fadeout (should've done a function for this)
for(0 => int i ; i <= 100; i++)
{
master.gain() - 0.01 => master.gain;
sixteenth/4 => now;
}