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 MIDI objects in Max may be useful before reading these tutorials.
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.
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 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 to any power yields , which leaves our main frequency untouched). A depth of scales the cycle~ object to the range of to , scaling the main frequency up and down by an octave.
Thevalue 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 as the bend amount raises to the power of , yielding a multiplier of for the frequency. An octave bend of yields a multiple of ; a bend of yields a multiple of .
Scaling MIDI for signal control
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 range ( to ) maps to a floating-point value between and
When working with MIDI messages, the general rule of thumb is that they transmit integers which are typically in the range of *~ object. The scale object is an important utility object in Max for performing these calculations.to . 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 and to control the output of a
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 higher, atHz.
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.
- Octave Pitch Bend. The controller outputs values from to
- Vibrato Rate. The controller outputs values from to , inverting the scaling so that it runs from high to low.
- Vibrato Depth. The controller scales its input to run from to
- Modulation Index. The MIDI gets scaled from to
- Amplitude. The MIDI goes from to with an exponential scaling factor of . 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.
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 values to an output range|
|mtof||Convert a MIDI note number to frequency|