🔥 Lifetime deal! Get Control Surface Studio for Just £67 👉 Click Here To Get It
Time left... mailtimers.com
⚠️ Lifetime licenses are ending soon, get yours before they're gone ⚠️
Your shopping cart is empty.

[SOLVED] Defer your response, workarounds?

Submitted by fatphil on Sat, 04/15/2023 - 12:55
fatphil
Control Surface Studio User

I'm trying to do the following;

When the selected track changes, change the colour of track 1 to yellow

Yes it's just a test for now.

I've tried it several ways but I keep getting the error message

(nanoK Box) There's a problem with 'Action Block 1' in reaction 'Reaction Colour track' (from 'Song - selected track' listener) >>
>> Changes cannot be triggered by notifications. You will need to defer your response.

I've written the following Action block to try to work around it:


def set_song_track_color(song):
   song().tracks[0].color = 1676960
self.schedule_message(1000, set_song_track_color(self.song))

But I still get the same error. Why isn't self.schedule_message working?

Creating a reaction that sets a modifier and then a 2nd reaction that detects the changed modifier and sets the track colour results in the same error.

Topic Category: 

20 Responses

Comments

fatphil
Control Surface Studio User
#1

I've even placed my method in the user.py file but that doesn't work either. Same error message.

So my question is what CAN be triggered by notifications????

fatphil
Control Surface Studio User
#2

Maybe I'm not using the right tool for the job, LOL.
I see there's a M4L plugin that can auto colour tracks based on the track name. That's basically what I want to do!
https://www.youtube.com/watch?v=R-0pehhtl9I

However I could do this in CSS with say something that reacts to the stop or play button on my controller that then changes the colours, but I'd prefer it to be automatic when a track is renamed. Maybe ClyphX could do this?

trololololol
Control Surface Studio User
#3

Clyphx can do basically everything.

Nobody can help you without your json file. There is a lot of undocumented error Codes i dont know. I have to see your reactions to help you.

fatphil
Control Surface Studio User
#4

Thanks for helping. Here's the error and the file, stripped down to the bare minimum.
As a test I just want track 1 to change to that colour when any track selection happens.

(Colour) There's a problem with 'Action Block 1' in reaction 'Reaction 1' (from 'Song - selected track' listener) >>
>> Changes cannot be triggered by notifications. You will need to defer your response.

upload files: 
trololololol
Control Surface Studio User
#5

i absolutly dont know what you have in mind with your custom code :-) i think you tried to defy a method or something for custom colors? do you have a list where you point to?

i try to do everything in the software, so im not aware of programming. i just tinker here and there a litte bit.

i tried to do a reaction for your idea, i cant check it atm as im on the road.

Reaction 1:

1. Listener: when selected track value changes

2. Action 1 - this sets the track you had selected BEFORE the new one back to its color. Channel number in M2, Track color in M1.
this is why i have custom code here to point to the modifiers.

3. Action 2
Sets selected track to Color number. i just entered your number, you have to check that.

Reaction 2:
On script initizialize set the current selected track into M1 and M2.

WATCHOUT: havent tried this, im on the road. so its more a concept then a finished product.

I would love if you finish this and come back with a perfect solution for everybody to use.

i struggle with easy things still as i would like to set, instead of using 2 modifiers, this in a list as 2 items. but i struggle with the syntax and there is no help from developer atm.f

upload files: 
fatphil
Control Surface Studio User
#6

Thanks trololololol for taking the time to do that. I appreciate it.
The little bit of code I wrote defines a method that should be called after 100 ticks, thus deferring the response.

I'll try to give your idea a go tomorrow.

Phil

fatphil
Control Surface Studio User
#7

My goal was to automatically colour tracks based on their names. So say, Kick or Drums is always Black, Bass always Red etc. I've since found that Max4Live plugin which looks dead easy to use.

As far as I can tell, if an event (notification) originates from something in the live Object Model then it can't be used to trigger a reaction. I've seen workarounds that declare a method that should be called later, asynchronously. I imagine the idea is to minimize the chances of deadlocks or race conditions. It would be good if we could use schedule_message but it doesn't seem to work in the context of CSS.

Finally what I'm trying is out of scope of what you're supposed to be able to do with MIDI remote scripts. But it was worth a try.

I tried your solution and it worked great if the listen was on an external midi button, but if I put the listener on a Song Selected Track it complains for the same reasons I had:

(Colour copy) There's a problem with 'Action Block 1' in reaction 'Reaction 1' (from 'Song - selected track' listener) >>
>> Changes cannot be triggered by notifications. You will need to defer your response.
(Colour copy) There's a problem with 'Action Block 3' in reaction 'Reaction 1' (from 'Song - selected track' listener) >>
>> Changes cannot be triggered by notifications. You will need to defer your response.

Maybe John the developer could chip in at some point. I'd love to know his thoughts.

Thanks again,
Phil

trololololol
Control Surface Studio User
#8

Hi, thank you for your further investigation. I knew that UI Events cant trigger UI Events, but this should be possible. When i have i time i tinker around.

I wait for John to answer some topics for over a week now. i hope he comes back at some point in the future, seems like he has enough after the release 2.7 :-)

AH, so this is why you use a method and ticks, to separate the actions in the script and ableton doesnt notice... nice one, i will look into this stuff, i checked a basic programming course for next week..

