17 ms·
Basic Music Theory in ~200 Lines of Python
- sideshowb 5y agoAnyone wanting to take things back a step further to first principles may enjoy this (shameless plug - I wrote it) Deriving the piano keyboard from biological principles using clustering (Jupyter) https://fiftysevendegreesofrad.github.io/JupyterNotes/piano.html https://fiftysevendegreesofrad.github.io/JupyterNotes/piano....
- harperlee 5y ago> If you hear a sound of frequency f and others of frequency 2f, 3f, etc then there's a good chance these sounds come from the same object, due to the physical principle of resonance. And so our perception of sound evolved to reflect this... Wow that's interesting enough to share as a standalone post, so I took the liberty! Thanks for the link!
- enriquto 5y agoThe quoted sentence seems false to me. Most physical objects do not have naturally harmonic vibration spectra. The vibration modes are not integer multiples ofthe fundamental (except for a vibrating string). Only the finely tuned western instruments do. So this is a somewhat backwards argument.
- jacquesm 5y ago> Most physical objects do not have naturally harmonic vibration spectra. What is your basis for saying this? A large number of physical objects, solids as well as hollow can be approximated as systems of springs, surfaces and tensile elements, which all have some frequency response. It isn't rare at all for a physical system to have a very sharp resonant peak in its frequency response, to the point that you'll often find mechanisms to dampen that response so the structure will survive certain inputs.
- enriquto 5y agowhat you are describing is a graph. The laplacian spectrum of a graph is arbitrary.
- PEJOE 5y agoEvery rigid object has a fundamental frequency, regardless of whether you put it on a graph.
- enriquto 5y agoSure. But the other frequencies need not be integer multiples of the fundamental.
- jacquesm 5y agoThey 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.
- enriquto 5y ago> 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.
- jacquesm 5y agoYes, 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.
- kortex 5y agoYou have the causality backwards though. It isn't saying most objects emit quantized overtones. But if you hear quantized overtones, there's a very good chance they are from the same source. It's not just strings, either. Drum heads have varying degrees of quantized modes.
- OscarCunningham 5y agoThe code itself also contradicts that sentence. Notice that the first roughness graph doesn't have any local minima at rational numbers. It's only when the overtones are added to the notes (at integer multiples of the fundamental frequency) that the minima appear. So the code thinks that human ears don't detect integer multiples specifically, they just detect sounds whose overtones line up with each other.
- sideshowb 5y agoGood point, but our ears definitely do perceive the 2 to 1 ratio. Maybe that particular phenomenon is better analysed through the usual pschoacoustic approach of "at what point do we stop perceiving one sound and start perceiving two "?
- IggleSniggle 5y agoI don't think so. If a sound persists long enough to hear its continuation, then its partials are generally going to be harmonic. Non-resonant frequencies will have a tendency to dissipate very quickly, unless they are explicitly designed to warble between resonances (like a gong or similar).
- sideshowb 5y ago@harperlee no worries about the share, it's great to see the variety of responses on the other thread
- blagie 5y agoAs someone who might use these with kids: I think the problem with both of these is lack of, well, sound. To get things, people need to hear sounds, not just see note names and pictures.
- 867-5309 5y agoit could be argued that this is music theory, and therefore sound belongs to the realm of music practice
- protoman3000 5y ago> 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 major scale in a circle-of-fifths sorted way: Mixolydian: b7, Dorian: b7 b3, Aeolian: b7 b3 b6, ... You can see that the modes appear walking left on the circle of fifths or walking along fourths (or going "darker", as some prefer to say). Try this out when starting at e.g. C and you see the pattern immediately. Then take Lydian: #4 That's going right on the circle of fifths or going in fifths going "brighter". Also, tangential comment: My music and my life has changed profoundly when I found out how to use the Lydian mode. I can't explain it, but it is just exciting.
- mvanga 5y agoOddly, 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.
- protoman3000 5y ago> modes required modifying certain notes from a major scale 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?
- seanhunter 5y agoOne way to make that ordering work with Lydian is to start with Lydian and flatten one note each time. So say we start in C. C lydian, flatten the F# we have C Ionian, flatten the b we have C mixolydian, flatten the e we have C dorian, flatten the A we have C aeolian, flatten the d we have C phrygian, flatten the g we have C locrian Now we flatten the C (after all this is the next note in the cycle of fifths) and we have.... B lydian. And the whole thing starts again. In this way you can understand how all the modes and keys relate. You can do a similar thing with the other 3 similar modes of limited transposition in this order (melodic minor, harmonic minor and harmonic major). Have fun.
- whiddershins 5y ago“ For historical reasons, there are no sharps or flats between the notes B/C, and E/F.” Mmmm yes, and that’s also a bit confusing because it dodges around why the scale was and is 7 notes to begin with.
- xavriley 5y agoCoincidentally there are no commonly used scales or modes with two consecutive semitones. The semitone gaps are always spaced out. With 11 notes (excluding the octave), that only leaves 4 possibilities for a 7 note scale if you remove rotations. These correspond to major, harmonic minor, melodic minor and harmonic major. It’s easy to prove with pencil and paper concentrating on c to c
- boomlinde 5y ago> Coincidentally there are no commonly used scales or modes with two consecutive semitones. It's common in Bebop to add a passing tone to otherwise heptatonic scales. Consecutive semitones are also a common feature in blues.
- xavriley 5y agoThat’s true but in those cases they are passing tones. For examples in a bebop scale you don’t tend to arpeggiate using both the consecutive tones.
- boomlinde 5y ago> That’s true but in those cases they are passing tones. That may well be their main function, especially in bebop (it's not so certain in blues), but they're still considered as part of the scale. > For examples in a bebop scale you don’t tend to arpeggiate using both the consecutive tones. That's true for any non-chord tones. The intervals are still very common (in bebop you commonly simply walk the whole scale up and/or down in straight 8ths or 16ths, playing adding the passing tone for the chord tones to end up on the downbeats).
- 5y ago
- diegoperini 5y agoI wonder if there is a scripting environment where I describe a chord progression in one thread, a lead voice in another and run them simultaneously, written entirely in code as a single file (or 2 files for parts + 1 for importing those).
- reitzensteinm 5y agoYou might want to try Sonic Pi, which pairs Ruby with the SuperCollider synthesizer engine: https://sonic-pi.net/ https://sonic-pi.net/
- xavriley 5y agoIt 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
- TheOtherHobbes 5y agoThere are no simple algorithms, because solutions are style dependent, covering the range from parallel transposition of house chords to a full Baroque counterpoint solver, via pop, rock, and jazz theory. 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.
- ksm1717 5y agohttps://github.com/synestematic/kord https://github.com/synestematic/kord I don’t think this has “execution”/synthesis features, but it could at least provide the basis for this environment.
- codeulike 5y agoThis 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 actually interesting bit IMHO (the bit defined as 'formulas = {..}' in the article)
- mvanga 5y agoAgreed. 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 discussion I came across on Stack Exchange while writing the article: https://music.stackexchange.com/questions/67730/why-have-sharps-and-flats-instead-of-twelve-notes-with-distinct-names https://music.stackexchange.com/questions/67730/why-have-sha...
- coldtea 5y ago>Actually, just the fact that there exist patterns is pretty amazing. How so? If patterns didn't exist, it would just be random choices. Any non-random music making (and thus theory) requires patterns.
- codeulike 5y agore: the patterns, see discussion here https://news.ycombinator.com/item?id=26860627 https://news.ycombinator.com/item?id=26860627 and my comment here https://news.ycombinator.com/item?id=26861415 https://news.ycombinator.com/item?id=26861415
- protoman3000 5y agoI disagree, because with the way of writing it down we have a homomorphism, e.g. transpositions preserve relations between letters, e.g. (A D E) -> (Ab Db Eb), or (G C D) -> (G# C# D#). Of course, for every rule there are exceptions, e.g. we have things like (F Bb C) -> (F# B C#)
- fatiherikli 5y agolop
- sampo 5y agoThere 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.
- 867-5309 5y agomost disciplines, music included, have theory and practice. how things sound is an element of the latter, whereas why things sound the former. this article as the title atates is about music theory and does a pretty decent job IMO I would be delighted to see a follow up article that explores frequencies and harmonics while sticking with the code demonstrations and incorporating a simple tone generator for the practice side of things
- max_ 5y agoI once listened to a podcast where fourier transforms were used to generate sounds that otherwise don't exist.
- Jenz 5y ago> sounds that otherwise don’t exist. hmmm
- tobr 5y agoCould you maybe share which podcast? Generating “sounds that otherwise don’t exist” does not sound particularly remarkable taken at face value. It’s basically what any synthesizer or audio processor does, and Fourier transforms are also a very commonly used in audio processing.
- max_ 5y agoThis podcast. The episode of Joseph Fourier. https://www.bbc.co.uk/programmes/b00srz5b/episodes/downloads https://www.bbc.co.uk/programmes/b00srz5b/episodes/downloads What I meant by "sounds that otherwise don’t exist" are sounds that are too complex to be created by physical music instruments its easier to simulate them by computer.
- keymasta 5y agoI'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 https://edrihan.neocities.org/wayofchange%20v14.html
- williesleg 5y agoOh what a genius! Somebody wrote some code!
- deleted 5y ago[deleted]
- noisem4ker 5y agoPerhaps related: Haskell School of Music http://www.euterpea.com/haskell-school-of-music/ http://www.euterpea.com/haskell-school-of-music/
- dvfjsdhgfv 5y agoIt would be awesome to add short audio clips. I mean, the examples are correct and all, but it's like discussing painting or photography without a single picture.
- siltpotato 5y agoAs a musician, I’d say no. Sure, you don’t get the significance of “what is this Dorian thing” unless Scarborough Fair is playing, but nothing in the article really applies to hearing music.
- dvfjsdhgfv 5y ago> As a musician, I’d say no. Sure, you don’t get the significance of “what is this Dorian thing” unless Scarborough Fair is playing, but nothing in the article really applies to hearing music. I don't know what's with the current flagging/downvoting trends on HN, comments get dead before I can reply. That said, your view seems rather extreme. What would be the downside of illustrating at least some of the samples with audio clips?
- siltpotato 5y agoI didn't mean there was no downside, certainly not. Just that it didn't seem as needful to me.
- goto11 5y ago> 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!
- harry8 5y agoDifferent way of saying the same thing. "For historical reasons the notes B/C and E/F are one semitone apart."
- goto11 5y agoBut 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.
- deleted 5y ago[deleted]
- kaoD 5y agoWhat the article means is: we dont have 12 notes (A B C D E F G H I J K L). Instead, for historical reasons (the choice of CMaj/Amin as a reference due to the notation evolution from heptatonic scales) we have A B C D E F G and we annotate with accidentals but, since those are not evenly spaced, there are some missing "black keys" there. Also, what devnonymous says, which I agree with too (but that's another story...)
- devnonymous 5y agoThe idea of a semitone in Western classical music is historical not (just) tonal.
- goto11 5y agoTrue, but that does not mean you can just space notes in a scale randomly.
- algesten 5y agoA 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?
- mvanga 5y agoInteresting. Do you have some reference or link where I can learn more?
- mmcconnell1618 5y agoHere'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 https://www.youtube.com/watch?v=41g2fSYZ4Sc
- ebiester 5y agoYou basically can look up just intonation versus equal temperament for the basics. https://pages.mtu.edu/~suits/scales.html https://pages.mtu.edu/~suits/scales.html gives the mathematical answer but doesn't get into the history. A clause that says "assuming twelve-tone equal temperament" would be sufficient here, but you can really go down the rabbit hole if you start digging into scales (see microtonal), and your page is meant to be more basic.
- algesten 5y agoThe wikipedia page is pretty good https://en.wikipedia.org/wiki/Equal_temperament#Comparison_with_just_intonation https://en.wikipedia.org/wiki/Equal_temperament#Comparison_w... A fifth might even sound off key if you're very used to equal temperament (it's about 2 cents below an equal temperament). You know it by there being no or less "wobbling" between the tones. For listening tips, look for vocalist groups where there's "One Voice Per Part" (OVPP). Voces8, Vox Luminis, etc. When there's only one voice, you don't get the inherent wobbling happening when two instruments/voices play in unison. Not all genres are possible to have just (jazz chord colors would sound rubbish).
- 5y ago
- HorkHunter 5y agoDoes 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
- nickelcitymario 5y agoYes, 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.
- noman-land 5y agoIt'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.
- peterpostman 5y agoUnreadable code,considering the subject should have been written in either in c, c#, d, f or f#.
- madcaptenor 5y agoInteresting 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".
- seanhunter 5y agoJazz musicians (and brass players) generally prefer playing in flat keys (because of transposition making the reading easier) so while "sharp" has a more positive connotation in normal use, if you asked a tenor saxophone player to play something in F# or C# they would generally not be pleased :-)
- madcaptenor 5y agoI didn't think of that. My musical experience is on piano and voice (neither of which has a preference for sharp or flat keys) and I've played around with guitar a bit (which prefers sharp keys in standard tuning) so I tend to forget that some people like flat keys.
- goto11 5y agoI 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.
- jancsika 5y agoIt 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.
- DavidPiper 5y ago> Figuring out what it means to have a chromatic scale "for a given key" is advanced music theory Interesting... Do you have any links for learning more about this - maybe some analyses? My take on chromatic scales (in the context of this post) is that the very existence of a(n equally tempered 12 tone) chromatic scale is the axiom the OP is using but not stated - hence a comment further up/down about P5s not necessarily being equivalent to d6 in other tunings. My take on chromatic scales (outside the context of this post) is that there is only one, like there are only two whole-tone scales, etc, and that it wouldn't necessarily make sense to say "the E chromatic scale" - instead you'd say "playing a chromatic scale over an E major harmony" (for example). However, if there are cases where it's useful to be more specific I'd be really keen to go deeper.
- jancsika 5y ago> My take on chromatic scales (in the context of this post) is that the very existence of a(n equally tempered 12 tone) chromatic scale is the axiom the OP is using but not stated - hence a comment further up/down about P5s not necessarily being equivalent to d6 in other tunings. Ooh, good catch-- I completely left out tuning systems! But again-- the point of "basic" music theory is to simplify the practice of discussing music. In that context, the fundamental purpose of the chromatic scale is to introduce the complete set of note names, as well as the range of the piano pitches. This gives the student a full set from which to derive all other concepts like scales, keys, triads, and all the other fundaments of the common practice period. So again, if you start with a chromatic scale and then start talking about the differences in half-step intervals along it-- boom. Huge conceptual warp. Honestly, I don't know much about the intersection between symmetric scales and alternate tuning systems. Personally, it seems like it would be an incredibly esoteric niche, although I can imagine some funny musical jokes with the idea. :)
- dvh 5y agoNot a musician here but are scales really necessary? Why not just play any frequency I want?
- bazeblackwood 5y agoMusician here—strictly speaking, music itself isn't necessary. Armed with that knowledge, you should produce any combinations of sounds that please you.
- mhh__ 5y agoScales and Chords are broadly speaking just a way of neatly-ish categorizing sounds and moods. This is true of both most classical music and jazz, for example, but Jazz in particular has a very practical relationship with scales. One of the personality tests of an improviser is how you think about the music - do you think vertically (in the chord), horizontally (in the mode), for example.
- zild3d 5y ago> Why not just play any frequency I want? reply You're more than welcome to. If you try to discover what intervals between these random frequencies tend to be pleasing, or displeasing, you'll rediscover some of the intervals and scales covered above
- analog31 5y agoI'm a musician. For me, a great deal of the pleasure of being a musician is making fairly sophisticated, coherent music, with other musicians, in front of an audience. Scales are not strictly necessary, but are part of an apparatus of making music work in the way that I enjoy it. They are a technology.
- scpedicini 5y agoMost composers were musicians before that and a lot of instruments adhere to scales such as fretted instruments or percussive instruments like the piano. Using scales gives people a familiar territory in which to compose music and a western audience will already be culturally attuned to those sensibilities.
- 5y ago
- tomrod 5y agoI love this!
- calebm 5y agoI have some similar notes here: https://calebmadrigal.com/music-theory-notes/ https://calebmadrigal.com/music-theory-notes/. It's all about the ratios.
- muyanapar 5y agoLove this article, i really enjoyed reading the code and now i want to reproduce it.
- valdiorn 5y agoHi there - was wondering if you had come across my Pentatonic scale github repo by any chance? :) It's a very similar type of study, where I attempted to generate all possible pentatonic scales (within reason). https://github.com/ValdemarOrn/PentatonicScales https://github.com/ValdemarOrn/PentatonicScales
- WhompingWindows 5y agoAs 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 will be G major, aka the V chord. Add just the F major chord, and you'll know 1-4-5 in a "basic" key: C major. 1-4-5 is the simplest chord progression, you can play amazing grace, you are my sunshine, even The Beatles, you'll be rocking with 1-4-5. Next level, if you add in the minor 6 (a minor) and minor 2 (d minor), you realistically know 95% of the chords you'll ever hear in C major pieces. And on the piano, this is ALL white notes, so even someone with zero musical knowledge can "solo" over your chords by just plunking any white notes while you play these chords (kids LOVE LOVE this btw, highly recommend trying with a kiddo). I wouldn't consider double-sharps and double-flats "basic" music theory. They really aren't needed for beginners, since they're relegated to keys like C# major where you'll occasionally sharpen a note like E# (aka F) into E## (aka F#). I didn't run into these until around 5 years into my piano training, playing Chopin's F# major nocturne Op 15 No 2, there's a bunch of double sharps in that piece. In any case, don't worry about double-flats and double-sharps or the precise notes of various modes and scales. Just learn pieces you enjoy, preferably with a mentor or teacher who can suggest improvements based on their trained ear.
- irrational 5y agoHeh, I understood your first paragraph. I understood literally nothing in the following two paragraphs. Is this what it is like when I talk to people who don’t know anything about programming about my work? Pure gibberish?
- tarboreus 5y agoIs there a (really) accessible book on music theory that anyone would recommend?
- analog31 5y agoI'm going to go in a slightly different direction and recommend starting with a book on music history. There will probably be enough theory in there, as it's needed to explain many developments. And then, don't try to study it, but start out by just reading it as a narrative. Modern college textbook writers are doing a decent enough job of not focusing strictly on classical music. You could find out what your local university uses.
- geekster777 5y agoI've been finding Signal Music Studio[1] to be doing a good job of conveying theory with minimal notation and practical examples. E.g. less labeling of things and more "here's what folks like to use this construct for". Not quite a book, and maybe not as comprehensive as you're hoping. [1] https://www.youtube.com/playlist?list=PLTR7Cy9Sv285kV3pohsMtUg_O_50oDyoR https://www.youtube.com/playlist?list=PLTR7Cy9Sv285kV3pohsMt...
- delineator 5y agoThings 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.lua https://github.com/robmckinnon/pitfalls/blob/main/lib/ratios... And chords based on those ratios: https://github.com/robmckinnon/pitfalls/blob/main/lib/chords.lua 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 https://llllllll.co/t/pitfalls/37795
- adamnemecek 5y agoI've been working on an IDE for music composition and I like to think that I nailed the UI. Launching soon http://ngrid.io http://ngrid.io.
- pashariger 5y agoI 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!
- pohl 5y agoA 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
- starchild_3001 5y agoI thought this is very cute. Playing these as chords or arpeggios, then adding other features to put them together to form a melody or chord progression, then hearing the effects would be super cool.
- markc 5y agoOvertone is a music toolkit in Clojure. One of its source modules similarly captures music theory: https://github.com/overtone/overtone/blob/master/src/overtone/music/pitch.clj https://github.com/overtone/overtone/blob/master/src/overton...
- njharman 5y agoWe 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.
- FabHK 5y agoI 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?"
- zarmin 5y agoIf 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?
- FabHK 5y agoI guess you're right. I was trying to understand why it's so complicated, and how one could express it in a simpler manner (that refers to the underlying reality, namely frequencies).
- geekster777 5y agoSomething 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.
- bdenckla 5y agoThis is a fun read but IMO it falls into the common trap of trying to formalize concepts in music theory based on a representation too close to traditional music notation. A notable consequence of this trap is that the author has to do a lot of distracting work to handle enharmonics, and yet still has arbitrary limits on number of flats and sharps. In other words, he has to do a lot of distracting work, and still all that work doesn't yield a general system. In my opinion (and experience) it is better to do a little work "up front" and "in the back" to convert to the line-of-fifths representation since that is more friendly to formalization. In other words you can take input in traditional musical notation and give output in traditional musical notation, but "in the middle," formalization should be done in the line-of-fifths representation. Above I have used "formalize" to mean something like "mathematicize" (if that's a word) or "be precise" or "be able to compute" or "be able to express in a programming language (like Python)". For example, I consider the line-of-fifths representation to be a good one in which to formalize music theory because in line-of-fifths representation, transposition can simply be formalized as integer addition, and integer addition needs no further explanation or formalization, i.e. it can be taken as sort of axiomatic. Here's another way of putting it: if you wanted to be able to add Roman numeral strings, would you write code that directly operated on the Roman numeral strings, or would you first convert to a compute-friendly representation like integers, and then do your adding from there? No doubt there are tradeoffs involved, but I tend to think that it is usually worth it to move to a compute-friendly representation, both with Roman numerals and music notation. An added benefit of line-of-fifths representation is it provides a good basis to formalize many important historical European tuning systems.
- vram22 5y agoApropos, some years ago I had written this blog post and Python program: Play the piano on your computer with Python: https://jugad2.blogspot.com/2013/04/play-piano-on-your-computer-with-python.html?m=0 https://jugad2.blogspot.com/2013/04/play-piano-on-your-compu... The post got some interesting comments with info about Western music theory, which I knew nothing about. And suggestions on how to improve the program to make calculation of note frequencies more accurate.
- ngcc_hk 5y agoNotation wise and officially it is a loop. But the tuning is a compromise. Hence some sounds are not harmonised that way using the current scale. There is a reason why well-tempered clavier tuning is still a bit of debate. You may have to tune fir some songs differently in those days. Hence assume all flat and sharp are equal is a bit too pure that might not exist n the real world.