I'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 things basically to an int (if we want to for some other function):
# 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
Thank you very much. I guess because I have not succeeded yet at some externalities in this lifetime the album isn't even properly distributed.. something to do with the cover and my procrastination at registering with SOCAN.. and my preoccupation with my music-coding project for several years. And lack of internet chops and social stuff and neuroatypicality perhaps.
But every once in a while I'll throw it on and be truly weirded out (in a weird/good[?] way). The album is kinda like getting your brain hit by a truck in space. In the future I would like to make stuff that is slightly less dense. And also more focused.
But ya I recorded, composed, produced, played most of the instruments on that piece and am hypothetically available for musical services. Of course peeps can use the wonders of the www and just get weirded out whenever, wow! For free! I guess that's why people like me get minimum wage jobs in kitchens!
Ya that album will always be a personal memento and all round strange banger. I'm glad you enjoyed it!
Most of the stuff on my youtube honestly borderline sucks. Different phase of idea.. more improv and raw.. but there's like 2 or 3 good ones. Then I quit youtubing like 6 months ago cause I had to go frame houses to pay my rent which put my hand out of commission for a while. If you like Lotus Helix maybe check out a more solo-project one I did last year on the youtube.
It's about where I was born, outside among trees and stuff. I was actually born in the middle of a place called Riverdale.. but not like the tv show but the real one by the river. The tune is called Edrihan - The Riverdalian. https://www.youtube.com/watch?v=E-XZx1DUGhM
Very nice! I like your way much better than the one in my writeup :-) I'll refactor things over the weekend to use this approach if that's OK with you.
That would be very cool! Maybe just give me a mention if that is cool, you can use the code verbatim (or changed) if you want. My name is Édrihan Lévesque. My book on music theory which isn't out is called Way Of Change.. which is what I refer to these algorithms by.
You might just realise how this approach goes back into keys.. like Ab, C#, F.. it's almost exactly the same, but you have to account for the accidentals being on the right side of the string as opposed the the left, as it is in Jazz.
And ya! - I actually originally wrote almost exactly what you wrote.. but I kept adding enharmonics of things.. like ['3','##2','b4','bbb5'] # and so on..
So I got to a point where it's like.. yeah this should just understand it. I'll give you another hint for the keys.. Use the scale degree to get your root note name. Get rid of the accidentals (do it after). Once you know that Major in dist == [0,2,4,5,7,9,11] you can use the list that contains all 12 notes in one spelling to find it. That's why I'm getting rid of accidentals. That way if you're looking for C# but you wrote as I did with all flat-spellings, it throws away the "#", finds the 'C', counts from there, and finally adds the sharp back if necessary. Just kinda paying attention to adding a flat to a note with a sharp.. they cancel out etc. Usually that's why it makes sense to keep the degree part separate from the accidentals part in some way. At the end you reconcile a difference between distance and degree-distance. Really easy to do double sharps or flats that way cause you know that all valid note names will work.. don't have to worry about giving it a particular format.
Not only can you use any names notes may have, but you can specify an odd rule.. like for example the difference between looking at the scale in "Western" vs. "Indian". Let's say a scale like Mela Vanaspati/Raga Bhanumati/Zaptian (number 1129 on my site). If it's Zaptian, then let's say we're Western. I'd say it's spelled like the first line following this. If it's a Raga or Mela and we're looking at it that way then even in Jazz we can correctly see it how it's originally stated as the second spelling.
1 b2 2 4 5 6 b7
1 b2 bb3 4 5 6 b7
For me in this case the Indian numbers make sense as you are just counting up integers.. albeit with the "ugly" double flat. And yes it's ugly unless you were using a system that doesn't express it as uglily. Here I'm just comparing the first three notes in a few ways. Let's say for a bb3 a system that would express that less ugly than some would be in the key of C#.. as in [1 b2 bb3] == [C# D Eb] == [Db Ebb Fbb]. Of course all these can be described as [S R1 G1]. This is how it's notated in Indian.. but equivilent to Jazz in that there is a part that talks of which nth note of the change and a part that talks about how far from where it usually is. Obviously C# is better for this change than Db. Even if you use the Western Jazz to derive it it's not good unless in C#. Of course the Western jazz statement to me is more ugly because it doesn't count up in degrees sensibly from 1 through 7. The ugliness of the jazz numbers is equal to the ugliness of putting it in the key of C, like I said before. On other changes Jazz wins because Indian won't let you use #4 or b5.
I'm glad you'll use my codes too. Eventually once you have it working you can do a scale in the key of like... let's say Abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.. which is actually also known as C or even B#.. ok stay sharp out there in code land. ;) Music theory is an obsession of mine and fun with codes. There are always many options. There's more than one correct answer. And there are ones that make less sense than others.
And P.S. to anyone just dropping in.. we're lazy so we type b instead of ♭, and # instead of ♯. The former is pronounced flat, is equal to the number -1 and is pronounced double-flat if there are two. The latter is pronounced sharp, is equal to +1 and same rule applies about not pronouncing something like "sharp sharp" in music ever. This way I can pronounce C septuple-sharp, which I made up. That particular strange way to describe a note is equivalent to G because music is weird like that. Also if something has six sharps then you could just as easily say it has six flats. So B♭♭♭♭♭♭ is the same note as B♯♯♯♯♯♯. And yes those are the very sexy-sounding sextuple type words ;)
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