Found a way to use timers/animation with Ableton

6

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.

Glenn V. Answered question

Would you be able to make flashing led function that could be incorporated into your user.py file and used along side of timer so that it could be used to make buttons behave like delayed switches that flash when toggled and shine when held?

been really interested in your code, so i started doing some changes so that I could use it as delayed on/off switch and figured id be nice if my buttons blinked as well depending on their function.

Yes, I think it’s possible. I made flashing LED’s before using this method. Handling the flash and shine like you’re asking shouldn’t be too difficult. I’m finishing up on something else first, then I’ll look into this.

Hi Makill, I’ll post my progress on your request in an answer here. This comment is meant as a notification.

0

Hi Makill,

Here’s a link to the user.py file. There is info on how to use the toggle_delayedSwitchLED function inside the document. It works as listed out in my previous comment.

There are also a few other functions, some of which are being used by toggle_delayedSwitchLED, that can be used separately as well:

  • A custom modifier dictionary with a few functions to manage it with. Used by toggle_delayedSwitchLED.
  • A custom log function that I’ve used for warning and error messages. Used by toggle_delayedSwitchLED.
    • It gives the ability to add a short all-caps descriptor before the actual message, making it easy to visually filter all of the messages.
  • The `timed_action` function and class that were made for making custom button_hold actions with. NOT used by toggle_delayedSwitchLED.

Let me know if this is what you wanted or if you had something different in mind.

makill01 Posted new comment

Hi,

I’ve been looking into your user.py and to be honest I am a bit confused by it. It contains something about inner ring, outer ring and multiple colors, which I am not certain what is meant by it. I am using Akai MidiMix which has buttons that have only ON(127) or OFF(0) state and have only one color on each button.

What I was hoping to achieve is that I would have 8 buttons set up as SOLO buttons for 8 tracks that could be pressed briefly to turn SOLO for each track and begin flashing to indicate SOLO is ON, then pressed again to turn SOLO OFF which would stop flashing or held (either one or more buttong at the same time) to activate SOLO and light up held button  for as long as it is held.

to simplify things:

– Button 1 is pressed -> track 1 SOLO is ON and Button 1 LED start flashing until pressed again, which deactivates SOLO and LED flashing
– Button 1 is held -> Track 1 SOLO is ON and Button 1 is lit up until released, , which deactivates SOLO and LED feedback

I’ve been trying to achieve this dual button function with your timed_action reaction and would like to add LED feeback to it.
hope this sums up what I am trying to achieve.

Thanks for your help.

My apologies. Seems I’ve uploaded the wrong user.py file. I’ve updated the link with the correct one.

I misunderstood the ‘holding down’ part. I’ll fix that in an update.

I’ll also check if I can make the soloing work as you describe.
I have a MIDIMIX at home, and I’m guessing you’re using the same template from on Remotify (?), so I should be able to test it out in full.

Yes I am using Remotify template for MidiMix

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