KrBusWatcher : NodeWatcher


Repeatedly polls control buses for their value and updates dependents assigned to the bus objects. Based on NodeWatcher.


*newFrom(server) 


Returns the KrBusWatcher belonging to this server. If the KrBusWatcher has already been created, the same one will be returned; otherwise a new one will be created.


*register(bus)

*unregister(bus) 

register(bus)

unregister(bus) 


Add or remove a bus from the list of buses to monitor. Buses may be given as any object that responds to .asBus


startAliveThread

stopAliveThread 


Start and stop the routine that periodically asks the server for the bus values.


You should not need to use these methods manually. The alive thread is started whenever you register a bus, and it's stopped when all buses are unregistered.


Buses get updated based on /c_setn responses coming from the server. To get these responses, the client has to send /c_getn messages. The alive thread sends these messages.


Note: if the bus watcher is running when you press cmd-., all the buses will be unregistered and the alive thread will be stopped. 


Every cycle, all the dependents of the Bus object will receive the .update message with the args (bus, value). value will be an array with one float for each channel in the bus. One channel buses will return a one element array.


Updater (crucial lib) is a useful class that sets up a function as a dependant of any Object.


Example: 


s.boot;


(

b = Bus.control(s, 1);

a = { LFNoise1.kr(0.1, 0.5, 0.5) }.play(s, b);

KrBusWatcher.register(b);


f = FlowView.new;

x = GUI.slider.new(f, Rect(0, 0, 100, 15));

u = Updater(b, { |bus, val|

{ x.value_(val[0]); }.defer;

});

)


(

KrBusWatcher.unregister(b);

u.remove;

a.free; b.free;

a = b = f = x = u = nil;

)