CSS extra coding
I see that CSS allows to use some coding inside action blocks. It works well when some condition, parsing code added there. But i see a problem with adding attributes. As there are not enough modifiers, and storing data outside is not comfortable, i would like to know:
Is there a way to store data inside CSS scripts?
ChatGPT is suggesting to add this code into an action:
if not hasattr(self, "_rec_blink_active"): self._rec_blink_active = False if not self._rec_blink_active: self._rec_blink_active = True self.midi_cc_ch_0_val_16.send_value(57)
But this crushes ableton really hard so the reaction stop working correctly by parts or the whole reaction misses…
Only PC reboot helps.
So is there a way to add attributes and store data there? What is a correct way to do so if possible?
Does CSS allow def in actions?
Like can i insert this in action block? And what is a proper way to declare functions? To make a repetetive blink for led and not to have a time listener in reaction.
def _blink_tick(self):
# stop if no longer active
if not getattr(self, "_blink_active", False):
return
# get current sub (1..4)
t = self.song().get_current_beats_song_time()
parts = str(t).replace(",", ".").split(".")
sub = int(parts[2]) if len(parts) >= 3 and parts[2].isdigit() else 1
sub = min(4, max(1, sub))
# toggle on sub 1 / off on sub 3 (your original pattern)
if sub == 1:
self.midi_cc_ch_0_val_16.send_value(57)
elif sub == 3:
self.midi_cc_ch_0_val_16.send_value(0)
# schedule next tick (fastest is 1)
self.schedule_message(1, self._blink_tick)
You can also declare variables in Actions.
Useful when you need duplicate mappings with only a few parameters changed; you can put those parameters in variables in the first Action; no need to search through the different Action Blocks or code to change them.
Yep, that helps. I created outgoing midi send functions for easy remapping.
Sign up
User registration is currently not allowed.
Yes, CSS allows to define functions. They will be available only in the same reaction where they were declared.
!!! BUT NOT ALWAYS !!!