I'm programming a midi controller using KM amongst other things. It has OLED displays that I write to using MIDI OUT that is being sent from KM. KM also monitors MIDI IN.
The OLED displays the name of a controller but when that controller is adjusted, it displays the value of the controller setting. What I want to achieve is to keep displaying the controller value until say after 5 seconds of it not changing and then revert to the name.
While doing this, KM needs to keep running and do other things. Happy that KM will keep tending whilst the controller is changing but once it is no longer changing, how do I set an "alarm" for say 5 seconds, to tell KM to revert to the default display?
Hope that makes some sense...
I’m unfamiliar with midi controllers, but if you already have KM interfacing with it could you simply add a 5 second pause and then send the command to set it back to its default display?
Thanks for your reply.
I could do that but it would mean (as I understand matters) that KM would not act upon anything else in the 5 second period or have I misunderstood that?
No, Keyboard Maestro is fully asynchronous. A macro can be paused for an hour, and other macros will continue to operate normally.
What is the situation if the same macro is called whilst in a paused state, will it run in parallel?
In the particular case, it is quite likely that another midi control might be adjusted within 5 seconds of a previous one being touched.
You can add a semaphore lock to the beginning of that macro and have it set to a short timeout to prevent it from triggering again if it's already running.
See this wiki entry.
I have a few macros that run every 15 seconds while certain apps are open, and if for some reason a particular instance takes longer than 15 seconds to execute, it could mean that the same macro is triggered again and now they are both running at the same time. To avoid this, I add the semaphore lock as the first action in those macros, and give it a unique name. I then set it's timeout to 1 second. This means that any other macro that has a semaphore lock with that same name, will wait for the first macro to finish running, and in this case, timeout if it takes longer than 1 second.
This should prevent your midi control macro from having multiple instances running at the same time. Below is a screenshot of one of those macros. It gets the microphone's mute status and changes my Stream Deck icon accordingly in case my SD was changed to a different profile when I triggered my mute and the icon was unable to update (none of that is really relevant, but it explains why I have this macro repeating every 15 seconds).
You'll notice the first action is a semaphore lock, with a rather generic name in this case "Lock Macros". This way nothing else with this semaphore lock with the same name that executes at the same time as this macro will interfere with it, while all my other macros will run as normal.
Hope that makes sense!
The issue is that I do want it to trigger again. The macro will trigger if any one of 8 midi events takes place; it will note which event caused the trigger and then instruct one of 8 consequences.
The alternative is 8 macros but this means if I change the algorithm at all, I have to replicate across the 8 pieces of code.
I just barely realized you had responded the other day, sorry for not seeing this sooner.
At this point it’d probably be beneficial to upload your current macro so we can take a look at it and make some recommendations. I’m unfamiliar with midi triggered macros so it’s hard for me to wrap my head around your use case without seeing the macro.