Skip to content

Music Primer for Engineers ​

This page defines the music terms used throughout the documentation. It assumes you can read code and data structures, but not necessarily staff notation.

How to read this page

Think of a composition as several time-aligned streams. A voice is one stream of notes. A chord is the vertical snapshot made when several streams sound together. Most counterpoint rules ask whether the streams stay independent while the vertical snapshots remain stable.

Mental Model ​

Music termEngineering analogyWhere it appears
VoiceA time-ordered streamOne MIDI track in events.tracks
BarA fixed-size time windowtotal_bars, targetBars
BeatA pulse inside a barMeter-specific strong, medium, and weak positions
Structural accentA strong or medium metric position — checked strictlystrong_beat_dissonance, vertical_dissonance
ChordA vertical state at a time pointHarmonic plan and chord-tone checks
FormA template or state machineform, voice count, meter, natural length
MaterialImmutable or semi-fixed source datasource: "material"
OrnamentA post-processing decorationsource: "ornament"

The validator's basic question

For most local rules, the validator asks three things: which voices are sounding, what interval or chord they create, and whether that situation is allowed at this beat. The staff examples in the course visualize exactly that.

Reading the Staff Figures ​

Every figure in the course is a small score with two or three staves. You do not need fluent notation reading — five conventions cover everything:

  1. Vertical position is pitch. Higher on the staff means higher pitch. The upper staff is the higher voice, the lower staff the lower voice; the clef at the start of each staff says which pitch each line stands for (next section).
  2. Left to right is time. Notes aligned vertically sound at the same moment — that vertical pair is what "interval" rules inspect.
  3. The note shape is the duration. A hollow head with no stem is a whole note; hollow with a stem is a half note; filled is a quarter; filled with a flag or beam is an eighth.
  4. Symbols before a note bend its pitch. A sharp (♯) raises the note one semitone, a flat (♭) lowers it one, a natural (♮) cancels a previous alteration.
  5. Colors and marks are analysis, not music. Red marks a violation, amber a scoped or conditional sonority, green a correct resolution. Rings, boxes, arrows, and brackets show where the validator is looking.
DurationBeats (quarter = 1)In event JSON
Whole note4duration: 1920
Half note2duration: 960
Quarter note1duration: 480
Eighth note1/2duration: 240
Sixteenth note1/4duration: 120

A dot after a note multiplies its length by 1.5: a dotted half lasts 3 beats (1440 ticks), a dotted quarter 1.5 (720). A rest is a silence with the same set of durations; the event JSON has no rest events, only gaps between notes.

A tie is a curved line joining two notes of the same pitch: they sound as one continuous note held across the boundary. Suspensions (course chapter 3) depend on this — a note is held over while the harmony changes underneath it.

Clefs and Octave Numbers ​

A staff has five lines, and on its own it does not say which pitch each line is. The clef at its left edge fixes that. The treble clef (𝄞) curls around the line for G4; the bass clef (𝄢) puts its two dots around the line for F3. Notes too high or too low for the staff get short ledger lines of their own.

Pitches are named with a letter and an octave number: C4 is middle C (MIDI 60), and the number goes up by one at each C, so the B just below C4 is B3 and the D just above it is D4. Each octave is 12 MIDI numbers, so pitch / 12 - 1 (integer division) gives the octave number. Middle C sits on one ledger line between the two staves: below the treble staff, above the bass staff.

Octave numbers and middle CLeft: the C notes from C2 to C6 on a line, each 12 MIDI numbers above the last, with C4, middle C, at MIDI 60. Right: a treble staff above a bass staff. The treble clef marks the G4 line and the bass clef the F3 line. Middle C is written on one ledger line below the treble staff and on one ledger line above the bass staff; C5 sits inside the treble staff and C3 inside the bass staff.Octave numbersThe number goes up by one at every C.C2MIDI 36+12C3MIDI 48+12C4MIDI 60+12C5MIDI 72+12C6MIDI 84C4 is middle C, MIDI 60B3 = 59 · C4 = 60 · D4 = 62octave = pitch / 12 − 1Middle C on both stavesG4F3TREBLE CLEFBASS CLEFC4, written twiceC5C3One ledger line below the treble staff = one above the bass staff.
FoundationMiddle C in both clefs
The clef at the start of each staff fixes which line is which pitch. The treble clef curls around the G line (G4); the bass clef’s two dots bracket the F line (F3). Middle C, C4 (MIDI 60), sits one ledger line between the two staves, so it is written below the treble staff and above the bass staff. The octave number goes up by one at every C: the next C up is C5, the next C down is C3.
The first chord is one pitch, C4, written on a ledger line under the treble staff and over the bass staff.

