//MovieTrack.ck //220b //Emily Graber ///////////////////////// load file ///////////////////////////////////////// SndBuf sequence => Envelope e => NRev rev => dac; dac => WvOut w => blackhole; rev.mix(0); e.duration(10::ms); sequence.chunks(0); "C:/Users/emgraber/Documents/Stanford/Paul/sequence1.wav" => string filename; filename => sequence.read; "C:/Users/emgraber/Documents/Stanford/Paul/sequence1Granular.wav" => w.wavFilename; ///////////////////////// variables ////////////////////////////////////////// float TimeScale; 0 => float mix; //////////////////////// hid objects //////////////////////////////////////// // which mouse 0 => int device; // get from command line if( me.args() ) me.arg(0) => Std.atoi => device; Hid hi; HidMsg msg; // try if( !hi.openMouse( device ) ) me.exit(); <<< "mouse '" + hi.name() + "' ready...", "" >>>; Hid type; HidMsg typemsg; if( !type.openKeyboard( device ) ) me.exit(); <<< "keyboard '" + type.name() + "' ready...", "" >>>; /////////////////////// infinite time loop ////////////////////////////// while( true ) { // wait on eventhdu hi => now; //type => now; if( type.recv( typemsg ) ) { spork ~ revMix(); if( typemsg.key == 44 ){//spacebar break; } continue; } // loop over messages if( hi.recv( msg ) ) { if( msg.deltaY < 0 ) { sequenceRateHigh() => TimeScale; 1 => e.keyOn; Std.rand2(0,sequence.samples()) => sequence.pos; (1/(TimeScale*TimeScale))*10::ms => now; 1 => e.keyOff; 10::ms => now; } if( msg.deltaY > 0 ) { sequenceRateLow() => TimeScale; 1 => e.keyOn; Std.rand2(0,sequence.samples()) => sequence.pos; (1/(TimeScale*TimeScale))*1::ms => now; 1 => e.keyOff; 10::ms => now; } } } fun float sequenceRateHigh(){ sequence.rate(Std.rand2f(1, 1.9)) => float a; return a; } fun float sequenceRateLow(){ sequence.rate(Std.rand2f(0.1,0.9)) => float a; return a; } fun void revMix(){ if (typemsg.key == 82){ 0.01 +=> mix; rev.mix(mix);} if (typemsg.key == 81){ 0.01 -=> mix; rev.mix(mix);} /*if (typemsg.key<81 || typemsg.key>82 ) // uncomment to use the drone function { drone(typemsg.key); }*/ } fun void drone(int key){ SinOsc m => SinOsc c => Envelope env => NRev reverb => dac; env.duration(2::second); reverb.mix(0.5); c.sync(2); m.gain(0.5*key); c.gain(0.4); c.freq(key); //m.freq(Std.mtof(key)); //m.gain(0.8); 1 => env.keyOn; 2::second => now; 1 => env.keyOff; 5::second => now; } // /*fun void playStuff(){ if( typemsg.key == 81 || typemsg.key == 82 ) { spork ~ revMix(); } if( typemsg.key < 81 || typsmsg.key > 82 ) { typemsg.key => int key; spork ~ drone(key); 11::second => now; } } */ w.closeFile();