[chuck-users] Load UGen if condition is met
Casper Schipper
casper.schipper at gmail.com
Mon Oct 5 02:01:48 EDT 2015
Hello Jean,
You can solve your problem by declaring an empty variable (Osc is the superclass of both SinOsc and TriOsc):
fun void playForPixels(int totalpixels, string osc) {
Osc @ sh;
if ( osc == "sin" ) { new SinOsc @=> sh; }
else {
if ( osc == "tri" ) { new TriOsc @=> sh; }
else { new SawOsc @=> sh; }
}
440 => osc.freq; // Still allows you to control frequency...
Best,
Casper
> On Oct 5, 2015, at 04:19, Jean Menezes da Rocha <jean at menezesdarocha.info> wrote:
>
> 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 <http://listener.ck/>]:line(38): undefined variable/member 'sh' in class/namespace 'Pixel'...
> [listener.ck <http://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
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20151005/e3d82ea2/attachment.html>
More information about the chuck-users
mailing list