//score

// paths to chuck files
me.dir() + "/drummer.ck" => string drummerPath;
me.dir() + "/violin.ck" => string violinPath;
me.dir() + "/voice.ck" => string voicePath;
me.dir() + "/voice2.ck" => string voice2Path;

// function junction
fun string sectName ( int i )
{
    SinOsc magiclead;
    
    magiclead => ADSR e => NRev r => dac;
    
    // set adsr
    
    e.set (2000::ms, 4000::ms, 0.1, 1000::ms);
    
    // set gain
    
    0.2 => magiclead.gain;
    Std.mtof(63) => magiclead.freq;
    

    if (i == 1)
    {
        <<< "Safe in Nature" >>>;
        e.keyOn();
        7000::ms => now;
        e.keyOff();
        7000::ms => now;
    }
    if (i == 2)
    {
        <<< "Machines Invade" >>>;     
    }
    if (i == 3)
    {
        <<< "A Call to Arms" >>>;
    }
    if (i == 4)
    {
        <<< "War!" >>>;
        
    }
    if (i == 5)
    {
        <<< "All is Lost" >>>;
    }
}

BPM tempo;
//set initial tempo
tempo.tempo(120); //120 BPM

section s;



tempo.quarterNote => dur quarter;

// start with voice 1
s.sectionCall(1);
Machine.add(voicePath) => int voiceID;
spork ~ sectName(1);
quarter*16 => now;

// add voice 2
Machine.add(voice2Path) => int voice2ID;
quarter*16 => now;

// add violin
sectName(2);
Machine.add(violinPath) => int violinID;
Machine.add(drummerPath) => int drummerID;
quarter*12 => now;

// drum solo
s.sectionCall(2);
quarter*4 => now;

// restore
s.sectionCall(1);
quarter*12 => now;

// drum solo
s.sectionCall(2);
quarter*4 => now;

// cadenza
sectName(3);
s.sectionCall(3);
quarter*12 => now;

// drum solo
s.sectionCall(2);
quarter*4 => now;

// grand pause
s.sectionCall(3);
quarter*1 => now;
s.sectionCall(5);
quarter*7 => now;

// add back drum
sectName(4);
s.sectionCall(2);
quarter*4 => now;

// presto
s.sectionCall(6);
120 => float presto;
for (0=>int i; i<12; i++)
{
    presto*1.01 => presto;
    tempo.tempo(presto);
    tempo.quarterNote => quarter;
    quarter*2 => now;
}

// drum solo
tempo.tempo(120);
tempo.quarterNote => quarter;
s.sectionCall(2);
quarter*4 => now;

// last note
sectName(5);
s.sectionCall(3);
Machine.remove(violinID);
quarter*8 => now;


// stop all
s.sectionCall(4);
quarter*12 => now;
Machine.remove(drummerID);
Machine.remove(voiceID);
Machine.remove(voice2ID);