//Number 2
//Chuck a day 2009
//by Scott Hewitt
//www.ablelemon.co.uk/chuckaday

//Declare
int k;
//int used to track if shreds are running
int f;

rand2f

pow2

log10

//main function
fun void valueshift() 
{
    //Build DSP
    SinOsc s => dac;
    //declare freq
    440 => s.freq;
    int i;
    
    f++;
    //<<< f >>>;
    while (i < 50)
    {
        //Random frequency
        Std.rand2f(200, 1000) => s.freq;
        //Random duration to pass
        Std.rand2f(10, 500)*1::ms => now;
        //Increment Loop
        i++;
    }
    f--;
    //<<< f >>>;
}

//sporks shreds off
while (k < 6)
{
    spork~ valueshift();
    2000::ms => now;
    k++;
}

//loop time until all shreds are dead
while (f > 0 )
{
    500::ms => now;
    //<<< "waiting on" >>>;
    //<<< f >>>;
}

ChucK Source file here.


//Number 8
//Chuck a day 2009
//by Scott Hewitt
//www.ablelemon.co.uk/chuckaday

int scorelength;
Std.rand2(10, 30) => scorelength;
int score[scorelength];
float beat[scorelength];
int ups;
int downs;
int change;
int extra;
int doublebar;
float f;

scorelength / 4 $ int => doublebar;

//layout picths steps
<<< "scorelength", scorelength >>>;
scorelength * 0.4 => f;
f $ int => ups;
<<< "ups", ups >>>;
scorelength * 0.4 => f;
f $ int => downs;
<<< "downs", downs >>>;
scorelength * 0.2 => f;
f $ int => change;
<<< "change", change >>>;

scorelength - ups - downs - change => extra;
change + extra => change;

<<< "change + extra", change >>>;

int i;
int control;
0 => int shift;

//functions handle pitch steps
function void upper(int move){
    score[i-1] + move + shift => score[i];
    ups--;
}

function void downer(int move){
    score[i-1] - move + shift => score[i];
    downs--;
}

function void changer(int move){
    score[i-1] + move + shift => score[i];
    change--;
}

//tempo score
function void rythmscore(){
    <<< "rythm" >>>;
    int kk;
    for (1 => int ii; ii < scorelength; ii++)
    {
        1 => beat[ii];
        kk++;
        if (kk == 3){
            if (maybe){
                0.7 => beat[ii];
            }   else 1.3 => beat[ii];
        }
        if (kk > doublebar){
            0 => kk;
            if (maybe){
                2.54 => beat[ii];
            }   else 4.56 => beat[ii]; 
    }   
}
}

//creates score using pitch step values
function void makescore() {
    <<< "score" >>>;
    1 => score[0];
    for (1 => i; i < scorelength; i++)
    {
        if (score[i-1] == 7)
        {
            8 => shift;
           // 4 => beat[i-1];
            //1 => beat[i];
        }
        if (shift == 8){
            if (score[i-1] == 11){
                0 => shift;
              //  4 => beat[i-1];
               // 1 => beat[i];                
            }   
        }       
        0 => control;
        <<< "shift", shift >>>;
        if (ups > 0)
        {
            control + 1 => control;
        }
        if (downs > 0)
        {
            control + 2 => control;
        }
        if (change > 0){
            control + 4 => control;
        }
        <<< "control" , control >>>;
        if (control == 0){
            Std.rand2(0,2) => int choice;
            <<< "choice", choice >>>;
            if (choice == 0){
                upper(4);
            }
            if (choice == 1){
                downer(4);
            }
            if (choice == 2){
                changer(-8);
            }                        
        }
        if (control == 1){
            upper(2);
        }
        if (control == 2){
            downer(2);
        }
        if (control == 3){
            if (maybe){
                upper(3);
            }else downer(3);
        }
        if (control == 4){
            changer(5);
        }
        if (control == 5){
            if (maybe){
                upper(5);
            }else changer(6);
        }
        if (control == 6){
            if (maybe){
                downer(3);
            }else changer(3);
        }
        if (control == 7){
            Std.rand2(0,2) => int choice;
            <<< "choice", choice >>>;
            if (choice == 0){
                upper(4);
            }
            if (choice == 1){
                downer(2);
            }
            if (choice == 2){
                changer(5);
            }                        
        }
    }
}

//creats pitch score
makescore();
rythmscore();

SinOsc s => Envelope env => dac;
1 => env.value;
0.1 => s.gain;

//plays score
while (true){
    
int j;
for (1 => j; j < scorelength; j++)
{
   <<< "score: ", score[j] >>>;
   if (Std.mtof(score[j] + 69.0) > 100){
       if (Std.mtof(score[j] + 69.0) < 2000){
        Std.mtof(score[j] + 69.0) => s.freq;
    }
}
   <<< "freq: ",s.freq() >>>;
   130::ms => env.duration;
   1.0 => env.target;
   1 => env.keyOn;
   100::ms => now;
   beat[j] * 500::ms => now;
   130::ms => env.duration;
   0.0 => env.target;
   1 => env.keyOn;
   400::ms => now;
   <<< "beat: ", beat[j] >>>;
}
makescore();
rythmscore();
<<< "next score" >>>;
150::ms => env.duration;
0.0 => env.target;
1 => env.keyOn;
1000::ms => now;
0 => env.keyOff;
1 => env.value;
}

ChucK Source file here.