57129 => int RECEIVE_PORT; fun OscEvent makeEvent(string messagePattern) { OscRecv recv; OscEvent oscEvent; RECEIVE_PORT => recv.port; recv.listen(); recv.event(messagePattern) @=> oscEvent; return oscEvent; } ///////////////////////////////////////////////////// class LiveGranulizerManager { dac.channels() => int chans; LiveGranulizer@ granulizers[8]; 0 => static int maxId; //Pan2 pans[8]; Pan8 pans[8]; JCRev revs[chans]; spork ~ receiveGain(); spork ~ receivePan(); spork ~ receiveReverb(); fun void startNewGranulizer(int inputChannel) { LiveGranulizer granulizer; granulizer @=> granulizers[maxId]; maxId => granulizer.id; granulizer.setBufferSize(1::minute); granulizer.lisa => pans[maxId]; for (0 => int i; i < chans; i++) { if (i < chans) { pans[maxId].chan(i) => revs[i] => dac.chan(i); } 0.05 => revs[i].mix; } granulizer.start(inputChannel); maxId + 1 => maxId; } fun void receiveGain() { <<<"receiveGain">>>; int id; float gainAmount; makeEvent("/gain, if") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { oscEvent.getInt() => id; oscEvent.getFloat() => gainAmount; granulizers[id].setGain(gainAmount); <<>>; } } } fun void receivePan() { <<<"receivePan">>>; int id; float panAmount; makeEvent("/pan, if") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { oscEvent.getInt() => id; oscEvent.getFloat() => panAmount; if (chans == 8) { <<>>; panAmount * 4 + 4 + 0.01 => pans[id].pan; } else panAmount => pans[id].pan; <<>>; } } } fun void receiveReverb() { float reverb; <<<"receiveReverb">>>; makeEvent("/reverb, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { oscEvent.getFloat() => reverb; for (0 => int i; i < chans; i++) { reverb => revs[i].mix; } } } } } class LiveGranulizer { int id; LiSa lisa; 1000::ms => dur grainSize; 1 => float playRate; dur pos; 0.5 => float grainSizeRandLimit; 0.5 => float playPosRandLimit; 0.5 => float playRateRandLimit; time startTime; fun void playNextGrain() { Std.rand2f(0, grainSizeRandLimit) => float grainSizeRand; Std.rand2f(0, playPosRandLimit) => float playPosRand; Std.rand2f(0, playRateRandLimit) => float playRateRand; playRate * (1 + playRateRand) => lisa.rate; //gain * (1 + rand)=> buffer.gain; 1::ms => lisa.rampUp; grainSize * (1 + grainSizeRand) => now; 1::ms => lisa.rampDown; 1::ms => now; (now - startTime) * (1 - playPosRand) => lisa.playPos; } fun void setBufferSize(dur size) { lisa.duration(size); } fun void clear() { lisa.clear(); } fun void start(int inputChannel) { setGain(0.01); adc.chan(inputChannel) => lisa; spork ~ receiveClear(); // spork ~ receiveMotion(); spork ~ receivePlayRate(); spork ~ receiveGrainSize(); spork ~ receiveGrainSizeRand(); spork ~ receivePlayRateRand(); spork ~ receivePlayPosRand(); startRecording(); 1::ms => now; startPlaying(); spork ~ run(); <<>>; } fun void startRecording() { now => startTime; lisa.recRamp(1::ms); lisa.record(1); } fun void stopRecording() { lisa.record(0); } fun void startPlaying() { 1 => lisa.loop; lisa.play(1); } fun void stop() { stopRecording(); stopPlaying(); } fun void stopPlaying() { lisa.play(0); } fun void setPlayPos(dur pos) { pos => this.pos; lisa.playPos(pos); } fun void setPlayRate(float playRate) { playRate => this.playRate; lisa.rate(playRate); } fun void setGain(float gain) { lisa.voiceGain(0, gain); } fun void receiveClear() { float clearState; <<<"receiveClear">>>; makeEvent("/ccc") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { clear(); } } } fun void receivePlayRate() { float x; <<<"receivePlayRate">>>; makeEvent("/accx, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { oscEvent.getFloat() => x; setPlayRate(x); } } } fun void receiveGrainSize() { <<<"receiveGrainSize">>>; makeEvent("/grainSize, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { oscEvent.getFloat()::ms => grainSize; <<>>; } } } fun void receiveGrainSizeRand() { <<<"receiveGrainSizeRand">>>; makeEvent("/grainSizeRand, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { oscEvent.getFloat() => grainSizeRandLimit; <<>>; } } } fun void receivePlayRateRand() { makeEvent("/playRateRand, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { oscEvent.getFloat() => playRateRandLimit; <<>>; } } } fun void receivePlayPosRand() { float y; <<<"receivePlayPosRand">>>; makeEvent("/playPosRand, f") @=> OscEvent oscEvent; while ( true ) { oscEvent => now; while ( oscEvent.nextMsg() != 0) { oscEvent.getFloat() => playPosRandLimit; <<>>; } } } fun void run() { while (true) { playNextGrain(); } } } ////////////////////////////////////////////////////////////////////////// LiveGranulizerManager granulizerManager; for (int i; i < 8; i++) granulizerManager.startNewGranulizer(i / 4); 1::day => now;