Republic assemble participants in network ensembles (sclang + scserver)


Inherits from: Object : SimpleRepublic


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

In addition to SimpleRepublic, Republic looks after a server object for each participant.



See also: Server, NetAddr, OSCresponder


For the other methods, see SimpleRepublic



join(nickname, clientID, serverPort)

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.

clientID: when sharing servers, each participant needs a different client ID, which is an integer between 0 and 31. If there are conflicting IDs in a group, "duplicate node id" errors will result.

serverPort: the port under which all servers are accessible (default: 57110).

servers

Returns a dictionary of all available servers.

addrs

Returns a dictionary of all available (sclang) addresses.

addSynthDef(synthDef)

Add a SynthDef to the repository. Participant servers and SynthDescLibs are kept updated. It is equivalent to calling memStoref or that SynthDef on each computer.


A shortcut is the message share, which adds the SynthDef to the default Republic. 

SynthDef(\x, { ... }).share;

removeSynthDef(name)

remove a given synthdef by name.

synthDefs

all locally added synthDefs.


synthDescs

all synthDescs in the republic.

sendServer(name ... args)

Send an OSC message (args) to the server of the given name. If the name is \all, the message is sent to all participant's servers, if it is an array, the message is sent to each server of the given names.

r.sendServer(\alice, '/s_new', \default, 1900, 1,1);

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

r.sendServer([\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 = Republic(NetAddr("192.168.178.255", 57120)).makeDefault; // put the ip here.

r.join(\alice, 0); // nickname and clientID. Each person in the group should have their own id.

r.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", "hi all."); 

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

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

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

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

// multiple names

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

g.remove; // remove responder

// server side:

r.servers; // a dictionary with all servers

r.servers.do { |server| server.makeWindow }; // make a window for each server

s.boot; // boot localhost

// share a SynthDef with all participants

(

SynthDef(\xxx, {|out, zzf = 440, sustain = 1, mod = 0.5, amp = 0.1, pan|

var env = Line.kr(1, 0, sustain, doneAction: 2);

Out.ar(out,

Pan2.ar(

RLPF.ar(

LFPulse.ar(zzf, 0, SinOsc.kr(mod * zzf)),

zzf * (env.cubed + mod + 0.5),

0.2

),

pan, env * amp

))

}).share;

)

r.synthDefs; // stored here, so participants can be updated.

SynthDescLib.global.at(\xxx); // it has arrived here, too.

r.synthDescs; // any shared descriptions are here

(

Tdef(\x, { 

loop { 

0.12.wait; 

(server: r.servers.choose, instrument: \xxx, 

zzf: exprand(300, 11111), mod: 0.03, sustain: 0.1).play;

} 

}).play

);

// test if pattern works here:

(

Pdef(\x, 

Pbind(

\instrument, \xxx,

\zzf, Pseq([8700, 800, 720], inf),

\mod, Pwhite(0.1, 0.7, inf),

\dur, Prand([0.3, 0.5, Pn(0.04, 5)], inf)

)

).play

)

// send synth messages to random participants:

(

Pdef(\x, 

Pbind(

\instrument, \xxx,

\server, Pfunc { r.servers.choose } .trace,

\zzf, Pseq([8700, 800, 720], inf),

\mod, Pwhite(0.1, 0.7, inf),

\dur, Prand([0.3, 0.5, Pn(0.04, 5)], inf)

)

).play

)

// leave republic.

r.leave;