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 already listening for incoming network messages.
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.
leave (free)
Leave the current republic.
If free is true, free the republic's resources (default is false)
nameIsFree(name)
Returns true if the name is not in use already.
free
free the republic's resources.
Network connections are closed and addresses are removed.
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");
gui(parent, bounds)
Return an EZRepublicGUI and open the window with an overview and a minimal chat (Hit tab key for sending message).
shareHistory
Open the commandline history and shares it with all participants. See History.
Examples
// make a new instance. NetAddr broadcast flag is switched to true.
r = SimpleRepublic(NetAddr("255.255.255.255", NetAddr.langPort));
// make a gui to monitor its state
r.gui;
// individual status messages from other participants may come in
// before you join the republic - then one can see who is already there,
// and which names are already in use.
// if they are not renewed, they fade away.
r.broadcastAddr.sendMsg('/republic', \dada);
r.broadcastAddr.sendMsg('/republic', \otto);
r.broadcastAddr.sendMsg('/republic', \alice);
r.addrs; // a dictionary of all current net addresses.
r.join(\alice);
r.join(\alice); // have joined already
r.join(\bob); // please leave before rejoining
r.leave
// wait a bit..
r.join(\alice); // please leave before rejoining
r.nickname; // nickname
// 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");
r.send([\alice, \bob], '/chat', "alice speaking", "hi all");
// leave republic. you can still see who else is in.
r.leave;
// free its resources:
r.free;
// and maybe turn broadcasting back off if desired
NetAddr.broadcastFlag = false;