57120 => int INPUT_PORT; 57125 => int OUTPUT_PORT; OscSend xmit; xmit.setHost("localhost", OUTPUT_PORT); class NoiseSynth { Noise noise => LPF filter => Pan2 panner => JCRev rev => dac; 0.1 => rev.mix; 0.7 => static float amp; 0.1 => static float res; 0.5 => static float pan; 0.2 => static float cutOffFreq; 0.1 => static float modDepth; 0.9 => static float modRate; 0 => static int mute; fun void run() { while (true) { 60 + cutOffFreq * 1000 => float f; modDepth * 500 => float d; 60 + modRate * 3000 => float r; float modFreq; Std.rand2f(0, d - 1) => modFreq; filter.freq(f + modFreq); filter.gain(amp); panner.pan(pan * 2 - 1.0); filter.Q(res * 20); 20::ms +=> now; } } } /////////////////////////////////////////// NoiseSynth synth; fun OscEvent makeEvent(string messagePattern) { OscRecv recv; OscEvent oscEvent; INPUT_PORT => recv.port; recv.listen(); recv.event(messagePattern) @=> oscEvent; return oscEvent; } fun void receiveAmp() { float amp; makeEvent("/wii/1/accel/pry/0, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { oscEvent.getFloat() => amp; if (!NoiseSynth.mute) amp => NoiseSynth.amp; // as a special case the OSC message gets passed to other host // can be removed for a general case xmit.startMsg("/wii/1/accel/pry/0", "f"); xmit.addFloat(amp); } } } fun void receivePan() { makeEvent("/wii/1/accel/pry/1, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) oscEvent.getFloat() => NoiseSynth.pan; } } fun void receiveRes() { float buttonState; makeEvent("/wii/1/button/A, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) oscEvent.getFloat() => buttonState; <<<"mute received", buttonState>>>; if (buttonState == 0) { 1 - NoiseSynth.res => NoiseSynth.res; } } } fun void receiveCutOffFreq() { makeEvent("/cam/motion/y, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) oscEvent.getFloat() => NoiseSynth.cutOffFreq; } } fun void receiveModDepth() { makeEvent("/cam/motion/x, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) oscEvent.getFloat() => NoiseSynth.modDepth; } } fun void receiveMute() { float buttonState; makeEvent("/wii/1/button/B, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) oscEvent.getFloat() => buttonState; <<<"mute received", buttonState>>>; if (buttonState == 0) { !NoiseSynth.mute => NoiseSynth.mute; if (NoiseSynth.mute) 0 => NoiseSynth.amp; } } } spork ~ synth.run(); spork ~ receiveAmp(); spork ~ receivePan(); spork ~ receiveRes(); spork ~ receiveCutOffFreq(); spork ~ receiveModDepth(); spork ~ receiveMute(); 10::minute +=> now; //////////////////////////////////////////