Control Mouse with MIDI Touchpad/Trackpad/Kaospad

florian

2012-11-06 23:10:11

Hi, here I'll outline how you can control the mouse with a MIDI touchpad.

In the example, I use the Korg NanoPad. It sends Controller #1 for up/down: value 0 at bottom and value 127 at top. For the horizontal (left/right) direction, it uses pitch bend.

Code: Select all

Translator 0: Down
Options: stop=false
Incoming: MIDI B0 01 pp
Rules: 
  gd=gy-pp
  gy=pp
  if gd<0 then exit rules, skip Outgoing Action
Outgoing: Mouse move  10 (down)

Translator 1: Up
Options: stop=false
Incoming: MIDI B0 01 pp
Rules: 
  if gd>=0 then exit rules, skip Outgoing Action
Outgoing: Mouse move  -10 (up)

Translator 2: Right
Options: stop=false
Incoming: MIDI E0 pp qq
Rules: 
  hd=pp-hy
  hy=pp
  if hd<0 then exit rules, skip Outgoing Action
Outgoing: Mouse move 10 (right) 

Translator 3: Left
Options: stop=false
Incoming: MIDI E0 pp qq
Rules: 
  if hd>=0 then exit rules, skip Outgoing Action
Outgoing: Mouse move -10 (left) 
For each message from the pad, I calculate the difference of the new value minus the last value.
For up/down movement (CC#1), if the difference is positive, the mouse pointer is moved down a bit (Translator 0). Otherwise, in Translator 1, the mouse pointer is moved up a bit. Note that you do not need to recalculate the difference there, because the global variable gd remembers the current difference.
For left/right movement, the logic is the same. Since it is a pitch bend message, correct would be to calculate the full value. However, the NanoPad does not send a fine grained pitch bend anyway, so only the high byte is used for calculating the difference.

Global variables:
gd: current difference of position in up/down direction
gy: last position in up/down direction
hd: current difference of position in left/right direction
hy: last position in left/right direction

Hope this helps!
Florian