Diatonic Scale Example

This example plays a one-octave diatonic scale.

Diatonic Scale

While a chromatic scale consists of 12 notes, a diatonic scale consists of 7 of those 12 notes arranged in a specific sequence of whole and half steps that sound inherently cohesive together in Western music.

The origin of these 7 notes dates back to early medieval church music, which was purely vocal and consisted of the 7 notes that people could sing well, with 5 stable steps (whole steps) and 2 reference points (half steps).

These half-step reference points are vital landmarks. Without them, the scale would consist entirely of identical whole steps. You would not be able to tell where you were in the octave and all movement would sound the same. The half steps break up the monotony and tell your brain exactly where you are in musical space.

Note Names

Early monks labeled these 7 vocal notes with the first letters of the alphabet: A, B, C, D, E, F, G. Early instrument builders made these the prominent white keys on a keyboard.

Relationship to Chromatic Scale

As music evolved, composers wanted to transpose keys and add dramatic tension. This led to inserting 5 black keys between the whole steps, creating the 12 note chromatic scale. Because each of these 12 notes is equally spaced, and includes all the half steps, the 12 notes of the chromatic scale are also called semitones.

Sharps and Flats

A black key sounds sharp (higher in pitch) compared to the white key to its left and flat (lower in pitch) relative to the white key to its right.

Sharps are indicated by a character called diesis (from the Greek word for division) that looks similar to the number sign on a computer keyboard (#). Flats are indicated by a character called bemolle (from the Latin b molle) that looks similar to lowercase b.

Minor and Major Scales

If you play a series of 7 white keys on a piano starting on A, the sequence of whole and half steps is: whole, half, whole, whole, half, whole, whole. This interval pattern defines a Natural Minor scale, which typically evokes a sad mood.

Whole steps are where you jump over a black key to get to the next white key. Half steps are where there is no black key between the white keys.

A half step is also known as a semitone. There are two semitones per whole step.

We can assign these whole and half step intervals to a JavaScript array to represent the minor scale pattern (2 semitones for a whole step, 1 semitone for a half step):

var minor = [ 2, 1, 2, 2, 1, 2, 2 ];

Moving up two notes and playing a series of 7 white keys starting at C, the sequence of whole and half steps becomes: whole, whole, half, whole, whole, whole, half. This interval pattern defines a "Major" scale, which typically evokes a bright, happy mood.

var major = [ 2, 2, 1, 2, 2, 2, 1 ];

Note that both of these scales are derived from the exact same set of white keys. Because the physical positions of the half steps on the piano are fixed, changing your starting note shifts where those half steps occur relative to your root, completely altering the musical mood.

Modes

In addition to starting on A (Minor) or C (Major), starting on any of the other 5 white keys shifts the location of those half step sequences to create different musical "modes", each with its own musical mood.

Terminology

The term diatonic is from the Greek diatonikos, meaning "progressing through tones". It describes a maximally spaced scale that divides the octave up into 7 notes and positions the resulting 5 whole steps and 2 half steps as far apart from each other as possible.

Be careful not to confuse the relational prefix dia- (meaning through) with the numerical prefix di- (meaning two). This is why diatonic means "through tones", but pentatonic means "five tones" (or a 5-note scale).

Playing Scales

With a modern piano keyboard, you can play a major or a minor scale starting at any white or black key on the keyboard by following the pattern of whole and half steps that define the major or minor scale.

The same is true for the JavaScript minor and major interval arrays we defined earlier. They can be applied to any root note to create a major or minor scale starting at that note.

With MIDI, each MIDI note number represents a semitone, starting at C with MIDI note number 0. Because there are 12 semitones per octave, any MIDI number that is evenly divisible by 12 is a C (e.g 36, 48, 60, 72, 84).

Getting Your Bearings

On a piano, the white key just to the left of each set of two black keys is a C. The C near the middle of the piano is middle C. In written sheet music, middle C is the note on the ledger line between the treble and bass clefs in the grand staff. If only the treble clef is present, it's the note on the first ledger line below the clef.

The MIDI note number for middle-C on the piano is 60. This is generally called C4 in the piano world (scientific pitch notation), and sometimes C5 in the MIDI world (because 60 / 12 is 5).

The octave one octave below middle-C is called C3 in scientific pitch notation and begins at MIDI note 48.

Example Source Code

Press the Copy button below to copy the example to the clipboard.

// Example: diatonic-scale.js - Play notes in a diatonic scale
var C3 = 48; // MIDI note 48 is C in the 3rd octave on a piano

var channel = 0;    // Channels are in the range 0 to 15 (MIDI channel 1 to 16)
var velocity = 80;  // MIDI velocity is in the range 0 to 127 (note volume)
var delay_ms = 0;   // Delay in milliseconds before playing note (for swing)
var duration = 250; // Note duration in milliseconds (250 is an eighth note at 120 bpm)

/**
 * Plays a diatonic scale starting at the specified root note
 *
 * @param {number[]} scale - An array of scale intervals (e.g. minor, major)
 * @param {number} root - The starting point for the scale
 */

function playDiatonicScale(scale, root)
{
    var note = root;

    for (var i = 0; i < scale.length; i++) {
        print("Playing note " + note);
        ws.fire("note_on", channel, note, velocity, delay_ms);
        ws.sleep(duration);
        ws.fire("note_off", channel, note);
        note += scale[i]; // increment by number of semitones for this scale position
    }
}

function runExample()
{
    print("Playing C-minor");
    playDiatonicScale(minor, C3);

    ws.sleep(1000); // 1-second pause between scales

    print("Playing C-Major");
    playDiatonicScale(major, C3);
}

runExample();