[chuck-users] Get the value of an Envelope

Kassen signal.automatique at gmail.com
Tue Jan 20 17:14:20 EST 2009


Some notes here in addition to what Tom already covered because I think some
of the topics here can stand some clarification;

    Generally it's not such a good idea to define things (like variables or
UGens) inside of a loop. This is because defining  -and so instantiating-
things will take memory and right now we don't have garbage collection so
the memory that gets used for these things will never be freed. Aside from
that; when you define things inside of a loop it will become impossible to
later address those (for example to change their parameters). Unless you are
very sure of what you are doing defining UGens within a loop is probably a
bad idea.

Let me give a example;
    SinOsc s => dac;
    Std.rand2f(200, 2000) => s.freq;
    .33 => s.gain;
    second => now;

5::second => now;

This wil create a sort of "chord" (probably a very bad one). Let's suppose
that after these 8 seconds we'd like to change the "chord". How would we
distinguish between the 3 copies of "s"? The sad truth is tthat we can't.
This is a bit tricky; in a way we can say that every iteration of such a
loop is it's own namespace like a function has it's own namespace. Obviously
this namespace is a superset of the namespace the loop itself is in, or
loops wouldn't be good for much. To re-phrase; from within a loop you can
address anything defined within that loop and anything in the scope the loop
itself is in. You can't address things defined within a loop from outside of
that loop.

    About Envelope; Envelope.last() will give you the last value calculated
by the UGen. This is the same as the value it sends to the UGen it's
connected to at the last "tick" of the sample rate. This value is based on
Envelope's input multiplied by the current value of the Envelope. When
nothing is connected to the input of the Envelope this value will always be
0 though the value of .value() may be any number (because anything
multiplied by 0 will be 0).

At times it's handy to feed a Envelope with a Step UGen to scale it's
output. Let me demonstrate;

Envelope e => dac; //notice a connection to the dac or blackhole is needed
for any results to be calculated at all
3::second => e.duration;

1 => e.target;
<<<e.value(), e.last()>>>;

    second => now;
    <<<e.value(), e.last()>>>;

//second case, notice the difference

Step s => e;
10 => s.next;
0 => e.value;
samp => now; //allow parameter changes to have effect
<<<e.value(), e.last()>>>;

1=> e.target;

    second => now;
    <<<e.value(), e.last()>>>;

Quite different, I'd say.

I hope that clarifies. Some of this is slightly tricky but most of it
directly translates to more power to you. Shout if this was unclear.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20090120/6982be5d/attachment.html>

More information about the chuck-users mailing list