## Simple MIDI harmonizer in C major

One way to analyze MIDI note information is to use the modulo operator to determine a note’s pitch class (C, C#, D, etc., regardless of what octave it occurs in).

One way to analyze MIDI note information is to use the modulo operator to determine a note’s pitch class (C, C#, D, etc., regardless of what octave it occurs in).

The **%** object is the arithmetic operator “modulo” (a.k.a. “mod”), used in modular arithmetic. Whereas the **/** object (“divided by”) divides the left input by the right input and outputs the quotient, the **%** object divides the left input by the right output and outputs the remainder.

This example shows how to play sound files preloaded into **sfplay~ **using a MIDI keyboard with the **select** object.

This patch demonstrates an application of modular arithmetic to wrap a series of numbers around within a defined range. The algorithm produces a series of expanding steps: 0, 1, 3, 6, 10, 15, 21, etc. The difference between each number and its predecessor in the series increases with each step—1-0=1, then 3-1=2, 6-3=3, 10-6=4, and so on. We do this by incrementing a **counter** and adding its output to the previous output of the **+** object.

This patch shows examples of linear mapping and linear interpolation, using the **lmap** abstraction described in the “Linear mapping equation” example. One could substitute the built-in Max object **scale** in place of **lmap** with the same results.