| 1 |
//---------------------------------------------------------------------------- |
| 2 |
// name: midi2osc-r.ck |
| 3 |
// desc: starter code for receiving OSC from midi2osc |
| 4 |
// |
| 5 |
// author: Ge Wang (https://ccrma.stanford.edu/~ge/) |
| 6 |
// date: Spring 2024 |
| 7 |
//---------------------------------------------------------------------------- |
| 8 |
|
| 9 |
// create our OSC receiver |
| 10 |
OscIn OIN; |
| 11 |
// create our OSC message |
| 12 |
OscMsg MSG; |
| 13 |
// use port 6449 (or whatever) |
| 14 |
6449 => OIN.port; |
| 15 |
|
| 16 |
// received INT |
| 17 |
global int R_INT; |
| 18 |
// receved FLOATS |
| 19 |
global float R_FLOAT1; |
| 20 |
global float R_FLOAT2; |
| 21 |
global float R_FLOAT3; |
| 22 |
|
| 23 |
// allow any address |
| 24 |
OIN.addAddress( "*" ); |
| 25 |
|
| 26 |
// infinite event loop |
| 27 |
while( true ) |
| 28 |
{ |
| 29 |
// wait for event to arrive |
| 30 |
OIN => now; |
| 31 |
|
| 32 |
// grab the next message from the queue. |
| 33 |
while( OIN.recv(MSG) ) |
| 34 |
{ |
| 35 |
// print stuff (useful for debugging) |
| 36 |
// cherr <= "received OSC message: \"" <= MSG.address <= "\" " |
| 37 |
// <= "typetag: \"" <= MSG.typetag <= "\" " |
| 38 |
// <= "arguments: " <= MSG.numArgs() <= IO.newline(); |
| 39 |
|
| 40 |
// check message and typetag |
| 41 |
if( MSG.address == "/foo/control/knob" && MSG.typetag == "if" ) |
| 42 |
{ |
| 43 |
// fetch the first data element as int |
| 44 |
MSG.getInt(0) => R_INT; |
| 45 |
// fetch the second data element as float |
| 46 |
MSG.getFloat(1) => R_FLOAT1; |
| 47 |
|
| 48 |
// print |
| 49 |
cherr <= "received OSC: " <= R_INT <= " " <= R_FLOAT1 <= IO.newline(); |
| 50 |
} |
| 51 |
// check message and typetag |
| 52 |
else if( MSG.address == "/foo/control/button" && MSG.typetag == "if" ) |
| 53 |
{ |
| 54 |
// fetch the first data element as int |
| 55 |
MSG.getInt(0) => R_INT; |
| 56 |
// fetch the second data element as float |
| 57 |
MSG.getFloat(1) => R_FLOAT1; |
| 58 |
|
| 59 |
// print |
| 60 |
cherr <= "received OSC: " <= R_INT <= " " <= R_FLOAT1 <= IO.newline(); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|