-
-
Save zeffii/7380669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<<< "Extra Curricularr - drum machine 32 note + swing" >>>; | |
// utility functions | |
fun string repr_int_array(int arr[]){ | |
/* | |
this returns a string representation of an int array, | |
useful for debug printing. | |
*/ | |
"[" + Std.itoa(arr[0]) => string s; | |
for (1 => int i; i < arr.cap(); i++){ | |
s + "," + Std.itoa(arr[i]) => s; | |
} | |
return s + "]"; | |
} | |
fun int[][] stepify(string sequence_data[]){ | |
/* | |
this function converts a string array to an int array, | |
it accepts fuzzy formatting: | |
"1..1..1..1.." becomes [1,0,0,1,0,0,1,0,0,1,0,0] | |
"1..1. .1..1.." also becomes [1,0,0,1,0,0,1,0,0,1,0,0] | |
*/ | |
sequence_data.cap() => int parts; | |
32 => int steps; // hard code for now | |
<<< parts, steps >>>; | |
int data_store[parts][steps]; | |
for(0 => int i; i<sequence_data.cap(); i++){ | |
sequence_data[i] => string seq_string; | |
int part_data[0]; | |
int trigger; | |
//<<< seq_string >>>; | |
for(0 => int j; j < seq_string.length(); j++){ | |
seq_string.substring(j,1) => string token; // crazy | |
if (token == " ") continue; | |
if (token == ".") 0 => trigger; | |
else if (token == "1") 1 => trigger; | |
part_data << trigger; | |
} | |
//<<< repr_int_array(part_data)>>>; | |
part_data @=> data_store[i]; | |
} | |
return data_store; | |
} | |
// setting up sounds | |
Gain master => dac; | |
0.3 => master.gain; | |
Noise noise_hat => ADSR hatEnv => NRev ccr => Echo cave => master; | |
0.2 => noise_hat.gain; | |
ccr.mix(0.02); | |
cave.delay(420::ms); | |
cave.max(3629::ms); // 350 is also nice | |
cave.mix(0.3); | |
SinOsc sin_bass => ADSR bassEnv => master; | |
0.0 => sin_bass.gain; | |
me.dir() + "/audio/" => string path; | |
[ "kick_01.wav", | |
"kick_03.wav", | |
"snare_01.wav", | |
"hihat_03.wav", | |
"click_01.wav", | |
"click_02.wav", | |
"click_03.wav", | |
"click_04.wav", | |
"click_05.wav" | |
] @=> string sample_names[]; | |
sample_names.cap() => int num_wavs; | |
SndBuf samples[num_wavs]; | |
Pan2 pans[num_wavs]; | |
for (0 =>int i; i<num_wavs; i++){ | |
path + sample_names[i] => samples[i].read; | |
samples[i].samples() => samples[i].pos; | |
samples[i] => pans[i] => master; | |
} | |
// patch | |
JCRev rvb => ADSR mf => Echo a => Echo b => Echo c => dac; | |
[62,65,67,69] @=> int notes[]; | |
Rhodey vocs[4]; | |
for(0 => int i; i<vocs.cap(); i++){ | |
Std.mtof(notes[i]) => vocs[i].freq; | |
0.41 => vocs[i].gain; | |
vocs[i] => rvb; // send each voice to the same reverb unit | |
} | |
.8 => rvb.gain; | |
.1 => rvb.mix; | |
1400::ms => a.max => b.max => c.max; | |
750::ms => a.delay => b.delay => c.delay; | |
.10 => a.mix => b.mix => c.mix; | |
// sequences | |
[ | |
"1...1... 1...1... 1...1... 1...1...", | |
"1...1... 1...1... 1...1... 1...1...", | |
"..1...1. ..1...1. ..1...11 ...1..1.", | |
"..1..1.. ..1..1.. ..1..1.. ..1..1..", | |
"..1..... .....1.. ...1..1. .......1", | |
"...1...1 ...11... ...1.1.. ......1.", | |
"....11.. ..1..... .....1.. ....1...", | |
"..1...1. ..1...1. ..1...1. ..1...1.", | |
".......1 ........ ........ ....1..." | |
] @=> string str_seq[]; | |
[ | |
".1.1.... ..1.1... ..1..... ........", | |
"...1...1 .1...1.. 1...1... 1...1..." | |
] @=> string stab_seq[]; | |
stepify(str_seq) @=> int multi_parts[][]; | |
stepify(stab_seq) @=> int stab_parts[][]; | |
multi_parts.cap() => int parts; | |
multi_parts[0].cap() => int steps; | |
int shuffle; | |
float tick_duration; | |
124 => float long_tick; | |
long_tick * .74 => float short_tick; | |
1.0 => float bend; | |
0 => int chords; | |
0 => int beat; | |
0 => int tick; | |
0.0 => float synth_vol; | |
0.01 => float delta_vol; | |
1 => int direction; | |
while(beat<64){ | |
for(0 => int i; i<steps; i++){ | |
i % 2 => shuffle; | |
// simple noise hat | |
if (((i+2) % 4) == 0){ | |
12::ms => dur a; // attack time | |
23::ms => dur d; // decay time | |
0.013 => float s; // sustain level | |
100::ms => dur r; // release time | |
noise_hat.gain(.4); | |
hatEnv.set(a,d,s,r); | |
hatEnv.keyOn(); // start attack | |
} | |
// STABS! | |
stab_parts[0][i] => int stab_trigger; | |
if (stab_trigger){ | |
for(0 => int i; i<vocs.cap(); i++){ | |
Math.random2(157, 162) => int lfo; | |
Math.random2f(0.77, 0.9) => float dpth; | |
vocs[i].lfoSpeed(lfo); // static at 160 is good | |
vocs[i].lfoDepth(dpth); // static at 0.9 is fine. | |
Math.random2f(0.6, 0.8 ) => vocs[i].noteOn; | |
} | |
if (synth_vol <= 0.8 && direction==1) { | |
delta_vol +=> synth_vol; | |
} else { | |
-1 => direction; | |
} | |
if (synth_vol >= 0.0 && direction==-1) { | |
delta_vol -=> synth_vol; | |
} else { | |
1 => direction; | |
} | |
rvb.gain(synth_vol); | |
<<< synth_vol >>>; | |
12::ms => dur a; // attack time | |
Math.random2(110, 119)::ms => dur d; // decay time 113 is fine | |
0.013 => float s; // sustain level | |
100::ms => dur r; // release time | |
mf.set(a,d,s,r); | |
mf.keyOn(); // start attack | |
} | |
// PERCUSSION TRACK | |
for(0 => int j; j<parts; j++){ | |
multi_parts[j][i] => int trigger; | |
// i might trigger using different integer values | |
if (trigger==1){ | |
0 => samples[j].pos; | |
if (j==0){ | |
2818 => samples[j].pos; | |
1.16 => samples[j].rate; | |
3.2 => samples[j].gain; | |
// piggyback this sample trigger for basss | |
// set a, d, s, and r | |
1.2 => sin_bass.gain; | |
50 => sin_bass.freq; | |
2::ms => dur a; // attack time | |
183::ms => dur d; // decay time | |
0.013 => float s; // sustain level | |
100::ms => dur r; // release time | |
bassEnv.set(a,d,s,r); | |
bassEnv.keyOn(); // start attack | |
//bassEnv.keyOff(); // start release | |
} | |
if (j==1){ | |
.4 => samples[j].gain; | |
20 => samples[j].pos; | |
1.08 => samples[j].rate; | |
} | |
if (j==2){ | |
Math.random2f(.1,.2)+0.2 => samples[j].gain; | |
4.3 => samples[j].rate; | |
2200 => samples[j].pos; | |
} | |
if (j==3){ | |
Math.random2f(2.2, 2.4) - 2.0 => samples[j].gain; | |
Math.random2f(3.22, 3.24) - 1.2 => samples[j].rate; | |
8200 => samples[j].pos; | |
} | |
if (j==4){ | |
(Math.random2f(2.2, 2.4) - 1.3) => samples[j].gain; | |
Math.random2f(3.22, 3.24) - 1.1 => samples[j].rate; | |
330 => samples[j].pos; | |
} | |
if (j==5){ | |
(Math.random2f(2.2, 2.4) - 3.3) => samples[j].gain; | |
Math.random2f(3.22, 3.24) - 1.12 => samples[j].rate; | |
600 => samples[j].pos; | |
} | |
if (j==6){ | |
(Math.random2f(2.2, 2.4) - 3.3) => samples[j].gain; | |
Math.random2f(3.22, 3.24) - 4.1 => samples[j].rate; | |
10 => samples[j].pos; | |
} | |
if (j==7){ | |
(Math.random2f(2.2, 2.4) - 3.3) => samples[j].gain; | |
Math.random2f(3.22, 3.24) - 1.1 => samples[j].rate; | |
20 => samples[j].pos; | |
} | |
if (j==8){ | |
(Math.random2f(2.2, 2.4) - 3.3) => samples[j].gain; | |
Math.random2f(3.22, 3.24) - 1.1 => samples[j].rate; | |
30 => samples[j].pos; | |
} | |
} | |
} | |
// TIME | |
if (shuffle==0) long_tick => tick_duration; | |
else short_tick => tick_duration; | |
tick_duration::ms => now; | |
tick++; | |
noise_hat.gain(0.0); // this is the same as writing 0.0 => .. | |
} | |
beat++; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment