[chuck-users] String as an argument...

Stephen Sinclair radarsat1 at gmail.com
Wed Oct 8 11:07:35 EDT 2008


On Wed, Oct 8, 2008 at 4:52 AM, Dimitri <eliftherious at gmail.com> wrote:
> Hey guys, first time posting here; short-time reader :)
>
> I've run into a bit of trouble programming a function to fade a ugen in or
> out. The code below will work nicely on g.gain however I can't abstract it
> to affect anything else without controlling the reference object, in this
> case 'g.'
>
> The input is time 'x' in number of seconds.
>
> //==============================================//
> function void fadeOut(int x)
> {
>     1 => float master;  x * 1000 => int top;
>     for( 0 => int i ; i <  top;  i++ )
>         {
>             if (master > 0) master - (master / (top * .2 ))  => master =>
> g.gain;
>             1::ms => now;
>         }
> }
> //==============================================//
>
> Obviously the below would be my desired function, but even delving through
> ChucK's string class, it doesn't seem that there's a function to return an
> object reference from a string...
>
> //==============================================//
> function void fadeIn(int x, string y)
> {
>     .01 => float master;  x * 1000 => int top;
>     for( 0 => int i ; i <  top;  i++ )
>         {
>             if (master < 1) master + (master / (top * .2)) => master =>
> y.gain;
>             1::ms => now;
>         }
> }
> //==============================================//
>
>
> Am I crazy for thinking something like this would be useful?

I'm not too sure what the meaning of the gain of a string would be,
since it has nothing to do with audio...

But perhaps you're looking for references.  The following code seems to work..

SinOsc s => blackhole;
1 => s.gain;

fun void cut(UGen@ x)
{
    0 => x.gain;
}
cut(s);


On the other hand, I suggest using the Envelope ugen instead of
manually fading the gain with a loop.


Steve


More information about the chuck-users mailing list