ccrma / webchuck

ChucK on the Web
https://chuck.stanford.edu/webchuck
MIT License
42 stars 8 forks source link

Port iter~ code to javascript #9

Closed nshaheed closed 1 year ago

nshaheed commented 1 year ago

Ported iter~ to javascript. This version runs faster (I wasn't noticing any delay when adding a shred), is cleaner, and now works correctly when the iter~ is inside of brackets (mostly).

Example code:

JCRev r => dac;

fun void player(int freq){
    SinOsc s => r;
    Std.mtof(freq+60) => s.freq;
    0.4 => s.gain;
    Math.random2f(0.5,3.5)::second => now;
}

[0,2,4,12] @=> int freqs[];
[2,4,6] @=> int freqs2[];
[2,4,6,8] @=> int freqs3[];
[4,14] @=> int freqs4[];

for (int i; i < 1; i++){
    iter~(player,freqs2,2::second);
    iter~(player,freqs3,3::second);
}

50::second => now;