Skip to content

Chapter 0 — Music Primer for Engineers

If you can read a coordinate system and reason about modular arithmetic, you already have the mental tools to read music. This chapter treats pitch as integers, time as a grid, and tempo as a playback clock — no prior music background required. By the end you will be able to read every score in this course and map it onto MidiSketch config fields.

Pitch is just an integer

Music has a finite alphabet. Western pop divides the octave into 12 equally spaced steps, and every melody, bassline, and chord is drawn from that grid. MidiSketch never sees "the note C" — it sees the integer 60.

Note / pitch

Pitch is how high or low a sound is, perceived by your ear. A note is a single pitch with a duration — the atomic event in a melody. Think of a note as a (pitch, start, length) tuple; this chapter focuses on the pitch field.

Semitone

A semitone is the smallest pitch step in this system — one cell on the 12-step grid, equivalent to +1 in MIDI. Adjacent piano keys (white-to-black or the two white pairs E–F and B–C) are one semitone apart. Twelve semitones make a full octave.

MIDI note number

A MIDI note number is the integer encoding of a pitch: an enum from 0 to 127. By convention C4 = 60, and each semitone adds 1. So C#4 = 61, D4 = 62, up to B4 = 71. It is the canonical identifier MidiSketch and every synth speak in.

Pitch systemThe 12 semitones from C to B
Every pitch in pop music comes from this 12-step grid. MIDI numbers them: C4 is 60, C#4 is 61, and so on up to B4 = 71. After 12 steps the names repeat one octave higher.
MIDI notemod 12Twelve equal steps fill one octave; pitch class = MIDI note mod 12.

The number-line view above is the whole point: pitch arithmetic is integer arithmetic. Want the note a tritone above G4? 67 + 6 = 73.

The octave and pitch class (mod 12)

Notes exactly 12 semitones apart share a name and sound like "the same note, higher". That equivalence is what lets us treat pitch with modular arithmetic.

Octave

An octave is the interval between a pitch and the one with twice its frequency — exactly 12 semitones, or +12 in MIDI. Notes one octave apart (C4 = 60, C5 = 72) are perceived as the same note class. The pitch class of any MIDI number is n mod 12, so all the C's collapse to 0.

OctaveSame name, one octave apart
Notes 12 semitones apart sound "the same but higher". That is an octave. In MIDI it is simply +12: C4 = 60, C5 = 72. This is why pitch class works as mod 12.
octave+12C4 (60) and C5 (72): same pitch class, +12 in MIDI.

This is why MidiSketch can fold an out-of-range note back into range by adding or subtracting 12: the pitch class (n mod 12) is preserved, only the octave register changes. Keep this mod 12 model in mind — Chapter 1 builds scales as subsets of the 12 classes.

Time is a grid

Pitch answers what; the next axis answers when. Time in pop music is quantized onto a regular pulse.

Beat

A beat is the steady pulse you would tap your foot to — the fundamental time unit. Tempo and rhythm are both measured in beats. In notation the default beat is the quarter note.

Bar (measure)

A bar (or measure) groups a fixed number of beats into a repeating cell, marked by vertical barlines in the score. It is the loop unit of musical time: most pop is built from bars of four beats.

Time signature

A time signature like 4/4 declares the grid: the top number is beats per bar, the bottom names the beat unit (4 = quarter note). 4/4 ("four-four") means four quarter-note beats per bar and is the default for almost all pop music.

BeatFour beats in a 4/4 bar
The beat is the steady pulse you tap your foot to. A 4/4 time signature means each bar holds four quarter-note beats — the default grid for nearly all pop music. MIDI Sketch uses 480 ticks per quarter note.
beatbarEach quarter note is one beat; four beats fill one bar.

Internally MidiSketch measures time in ticks: there are 480 ticks per quarter note. A beat is therefore 480 ticks, and a 4/4 bar is 1920 ticks — a fixed-point time base, much like a sample-accurate clock.

Tempo: the playback clock

The grid is dimensionless until you assign it a speed. That speed is the tempo.

BPM

BPM (beats per minute) is the playback rate of the beat grid — literally how many beats elapse per minute. Doubling BPM does not change which notes play or their relative spacing; it only scrolls the grid faster. MidiSketch accepts BPM 40240, and bpm: 0 selects the style preset's default.

TempoSame notes, different speed
BPM (beats per minute) is the playback speed of the beat grid. Here the same four-note phrase is written in quarter notes, then in eighth notes — the second one sounds like the same melody at double BPM. MIDI Sketch accepts BPM 40-240.
bpmBPM only changes how fast the grid scrolls — the notes stay the same.

Note the separation of concerns: pitch (integers), rhythm (tick offsets), and tempo (a scalar multiplier on the clock) are independent. You can transpose without touching rhythm, or change BPM without touching a single note.

Range: bounding the integers

A real instrument or voice can only produce a band of the 0127 range comfortably. MidiSketch expresses that constraint as two bounds.

RangeThe default vocal range: C4 to G5
A singer (or any instrument) has a comfortable range. MIDI Sketch expresses it as two MIDI numbers: the default melody stays between C4 (60) and G5 (79). Notes that would fall outside are folded back in by octaves.
vocalLowvocalHighvocalLow = 60 (C4) and vocalHigh = 79 (G5) bound every generated melody.

The defaults vocalLow: 60 (C4) and vocalHigh: 79 (G5) define a closed interval. Any generated note that would land outside is folded back by octaves (±12) until it fits — same pitch class, legal register. Valid bounds run 3696.

Reading the scores

Every interactive example here is drawn on a staff with a clef.

Staff & clef

A staff is the five horizontal lines notes are placed on; higher on the staff means higher pitch. A clef at the left fixes the reference: the treble clef used throughout this course pins the second line to G4. You do not need to sight-read — treat the staff as a vertical pitch axis and the clef as its origin marker.

Common pitfall — bpm: 0 is not silence

bpm: 0 does not mean "no tempo" — it tells the engine to use the style preset's default tempo. To pin a tempo, set a real value in 40240. Anything outside that range (or a vocalLow/vocalHigh outside 3696) is rejected by validateConfig, not clamped.

MidiSketch mapping

ConceptConfig fieldRange / notes
Tonic pitch classkey011 (0 = C, 7 = G)
Playback tempobpm40240; 0 = style default
Lowest allowed melody notevocalLowMIDI number, 3696 (default 60 = C4)
Highest allowed melody notevocalHighMIDI number, 3696 (default 79 = G5)
Time base(internal)480 ticks per quarter note

Continue with Chapter 1 — Scales & Keys.