Alfarebis

Musings on informatics, language, music...

Harmalysis: a tool for harmonic analysis

Harmalysis is a command line tool used for harmonic analysis based on the roman numeral notation system used for interpreting chords and chord sequences.


In harmonics, roman numerals are used as an abstract layer of chord sequences which can be useful for roman numeral analysis.

Harmalysis is a python module which can be used to analyse chord sequences. The input is a set of roman numerals representing chords. The output returns a record of information for each chord.

Suppose we have the following sample text file containing a sequence of roman numerals referring to the sequence of triads on the first, fourth, fifth and again the first note:

 $ cat example-harmalysis.txt
 I
 IV
 V
 I

In the default case, the key of C is selected, so that the sequence of roman numerals corresponds with the following chords: C, F, G and C.

If you take the first line of the sample file (using the head -1 filter which selects the first line) and pipe the output to the python harmalysis module, we get a record with musical information about the first chord, including the chord label and the chord pitches:

 $ cat example-harmalysis.txt | head -1 | python3 -m harmalysis
 (C major)  >   Current key: C major
  Tonicized key: None
  Intervallic construction: CM3P5
  Inversion: 0
  Chord label: C major
  Default function: tonic
  Chord pitches: ('C', 'E', 'G')
  Chord pitch classes: (0, 4, 7)
 (C major)  >

When running the script for the whole sample file, we get the same information for each of the four chords. The following sample run filters only the Chord label line for each chord record, thus showing the chord sequences for this piece of music in the key of C:

 $ cat example-harmalysis.txt | python3 -m harmalysis | grep 'Chord label:'
 Chord label: C major
 Chord label: F major
 Chord label: G major
 Chord label: C major

You could also add an extra filter, removing the Chord label text at the beginning of each output line:

 $ cat example-harmalysis.txt | python3 -m harmalysis |
 grep 'Chord label:' | sed 's/.*: //y' 
 C major
 F major
 G major
 C major

Things become more interesting, if we add the key in front of the first root chord.

 $ cat example-harmalysis-v2.txt
 C=>:I
 IV
 V
 I

In fact, the key of C is redundant, since harmalysis uses this key as default. But it becomes useful in the next part, where we transpose from C to another key.

Now we can write a script which changes the root chord, resulting in the transposition of the chord sequences for the selected root. In the following example we transpose the input file from C to the key of F and G respectively, so that we get the corresponding chord sequences:

 $ for i in F G; do
      echo  === $i;
      cat example-harmalysis-v2.txt |
      sed "s/^C/"$i"/" |
      python3 -m harmalysis |
      grep 'Chord label' |
      sed 's/.*: //'
   done
 === F
 F major
 Bb major
 C major
 F major
 === G
 G major
 C major
 D major
 G major

In fact, for each select key (F and G) we replace the C key in the input file, before using harmalysis on the modified input file. For the replacement, we simply use a sed script which replaces the letter C at the beginning of a line by the selected key.

Harmalysis in combination with some basic linux scripting for modifying the input and the output, can be a useful instrument for exploring chord sequences on the command line.

If you want to find out more about harmalysis, have a look at following documents:

Tags: music, harmony, chords, harmalysis