Moving session box while a button is pressed / repeating an action while a condition is met

2.84K viewsCSS Community Scriptssession box
0

Hello everyone,

So I’d like to get a ‘long’ button pressed to continuously move the session box, so that it stops only when I release the button (e.g. when I press down and the box goes down several scenes until I release the button). Right now, I can only get one button press = one move. I tried a bit through both Session box navigation and through reactions (for instance by creating several times the same action) but I did not manage to create this behavior – but to be honest my knowledge at this point is still very limited.
Is there a way to mimic such behavior?  (it’s the original behavior for the APC40 MK2 but could be useful to anyone).

More generally I think the issue is about: “How can we repeat any action (like moving session box down one scene) as long as a condition is met (like button X is still pressed) ?” A bit like a ‘while’ condition in programming.

In the case ‘a button still pressed’ cannot be detected, I guess we could have something like “move the box down” several times with a very short delay between each move (so it’s not instantenous) when the button is pressed, and when the button is released, end this action (a bit like in the shift mode tutorial). But I have no clue how to programm that – I did’nt manage to get a box moving down several times in a row, and not idea how to implement a short delay between actions.

Any help is welcome!

Cheers

neoseed Answered question
0

Maybe something like this would work, it would require 2 Reactions:

Reaction 1:
Add a reaction which changes the value of a modifier to ‘1’ when the button is pressed,
set it to ‘0’ when button is released.
To achieve this you would use the current velocity value of the button in the condition section of the action block.

Condition:  ‘midi controller > current velocity value > button 1’s current velocity value’
‘is equal to’
127 (or whatever velocity value your button sends when pressed)

Action: ‘script > modifiers – set value of a modifier’
modifier: m1
value to set: 1

And then add a second action block in the Reaction which does the same but checks if button velocity is 0, if it is, set the modifier value to 0

Reaction 2:
write a while loop in the Reaction action (in custom code view), which keeps looping while the modifier is set to 1.
Include a timeout/delay to control the speed of the loop.

while self.get_modifier_value("m1"):
    # the session box navigation code - this will move the session box right
    self.set_sessionbox_offsets(self.get_sessbox_track_offset() + 1, self.get_sessbox_scene_offset())
     # Pause for 1 second before continuing the loop
    time.sleep(1)  # You can adjust the time in seconds

The listener for this could be either:
when the button is pressed (midi controller > button 1 was pressed)
Or
when the value of the modifier changes (script > modifiers >m1 modifier was updated)

JohnC Edited comment

One thing to note, this will probably pause execution of everything else while it is looping, so you couldn’t i.e turn a knob at the same time to adjust the volume

You are viewing 1 out of 6 answers, click here to view all answers.