The course text names notes this way too: "G4 over C3" means the G above middle C against the C an octave below it.

Notes, Beats, and Bars ​

A note has a pitch and a duration. In MIDI Sketch Bach event JSON, this becomes a pitch, a start_tick, and a duration.

A beat is the regular pulse inside the music. A bar or measure groups beats into a repeated pattern. The time signature says how: 4/4 means four quarter-note beats per bar; 3/4 means three quarter-note beats per bar. The engine clocks one quarter-note beat at 480 ticks, so a 4/4 bar is 1920 ticks and a 3/4 bar is 1440.

Strong and Weak Beats ​

Beats inside a bar are not equal. The first beat of each bar — the downbeat — is strongest, but meter can assign secondary accents elsewhere. Play this 4/4 example and count along:

FoundationStrong, medium, and weak beats
Count 1-2-3-4 through both bars. The downbeat is strongest, while beat 3 carries a secondary accent. The validator treats both as structural accents and the intervening beats as weak. Other meters supply their own hierarchy: compound meters accent dotted pulses, and a Sarabande gives beat 2 a medium accent.
In 4/4, beat 1 is strong and beat 3 is a medium accent; both are structural checkpoints.

The validator assigns three levels: Strong, Medium, and Weak. A structural accent is any position that is not Weak. The grid comes from the time signature and, for a Sarabande, the form's meter profile:

MeterStrongMediumWeak
4/4beat 1beat 3beats 2 and 4, plus subdivisions
2/4, 2/2, 3/8, and 3/4 outside a Sarabandebeat 1noneevery other beat and subdivision
Compound meter (6/8, 9/8, 12/8)first dotted pulselater dotted pulsesthe intervening eighth-note subdivisions
Sarabande 3/4beat 1beat 2beat 3 and subdivisions
Longer even simple meterbeat 1midpoint of the barother beats and subdivisions

In an ordinary 3/4 bar, then, beats 2 and 3 are both weak: the downbeat is the only structural accent.

The implementation reduces that hierarchy to one predicate for the rules:

cpp
bool isStructuralAccent(const HarmonicPlan& plan, Tick tick) {
  return metricalStrengthAt(plan, tick) != MetricalStrength::Weak;
}

Why the rules care:

  • Structural accents demand stability. Generated notes there must belong to the active chord, and simultaneous voice pairs must form consonant intervals (chapter 3).
  • Weak positions tolerate passing tension. A dissonance between accents can sound like motion from one stable point to the next — that is what passing and neighbor tones are.
  • Some rules only fire on structural accents. invertible_at_octave checks those checkpoints and ignores weak positions.

Voice ​

A voice is an independent melodic line, whether it is sung or played by an instrument. A three-voice fugue has three simultaneous lines. In MIDI Sketch Bach, each voice is exported as a separate MIDI track.

Voice is not the same as instrument

An organ can play three voices at once. A solo cello can imply multiple voices by jumping between low and high registers. The documentation uses voice for the musical line, and instrument for the playback sound.

The course also speaks of upper voices and outer voices. The lowest voice is the bass; everything above it is an upper voice. The outer voices are the highest and lowest lines — the ones listeners track most easily, which is why cadence rules inspect them specifically.

Pitch, Key, and Scale ​

A pitch is the height of a note, such as C, D, or E. The smallest distance between two pitches is a semitone — one MIDI number; two semitones make a whole tone. An octave is 12 semitones, and notes an octave apart share a letter name. pitch % 12 gives the pitch class — the pitch identity modulo the octave. It does not retain letter spelling or accidental notation, and many validator checks work on pitch classes.

A key is the tonal center: C major means C feels like home; D minor means D feels like home in a minor mode.

A key name has two parts: the tonic pitch class and the mode — major or minor. The mode is the pattern of whole tones (W) and semitones (H) the scale climbs from the tonic. Play the major version and watch where the two semitones fall:

FoundationThe major scale — W W H W W W H
A key name is a tonic plus a step pattern. Play the scale over the held tonic: degrees 3→4 and 7→1 are semitones, every other step is a whole tone — W W H W W W H. Start that same pattern on any of the 12 pitch classes and you get that pitch's major key; the accidentals needed to keep the pattern intact become the key signature. Note how the final semitone (the leading tone) pulls the line home to the tonic.
Two of the seven steps are semitones (H); the other five are whole tones (W).

