Tutorial
Scales - Using Pitch Class Sets
Reload page to restart example
A pitch class is a type of pitch name, such as C, C# or D, regardless of octave range. Particular pitch classes can be grouped together as a pitch class set, for example; C, D, E, G, A. In music theory these are more often referred to as an ordered list, which are called scales, for example the Pentatonic Scale. Some scales are called modes, such as Aeolian or Phrygian mode. These pitch sets are also related in some cases to the key of the music, for example C Major.

While this might sound complicated (and it can get so) all this can be looked up in various music theory texts.

The most common use of the pitch class sets in SoundCipher is to enable you to restrict note pitches to a particular scale or mode. So you can, for example, play music in A minor.

In code a pitch class set is described as an array of floats with values in the octave from 0-11. For example, float[] BLUES = {0, 3, 5, 6, 7, 10}; Check the documentation for a complete list of pitch class sets.

The pitch class sets are Java constants, which means they cannot be changed and also, by convention, that  their names are written in UPPER case. They are automatically included in ScoundCipher instances and so can be accessed by de-referencing, for example; sc.MINOR;

Let's look at how they can be used. First in a non-sounding example. The idea is to quantize a pitch value so that it is one that is within a nature minor scale.



After importing the SoundCipher library and creating an instance of it called sc, a variable pitch is set to a random value between 60 and 80. A boolean flag, inScale is initiated as false, assuming that the random choice may not be a member of a pitch class set (not a scale degree).

The while loop checks the pitch against every scale degree (number in the set) and if it is not within the scale it makes a new random selection. This process continues until a scale degree is selected, then this pitch value is printed.

An important bit of math is the modulo function (%) that reduces the pitch to its octave position by returning the remainder when dividing by 12. This results in a number between 0-11 and this is compared to the numbers in the pitch class array for the specified scale.

Minor Riff
Now let's look at applying this process in a musical context. We'll create a short random riff that is in a minor key (only using pitches from the minor pitch class set).

The process of checking for inScale has been made into the function called modeQuantize (with a few refinements).



The random riff is written twice to a score (to repeat it for some more musicality) then played. A callback at the end of the riff causes the process to be repeated.

The whole process is looped 8 times and the graphics count this down visually.