Thursday, June 14, 2012

Kins Project Progress

//piano patch

//clarinet patch
Clarinet clarin => JCRev c => dac;
0 => c.gain;
.1 => c.mix;  

//flute patch

//organ patch
BeeThree org => JCRev o => Echo e => Echo e2 => dac;
o => dac;
   
// set delays
240::ms => e.max => e.delay;
480::ms => e2.max => e2.delay;
// set gains
//.6 => e.gain;
//.3 => e2.gain;
0 => o.gain;
0 => e.gain;
0 => e2.gain;
.05 => o.mix;

//brass patch


MAUI_View view;
view.name("Kins 2012");

MAUI_Button piano, clarinet, flute, organ, brass;
MAUI_LED lpiano, lclarinet, lflute, lorgan, lbrass;
MAUI_Slider volume;

view.size(500,250);

piano.pushType();
piano.size(100,100);
piano.position(0,0);
piano.name("piano");
view.addElement(piano);

clarinet.pushType();
clarinet.size(100,100);
clarinet.position(piano.x()+piano.width(),piano.y());
clarinet.name("clarinet");
view.addElement(clarinet);

flute.pushType();
flute.size(100,100);
flute.position(clarinet.x()+clarinet.width(),clarinet.y());
flute.name("flute");
view.addElement(flute);

organ.pushType();
organ.size(100,100);
organ.position(flute.x()+flute.width(),flute.y());
organ.name("organ");
view.addElement(organ);

brass.pushType();
brass.size(100,100);
brass.position(organ.x()+organ.width(),organ.y());
brass.name("brass");
view.addElement(brass);

lpiano.color(lpiano.blue);
lpiano.size(50,50);
lpiano.position(25,75);
lpiano.light();
view.addElement(lpiano);

lclarinet.color(lclarinet.blue);
lclarinet.size(50,50);
lclarinet.position(lpiano.x()+100, lpiano.y());
lclarinet.light();
view.addElement(lclarinet);

lflute.color(lflute.blue);
lflute.size(50,50);
lflute.position(lclarinet.x()+100,lclarinet.y());
lflute.light();
view.addElement(lflute);

lorgan.color(lorgan.blue);
lorgan.size(50,50);
lorgan.position(lflute.x()+100,lflute.y());
lorgan.light();
view.addElement(lorgan);

lbrass.color(lbrass.blue);
lbrass.size(50,50);
lbrass.position(lorgan.x()+100,lorgan.y());
lbrass.light();
view.addElement(lbrass);

volume.range(0,5);
volume.position (0,125);
volume.size(500,volume.height());
volume.name("Volume");
view.addElement(volume);

view.display();

[lpiano, lclarinet, lflute, lorgan, lbrass] @=>MAUI_LED leds[];
[622, 659, 698, 739, 783, 830,880, 932, 987, 1046, 1479,1567,1244,
349, 493, 174, 369, 415, 554, 440, 220, 311, 329, 1661, 1760,1864,
138,391,164,184,195,207,233,246,261,2093,2217,1108,587,523,155,466,146,293,277,2489,2637,2793,
61101016] @=>int keys[];
   
[131,139,156,165,185,208,233,247,277,311,330,370,415,
131,147,165,175,196,220,247,262,294,330,349,392,440,
523,554,622,659,740,831,932,988,69,78,82,93,
523,587,659,698,784,880,988,65,73,82,87] @=>int pitch[];

int ip, ic, ifl, io, ib;

function void volumeControl(){
    while (true){
       volume => now;
       if (ip == 1){
           <<<"volume">>>;
        }
        else if (ic == 1){
            volume.value() => c.gain;
        }
        else if (ifl == 1){
        }
        else if (io == 1){
            volume.value() => org.gain;
        }
        else if (ib == 1){
        }
        else{
        }
    }
}

function void ledControl(MAUI_LED led){
    for (0=>int i; i<leds.cap(); i++){
        leds[i].color(leds[i].blue);
        leds[i].light();        
    }
    led.color(led.green);
    led.light();
}

function void allinstrumentsControl(){
    while (true){
        if (ic == 1){
            clarinetSounds();
        }
        if (io == 1){
            organSounds();
        }
       
    }
  
   /* if (piano.state() == 0 || clarinet.state() == 0){
        while (true){
    <<< piano.state(), clarinet.state(), flute.state(),
    organ.state(), brass.state()>>>;
    if (piano.state() == 1){
        pianoControl();
    }
    else if (clarinet.state() == 1){
        clarinetControl();
    }
    else if (flute.state() == 1){
        fluteControl();
    }
    else if (organ.state() == 1){
        organControl();
    }
    else if (brass.state() == 1){
        brassControl();
    }
    else {
    }
}
}*/
}