The minor mode rearranges the same seven steps into a different pattern:

major  W W H W W W H  →  C major:  C D E F G A B
minor  W H W W H W W  →  A minor:  A B C D E F G

That step pattern is the entire structural difference, yet major keys read as bright and grounded while minor keys read as darker and more tense. Hear it directly — the same scale on the same tonic, major first, then minor:

FoundationC major vs. C minor — same home, different modevoices play in turn
Both scales start and end on C — same home, different step pattern. The play button plays them in turn: first major, then minor. Lowering degrees 3, 6, and 7 is all it takes for the line to turn darker. Shown here is the natural minor; in practice counterpoint raises the 7th back up to recover a leading tone (harmonic minor — course chapter 4). A minor played from A to A uses the unaltered white keys of C major: that pair is the relative keys.
The minor scale lowers degrees 3, 6, and 7 — three notes turn bright into dark.

C major and A minor in the pattern table share all seven notes and differ only in which one is home — such pairs are called relative keys (they return in chapter 6, where fugues modulate to them). Any of the 12 pitch classes can be the tonic, and each supports both modes, so there are 24 keys in total; MIDI Sketch Bach generates in all of them (key plus isMinor in the JS API, c_major / d_minor style values in the CLI). On a printed staff, the key is announced by the key signature — the sharps or flats stacked at the start of each line so they need not be repeated on every note.

In practice the minor mode is not one fixed scale. Counterpoint often raises its 7th degree to supply a leading tone (harmonic minor), and the familiar textbook pattern raises degrees 6 and 7 when ascending and lowers them when descending (melodic minor). In Bach's music, these degrees can be altered in either direction when harmony and voice leading call for it, so the ascending/descending pattern is a teaching description rather than a mechanical rule. See this common-practice scale overview; Chapter 4 of the course shows what the validator does with the distinction.

A scale is the ordered set of pitches used around that center — the major and natural-minor patterns above are useful reference patterns, not a complete description of Baroque scale practice. One API caveat: in MIDI Sketch Bach, scale means the length multiplier (short, medium, long, full), not a musical scale. The musical key is selected by key.

Scale Degrees ​

Positions in the scale are numbered from the tonic — a 1-based index into the scale array. Each degree has a name, and two of them carry obligations the validator enforces:

DegreeNameIn C majorRole
1TonicCHome — phrases want to end here.
2SupertonicD
3MediantE
4SubdominantFBass of the plagal cadence.
5DominantGThe strongest pull back to the tonic; cadences run V → I.
6SubmediantAThe deceptive cadence lands here.
7Leading toneBOne semitone below the tonic — obligated to resolve up to it.

Roman numerals (I, IV, V, vi...) name the chords built on these degrees: in C major, V is the chord G-B-D rooted on degree 5. Uppercase numerals are major chords, lowercase minor.

Degree numbers turn real scores into readable data. The opening bar of the C major prelude from WTC I — the most famous arpeggio in keyboard music — reduces to three of them:

From BachBach: WTC I Prelude in C major — a bar built from degrees 1, 3, and 5
The first bar of the most famous prelude ever written (WTC I, BWV 846) uses no melody at all — just the tonic triad C-E-G spread into a ripple, two notes for the left hand and a six-note wave for the right, twice per bar. Read it with the degree numbers: 1-3-5-1-3, climbing through two octaves and never touching another degree. The next bar keeps the same ripple and changes the degrees to 2-4-6 over a held 1 — that is all "harmony changing over a pattern" means. (Bach notates the first two notes as held voices; they are shown here as the plain sixteenths the hand plays.)
Sixteen notes, three pitch classes: every single one is degree 1, 3, or 5 of C major — the tonic triad.

Chord and Harmony ​

A chord is a group of notes understood as one vertical sonority. A C major triad contains C, E, and G — its root, third, and fifth. A seventh chord adds a fourth note a seventh above the root: G-B-D-F is G7, the dominant seventh in C major. Harmony is the sequence of chords over time.

Chord tone and non-chord tone

A chord tone belongs to the active chord. In C major, C, E, and G are chord tones. A non-chord tone does not belong to the chord; it can still be valid when it behaves as a passing tone, suspension, or other controlled tension.

Chord positions ​

The same triad can stand on any of its three notes. Which note is in the bass sets the chord's position:

