Live Javascript API: Observe multiple properties from one LiveAPI object
If the feature exists, I would like to have the ability for one LiveAPI object with multiple observers attached to it:
let api = new LiveAPI("live_set tracks 0")
api.property = "mute solo arm"
//OR
api.property = ["mute", "solo", "arm"]
rather than have one LiveAPI object per observer (the current implementation) :let muteObserver = new LiveAPI("live_set tracks 0")
let soloObserver = new LiveAPI("live_set tracks 0")
let armObserver = new LiveAPI("live_set tracks 0")
muteObserver.property = "mute"
soloObserver.property = "solo"
armObserver.property = "arm"
As shown in the first code snippet, I have tried both a string containing space delimited properties as well as an array of properties as strings. Neither return desired output (mute 0
, arm 1
, solo 0
etc.) - nor do they throw errors in the console. It seems this syntax might possibly work with the current callback system implemented by the LiveAPI object, which would allow for the user to specify an individualized handler for each property within the callback function.
The reasoning for wanting this is 1: more compact and easier to manage code (in some cases) and 2: more efficient operation, assuming creating multiple LiveAPI objects also creates extra overhead (although I haven't yet tested whether having up to thousands of observers, as per my use case, is currently feasible)
Another alternative would be to allow for the LiveAPI object to observe all properties (maybe by passing "allprops" as an argument or something) and executing the callback each time one of them changes. Ideally both solutions would exist.
Because I am unsure of whether these features exist, I am posting here to inquire. If it doesn't, I will forward the feature request to C74.
I would also like this feature!
I wonder if something like this would work:
myObj.property = "mute"
myObj.property = "solo"
myObj.property = "arm"
Or maybe something like
myObj.property = "mute,solo,arm"
multiple times? I've seen in Zach Steinkamp's Chiastic Slide that one can filter the callback based on the name of the property; see here. I've also seen that the documentation for LiveAPI.property does state
The observed property, child or child-list of the object at the current path, if desired. For instance, if the LiveAPI object refers to "live_set tracks 1", setting the property to "mute" would cause changes to the "mute" property of the 2nd track to be reported to the callback function defined in the LiveAPI Constructor.
I don't yet see how best to specify a "child-list", but it seems like the syntax could in theory be overloaded for property names.
Mattijs commented in observers - Observe property changes inside the drum rack/chains - Stack Overflow that there's no way currently for this to happen:
For every property you want to observe, you need to create a LiveAPI object with a callback property ... There is one pitfall though: at the time of this writing there is no way to unregister an observing LiveAPI object. So if you create new ones often, Live may at some point start to become sluggish.
I would have expected that LiveAPI object garbage collection would have removed the listeners. I suspect we need some evidence that doesn't happen to really conclude that the event handlers are not gc'd.
I'd also like this feature, it seems much more elegant than multiple instantiation.