could you name the M4L plugin as other users run into the same problem and will use this thread as help :-)

fatphil
Control Surface Studio User
#9

I too hope John returns soon! This app is awesome, with a little more organisation of the documenation, and more frequent support it will help so many producers! Once passed the initial learning curve it's so easy to use it's amazing!

As for the M4L plug-in it called Auto Track Colors
https://liveworkflowtools.gumroad.com/l/autotrackcolors
video demo here https://www.youtube.com/watch?v=R-0pehhtl9I

JohnC
Forum Admin
#10

Hi guys,
Yes the 'defer your response' error is a pain, I did do some investigation on this a while back but couldn't find a way around it.
If I remember right, I think clip actions might not get caught by this problem (i.e. when clip is triggered etc).

fatphil
Control Surface Studio User
#11

I finally figured it out. I was previously using self.schedule_message incorrectly

I looked at the decompiled Framework ControlSurface script and found the definition for
schedule_message :
def schedule_message(self, delay_in_ticks, callback, parameter=None)

So if you want to have an action that is triggered by the Live Object Model and that affects the Live object model you can do it with schedule_message.

Here's an example where I'm changing the first track's colour to a random one each time I select a track:

def my_set_color(self,myColor):
self.song().tracks[0].color = myColor

def _mode1_self_song_view_add_selected_track_listener_id_2(self):
try:
reaction_listener_number = 1
loop_is_active = False
loop_number = 0
loop_result_count = 0
self.schedule_message(1, self.my_set_color, random.randrange(0, 16581375))
except Exception as e:
self.log_message("csslog:(Colour) There's a problem with 'Action Block 1' in reaction 'Reaction 1' (from 'Song - selected track' listener) >> ")
self.log_message("csslog: >> " + str(e) )

Hope this helps someone!
Phil

fatphil
Control Surface Studio User
#12
JohnC
Forum Admin
#13

Hey Phil, thanks a lot for investigating and sharing this, I'll test it out and hopefully we can roll this into Reactions!

JohnC
Forum Admin
#14

While making a note of your comments Phil,
I just found a note to myself from a while ago:

A workaround of the defer issue is also to update a modifier value, then in a separate reaction, add a listener which waits for a change to that modifier and then update the UI in someway.

So it would look like this:
Reaction 1: - update 'modifier 1'
Reaction 2: - do another UI event.

ianef
Control Surface Studio User
#15

Hi All, I don't know if thangs have changed in 11.3.4, but I'm getting the same error even after trying the modifier approach. As an example I'm trying to arm the track on selection (yes I know -EnableArmOnSelection works!), using one reaction to set the modifier, and a modifier listener to arm the track:

There's a problem with 'Action Block 1' in reaction 'Arm Selected Track' (from 'modifier - m1 modifier was updated' listener) >>
Changes cannot be triggered by notifications. You will need to defer your response.

I'm pretty new to Ableton and CSS but I've found this tool a great help trying to get my Pacer and APC mini setup for liver performances.

Top job!

ianef
Control Surface Studio User
#16

OK. I have a workaround that works using the schedule_message method described by @fatphill.

In an action, add some custom code. Here I'm defining a local function whose scope is buried within the listener, I then create a pointer on the control surface class to that function so it can be seen from the schedule_message method:

def arm_selected_track():
self.song().tracks[self.get_selected_track_num()].arm = True

self.pacer_arm_selected_track = arm_selected_track
self.schedule_message(1, self.pacer_arm_selected_track)
return

So what's happening here?
The "def arm_selected_track():" and the next line define the function.
The "self.song().tracks[self.get_selected_track_num()].arm = True" is the body of the function that arms the track. You could add more funky stuff here but you must keep it indented to the same level.
The "self.pacer_arm_selected_track = arm_selected_track" declares a function on the class called pacer_arm_selected_track that points to my local function arm_selected_track.
The "self.schedule_message(1, self.pacer_arm_selected_track)" schedules a callback to pacer_arm_selected_track after 1 millisecond (I think!).

It's not the nicest way of solving this, but as a temporary hack it works. You need to be very careful about the naming of the method you are declaring on self. Always prefix this with something unique to you, in my case "pacer_" as it''s for a Pacer pedal. You don't want to screw up the core CSS code by overwriting John's functions.

Have fun!

ianef
Control Surface Studio User
#17

Arghh, the post lost my indentation! How do you mark text as code in this forum?

ianef
Control Surface Studio User
#18

Here's a sample callback to exclusively arm the newly selected track, just like adding -EnableArmOnSelection to Options.txt, except you can't accidentally turn it off by shift clicking and wonder why the hell it doesn't work any more!

ianef
Control Surface Studio User
#19

I found out how to mark text as code, hopefully, so here's another attempt to make it look correct:

def arm_selected_track():
tracks = self.song().tracks
for i in range(len(tracks)):
tracks[i].arm = (self.get_selected_track_num() == i)
self.log_message("csslog: index: " + str(i) + " selected: " + str(self.get_selected_track_num()) + " armed: " + str(tracks[i].arm))

self.pacer_arm_selected_track = arm_selected_track
self.schedule_message(1, self.pacer_arm_selected_track)

ianef
Control Surface Studio User
#20

Argghhhhhh.....