[chuck-users] how do you maipulate an array with rand2()?

Malik Martin laserbeak43 at gmail.com
Tue Nov 14 06:46:56 EST 2006


hi Spencer thanks for the welcome!
glad to be here.

i was suspecting that might be the case but didnt try it because i did 
some research on the buf.pos
command because i kept getting an error saying the argument has 2 
different types. It turns out that
buf.pos or formally speaking, SndBuf.pos only takes an int type so i 
turned all the values to ints rounded to their
highest value in the one's place.

this worked, but it still output nothing. the patch just works as if the 
array that i made doesn't exist!! here is a copy
 of the patch. but before i post it, would i be able to send patches as 
attatchments
to the mailing-list?(would like to know for future refference)

// the patch
SndBuf buf => dac;

// load the file
"E:\samples\AmenMRZ2-180bpm.wav" => buf.read;

//get number of samples
buf.samples() => int NumOfSamps;
<<<NumOfSamps>>>;

//get length in milliseconds by converting seconds to ms
buf.length() / ms => float length;
<<<length>>>;

// time loop
while( true )
{   
    //1 bar at 180bpm cut into 8ths
    [ 0, 167, 333, 500, 667, 833, 1000, 1166 ] @=> int push[];
    push[Std.rand2(0,7)] => buf.pos;
    1333::ms => now;
}



Spencer Salazar wrote:

>Hi Malik,
>Welcome to ChucK land!
>
>What you have found is a bug, the lack of a feature, or a result of  
>strong typing (depending on your point of view), in which the type of  
>the first element of an array determines the overall type of an  
>array.  This is better explained by example:
>
>[ 0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75, 1166.375 ] @=>  
>float push[];
>
>produces an error, whereas
>
>[ 0.0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75, 1166.375 ]  
>@=> float push[];
>
>does not produce an error (but is functionally equivalent).  The  
>difference is that the first element is explicitly a float when  
>initializing the array of floats.  hopefully this clarifies things a  
>bit.
>
>spencer
>
>On Nov 13, 2006, at 10:21 PM, Malik Martin wrote:
>
>  
>
>>hi i already posted this on the forums, but it doesnt seem as  
>>active as
>>i imagine the mailing list might be(no offense of course).
>>
>>so here's my post
>>
>>hi
>>i'm trying to access an array with rand2() but i get syntax errors:
>>
>>while( true )
>>{
>>   //1 bar at 180bpm cut into 8ths
>>   float push[ 0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75,
>>1166.375 ]
>>    push[Math.rand2(0,7)] => buf.pos;
>>
>>    1333::ms => now;
>>}
>>
>>i made a second post with a minor update
>>
>>i noticed my syntax errors in comparison to otf_06.ck on page 49 in  
>>the
>>manual and re-wrote it.
>>
>>// time loop
>>while( true )
>>{
>>   //1 bar at 180bpm cut into 8ths
>>   [ 0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75, 1166.375 ] 
>>@=>
>>float push[];
>>    push[Math.rand2(0,7)] => buf.pos;
>>
>>    1333::ms => now;
>>}
>>
>>but i still get this error: [SndBufTest1.ck]:line(19): array init  
>>[...]
>>contains incompatible types...
>>
>>Malik
>>_______________________________________________
>>chuck-users mailing list
>>chuck-users at lists.cs.princeton.edu
>>https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>    
>>
>
>_______________________________________________
>chuck-users mailing list
>chuck-users at lists.cs.princeton.edu
>https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>  
>



More information about the chuck-users mailing list