Midi Trigger - Separate Increase/Decrease Trigger in 1 Macro

Hello, I currently am using a midi controller to execute macros and have multiple banks of knobs and faders to utilize. For each controller number, I currently have to make 2 separate macros that use "controller # increases" or "controller # decreases" as triggers depending on which direction the knob/fader moves. With multiple banks of 16 different controllers, it gets tedious and crowded having 2 macros for each one and clutters up the library. So i am wondering how to implement a separate actions for controller # increases and decreases within the same macro? Maybe this is a simple concept and I just am missing something, but I went through multiple forum posts and played with various variable, if/then, and switch/case setups for a while last night and I couldn't get it to work the way I want. I am trying to learn more about the program but could use some help here. Thanks so much for any help!

Write a simple macro that's triggered on both Controller Increase and Controller Decrease. In that macro, display the token %TriggerValue%.

I assume it will be different for each controller direction, and if it is, then that's the answer: Set both triggers on the same macro, then use a Case statement based on the %TriggerValue%.

-rob.

Hey Rob, thanks for the fast reply! I played around %TriggerValue[3]% with case statements and if/then yesterday, but the problem is that with midi, the trigger value can be is 0-127 depending on the position of the knob/fader, so it's not just one value for increase and one value for decrease. So I was trying to figure out if there was a way to compare the incoming trigger value with the previous value by creating a variable and then using variable+1 or variable-1 conditionals, but I couldn't figure out how to make that work.

Ah, I see (never having used a MIDI device, I didn't know how they worked). Assuming the macro triggers on a change from the MIDI device, multiple variables should work, but they'd have to be global variables, so they remained in place between uses.

Something like...

If (TriggerTrackerVar is empty)
   set TriggerTrackerVar to %TriggerValue%
   exit macro
endIf

Case
    %TriggerValue% > TriggerTrackerVar
        Do things when value increased
    %TriggerValue% < TriggerTrackerVar
       Do things when value decreased
endCase

The one thing I stumble with with the above is what happens the first time you run it—you've obviously turned the knob, as the macro has fired, but there won't be an existing value to compare it to. In the above, I just set the variable, then exit, but that doesn't seem right.

Is there something in %TriggerValue% that show you which direction you turned the knob? Or is it just a number?

-rob.

No worries, I appreciate you taking a look at it. %TriggerValue% is just a number basically. The [%TriggerValue%] token will hold channel,controller,value,device. So for my device "2,13,40,nanoKONTROL Studio CTRL" is an example of what i get when the knob is rotated and the third value (40) can be anything from 0-127 depending on how the knob is rotated. The other three values remain the same no matter which direction the knob is turned.

I think the macro structure I described above would work, except for the very first time you turn it, because then there's no value in the variable for it to compare it toㅤ …ㅤ I have no idea how that would work. But after you turn it once, there should be a value in the variable, so the next turn should be able to determine if it was increased or decreased.

-rob.


Ok this is what I have set up based off of what you wrote. Is this correct overall? And then what would I put in the Case condition under Calculation? Or is there a better way to implement the code structure you sent above? Sorry I am not super familiar with how to implement code into the macros

You don't need a calculation:

image

In the screenshot I took, you'd put whatever actions you wanted to happen when the value increased into that first block. Then click the "+" sign in the Case action and add another condition for when it's less than the variable.

And actually, you could put that whole Case section into the "Otherwise" of the If statement that initially sets the global variable—that way, if there's no value, it sets it and quits. Otherwise, it runs the Case statement.

-rob.


Yes this is working now! Thank you so much! I had to delete the variable after the actions, so that it resets each time, but now it is functioning the way I want. I really appreciate your help Rob! Saved me a lot more headaches today

Interesting ... if that's the case, try changing TriggerTrackerVar to local_TriggerTrackerVar, and then you could delete the delete—locals only exist during the macro's run.

But honestly, I'm surprised it works deleting the value, because that should mean that it simply exits every time on that first statement .... weird.

-rob.

Yea i was going to experiment with the local variables next, but then the delete variable worked so I didn't switch it. But interestingly again, I just tried switching everything to local variables and it isn't working now. No idea why though.

For anyone else that finds this, this is the final macro I came up with it. It combines what @griffman suggested with the solution suggested by @kvanh on this post MIDI Controller Input -- a Difficult Question for Keyboard Nerds - #7 by kvanh, so the macro ignores every few trigger events and doesn't get bogged down.
Midi Trigger Increase:Decrease.kmmacros (9.6 KB)