Live data from Hacker News

Basic Music Theory in ~200 Lines of Python

mvanga.com

141–150 of 192 posts

Re: Basic Music Theory in ~200 Lines of Python

#141

As a primer for music theory, this post doesn't teach much. It's using Python to derive various sets of notes in scales and modes, which is already easily available via google search, and in a more learnable format than Python code. The most basic aspect of Western music theory overlooked here is the relationship between tonic and dominant. If you know the "home" chord aka "the I" aka "tonic" is C major, the dominant…

Do you know why these chords are so common? Is it simply cultural or something else?

As it was explained to me by my musician aunt (and I've heard it repeated in other places): because Music Execs. Lots of successful pop music is uses the 1-4-5-(6) chord progression, thus, when executives are picking hit songs, they go with what they know will work.

It's like bringing brownies to a potluck. It won't blow anyone's mind, but everyone will happily eat them.

Re: Basic Music Theory in ~200 Lines of Python

#142
post #118

Earlier quoted context omitted.

The spacings are not random, they are still based on ratios. They just include more intervals in (what we call) the octave. The linked article actually explains the math pretty well.

Ah alright, I finally understand you. What you meant to say is the reason why Western classical music is built on the 12 note chromatic scale is because the musicians used the math! It has nothing to do with history. Sound about right?

Not exactly, although I think I understand what you are getting at.

What I meant was that the interval between a major third and fourth in a 12-tone chromatic scale has to be a semitone due to math, not due to some historical accident or decision.

It might be an accident of history that we use a 12-step scale in the first place though, since you can have arbitrary many intervals in an octave - but you can't just divide the octave in arbitrarily places and get music out of it. The intervals still have to be ratios.

(Well I'm sure some avant-garde composer have tried making music with intervals that are not ratios just to be clever, but I hope you get my point!)

Re: Basic Music Theory in ~200 Lines of Python

#143

Earlier quoted context omitted.

Heh, I understood your first paragraph. I understood literally nothing in the following two paragraphs. Is this what it is like when I talk to people who don’t know anything about programming about my work? Pure gibberish?

Yes, it is! Music and programming both have a lot of notation, syntax, and terminology. I am not really a programmer, but the thing I always wanted wasn't a "how to program guide" but "what is all this syntax" guide. It is funny, but when you learn a written language, you spend a lot of time learning grammar and punctuation, but when you go to learn programming it all seems conceptual. there are lots of demonstration…

So, this is for a few reasons.

Syntax is a skill floor, but it's not anywhere close to a skill ceiling.

If you want rapid-fire example of the various forms a given language commonly uses, I recommend X in Y minute guides. Those show off the various bits of syntax for a given programming language, though without rigorously defining them as such.

Part of the reason that programming syntax is usually taught by example, rather than by formalism is that the formalisms for programming syntax, well, look like this: (cribbing from wikipedia).

  program = 'PROGRAM', white_space, identifier, white_space, 
            'BEGIN', white_space, 
            { assignment, ";", white_space }, 
            'END.' ;
  identifier = alphabetic_character, { alphabetic_character | digit } ;
  number = [ "-" ], digit, { digit } ;
  string = '"' , { all_characters - '"' }, '"' ;
  assignment = identifier , ":=" , ( number | identifier | string ) ;
  alphabetic_character = "A" | "B" | "C" | "D" | "E" | "F" | "G"
                       | "H" | "I" | "J" | "K" | "L" | "M" | "N"
                       | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
                       | "V" | "W" | "X" | "Y" | "Z" ;
  digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
  white_space = ? white_space characters ? ;
  all_characters = ? all visible characters ? ;
Can you take that grammar and write 10 examples of valid statements from it, with no other context?

vs, if I give you

  PROGRAM ASSIGNMENTS
  BEGIN
    MYSTRING := "A STRING";
  MYNUMBER := 123;
  END
That gives you a much better flavor from looking at things.

Ultimately, most programming languages should have defined grammars in their docs somewhere, but most devs use them by intuition, rather than formally.

The other thing, as well, is that it's one you get past grammar as a primary concern that you gain true fluency. And there are a lot of things that are higher level than grammar that can aid/hurt a program much more than the grammar constructs (like various patterns, know algorithms, schemes of organization for different types of projects, and so on). A mostly human-usable grammar is table-stakes these days.

If you have a specific language you want examples or a grammar on, let me know, and I'll see if I can find it.

(edited for formatting)

Re: Basic Music Theory in ~200 Lines of Python

#144
post #118

Earlier quoted context omitted.

The spacings are not random, they are still based on ratios. They just include more intervals in (what we call) the octave. The linked article actually explains the math pretty well.

Ah alright, I finally understand you. What you meant to say is the reason why Western classical music is built on the 12 note chromatic scale is because the musicians used the math! It has nothing to do with history. Sound about right?

Although I agree with you... didn't Pythagoras derive the pythagorean tuning of diatonic doing the math with the 3:2 ratio?

I know near zero music history, but I was under the impression that that's the evolution from diatonic scales and eventually into our western music system.

Re: Basic Music Theory in ~200 Lines of Python

#145

Earlier quoted context omitted.

Yes, it is! Music and programming both have a lot of notation, syntax, and terminology. I am not really a programmer, but the thing I always wanted wasn't a "how to program guide" but "what is all this syntax" guide. It is funny, but when you learn a written language, you spend a lot of time learning grammar and punctuation, but when you go to learn programming it all seems conceptual. there are lots of demonstration…

So, this is for a few reasons. Syntax is a skill floor, but it's not anywhere close to a skill ceiling. If you want rapid-fire example of the various forms a given language commonly uses, I recommend X in Y minute guides. Those show off the various bits of syntax for a given programming language, though without rigorously defining them as such. Part of the reason that programming syntax is usually taught by example,…

Also, to add a further point: Because much programming is done by intuition rather than formalism is why there can be so much unintended use of a given program.

Re: Basic Music Theory in ~200 Lines of Python

#146

Earlier quoted context omitted.

Do you know why these chords are so common? Is it simply cultural or something else?

As it was explained to me by my musician aunt (and I've heard it repeated in other places): because Music Execs. Lots of successful pop music is uses the 1-4-5-(6) chord progression, thus, when executives are picking hit songs, they go with what they know will work. It's like bringing brownies to a potluck. It won't blow anyone's mind, but everyone will happily eat them.

That still doesn't explain why those chord progressions became popular, and they far predate the late 20th century record industry, so it really isn't a very satisfying or informative explanation, even though it's not outright wrong (it's just a restatement of familiarity bias, which generalizes outside music).

Re: Basic Music Theory in ~200 Lines of Python

#148

As a primer for music theory, this post doesn't teach much. It's using Python to derive various sets of notes in scales and modes, which is already easily available via google search, and in a more learnable format than Python code. The most basic aspect of Western music theory overlooked here is the relationship between tonic and dominant. If you know the "home" chord aka "the I" aka "tonic" is C major, the dominant…

Thanks a lot. I am adding your post into my collection of Hacker News wisdom snippets :)

Re: Basic Music Theory in ~200 Lines of Python

#149

As a primer for music theory, this post doesn't teach much. It's using Python to derive various sets of notes in scales and modes, which is already easily available via google search, and in a more learnable format than Python code. The most basic aspect of Western music theory overlooked here is the relationship between tonic and dominant. If you know the "home" chord aka "the I" aka "tonic" is C major, the dominant…

Just a note, it would be less ambiguous to say the chords are a 6 minor and 2 minor since minor 6th and minor 2nd are both intervals that don't relate to those chord qualities, for example the minor 2nd is a semitone above the tonic note, whereas a 2 minor chord (or ii, since lowercase represents minor chords in roman numeral chordal analysis) starts a whole tone above the tonic. Also, I think you mean the iii chord, since the ii chord is much less common. But by that measure you may as well be teaching the bVII (flat 7 dominant), which shows up all over the place in popular music (https://www.hooktheory.com/theorytab/common-chord-progressio...). That said, I agree chordal analysis is quite useful as a beginning point, but mostly for teaching the instruments that, well... play chords.

Re: Basic Music Theory in ~200 Lines of Python

#150

Earlier quoted context omitted.

> usually those integer multiples will be present as well "usually", under what probability model? A random 3d or 2d shape will have zero harmonic partials with probability 1. What is hard to achieve is having even a few harmonic partials. A rectangular wooden piece is painstakingly carved to have a couple of harmonic partials, in order to become a xylophone or marimba bar.

Yes, but shapes are not usually random. Bars, cylinders, cubes, rectangles, squares and circles are everywhere. That does not mean that they will have a string like attenuation curve for those higher harmonics, but they'll be there.

> Yes, but shapes are not usually random. Bars, cylinders, cubes, rectangles, squares and circles are everywhere.

While there are some exceptions, this is skewed in the modern industrial world. If we're making evolutionary scale arguments about sound perception it's a much tougher sell.

Post reply on HN