MIDI double tap, long pressed etc

Greetings,

MIDI triggers are very useful way of triggering actions and I love this feature.
Also, triggering one hot key in multiple ways is very useful too (double tapped, long pressed etc.) but there is no such options for MIDI triggers. Why? :slight_smile:

I tried one workaround: triggering keystroke action with MIDI and then used that keystroke for triggering hot key macro with options for double tap and long press but it didn't work.

Cheers,
V

I'm not capable of speaking for "The Architect" of KM, but my guess is that MacOS has an API for the various kinds of keypresses that KM supports, like double click, or press, or release, but the API in MacOS for MIDI note recognition probably does not support those "options." That's my guess for what the answer is.

But I think your request is reasonable. And possibly doable. Let me explain.

I don't think the API limitation stops you from creating a KM macro (or subroutine) that emulates these "double click" types of features. There's a small chance that you might persuade me to (try to) write these functions for you. Exactly which modifiers do you want implemented for MIDI keys:

Screen Shot 2022-02-13 at 10.28.58 AM

Bear in mind the following point from the KM docs. This illustrates some of the problems with defining these special types of button clicks.

You can configure the trigger to execute when the key is tapped (press and released quickly) each time, the first tap, double tapped, triple tapped, or quadruple tapped (v7.0+). Keep in mind that Keyboard Maestro cannot see the future, so “tapped once” will will fire even on the first tap even if you tap the key twice (“tapped” would fire both times).

I'm not sure if anyone else wants these special types of clicks for MIDI signals, but from what I can see right now it's doable. My plan would be as follows:

  1. Create a KM macro that a user calls when they want to register the kind of MIDI click that they want to take action on. It would probably look like this:
  2. Create a KM macro that triggers on any MIDI note, and if the note matches one of the registered actions (this requires some tricky but not impossible code), calls the macro named in the registration process.
  3. I think the user has to remove all other MIDI triggers from their program so that this will work. That's because, I believe, two conflicting MIDI triggers will bring up a palette rather than run both macros triggered by a duplicate trigger.

You know, this could be easier for us if KM supported running multiple macros for the same trigger. But I don't think it does. There are several times I've wanted two macros to run from the same hotkey simultaneously, but I don't think KM supports this idea. But now that you've raised this point, I think I have just come up with an idea to have two macros invoked by the same trigger. You've really helped me out here today, thanks.

1 Like

Good news, everybody (apologies to Futurama.) I've built a prototype that allows people to trigger multiple macros from the same Hotkey. It seems to work fine. It does have a small downside that I'm trying to eliminate before I publish it.

But the idea, in principle, should work for your MIDI note requirements, too. It has the same idea: you register what you want to do with a macro, and you have another macro implement what you registered. It's just "adding a level of indirection" which is what good programming is all about. In my case I managed to put both the registration and the execution into a single macro, but that's just coding trickery that doesn't really add anything important.

1 Like

This was an easy adaptation of my existing double tap / long press macro.

Here are two macros:

Midi Multipress.kmmacros (385.8 KB)

The second keeps note of midi traffic. The first macro makes use of this by watching for "00" in the midi packet, which indicates note-off (you've released the key). This macro is automatically disabled when not in use to avoid KM unnecessarily reading MIDI data all the time.

Set up the midi trigger in the first macro to receive a note on whichever channel/device you like. Hit the note once or twice (quickly) or hold it down a bit longer and you'll see "Single", "Double" or "Long" pop up onscreen respectively. Replace these display text actions with whatever you want the macro to do. Feel free to make as many duplicates as you like, which will all reference the same Monitor macro.

Edit: I've updated it (v2) to work a bit differently and it's slightly snappier. It also allows you to choose which types of presses to detect and add a triple-tap action. I've left the original macro (v1) in there too, as a disabled group, in case you prefer it.

Macro 1 (v1) Screenshot

Macro 1 (v2) Screenshot

Macro 2 Screenshot

Wow. I didn't know you could trigger like that on MIDI. I think I'm going to connect my MIDI keyboard and see if it will be a functional substitute for a Stream Deck. Using Regex in that is brilliant. I had no idea about that feature. KM always surprises me.

I can't recommend Stream Deck enough though... The visual feedback is something I'd struggle to live without now.

Updated above...

I figured out a way to get it to work standalone, as in without needing the Midi Monitor companion macro. It works nicely, although you have to hold the button slightly longer for it to register as a 'long press'. Changing the timing of the long press check loop doesn't seem to change this, so I think it might be something to do with the macro triggering on both press and release and seeing whole loop twice... or something. If you can figure it out, let me know! Regardless, some people might prefer this as it's self-contained.

Multipress - Midi Standalone (Beta).kmmacros (72.4 KB)

Screenshot