Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/extra_curricular5_xp.ck
Created November 9, 2013 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/7385877 to your computer and use it in GitHub Desktop.
Save zeffii/7385877 to your computer and use it in GitHub Desktop.
<<< "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;
}
fun int inArray(int token, int arr[]){
/*
tests membership of an array
*/
for(0 => int i; i<arr.cap(); i++){
if (arr[i]==token) return 1;
}
return 0;
}
// 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.021);
cave.delay(426::ms);
cave.max(3679::ms); // 350 is also nice
cave.mix(0.31); //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;
// set extra delay parameters
mf => Gain rmaster => DelayL delay2 => JCRev rvb2 => Chorus chr => dac;
rmaster.gain(0.0); // to 0.5
rvb2.mix(0.022); //0.032
chr.modFreq(0.22);
chr.modDepth(0.02);
chr.mix(0.4); // 0.2
2*.75::second => delay2.max => delay2.delay;
rmaster => Gain delayGain => DelayL delay3;
delayGain.gain(0.04);
delay3 => rvb2;
5*.75::second => delay3.max => delay3.delay;
delay3 => rvb2;
delay2 => Pan2 delaypan1 => dac;
delay3 => Pan2 delaypan2 => dac;
delaypan1.pan(-0.8);
delaypan2.pan(0.8);
// 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..... ........"
] @=> 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;
// stab vol
0.0 => float synth_vol;
0.002 => float delta_vol;
1 => int direction;
// fx vol slower
0.0 => float fx_vol;
0.005 => float fx_delta_vol;
1 => int fx_direction;
26 => int hat_change;
while(beat<64){
<<< "beat:", beat >>>;
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
if (beat > hat_change) {
8::ms => a;
32::ms => d;
}
noise_hat.gain(.34);
hatEnv.set(a,d,s,r);
hatEnv.keyOn(); // start attack
}
// STABS!
stab_parts[0][i] => int stab_trigger;
if (inArray(beat, [32,43,54])){
stab_parts[1][i] => stab_trigger;
}
cave.delay(426::ms);
if (beat==31 && i > 7 ){
cave.delay(1.5*219::ms); // 626 nice
}
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;
if (inArray(beat, [1,2,32,33])){
120 => lfo; // static at 160 is good
0.2 => dpth; // static at 0.9 is fine.
}
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;
}
// pre fx 1
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 >>>;
if (beat>20){
// pre fx 2 , this shall kick in a little later
if (fx_vol <= 0.8 && fx_direction==1) {
fx_delta_vol +=> fx_vol;
} else {
-1 => fx_direction;
}
if (fx_vol >= 0.0 && fx_direction==-1) {
fx_delta_vol -=> fx_vol;
} else {
1 => fx_direction;
}
rmaster.gain(fx_vol);
<<< fx_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 valu9s
if (trigger==1){
0 => samples[j].pos;
if (j==0){
2818 => samples[j].pos;
1.16 => samples[j].rate;
if (beat > 0 && beat < 44) {
3196 => samples[j].pos;
1.76 => samples[j].rate;
}
3.2 => samples[j].gain;
// piggyback this sample trigger for basss
// set a, d, s, and r
.3 => sin_bass.gain;
47 => sin_bass.freq;
32::ms => dur a; // attack time
113::ms => dur d; // decay time
0.013 => float s; // sustain level
100::ms => dur r; // release time
bassEnv.set(a,d,s,r);
if (beat>1 && beat < 44){
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){ // hat
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;
// hijack offbeat
if (beat > hat_change){
1130 => samples[3].pos;
samples[3].rate(2.84);
samples[3].gain(0.11);
}
}
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