Cracked Documentation examples/sequencing.html

Loop

//set up sounds __().sine(600).adsr().delay().dac(); __("adsr").reverb().gain(.5).connect("dac").play(); //configure sequencer- 8 steps, each step is 400 ms __.loop({steps:8,interval:400}); //bind the sine and adsr to step events from loop //the callback function executes on each step __("sine,adsr").bind("step",function(index,data,array){ //callback function is passed 3 parameters: the current index, //the element in the array cooresponding to the index and a reference to //data array itself. //random pitch from major scale __.frequency( __.pitch2freq( __.scales("major")[__.random(0,6)] + __.random(5,7) * 12 ) ); //if the current array element = 1, trigger the adsr if(data) { //100 millisecond envelope __.adsr("trigger",0.1); } //callback interates over the data array },[1,1,0,0,1,0,0,1]); //start the loop __.loop("start");

//set up some sounds __().sine({frequency:180,id:"bass"}).lowpass(120).compressor({release:0}).dac(); __().sine(80).adsr({id:"kick",envelope:0.1}).connect("compressor"); //100 ms envelope __().pink().adsr({id:"snare",envelope:0.05}).connect("compressor"); //50 ms __().white().adsr({id:"hihat",envelope:0.01}).connect("compressor").play(); //10 ms //configure sequencer __.loop({steps:8,interval:150}); //bind first sine to step events //callback iterates thru the data array passed as the 2nd arg to bind __("#bass").bind("step",function(index,data,array){ //change the frequency based on incoming data (data) ? __.frequency(220) : __.frequency(110); },[1,1,1,1,0,0,0,0]); __("#kick").bind("step",function(index,data,array){ if(data) { __.adsr("trigger"); } },[1,1,0,0,1,0,1,0]); __("#snare").bind("step",function(index,data,array){ if(data) { __.adsr("trigger"); } },[0,0,0,1,0,0,0,1]); __("#hihat").bind("step",function(index,data,array){ if(data) { __.adsr("trigger"); } },[1,1,1,1,1,1,1,1]); //start it __.loop("start");

//set up sounds- start sine w/ freq = 0 __().sine(0).dac().play(); //configure loop- step length = 100 ms __().loop({steps:10,interval:100}); //bind callback on the sine. listen for steps __("sine").bind("step",function(index,data,array){ //init variables, store properties on the array //so we can persist values between callbacks var upper=9; array.dir = __.isUndef(array.dir) ? "up" : array.dir; array.count = __.isUndef(array.count) ? 0 : array.count; //go up, then come back. repeat. if(index===0 && array.dir==="up" && array.count < upper) { array.count++; } else if (index===0 && array.dir==="up" && array.count === upper) { array.reverse(); array.dir = "down"; array.count--; } else if(index===0 && array.dir==="down" && array.count > 0) { array.count--; } else if(index===0 && array.dir==="down" && array.count === 0) { array.reverse(); array.dir = "up"; array.count++; } //calculate pitch var p = data+(array.count*10); //set frequency with the new value __.frequency(__.pitch2freq(p)); },[30,31,32,33,34,35,36,37,38,39]); //start it __().loop("start");