//score

// paths to chuck files
me.dir() + "/1910.ck" => string Path1910;
me.dir() + "/1920.ck" => string Path1920;
me.dir() + "/1930.ck" => string Path1930;
me.dir() + "/1940.ck" => string Path1940;
me.dir() + "/1950.ck" => string Path1950;
me.dir() + "/1960.ck" => string Path1960;
me.dir() + "/1970.ck" => string Path1970;
me.dir() + "/1980.ck" => string Path1980;
me.dir() + "/1990.ck" => string Path1990;
me.dir() + "/piano.ck" => string PathPiano;

// Start Classes
Keystroke keys;
Interpreter franz;
Sonify sonify;
Section s;

// define variables
"" => string word;

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

// initialize keyboard event
KBHit kb;

tempo.quarterNote => dur quarter;

Machine.add(Path1910) => int ID1910;
Machine.add(Path1920) => int ID1920;
//Machine.add(Path1930) => int ID1930;
Machine.add(Path1940) => int ID1940;
Machine.add(Path1950) => int ID1950;
Machine.add(Path1960) => int ID1960;
Machine.add(Path1970) => int ID1970;
Machine.add(Path1980) => int ID1980;
Machine.add(Path1990) => int ID1990;
Machine.add(PathPiano) => int IDPiano;

s.set1910(0);
s.set1920(0);
s.set1930(0);
s.set1940(0);
s.set1950(0);
s.set1960(0);
s.set1970(0);
s.set1980(0);
s.set1990(0);
s.setpiano(0);

// Hid object
Hid Typewriter;
// message to convey data from Hid device
HidMsg key;

// device number: which keyboard to open
0 => int device;

// open keyboard; or exit if fail to open
if( !Typewriter.openKeyboard( device ) ) me.exit();
// print a message!
<<< "THE HENRY FORD VARIATIONS by Jason E. Weber" >>>;
0.5::second => now;
<<< "Keyboard Found:'" + Typewriter.name() + "'">>>;
0.5::second => now;
<<< "Syntax to Start: S1Y1 (S1 = Section 1, Y1 = Year 1910, Section 0 is silence)" >>>;

// infinite event loop
while( true )
{
    // wait for event
    Typewriter => now;
    
    // get message
    while( Typewriter.recv( key ) )
    {
        // filter out button down events
        if( key.isButtonDown() )
        {
            // take ascii value of button, send to interpreter
            keys.listen(key.ascii);
            franz.translate(keys.currLetter) => word;
        }
        else // on release
        {
            if ((word != "") && (key.ascii == 32))
            {
                spork ~ sonify.word(word);
                quarter => now;
                <<>>;
                
            }  
            if ((word != "") && (key.ascii == 10))
            {
                spork ~ sonify.word(word);
                quarter => now;
                <<>>;
            } 
        }
    }
    
}