Monitor playing clip of a track (not selected or triggered)

Daniel Skantze's icon

I have a midi controller with a grid of programmable buttons. Besides sending a midi message when a button is pressed, I can also send a midi message to the controller to light up a specific button.

I want to use this grid to light up the index of the clip playing for a certain track and also to be able to trigger the same clip.

I want this to work regardless if I trigger a clip from the Ableton UI or the controller. This means that just maintaining the state of the controller is not an option, instead I would want to monitor (or poll) the playing state of each clip slot and respond to changes.

I have created a patch that does this but I am getting this error:

live.object: Setting the Id cannot be triggered by notifications. You will need to defer your response.

I have tried to put a deferlow at different places in the patch. I have also tried to use pipe to delay different parts. None has worked.

In the attached patch you can see what I have tried (I have also indicated the offending part of the patch).

I am quite new to programming Max MSP and maybe I am taking the wrong approach here? I would really appreciate some help.

get-playing-track-clip_slot.maxpat
Max Patch