Found a way to use timers/animation with Ableton
Recently learned about threading in python, which is a way to have multiple different functions run at the same time.
Without threading, functions would be run one after the other, which means the next function in line needs to wait until the current one is finished.
If, for example, your current function has a sleep_timer set to 10 seconds, then it would take 10 seconds before the next function in line is called.
Because of this, we can’t simply use a timer in our Reactions because it would jam up Ableton until the timer has finished.
With threading however, the function with the sleep_timer could be counting its 10 seconds away while a second function has already fired up.
How to initiate a thread
The following image shows the basics:
When the thread is started, it will run whatever code is inside myFunction.
Notice how myFunction is inserted in the Thread using the keyword argument target.
However, you might want the code in myFunction to be in a loop. How would you exit the loop?
When using your code inside a Reaction, you can use Modifiers to carry the on/off switch:
Example
I’ve added a Reaction to this post with an example. It’s made for MIDI Fighter Twister with a momentary switch, although you could use any controller, as long as you don’t forget to adjust the condition, which checks if the button you’re using as a Listener has a value of 127.
This Reaction uses the following code:
As you can see I made 2 functions:
- lower_volume
- Lowers the master volume by 0.01 every 0.1s when a thread has been activated
- toggle_volume_lowering
- This is the function that is called by the Reaction
- When a thread is already active, it stops that thread
- When no thread is active, it creates and activates a thread that runs the lower_volume function
Post-scriptum
I was also able to make the LED’s on my MFT animate in a pattern (continuously changing colors of the inner and outer buttons of the device) while still being able to use Ableton.
That´s cool! Now you can have Launchpad Pro functionality (touch fader) with a simple Launchpad Mini…..
Dieter
Just a simple example for a reaction, works well. Code is more or less self explaining.
Dieter
Sign up
User registration is currently not allowed.
Thanks John. I’m working on a class in a user.py file (+ some documentation) to set up actions with that perform after holding a button for some time. If it’s ready, I’ll make a separate post about it.