//Violin 3

BPM tempo;
section s;



// initialize variables
0 => int b;

// sound chain
Bowed vio => NRev rev => dac;

// create notes object
notes notes;
notes.scale(63,66,68,69,70,73,75,51);

// create 2D chord array
[notes.chord1,notes.chord2,notes.chord3,notes.chord4] @=> int chords [][];



while ( true )
{
    tempo.sixteenthNote => dur hit;
    
    b % 32 => int count16;
    count16/2.0 => float count8;
    count8/2.0 => float count4;
    
    
    if ((s.number == 1) || (s.number == 5) || (s.number == 6))
    {
        1 => vio.gain;
        1.0 => vio.volume;
        5 => vio.vibratoFreq;
        0.05 => vio.vibratoGain;
        
        if ((count8 == 0.0) || (count8 == 1.0) || (count8 == 2.0))
        {
            Math.random2(0,notes.notes.cap()-1) => int i;
            Std.mtof(notes.notes[i]) => vio.freq;
            1.0 => vio.startBowing;
        }
        
        if ((count8 == 8.0) || (count8 == 10.0) || (count8 == 12.0))
        {
            if (Math.random2(0,5) == 1)
            {
                Math.random2(0,notes.notes.cap()-1) => int i;
                Std.mtof(notes.notes[i]) => vio.freq;
                1.0 => vio.startBowing;
            }
        }
        
        if (count8 == 15.5)
        {
            1.0 => vio.stopBowing;
        }
        
    }  
    
    if (s.number == 2)
    {
        1 => vio.gain;
        1.0 => vio.volume;
        5 => vio.vibratoFreq;
        0.05 => vio.vibratoGain;
        
        if (count4 == 0.0)
        {
            Std.mtof(notes.notes[1]-12) => vio.freq;
            1.0 => vio.startBowing;
        }
        
        if (count4 == 3.0)
        {
            1.0 => vio.stopBowing;
        }
    }
    
    if (s.number == 3)
    {
        1 => vio.gain;
        1.0 => vio.volume;
        5 => vio.vibratoFreq;
        0.05 => vio.vibratoGain;
        
        if (Math.random2(0,5) == 2)
        {
            Math.random2(0,notes.notes.cap()-1) => int i;
            Std.mtof(notes.notes[i]) => vio.freq;
            1.0 => vio.startBowing;
        }
        
    }
    
    
    
    hit => now;
    
    b+1 => b;    
}