Debian Codegraph @

examples/osc/multi-msg/s-multi-msg.ck

raw
1 //----------------------------------------------------------------------------
2 // name: s-multimsg.ck
3 // desc: OSC example: sender for multiple message types
4 // note: launch with r-multimsg.ck
5 //
6 // author: Ge Wang (https://ccrma.stanford.edu/~ge/)
7 // date: spring 2022
8 //----------------------------------------------------------------------------
9
10 // destination host name
11 "localhost" => string hostname;
12 // destination port number
13 6449 => int port;
14
15 // check command line
16 if( me.args() ) me.arg(0) => hostname;
17 if( me.args() > 1 ) me.arg(1) => Std.atoi => port;
18
19 // sender object
20 OscOut xmit;
21
22 // aim the transmitter at destination
23 xmit.dest( hostname, port );
24
25 // spork sending loops, one for each message type
26 spork ~ sendNotes();
27 spork ~ sendHarmonics();
28
29 // keep allive
30 while( true ) 1::second => now;
31
32 fun void sendNotes()
33 {
34 // infinite time loop
35 while( true )
36 {
37 // start the message...
38 xmit.start( "/foo/notes" );
39
40 // add int argument
41 Math.random2( 30, 80 ) => xmit.add;
42 // add float argument
43 Math.random2f( .1, .5 ) => xmit.add;
44
45 // send it
46 xmit.send();
47
48 // advance time
49 0.2::second => now;
50 }
51 }
52
53 fun void sendHarmonics()
54 {
55 // infinite time loop
56 while( true )
57 {
58 // start the message...
59 xmit.start( "/foo/harmonics" );
60
61 // add int argument
62 Math.random2( 1, 8 ) => xmit.add;
63
64 // send it
65 xmit.send();
66
67 // advance time
68 2.4::second => now;
69 }
70 }