Extracting values from a MIDI trigger, and getting them at all anyway

Hi all -

I'm having issues with MIDI triggers. I want to look for packets as a trigger. They appear as hex - three sets of two characters - and when using MIDI Learn appear with a "^" character at the top, thus: ^9B 01 7F$

I want to extract the middle pair, here represented as 01, and set a variable to that value. Have not been able to do so. I'd thought that using the token for Tripped Trigger Text or Tripped Trigger Value would work, and that I could just use TriggerValue[2], but this hasn't worked. And I get no response from these macros when in the application they are active in. I can use MIDI learn, so data from my trigger source reaches KM, and I can see data from the trigger source reaching the sequencer I use. But when I am using the sequencer, the data no longer appears to reach KM. Is it common to need an external patchy app or to use IAC to duplicate the MIDI from a remote so it will go to both places, or shouldn't KM see what's going to the sequencer also?

Hi, welcome to the forum.

When using a regular expression (regex), the ^ indicates the beginning of the string, and the $ the end. I am not actually sure right now why those values would be included in this context, but I trust that there will be a good reason for it! :smiley:

I think you are on the right lines with your thinking. I have just put together this little demo. The regex in the Search Text action matches a group of characters with spaces either side, so works to extract the byte that you want.

MIDI packet demo.kmmacros (2.4 KB)

Ah, you mean the text in the %TriggerValue%? Your guess is sensible and I'll experiment further to try to understand why that shouldn't work.

By "the sequencer" I presume that you mean some piece of software running on the same Mac. In the trigger section of the demo macro, if you click on "from: any device", you will see a list of MIDI that devices that KM knows about. You will need to make sure that there is a route from your sequencer's MIDI output to KM. This is not a limitation of Keyboard Maestro; no app will know about MIDI that is not routed to it. IAC may well be a suitable solution.

Edit: rereading your post, I think what you are saying is that incoming MIDI is seen by the macro except when the sequencer app is running. That suggests that incoming MIDI is being grabbed by the sequencer software before KM can access it. You could perhaps first see if there is a way for the sequencer to pass incoming MIDI through to IAC. Otherwise something like MIDIPipe might do the trick.

Have you made any progress, @justthere?

Meanwhile, I have looked into this:

The Wiki says that %TriggerValue% for a MIDI trigger gives a comma-separated list of: channel, note, velocity, device. However, this is of course only correct when a MIDI note is the trigger.

In the case of a MIDI packet being used as the trigger, the components of %TriggerValue% turn out to be:

%TriggerValue[1]% = the packet.
%TriggerValue[2]% = the device.

So that is why %TriggerValue[2]% did not work: by design, %TriggerValue[2]% contains the whole packet.

Thank you so much for this insight! That would explain why that technique didn't work. I am going to try a different approach and I will post the result. Your effort are very much appreciated!

2 Likes

My pleasure; I learned from looking into that!

Yes, please let us know how you get on.

1 Like

The method I use (based upon the assistance of another user I know) that works is:

I don't use a packet now - I have simply set KM to wait for a change in a specific control change message on a specific MIDI channel. Then:

Set Variable “MIDI_CC_Value” to Text “%TriggerValue[3]%”

Then I use that to trigger particular actions. I will return to the packet parsing later. Seems like interpreting the packet as text would be the easiest way to do this - but getting to that for me was a little oblique, which speaks to my level of understanding of KM more than anything else. The journey continues. And thank you again for your insight, which led me to think about it differently!

1 Like

See: MIDI trigger.

Specifically, something like:

  • Set Variable to Text “Data” to “%TriggerValue[1]%”
  • Display Text “%Variable%Data[2] %” <-- note the important space after the ] and before the closing %.