I’m not a fan of 12-tone based scales in general. However sometimes in order to use some standard controllers you are stuck with it. Recently I’ve been working on ways to perform music in just intonation using MIDI input from a guitar so I’ve been forced to think in 12 step groupings, even if I intend to not use all of them (or some more than once). Here’s one solution that I’ve been playing with. The code is all SuperCollider but is pretty easy to implement in other languages.
First we need to make a “chromatic” JI scale. Honestly this could be anything depending on your needs. In my case I’m trying to keep each step within +/- 50 cents of the tempered pitch but this doesn’t need to be the case. Here’s one option:
The next step is to give it a fundamental/tonic. As usual, I’ll use A 440:
440 * [1,17/16,9/8,6/5,5/4,4/3,10/7,3/2,8/5,12/7,7/4,15/8];
Now we have all our frequencies for our A “chromatic” scale. Time to convert it to the linear MIDI number version (using floats to keep the offset). Lets also mod 12 it so that we get everything in the 0-11 pitch-class range:
((440 * [1,17/16,9/8,6/5,5/4,4/3,10/7,3/2,8/5,12/7,7/4,15/8]).cpsmidi % 12); // .cpsmidi converts frequencies to midi numbers
Almost done. The goal here is to take any MIDI number as an input, mod 12 it to get it’s pitch class as an index into our scale, and get the cent deviation in the format of +/- 0.50 so we can add that back to the original input. That may sound complicated but it will make more sense after seeing this last part. Now we need to reorder this list so that pitches are ascending (0-11), subtract the integer series 0-11 from it, and in this case round to the nearest cent:
((((440 * [1,17/16,9/8,6/5,5/4,4/3,10/7,3/2,8/5,12/7,7/4,15/8]).cpsmidi % 12).sort) - (0..11)).round(0.01); // .sort, uh, sorts it, (0..11) creates an array of 0-11 to subtract from our scale, and .round(0.01) rounds to the hundredths place
Afterwards we are left with:
[ 0.16, -0.14, -0.02, 0.17, 0.02, 0.14, 0.33, -0.31, -0.12, 0, 0.05, 0.04 ]
which are the cent deviations for all chromatic pitches from C-B. Notice how the only 0 is A (index/pitch class 9), since it’s our fundamental. Now by using MIDInumber % 12 as an index into this array, you get the cents to add or subtract to get your tuning. This is essentially what MIDI tuning tables are. Later I’ll explain how to use this along with pitch bends.