How a computer finds guitar chord fingerings
Guitar Chord Fingerings answers a simple question: how do I play this chord? Type Am7, D/F# or C7#9 and you get the playable shapes on the first twelve frets, the most useful first, with fingers, notes on the staff, sound and a hand in 3D. It also works backwards: put a shape on the fretboard and it names the chord.
Chord books answer the same question with a page of hand-picked diagrams. A program has to earn that judgement. This is how it does it, step by step.
1. Reading the chord name
A chord symbol is a small language. Cmaj7, CM7 and CΔ7 are the same chord; C7#9 is not C7b9; in D/F# the part after the slash is the bass note, not part of the chord's name. The parser turns the text into three facts:
- the root:
C,F#,Bb; - the intervals above it: a major chord is 0, 4, 7 semitones;
m7is 0, 3, 7, 10;9adds 14; - the bass, if a slash asks for one.
It also decides how to spell the notes. In B major the third is D#, not Eb; in Fm the third is Ab, not G#. The site names notes and draws the staff by chord degree, so B shows B D# F# and its staff shows sharps.
2. Which notes must sound
A guitar has six strings, and a 13th chord has seven notes, so something has to give. Not all notes matter equally. The root, the third (or the suspended note), the seventh or sixth, an altered fifth, the highest extension and every altered extension define the sound. The perfect fifth and lower natural extensions are optional: guitarists leave them out all the time, and the chord still sounds like itself. A shape that drops a required tone is not offered; a shape that drops an optional one is offered with a small penalty.
3. Every playable shape
Then the program does what no book can: it tries all of them. For each string it considers "muted", "open" or a fret on the first twelve, and keeps combinations that:
- sound only chord tones, with the requested bass at the bottom;
- sound at least three strings;
- fit in a stretch of four frets for the fretting hand;
- mute at most one string in the middle of the shape, because muting inner strings while strumming is hard.
Most combinations die early: once a few strings are chosen, it is often clear that no hand could finish the shape, and the search does not go deeper.
4. Fitting a hand
A list of frets is not a fingering. For each surviving shape the program finds which finger presses which string: whether the index finger lays a barre across a fret, whether a small barre with another finger is needed, whether four fingers are enough at all. Some shapes that look fine on paper need five fingers and are dropped here. For the rest, the hand model estimates how hard the grip is: stretch, finger crossings, barres.
5. Ranking like a chord book
The hard part is the order. "Easiest first" is not quite what a guitarist expects; a guitarist expects the usual one first. For C that is x32010, not some easier-to-hold but odd shape higher up the neck.
The ranking adds up two kinds of cost. One is physical: the effort of the grip and how far up the neck it sits. The other is musical: a bass note that turns the chord into an inversion nobody asked for, missing or doubled tones, open strings in awkward places, extensions crowded into the low strings. Familiar shapes, the CAGED forms every guitarist knows, get a bonus, so movable barre chords appear in their familiar places.
There is also a library of curated shapes from the open-source chords-db project (MIT license), and its first shape for a chord gets a bonus too. I tried to remove the library and rely on the generator alone. On a set of 204 standard chord-book shapes, the generator alone puts the book's shape first 190 times; with the library, 204 out of 204. The 14 misses are telling: without the library, C7 starts with x35353 instead of the x32310 every book prints, and Fmaj7 with 132211 instead of xx3210. So the library stays until the generator can match it on its own.
The web version is a port of the same engine in my Android songbook, MySongbook. To keep them identical, a test compares the web version with data exported from the Kotlin code: 79 chord names, 3256 library shapes, 232 chords with their generated shapes and final order.
6. Naming a chord from a shape
The "Shape → chord" tab runs the idea backwards. Put x02010 on the fretboard and it answers Am7. Each note that sounds is tried as the root, combined with a vocabulary of chord qualities; the bass becomes a slash bass when it is not the root. A guess survives if every sounding note belongs to the chord and at most one defining tone is missing. The survivors are then checked the forward way: if the generator itself offers this very shape for a chord, and ranks it high, that is strong evidence for the name. A self-check keeps it honest: the first shapes the site offers for a set of chords must be named back as the same chords.
7. A hand in 3D
The 3D view shows a hand holding the shape. The pose is solved on the server: the position of the hand and five angles for each finger, found by least squares under physical conditions. Each fingertip presses its string at its fret and not its neighbour, nothing goes into the fretboard, sounding strings stay untouched, fingers do not pass through each other. Where the shape leaves freedom, the solver leans towards how real hands sit, using statistics (only averages and regressions) from motion-capture recordings of guitarists.
"Looks real" is hard to test, so there is a quality floor. A corpus of about 400 shapes, the three most common shapes for twelve roots and eleven qualities plus every shape someone sent feedback on, is solved and checked for physical problems after every change. A change may not add a new kind of problem, may not make any problem more frequent, and may not move the fingers of clean shapes. Feedback from the 3D dialog ("this finger is bent unnaturally") is treated as a bug report: reproduced, fixed, and added to the corpus.
What I learned
- Generate, then judge. Enumerating every shape is cheap; the knowledge is in the ranking.
- Musical rules beat clever maths. Required and optional tones, bass, doubling: the rules guitarists already follow did more than any tuning of weights.
- Keep the human-curated data until the algorithm proves it can do without it, on a test written in advance.
- Turn taste into tests. "The usual shape first" became 204 book shapes; "the hand looks real" became a quality floor that may only go up.