Chords

Vertical Sonorities

Our plan for today:

I'm just going to set up install music21 and musescore before I forget...

How Humdrum Looks at Harmony

These all work quite well.

You can also just parse the kern files in Python, if they're separated consistently. For example, you could parse it as:

for each line:
    for each column in that line:
      process something.

But you would have to write all of the things to parse out what it means to be a triad, interval vectors, etc.

Thankfully, people have already done that for us.

How music21 Looks at Harmony

It requires a bit more time to parse the files (you can use the chordify function to reduce), but it has a bit more functionality, overall.

For eaxample, you can get:

Chordify

The chordify function can reduce the harmony to an object that can be more easily analyzed.

Annotating with Chordify:

The loop below (from the music21 User Guide) shows how you can annotate the interval of the piece:

A similar loop can show all of the labels:

Roman Numerals

In order to get Roman numerals, you need to give it the key first. In the example below, you can manually input the key and the chord spelling.

Getting all the chords in a Bach Chorale

The code below can get the chord quality of every chord in a chorale.

Exercise

How might we get all Roman numerals in all Bach Chorales?

Annotating a Score

It's not entirely clear how helpful such an annotation would be, though...

Wednesday

Today we will:

But how often are we getting certain types of transitions?

While Loops

So what was the while functionality in that last bit of code?

There are a number of steps here that might be of interest:

  1. Starts a counter at 0
  2. Says that while the counter is less than the length of the list - 1 (it's one less than the list so it doesn't run over the range of the list)
  3. create a variable that is the chord your looking at, as well as the next chord.
  4. then add one to the counter.

It will repeat this until it gets to the length of the variable (-1).

i= 0
while(i< len(chord_qualities)-1):
    roman_numerals = f'{chord_qualities[i]} --> {chord_qualities[i+1]}'
    bi_gram.append(roman_numerals)
    i=i+1

Here is a basic example of a while loop:

You can also add break statements, to exit out of the loop when needed:

And you can go the other way too...

On Monday, we looked at the below code that returned the Roman numerals of a chorale (I've changed it a little bit to create an array, and not a print statement.)

Let's try to get the same type of table, but with Roman numerals. It might be worth considering a function for this. Perhaps a "make_bigram_table" function or something.

Exercise:

What if I just want roman numerals from downbeats? How would I find that?

Recall that we used this beatStrength function a couple of weeks ago...

for n in littleMelody.flat.notes:
    if n.beatStrength == 1:
      n.show()