Absolute > Relative CCs?

muckleby

2011-10-12 17:20:50

I have an NI Kore 2 controller, with endless encoders that transmit absolute CCs.
And what I'd like to do is use MT to trigger a Left keypress every time an encoder is turned to the left and trigger a Right keypress every time the encoder is turned to the right.
So essentially the encoder will be acting as though it was in relative mode and triggering keypresses.
Is this possible?

florian

2011-10-22 17:22:17

yes, that is no problem. By comparing the last value, you can derive if it was turned left or right:

Code: Select all

Translator 0: turn left
Options: stop=false
Incoming: MIDI B0 0E pp 
Rules: 
  gd=pp-ga
  ga=pp
  if gd>=0 then exit rules, skip Outgoing Action
Outgoing: Keystroke: 0 

Translator 1: turn right
Options: stop=false
Incoming: MIDI B0 0E pp 
Rules: 
  if gd<=0 then exit rules, skip Outgoing Action
Outgoing: Keystroke: 1 
Upon turning the knob (here: controller 0E hex), the variable pp receives the current controller value. In ga, I store the last value of the controller. By taking the difference (and set gd to it), I know that: if gd < 0, I turned left (counter clockwise), and if gd > 0, I turned right. I also update ga with the current value.

Now whenever you turn right, gd will be positive. The IF statement in "Translator 0" will evaluate to TRUE, and therefore that translator's outgoing action is not executed. However, the second Translator's IF statement is false, and so that outgoing action is executed: keystroke 1. It works the other way round for turning left.

Thanks,
Florian

PS: one problem with this approach is that turning fast will likely skip controller values and therefore you'll miss keystrokes. This can be solved with MT, too. The example project for Frontier Design's Tranzport (shipping with MT) shows such an approach with timers in the Winamp preset.

muckleby

2011-11-11 01:03:26

niceone florian, thanks for such a helpful reply.

nice little bit of code that :)

the skipping values is not so bad, a bigger issue is the fact that once the min/max CC is reached, the rule no longer works and the the action isn't triggered. i can't think of a way around it either.

so the result isn't quite an endless encoder, but might be close enough for my use anyway.

so thanks again, i'll have a play with the demo some more and see how it works out....

florian

2011-11-17 12:13:13

when you're at max CC value and keep on turning, does it still send repeated MIDI messages with the max value? Then we can tweak the translators to keep on sending keystrokes.
Florian

Big_T

2011-12-01 02:54:27

florian wrote:when you're at max CC value and keep on turning, does it still send repeated MIDI messages with the max value? Then we can tweak the translators to keep on sending keystrokes.
Florian
Thank you for the useful code!

This is the case for me (still keeps sending the max or min values: MIDI B0 11 00, oo=0x00 or MIDI B0 11 7F, oo=0x7F ). I have continuous rotary knobs but the keystrokes stop once maxed or mined out.

You mentioned tweaking the translators to keep on sending keystrokes. Can you elaborate on how to do that? How can we keep the good times rolling?

Many thanks!

T

florian

2011-12-01 13:51:10

i guess it's as simple as adding one more IF statement:

Code: Select all

   Translator 0: turn left
   Options: stop=false
   Incoming: MIDI B0 0E pp
    Rules:
      gd=pp-ga
      ga=pp
      if pp==0 then exit rules, execute Outgoing Action
      if gd>=0 then exit rules, skip Outgoing Action
    Outgoing: Keystroke: 0

    Translator 1: turn right
    Options: stop=false
    Incoming: MIDI B0 0E pp
    Rules:
      if pp==127 then exit rules, execute Outgoing Action
      if gd<=0 then exit rules, skip Outgoing Action
    Outgoing: Keystroke: 1
[updated Dec.6, 2011]

Big_T

2011-12-04 21:33:25

Hi Florian,

Thanks for your help. I tried the new line but nothing different happened? I can still only output 127 1's or 0's in a given sweep. It stalls at the max or min cc message but in the monitor it is still trying to send out.

I'm not very good a coding but form your additional code : "if pp=0 then exit rules, execute Outgoing Action" I think I see what you mean where you are saying to keep going but in practice it doesn't seem to work?

From the log:

on the left side it says pp=0x00
on the right side it says pp=0x7f



T

florian

2011-12-04 22:59:17

hmm, don't know what's hapening. Can you post your full translator here (use copy in Midi Translator, and paste here in the forum)? Also copy/paste some lines from the log.
Thanks,
Florian

Big_T

2011-12-05 04:52:48

Hmm I can't seem to copy and paste the code? I used copy form MT and past in here.



I see an error code: Error: executing Preset|Copy: (ExceptionInInitializerError)

When I copy the translators it copied and pastes like this:

translator 0:

