3 var <rate,<index,<numChannels,<server;
6 *control { arg server,numChannels=1;
8 server = server ? Server.default;
9 alloc = server.controlBusAllocator.alloc(numChannels);
11 error("Meta_Bus:control: failed to get a control bus allocated."
12 + "numChannels:" + numChannels + "server:" + server.name);
15 ^this.new(\control,alloc,numChannels,server)
17 *audio { arg server,numChannels=1;
19 server = server ? Server.default;
20 alloc = server.audioBusAllocator.alloc(numChannels);
22 error("Meta_Bus:audio: failed to get an audio bus allocated."
23 + "numChannels:" + numChannels + "server:" + server.name);
26 ^this.new(\audio,alloc,numChannels,server)
28 *alloc { arg rate,server,numChannels=1;
29 ^this.perform(rate ? \audio,server,numChannels);
32 *new { arg rate=\audio,index=0,numChannels=2,server;
33 ^super.newCopyArgs(rate,index,numChannels,server ? Server.default)
40 set { arg ... values; // shouldn't be larger than this.numChannels
42 server.sendBundle(nil,(["/c_set"]
43 ++ values.collect({ arg v,i; [index + i ,v] }).flat));
44 }, {error("Cannot set an audio rate bus")});
46 setMsg { arg ... values;
49 ++ values.collect({ arg v,i; [index + i ,v] }).flat
50 }, {error("Cannot set an audio rate bus"); ^nil});
54 // could throw an error if values.size > numChannels
56 server.sendBundle(nil,
57 ["/c_setn",index,values.size] ++ values);
58 }, {error("Cannot set an audio rate bus")});
62 ^["/c_setn",index,values.size] ++ values;
63 }, {error("Cannot set an audio rate bus"); ^nil});
65 setAt { |offset ... values|
66 // shouldn't be larger than this.numChannels - offset
68 server.sendBundle(nil,(["/c_set"]
69 ++ values.collect({ arg v,i; [index + offset + i ,v] }).flat));
70 }, {error("Cannot set an audio rate bus")});
72 setnAt { |offset, values|
73 // could throw an error if values.size > numChannels
75 server.sendBundle(nil,
76 ["/c_setn",index + offset, values.size] ++ values);
77 }, {error("Cannot set an audio rate bus")});
79 setPairs { | ... pairs|
81 server.sendBundle(nil,(["/c_set"]
82 ++ pairs.clump(2).collect({ arg pair; [pair[0] + index, pair[1]] }).flat));
83 }, {error("Cannot set an audio rate bus")});
87 if(numChannels == 1, {
88 action = action ? { |vals| "Bus % index: % value: %.\n".postf(rate, index, vals); };
89 OSCpathResponder(server.addr,['/c_set',index], { arg time, r, msg;
90 action.value(msg.at(2)); r.remove }).add;
91 server.listSendMsg(["/c_get",index]);
92 }, {this.getn(action)});
95 getn { arg count, action;
96 action = action ? { |vals| "Bus % index: % values: %.\n".postf(rate, index, vals); };
97 OSCpathResponder(server.addr,['/c_setn',index],{arg time, r, msg;
98 action.value(msg.copyToEnd(3)); r.remove } ).add;
99 server.listSendMsg(this.getnMsg(count));
105 ^["/c_getn",index, count ? numChannels];
109 if (not(this.isSettable)) {
110 Error("Bus-getSynchronous only works for control-rate busses").throw;
112 ^server.getControlBusValue(index);
116 getnSynchronous {|count|
117 if (not(this.isSettable)) {
118 Error("Bus-getnSynchronous only works for control-rate busses").throw;
120 ^server.getControlBusValues(index, count ? numChannels);
124 setSynchronous { |... values|
125 if (not(this.isSettable)) {
126 Error("Bus-setSynchronous only works for control-rate busses").throw;
128 if (values.size == 1) {
129 server.setControlBusValue(index, values[0])
131 server.setControlBusValues(index, values)
136 setnSynchronous {|values|
137 if (not(this.isSettable)) {
138 Error("Bus-setnSynchronous only works for control-rate busses").throw;
140 server.setControlBusValues(index, values)
144 fill { arg value,numChans;
145 // could throw an error if numChans > numChannels
146 server.sendBundle(nil,
147 ["/c_fill",index,numChans,value]);
151 ^["/c_fill",index,numChannels,value];
156 if(index.isNil,{ (this.asString + " has already been freed").warn; ^this });
158 server.audioBusAllocator.free(index);
160 server.controlBusAllocator.free(index);
167 // allow reallocation
170 if(rate === 'audio', {
171 index = server.audioBusAllocator.alloc(numChannels);
173 index = server.controlBusAllocator.alloc(numChannels);
181 r = rate; n = numChannels;
183 rate = r; numChannels = n;
188 // alternate syntaxes
190 this.fill(value,numChannels);
194 this.fill(value,numChannels);
197 printOn { arg stream;
198 stream << this.class.name << "(" <<*
199 [rate, index, numChannels, server] <<")"
202 storeOn { arg stream;
203 stream << this.class.name << "(" <<*
204 [rate.asCompileString, index, numChannels, server.asCompileString] <<")"
207 ^this.compareObject(aBus, #[\index, \numChannels, \rate, \server])
210 ^this.instVarHash(#[\index, \numChannels, \rate, \server])
213 isAudioOut { // audio interface
214 ^(rate === \audio and: {index < server.options.firstPrivateBus})
217 ar { |numChannels=(this.numChannels), offset=0|
219 ^In.ar(index + offset, numChannels)
221 //"Bus converting control to audio rate".inform;
222 ^K2A.ar( In.kr(index + offset, numChannels) )
225 kr { |numChannels=(this.numChannels), offset=0|
227 ^A2K.kr( In.ar(index + offset, numChannels) )
229 ^In.kr(index + offset, numChannels)
233 play { arg target=0, outbus, fadeTime, addAction=\addToTail;
234 if(this.isAudioOut.not,{ // returns a Synth
235 ^{ this.ar }.play(target, outbus, fadeTime, addAction);
239 asUGenInput { ^this.index }
240 asControlInput { ^this.index }
244 if(index.isNil) { MethodError("bus not allocated.", this).throw };
245 mapSymbol = if(rate == \control) { "c" } { "a" };
246 mapSymbol = (mapSymbol ++ index).asSymbol;
250 // added by nescivi; gets a subbus from another bus
252 *newFrom { |bus, offset, numChannels=1|
253 if ( offset > bus.numChannels or: {numChannels + offset >
256 Error( "Bus:newFrom tried to reach outside the channel range of
257 %".format( bus )).throw
259 ^Bus.new( bus.rate, bus.index + offset, numChannels);
262 subBus{|offset, numChannels=1|
263 ^Bus.newFrom( this, offset, numChannels );