How to create a reaction for a button in mode toggle ?

363 viewsCSS Community ScriptsButton toggle
0

Hello everyone
I’m trying to create a reaction for a button in toggle mode like for the “track mute” function. Example :
– Button 1 was pressed = set loop is ON
– Button 1 was pressed again = set loop is OFF
With a feedback LED on button 1.
Should I put button 1 on my controller and on the CSS in Momentary mode or Toggle mode?
Thanks in advance

Fabrice Planquette Answered question December 7, 2024
2

In a Reaction, if your button sends a Momentary CC, then the Reaction that Listens to that button will fire each time you press AND release your button. Because you want the Reaction to act as a Toggle, you can account for this by making the first Action exit the Reaction whenever the button is released (in other words, whenever a value of 0 is sent by the button). This is how you could set the first Action up:

Listener

Button 1

Action Block 1

Condition: Button 1 value >> is equal to >> 0

Action: “Script” >> “Exit Reaction Here”

If you have set the button on your controller to Toggle, then you may skip that previous Action Block.

For the rest of your Reaction, you’ll need at least 2 Action Blocks: 1 for activating the loop and one for deactivating it. We can also give each Action Block an Action to send a value to the button itself, to give the button LED Feedback. This is how you can set up those Action Block (I’ll continue the numbering from the previous example):

Action Block 2

Condition: “set loop” >> is equal to >> 0 (in other words, only fire this action when loop is deactivated)

Action 1: “set loop” to 1

Action 2: “Send MIDI velocity value” of 127 to Button 1

Action Block 2

Condition: “set loop” >> is equal to >> 1 (in other words, only fire this action when loop is activated)

Action 1: “set loop” to 0

Action 2: “Send MIDI velocity value” of 0 to Button 1

I’m guessing the “loop” parameter you need can be found in the menu like this:

“Live Object Model” >> “Song” >> “Set Loop”

Glenn Verhaeghe Answered question December 6, 2024
0

This first one from Glenn is very clever and simple, just add an exit reaction to the first block when applying to a modifier.

You could also do this using this method : https://community.remotify.io/questions/question/cycle-through-values-with-1-button/

And for the LED feedback you could simply send this value scaled to 0-127 to the corresponding controller.

ie if i range is 0-1, self.midi_cc_ch_0_val_2.send_value(i*127) (for controller CC2 ch1).

gwen971 Posted new comment December 8, 2024

Thank for your answer. I work today I will check this tonight. Have a good day

Hi
Thanks for the set loop that’s OK !!
I’m trying to transpose the function to set mute.
Led = 60 = mute off
Led = 15 = mute on
Led = 12 = track M1 doesn’t exist.
I managed to add the return led = 12 when we delete track M1. But I can’t make the LED = 60 when I create a new m1 track. I have to click button 9 (set mute) twice for the LED to come back on. If you have a solution, I thank you in advance. Here is the code below.

Listener :
– script is initialized
– button 9 was pressed
– m1 modifier was updated
– self.song().tracks[self.get_modifier_value(“m1”)].add_name_listener

Action block 1 :
conditions : self.song().tracks[self.get_modifier_value(“m1”)].mute == False
action :
self.song().tracks[self.get_modifier_value(“m1”)].mute = True
self.midi_cc_ch_6_val_50.send_value(15)
return

Action block 2
condition : self.song().tracks[self.get_modifier_value(“m1”)].mute == True
actions :
self.song().tracks[self.get_modifier_value(“m1”)].mute = False
self.midi_cc_ch_6_val_50.send_value(60)

action 3
condition : self.get_modifier_value(“m1”) == -1
self.midi_cc_ch_6_val_50.send_value(12)

if you have a solution thanks

It is because when you create a new track, the condition to have LED at 60 is only “is it muted? = yes”.
Maybe you should add an OR condition for m1 == -1

Thanks I found the solution. I removed the led feedback from the reaction st Mute and I created a specific reaction for the led feedback set mute using the script that you previously sent me. Everything works, it’s perfect. Thanks again