FoundationOne C major triad, three bass notes
All three chords contain only C, E, and G; what changes is which of them is lowest. The figures 6 and 6/4 are the intervals above the bass that name the position: E–G–C gives a third and a sixth (shortened to “6”), G–C–E a fourth and a sixth (“6/4”). The fourth above the bass in the last chord is why the 6/4 is the unstable one. Its standard use is the cadential 6/4: the tonic triad over the dominant bass on a strong beat, whose sixth and fourth then fall to the fifth and third of V over the same bass note.
Root position puts C in the bass, first inversion (6) puts E there, second inversion (6/4) puts G there.
PositionBass note (C triad)FiguresIntervals above the bass
Root positionC5/3third and fifth
First inversionE6third and sixth
Second inversionG6/4fourth and sixth

The figures are the intervals above the bass, the shorthand of Baroque figured bass. The 6/4 contains a fourth over the bass, which is why it is the unstable position. Its most common job is the cadential 6/4: the tonic triad sounding over the dominant bass on a strong beat (C-E over G in C major), whose sixth and fourth then fall to the fifth and third of V over the same bass. It is really a decorated dominant chord.

"Inversion" means three different things

Interval inversion flips two notes so the lower one goes up an octave: a third becomes a sixth, a fifth a fourth. Chord inversion puts a note other than the root in the bass (above). Melodic inversion turns a line upside down, so every step up becomes a step down (chapter 2's Goldberg canons, chapter 6's fugal devices). Invertible counterpoint (chapter 2) is built on the first meaning.

Interval and Degree ​

An interval is the distance between two notes. The documentation often means a vertical interval: the distance between two voices sounding at the same time.