function void pianoControl(){
    while (true){
        piano => now;
        if (piano.state() == 1){
            ledControl(lpiano);
            1=>ip;
            0=>ic=>ifl=>io=>ib;
            <<< ip, ic, ifl, io, ib>>>;
        }
    }
}

function void clarinetControl(){
    while (true){
        clarinet => now;
        if (clarinet.state() == 1){
            ledControl(lclarinet);
            1=>ic;
            0=>ip=>ifl=>io=>ib;
            <<< ip, ic, ifl, io, ib>>>;
            //clarinetSounds();
        }
    }
}

function void fluteControl(){
    while (true){
        flute => now;
        if (flute.state() == 1){
            ledControl(lflute);
            1=>ifl;
            0=>ip=>ic=>io=>ib;
            <<< ip, ic, ifl, io, ib>>>;
        }
    }
}

function void organControl(){
    while (true){
        organ => now;
        if (organ.state() == 1){
            ledControl(lorgan);
            1=>io;
            0=>ip=>ic=>ifl=>ib;
            <<< ip, ic, ifl, io, ib>>>;
        }
    }
}

function void brassControl(){
    while (true){
        brass => now;
        if (brass.state() == 1){
            ledControl(lbrass);
            1=>ib;
            0=>ip=>ic=>ifl=>io;
            <<< ip, ic, ifl, io, ib>>>;
        }
    }
}
function void pianoSounds(){
}
function void clarinetSounds(){
// HID
Hid hi;
HidMsg msg;
   
// which keyboard
0 => int device;
// get from command line
if( me.args() ) me.arg(0) => Std.atoi => device;
   
// open keyboard (get device number from command line)
if( !hi.openKeyboard( device ) ) me.exit();
<<< "keyboard '" + hi.name() + "' ready", "" >>>;
 
 
    // infinite event loop (the if was a while)
while (true){       
 // wait for event
 hi => now;
 // get message
 while ( hi.recv( msg ) ) {
     if( msg.isButtonDown() && ic == 1) {
         //0.75 => c.gain;
         volume.value() => c.gain;
         clarin.clear(1.0);
         1 => clarin.reed;
         Std.rand2f(0,1) => clarin.noiseGain;
         Std.rand2f(0,12) => clarin.vibratoFreq;
         Std.rand2f(0,1) => clarin.vibratoGain;
         Std.rand2f(0,1)=> clarin.pressure;                    
         // Std.mtof( msg.which + 45 ) => float freq;
         Std.mtof( msg.which+45) => float freq;
         freq $ int => int ifreq;
         <<< "Frequency: " + freq + "   " + ifreq>>>;
         if( ifreq > 20000 ) continue;
            for (0=>int i; i<keys.cap(); i++){
                if (ifreq == keys[i]){
                    pitch[i] => clarin.freq;
                    1 => clarin.noteOn;
                    //<<< "in: noteOn">>>;
                    300::ms=>now;
                }
                0 =>clarin.noteOff;
            }
        }
        0=>c.gain;
    }
 }
}

/**********************************************************************************************/
function void fluteSounds(){
}
/**********************************************************************************************/
function void organSounds(){
// HID
Hid hi;
HidMsg msg;
   
// which keyboard
0 => int device;
// get from command line
if( me.args() ) me.arg(0) => Std.atoi => device;
   
// open keyboard (get device number from command line)
if( !hi.openKeyboard( device ) ) me.exit();
<<< "keyboard '" + hi.name() + "' ready", "" >>>;

//0 => organ.gain;
   
// infinite event loop
while (true){
    // wait for event
    hi => now;
    // get message
    while ( hi.recv( msg) && io == 1) {
        // check
        //.75 => o.gain;
        volume.value() => o.gain;
        .6 => e.gain;
        .3 => e2.gain;
        if( msg.isButtonDown() ) {
            // Std.mtof( msg.which + 45 ) => float freq;
            Std.mtof( msg.which+45) => float freq;
            freq $ int => int ifreq;
            <<< "Frequency: " + freq + "   " + ifreq>>>;
            if( ifreq > 20000 ) continue;
           
            //.5 => organ.gain;
            for (0=>int i; i<keys.cap(); i++){
                if (ifreq == keys[i]){
                    pitch[i] => org.freq;
                    1 => org.noteOn;
                    80::ms=>now;
                }
                0 => org.noteOff;
             }
            
         }
         0=>e.gain;
         0=>e2.gain;
         0=>o.gain;
     }
 }
}
           
/**********************************************************************************************/
function void brassSounds(){
}

function void keyBoard(){
}
spork ~ pianoControl();
spork ~ clarinetControl();
spork ~ fluteControl();
spork ~ organControl();
spork ~ brassControl();
//spork ~ allinstrumentsControl();
spork ~ clarinetSounds();
spork ~ organSounds();

while (true){
    1::day=>now;
}

No comments:

Post a Comment