105 lines · 2.3 KB · Text
RawDownload
//------------------------------------------------// name: polyfony2.ck// desc: polyfonic clarinet model with midi input//// authors: Ananya Misra and Ge Wang// send all complaints to prc@cs.princeton.edu//-------------------------------------------- // device to open0 => int device;// get from command lineif( me.args() ) me.arg(0) => Std.atoi => device; MidiIn min;MidiMsg msg; // try to open MIDI port (see chuck --probe for available devices)if( !min.open( device ) ) me.exit(); // print out device that was opened<<< "MIDI device:", min.num(), " -> ", min.name() >>>;  // make our own eventclass NoteEvent extends Event{    int note;    int velocity;} // the eventNoteEvent on;// array of ugen's handling each noteEvent @ us[128]; // the base patchGain g => JCRev r => dac;.1 => g.gain;.2 => r.mix; // handler shred for a single voicefun void handler(){    // don't connect to dac until we need it    Clarinet c;    Event off;    int note;     // inifinite time loop    while( true )    {        on => now;        on.note => note;        // dynamically repatch        c => g;        Std.mtof( note ) => c.freq;        .4 + on.velocity / 128.0 * .6 => c.startBlowing;        off @=> us[note];         off => now;        c.stopBlowing( 10.0 );        null @=> us[note];        100::ms => now;        c =< g;    }} // spork handlers, one for each voicefor( 0 => int i; i < 20; i++ ) spork ~ handler(); // infinite time loopwhile( true ){    // wait on midi event    min => now;     // get the midimsg    while( min.recv( msg ) )    {        // catch only noteon        if( (msg.data1 & 0xf0) == 0x90 )        {            // check velocity            if( msg.data3 > 0 )            {                // store midi note number                msg.data2 => on.note;                // store velocity                msg.data3 => on.velocity;                // signal the event                on.signal();                // yield without advancing time to allow shred to run                me.yield();            }            else            {                if( us[msg.data2] != null ) us[msg.data2].signal();            }        }        else if( (msg.data1 & 0xf0) == 0x80 )        {            us[msg.data2].signal();        }    }}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t