2b_rgb_synthdefs.scd 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Module 2b: RGB-controlled synthesizer - FIXED VERSION
  2. // Save as "2b_rgb_synthdefs.scd" (REPLACE YOUR EXISTING VERSION)
  3. (
  4. // RGB-controlled synthesizer with proper gate handling
  5. SynthDef(\rgbSynth, { |out=0, freq=440, amp=0.5, gate=1,
  6. ampAttack=0.01, ampRelease=1,
  7. filterAttack=0, filterRelease=0, filterMin=200, filterMax=5000,
  8. pitchAttack=0, pitchRelease=0, pitchRatio=2,
  9. redAmt=0.5, greenAmt=0.5, blueAmt=0.5|
  10. var ampEnv, filterEnv, pitchEnv, red, green, blue, sig;
  11. // Amplitude envelope - CRITICAL: This must respond to gate
  12. ampEnv = EnvGen.kr(
  13. Env.adsr(ampAttack, 0.1, 0.8, ampRelease),
  14. gate,
  15. doneAction: 2 // Free the synth when envelope finishes
  16. );
  17. // Filter envelope
  18. filterEnv = EnvGen.kr(
  19. Env.adsr(filterAttack, 0.1, 0.8, filterRelease),
  20. gate
  21. );
  22. // Pitch envelope
  23. pitchEnv = EnvGen.kr(
  24. Env.adsr(pitchAttack, 0.1, 0.8, pitchRelease),
  25. gate
  26. );
  27. // Calculate modulated frequency
  28. freq = freq * (1 + (pitchEnv * (pitchRatio - 1)));
  29. // Different waveforms for RGB components
  30. red = SinOsc.ar(freq) * redAmt;
  31. green = Saw.ar(freq) * greenAmt;
  32. blue = Pulse.ar(freq, 0.5) * blueAmt;
  33. // Mix the waveforms
  34. sig = (red + green + blue) / 3;
  35. // Apply filter with envelope control
  36. sig = RLPF.ar(sig, filterEnv.linexp(0, 1, filterMin, filterMax), 0.8);
  37. // Apply amplitude envelope and output
  38. sig = sig * ampEnv * amp;
  39. Out.ar(out, sig!2);
  40. }).add;
  41. "RGB-controlled synthesizer loaded with proper gate handling".postln;
  42. )