The word degree in "5th" or "8th" means counted scale-letter positions, not semitones. C to G is a fifth because counting C-D-E-F-G gives five letters. C to the next C is an octave or eighth because counting C-D-E-F-G-A-B-C gives eight letters. (Do not confuse this with scale degrees above: an interval number counts the span between two notes; a scale degree numbers one note's position in the key.)

Why fifths and octaves matter

Fifths and octaves sound especially fused. If two voices move in parallel fifths or octaves, they can stop sounding like independent lines. That is why the validator treats parallel perfect intervals as a structural problem.

Interval Names and Qualities ​

The labels in the staff figures use standard shorthand: a quality letter plus the degree number — P5, M3, m10, A4. The degree number counts letters (previous section); the quality letter pins down the exact semitone count:

LetterQualityApplies toExample
PPerfectunison, 4th, 5th, octaveP5 = 7 semitones
MMajor2nd, 3rd, 6th, 7thM3 = 4 semitones
mMinorone semitone narrower than majorm3 = 3 semitones
AAugmentedone semitone wider than perfect/majorA4 = 6 semitones
dDiminishedone semitone narrower than perfect/minord5 = 6 semitones

The full lookup for one octave:

semitones  0   1   2   3   4   5   6      7   8   9   10  11  12
name       P1  m2  M2  m3  M3  P4  A4/d5  P5  m6  M6  m7  M7  P8

Four things worth noticing:

  • P1 (unison) is two voices on the same pitch — distance zero.
  • 6 semitones has two spellings, A4 and d5. Either way it is the tritone: three whole tones, the F-to-B distance, and dissonant under both spellings.
  • Other counts are ambiguous too: 9 semitones is usually a major sixth but can be spelled as a diminished seventh (d7); 3 is a minor third or an augmented second (A2). MIDI cannot tell spellings apart. In the one case where the difference changes a verdict — A2 is a forbidden melodic leap, m3 is fine — the validator reconstructs the spelling from the key's scale degrees (course chapter 4).
  • Compound intervals add 12: M10 = M3 + octave (16 semitones). The validator classifies intervals mod 12, so a tenth behaves like a third.

Steps and Leaps ​

A melodic interval — one voice moving to its own next note — is either a step or a leap. A step moves to the adjacent scale note (1–2 semitones); anything larger is a leap.

FoundationSteps and leaps
A step moves to the next-door scale note (1-2 semitones); anything larger is a leap. The distinction drives the melodic rules: dissonance must be approached and left by step, and leaps spend energy that stepwise motion has to pay back. Here the bass holds while the melody walks up by step and then leaps a fourth to the octave.
The melody steps twice, then leaps a fourth.

The distinction does real work in the rules: dissonant non-chord tones must be approached and left by step (chapter 3), and consecutive large leaps are rejected because the line stops sounding like a singable voice (chapter 4).

The first bar of the First Cello Suite spends both kinds of motion exactly this way — leaps to outline the chord, steps to decorate it:

From BachBach: Cello Suite No. 1, Prélude — steps and leaps in one bar
The opening bar of the First Cello Suite (BWV 1007) is a one-line demonstration of the step/leap economy. Each half bar opens with two leaps, a fifth G→D and a sixth D→B, which outline the G major triad. Then comes the one stepwise moment, B-A-B, a neighbor figure around a chord tone. The half bar ends by rocking between B and D, leaps again, but between two tones of the same chord, so the line never leaves the harmony it is spelling out. Leaps that land on chord tones are cheap; the single non-chord tone, A, is the one that arrives and leaves by step. One voice, two registers, and the harmony is fully implied. Chapter 7 returns to this under the name "compound melody".
Each half bar opens with two leaps, steps B-A-B, then rocks between B and D: every leap lands on a chord tone.

Consonance and Dissonance ​

A consonance is a stable-sounding interval or chord. A dissonance is a tense interval or chord that usually needs placement and resolution.

In this documentation, dissonance is not "bad sound." It is controlled tension. The validator rejects dissonance when it appears in the wrong metric position, lacks preparation, or fails to resolve.

Motion ​

When two voices move from one note to the next, their relationship is called motion.

TermMeaning
Parallel motionBoth voices move in the same direction and keep the same vertical interval number (a sixth to a sixth, a fifth to a fifth).
Similar motionBoth voices move in the same direction, and the interval between them changes.
Contrary motionThe voices move in opposite directions.
Oblique motionOne voice holds while another moves.

Motion is about pairs of time steps

A single vertical fifth is not automatically a problem. A parallel fifth needs two snapshots: the previous interval and the current interval are both fifths, and both voices moved in the same direction.

The engine takes those snapshots at union onsets: the sorted list of every tick at which any voice starts a note. Each voice pair is compared at consecutive union onsets, so a voice that holds a long note still takes part, sounding the same pitch at each onset.

Cadence ​

A cadence is a phrase ending. In tonal music, the strongest common ending moves from V to I: dominant to tonic.

What are I and V?

Roman numerals name chords by their position in the key. In C major, I is the tonic chord C-E-G. V is the dominant chord G-B-D. A V-to-I cadence is roughly "away from home, then home."

Diatonic and Chromatic ​

A note is diatonic when it belongs to the current key's scale, and chromatic when it falls outside that scale, whether written with a sharp, flat, or natural. A natural sign can therefore make a pitch chromatic by cancelling a key-signature accidental. Baroque counterpoint is mostly diatonic; chromatic notes are allowed where a device licenses them — secondary dominants borrow a chromatic leading tone, and the minor mode raises its seventh degree. Unlicensed chromatic contradictions between voices are rejected as cross relations (chapter 5).

Fugue Terms ​

A fugue is a contrapuntal procedure built from a main theme that enters in different voices.

TermMeaning
SubjectThe main theme of a fugue.
AnswerThe subject restated in another voice, usually shifted toward the dominant.
CountersubjectA recurring accompanying line used in some fugues.
EpisodeA comparatively freer passage between subject entries, often developing subject material or another salient idea.
StrettoOverlapping subject entries before the previous entry has finished.

Fixed Material ​

Some forms contain material the engine treats as fixed.

TermMeaning
Ground bassA repeating bass pattern used as the foundation of variations.
Cantus firmusA fixed long-note melody, often a chorale tune.
Pedal pointA held or repeated bass note while harmony changes above it.

Fixed carrier lines and their default supporting material are marked as "material" in event data. Notes emitted by the opt-in scored search (currently the Passacaglia free-counterpoint path) are marked as "compose", and decorative post-pass notes are marked as "ornament".

That source label decides how the validator treats a finding, because validation runs at two points. During Generation, a finding whose notes are all Material or Ornament is counted but exempted: the composer cannot repair fixed input. The FinalScore pass audits every source again; findings on authored material are recorded as information, and the form's vertical budget decides whether the rest close the form. The course chapters refer to this as the validation lifecycle.

Where to Go Next ​

This page is chapter 0 of the Counterpoint Course — the natural continuation is Chapter 1: Intervals & Consonance.

For the engine side instead:

  1. Features for what the generator can produce.
  2. Forms to choose a composition template.
  3. Voice Architecture to see how voices become MIDI tracks.
  4. Generation Pipeline to connect the musical terms to the engine stages.

Dual-licensed: AGPL-3.0 · commercial licensing available. Generated MIDI is yours to use freely.