[HN Gopher] How Chordcat works - a chord naming algorithm
       ___________________________________________________________________
        
       How Chordcat works - a chord naming algorithm
        
       Author : lapnect
       Score  : 94 points
       Date   : 2024-11-11 12:02 UTC (10 hours ago)
        
 (HTM) web link (blog.s20n.dev)
 (TXT) w3m dump (blog.s20n.dev)
        
       | parpfish wrote:
       | I don't think that this algorithm can handle slash chords like
       | G/C (G over C) and would instead label it as Gsus4. The former
       | gives a lot of important context to voicing which can by
       | important if you need a particular sort of motion in the bass
       | line.
       | 
       | My hunch is that any algorithm that analyzes chords in isolation
       | (and not in the context of other chords in the song) is going to
       | miss out on overall readability. Good chord notation has a sort
       | of elegance that can highlight the similarities/differences
       | between sequential chords that can make things very intuitive for
       | the musician
        
         | seanhunter wrote:
         | Yes.[1] In particular your point about analyzing chords in
         | isolation is spot on.
         | 
         | In "An Introduction to Musical Analysis"[2], Nicholas Cook says
         | something that I have always considered very profound and
         | applies widely, not just in music, which is                  >
         | All notation is analysis
         | 
         | So whenever you write something down in music you are (of
         | course) making some simplifications and you are also doing it
         | for a particular purpose. Usually the purpose is performance.
         | So when you write something you are providing an instruction to
         | the performer.
         | 
         | So when you write Cma7 for a jazzer, that's an instruction that
         | you are generally in the major tonal area and they may well
         | play a Cma9 or a Cma7#11 for example. This is why my functional
         | harmony teacher used to get annoyed by people writing the
         | "Crosstown Traffic"/"Purple Haze" Hendrix chord as E7#9 (which
         | you see a lot). He would say it is E7b10 because that g natural
         | is coming from the minor modes so it's actually the fourth
         | degree which has been flattened. If you call it a #9 you're
         | telling players the wrong scale for improvisation (pretty much
         | everyone else in the whole world calls it E7#9 though).
         | 
         | Likewise going back to your point about slash chords, a lot of
         | people learning this stuff get hung up on "what is this slash
         | chord really?" (Eg if I've got B/C or whatever what actually is
         | that) whereas when I've talked to really serious musicians in
         | that world who play that kind of intense modal music they
         | really are thinking about what the slash chords are in terms of
         | where they come from and what they are leading to. Because that
         | gives a sense for what the underlying tonality is. You can't
         | get it just from the notes of the chord vertically in that one
         | instant.
         | 
         | If you look at baroque music and earlier, if you just do a
         | vertical chord analysis (eg something like Gesualdo if you
         | really want an extreme example) the chords make absolutely no
         | sense in many cases but that's because they work in terms of
         | voice leading (ie context) rather than vertical relationships.
         | Analysts used to call that feature "vertical false relations"
         | because they found the vertical chord analysis troubling.
         | 
         | [1] ex-professional musician with a degree and postgrad in
         | jazz, contemporary and popular music here. Wife is a
         | professional musician who teaches at a couple of conservatoires
         | and mostly plays baroque and early music with some 20th and
         | 21st C music thrown in for good measure. Lots of pro musician
         | friends. Not trying to argue purely from authority but I do
         | talk music a lot with people who know a lot, and this topic
         | comes up a lot.
         | 
         | [2] Which stands out as a great book in a field with lots of
         | terrible books btw.
        
           | anentropic wrote:
           | > This is why my functional harmony teacher used to get
           | annoyed by people writing the "Crosstown Traffic"/"Purple
           | Haze" Hendrix chord as E7#9 (which you see a lot). He would
           | say it is E7b10 because that g natural is coming from the
           | minor modes so it's actually the fourth degree which has been
           | flattened. If you call it a #9 you're telling players the
           | wrong scale for improvisation (pretty much everyone else in
           | the whole world calls it E7#9 though).
           | 
           | you mean the third degree I think?
           | 
           | at first I thought your teacher seems overly pedantic here,
           | but it does kinda make sense... I'm surprised I've never
           | heard anyone argue that before!
        
             | derriz wrote:
             | Yep! It's far more logical. This chord blends major and
             | minor so the obvious way to indicate this is by adding a
             | flattened 3rd.
        
           | madcaptenor wrote:
           | It looks like this book is called "A Guide to Musical
           | Analysis" (or does Cook have more than one such book?)
        
             | seanhunter wrote:
             | Maybe. Or my edition is old or something. He does have a
             | few books. "music, imagination and culture " is also
             | excellent
        
           | magicalhippo wrote:
           | > Because that gives a sense for what the underlying tonality
           | is. You can't get it just from the notes of the chord
           | vertically in that one instant.
           | 
           | I'm not at all into music theory and such, but your passage
           | just reminded me of what AlphaPhoenix mentioned in his latest
           | video[1], where he analyzed two frames from an experiment,
           | both with a piece of string stretched horizontally across the
           | screen.
           | 
           | They look identical, but they are not. One is a stationary
           | string and the other in an oscillating string which just
           | happens to be flat at that moment in time, but the pieces of
           | the string still carry momentum.
           | 
           | [1]: https://youtu.be/WCKt405t9V8?t=478
        
           | Sesse__ wrote:
           | All of this makes a lot of sense. But to add; a semi-
           | professional piano player I know once gave me a heuristic
           | that can help sometimes, namely "the lowest fifth contributes
           | the most to what the chord feels like". But you can still get
           | into discussions about whether something is, say, a Dm/F or
           | F6 (and I see a lot of tabs where I disagree which the
           | author's choice).
        
             | scrozier wrote:
             | (semi-professional piano player here) That's interesting.
             | I've never heard that...not even sure what "lowest fifth"
             | would mean. I would think that the root and the third
             | contribute the most, right? The fifth is sometimes even
             | omitted. I'm very curious how this might work. Do you have
             | any examples?
        
               | Sesse__ wrote:
               | I guess it means in the sound scape as a whole,
               | potentially including multiple instruments. But to keep
               | it to a single piano, e.g. if you play B3 D4 G4, then it
               | won't sound like a B chord (neither minor nor major)
               | because there's no fifth. Instead, you'll hear D5 as an
               | overtone of D4, and G4-D5 will be the lowest fifth that
               | you hear, so it is readily interpreted as G/B. If the
               | third were the most important, then this would have been
               | a Bm, which is pretty clearly isn't unless you add an F#
               | (or there is some other instrument in the mix that
               | provides one).
               | 
               | At least that's how I interpreted him :-)
        
           | ta2112 wrote:
           | > He would say it is E7b10 because that g natural is coming
           | from the minor modes so it's actually the fourth degree which
           | has been flattened.
           | 
           | I'm guessing you mean Emin7b10.
           | 
           | It's in interesting take, but a bit weird considering you
           | wouldn't stack the chord that way. You want to voice the G#
           | below the G, E G# D G, making a major 7 interval which sounds
           | good. If you instead voice it E G D G#, then the G to G# will
           | form a minor 9th which is pretty clashy, generally avoided,
           | and doesn't sound like the Hendrix chord anymore. Try it out,
           | tab (0 7 6 7 8 x) vs (0 7 5 7 9 x). This is a standard jazz
           | voicing rule of thumb, although I forget the name of it.
        
         | epcoa wrote:
         | > My hunch is that any algorithm that analyzes chords in
         | isolation (and not in the context of other chords in the song)
         | 
         | You can at least get much further by naming a key (what a key
         | is, is not etched in stone either, but there are some useful
         | enough definitions for most cases). That would be a bare
         | minimum for a useful algorithm though. Especially if your input
         | is just a set of notes.
        
           | tolciho wrote:
           | And then the key may be unclear, or musicians may differ as
           | to where they feel, say, modulations occur: "it clearly
           | modulates in measure six" "no, measure six is just a borrowed
           | chord and the real modulation is at the cadence in measure
           | eight" etc.
        
           | HelloNurse wrote:
           | Naming a key seems, at the very least, a better way to decide
           | the root note than counting accidentals; but which chords are
           | the preferred, common ones isn't completely clear-cut.
        
         | abeppu wrote:
         | I agree with you but I wonder if this algorithm could be
         | reworked to be an important part of a system of that considers
         | context.
         | 
         | Roughly, what if we consider x_i the sequence of latent chords,
         | and y_i the observed notes. If we reframe the accidental-based
         | sorting this uses to act like a likelihood function e.g. P(y_i
         | | x_i) ~= 1/exp(# accidentals), then we "only" need a
         | transition function P(x_i | x_i-1) which describes what chords
         | typically follow which preceding chords, and then we have an
         | HMM system for which we can do inference easily. You can also
         | imagine extending the order (number of preceding chords
         | regarded as context), or training some higher order latent
         | state z which might carry information about mood or genre and
         | what chord sequences are appropriate in context e.g. P(y) =
         | P(z_0) \Product P(z_i | x_i-1, z_i-1) P(x_i|z_i) P(y_i|x_i)
        
         | bonzini wrote:
         | Sometimes the context even includes the genre. A F/G might be
         | written G9sus4 on a jazz lead sheet or G11 for a pop song. The
         | latter is somewhat incorrect, since the 3rd is pretty important
         | in a G11 voicing.
         | 
         | Without other context I would say that you can probably label
         | G/C as Cmaj9 or even Cadd9, even though the E was not in the
         | original label, but to be sure you do need to check whether the
         | E is indeed okay instead of or in addition to the B.
        
           | dhosek wrote:
           | What's more functionally F[maj7]/G1 is functionally a G7
           | chord in that any place you see the one you can substitute
           | the other and the harmonic function remains the same.
           | 
           | [?]
           | 
           | 1. This chord and its relatives in other keys is my favorite
           | chord.
        
             | bonzini wrote:
             | Kind of since you don't have the B-F tritone. There is a
             | lot more instability, and the resolution to C is a lot
             | stronger, in G7 than in F/G or similar chords.
        
       | badlibrarian wrote:
       | "It is also important to know that chords are built on thirds."
       | 
       | Except for the ones built on seconds ("cluster chords"), fourths
       | ("quartal chords"), fifths ("quintal chords"), the chords that
       | make jazz work, and for obsessive/completists, polychords.
        
         | Ylpertnodi wrote:
         | Zappa used 2nds a lot, for his improvs. Allows a lot of freedom
         | to both major or minor or both.
        
           | pohl wrote:
           | See also the very recent "Symptom Of Life" by Willow Smith, a
           | cluster chord bonanza.
        
           | badlibrarian wrote:
           | I considered sending the first ten seconds of Clair de Lune
           | through this thing to see what nonsense it would spit out.
           | Tech people tinkering in the humanities (and vice versa) is
           | always good for fun.
        
             | scrozier wrote:
             | This is one of my favorite categories of HN posts. But hey,
             | if it engenders some interest in ______ (fill in arts
             | category), then it's all good.
        
         | andybak wrote:
         | I'm going out a limb here and saying "your ears interpret them
         | in terms of their relationship to thirds and everything else is
         | a fiction"
         | 
         | Although:
         | 
         | a) I have only given this a moment's thought and...
         | 
         | b) The term "fiction" here is relative as all music theory is a
         | fiction to some degree.
         | 
         | c) "Ears" here is short hand for a weird mixture of maths,
         | physics, brain structure and learned cultural expectations.
         | 
         | I'm kinda clutching at a valid idea here though - despite the
         | above flakiness.
        
           | klodolph wrote:
           | "Your ears interpret them in terms of their relationship to
           | thirds"
           | 
           | I don't really see a basis for this one. I think if we really
           | dig into it, the use of thirds is somewhat arbitrary and has
           | more of a historical basis to it than any other foundations
           | (rather than physical or physiological foundations).
           | 
           | Thirds really do fall apart when you start looking at quartal
           | harmony, tone clusters, and all sorts of modern harmony.
           | Thirds even get stretched to the limit in a lot of very
           | traditional, "safe" harmony. I think on some level, we are
           | just using thirds because of the mathematical coincidences in
           | our systems of harmony.
           | 
           | Cultural explanations are the biggest ones.
        
             | schwartzworld wrote:
             | It's not that arbitrary. A lot of what we define as
             | consonance comes from the harmonic series, the set of
             | overtones you can access by doubling, tripling, etc the
             | frequency of the fundamental tone. If you look at this
             | series, the third is the first interesting interval.
             | 
             | Fundamental - octave - fifth - octave - third - fifth -
             | flat 7
        
               | klodolph wrote:
               | The harmonic series really, really does not explain why
               | harmony comes in thirds.
               | 
               | The minor 7 is not in the harmonic series. It's just not
               | there. This is not a nitpick or a quibble--the minor 7 is
               | just a completely different interval, separate from the
               | just intonation 7:4 interval. To my ears, it is like
               | saying that red and yellow are the same color.
               | 
               | What about augmented or diminished chords? How do they
               | fit into this theory? What about, say, the 9? Why do we
               | put a 9 in a chord, and not a 2? Why do we like the b9?
               | Why do we use a #11?
               | 
               | There's a million little historical and cultural factors
               | going on here. You can come up with a sort of apologia to
               | explain why thirds make sense, but this doesn't mean that
               | thirds are in any sense fundamental in some physical or
               | physiological sense.
        
               | schwartzworld wrote:
               | If you look at the evolution of how music and harmony
               | progressed in western music, fifths were seen as
               | consonances, then later thirds. Minor 7ths weren't much
               | of a thing until like the 1400s. Augmented intervals were
               | still not really even used during the baroque.
               | 
               | You can discount the fundamentalness of thirds, but it's
               | there.
        
               | klodolph wrote:
               | That's a historical, cultural foundation for thirds--
               | exactly the point I am making.
        
       | kiaofz wrote:
       | Technically one of the points in the first example with the
       | different ways of describing C E G isn't quite right. C, while
       | enharmonically equivalent to B#, indicates a different function,
       | and potentially a different tonal center/tonic. This change is
       | tough though because it ~triples the number of note values you
       | can have I think.
        
         | bonzini wrote:
         | Also because when you add diminished chords you get lots of
         | double flats (for example C-E-G-B vs C-E-F#-A)
        
       | afandian wrote:
       | I built something like this in CLIPS at university. Would easily
       | suit Prolog too. When compared with the bookkeeping needed in
       | this example, it's a great demo of logic programming's strengths.
       | 
       | (If only I could find the code)
        
       | tiniuclx wrote:
       | Thanks a lot for posting this. I am working on Chord Chart Memo
       | [0] which is a tool for entering and transposing chord charts and
       | this algorithm might come in very handy for naming the chords
       | entered through the application.
       | 
       | What we're doing right now is essentially a hard-coded database
       | of chord names. Every single new chords requires a new entry into
       | this database, which currently makes adding chords with many
       | accidentals impractical. Your approach of tracking the
       | accidentals separately to the database of chords seems very
       | useful and it may allow me to add 'jazz chords' into the app!
       | 
       | [0] https://tiniuc.com/chord-chart-memo/
        
       | mjg2 wrote:
       | as a programmer and a classically trained pianist, this section:
       | 
       | > For example, the notes C, E and G (The C major chord) can have
       | any of the following names, based on what is considered to be the
       | root note.
       | 
       | > root note chord name
       | 
       | > C C Major
       | 
       | > E E Minor #5
       | 
       | > G G sus4 (13)
       | 
       | > (To the best of my knowledge, I'm no music theorist)
       | 
       | is disqualifying for any usefulness in this program-- it will
       | lead to more misguidance than clarity. without theory, there is
       | no reason.
       | 
       | i would analyze these inversion chords in the frame of the key of
       | C major: CM, C6, and C64 based on Figured Base Notation
       | https://en.wikipedia.org/wiki/Inversion_(music)#Figured_bass
        
         | recursive wrote:
         | Interesting.
         | 
         | Coming from a cover band/local small-time musician, C6 means
         | C-E-G-A. In other words, C with an added 6 on top.
         | 
         | The charts I play from generally don't have any inversion
         | information on them, and I probably play different inversions
         | each time.
        
           | epcoa wrote:
           | This is unfortunately one of the ambiguities in notation. But
           | usually not a problem because it should be quite clear when
           | figured bass is being used.
           | 
           | In jazz/pop notation inversions are indicated with slash
           | chords.
        
         | epcoa wrote:
         | For what it is worth it's not wrong to say that the triad where
         | E is the _root_ would be Em#5. The inversions you point out
         | still have the same root (C) even if the bass is different. But
         | I agree you've identified the fundamental problem: we cannot
         | infer the root note and, therefore the name (enharmonics
         | aside), from just a _set_ of notes and attempting to is a
         | fool's errand. Even with a root note, it 's going to be
         | difficult many times to have a sensible answer
         | 
         | The key problem with this implementation in addition to not
         | simply taking the root note as input (or a key or scale),
         | appears to be the chord database is pretty spartan, since it
         | doesn't appear it would identify C-E-G as anything other than
         | CMaj. If you want figured bass/slash notation then you'll need
         | to specify that as well (bass note).
         | 
         | A number of chord namers take these as additional inputs.
        
           | tunesmith wrote:
           | Em #5 would have a B#, not a C. This isn't a pedantic point;
           | it very much matters if we're trying to be accurate with
           | chord naming.
           | 
           | Another example to illustrate how identifying the root is
           | important: C E G A. It's either a C6 or an amin7.
        
       | ysofunny wrote:
       | way tangential
       | 
       | but why, oh why, does 12 but not 12*1 nor 6+6, not even 5+7 but
       | precisely as 2+2+1+2+2+2+1=12 is so important for music !?
       | 
       | how can we make a general object that describes such a "folded"
       | structure?
       | 
       | this strtucture arises naturally from repeating 3^1 all the way
       | to 3^12 and inserting the appropriate 2^n (where n is negative
       | integer) to keep all between 1 and 2 (or 2 and 4)
       | 
       | is 2212221 a group?
       | 
       | if we stop at 3^7 instead of going all the way to 12 we have a
       | diatonic major, if we stop after 5 iterations of multiplying 3*3
       | it's a pentatonic.
        
         | wrs wrote:
         | It's only so important for "Western" music. Other musical
         | traditions/cultures (including some from the "West") find other
         | scale patterns more important. Or they don't even use the
         | 12-tone division of the octave that this is working within.
        
         | mrob wrote:
         | Because that pattern forms a scale that allows for playing
         | several intervals such that the harmonics line up nicely, so
         | that they're either very similar or very distinct, but not
         | annoyingly almost similar. William Sethares has a good overview
         | here:
         | 
         | https://sethares.engr.wisc.edu/consemi.html
         | 
         | Note how figure 3 shows dissonance minima close to degrees 3,
         | 4, 5, and 6 of the major scale when played against degree 1.
         | Although there are many other possible combinations of notes,
         | combinations with degree 1 are very important because degree 1
         | provides a kind of "home" that the music often returns to (the
         | "tonic"). But the goal isn't just to maximize consonance, so
         | these notes alone would make for a boring scale. For better
         | musical value, we need some more dissonant intervals to build
         | tension before it can be resolved with the consonant intervals.
         | The obvious place to put them is in the big gaps. Putting
         | degree 2 a single semitone above degree 1 is probably overdoing
         | the dissonance a bit, but putting it two semitones higher gives
         | a useful mild dissonance. Considering only combinations with
         | degree 1, degree 7 could theoretically also go a single
         | semitone above degree 6, which gives the mixolydian scale, but
         | the major scale is more popular. I assume this is because of
         | combinations that don't involve degree 1.
        
           | ysofunny wrote:
           | I know his work well, I must rephrase my question
           | 
           | he answers why it works well, but I don't think he really
           | addresses why the "folding" pattern (as I called it) arises
           | 
           | I'm also looking at Erv Wilson's work (in the book by
           | Nakamura) and he gets closer to addressing what I'm focusing
           | on.
        
         | Phrodo_00 wrote:
         | It's pretty much historical, and initially based on the tastes
         | of medieval priests doing Gregorian chant. It started with the
         | handful of intervals they would use and more intervals were
         | added as needed when music grew more complex until we got to
         | similar-ish 12 intervals, which were then actually equally
         | spaced later.
        
       | wrs wrote:
       | As people are rightly pointing out, this is only ever going to be
       | a crude heuristic since it has no idea of the context. But in
       | that spirit, I suggest including the distance between the notes
       | as a factor. That would help with slash chords (E2 C4 G4 Bb4 ->
       | C7/E because the E is much lower) and extensions (distinguishing
       | a sus2 from an add9).
        
       | ks2048 wrote:
       | This problem is calling out for a real world test set to evaluate
       | the method. I would be surprised if such a dataset doesn't
       | already exist (eg in the MIR, music information retrieval,
       | community)
        
         | epcoa wrote:
         | The problem is not the testing. The problem statement is
         | flawed.
         | 
         | Chord naming is not particularly useful as simply a function
         | mapping a _set_ of undifferentiated notes to a name. The post
         | interestingly gets that the root note is important, but then
         | sort of misses the point in the end. You either have to specify
         | the root, or if the procedure is generating all combinations
         | then one needs to know the implied root in the output (and then
         | this of course leaves the hard bit of identifying what is the
         | correct root to elsewhere). As an example, an input of {A, C,
         | E, G} will spit out C6 and Am7. Which one it is, is the
         | important part. And these are both relatively common chords.
         | 
         | Looking at prior art you will see that chord namers either take
         | something like a key to infer the root, they take the root
         | explicitly, or they treat the notes as an ordered set, some
         | then improperly assume the first element is the root
         | (conflating root and bass). In a GUI that is super misleading.
         | 
         | https://muted.io/chord-identifier/
         | 
         | eg: If you put in E-G-C it identifies as Em#5. Which is a
         | completely false sense of "oneness" and would usually be
         | incorrect. In practice E-G-C played on the keyboard in pop
         | music is more likely a first inversion Cmaj chord, or C/E.
         | 
         | There are better tools out there (https://www.scales-
         | chords.com/), but the example above would be how not to do it.
         | This is not to dunk on it (or the post), but to motivate
         | thinking more about the problem.
         | 
         | In this case the posted algorithm won't identify Em#5, simply
         | because the database doesn't have an those entries. If you
         | scale the algorithm by augmenting the database with more
         | spellings then the output set is going to become larger without
         | being more useful. It will be technically correct, yes that
         | C-E-G might be a Csus44, a C, a Em#5, but what do I do with
         | that.
        
           | ks2048 wrote:
           | I think you're right, and other posts here point out that you
           | need context for this problem. A good dataset of the type I
           | was referring to, would take a score and simply remove the
           | chord labels and try to infer them for the whole piece.
        
       | xanderlewis wrote:
       | > (To the best of my knowledge, I'm no music theorist)
       | 
       | I know this is considered off-topic, but I've refrained a
       | thousand times and now I can't help it...
       | 
       | Please stop abusing commas! This sentence deserves a semicolon or
       | a dash or a hyphen or a couple of full stops/periods or...
       | anything else! With a comma it's actually harder to read and is
       | semantically indistinguishable from the sentence 'I'm no music
       | theorist, to the best of my knowledge', which is obviously not
       | what is meant.
       | 
       | </unpopular rant>
        
         | PittleyDunkin wrote:
         | > or a dash or a hyphen
         | 
         | Em-dashes are typically used for separating clauses. Hyphens
         | and en-dashes are used for hyphenating terms and indicating
         | ranges (among a couple of other uses).
         | 
         | Not that this really matters in practice, but the visual cue is
         | useful for reading rapidly and accurately
        
           | xanderlewis wrote:
           | Thank you -- I know. I think the usage varies (traditionally,
           | anyway) between British and American English anyway.
           | 
           | My point was that anything other than a comma would be
           | preferable.
        
       | ksr wrote:
       | Thanks, I'm curious to try this algorithm. I've been using
       | https://github.com/no-chris/chord-symbol for many years with much
       | success in my own iReal Pro to MusicXML converter
       | https://github.com/infojunkie/ireal-musicxml. The author mentions
       | that their source is "Standardized Chord Symbol Notation: A
       | Uniform System for the Music Profession" by Carl Brandt and
       | Clinton Roemer, published in 1976.
        
       | seancolsen wrote:
       | I have a similar project which is web-based:
       | 
       | https://octavecompass.com/
       | 
       | My chord naming algorithm works somewhat like the one described
       | here but is based on an intentionally more limited set of chords
       | which I've carefully curated here:
       | 
       | https://github.com/seancolsen/music-theory-data/blob/master/...
        
       | efortis wrote:
       | For teaching coding to musicians, I wrote a program the other way
       | around.
       | 
       | But it can help you understand how most chords are formed.
       | 
       | https://github.com/ericfortis/web-projects/blob/main/chord-m...
        
       ___________________________________________________________________
       (page generated 2024-11-11 23:00 UTC)