(
// RGB-controlled synthesizer with amplitude envelope
SynthDef(\rgbSynth, { |out=0, freq=440, amp=0.5, attack=0.01, release=1, redAmt=0.5, greenAmt=0.5, blueAmt=0.5|
    var env, red, green, blue, sig;

    // Amplitude envelope
    env = EnvGen.kr(Env.perc(attack, release), doneAction: 2);

    // 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 envelope and output
    sig = sig * env * amp;
    Out.ar(out, sig!2);
}).add;

// RGB-controlled synthesizer with filter envelope
SynthDef(\rgbFilterSynth, { |out=0, freq=440, amp=0.5, attack=0.01, release=1,
    filterAttack=0.01, filterRelease=1, filterMin=200, filterMax=5000,
    redAmt=0.5, greenAmt=0.5, blueAmt=0.5|

    var ampEnv, filterEnv, red, green, blue, sig;

    // Amplitude envelope
    ampEnv = EnvGen.kr(Env.perc(attack, release), doneAction: 2);

    // Filter envelope
    filterEnv = EnvGen.kr(Env.perc(filterAttack, filterRelease));

    // 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.5);

    // Apply amplitude envelope and output
    sig = sig * ampEnv * amp;
    Out.ar(out, sig!2);
}).add;

// RGB-controlled synthesizer with pitch envelope
SynthDef(\rgbPitchSynth, { |out=0, freq=440, amp=0.5, attack=0.01, release=1,
    pitchAttack=0.01, pitchRelease=1, pitchRatio=2,
    redAmt=0.5, greenAmt=0.5, blueAmt=0.5|

    var ampEnv, pitchEnv, red, green, blue, sig;

    // Amplitude envelope
    ampEnv = EnvGen.kr(Env.perc(attack, release), doneAction: 2);

    // Pitch envelope
    pitchEnv = EnvGen.kr(Env.perc(pitchAttack, pitchRelease));

    // 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 amplitude envelope and output
    sig = sig * ampEnv * amp;
    Out.ar(out, sig!2);
}).add;

"RGB-controlled synthesizers loaded".postln;
)