Click here to open the tutorial patch: 01iMappingMIDItoMSP.maxpat
In this group of tutorials, we'll look at different strategies for integrating MIDI control into MSP patchers. Commercial hardware synthesizers and samplers typically implement MIDI in some form or another in fairly standardized ways; software systems that mimic these devices (such as Max patches) can use all the same routing and mapping systems to successfully control our sound-producing systems with MIDI controllers.
A review of the tutorials that cover <link type="tutorial" module="max" name="midichapter01">MIDI objects</link> in Max may be useful before reading these tutorials.
have a correctly configured MIDI controller connected to your computer. The tutorials in this section use a variety of MIDI messages as example input; if your controller lacks any of these features, you can simulate their input with user interface objects in the tutorial.
The MIDI standard was developed to enable the control of electronic music devices through the use of a simple serial communications standard that would be easy to implement on any platform and could be used by anyone. As music performance equipment has evolved in the 25 years since, MIDI has remained a standard-issue interface protocol for nearly all music-making equipment, whether we're talking about hardware or software. Whether you're interested in routing a keyboard, slider box, or software sequencer in Max, you need to deal with translating MIDI messages into numbers that make sense for MSP.
simpleFM~ controlled by a number of signal objects, the
values of which are set by floating-point number boxes. Turn on the
audio in the patcher by clicking on the ezdac~ object and turn
up the gain~ slider. Familiarize yourself with the
way the audio portion of the patcher works by trying different values is in
the number boxes labeled
Our patcher uses frequency modulation synthesis as we looked at earlier in the
tutorials, with the addition of a circuit that provides vibrato to the
main frequency of the synthesizer. The cycle~ object labeled
is scaled by the
Vibrato depth control to oscillate the main frequency (the
output of the line~ object on the right of the patcher. Unlike a vibrato circuit
which adds the output of a modulating oscillator to a constant frequency, this
patcher logic multiplies the constant frequency by the output of the oscillator
treated as an exponent by the pow~ object. A vibrato depth of
therefore, has the equivalent of turning off the vibrato (raising
any power yields
1, which leaves our main frequency untouched). A depth
2 scales the cycle~ object to the range of
scaling the main frequency up and down by an octave.
Octave bend value on the left allows us to use a value as a
frequency multiplier in a range where each unit of value transposes the
pitch by an octave. Like the vibrato circuit, it uses an exponential
scaling logic; a value of
0. as the bend amount raises
the power of
0., yielding a multiplier of
1. for the frequency.
An octave bend of
1. yields a multiple of
2.; a bend of
yields a multiple of
it sends CC#1 on any MIDI channel (the modulation wheel on a keyboard
controller is a good candidate for this mapping). From the umenu object
A, select option
1 ('Octave Pitch Bend'). Move your
controller and listen to and watch the result.
The Max ctlin object transmits our controller through the slider object
in the patcher and from there through a scale object. The gate object
allows us to route the controller to different destination number boxes
in the patcher. Notice that, with the default scaling, our MIDI number
127) maps to a floating-point value between
When working with MIDI messages, the general rule of thumb is that they
transmit integers which are typically in the range of
While these values make sense within the MIDI domain, when applied to signal
values these ranges are usually wrong. When we want to control an oscillator,
we need to think in terms of frequency (cycles per second or Hz), not
the pitch that MIDI note numbers refer to. When thinking about amplitude,
we might want these numbers scaled between
1. to control the output
of a *~ object. The scale object is an important utility object in Max
for performing these calculations.
The values for the scale object should change so that the
xmax values read
values should read
2. Move the MIDI controller and notice the
Using the settings controlled by this preset, we can take a MIDI controller
and use it to give us an octave bend range of two octaves. Setting the
controller to its lowest value will leave our FM synthesizer untransposed.
Moving it all the way up will cause the frequency to output two octaves
yminand enter the value of
Move your MIDI controller and notice the difference.
The scale object can map any range to any other range, including negative values. Now our controller leaves the synthesizer untransposed in the middle of its range; moving it downwards and upwards gives us two octaves of shift in either direction.
contains a different mapping and routing:
1 - Octave Pitch Bend. The controller outputs values from
2 - Vibrato Rate. The controller outputs values from
the scaling so that it runs from high to low.
3 - Vibrato Depth. The controller scales its input to run from
4 - Modulation Index. The MIDI gets scaled from
5 - Amplitude. The MIDI goes from
1. with an exponential scaling factor of
1.06. Using this value means that upper values of the MIDI range control a wider part of the mapping than lower values.
Notice that different MSP parameters in our patch require different scalings, none of which directly correspond to the default values of MIDI controllers.
B, look at the number boxes below the
notein object. Play some notes on a MIDI keyboard connected to your computer.
When dealing with pitch in MIDI values, a utility Max object called mtof allows us to convert directly to frequency. The stripnote object in this patch is necessary to prevent double-triggering of values due to the note-off events generated by the keyboard. Notice that because our MSP synth in this patch is monophonic, only one note can be sounded at a time.
Working with MIDI controllers within the Max environment is extremely simple. Using these values with MSP patches requires an understanding of how to map the MIDI values appropriately for the different parameters of a digital signal network. The Max scale and mtof objects are incredibly useful for performing this function, and allow you to map MIDI input into appropriate ranges for any number of applications.
scale - Map an input range of values to an output range
mtof - Convert a MIDI note number to frequency