// Idea with inspiration from Michael Berger // incoming OSC data values float XYZ[3]; 0.5 => XYZ[0]; 0.5 => XYZ[1]; 0.5 => XYZ[2]; // create our OSC receiver OscRecv rec; 8000 => rec.port; // start listening (launch thread) rec.listen(); rec.event("/accelerometer/0, f") @=> OscEvent accelX; rec.event("/accelerometer/1, f") @=> OscEvent accelY; rec.event("/accelerometer/2, f") @=> OscEvent accelZ; // spork the shreds // OSC listeners spork ~ ListenerAccel(accelX, 0); spork ~ ListenerAccel(accelY, 1); spork ~ ListenerAccel(accelZ, 2); 1 => int check; fun void ListenerAccel( OscEvent event, int index ) { while ( true ) { event => now; while( event.nextMsg() ) { if (check == 1) { <<<"message received">>>; 0 => check; } event.getFloat() => XYZ[index]; //<<>>; } } } [60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83, 84] @=> int array[]; 1 => int playAmen; 0 => int notePlaying; while( true ) { //<<<"this value: ">>>; //<<>>; //<<>>; //<<>>; if (XYZ[2] < .08 && XYZ[0] < .7 && XYZ[0] > .3 && XYZ[1] < .7 && XYZ[1] > .3 ) { if (playAmen == 1) { 0 => playAmen; spork ~ amen(); } } if (XYZ[2] >= .8 && playAmen == 0) { 1 => playAmen; 1::second => now; } 0.6 => float thresh; if ((XYZ[0] > thresh || XYZ[1] > thresh) && notePlaying == 0) { 1 => notePlaying; 0.0 => float xVal; 0.0 => float yVal; if (XYZ[0] > thresh) { XYZ[0] - thresh => xVal; xVal * 8.5 / (1 - thresh) => xVal; }else { 0.0 => xVal; //Std.rand2f(0, 5) => xVal; } if (XYZ[1] > thresh) { XYZ[1] - thresh => yVal; yVal * 8.5 / (1 - thresh) => yVal; }else { 0.0 => yVal; //Std.rand2f(0, 5) => yVal; } if (XYZ[0] < thresh) { yVal * 2 => yVal; } if (XYZ[1] < thresh) { xVal * 2 => xVal; } xVal + yVal => float total; <<>>; <<>>; total $ int => int intTotal; <<>>; spork ~ playNote(intTotal); 150::ms => now; 0 => notePlaying; } 10::ms => now; } fun void playNote(int note) { //SinOsc m => SinOsc c => dac; //Std.mtof(array[note]) => c.freq; //XYZ[0] + XYZ[1] => float total; //total / 2 => total; //c.freq() * total => m.freq; //50 => m.gain; //50 => c.gain; Clarinet clar => JCRev r => dac; .75 => r.gain; .1 => r.mix; Std.mtof(array[note]) => clar.freq; XYZ[0] + XYZ[1] + XYZ[2] => float total; total / 3 => total; total / 2 => total; total + 0.5 => total; total => clar.noteOn; //SinOsc s => dac; //s.freq(Std.mtof(array[note])); //s.gain(XYZ[2]); 300::ms => now; clar.clear(1.0); } fun void amen() { <<<"amen">>>; SndBuf buf => dac; "amen.wav" => buf.read; buf.loop(1); 200::ms => now; while (XYZ[2] < 0.8) { 100::ms => now; } }