//Shaker, with amplitude controlled by gametrak Shakers shake => dac; // JCRev r => dac; //setting gain //.95 => r.gain; //set the reverb //.1 => r.mix; //set instrument 22 => shake.which; .95 => shake.gain; // Copy and pasted from gametrak-0.ck // z axis deadzone .032 => float DEADZONE; // which joystick 0 => int device; // get from command line if( me.args() ) me.arg(0) => Std.atoi => device; // data structure for gametrak class GameTrak { // timestamps time lastTime; time currTime; // previous axis data float lastAxis[6]; // current axis data float axis[6]; } // gametrack GameTrak gt; // HID objects Hid trak; HidMsg msg; // open joystick 0, exit on fail if( !trak.openJoystick( device ) ) me.exit(); // print <<< "joystick '" + trak.name() + "' ready", "" >>>; // spork control spork ~ gametrak(); // print spork ~ print(); // print fun void print() { // time loop while( true ) { // values <<< "axes:", gt.axis[0],gt.axis[1],gt.axis[2], gt.axis[3],gt.axis[4],gt.axis[5] >>>; // advance time 100::ms => now; } } // gametrack handling fun void gametrak() { while( true ) { // wait on HidIn as event trak => now; // messages received while( trak.recv( msg ) ) { // joystick axis motion if( msg.isAxisMotion() ) { // check which if( msg.which >= 0 && msg.which < 6 ) { // check if fresh if( now > gt.currTime ) { // time stamp gt.currTime => gt.lastTime; // set now => gt.currTime; } // save last gt.axis[msg.which] => gt.lastAxis[msg.which]; // the z axes map to [0,1], others map to [-1,1] if( msg.which != 2 && msg.which != 5 ) { msg.axisPosition => gt.axis[msg.which]; } else { 1 - ((msg.axisPosition + 1) / 2) - DEADZONE => gt.axis[msg.which]; if( gt.axis[msg.which] < 0 ) 0 => gt.axis[msg.which]; } } } // joystick button down else if( msg.isButtonDown() ) { <<< "button", msg.which, "down" >>>; } // joystick button up else if( msg.isButtonUp() ) { <<< "button", msg.which, "up" >>>; } } } } while(true){ Std.mtof(Math.random2f(60,80)) => shake.freq; 1 => shake.noteOn; // (gt.axis[0] + 1)/2 => shake.energy; // (gt.axis[1]+1)/2 => shake.objects; gt.axis[2] * 2=> shake.gain; // be careful here //0.5 => shake.gain; 100::ms => now; }