Rhythms

Presentation and Paper

Due in Week 6:

Working with Rhythms

Rhythmic Representation

In Kern Files (Humdrum)

As we've seen, kern files use reciprical notations to show rhythms. Whole notes are notated as "1", half notes as "2", etc.

Tuplets are a bit of a different matter. The handbook states that:

In general, the way to determine the kern equivalent of an arbitrary “tuplet” duration is to multiply the number of tuplets by the total duration which they occupy. If 7 notes of equal duration occupy the duration of a whole-note 1, then each septuplet is represented by the value 7 (i.e. 1 x 7). A more extreme example is 23 notes in the time of a doubly dotted quarter.

So an eighth note triplet, which occupies the space of a quarter note, would be notated with a "12", and quarter-note triplets, which take up two beats, would be notated with a 6.

In Music21

Metric Position

In Humdrum

There are also a number of tools that analyze the metric position of a note, so you can search for instances that happen on the downbeat, for example, or on beats 1 and 3. Humdrum uses a combination of two tools to do this (metpos and timebase).

In music21

In music21, there is a tool called beatstrength which will do it for you. See the example below.

Exercise 1: Searching the Polska Collection

Let's try to find out which scale degrees are the most common on downbeats in the Polish folksong collection.

We will first need to talk about getting scale degrees.

humdrum

In Humdrum, this is quite straightforward, as you simply use the deg tool. This requires a key signature already labeled in the piece, though.

music21

It's a bit more complicated in music21, but is also a little bit more flexible.

You first need to run a key-finding algorithm on the excerpt (we will talk about the specifics of key-finding algorithms next week).

Once you have the key, you create a list of pitches, and get the scale degree of each of those in reference to the home key.

Back to the exercise.

How can we get all of the scale degrees on downbeats in the entire polska corpus?

Return and Print

What's the difference between print and return in Python?

So far, our functions have just been printing things out for us to read, but it's important to realize that there is a big difference between print, which shows something for a human to read, and return, which passes the output of one part of code to another.

Using return changes the "control flow" of the program. Using print just shows you something in the console.

Counting All Downbeats

Here's a solution (adapted from Dr. Tan's code) that counts all of the downbeats, and then graphs the scale degree.

Testing a Hypothesis

H1: Are pieces in the Polish folksong corpus more "rhythmically complex" than another corpus? "Complex" is obviously a pretty loaded term, and it isn't really not something that can be formalized, but "variability" might be thought of as a proxy for complexity.

The normalized variability index (nPVI) has been used extensively over the past few years as a way of examining rhythmic variability in melodies. It's adapted from linguistics (Grabe and Low, 2003) looking at the rhythmic variability of speech. Patel and Daniele (2004) argued that the variability of melodies can be correlated with the composer's native language.

npvi

Let's break down how we might break this down into a function we could implement.

Getting Rhythmic Content

For the nPVI tool, we will need to strip all non-rhythmic data. This means getting rid of all metadata, pitch content, and barlines. Kern files look at rhythms reciprocally, in that a whole-note is a 1, and eighth-note is an 8, etc. We will first need to arrange those durations so that a lower number equals a shorter rhythm.

Here's a brief reciprocal rhythm function for that. Let's break this function down a bit.

The above loop that begins with "for i in x" focuses on dotted rhythms. It goes through that x list, and If there is no dot, then just turn i into a float, and put it in the list. The equation under the recip function basically says: if you find a dot, that means it's the rhythm plus half of that rhythm.

The nPVI equation.

Now that we have the data in this format, we can just run the nPVI equation on the melody. This is the nPVI equation, when fed the list from the recip_rhythm function. See Daniele and Patel (2004) for full explanation of it.

The nPVI rating is sum of the the distance between two successive onsets (dk-dk+1) divided by half of the sum of those. The absolute value fo this is multiplied by 100 over the degrees of freedom (the number of notes in the melody minus 1).