// patch Wurley wurley => dac; // offset 57 => int offset; // mapping [ 0, 2, 4, 5 ] @=> int pitch[]; // state transition table [ [ .8, 0.0, 0.2, 0.0 ], // <--- make sure values in each row adds up to 1 [ .3, .1, .5, .1 ], [ 0.0, .65, .25, .1 ], [ .1, .2, .7, 0 ] ] @=> float table[][]; // current state 3 => int state; // go while( true ) { // sound the current state offset + pitch[state] => Std.mtof => wurley.freq; 1 => wurley.noteOn; // generate probability Std.rand2f( 0, 1 ) => float prob; // sum 0 => float sum; // find transition for( int i; i < table[state].size(); i++ ) { // sum probs we've seen so far table[state][i] +=> sum; // check if( sum > prob ) { // i is the next state to transition to i => state; // break out of for break; } } // advance 200::ms => now; }