Generating guitar chords algorithmicallyPosted: July 19, 2012
A musician playing a guitar, or a related fretted instrument, forms musical chords by arranging up to four fingers on the instrument’s fretboard. The positions of the fingers dictate the musical pitch that is generated by each string. Strings can also be muted so that they do not produce any sound. For every common musical chord, there are several known frettings, or ways of playing that chord, and these frettings are available in databases such as chordbook.com. However, it would be interesting and useful to generate these frettings algorithmically.
This is a difficult computational problem. It amounts to choosing a subset of finger positions, and the number of subsets grows exponentially in the number of finger positions, of which there are hundreds. Fender Stratocasters typically have 6 strings, each of which may be left open, muted, or sounded in 21 different frets, for a total of 6*23 = 138 finger positions and 2^138 sets of finger positions.
However, there are also many constraints on which fingerings are valid. A fingering must only generate musical pitches that are actually in the desired chord, and in the Western musical temperament there are only 12 pitches to worry about. Also, many conceivable fingerings are impossible to play due to anatomical limitations of the human hand.
The problem of generating guitar chords algorithmically can be posed as a branch-and-bound problem, where each step involves adding one finger to a candidate fingering. This formulation limits the depth of the search to the number of fingers, which is typically four. The branching factor is the number of legal places to position each next finger, which, naively, is large. However musical and anatomical constraints make the effective branching factor much smaller.
Alternatively, using dynamic programming, integer linear programming, a constraint solver, or logic programming, may be feasible. I haven’t thought about these approaches as much.