Adding analog inputs to your graphics app
When prototyping graphics applications it doesn’t take long until you want to control some parameters during runtime. Using the keyboard is often the first candidate as getting keystrokes is very easy for most toolkits used in graphics like GLFW or GLUT.
But it doesn’t take long until the number of keys it so large that it becomes confusing. There is also no direct feedback of the currently set values (and a lot of printf doesn’t scale so good as well). So the next step is adding a simple UI. Some use QT for this as it’s a nice GUI toolkit and works cross platform (so did I for many projects). QT is great when your prototype turns into a full application (unless you are building a game) but may require too much glue code for simple prototypes.
More limited but also much simpler to include into existing projects and very simple to set up for simple tasks is AntTweakBar. After writing a couple of lines of glue code, exposing one more variable for testing is a matter of one line of code!
In case you want some haptic feedback or adding a UI is not an option (maybe you don’t want to occlude anything from your game and need the keyboard and mouse for the game control), adding a MIDI device might be an option. rtMidi is a small cross platform library that helps getting the MIDI commands from your device. A simple MIDI controller with nine analog sliders and knobs will set you back 50€. Each control will give you a 7bit value of the current position.
One downside of this setup is the fact that the device only sends the values of the controls when they change, this means that the initial state when starting your app is not reported. So you might want to reset all physical sliders or move each one slightly after your application started to send the current control value to your app.
The video below shows how a small MIDI board is used to adjust the lighting parameters of our beloved Stanford bunny: