Live data from Hacker News

Basic Music Theory in ~200 Lines of Python

mvanga.com

121–130 of 192 posts

Re: Basic Music Theory in ~200 Lines of Python

#121

Unreadable code,considering the subject should have been written in either in c, c#, d, f or f#.

Interesting that there are no languages with "flat" names. I can think of two reasons: - the word "sharp" has more positive connotations - if you're limited to the keys on a usual keyboard "flat" would be denoted by "b".

I think it is just due to C# being a play on C++ (the # could be seen as ++ just rearranged to overlap). No doubt the positive connotations of "sharp" also played a role. Cb or C-flat neither looks or sound cool! That said, MS did have en experimental language called C-flat, but it was not intended for general purpose use (if I remember correctly), so the name might have been chosen as a joke.

F# is in turn named after C#, as it is the functional equivalent to C# in the framework.

Re: Basic Music Theory in ~200 Lines of Python

#122

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

I don't think this is really anything to do with music vs programming. The author just used the wrong words... it's pretty clear they meant "generate a chromatic scale starting at any note" ;) Thanks for bringing up the connection with symmetric scales -- these are really interesting!

If you want to go further down the rabbit hole of symmetrical scales, checkout Olivier Messiaen's modes of limited transposition https://en.wikipedia.org/wiki/Mode_of_limited_transposition. For a given set of pitches within an octave there are a limited number of times those pitches can be transposed before you wind up with the same set of pitches. And the modes in that scale must also be fewer in number than the number of pitches in the scale, meaning at least two modes of the scale must have the same interval spelling. The simplest example is the whole tone scale. Up a half step I get the same set of pitches, another half step and I get the same pitches I started with, so it is 'limited' to one transposition. And there is only one mode of the whole tone scale, since no matter where I start I always have the same set of intervals.

Re: Basic Music Theory in ~200 Lines of Python

#123
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.

Why is that mess necessary? Cant a semantically rich notation be devised to avoid that mess?.

To me, that’s like asking “why are inconsistencies in English necessary? can’t we all just learn Esperanto?” There’s hundreds of years worth of written music, hundreds of years worth of pedagogical material, and millions of people who simply will not “un-learn” the current tradition. Just like English, over the centuries, music notation evolves, but only just does that, evolves.

Re: Basic Music Theory in ~200 Lines of Python

#124

> Modes are essentially left-rotations of a scale. While true, I find this interpretation harmful to the understanding of modes. It didn't provide me with any insight and instead it seemed irregular to the other theoretical constructs we have and thus deterred and misled me in the beginning. To me, it all clicked when I took all the modes, except Lydian, and constructed them by putting down the augmentations to the m…

What made it click for me analyzing music, in particular rock songs like 'Gloria.' That song very strongly identifies E major as the tonic, but the D and A chords are not in E, they are diatonic to A major. To say it is in A major would mean the song's tonic would be A, but since it is E major it is more correct to say the song is in E Mixolydian.

Adam Neely recently did a great analysis of 'Hey Joe' that goes pretty deep into this stuff https://youtu.be/DVvmALPu5TU

Re: Basic Music Theory in ~200 Lines of Python

#125
I found this very helpful! As a self-taught musician, it filled some gaps in my music theory knowledge - especially being able to visualize computing scales, modes, and intervals as algorithms. I can now better evaluate these in my head when I encounter a key/scale that I haven't seen before! Thank you!

Re: Basic Music Theory in ~200 Lines of Python

#126
post #118

Earlier quoted context omitted.

Hmm, I guess someone should tell those people, like Like Tolgahan Çoğulu who are writing music in microtonal scales with 19, 24 or 31 notes in a scale, that their notes spacing is random. https://en.m.wikipedia.org/wiki/19_equal_temperament https://en.m.wikipedia.org/wiki/31_equal_temperament https://en.m.wikipedia.org/wiki/Arab_tone_system

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?

Re: Basic Music Theory in ~200 Lines of Python

#127
A fun idea for a function to implement: the negative harmony mapping, which is a note-by-note transformation that preserves some character of the note:

  R ⟷ 5 (stable)
  2 ⟷ 4 (unstable)
  3 ⟷ ♭3 (modal)
  7 ⟷ ♭6 (leading)
  6 ⟷♭7 (hollow)
  ♭2 ⟷ ♯4 (uncanny)

 [1] https://www.youtube.com/watch?v=et3CMn2oCsA
 [2] https://www.youtube.com/watch?v=SF8CdxcdJgw

Re: Basic Music Theory in ~200 Lines of Python

#128
Things get more fun when we explore musical tunings other than the 12 equal divisions of the octave (EDO) of Western music.

You can define interval structure as a sequence of large L, small s, and optionally medium M steps.

For example, the Major diatonic scale - a 7 note scale from 12 EDO - in Ls notation is:

   LLsLLLs with L: 2  s: 1 (12=2+2+1+2+2+2+1)
A 19 EDO, 7 note scale:

   LLsLLLs with L: 3  s: 2 (19=3+3+2+3+3+3+2)
And here's a 19 EDO scale with 9 notes (Godzilla-9):

   LLsLsLsLsLs with L: 3 s: 1 (19=3+3+1+3+1+3+1+3+1)
You can then explore frequency ratios beyond those available in 12 EDO: https://github.com/robmckinnon/pitfalls/blob/main/lib/ratios...

And chords based on those ratios: https://github.com/robmckinnon/pitfalls/blob/main/lib/chords...

The above links are Lua code files for a monome norns library for exploring microtonal tuning: https://llllllll.co/t/pitfalls/37795

Re: Basic Music Theory in ~200 Lines of Python

#129

Earlier quoted context omitted.

I don't think this is really anything to do with music vs programming. The author just used the wrong words... it's pretty clear they meant "generate a chromatic scale starting at any note" ;) Thanks for bringing up the connection with symmetric scales -- these are really interesting!

If you want to go further down the rabbit hole of symmetrical scales, checkout Olivier Messiaen's modes of limited transposition https://en.wikipedia.org/wiki/Mode_of_limited_transposition . For a given set of pitches within an octave there are a limited number of times those pitches can be transposed before you wind up with the same set of pitches. And the modes in that scale must also be fewer in number than the nu…

Shtaaap, you’re headed for the Totient Function! Collision immanent, abort, abort!

Re: Basic Music Theory in ~200 Lines of Python

#130

Earlier quoted context omitted.

They don't have to, but usually those integer multiples will be present as well. Whether they are dominant or not is another matter but it is quite hard to design something in such a way that if it has a natural resonance at a certain frequency that integer multiples will not be present in the response spectrum. A typical object will have multiple modes of resonance as well.

> 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.
Post reply on HN