class DetunedFuzzVoice extends VoiceBankVoice { // override 0.5 => gainAtZeroVelocity; 0.2 => highCutoffSensitivity; -0.9 => lowCutoffSensitivity; 1 => int unison; float myFreqWaver; 400 => float myLPFCutoff; Gain preLPF => LPF lpf => adsr; SqrOsc osc1[unison]; SqrOsc osc2[unison]; SqrOsc osc3[unison]; SinOsc root => adsr; 0.2 => root.gain; // drive 1.5 => preLPF.gain; 1.0 / preLPF.gain() => lpf.gain; // oscs, gain, widths for( int i; i < unison; i++ ) { 0.33 / unison => osc1[i].gain; 0.33 / unison => osc2[i].gain; 0.33 / unison => osc3[i].gain; 0.9 => osc1[i].width; 0.8 => osc2[i].width; 0.6 => osc3[i].width; osc1[i] => preLPF; osc2[i] => preLPF; osc3[i] => preLPF; } TriOsc lfo1 => Envelope lfo1env => blackhole; 1.9 => float lfo1BaseFreq => lfo1.freq; 360::ms => lfo1env.duration; fun void startLFO1() { -0.25 => lfo1.phase; 1 => lfo1env.keyOn; while( true ) { // scale 0.01 * lfo1env.last() + 1 => myFreqWaver; 5::ms => now; } } spork ~ startLFO1() @=> Shred LFO1Shred; fun void sync() { for( int i; i < unison; i++ ) { // TODO: necessary? 0 => osc1[i].phase => osc2[i].phase => osc3[i].phase; } LFO1Shred.exit(); spork ~ startLFO1() @=> Shred LFO1Shred; } // lpf cutoff fun float cutoffToHz( float cutoff ) { return Math.min( Std.scalef( Math.pow( Std.clampf( cutoff, 0, 1 ), 3 ), 0, 1, myFreq, 21000 ), 21000); } // LPF cutoff envelope ADSR lpfEnv => blackhole; 0.000001 => float lpfSustain; lpfEnv.set( 1::ms, 170::ms, lpfSustain, 100::ms ); fun void triggerLPFEnv() { // reset 0 => lpfEnv.value; lpfSustain => lpfEnv.sustainLevel; // bounds 0.81 => float minCutoff; // higher cutoff at higher pitch and at higher velocity Std.scalef( Math.pow( myVelocity, 1.6 ), 0, 1, 0.9, 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(), 3 ) => 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 ); } // resonances 1.9 => lpf.Q; // then ADSR on volume 330::ms => rTime; adsr.set( 1::ms, 750::ms, 0.0001, rTime ); // osc1: freq // osc2: +38c // osc3: -2c fun void applyFreqs() { float f1, f2, f3; while( true ) { Math.min( myLPFCutoff, 21000 ) => lpf.freq; // myFreq myFreq * myFreqWaver => f1; // +38 cents f1 * 1.022192 => f2; // -2 cents f1 * 0.998845 => f3; for( int i; i < unison; i++ ) { f1 => osc1[i].freq; f2 => osc2[i].freq; f3 => osc3[i].freq; } f1 => root.freq; 10::ms => now; } } spork ~ this.applyFreqs(); // trigger note on fun void noteOn() { // sync sync(); // key on adsr.keyOn( 1 ); triggerLPFEnvShred.exit(); spork ~ this.triggerLPFEnv() @=> triggerLPFEnvShred; } // trigger note off fun void noteOff() { adsr.keyOff( 1 ); endLPFEnv(); } } class DetunedFuzz extends VoiceBank { 8 => numVoices; // voices DetunedFuzzVoice myVoices[numVoices]; // assign to superclass v.size( myVoices.size() ); for( int i; i < myVoices.size(); i++ ) { myVoices[i] @=> v[i]; } // connect init( true ); } DetunedFuzz d => LPF l => JCRev rev => dac; 0.3 => d.gain; 0.0 => rev.mix; 15000 => l.freq; // knobs global float gReverb; global float gCutoff; global float gLowpass; fun void ApplyGlobals() { while( true ) { 10::ms => now; gReverb => rev.mix; gLowpass => l.freq; gCutoff => d.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; d.noteOn( m, velocity ); //<<< "on", m, v >>>; } fun void NoteOff( int m ) { spork ~ d.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 >>>; } }