[chuck-users] Load UGen if condition is met

Jean Menezes da Rocha jean at menezesdarocha.info
Sun Oct 4 22:19:48 EDT 2015


Hello, guys,

I am trying to choose which UGen to load (SinOsc, TriOsc or SawOsc) based
on a given condition. This sample code

    fun void playForPixels(int totalpixels, string osc) {
        if ( osc == "sin" ) { SinOsc sh; }
        else {
            if ( osc == "tri" ) { TriOsc sh; }
            else { SawOsc sh; }
        }

        Envelope e => Gain g => dac;

        ( ( s + v) * 100 )::ms => dur dura;
        s * v => g.gain;
        ( dura / 40 ) / second => e.time;

        h * 2000 => sh.freq;

        sh => e;

(code goes on...)

gives me the following error:

[listener.ck]:line(38): undefined variable/member 'sh' in class/namespace
'Pixel'...
[listener.ck]: ...in function 'playForPixels'

(i am working inside a class named 'Pixel', in case it is important).

How can I load my UGen and make it persist outside the scope of the if
clause?

Thanks in advance!
-- 
Jean Menezes da Rocha
Compositor
Professor -- Faculdades Est
Mestre e Doutorando em Composição pela Universidade Federal da Bahia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20151004/95ae0ddc/attachment.html>


More information about the chuck-users mailing list