One question I get from my students quite a bit is,
how do I make a scale quantizer in max.
It's actually pretty easy.
I'm going to show you how to do it.
First of all, we're going to start with our incoming note into our system.
I'm going to create a number box just by hitting the 'I' key for integer.
Let's specify the properties here.
I hit "Command I" to open up the inspector
and I'm going to change the display format to midi notes.
I find it's also helpful to set the minimum and maximum values to 0-127.
This represents any MIDI integer coming into our system and you can see
there's some sharps here and we're going to quantize that to whatever scale we want.
It doesn't have to be a diatonic scale.
It could be a pentatonic scale, it could be just like root and fifth, whatever you want.
This is up to you.
You're making your own scale quantizer.
We're going to create a C Ionian diatonic scale.
The first thing that we need to do is separate
this information from this number box into two bits of information.
One is going to represent the pitch class,
which is an integer that is going from 0-11.
Then the other bit of information is which octave that is actually relying on.
What we need to do is we need to take
this number box and we need to strip the octave information out of it.
Now remember, this is just a number box that's showing us of an integer between 0-127.
We want to first of all just obtain the pitch class.
So a C is going to be represented by an integer of zero,
and then a C-sharp would be represented by an integer of one and so on,
all the way up to B,
which would be represented by an integer of 11.
Mathematically, this is what's known as the modulo operator.
We want to separate this into classes of 12 subdivisions.
The modulo operator is the little percent sign and I enter in an argument of 12.
If I just grab
this number box that we've already formatted into midi messages, midi integers,
you can see that we get that first octave no matter
where I'm at with this incoming midi note.
If I were to display this with an integer,
we're going to see a number between zero and 11.
As I move this up you can see it goes up to 11 and then
recycles back starting at zero on our C. That's the pitch class.
Now we need to extract the octave information.
The octave information can be derived just simply by dividing the input by 12.
You will see that the first octave in our midi system
here is going to give us a zero and as we move up to the next octave,
here we are at C-1, now you can see we're at octave one and this will go all the way up
to octave 10 because we have about 10 octaves specified in the midi spec.
Now, we have these two numbers.
This is the pitch class and this is the octave.
Now the reason we're separating out this octave information
is because we're going to use a coll to look
up the output of this pitch class and then constrain it to the values that we want.
Let's go ahead and create a coll.
I hit "n" for new object and I'm going to type in coll.
The very first thing when you create a coll is you really
almost always want to embed the information in the patcher and
the easiest way to do that is just to use
the @embed argument with a value of one to indicate that it's on.
It's just a little flag, one is on, zero is off.
We're going to edit this information directly in the coll.
I'm going to double-click on the coll and I get my coll editor here.
We want to process these numbers zero through 11,
so I'm just going to enter those in 0, 1, 2,
3, 4, 5, 6, 7,
8, 9, 10 and 11.
Then we need to follow this with a comma that delineates
the index from the values that the coll is actually accessing.
I find it's really easy just to enter in
the comma and use the down arrow key to go to the next line.
Now, we have to make some decisions about the values that these are going to represent.
So C is zero,
so that should definitely remain a C and
then when I'm done I close that with a semicolon.
Then C sharp, this is where some of your judgment has to come into play,
like does a C-sharp translate to a D and C Ionian,
or does it translate to a C?
I'm going to weight this more heavily to the root
so I'm going to say that's going to be also a zero.
Two is going to be a D, that shall always be a two.
That's the D-Sharp and that will also be a D. Four is a
third so we're going to have that output our four.
[NOISE] Then five is also going to be a five.
That's our fourth, that's our F. Now at six,
we probably want to send that up one level,
so that's going to go to the fifth.
Six is going to go to seven.
Seven of course will be seven,
that's our G. Then we can also emphasize the G more,
so a G-sharp comes in,
we can translate that down to a G. A should stay in a A.
Our A-sharp should go to an A or the seventh.
Let's have it go to the seventh, so I'll have it go up to 11,
and this will go to 11.
I have defined one octave of our pitch class.
You're not just allowing which pitches are going through,
but you're also specifying which values are weighted to what they're translated into.
When we're done with this, just hit the validate button.
Now this call should output
a C diatonic scale regardless of what number is coming into it.
We shouldn't see any sharps or flats as I move through this.
You could see this is an A-sharp and it's outputting a B.
Now I need to marry this back with
the octave information and this is going to seem weird,
but in order to convert this number which represents octaves into a semitone offset,
I'm going to multiply it by 12.
I have divided by 12 here at the octave,
and I multiply it by 12 to get the semitone offset.
When I move this number,
you should see this increment in banks of 12 and that's correct.
We're going to take this pitch class and add it to our octave
and this is going to produce the final quantized output.
I just use an ad object here
and plug this into the left and right operand and then finally,
that'll get us to this ending point.
We should just see regardless of what octave we're playing,
we should see a C Ionian output and we do.
There you go. That's how you make a pitch quantizer.