This forum is read-only. Please post new topics in our Q&A forum.

Relative Rotary Encoder to Keystrokes

General discussion about MIDI Translator

Moderators: florian, DvlsAdvct

Post Reply
User avatar
florian
Bome Software: Founder
Posts: 2435
Joined: Thu Apr 28, 2005 10:09 pm
Location: Munich, Germany
Contact:

Relative Rotary Encoder to Keystrokes

Post by florian » Mon Jan 30, 2012 5:30 am

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.

User avatar
florian
Bome Software: Founder
Posts: 2435
Joined: Thu Apr 28, 2005 10:09 pm
Location: Munich, Germany
Contact:

Re: Relative Rotary Encoder to Keystrokes

Post by florian » Mon Jan 30, 2012 5:36 am

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

User avatar
florian
Bome Software: Founder
Posts: 2435
Joined: Thu Apr 28, 2005 10:09 pm
Location: Munich, Germany
Contact:

Re: Relative Rotary Encoder to Keystrokes

Post by florian » Mon Jan 30, 2012 5:41 am

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

Post Reply