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'...
(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