Page 1 of 1

Relative Rotary Encoder to Keystrokes

Posted: Mon Jan 30, 2012 5:30 am
by florian
Hi, a user wants to convert his rotary encoder (in "Mackie" mode) to keystrokes.
The encoder outputs controller values 0x41...0x4F for rotation clockwise (the faster, the higher the value).
And it outputs values 0x01...0x0F for counterclockwise rotation.

Re: Relative Rotary Encoder to Keystrokes

Posted: Mon Jan 30, 2012 5:36 am
by florian
The simple, "naive" solution is to just output a keystroke for every message that comes in.

Assumptions:
- the encoder sends on CC 01
- we want to press key "up" for clockwise rotation, and "down" for counterclockwise rotation

Code: Select all

Translator 0: clockwise
Options: stop=false
Incoming: MIDI B0 01 pp
Rules: 
  if pp<65 then exit rules, skip Outgoing Action
Outgoing: Keystroke: Down 

Translator 1: counter-clockwise
Options: stop=false
Incoming: MIDI B0 01 pp
Rules: 
  if pp>15 then exit rules, skip Outgoing Action
Outgoing: Keystroke: Up 
Both translators will trigger on the encoder controller. But the first translator will not do anything if the controller value pp is lower than 65 (which is hexadecimal 0x41). The second translator will not be executed if its value pp is more than 15, i.e. 0x0F.

This will work in many cases, but the acceleration feature of the encoder will be completely ignored. Turning it fast will result in slow keypresses.

That's where the next post comes in.
Florian

Re: Relative Rotary Encoder to Keystrokes

Posted: Mon Jan 30, 2012 5:41 am
by florian
So this solution will take acceleration into account:

Code: Select all

Translator 0: clockwise encoder
Options: stop=false
Incoming: MIDI B0 01 pp
Rules: 
  if pp<65 then exit rules, skip Outgoing Action
  pp=pp-64
Outgoing: Timer pp times "Key Down": 2 ms (initial delay: 0 ms)

Translator 1: counter-clockwise encoder
Options: stop=false
Incoming: MIDI B0 01 pp
Rules: 
  if pp>15 then exit rules, skip Outgoing Action
Outgoing: Timer pp times "Key Up": 2 ms (initial delay: 0 ms)

Translator 2: clockwise keystroke
Options: stop=false
Incoming: On timer "Key Down"
Outgoing: Keystroke: Down 

Translator 3: counter-clockwise keystroke
Options: stop=false
Incoming: On timer "Key Up"
Outgoing: Keystroke: Up 
Instead of generating the keystroke directly from the incoming MIDI message, a timer is started. The trick is that the timer will be fired as many times as the encoder specified for the speed. So a fast rotation will result in multiple timer triggers. Upon timer expiration, the keystroke will be pressed in the third and fourth translator -- as many times as the acceleration was.

Hope this helps!
Florian