Difference between revisions of "Poly demo.ck"

From CSWiki
Jump to: navigation, search
Line 35: Line 35:
 
     mand =< dac;
 
     mand =< dac;
  
     //think about how to make this better with and envelope or ADSR
+
     //think about how to make this better with an envelope or ADSR
 
      
 
      
 
}
 
}
 
</pre>
 
</pre>

Revision as of 21:47, 25 February 2008

MidiIn min;
MidiMsg msg;

Event noteoffs[127];

// open midi receiver, exit on fail
if ( !min.open(1) ) me.exit(); 

while( true )
{
    // wait on midi event
    min => now;
    
    // receive midimsg(s)
    while( min.recv( msg ) )
    {
        // print content
        <<< msg.data1, msg.data2, msg.data3 >>>;
        
        if(msg.data3 > 0) spork ~ mand_note(Std.mtof(msg.data2), msg.data3/127., noteoffs[msg.data2]);
        else noteoffs[msg.data2].signal();
    }
}

fun void mand_note(float freq, float amplitude, Event mynoteoff) {
    
    Mandolin mand => dac;
    
    mand.freq(freq);
    mand.pluck(amplitude);
    
    mynoteoff => now;
    
    mand =< dac;

    //think about how to make this better with an envelope or ADSR
    
}