Why There Are Twelve Notes: Music Theory from First Principles

Music Theory for Programmers

Why There Are Twelve Notes: Music Theory from First Principles

A programmer who can't play an instrument derives music theory from scratch using code. Starting with a single sine wave, they explain pitch, timbre, and the harmonic series, showing why simple frequency ratios sound good and why there are twelve notes in an octave. Along the way, they build scales, chords, and a chord progression using the Web Audio API—no instrument or prior knowledge required.

The simpler the fraction, the better it sounds.
  1. seanhunter

    This is (mostly) not music theory and what is music theory is mostly wrong or incomplete to the point of being wildly misleading. Source: have degree and postgrad in music, was a professional musician until RSI put paid to that career, wife is a professional musician and teaches to postgrad level at 2 conservertoires, most of our friends are professional musicians, have a house full of scores and music books.

    If you actually want to learn music theory for the purposes of playing I strongly recommend you just follow whatever tutorials for your instrument and style and if you get to the point where feel you want to learn more and take it seriously in and of itself, buy “The Jazz Theory Book” by Mark Levine[1]. In spite of what it says, there really isn’t any such thing as Jazz theory - it’s just music theory, and this book is a great presentation with lots of good examples. If you like jazz (or the western popular music tradition including rock, pop, funk, etc) you’ll come out understanding how that music works better than most people. If you’re doing a music degree, there will be books recommended by your music programme, but honestly, Levine will cover most of what you need if you’re not doing a straight classical course in which case you’ll want to augment with a more conventional source so you understand the “rules” they want you to follow when writing pastiche counterpoint etc.

    If you want to get big into composition and/or want to understand late romantic and 20th centur […]

  2. polotics

    Let us try an experiment shall we: listen to any music you like and try and match the information the article provided to the complexity of what you are hearing.

    How much do you see a path from A(rticle) to S(ound in your ear).

    This article is trivializing music down to a few not-so-important facts and mistaking some math for anything that would help `programmers` (?) understand music.

    Maybe start by rewatching "This is Spinal Tap" instead, and consider that https://www.reddit.com/r/musictheory/comments/59n3pg/remembe...

  3. ergonaught

    I want to read it, because it’s interesting. And yet.

    https://bcantrill.dtrace.org/2026/09/05/the-revolt-of-the-re...

  4. maybewhenthesun

    > Which is a strange way to teach a system that essentially comes out of physics and arithmetic. There are twelve notes for a reason.

    There is of course a lot of physics involved. But there is at least as much convention at play. So imho this is a very one sided way of looking at it.

    There is a physical reason the 12 notes are those 12 notes (though the exact frequencies assigned are influenced by culture as well), but lots of different cultures use less notes, or more, or extra notes inbetween.

    So 'Because that is the convention.' is imho at least a good an explanation as the physics one.

  5. jkahrs595

    This is more “synthesizers for programmers” than “music theory for programmers”.

  6. theanonymousone

    How come the same article has been posted four times in the past 18 days? https://news.ycombinator.com/from?site=runjs.app

    Doesn't HN have a temporal deduplication system?

  7. _kb

    If this is the sort of thing that interests you, I highly recommend setting aside 90 minutes and strapping yourself in for a listen to https://malwebb.com/notnoi.html.

  8. pianopatrick

    For all the programmers reading this who think music theory is complex, just realize that is how programming seems to most people.

More from this day

2026-09-06