The Scale

EDM.8a: numbers become notes, melody gets a map

Every note so far has been spelled out. note("c3 eb3 g3")—you type the pitch, strudel plays it. That works, but it forces you to think in note names. Scales let you think in numbers. Pick a scale, type a number, and the scale decides which pitch to play.

what you already know

s(), note(), stack(), cat(), setcpm(35), mini-notation (~ * [] <> / @), .gain(), .pan(), .lpf(), .lpq(), .attack(), .decay(), .sustain(), .release(), .room(), .size(), .delay(), .delaytime(), .delayfeedback(), .distort(), chord notation [c3,eb3,g3], progressions with <>, .every(), .sometimes(), .jux(), .off(), arrangement with cat() and gain automation, and the phonk palette from EDM.4–7.

00Scale Degrees

Eight numbers. One scale. Hit play:

C minor scale by number

That’s C minor, ascending. The numbers map to notes: 0=C, 1=D, 2=Eb, 3=F, 4=G, 5=Ab, 6=Bb, 7=C one octave up. You typed numbers. The scale decided the pitches.

Now rearrange those numbers into a rhythm:

numbers as melody

Same scale. Different order, different grouping. Now it’s a melody, not a scale run. The last beat subdivides—[7 5] plays two notes where one used to be. Everything you know about mini-notation still works. The numbers just replace note names.

scale / scale degrees

A scale is a set of notes ordered by pitch. Scale degrees are numbered positions in that set. 0 is the root—the home note. The scale decides which actual pitches the numbers map to. Change the scale, the same numbers produce different pitches.

tweak it

Try n("0 4 2 6 4 1 3 5").scale("C:minor") for a different melody from the same seven notes. Or n("7 5 3 1 6 4 2 0") for a descending line. Same raw material, different shape.

01Major + Minor

C major. Same numbers as before:

C major scale

Now C minor. Same code, one word changed:

C minor scale

Same numbers, different scale, completely different mood. Major is bright. Minor is dark. The difference is three notes: the 3rd, 6th, and 7th are each one semitone lower in minor.

Hear both back to back. Same degree pattern, different scale—first major, then minor:

major then minor — same melody

One cycle bright, one cycle dark. cat() alternates between them. The degree pattern 0 2 4 7 4 2 stays identical. Only the scale name changes. That’s the power of scale degrees—the shape of the melody is separate from its mood.

major vs minor

The major scale follows the interval pattern: whole whole half whole whole whole half (W W H W W W H). The minor scale: W H W W H W W. The 3rd degree is the tell. A major 3rd sounds bright. A minor 3rd sounds dark. Three notes change. The whole character flips.

tweak it

Try "C:dorian" or "C:mixolydian" in place of major or minor. Same root, different mood. Dorian is minor but warmer. Mixolydian is major but heavier. Preview of EDM.8b.

rabbit hole: equal temperament and why 12 notes

The octave is 2:1

Play a note at 261.63 Hz (middle C). Double the frequency to 523.25 Hz. That’s the same note one octave higher. Every culture with a tonal system agrees on this: the octave is the most fundamental interval. The ratio is 2:1.

Dividing the octave

The question is how to fill the space between a note and its octave. Western music divides it into 12 equal steps (semitones). Each step multiplies the frequency by the 12th root of 2—approximately 1.05946. Twelve steps of that ratio land exactly on 2:1.

This system is called equal temperament. It’s a compromise. Pure intervals—a perfect fifth at exactly 3:2, a major third at exactly 5:4—sound cleaner. But they don’t add up evenly. Stack twelve perfect fifths and you overshoot seven octaves by about a quarter of a semitone (the Pythagorean comma). Equal temperament spreads that error across all twelve notes so every key sounds the same.

Not everyone makes this trade. Arabic maqam uses quarter tones (24 divisions). Indonesian gamelan uses 5 or 7 unequal divisions. Indian classical music uses 22 shrutis. The 12-note system is a choice, not a law.

One octave: C4 to C5

notefrequency (Hz)semitones from C
C4261.630
C#/Db277.181
D293.662
D#/Eb311.133
E329.634
F349.235
F#/Gb369.996
G392.007
G#/Ab415.308
A440.009
A#/Bb466.1610
B493.8811
C5523.2512

A major scale picks 7 of these 12 notes. A minor scale picks a different 7. A pentatonic picks 5. The chromatic scale uses all 12. Every scale is a selection from this grid.

02First Melodies

A melody in C minor. Rests give it shape:

simple melody with rests

Four notes, four rests. The melody breathes. Now put it on top of the phonk beat from EDM.4:

melody over phonk

