| 1 |
//---------------------------------------------------------------------------- |
| 2 |
// name: r.ck ('r' is for "receiver") |
| 3 |
// desc: OpenSoundControl (OSC) receiver example |
| 4 |
// note: launch with s.ck (or another sender) |
| 5 |
//---------------------------------------------------------------------------- |
| 6 |
|
| 7 |
// the patch |
| 8 |
SinOsc s => JCRev r => dac; |
| 9 |
.5 => s.gain; |
| 10 |
.1 => r.mix; |
| 11 |
|
| 12 |
// create our OSC receiver |
| 13 |
OscIn oin; |
| 14 |
// create our OSC message |
| 15 |
OscMsg msg; |
| 16 |
// use port 6449 (or whatever) |
| 17 |
6449 => oin.port; |
| 18 |
// create an address in the receiver, expect an int and a float |
| 19 |
oin.addAddress( "/foo/notes" ); |
| 20 |
|
| 21 |
// infinite event loop |
| 22 |
while( true ) |
| 23 |
{ |
| 24 |
// wait for event to arrive |
| 25 |
oin => now; |
| 26 |
|
| 27 |
// grab the next message from the queue. |
| 28 |
while( oin.recv(msg) ) |
| 29 |
{ |
| 30 |
// print stuff |
| 31 |
cherr <= "received OSC message: \"" <= msg.address <= "\" " |
| 32 |
<= "typetag: \"" <= msg.typetag <= "\" " |
| 33 |
<= "arguments: " <= msg.numArgs() <= IO.newline(); |
| 34 |
|
| 35 |
// check typetag for specific types |
| 36 |
if( msg.typetag == "if" ) |
| 37 |
{ |
| 38 |
// expected datatypes: int float |
| 39 |
// (note: as indicated by "if") |
| 40 |
int i; |
| 41 |
float f; |
| 42 |
|
| 43 |
// fetch the first data element as int |
| 44 |
msg.getInt(0) => i => Std.mtof => s.freq; |
| 45 |
// fetch the second data element as float |
| 46 |
msg.getFloat(1) => f => s.gain; |
| 47 |
|
| 48 |
// print |
| 49 |
cherr <= i <= " " <= f <= IO.newline(); |
| 50 |
} |
| 51 |
} |
| 52 |
} |