[chuck-users] list oriented ways to make this more simple?

Kassen signal.automatique at gmail.com
Mon Aug 27 05:44:43 EDT 2007


On 8/27/07, 2g <electriclightheads at gmail.com> wrote:
>
> mmm...i seem to be writing same things too much
> can't any of these done in list[] oriented ways?



Sure!

I'll just take this ChunK (a ChunK is a unit of ChucK code, at least it
should be) as a example and then you can see how far you get with that, ok?


sa.ck:
>
> SinOsc sun1 => Pan2 ps1 => dac;
> SinOsc sun2 => Pan2 ps2 => dac;
> SinOsc sun3 => Pan2 ps3 => dac;
> SinOsc sun4 => Pan2 ps4 => dac;
> SinOsc sun5 => Pan2 ps5 => dac;
> SinOsc moon1 => Pan2 pm1 => dac;
> SinOsc moon2 => Pan2 pm2 => dac;
> SinOsc moon3 => Pan2 pm3 => dac;
> SinOsc moon4 => Pan2 pm4 => dac;
> SinOsc moon5 => Pan2 pm5 => dac;
> .1 => ps1.gain;
> .1 => ps2.gain;
> .1 => ps3.gain;
> .1 => ps4.gain;
> .1 => ps5.gain;
> .1 => pm1.gain;
> .1 => pm2.gain;
> .1 => pm3.gain;
> .1 => pm4.gain;
> .1 => pm5.gain;



========================
10 => int foo;
//some oscilators
SinOsc suns_moons[foo];

//as many pans
Pan2 pans[foo];

//now we automate and from here on we save lots of lines
for( 0=> int n; n< foo; n++)
{
//make connections
suns_moons[n] => pans[n] => dac;
//set gain
1 => pans[n].gain;
}
===================


>From there on you could make the suns even and the moons odd numbers, that
might work nicely, you can sort odd from even using "if(n%2)" because
modulus n will always resolve to either 0 or 1 for a positive n. Arrays of
Ugens are a great way of structuring your code if you do a lot of monotonous
stuff. Another aproach might be making a class that conists of a sun-moon
pair and making a array of those.

As for the functions; you could pass those a reference to the arrays used or
hardcode their name in (less versatile). Because of the way the namespace
works it would be possible and a good idea to use "foo" again in the
functions or use the .cap() method that arrays have, this would make it
easier to create whole solar systems by increasing one number.


ChucK on!
Kas.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20070827/6b50ce4e/attachment.htm 


More information about the chuck-users mailing list