Friday, June 8, 2012

NETWORK SUCCESS!!!!

Successful network connection through OSC to play sounds generated from transmitting computer to receiving computer.  Lucy configured the iMac to communicate with chucK on her laptop and Julia's laptop, and shreds launched on the iMac played on their laptops.  Necessary code is below:



r.ck <Copy the code below to r.ck file>

// (launch with s.ck)

// the patch
SinOsc s => JCRev r => dac;
.5 => s.gain;
.1 => r.mix;

// create our OSC receiver
OscRecv recv;
// use port 6449 (or whatever)
6449 => recv.port;
// start listening (launch thread)
recv.listen();

// create an address in the receiver, store in new variable
recv.event( "/foo/notes, i f" ) @=> OscEvent @ oe;

// infinite event loop
while( true )
{
    // wait for event to arrive
    oe => now;

    // grab the next message from the queue. 
    while( oe.nextMsg() )
    { 
        int i;
        float f;

        // getFloat fetches the expected float (as indicated by "i f")
        oe.getInt() => i => Std.mtof => s.freq;
        oe.getFloat() => f => s.gain;

        // print
        <<< "got (via OSC):", i, f >>>;
    }
}

_____________________________________________________________________________

s.ck <Copy the code below to s.ck file>

// launch with r.ck

// name
"131.229.144.217" => string hostname;
6449 => int port;

// check command line
if( me.args() ) me.arg(0) => hostname;
if( me.args() > 1 ) me.arg(1) => Std.atoi => port;

// send object
OscSend xmit;

// aim the transmitter
xmit.setHost( hostname, port );

// infinite time loop
while( true )
{
    // start the message...
    // the type string 'i f' expects a int, float
    xmit.startMsg( "/foo/notes", "i f" );

    // a message is kicked as soon as it is complete 
    // - type string is satisfied and bundles are closed
    Std.rand2( 30, 80 ) => xmit.addInt;
    Std.rand2f( .1, .5 ) => xmit.addFloat;

    // advance time
    0.2::second => now;
}



No comments:

Post a Comment