SimpleRepublic assemble participants in network ensembles (sclang)


Inherits from: Object


Simplify synchronisation of networks. SimpleRepublic makes it easy to join and quit a running session.

For server and client side support, see  Republic



See also: NetAddr, OSCresponder




*new(broadcastAddr, republicName)

Return a new instance, which is not active yet.

broadcastAddr - The NetAddr with the broadcast IP of the current network, and the default langPort of SuperCollider (57120). If the langPort is different, setup fails. Restart SC for retrieving the correct port.

republicName  - The OSC command for communication. Separate sessions should have different names. Default: '/republic'


*default

*default_(a republic)

Get or set the default republic. Works like Server.default.


makeDefault

Make a given republic the default one.

join(nickname)

Join the current republic under a given nickname. After a couple of seconds, the other members' addresses are collected. The NetAddr is switched to send to broadcast IP.

leave

Leave the current republic. Network connections are closed and addresses / servers are removed.

The NetAddr is switched to block send to broadcast IP (if it was off before).

addrs

Returns a dictionary of all available (sclang) addresses.



send(name ... args)

Send an OSC message (args) to the SClang of the given name. If the name is \all, the message is sent to all participants, if it is an array, the message is sent to each participant of the given name.

r.send(\alice, '/chat', "alice speaking", "ping ping");

r.send(\all, '/chat', "alice speaking", "hi all");

r.send([\bob, \charlie], '/chat', "alice speaking", "hi all");


Examples



// first get the broadcast addr of your local network:

unixCmd("ifconfig | grep broadcast | awk '{print $NF}'") // usually this works.

// make a new instance

r = SimpleRepublic(NetAddr("192.168.178.255", 57120));

r.join(\alice);

r.nickname; // nickname

r.addrs; // a dictionary of all net addresses. May take some seconds until filled.

// make some OSC responder

g = OSCresponder(nil, '/chat', {|t,r,msg| (">" + msg[1] + ":" + msg[2]).postln }).add; 

// send to one address. This may not yet exist and fail.

r.addrs[\alice].sendMsg('/chat', "alice speaking", "hi all."); 

// if you are not sure if a participant is absent

r.send(\alice, '/chat', "alice speaking", "hi all");

// if you want to send to everyone, use the name \all:

r.send(\all, '/chat', "alice speaking", "hi all");

// multiple names

r.send([\alice, \john], '/chat', "alice speaking", "hi all");

// leave republic.

r.leave;