Counterpoint
Few engineers have heard the word counterpoint.
Harmony deals with vertical sonority. Stack chords, resolve dominant to tonic. Dissonance has strict rules — when it's allowed, when it must resolve. Counterpoint is a different axis. It deals with horizontal melody. When multiple independent melodies flow simultaneously, each must maintain its independence while still making harmonic sense when stacked vertically.
No parallel fifths. Restrictions on voice crossing. Contrary motion after a leap. Dissonance is permitted only as passing tones, neighbor tones, or suspensions under specific conditions. In Fux's species counterpoint, complexity builds in stages: 1:1, note against note, then 2:1, 4:1, syncopation, and finally florid counterpoint. Each rule is logical. An engineer's brain takes to it naturally. A set of conditionals. I can write this in code. That's what I thought.
So I started building an OSS that generates Bach's instrumental works. Implementing rules one by one in C++, generating melodies that satisfy the constraints. Parallel fifths detected. Voice crossing prevented. Suspension preparation and resolution enforced.
I extracted transition probabilities from Bach's scores — interval steps, beat positions, scale degrees — and fed them into Markov chains to capture his melodic tendencies. Run the validator and a compliance rate comes back. Tests pass. Every rule followed.
But what comes out is still impossibly far from music.
Every rule satisfied, yet it doesn't work as music. Software that meets spec but nobody wants to use. No bugs. But something crucial is missing.
Listen to a Bach fugue and you hear, painfully, what happens on top of the same rules. Melodies sing within constraints. Answers chase subjects. Tension builds and resolves. And then he steps outside the line. Knowingly. He has mastered the rule against parallel fifths, and deliberately chooses the leap that barely skirts it. Walking the edge of the constraint without breaking it. That is what creation means.
Same rules. Why is the gap this large? Completely beaten by a man who died 276 years ago.
This is what makes music hard. Rules can be taught. What to choose within those rules cannot. Programming is similar. Syntax can be learned. Design patterns memorized. But whatever lives between "code that works" and "good code" can only be grasped by writing, endlessly.
If this interests you, come play. It's C++, though.