The melody uses the same C minor scale that the chords and bass are in. Everything agrees on the key. The <7 5> alternation gives the melody a 2-bar phrase—different ending each time. Degree 7 is the octave C, degree 5 is Ab. One resolves up, one pulls down.

Mini-notation in melodies

The / operator from EDM.6 works with scale degrees too. Spread a melody across two bars instead of cramming it into one:

melody spanning 2 bars

Eight events spread across two cycles. Four notes per cycle. The melody slows to half speed. /2 stretches the pattern across two bars—useful for long phrases that need room.

tweak it

Change the scale to "C:pentatonic"—only 5 notes, everything sounds good. Almost impossible to hit a wrong note. Or "C:blues" for the blues scale. Both covered in depth in 8b.

03The Scale

The phonk track from EDM.4–6, now with a scale-based melodic lead. Drums, 808 bass, pad, cowbell—everything you’ve built. The new layer: a melody written entirely in scale degrees. Numbers in, notes out. Four bars, four different melodic shapes over the same C minor scale.

// TITLE: the scale
compose
  1. Rewrite the melody. Try n("<[4 ~ 7 ~ 5 ~ 2 ~] [3 ~ 0 ~ 4 ~ 6 ~]>") for a two-bar phrase that starts high and falls.
  2. Change .scale("C:minor") to .scale("C:dorian"). Same numbers, warmer mood. The 6th degree shifts up one semitone—Ab becomes A natural.
  3. Add .every(4, rev) to the melody line. Every fourth bar, the melody plays backward. Pattern variation from two words of code.
  4. Share it. The track has drums, bass, pad, and a melody that you wrote in numbers.
what you earned
tooldoeslooks like
.scale()maps numbers to notes in a key.scale("C:minor")
n()play scale degrees (numbers)n("0 2 4 7")
"C:major"the major scale — bright, W W H W W W H.scale("C:major")
"C:minor"the minor scale — dark, W H W W H W W.scale("C:minor")
scale degree numbers0=root through 7=octaven("0 1 2 3 4 5 6 7")
/N in melodiesspread melody across N cyclesn("[0 2 4 7 4 2 0 ~]/2")
scale checklist

.scale() to set the key. n() to write in numbers. "C:major" for bright, "C:minor" for dark. All mini-notation works inside n()—rests, groups, alternation, / for multi-bar phrases. The scale maps numbers to pitches. You write the shape.

Next: Modes. Same notes, different home. Same code, different mood.

listening

Tracks that demonstrate this lesson’s concepts.

artisttrackwhy
Koji KondoZelda OoT: Gerudo Valley (1998)(VGM) minor scale, flamenco guitar, rhythmic fire
NujabesFeather (2005)(hip-hop) modal harmony in beat music
LTJ BukemDemon’s Theme (1992)(atmospheric DnB) atmospheric DnB, melodic layers
Zhu ZaiyuEqual Temperament treatise (1584)(hip-hop) first mathematical derivation of 12-tone equal temperament
history

The 12-note scale is a compromise. Different cultures divided the octave differently. The version we use today was the result of centuries of argument.

Pythagoras and the monochord (c. 500 BC)

Pythagoras reportedly discovered that simple ratios produce consonant intervals — 2:1 (octave), 3:2 (fifth), 4:3 (fourth). He (or his followers) used a monochord to demonstrate this. The idea that musical beauty has mathematical structure became foundational to Western music theory. But stacking pure fifths (3:2 ratios) doesn’t perfectly cycle back — the “Pythagorean comma” means 12 pure fifths overshoot 7 octaves by about a quarter of a semitone.

Zhu Zaiyu and equal temperament (1584)

The Chinese prince and scholar Zhu Zaiyu published the first mathematically precise calculation of equal temperament — dividing the octave into 12 equal semitones using the 12th root of 2. Simon Stevin in the Netherlands independently derived the same system around 1585. Equal temperament is a compromise: no interval except the octave is acoustically pure, but every key sounds equally “in tune” (or equally “out of tune”). It enabled modulation between keys without retuning.

Bach and the Well-Tempered Clavier (1722/1742)

Bach wrote preludes and fugues in all 24 major and minor keys to demonstrate that a well-tempered keyboard could play in any key. Whether he used equal temperament specifically is debated — “well-tempered” likely meant some form of circulating temperament. The practical effect was the same: the keyboard as a universal instrument, not locked to one key.

Sources: Barker, Greek Musical Writings, Vol. 2 (1989); Needham, Science and Civilisation in China, Vol. 4 (1962); Isacoff, Temperament (2001).

→ explore the full timeline