Tag Archive for 'totalcontrol'

Controlling a Mouse with a MIDI Controller

I’ve been doing a lot of editing of large documents recently and some of them require lots of scrolling in either horizontal or vertical directions. Scrolling vertically is pretty easy thanks to my Logitech MX Revolution, which has an inertial scroll wheel — quite possibly the best invention ever. But quickly scrolling horizontally is basically impossible because it just has a rocker.

I glanced over at my MIDI controller and thought that it would be pretty great if I could use it to emulate scrolling. The Numark TotalControl has two jog wheels that can spin freely in an inertial manner.

I then discovered PyMouse and PyGame’s MIDI module. Using these two libraries, I cooked up this example, which uses the left wheel to scroll vertically and the right wheel to scroll horizontally.

The script simply initializes and finds a suitable MIDI controller. Then, it connects to that controller and periodically polls to see if there have been any events. If so, it processes the event to see if it’s something to scroll with. I implemented an overly-simple “low pass filter” which doesn’t even take advantage of the fact that the TotalControl outputs a number that increases as you scroll faster on the jog wheels, but it works well enough. Future iterations will have more complicated algorithms. Theoretically, this script is cross-platform since the libraries it uses are.

At any rate when you run this script, you can use the jog wheels to scroll. You need to patch PyMouse though. The developer forgot to include support for horizontal scrolling, but this patch changes a whopping two lines to add it (in reality, all of that code needs to be redone because it isn’t very well designed, but I’m lazy).

I’m sure MIDI mappers have been made before, but I’d like to make one where you can just script the controller in Python. You would just register a bunch of hooks (functions based on controller and control number) with calls to whatever functions you want to design. A project for when I’m bored and without internet access, I guess.