class SweepColdPadVoice extends StereoVoiceBankVoice { // override 0.5 => gainAtZeroVelocity; 0.45 => highCutoffSensitivity; -0.2 => lowCutoffSensitivity; 2 => int unison; 400 => float myLPFCutoff; DelayA chorusL => LPF lpfL => adsrL; DelayA chorusR => LPF lpfR => adsrR; SawOsc osc1[unison]; SqrOsc osc2[unison]; SawOsc osc3[unison]; Pan2 pans[unison]; SinOsc root => lpfL; root => lpfR; 0.2 => root.gain; 1.0 => float spread; // osc 1: sawosc +0c, 45% volume // osc 2: rectosc +18c, 27% volume // osc 3: sawosc -19c, 27% volume for( int i; i < unison; i++ ) { 0.45 / unison => osc1[i].gain; 0.27 / unison => osc2[i].gain; 0.27 / unison => osc3[i].gain; 0.61 => osc2[i].width; osc1[i] => pans[i]; osc2[i] => pans[i]; osc3[i] => pans[i]; Std.scalef( i, 0, unison-1, -spread, spread ) => pans[i].pan; pans[i] => lpfL; pans[i] => lpfR; pans[i] => chorusL; pans[i] => chorusR; } // chorus 0.72Hz, "18%" intensity 0.2::second => chorusL.max => chorusR.max; SinOsc chorusLFO => blackhole; 0.72 => chorusLFO.freq; 0.18 => chorusL.gain => chorusR.gain; fun void doChorus() { 3::ms => dur baseDelay; while( true ) { 0.3::ms * chorusLFO.last() + baseDelay => chorusL.delay => chorusR.delay; 5::ms => now; } } spork ~ doChorus(); fun void sync() { for( int i; i < unison; i++ ) { // TODO: necessary? // 0 => osc1[i].phase => osc2[i].phase; } } // lpf cutoff fun float cutoffToHz( float cutoff ) { return Math.min( Std.scalef( Math.pow( Std.clampf( cutoff, 0, 1 ), 3 ), 0, 1, myFreq, 18000 ), 18000 ); } // LPF cutoff envelope ADSR lpfEnv => blackhole; lpfEnv.set( 4200::ms, 10000::ms, 0.0, 10000::ms ); fun void triggerLPFEnv() { // reset 0 => lpfEnv.value; // not necessary but do anyway 0.0 => lpfEnv.sustainLevel; 0.25 => float minCutoff; // does not vary with velocity 1.0 => float maxCutoff; minCutoff => float currentCutoff; maxCutoff - minCutoff => float cutoffDiff; lpfEnv.keyOn( 1 ); 5::ms => dur delta; while( true ) { // set minCutoff + cutoffDiff * Math.pow( lpfEnv.value(), 2 ) => currentCutoff; // Math.pow( currentCutoff, 3 ) => currentCutoff; currentCutoff + myCutoff => this.cutoffToHz => myLPFCutoff; // wait delta => now; } } spork ~ this.triggerLPFEnv() @=> Shred triggerLPFEnvShred; fun void endLPFEnv() { lpfEnv.keyOff( 1 ); } // lpf is very resonant 4.0 => lpfL.Q => lpfR.Q; // then ADSR on volume 2200::ms => rTime; adsrL.set( 380::ms, 10000::ms, 1.0, rTime ); adsrR.set( 380::ms, 10000::ms, 1.0, rTime ); // analog: randomly alter pitch and cutoff (0 to 1: 1. units?) 0.01 => float analog; float analogs[unison + 1]; fun void calculateAnalog() { for( int i; i < analogs.size(); i++ ) { Math.random2f( 1 - analog, 1 + analog ) => analogs[i]; } } // osc1: freq // osc2: +3 cents fun void applyFreqs() { float f1, f2, f3; while( true ) { Math.min( myLPFCutoff * analogs[unison], 21000 ) => lpfL.freq => lpfR.freq; // myFreq +- 19 cents myFreq => f1; f1 * 1.010451 => f2; f1 * 0.989085 => f3; for( int i; i < unison; i++ ) { f1 * analogs[i] => osc1[i].freq; f2 * analogs[i] => osc2[i].freq; f3 * analogs[i] => osc3[i].freq; } f1 => root.freq; 10::ms => now; } } spork ~ this.applyFreqs(); // trigger note on fun void noteOn() { // sync sync(); // key on adsrL.keyOn( 1 ); adsrR.keyOn( 1 ); triggerLPFEnvShred.exit(); spork ~ this.triggerLPFEnv() @=> triggerLPFEnvShred; calculateAnalog(); } // trigger note off fun void noteOff() { adsrL.keyOff( 1 ); adsrR.keyOff( 1 ); endLPFEnv(); } } class SweepColdPad extends StereoVoiceBank { 10 => numVoices; // voices SweepColdPadVoice myVoices[numVoices]; // assign to superclass v.size( myVoices.size() ); for( int i; i < myVoices.size(); i++ ) { myVoices[i] @=> v[i]; } // and connect init( true ); } SweepColdPad s; 0.3 => s.gain; LPF lpfL => JCRev revL => dac.left; LPF lpfR => JCRev revR => dac.right; s.connect( lpfL, lpfR ); 0.05 => revL.mix => revR.mix; 15000 => lpfL.freq => lpfR.freq; // knobs global float gReverb; global float gCutoff; global float gLowpass; fun void ApplyGlobals() { while( true ) { 10::ms => now; gReverb => revL.mix => revR.mix; gLowpass => lpfL.freq => lpfR.freq; gCutoff => s.cutoff; } } spork ~ ApplyGlobals(); // end knobs global Event midiMessage; global int midiCommand; global int midiNote; global int midiVelocity; fun void NoteOn( int m, int v ) { v * 1.0 / 128 => float velocity; s.noteOn( m, velocity ); //<<< "on", m, v >>>; } fun void NoteOff( int m ) { spork ~ s.noteOff( m ); //<<< "off", m >>>; } while( true ) { midiMessage => now; if( midiCommand >= 144 && midiCommand < 160 ) { if( midiVelocity > 0 ) { NoteOn( midiNote, midiVelocity ); } else { NoteOff( midiNote ); } } else if( midiCommand >= 128 && midiCommand < 144 ) { NoteOff( midiNote ); } else { //<<< "unknown midi command:", midiCommand, midiNote, midiVelocity >>>; } }