Live data from Hacker News

Basic Music Theory in ~200 Lines of Python

mvanga.com

51–60 of 192 posts

Re: Basic Music Theory in ~200 Lines of Python

#53
It can be tricky to deal with the intersection of music and programming. For example:

> The chromatic scale is the easiest scale possible

So far so good-- in both programming and music we're just stepping through the smallest values (half step for music, the integer "1" in programming). So "easy" definitely applies to both domains.

> We can generate a chromatic scale for any given key very easily

For programming, sure-- you just find your offset and go to town.

For music, however, this is a wrong warp. The chromatic scale is a special case of a symmetric scale which cannot be transposed. There's literally only one such scale-- each transposition brings you back to the same exact set of pitch classes.

Figuring out what it means to have a chromatic scale "for a given key" is advanced music theory. In fact, I can only think of a few places where that makes sense:

* studying the complex harmony of late-19th century Romantic music

* studying the choice of accidentals in chromatic passages of Bach, Beethoven, etc. to infer the implied harmony

Those are important things, but they are definitely advanced concepts.

Long story short for programming, the author moves logically from an array to stepping through an array. But in terms of music, they start with the simplest possible scale and then jump to a third year undergrad theory concept.

Re: Basic Music Theory in ~200 Lines of Python

#54

A perfect 5th is not the same as a diminished 6th unless we assume equal temperament tuning. Granted it is the dominant tuning, but it irks me when this is just silently assumed. Plenty of music around that is recorded using actual perfect intervals, so why muddy the waters?

Interesting. Do you have some reference or link where I can learn more?

Re: Basic Music Theory in ~200 Lines of Python

#55
post #17

There are maybe three aspects to music theory: (1) Theory of how things sound like: Tones, melodies, scales, chords, based on the frequencies of individual sounds. (2) How to name things. (3) How to handle the mess of naming things in Western music theory, where things have 12 different names, depending on which note you choose as the base. This post seems to focus on 3.

Here I was expecting you to say:

(1) Melody

(2) Harmony

(3) Rhythm

:-)

Re: Basic Music Theory in ~200 Lines of Python

#56

This is great but if we could go back in time and influence the naming conventions so that the 12 semitones were called A-L or just numbered 1 to 12, and if the intervals were named after the actual semitone distance (a 'fifth' is actually seven semitones) the whole thing would be soooo much less jargonny. With all that bumf removed, the patterns of the 'scales' and 'chords' would be foregrounded and thats the actual…

People have had this idea before but I've never seen a version of it that is better than our existing notation systems. Most of our music is diatonic, and we named the notes in our scale A B C D E F G. Seven notes in the scale, seven letters. Seven positions on the staff. Our harmonies are built on stacked thirds, and the stacked thirds line up perfectly on a staff. Line, line, line; or space, space, space. Three dot…

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?

Re: Basic Music Theory in ~200 Lines of Python

#57
post #54

A perfect 5th is not the same as a diminished 6th unless we assume equal temperament tuning. Granted it is the dominant tuning, but it irks me when this is just silently assumed. Plenty of music around that is recorded using actual perfect intervals, so why muddy the waters?

Interesting. Do you have some reference or link where I can learn more?

Here's some good background on equal temperament as explain by Howard Goodall on a BBC series about music:

https://www.youtube.com/watch?v=41g2fSYZ4Sc

Re: Basic Music Theory in ~200 Lines of Python

#58

Does any programmer suffer with music theory as well, just based on the fact that an exact thing could be called in many different ways, depends on its position, function..etc? my brain kind of cannot accept this fact and I struggle with it

Yes, but we have similar issues in programming. Is a list a hash? Is a hash a dictionary? Are these all arrays? Are arrays collections?

Of course, there is a right answer, and depending on the language, all of the above can be VERY different things. But they're also similar enough to be completely unintuitive... their distinctions take practice to master.

Likewise, in music there is a right time to call a note a flat, a right time to call it a sharp, and a right time to talk about intervals instead. They can all technically refer to the same thing, yet there is a proper word to be used in any given context.

It's all very confusing, until you start using those terms in their proper contexts on a regular basis. Just like in programming.

Some other examples:

"=" vs. "==" vs. "===" vs. ":" vs. "=>" vs. "~>"

"function_name first_parameter" vs. "function_name(first_parameter)" vs. "hash_name[key]" vs. "object.property_or_method"

"MethodName" vs. "methodName" vs. "method_name"

"function" vs. "method"

...none of these are intuitive. But we use them, we get used to them, and then they seem obvious and we wonder how we could have ever written these things differently.

I think the same goes for musical notations. I struggle with them heavily, but I'm far too casual of a guitar player to take the time and learn the language properly. It's tempting to say the problem is the complicated and confusing language of music, but I know the problem is my own unwillingness to put in the time.

Re: Basic Music Theory in ~200 Lines of Python

#59
post #47
post #44

> For historical reasons, there are no sharps or flats between the notes B/C, and E/F. Come on, that is not for "historical reasons", that is because those notes are only one semitone apart!

Different way of saying the same thing. "For historical reasons the notes B/C and E/F are one semitone apart."

But that is not for historical reasons, that is due to the universal mathematical properties of the intervals.

The names of the notes and scales are due to historical reasons, but a major third and a fourth is one semitone apart due to math, not history.

Re: Basic Music Theory in ~200 Lines of Python

#60

Does any programmer suffer with music theory as well, just based on the fact that an exact thing could be called in many different ways, depends on its position, function..etc? my brain kind of cannot accept this fact and I struggle with it

It's all about thinking in thirds. If you want an A chord it has to be A, C, E, in thirds. A major would be A, C#, E not A, Db, E because that breaks the rule of thirds.

Also, and most importantly, if you're playing an instrument like violin, C# and Db are not actually the same note. Since they happen in different contexts, and have different positions in whatever key they're in, they have different psychological roles and are actually played differently by the player.

If I'm not mistaken, a C# would be played slightly sharper, and a Db slightly flatter to fit the particular key.

Post reply on HN