2 var <messages, <preparationMessages;
4 add { arg msg; messages = messages.add(msg) }
5 addAll { arg mgs; messages = messages.addAll(mgs) }
6 addPrepare { arg msg; preparationMessages = preparationMessages.add(msg) }
8 // the sound starts at: (next beat + latency) when the preparation is finished
9 // the client side task starts at: preparationTime + next beat
10 // next beat is 0 if no clock is passed in.
11 // eventstreams e.g. take into account the latency internally
13 schedSend { arg server, clock, quant;
14 server = server ?? { Server.default };
15 this.doPrepare(server, {
16 if(quant.isNil or: { clock.isNil }) {
17 this.prSend(server, server.latency)
19 clock.schedAbs(quant.nextTimeOnGrid(clock), {
20 this.prSend(server, server.latency);
26 send { arg server, time, timeOfRequest;
27 server = server ?? { Server.default };
28 timeOfRequest = timeOfRequest ?? {Main.elapsedTime};
29 this.doPrepare(server, { this.prSend(server, time,timeOfRequest) })
31 // see atTime helpfile
32 sendAtTime { arg server, atTime, timeOfRequest; // offset by preparation
33 server = server ?? { Server.default };
34 atTime.schedBundle(this,server,timeOfRequest ?? { Main.elapsedTime});
37 doPrepare { arg server, onComplete;
38 if(preparationMessages.isNil) { ^onComplete.value };
41 server.sync(Condition.new, preparationMessages);
49 prSend { arg server, delta,timeOfRequest;
51 server.listSendBundle(delta ?? { server.latency }, messages);
58 MixedBundle : OSCBundle {
60 var <sendFunctions; // functions to evaluate on send
61 var <functions; // functions to evaluate when the bundle is scheduled on the server
65 sendFunctions = sendFunctions.add(func);
67 addFunction { arg func;
68 functions = functions.add(func);
70 sched { arg time=0.0, func;
71 sendFunctions = sendFunctions.add({ SystemClock.sched(time, { func.value; nil }) });
74 addMessage { arg receiver, selector, args;
75 functions = functions.add( Message(receiver,selector,args) )
77 addOnSendMessage { arg receiver, selector, args;
78 sendFunctions = sendFunctions.add( Message(receiver,selector,args) )
83 functions.do({ arg item; item.value });
86 sendFunctions.do({ arg item; item.value });
91 prSend { arg server, delta, timeOfRequest;
93 delta = server.latency;
95 if(timeOfRequest.notNil,{
96 delta = (timeOfRequest + delta) - Main.elapsedTime;
98 ("bundle sent late:" + delta).warn;
99 delta = 0.0;// just send it now
103 if(functions.notNil) {
104 SystemClock.sched(delta ? 0.0, {
108 if(messages.notNil) {
109 server.listSendBundle(delta, messages);
111 this.doSendFunctions;