Basic Music Theory in ~200 Lines of Python
11–20 of 192 posts
Re: Basic Music Theory in ~200 Lines of Python
#12> 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…
Oddly, for me it was the opposite! I used to be confused on why modes required modifying certain notes from a major scale until I tried deriving them in the way shown in the article. Of course, once you understand that, the way you go about memorizing and practicing is probably easier the way you described; that is, deriving modes in any given key by modifying notes of the major scale using the circle of fifths.
But why though? If you're improvising on a dominant (e.g. a G7 in the key of C Major) with a G Mixolydian scale, you're actually not playing a Mixolydian sound, but Ionian, since your tonal center is C Ionian. It is true, it is indeed a G Mixolydian scale and it is using the tonal contents of our key C Ionian. But our frame is Ionian, so what is the purpose of adding Mixolydian other than ease of construction of the scale?
Re: Basic Music Theory in ~200 Lines of Python
#13Re: Basic Music Theory in ~200 Lines of Python
#14This 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…
Unfortunately the momentum that Western music notation has, with a few centuries of tradition behind it, means one has to work within that system.
There was an interesting discussion I came across on Stack Exchange while writing the article: https://music.stackexchange.com/questions/67730/why-have-sha...
Re: Basic Music Theory in ~200 Lines of Python
#15This 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…
Of course, for every rule there are exceptions, e.g. we have things like (F Bb C) -> (F# B C#)
Re: Basic Music Theory in ~200 Lines of Python
#16This 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…
Agreed. The patterns are the most interesting bits. Actually, just the fact that there exist patterns is pretty amazing. It's unfortunately hard to see them through the notation and that made it very unintuitive for me for the longest time. Unfortunately the momentum that Western music notation has, with a few centuries of tradition behind it, means one has to work within that system. There was an interesting discuss…
How so? If patterns didn't exist, it would just be random choices.
Any non-random music making (and thus theory) requires patterns.
Re: Basic Music Theory in ~200 Lines of Python
#17(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.
Re: Basic Music Theory in ~200 Lines of Python
#18Earlier quoted context omitted.
You might want to try Sonic Pi, which pairs Ruby with the SuperCollider synthesizer engine: https://sonic-pi.net/
It will work in Sonic Pi, but I’m looking at ways to make the voice leading of chords more intelligent. At the moment it will voice chords in root position unless you specify otherwise. I’m also looking at writing a parser so the chord symbols can be written naturally as a string Edit: I’m on the Sonic Pi core team. I mean that I’m looking to add these features to sonic pi soon
The question isn't can you do it - because you can, with varying degrees of difficulty.
The question is what specific user problem you're trying to solve.
Re: Basic Music Theory in ~200 Lines of Python
#19 # Assuming note values are of Jazz style.. i.e, '1', 'b3', '#5', or '♭3' with unicode-sub after
jazzAllFlats = ['1','b2','2','b3','3','4','b5','5','b6','6','b7','7']
sharpStrs = ['#','♯']
flatStrs = ['b','♭']
accidentalStrs = sharpStrs + flatStrs
def stripAccidentals(note:str) -> str:
return ''.join([c for c in note if not c in accidentalStrs])
def jazzToDist(jazz:str) -> int:
dist = 0
degree = int(stripAccidentals(jazz))
while degree > 7:
dist += 12
degree -= 7
dist += jazzAllFlats.index(str(degree))
for c in jazz:
if c in sharpStrs:
dist += 1
elif c in flatStrs:
dist -= 1
#Here you could add support for double sharps and double flats if you want.. although unlikely as font support for these glyphs is horrible overall.
else:
break
return dist
print(jazzToDist('bb3')) # returns 2
print(jazzToDist('1')) # returns 0
print(jazzToDist('♭♭♭♭♭♭44')) # returns 68
print(jazzToDist('2')) # This one is strange as it's the only one where input == output
I started making stuff more like this as it just saves a lot of trouble in the long run. Once you have things made generic like these it's easier to think about going into ways that are not Jazz/Dist (which is semitone distance, or set notation), like Keys for example.. because it turns out the logic for that is really similar to what is in the jazz.The shape of the jazz system is the same shape as a change in the key of C. You would just separate the accidental part of the note's name like I did and look up let's say the index in all keys, giving you distance from C instead of what I showed there which is like distance from what is called 1 in Jazz.
So yes I prefer to make helper functions like this that actually kind of "get it" about what the languages/ways like Jazz or note names are actually saying.. then you can go one to another, or different keys really easily. If interested in more of my "Way Of Change" algorithms I can share.
I think your article is cool and I could comment more.. maybe if you want you could read my repo I could pm it to you. But it's long. In the meantime I have a new website using some of this type of logic. unfortunately js instead of python (where my bigger codebase resides).
Google thinks this site is a security threat and I literally posted it two days ago but it's got all scales/chords etc, and other stuff. Still in prototype phase. https://edrihan.neocities.org/wayofchange%20v14.html
Re: Basic Music Theory in ~200 Lines of Python
#20I've worked on music theory coding for a while. I originally used a dict-lookup style like you have done, but found a simpler way (for me). The problem with that approach is you have to maintain values for enharmonics of note names. It's hardwired. Also what if you gave it something like ♭♭♭♭♭♭44? Why shouldn't it "theoretically" be able to handle that. It is "theory" after all. I use something like this to convert t…