// max factor 0.5 => float rate; // gain to pan to dac Gain g => dac; //Gain g => NRev r1, r2;// => NRev r2; g => r1 => r2; // stereo from here r1 => dac.left; r2 => dac.right; // set gain 0.5 => g.gain; // set mix 0.1 => r1.mix => r2.mix; SndBuf pegs[6]; ADSR e[6]; // load files me.sourceDir() + "num-2.wav" => pegs[0].read; me.sourceDir() + "ta-2.wav" => pegs[1].read; me.sourceDir() + "thom-2.wav" => pegs[2].read; me.sourceDir() + "dhin-2.wav" => pegs[3].read; me.sourceDir() + "cha-2.wav" => pegs[4].read; me.sourceDir() + "dheem-2.wav" => pegs[5].read; int beats4[6][8]; int beats3[6][6]; int beats5[6][5]; int beats7[6][7]; [1,0,0,0,0,0,0,0] @=> beats4[0];//num [0,1,0,0,1,0,0,1] @=> beats4[1];//ta [1,0,1,1,0,1,1,0] @=> beats4[2];//thom [0,0,1,1,0,1,1,0] @=> beats4[3];//dhin [0,0,0,0,0,0,0,0] @=> beats4[4];//cha [0,0,0,0,0,0,0,0] @=> beats4[5];//dheem [1,0,0,0,0,0] @=> beats3[0]; [0,1,0,0,1,0] @=> beats3[1]; [1,0,1,1,0,1] @=> beats3[2]; [0,0,1,1,0,1] @=> beats3[3]; [0,0,0,0,0,0] @=> beats3[4]; [0,0,0,0,0,0] @=> beats3[5]; [1,0,1,0,0] @=> beats5[0]; [0,1,0,0,1] @=> beats5[1]; [1,0,1,1,0] @=> beats5[2]; [0,0,0,1,0] @=> beats5[3]; [0,0,0,0,0] @=> beats5[4]; [0,0,0,0,0] @=> beats5[5]; [1,0,1,0,1,0,0] @=> beats7[0]; [0,1,0,1,0,0,1] @=> beats7[1]; [1,0,1,0,1,1,0] @=> beats7[2]; [0,0,0,0,0,1,0] @=> beats7[3]; [0,0,0,0,0,0,0] @=> beats7[4]; [0,0,0,0,0,0,0] @=> beats7[5]; // connect to gain for( 1 => int i; i < pegs.cap(); i++ ) { pegs[i] => g; g => e[i] => dac; 0.0 => e[i].gain; e[i].keyOff(); } 0 => int dest; 1 => int jump; 1 => int drumsOn; 0 => int randomize; 400 => external float bpm; 1::minute / bpm => dur T; T - (now % T) => now; (60000/bpm $ int) => int wait => int the_wait; 500 => external int attack; 0 => external int base; beats3 @=> int current[][]; external Event play, done; fun void perc(int x) { while(true) { 0 => int i; play => now; while (i < current[dest].cap()) { if (drumsOn == 1 || g.gain() >= 0) { x => dest; rate => pegs[dest].rate; } if (drumsOn == 0 ) { g.gain() - 0.001 => g.gain; g.gain()/2 => e[dest].gain; } if (drumsOn == 2 && g.gain() <= 0.5) { <<<"here", g.gain() >>>; 0.05 => e[dest].gain; g.gain() + 0.01 => g.gain; } if (current[dest][i] == 1) { 0 => pegs[dest].pos; e[dest].keyOn(); } else if (current[dest][i] == 0) { e[dest].keyOff(); } (60000/bpm $ int) => int wait => int the_wait; (the_wait)::ms => now; (i + 1) => i; } done.signal(); } } [beats3, beats4, beats5, beats7] @=> int allbeats[][][]; fun void randomBeats() { while(true) { if (randomize == 0) { <<< " not randomizing" >>>; play.broadcast(); done => now; } else { <<< "Randomizing">>>; Math.random2(0,3) => int nadai; <<>>; allbeats[nadai] @=> current; play.broadcast(); done => now; } } } for (0 => int i; i < 6; i++) { spork ~ perc(i); } spork ~ randomBeats(); -1 => int soundscape; fun void keyboard() { // HIDAB Hid hi; HidMsg msg; // which keyboard 0 => int device; // get from command line if( me.args() ) me.arg(0) => Std.atoi => device; // open keyboard (get device number from command line) if( !hi.openKeyboard( device ) ) me.exit(); <<< "keyboard '" + hi.name() + "' ready", "" >>>; while(true) { hi => now; // messages received while( hi.recv( msg ) ) { if( msg.isButtonDown()) { <<< msg.ascii >>>; if (msg.ascii == 69) { 0 => drumsOn; } if (msg.ascii == 66) { attack - 50 => attack; base + 3 => base; <<< attack >>>; <<< base >>>; } if (msg.ascii == 65) { attack + 50 => attack; base - 3 => base; <<< attack >>>; <<< base >>>; } if (msg.ascii == 61) { 1 => drumsOn; } if (msg.ascii == 46) { // > r1.mix() + 0.01 => r1.mix => r2.mix; <<< r1.mix() >>>; } if (msg.ascii == 44) { // < r1.mix() - 0.01 => r1.mix => r2.mix; <<< r1.mix() >>>; } if (msg.ascii == 91) { // [ wait + 20 => wait; wait => the_wait; <<< the_wait >>>; } if (msg.ascii == 93) { // ] wait - 20 => wait; wait => the_wait; <<< the_wait >>>; } if (msg.ascii == 48) { // < rate * 1.2 => rate; <<< rate >>>; } if (msg.ascii == 57) { // < rate * 0.8 => rate; <<< rate >>>; } if (msg.ascii == 49) { for (1 => int i; i <= 20; i++) { bpm + 10 => bpm; <<< bpm >>>; 0.5::second => now; } } if (msg.ascii == 50) { for (1 => int i; i <= 20; i++) { bpm - 10 => bpm; <<< bpm >>>; 0.5::second => now; } } if (msg.ascii == 51) { // 3 = Tisram beats3 @=> current; } if (msg.ascii == 52) { // 4 = Chatusram beats4 @=> current; } if (msg.ascii == 53) { // 5 = Khandam beats5 @=> current; } if (msg.ascii == 55) { // 5 = Khandam beats7 @=> current; } if (msg.ascii == 82) { // 5 = Khandam if (randomize == 0) { 1 => randomize; } else { 0 => randomize; } } if (msg.ascii == 83) { // 5 = Khandam if (soundscape == -1) { Machine.add(me.sourceDir() + "soundscape1.ck") => soundscape; } else { Machine.remove(soundscape); -1 => soundscape; } } } } 1::ms => now; } } keyboard();