Can i define global functions to call in individual translator rules?

Forgive me if i've somehow missed this, i've tried searching.

So i'm working on a preset that involves using modifier keys to send different messages. I use a message from a button press to set a global variable to 127 when held, and 0 when released, and then use rules to get the outputs i want when holding that button and pressing a second button. To avoid the message that would be sent when the second button is pressed without the modifier button held, i use a rule like "if m0==127 then exit and skip" for instance. But i have to use that rule on every translator that is for a button that i assign a secondary function to. OK, so now i'm adding another modifier key to set global variable m1, and i have to add another rule, "if m1==127 then exit and skip" but damn, i have to add it to every translator.

 

is there a way to define a function to call so i can just add that rule to it once instead of to every translator?

Hi,

There is no concept of "functions" in MT Pro however here are a few suggestions that might help.

1) Use presets to enable/disable  entire preset sections for the outgoing action you want (instead of a global variable). You could actually use the global variable to turn on/off different presets instead of evaluating the value of m0 in every translator.  if m0==1 turn on only preset 1,  if m0==2 turn on only preset 2 etc. Then the individual translators would not need to look at the value off m0. Only the translators in the enabled preset would be active. Or you could simply enable a given preset when the shift key option you want is pressed. 

IE note on note 1 value 127 - Enable prekey in preset 1. Note off note 2 value 0 - Disable preset 2.Then all of your output options for preset 1 would be used.

Note on note 1 value 127 - Enable preset 2. Note off note 2 value 0 - Disable preset 2. Then all of your output options for preset 2 would be used.

For non-shift you would have a translator to turn on preset "no shift" on release of either note 1 or note 2. You would also need to disable  "no shift" preset in translators above while enabling other ones. No global variables required for this option.

 

2) Bitmap the global variable and and use if m0!=0 instead of if m0==127 then skip.  This still requires initial rework but may be more flexible in the future.  So you can have different values of m0 and skip all translators if it is not 0 and only select the output if it the value you want (ie shift1 = value 1, shift 2 = value 2 etc).

Of course on the translators you want to execute only if the correct shift value, you would still need to evaluate the value to trigger the outgoing action. 

 

3) There may be a way to do it with timers. For gesture management I have a geneneral "dispatch" timer. with a series of translators that monitors for input of timer "dispatch". The output is a different timer depending on the the function I want to perform. It still uses global variables but allows me to  put the logic in a more centrally located area (the translator for the specific function I want).   

 

None of these methods are perfect but I've been able to achieve quite a bit of more functionality using these techniques.

Without looking at your code, I think I would probably recommend option 1 as the first plan of attack. 

I hope this helps!

 

Steve Caldwell
Bome Q and A Moderator and
Independent Bome Consultant/Specialist
bome@sniz.biz

 

Ahhhhh, yes, i like option 1.  thank you!

i've also already repurposed your dispatch code for double tap and hold detection. It's great, thank you for that too.  I'm really enjoying this software!

I've experimented with emulating functions using timers but with limited success. Here is what I tried. So far it seems to be a bit more trouble than it is worth to me but maybe it will be closer to what you want.

Use a timer for a function call.

1) Set the return value to default of 0  as a global variable in the calling translator

2) Calling translator set global variables used for the function call

3) Output of calling translator is a one-shot timer with the function name as the timer trigger.

4) Have function timer call a "function-name-timer-done" timer at the end for completion.

5) Function-name-done timer triggers a separate translator used by the caller for the evaluation of the return value and then proceeds from there.

 

Of course, since all of this uses global variables, you need to be careful in use and timing as there is no local "scope".

 

Steve Caldwell
Bome Q and A Moderator and
Independent Bome Consultant/Specialist
bome@sniz.biz

Good to know it helped!

I believe that the dispatch oneshot timer would only work in all cases by implementing this: https://www.bome.com/support/kb/can-timer-zero-events-be-injected-before-any-already-buffered-messages