Live data from Hacker News

Basic Music Theory in ~200 Lines of Python

mvanga.com

151–160 of 192 posts

Re: Basic Music Theory in ~200 Lines of Python

#151

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,…

> Just a note

This made me smile.

Re: Basic Music Theory in ~200 Lines of Python

#152

Earlier quoted context omitted.

I appreciate most of your points and I appreciate the conciseness of the stave notation for example. But ... A B C D E F G. Seven notes in the scale, seven letters. Seven positions on the staff. Thats fine as long as you're in C Major. As soon as you depart from C Major it all starts going wonky. Why is C Major baked into the notation as if you'd never want to use anything else?

> Thats fine as long as you're in C Major. As soon as you depart from C Major it all starts going wonky. Why is C Major baked into the notation as if you'd never want to use anything else? Actually, it works for every major scale and natural minor scale! What are the notes in E major? E F# G# A B C# D# E. It's still the same letters, E F G A B C D. Now, you may think that this is CHEATING because I've added sharps. B…

So if you pretend that the sharps arent there and that they dont make any difference to anything then its all simple?

Re: Basic Music Theory in ~200 Lines of Python

#154
We need more "Explain things like I'm a programmer" explanations.

I've tried to grok music theory several times. I've never understood the scale/notes, notations. The 2nd array (with sharps and flats) and couple paragraphs made it "click" instantly. Because it was in a language and presentation I understand.

Re: Basic Music Theory in ~200 Lines of Python

#155

Earlier quoted context omitted.

The notation OP is using is relative to the key of your song. So if your key is C major, the V chord is G. However, if your key is F major, the V chord is Bb. So it's not that there's only a few chords used in popular music, it's that there's a very consonant group of chords for any key your choose. Also, OP is leaving out lots of ways to modulate these basic chords into more complex ones (adding a seventh step, inve…

Any suggestions about theory learning beyond this? Something that would help with composition perhaps? Music phrasing? Some book to read? Something for self learning? I wish that melodies I am trying to compose would be better in reflecting what I like in music, and I whish to figure out what is missing. I can improvise with different chords but it is getting boring and once I try to do something more comlex it doesn…

I don't have any specific recommendations and am quite rusty - but years ago when I was similarly interested I just looked up a decent undergraduate music programs course requirements and got their intro harmony text followed by intro comp text; learned a lot from that.

Re: Basic Music Theory in ~200 Lines of Python

#156

Earlier quoted context omitted.

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).

A fair bit of early music composition is weighted by what is easily sung, more than anything else.

Re: Basic Music Theory in ~200 Lines of Python

#157

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,…

> 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).

Here's the thing though -- a "what is this syntax" guide does not imply that you need a formalism of the syntax. What the person is asking for, in my opinion, is a linkage between the symbols and the concepts.

