Articles

Joysticks!

It’s not the most attractive piece of gear on my desk, but in terms of cost, size, and getting a bunch of gestural control into Max, it’s hard to beat the humble game controller. It’s my go-to response when new users ask what their first gear purchase should be, despite a constant stream of new MIDI hardware with glowing buttons and glossy knobs. They are affordable, easy to toss into a bag, super easy to work with in Max, and provide 4 axes of gestural data at the tips of your thumbs.

When I started using Max in 2003, there wasn’t a big variety of readily available and user-friendly microcontroller boards like Arduino to get your hands on, but it was easy to find second-hand PC joysticks in the Thrift Town electronics section. Once I discovered how to modify the circuitry inside, and how to connect it to Max through the Max hi object, I was set for a few years of interactive media projects. For a guide on how to get started with that, check out my “Making Connections” tutorial.

While hacking an off-the-shelf controller has a certain romantic charm to it, you might want to build your own device from scratch. For this task, the Teensy series of microcontroller boards from PJRC (available from Adafruit) ship with a demo firmware that implements a basic joystick controller without much work. Just add your own components and connect 'em up to your Max patch using the hi object.

Once you’ve got a joystick connected to Max, there are a few tricks you’ll want to know about working with that data coming out of the hi object. You’ll want to use the the route object to parse out individual axes and buttons to different outlets. The buttons will give you a simple 0/1 output, and can be used anywhere a toggle might go in your patch. The analog sticks will give you 2-axes each of integer values within some range, depending on the bit resolution of your controller. The most obvious way to use the analog values will be to scale and map them directly to parameters using the scale, zmap, function, and table objects commonly employed for this purpose.

Another way to look at that analog data is to think of it as coordinates in a 2D space. This was the inspiration for the nodes object, which takes a pair of coordinates in the range of 0. - 1.0 and spits out weighted values based on proximity to each node. These weights can be used to set up spatial regions for sample triggering, mapped directly to parameters in your patch, or used to drive the interpolation of a pattrstorage object for parametric morphing. Check the nodes help patch for more ideas of how to use the object.

The best part of using a game controller with your Max patch is that it encourages you to have fun, play with your sounds, and experiment in ways that a ready-for-music controller might discourage. Have your own game controller patches to share? Let’s see them in the comments.

by Andrew Benson on June 22, 2016

Creative Commons License
larme's icon

I think [hi] object has a bug: if you use a bluetooth controller (like dualshock 4) and it disconnect from the computer. After reconnect the controller, there's no way to force the original [hi] object to re-recognize the controller. You need to either add a new [hi] object or close and reopen the entire patch.

Max Gardener's icon

Platform? Version of Max? You've already mentioned a specific device, so that's a help.

As usual, a little detail on the front end *really* assists engineers in tracing the problem more efficiently....

larme's icon

I'm on Mac OS 10.11.5. Max version is 7.2.3/32bit.

To reproduce the problem with dualshock 4:

1. pair dualshock 4 with mac
2. open the [hi] help patch, select ds4 (named as "wireless controller"), click (poll 10), max window will print ds4's outputs.
3. Long press the ps button on ds4 to shutdown it. Then press ps button again to turn it on. Make sure ds4 re-pairs with mac.
4. now in the same [hi] help patcher, click (menu) and select ds4 again, then click (poll 10). The [hi] won't output any message. In fact I need to restart max to make [hi] works again.

Source Audio's icon

Hi object allways behaved that way, You have to have hardware connected and ready when max starts up.
Disconnecting it while max is running will break the connection.
Sometimes reselecting device works, but I would not count on it.

Levy Lorenzo's icon

great blog post! i started using joysticks with max after my time at STEIM [ http://steim.org/ ]

here is an instrument - MODIFIED ATTACK - that i've built with a Logitech Attack 3 and a max patch:

newdendrite's icon

Andrew,

Thanks for the post on joysticks. I've found that the Teensy and Max are a good combination for managing joystick control of patches and software synths.

One issue has come up with joysticks similar to the one in your picture. Replacement parts for these kinds of controllers have deadband in the center of the potentiometer range. They work fine for large control motions originating from the center of the 2-D space, but not so fine for more nuanced motions. As the joystick travels across the center of the space, there is a region in which output remains constant. Artists who want a smoothly changing value across the entire x or y range are frustrated with this discontinuity.

I've been looking for a source for inexpensive joysticks that don't show this problem. Are you seeing this behavior in the one you have?

Thanks,
Michael