Recently I’ve been trying my hand at music production (again), and to this end I purchased a few gadgets, including the AKAI LPD8. This is a simple, cheap MIDI controller with a few knobs and pads (buttons). I was wondering if I could use it as an everyday audio controller? Starting and stopping music, adjusting system volume, etc. I know some keyboards have this functionality, so it should definitely be possible.

tl;dr: source on GitHub

AKAI LPD8

I started looking around, and I found a few tools that can do this. First, there’s Bome’s MIDI Translator Classic. This is a tool that intercepts events coming from a MIDI device, and emits keystrokes. Windows has support for media keys – play/pause, stop, forward, backward – so the idea was to simulate these. Unfortunately, I don’t have media keys. I got around this by launching AutoHotkey, setting up some key combos, and using that in MIDI Translator’s interface. Sounds complicated, huh? It was, and I had to find my way around incorrectly displayed symbols and weird parantheses to get this right (I mean, you can’t just type in the letter for media keys, right?). It also displayed a nag screen at startup. I could work with this, but it was a bit annoying.

So I found Power Mixer. This is a full-featured audio mixer replacement for Windows, and has support for MIDI input (and output, too). It is a very comprehensive app. I could assign a knob to control the volume of an indvidual app (Spotify, for example). I couldn’t get the buttons to work, though. That’s understandable – this is a mixer, designed to control volume. However, it is able to run programs on button presses.

How hard would it be to write a program that broadcasts a single keystroke? Is the overhead of executing a program too much?

So I did exactly that. It’s 167 lines, and is basically copy+paste. It calls a function found in user32.dll, and 75% of that code is interop (defining structs and constants to make it resemble the non-managed counterparts). I had concerns about the performance, but there isn’t any (the resulting .exe is 16kb). So that’s a success!

…but wait. If I can do that, can I just… write my own MIDI controller?

Well, yes. I did that too, and I’d be delighted to share some useful insights, but, alas, this turned out to be another excercise in copy+pasting.

First of all, to connect to the device, there’s Dry Wet MIDI. It is awesome, it works like expected – you connect to the device, you get an event when something happens. 10/10, far better than what I anticipated.

Sending media keys is already solved from the previous project.

Setting the system volume? That’s a bit complicated to understand, but once you find this post by EskeRahn, the problem is basically solved. It calls specific COM objects, referenced by their GUID, to control the volume of the default device. That’s good enough for me; for app-specific controls and manipulating different interfaces (I have 8 different output devices, don’t ask), the code would get considerably more complex.

I also wanted the program to run at startup. This is done by writing a registry key as described in this StackOverflow answer.

If you need any of these, check out the source on GitHub!


So, what’s the takeaway?

The finished stuff

Well, I’m super happy how it turned out, and it was way easier to do than I first thought. Maybe I should do this more often? I’m a programmer after all, and I… never do this. I look for the “perfect tool” to do the job, even simple jobs, even when I could roll my own solution.

An interesting thing to note is that I can create a highly-specific tool for myself, which means it is generally more efficient, and I can even be a bit lazier with things like error handling and managing settings – there are only so many things that consistently happen on my machine, I don’t have to worry about exotic setups, user privileges, and so on. If it crashes, I only have myself to blame, and I just restart it – no need to investigate, as I know for sure that there’s no malicious code in there.

But anyways, I’ve been using it for 1.5 month now without a single crash, and the warm fuzzy feeling of that is the best part. Try it!