| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- // Module 2b: RGB-controlled synthesizer - FIXED VERSION
- // Save as "2b_rgb_synthdefs.scd" (REPLACE YOUR EXISTING VERSION)
- (
- // RGB-controlled synthesizer with proper gate handling
- SynthDef(\rgbSynth, { |out=0, freq=440, amp=0.5, gate=1,
- ampAttack=0.01, ampRelease=1,
- filterAttack=0, filterRelease=0, filterMin=200, filterMax=5000,
- pitchAttack=0, pitchRelease=0, pitchRatio=2,
- redAmt=0.5, greenAmt=0.5, blueAmt=0.5|
- var ampEnv, filterEnv, pitchEnv, red, green, blue, sig;
- // Amplitude envelope - CRITICAL: This must respond to gate
- ampEnv = EnvGen.kr(
- Env.adsr(ampAttack, 0.1, 0.8, ampRelease),
- gate,
- doneAction: 2 // Free the synth when envelope finishes
- );
- // Filter envelope
- filterEnv = EnvGen.kr(
- Env.adsr(filterAttack, 0.1, 0.8, filterRelease),
- gate
- );
- // Pitch envelope
- pitchEnv = EnvGen.kr(
- Env.adsr(pitchAttack, 0.1, 0.8, pitchRelease),
- gate
- );
- // Calculate modulated frequency
- freq = freq * (1 + (pitchEnv * (pitchRatio - 1)));
- // Different waveforms for RGB components
- red = SinOsc.ar(freq) * redAmt;
- green = Saw.ar(freq) * greenAmt;
- blue = Pulse.ar(freq, 0.5) * blueAmt;
- // Mix the waveforms
- sig = (red + green + blue) / 3;
- // Apply filter with envelope control
- sig = RLPF.ar(sig, filterEnv.linexp(0, 1, filterMin, filterMax), 0.8);
- // Apply amplitude envelope and output
- sig = sig * ampEnv * amp;
- Out.ar(out, sig!2);
- }).add;
- "RGB-controlled synthesizer loaded with proper gate handling".postln;
- )
|