[chuck-users] Modulation of parameters "by hand"? Does ChucK have a function reference data type?

Michael Heuer heuermh at gmail.com
Thu Jun 9 11:18:36 EDT 2011

Johnathan Bell wrote:

> I'm trying to create a generic "modulation" function where I can give it some parameters to set up the modulation and a property to modulate. My current way of thinking would require passing a function object into the shred so that the parameter to be modulated can be chosen at the time of the function calling... Now I know already that I can't do something like the following:
> --code--
> // A failed attempt at tremolo
> SinOsc osc1 => Gain master => dac;
> 440 => osc1.freq;
> SinOsc lfo => master.gain;
> 5 => lfo.freq;
> .3 => lfo.gain;
> --/code--
> So thus I set up this function:
> --code--
> fun void tremolo(Gain noteGain)
> {
>    SinOsc lfo => blackhole;
>    5.75 => lfo.freq;
>    .3 => lfo.gain;
>    while (true)
>    {
>        1-lfo.last() => noteGain.gain;
>        // Assume "resolution" is a dur such as 10::ms, it is the resolution of our modulation
>        resolution => now;
>    }
> }
> --/code--
> And spork it with a gain object to modify... That works great, but I'll need to code a separate function for every single possible parameter that I'd want to modulate, so is there a way of specifying the specific parameter on the function call instead of the whole object, for instance, the prototype could be:
> --code--
> fun void modulate(FunctionObject param)
> --/code--
> And then the updated values would (in theory) be ChucK'ed directly to that "param" instead of object.parameter? I tried setting it up this way but I don't seem to know the object type for passing a function reference, if there is one. Or maybe someone else has a better idea that I haven't thought of?

Ideally one would be able to chuck a UGen directly to a property.
That would really help the chuck-operator-as-patch-cord model for
VCA/LFOs etc.

One way of implementing functions-as-parameters is with functors or
function classes.  Those are the primary focus of LiCK, which provides
Function.ck, IntFunction.ck, FloatFunction.ck, and so on, so that
other classes in the API (e.g. ArrayList.ck) can accept them as


ChucK forum contributor kijjaz posted a nice template for doing
parameter modulation that I've used a few times called ModulucK



More information about the chuck-users mailing list