[Ljava.lang.String;@fc9e7e


translator 1:

[Ljava.lang.String;@15fc606


I'm using a mac.


I did manage to save it as a text file though:

--------------- Preset try keystroke


[x] Translator 0: New Translator
Incoming: CC ch.1: Data Entry -1 (#97), pp
Rules:
gd=pp-ga
ga=pp
if gd>=0 then exit rules, skip Outgoing Action
Outgoing: Keystroke: 0

[x] Translator 1: New Translator
Incoming: CC ch.1: Data Entry -1 (#97), pp, on ports BCR2000 : Port 1 (BEHRINGER), BCR2000 : Port 2 (BEHRINGER)
Rules:
if gd<=0 then exit rules, skip Outgoing Action
pp=0
pp=0
Outgoing: Keystroke: 1





Here is some log window lines:

4081: IN 4.1 MIDI B0 61 7C, pp=0x7C
4082: OUT 4.1 1 : keystroke suppressed (main window active)
4083: IN 4.0 MIDI B0 61 7D, pp=0x7D
4084: IN 4.1 MIDI B0 61 7D, pp=0x7D
4085: OUT 4.1 1 : keystroke suppressed (main window active)
4086: IN 4.0 MIDI B0 61 7E, pp=0x7E
4087: IN 4.1 MIDI B0 61 7E, pp=0x7E
4088: OUT 4.1 1 : keystroke suppressed (main window active)
4089: IN 4.0 MIDI B0 61 7F, pp=0x7F
4090: IN 4.1 MIDI B0 61 7F, pp=0x7F
4091: OUT 4.1 1 : keystroke suppressed (main window active)
4092: IN 4.0 MIDI B0 61 7F, pp=0x7F
4093: IN 4.1 MIDI B0 61 7F, pp=0x7F
4094: IN 4.0 MIDI B0 61 7F, pp=0x7F
4095: IN 4.1 MIDI B0 61 7F, pp=0x7F
4096: IN 4.0 MIDI B0 61 7F, pp=0x7F
4097: IN 4.1 MIDI B0 61 7F, pp=0x7F
4098: IN 4.0 MIDI B0 61 7F, pp=0x7F
4099: IN 4.1 MIDI B0 61 7F, pp=0x7F
4100: IN 4.0 MIDI B0 61 7F, pp=0x7F
4101: IN 4.1 MIDI B0 61 7F, pp=0x7F
4102: IN 4.0 MIDI B0 61 7F, pp=0x7F
4103: IN 4.1 MIDI B0 61 7F, pp=0x7F
4104: IN 4.0 MIDI B0 61 7E, pp=0x7E
4105: IN 4.1 MIDI B0 61 7E, pp=0x7E
4106: OUT 4.0 0 : keystroke suppressed (main window active)

florian

2011-12-05 09:00:09

Hi,

thanks, the copy/paste thing is a bug! will be fixed in the next version.

In your preset, I don't see the additional "IF" lines in the rules!

Regards,
Florian

jaynyc

2011-12-05 23:36:10

i am trying this also... i add that 2nd rule (the new one), but ultimately it seems that only 1 rule stays.
if pp=127... it says "Erronous rule: condition expected"

so i have translator 0 with 4 rules, and translator 1 with 1 rule.

Big_T

2011-12-06 02:51:41

Hi Florian,

It seems I'm in the same situation as Jay above. When I add the code to the rules the second "if" statement does not seem to stick.
I have tried adding it as a whole copy and paste from your code, and also adding it after by hand. After I click away then back on the translator the code I just added seems to have disappeared and I get: pp=0 in it's place

I get the following statement in the rules section:


Translator (0)

gd=pp-ga
ga=pp
if gd>=0 then exit rules, skip Outgoing Action
pp=0


Translator (1)

if gd<=0 then exit rules, skip Outgoing Action
pp=0


Also when I add the additional "if" statement it says "line 4 parse error: condition expected" in red



T

florian

2011-12-06 11:27:29

sorry guys, I should've tried it myself! I used a single = for comparison, but it should be a double == for comparison:

Code: Select all

if pp==0 then exit rules, execute Outgoing Action
I've fixed it in the preset above, you should now be able to copy paste the rules.

Best,
Florian

Big_T

2011-12-07 08:54:19

Thanks Florian! It works perfectly now :)

I would have never figured that out by myself.


T

muckleby

2011-12-22 18:21:54

Glad this helped someone!
My controller stops sending at max value :(
However it does have a strange Mackie emulation mode where left turns send values from 41 to 4F and right turns send 01 to 0F.
Could I use a rule to send keystroked based on these value ranges?

florian

2012-01-30 05:42:35

Hi muckleby,

I've created an own topic for this:
http://www.bome.com/forums/viewtopic.php?f=3&t=3755

Regards,
Florian

NiDBiLD

2016-03-13 22:07:43

I know this is an old topic. But I just figured out a way to do this with only one translator and no global variables:

Code: Select all

[x] Translator 2.12: Knob 1 to relative
Options: swallow
Incoming: Control Change on channel 2 with CC#:30 (0x1E) set 'pp' to value
Rules:
  if pp>=65 then Goto "Right"
  if pp<=63 then Goto "Left"
  
  Label "Left"
  oo=29
  Goto "Exit"
  
  
  Label "Right"
  oo=30
  Goto "Exit"
  
  Label "Exit"
  pp=64
Outgoing: MIDI B2 oo 7f B1 1E pp
oo is the cc number (or note) you want the output when turning left or right. pp is the knob value. Only drawback is you have to send the knob message as outgoing as well, to reset the calculation for every message.

Might be of use to someone.

florian

2016-05-03 22:43:35

NiDBiLD, thanks for posting!