The Livid Code is designed to be useable out of the box without programming. The default behavior of the Code’s 32 encoders is to send values in the range of 0 to 127 as MIDI continuous controller (CC) messages. These messages can be easily assigned to software synthesizers to control parameters, providing a physical knob to any virtual instrument that supports controller mapping. The firmware of the Code produces an indication of the value on the LED ring that encircles each encoder.
1 – initialize the code
The first thing we need to do is set the Code to a known state. The best way to do that is to reset it to its factory default settings. All communication with the Code is accomplished via MIDI messages. The knobs and buttons on the Code send MIDI continuous controller or note messages. Messages that change change the behavior of the Code need to be a bit more flexible, so this is accomplished with system exclusive messages. The admittedly awesome Livid Code wiki details all the messages the Code responds to. Included in this tutorial are examples of these messages, formatted as working Max patches that you can easily adapt to your own use.
Even though the Code uses MIDI to communicate, you don’t need to hook up the MIDI ports on the unit itself. All you need to connect is a single USB cable which both provides power and transports the data. No drivers are required to install.
The first patch example establishes the MIDI port on which the Code communicates. Click on the sysex string to reset the code. The ctlin object instantly responds to the values sent from the Code’s encoders.
2 – decouple the LED rings
Now that the Code is in a known state, let’s decouple the LED rings from the encoders. Currently, the internal firmware of the Code is controlling the LEDs, but we want to do this from Max. This is like turning local control off on a MIDI synthesizer, which decouples the sound engine from the keyboard, so the routing can be controlled with a computer.
Click on the sysex message in patch example 2 to tell the Code you want to change its behavior. Don’t worry, you can always revert to the factory defaults with one click. Once you’ve done that, you’ll notice the LEDs do not respond when you turn an encoder. This is what we want. Values are still sent out from the encoders, but if the LEDs are going to do anything, we’re going to have to explicitly tell them to do so from Max.
3 – delta mode
128 steps of resolution is suitable for a lot of tasks, but with rotary encoders, we have the ability to precisely tailor the value range. We want the encoders to tell us when they are incremented or decremented. Another sysex message puts the Code into ‘delta mode’ Now the Code sends a ’1′ on increment and a ’127′ on decrement. This may seem like a step backwards, but now the encoders are unbounded. In other words, they don’t stop sending values when they reach 0 or 127. We can keep them unbounded or set the bounds ourselves to whatever we want.
We’ve built our own accumulator using the accum object to keep track of the increments and decrements as a running value. This produces an unbounded number that is edited with the first encoder on the Code.