| 1 |
// Listing 11.3 Simple OSC sender |
| 2 |
|
| 3 |
// First, make an OSC send object and set port # |
| 4 |
OscOut xmit; // (1) Makes an OSC output object. |
| 5 |
6449 => int port; // (2) Port number to send OSC on. |
| 6 |
xmit.dest ( "localhost", port ); // (3) Sets network destination to this computer. |
| 7 |
|
| 8 |
// infinite time loop |
| 9 |
while( true ) // (4) Infinite loop. |
| 10 |
{ |
| 11 |
// start the message, after prefix (our choice) |
| 12 |
// expects one int, one float, one string |
| 13 |
xmit.start( "/myChucK/OSCNote" ); // (5) Starts OSC output. |
| 14 |
|
| 15 |
Math.random2(48,80) => int note; // (6) Computes a random int note |
| 16 |
Math.random2f(0.1,1.0) => float velocity; // (7) Computes a random float velocity |
| 17 |
"Hi out there!!" => string message; // (8) Makes a string message |
| 18 |
|
| 19 |
// a message is kicked as soon as it is complete |
| 20 |
// - type string is satisfied and bundles are closed |
| 21 |
note => xmit.add; // (9) Adds note to output. |
| 22 |
velocity => xmit.add; // (10) Adds velocity to output. |
| 23 |
message => xmit.add; // (11) Adds string to output. |
| 24 |
xmit.send(); // (12) Send it! |
| 25 |
|
| 26 |
// hang a bit, then do it again |
| 27 |
0.2 :: second => now; |
| 28 |
} |