(
// Low Frequency Oscillator for parameter modulation
SynthDef(\lfo, { |out=0, freq=1, min=0, max=1, waveform=0|
    var lfo;

    // Select waveform based on parameter
    lfo = Select.kr(waveform, [
        SinOsc.kr(freq),        // Sine wave (waveform=0)
        LFTri.kr(freq),         // Triangle wave (waveform=1)
        LFSaw.kr(freq),         // Sawtooth wave (waveform=2)
        LFPulse.kr(freq, 0, 0.5) // Square wave (waveform=3)
    ]);

    // Scale to range
    lfo = lfo.range(min, max);

    // Output to control bus
    Out.kr(out, lfo);
}).add;

// ADSR envelope generator
SynthDef(\envelope, { |out=0, gate=1, attack=0.01, decay=0.3, sustain=0.5, release=1|
    var env = EnvGen.kr(
        Env.adsr(attack, decay, sustain, release),
        gate,
        doneAction: 2
    );
    Out.kr(out, env);
}).add;

// Random value generator with controllable rate
SynthDef(\randomGen, { |out=0, freq=1, min=0, max=1|
    var rand = LFNoise2.kr(freq).range(min, max);
    Out.kr(out, rand);
}).add;

"Modulation SynthDefs loaded".postln;
)