## 2014 - Week 32

*There are endless ways how we can map x-dimension to pitch. This patch-a-week is focused on 12 tone equal temperament, the predominant scale in modern western music. We will elaborate a bit on how to map a continuous x-dimension (e.g. from the Chimaera) to pitch and frequency.*

### Fractional MIDI notes

Most musicians will be familiar with MIDI notes, let us therefore base our mapping on top of the latter. But as we are facing a continuous scale, and MIDI notes are integer, we will use the concept of fractional MIDI. As two MIDI notes are evenly spaced by 100 cents), we can easily derive a definition of a fractional MIDI value representing a continuous scale:

$$\begin{array}{rcll}24& =& C& \text{(1)}\text{}\text{}\\ 24.5& =& C+50cents=C+\frac{1}{4}tone& \text{(2)}\text{}\text{}\\ 24.75& =& C+75cents=C+\frac{3}{8}tone& \text{(3)}\text{}\text{}\\ 25& =& C\#& \text{(4)}\text{}\text{}\end{array}$$

### Linear mapping of x-dimension

With number of sensors $n$ , octave $oct$ and base note ${m}_{0}$ , we can derive a linear mapping from x-dimension $\left[0,1\right]$ to fractional MIDI notes $m\left(x\right)$ . The formula for the base note may look a bit weird at first glance, but it has its reason, as the formula is adapted to the default engravings on the Chimaera controller. Depending on the case size, the engravings will slightly differ, e.g. the cyclic pattern will start at different offsets. This is needed in order to arrange a many complete pattern as possible on any case size. The formula will take the variable offset into account. The following equations will map the span of three sensors to one MIDI note, e.g. a $\frac{1}{2}$ note, whereby the middle sensor will coincide with the integer note.

We start off by shifting the base MIDI note to the right octave’s C note, then subtract a $\frac{1}{4}$ note (which corresponds to 1.5 sensors) and finally subtract by a variable offset. The offset $off$ is straightforward to derive. The x-axis with its $n$ sensors is divided in as many complete half-octaves (6 MIDI notes, each 3 sensors wide) and the remaining sensors are distributed equally to the bottom and the top of the scale, e.g. divided by 2 and the converted to fractional MIDI notes, e.g. divided by 3.

The final fraction MIDI note $m\left(x\right)$ will then be a simple linear relationship of dimension $x$ , offset by base note ${m}_{0}$ .

$$\begin{array}{rcll}off& =& \frac{n\%18}{6}=\frac{n\%\left(6\cdot 3\right)}{3\cdot 2}& \text{(1)}\text{}\text{}\\ {m}_{0}& =& oct\cdot 12-0.5-off& \text{(2)}\text{}\text{}\\ m\left(x\right)& =& {m}_{0}+\frac{x\cdot n}{3}& \text{(3)}\text{}\text{}\end{array}$$

*Linear mapping from x-dimension to fractional MIDI for n=48 sensors and oct=2.*

### Stepwise mapping of x-dimension

Sometimes it will be handy to have integer MIDI notes only, without a continuous mapping. This can easily be achieved by rounding the continuous mapping $m\left(x\right)$ to a stepwise mapping ${m}_{s}\left(x\right)$ which increases by integer values.

$$\begin{array}{rcll}{m}_{s}\left(x\right)& =& round\left(m\left(x\right)\right)& \text{(1)}\text{}\text{}\end{array}$$

*Stepwise mapping from x-dimension to fractional MIDI for n=48 and oct=2.*

### Polynomial mapping of x-dimension

And sometimes it may be advantageous to have something in between a linear and a stepwise mapping, e.g. a relationship where the main mapping is a stepwise, but between the steps, there will be a continuous relationship. When plotted, this looks like a curve with wide plateaus at each integer step. The higher the polynomial order $k$ , the wider the plateau.

Such a polynomial mapping is calculated by first deriving the fractional difference ${m}_{f}\left(x\right)$ between linear and stepwise mapping. The fractional difference (which ranges over $\left[-0.5,0.5\right]$ ) is then put into its corresponding order $k$ and rescaled to the original range and added to the stepwise mapping.

$$\begin{array}{rcll}{m}_{f}\left(x\right)& =& m\left(x\right)-{m}_{s}\left(x\right)& \text{(1)}\text{}\text{}\\ {m}_{p}\left(x\right)& =& {m}_{s}\left(x\right)+{\left({m}_{f}\left(x\right)\cdot {2}^{\frac{k-1}{k}}\right)}^{k}\text{for}k=1,3,5,...& \text{(2)}\text{}\text{}\\ {m}_{p}\left(x\right)& =& {m}_{s}\left(x\right)+{\left({m}_{f}\left(x\right)\cdot {2}^{\frac{k-1}{k}}\right)}^{k}\cdot sign\left({m}_{f}\left(x\right)\right)\text{for}k=2,4,6,...& \text{(3)}\text{}\text{}\end{array}$$

For an order $k=1$ we get the initial linear mapping. Note that there are two slightly differing formulae for even and odd polynomial orders.

*Polynomial mapping from x-dimension to fractional MIDI for k=2, n=48 and oct=2.*

*Polynomial mapping from x-dimension to fractional MIDI for k=3, n=48 and oct=2.*

*Polynomial mapping from x-dimension to fractional MIDI for k=5, n=48 and oct=2.*

*Polynomial mapping from x-dimension to fractional MIDI for k=9, n=48 and oct=2.*

*A ready to use SuperCollider class incorporating all three types of x-dimension mapping (linear, stepwise, polynomial) can be get at our SuperCollider repository.*