1 // used to bundle and cache set, map, mapa, setn, mapn, mapna commands.
5 var <>settings; // cache args:
6 var <>upToDate, <>setArgs, <>setnArgs, <>mapArgs, <>mapnArgs, <>mapaArgs, <>mapanArgs;
19 settings = IdentityDictionary.new;
25 forBy(0, args.size-1, 2, { arg i;
26 this.get(args.at(i)).map(args.at(i+1));
32 forBy(0, args.size-1, 2, { arg i;
33 this.get(args.at(i)).mapa(args.at(i+1));
41 setting = settings.at(key);
42 if(setting.notNil and: { setting.isMapped }) {
43 setting.map(nil, nil);
44 if(setting.isEmpty) { settings.removeAt(key) }
52 forBy(0, args.size-1, 2, { arg i;
53 this.get(args.at(i)).set(args.at(i+1));
58 setn { arg ... args; this.set(*args) }
64 setting = settings.at(key);
65 if(setting.notNil and: { setting.isMapped.not }) {
66 setting.map(nil, nil);
67 if(setting.isEmpty) { settings.removeAt(key) }
74 forBy(0, args.size-1, 3, { arg i;
75 this.get(args.at(i)).mapn(args.at(i+1), args.at(i+2));
81 forBy(0, args.size-1, 3, { arg i;
82 this.get(args.at(i)).mapan(args.at(i+1), args.at(i+2));
87 send { arg server, nodeID, latency;
90 this.addToBundle(bundle, nodeID);
91 server.listSendBundle(latency, bundle);
94 sendToNode { arg node, latency;
96 this.send(node.server, node.nodeID, latency)
106 setting = settings.at(key);
108 setting = this.settingClass.new(key);
109 settings.put(key, setting)
120 settings.do { arg item; if(item.isMapped.not) { res = res.add(item.key) } };
125 settings.do { arg item; if(item.isMapped) { res = res.add(item.key) } };
132 setArgs = setnArgs = mapArgs = mapnArgs = mapaArgs = mapanArgs = nil;
133 settings.do { arg item; item.updateNodeMap(this) };
134 controlNames = settings.values.collect { |setting|
135 ControlName(setting.key, nil, setting.mappedRate, setting.value)
140 addToEvent { arg event;
141 settings.do { |x| x.addToEvent(event) }
144 addToBundle { arg bundle, target;
146 target = target.asNodeID;
148 if(setArgs.notNil) { bundle.add([15, target] ++ setArgs) };
149 if(setnArgs.notNil) { bundle.add([16, target] ++ setnArgs) };
150 if(mapArgs.notNil) { bundle.add([14, target] ++ mapArgs) };
151 if(mapnArgs.notNil) { bundle.add([48, target] ++ mapnArgs) };
152 if(mapaArgs.notNil) { bundle.add([60, target] ++ mapaArgs) };
153 if(mapanArgs.notNil) { bundle.add([61, target] ++ mapanArgs) };
156 unsetArgsToBundle { arg bundle, target, keys;
158 if(settings.isEmpty) { ^this };
159 (keys ?? { settings.keys }).do { arg key;
161 item = settings[key];
162 if(item.notNil) { args = args ++ [key, -1] }
164 if(args.notNil) { bundle.add([15, target.asNodeID] ++ args) };
167 unmapArgsToBundle { arg bundle, target, keys;
169 if(settings.isEmpty) { ^this };
170 (keys ?? { settings.keys }).do { arg key;
172 item = settings[key];
173 if(item.notNil and: { item.isMapped }) {
174 args = args ++ [key, -1, item.busNumChannels];
177 if(args.notNil) { bundle.add([48, target.asNodeID] ++ args) };
180 blend { arg another, frac;
182 another.updateBundle;
183 another.setArgs.pairsDo { |key, x|
184 var s = settings[key], y;
185 s !? { y = s.getValue };
186 y !? { res.set(key, blend(y, x, frac)) }
194 res = this.class.new;
196 settings.keysValuesDo({ arg key, val; nset.put(key, val.copy) });
200 printOn { arg stream;
201 stream << this.class.name << "(";
202 settings.printItemsOn(stream);
210 ProxyNodeMap : NodeMap {
212 var <>parents, <>proxy;
217 parents = IdentityDictionary.new;
224 wakeUpParentsToBundle { arg bundle, checkedAlready;
225 parents.do({ arg item; item.wakeUpToBundle(bundle, checkedAlready) });
229 forBy(0, args.size-1, 2, { arg i;
230 var key, rate, setting;
232 setting = this.get(key);
234 if(rate.isNil and: { setting.notNil } and: { setting.isEmpty })
235 { settings.removeAt(key) }
236 { setting.rate_(rate) };
238 hasRates = settings.any { arg item; item.rate.notNil };
243 keys.collect({ arg key;
245 res = settings.at(key);
246 if(res.notNil, { res.rate }, { nil })
252 this.map(args) // for now, avoid errors.
257 playing = proxy.isPlaying;
258 args.pairsDo { arg key, mapProxy;
259 var setting, numChannels;
260 if(mapProxy.isKindOf(BusPlug).not) { Error("map: not a node proxy").throw };
261 if(playing) { mapProxy.wakeUp };
262 setting = this.get(key);
263 setting.map(mapProxy);
264 parents = parents.put(key, mapProxy);
269 mapEnvir { arg ... keys;
271 keys = keys ? settings.keys;
272 args = Array.new(keys.size*2);
273 keys.do({ arg key; args.add(key); args.add(currentEnvironment.at(key)) });
277 unmap { arg ... keys;
279 if(keys.at(0).isNil, { keys = this.mappingKeys });
281 setting = settings.at(key);
283 setting.map(nil, nil);
284 parents.removeAt(key);
285 if(setting.isEmpty, { settings.removeAt(key) })