Using a MIDI mixing board to tweak your game in real-time

So you’re writing special effects code for your game.  You just need a small explosion here and there, and it’s a small project so little things like this are hardcoded.  You type in a velocity multiplier for the particles, compile, run your game, click through the title screen, start playing and blow up an enemy, only to find that the velocity you hardcoded was a little off, and to test a new value, you need to recompile and run again.  Sure, you could set things up to load from a file, or add a slider to the UI (you have UI widgets already, right??), or lament that you’re not using Unity, but all those things are kind of a pain if the framework isn’t already there for it.  At the very least, you have to go click on a tiny slider on the screen or type in numbers on the keyboard, and neither of those are very fun .

Sometimes in this situation, I resort to using the throttle on a flightstick to let me dial in a value at runtime.  It’s pretty rad to be able to tweak something with a hardware dial.  It’s a more intimate interaction than a button or an analog stick.  So firm and precise and….well, anyway, that’s all well and good, except you only get one input, and chances are your game was designed to use a more standard gamepad and the flightstick is confusing your input.

Enter the MIDI mixer!  I learned about the KORG NanoKontrol2 while sharing a hotel room with Kozilek for Fantastic Arcade in ‘013.  He was practicing his mix on it, obviously, but I saw all the sliders and dials and thought of how many things I could control at once!

2014-09-21 23.03.02

But how to convert MIDI to something you can easily get to in your C++ app?  Some googling led me to ControllerMate, a very cool Mac-only app that basically lets you redirect and reconfubilate all your computer’s inputs.  With the free version, I set up to MIDI channels to go to a virtual gamepad’s analog channels, and intercept that in my gamepad code, along with some of the buttons.  After I forked over $25 (a steal, IMO) for the full version, I could do all 16 analog channels and all 30+ buttons.

But it was kind of a pain to keep everything working quite right, and I can’t very well write a blog entry about this awesome thing that they can do with the MIDI hardware they probably don’t have lying around if it also required them to spend $25 on the accompanying software.

So I wrote my own.

Starting with the most basic example from PortMidi,  I combined it with my gamepad-based Midi code and encapsulated it into its own sort of thing.  This is a very easy-to-follow example that shows you how to get the latest values from the mixer board with a minimal footprint in your code.   It’s tested on Mac and Windows, and should, in theory, work on Linux.  It’s C++-based, so if you can integrate that with the language you’re using, you should be good to go.  And it’s up on GitHub.

Download it here.

You’ll also need GLUT if you don’t have it.

Let me know if you find it useful!


One thought on “Using a MIDI mixing board to tweak your game in real-time”

Leave a Reply

Your email address will not be published. Required fields are marked *