File: s-multi-msg.ck

package info (click to toggle)
chuck 1.5.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,056 kB
  • sloc: cpp: 123,473; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (70 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//----------------------------------------------------------------------------
// name: s-multimsg.ck
// desc: OSC example: sender for multiple message types
// note: launch with r-multimsg.ck
//
// author: Ge Wang (https://ccrma.stanford.edu/~ge/)
// date: spring 2022
//----------------------------------------------------------------------------

// destination host name
"localhost" => string hostname;
// destination port number
6449 => int port;

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

// sender object
OscOut xmit;

// aim the transmitter at destination
xmit.dest( hostname, port );

// spork sending loops, one for each message type
spork ~ sendNotes();
spork ~ sendHarmonics();

// keep allive
while( true ) 1::second => now;

fun void sendNotes()
{
    // infinite time loop
    while( true )
    {
        // start the message...
        xmit.start( "/foo/notes" );
        
        // add int argument
        Math.random2( 30, 80 ) => xmit.add;
        // add float argument
        Math.random2f( .1, .5 ) => xmit.add;
        
        // send it
        xmit.send();
        
        // advance time
        0.2::second => now;
    }
}

fun void sendHarmonics()
{
    // infinite time loop
    while( true )
    {
        // start the message...
        xmit.start( "/foo/harmonics" );
        
        // add int argument
        Math.random2( 1, 8 ) => xmit.add;
        
        // send it
        xmit.send();
        
        // advance time
        2.4::second => now;
    }
}