For example, when reading mathematics, often the problem was not my conceptual understanding of the material, but merely that I was not sure how to parse the symbols and map them to what it was doing. I could read a formula, but the mapping of each component piece as a shorthand was not there. At the time I did not internalize that "square root" is literally just getting the side of a square (A somewhat silly, obvious-in-retrospect idea! But it gives you a perfect example of the kind of mapping I'm talking about) -- because of this I wasn't able to get an idea of what it was doing!

In such a case, your formalism would not have worked, because it's simply a grammar. I did not need the grammar -- examples can show that, wikipedia can show that, what I needed was enough information about the link between the symbolic, and the conceptual, that I could find reference material. What I found instead was either as you put down, literal grammars, or vast tomes of knowledge that required more vast tomes of knowledge to read and figure out what each one in turn was saying. So I would get lost down this rabbit hole.

What the solution to this is, again IMHO, is a listing of syntax, yes, but with a conceptual mapping on the right.

So not saying things that we already know -- like "this is a number", but having a construction of an IF statement, and then a conceptual mapping on the right in the form of written description of how it works, or a visual description like a flow chart.

The point of writing was to convey knowledge, it is possible to convey intuition, and yet in scientific fields we seem adverse to doing so! It's treated almost like an unspoken thing, it is covered in passing, but almost never explicitly. It's why much of "intermediate programming" is difficult to break into, in my opinion -- and the same for mathematics (3blue1brown is breaking this up, however)

Re: Basic Music Theory in ~200 Lines of Python

#158
I haven't found an introduction to music theory that makes sense to me.

I vaguely understand that complications arise because we want nice harmonics, ie frequencies whose ratio is a "nice" rational number, such as 2/3 or 3/5 or so.

But our chosen notes should be invariant under doubling of frequencies ("shifting by an octave"), because that's basically the same note.

The problem then is that roots of 2 are irrational, that is, one cannot find (p/q)^2 = 2, or (p/q)^n = 2, or even (p/q)^n = 2^m. Therefore, one cannot find a "nice" interval that, applied several times, wraps around to an octave (or multiple octaves).

However, in a neat coincidence, (3/2)^12 = 129.7463378906... which is close to 2^7 = 128. So, based on that ("Pythagorean comma"), something something something, and we end up with 12 half notes that are basically of frequency f_i = f_0 * 2^(i/12), which are all horribly irrational, but apparently sound "nice" enough, largely (because they are close enough to some "nice" fractions), but only if we pick out some specific 7 of them.

And then the question becomes, which 7 of the 12 do we pick, approximately uniformly distributed. (Why not 6? Every second? I don't know.)

And then, you can transpose them somehow (ie multiply frequencies by 2^(j/12) for some j, but then you change the names for some reason, and everything gets complicated and tonic and Mixolidian double-sharp.

Also, instead of frequencies of the form f_i = f_0 * 2^(i/12) (which, clearly, have the advantage that any multiplication by a power of 2^(1/12) is just a shifting of the index i), you could also use non-equal tuning, with the powers of the 12th root of 2 replaced by some "nice" fraction, which means that any shifting then subtly changes the character of everything, I assume.

This is complicated, admittedly, but for me the nomenclature obscures, rather than elucidates, the issue.

ETA: I sympathise with what irrational wrote: "Is this what it is like when I talk to people who don’t know anything about programming about my work? Pure gibberish?"

Re: Basic Music Theory in ~200 Lines of Python

#159
post #158

I haven't found an introduction to music theory that makes sense to me. I vaguely understand that complications arise because we want nice harmonics, ie frequencies whose ratio is a "nice" rational number, such as 2/3 or 3/5 or so. But our chosen notes should be invariant under doubling of frequencies ("shifting by an octave"), because that's basically the same note. The problem then is that roots of 2 are irrational…

If you're trying to learn music theory by thinking about the mathematical relationship between frequencies, you are severely overcomplicating things for yourself. I have a tendency to do the same thing.

What question are you trying to answer with what you just wrote?

Re: Basic Music Theory in ~200 Lines of Python

#160
Something I wish was more clear in music theory is just how much overlap exists between the various concepts. I think it suffers from having so many names for everything, the learning curve seems much steeper than it really is. Even in this article, much time is spent on the duplicate names of notes and intervals. As a fairly proficient self-taught guitarist, this intimidating perception of theory delayed my learning of it for easily 5-8 years.

For example, you may spend a while learning the major scale, and what can be done with it. Then you learn the minor scale, and it seems like a totally separate scale that sounds completely different. And after that you learn that there are five other scales (modes) to learn about! (Dorian, Phrygian, Lydian, Mixolydian, and Lochrian!). It can seem extremely overwhelming until you learn that they're all the same scale with different relative starting positions. Where major is [1,2,3,4,5,6,7], minor is [6,7,1,2,3,4,5], and the other modes are all the other permutations of starting positions.

My other gripe is that learning theory on piano puts a lot of bias on the notes themselves rather than the intervals. For example, the B major scale has 5 sharp notes (black keys) to remember whereas C major scale has none. These are pretty different shapes to remember. Learning these on guitar means taking the same exact shape and shifting it up a fret (so if you know one major scale, you know them all!). Not to say that guitar is the perfect instrument for learning this - folks will often learn scales as close to the 0th fret as possible, causing you to start on different strings and have slightly different patterns.

That being said, I wish there was a purely linear instrument (a piano with the black keys flattened?) for learning theory. The real magic comes from identifying the shapes and patterns, and how they're similar to each other. Like how major and mixolydian are identical except for one note, so it's very easy to modulate between them, or make a listener think they're in one mode when they're in another. Same with minor and phrygian. Being able to drop the baggage of "the second note of the B major scale is C# which is this black key here" and just focus on a floating set of intervals seems like it would make this all easier and less intimidating.

That all said, I still feel reasonably early in my theory journey. So maybe this is just my bias coming from guitar.

Post reply on HN