// name: playScale.ck // desc: this is not a starter code. // Try to change is as much as possible! // It maps the scale to the elevation axis // when the pedal is pressed. 6 => int numOsc; SinOsc osc[numOsc] => Gain gain[numOsc] => Gain master => JCRev reverb => dac; // set gain 0 => master.gain; // set reverb dry/wet gain 0.15 => reverb.mix; fun void sineGen(int freq) { for (int i; i osc[i].freq; 1/Math.pow((i+1),2) => osc[i].gain; 0.2 => gain[i].gain; } } [60, 63, 65, 67, 70, 72] @=> int pitchScale[]; 0.2 => float minZ; 0.5 => float maxZ; 0.05 => float incZ; 0 => int pedal; ////////////////////////////////////////////////////// // modified from; // name: gametra.ck // desc: gametrak boilerplate example // // author: Ge Wang (ge@ccrma.stanford.edu) // date: summer 2014 // 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(); // main loop while( true ) { if (pedal == 1){ gt.axis [2] => master.gain; minZ => float j; while (j < maxZ){ if (gt.axis[5] > j){ Std.ftoi((j-minZ)/incZ) => int num; <<< "num:", num >>>; sineGen(pitchScale[num]); } j + incZ => j; } } //else 0 => master.gain; // map axis data to reverb mix and delay //gt.axis[1]/4 + reverb.mix() => reverb.mix; // synchronize to display 100::ms => now; } // 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" >>>; 1 => pedal; } // joystick button up else if( msg.isButtonUp() ) { <<< "button", msg.which, "up" >>>; 0 => pedal; } } } }