Mapping one range of values to another needed range of values is a crucial technique in computer music. In this example, we want to map MIDI data values that range from 0 to 127 into a useful range for controlling the amplitude—and thus the loudness—of a sound in MSP.
This is an example of a patch loaded in a poly~ which uses midi values to load and transpose samples of guitar strings in a groove~. This patch is used as an abstraction inside of the Sampling Synthesizer in Max patch which includes pitch bend and mod wheel functionality and contains the buffer~ objects that the groove~ in this patch refers to.
Above are examples of four types of non-linear contours of values from 0 to 127 that one could use as continuous controller information for a MIDI device.
To generate a series of numbers in Max that outline a sinusoidal shape, you can use the sin() function in the expr object. As the argument in the sin() function goes from 0 to 2π (6.283185), the output will be the sine of that value, going from 0 up to 1, down to -1, and back up to 0. So, by feeding a series of numbers into expr, you can generate numbers that follow that sinusoidal pattern.
This example shows how to create a “theremin” where the mouse position controls pitch and amplitude of a cycle~ with the x and y position respectively.
Once you get to a large number of booleans, you might want to pack all those 0/1 states together as a single integer and use that integer to look up a behavior. Here’s an example using four booleans; extend and alter to suit your needs.
This example shows how you can output a single integer as the result of a group of button inputs. In this example if you toggle the first and last toggle objects or the first and last radiogroup’s checkbox, you can produce a 5, pretty much in a binary-fashion way.
Following the “Tap Tempo” example, this is a translation of that patch it into a Max for Live device that controls the Live transport (using the mouse instead of the t key). For the purpose of the example demonstration the code that would reside inside an amxd file is included here inside a Max patch, so you can just see in Max without having to load it into Live.
This example shows a super simple tap tempo implementation. The patch alters the transport tempo based on the rate at which you tap the “t” key. This method simply takes the average of the most recent three time intervals between the most recent four taps. So once you tap four times, it will set the transport tempo to your tempo, and if you keep tapping it responds to your changes but takes a couple beats to move gradually to your new tempo.
This example shows how to change the size and rotation position of an image or video displayed using Jitter. The x-y orientation of the image is manipulated via the rotate message sent to jit.gl.videoplane and the size of the image is altered via the camera message sent to jit.gl.render.