JavaScript, LiveAPI, and device/object removal

Learn about building and using Max for Live devices.
Post Reply
DirectGumby
Posts: 50
Joined: Sun Oct 25, 2009 2:40 pm

JavaScript, LiveAPI, and device/object removal

Post by DirectGumby » Sat Oct 02, 2010 6:54 pm

Hello,

I am looking for a clean way to know if an ojbect has been removed/deleted and the id assosciated with that removal/deletion.

When looking at the current data I am not able to understand when a delete/remove of a LiveObject has happened.

Does anyone have a good idea(s) on how to do this in JavaScript with the LiveAPI?

Thank you for your time and help,
Brett

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: JavaScript, LiveAPI, and device/object removal

Post by amounra93 » Sat Oct 02, 2010 10:53 pm

If there is a callback assigned to the object, I think it may report "id 0" if the object is deleted. If not, you'd have to poll it periodically.
http://www.aumhaa.com for Monomod and other m4l goodies.

DirectGumby
Posts: 50
Joined: Sun Oct 25, 2009 2:40 pm

Re: JavaScript, LiveAPI, and device/object removal

Post by DirectGumby » Sun Oct 03, 2010 2:46 am

I did not see a message from the callback that indicated that an object was going/has gone away.
I also did not see any reference to this in the manual (although that does not imply that I have not missed it <grin>).

As for polling, yes I could do that indeed, problem there is that I still have an issue with that for two reasons: 1) It is expensive to poll objects all the time and 2) there will be a tradeoff between how expensive I want the polling to be and how large the gap will be between when something goes away and when I can know that it has gone.

Thank you for the idea... i'll take another look, perhpas there is a change notification sent to the parent of the device going away as the parent is observing the children.

Thanks,
Brett

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: JavaScript, LiveAPI, and device/object removal

Post by amounra93 » Sun Oct 03, 2010 8:27 am

Yeah, I know where you are coming from.

You are correct: I thought that maybe the callback would register an id 0 on deletion, but I just checked it and it doesn't.

I made a similar complaint some time ago to someone at Cycling about not having listeners for stuff like this, and got a reply that was something like 'either you can poll it via LiveAPI or we <c74> can poll it internally...there is no difference'.

So, yeah, it costs something, but its not that expensive. All you are doing is checking a property of an object that you've already instantiated; you're not actually making a change to the Live set's properties. Give it a try, I think you will find its not so bad (cpu wise).

Unfortunately I don't think there is another way to do it at this point.

I manage this sort of thing differently depending upon what object I'm trying to keep track of. You can always trigger the poll based on other things changing in the set (like tracks added/deleted, which there is a listener for). I'm working on some Python scripts that will eventually be bridgeable to m4l that deal with this sort of thing better, but they are a long way off. I don't even know that it will be that much more efficient (but I suspect it will be).

If you want to keep track of absolutely everything, I'd probably use an array. Just add each API element to the array when you create the element, and recurse the array at an interval (called by an external metro, not a Task: Task's have caused me all sorts of problems in conjunction with m4l due to all js code running in the same thread) to make sure that the element still has an id > 0.
http://www.aumhaa.com for Monomod and other m4l goodies.

hoffman2k
Posts: 14718
Joined: Tue Jun 15, 2004 6:40 pm
Location: Belgium
Contact:

Re: JavaScript, LiveAPI, and device/object removal

Post by hoffman2k » Sun Oct 03, 2010 8:34 am

Not sure how this works with JS, but with objects like live.observer you can now get empty lists. So if something is observing ID 7 and the ID gets removed/deleted, live.observer sends an empty list. Its like a bang without a bang. You can detect it with "ZL Len" for example. The empty list returns a 0.

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: JavaScript, LiveAPI, and device/object removal

Post by amounra93 » Sun Oct 03, 2010 9:32 am

What versions did this start with? I haven't updated to 8.2 yet....
http://www.aumhaa.com for Monomod and other m4l goodies.

hoffman2k
Posts: 14718
Joined: Tue Jun 15, 2004 6:40 pm
Location: Belgium
Contact:

Re: JavaScript, LiveAPI, and device/object removal

Post by hoffman2k » Sun Oct 03, 2010 9:51 am

My bad, its an incremental update http://cycling74.com/downloads/incremental/

Should be part of the next Max update whenever it appears.

DirectGumby
Posts: 50
Joined: Sun Oct 25, 2009 2:40 pm

Re: JavaScript, LiveAPI, and device/object removal

Post by DirectGumby » Sun Oct 03, 2010 2:23 pm

Interesting... I wonder if this will also update the JS part as well so that one can get a notification of device removal. Maybe I'll ask over there on their side. The inital reason I asked here and not on the c74 site was that I felt Live had to hook up the ability to notify when something went away. The the c74 guys could propigate the message. Somewhere in Live it knows the device/object is going away because the UI goes away and things get unloaded... so, just before it does all of that I thought it would be nice to get a message on that ID saying "goodbye" or some other notification of removal.

I may give the Max update a try.

Thanks,
Brett

Post Reply