Tutorial Sheet Music Advanced Part1: Search for a motif in Josquin's mass “La sol fa re mi”

(version 2022_01_03)

Table of contents:

  1. Search for a sequence of tones
  2. Search for all transpositions of a sequence
  3. Tasks

This tutorial explains how to use Music21 to search for a melodic motif in a piece and how to display the exact positions of the instances (voice, measure, beat).

As always, you first start the program and load the piece to be analyzed under a freely chosen variable name ('music'). We choose the Kyrie from the mass "Missa La sol fa re mi" by Josquin (Jos1102) to search for the sequence of notes "La sol fa re mi" (= A G F D E):

1. Search for a sequence of tones

Now we have to enter the motif we want to search for. To do this, we need to create a so-called stream (i.e. a sequence of notes), which we call "StreamMot". We are looking for the "La Sol Fa Re Mi" (= A G F D E) motif. For this we enter it through the internal notation of music21:

Since we only want to search for a pitch sequence independent of the rhythm, the rhythm entered in our search motif must be ignored. The 'recurse' command filters out all features except the pitches from the file; the result of this filtering is a sequence of notes as the variable 'full_piece_stream'.

Now the search for the melodic line of the motif is created by the "search.noteNameSearch" function

The positions of the output tones are listed (as 'p_full_piece'). This list can be further processed in several ways:

  1. Number of motifs in the entire score.
  1. You can also display the frequency of the motif in the different voices:
  1. The exact position in the score of a single element of the list 'p' is displayed if you put the position of the element in square brackets. For example, one asks for the position of the fourth element (music21 always starts counting at 0, so one must enter a '3' for the fourth element):

This means that the fourth element of the list 'p_full_piece' is the 84th note in the stream 'StreamMot' (the list with the notes of the piece). If you put this again in square brackets you get more info:

It was to be expected that it is the note A (initial note of our search motive). More important is the measure and the exact position of the beginning of the motif as well as the voice:

We can verify this by looking at the score, measure 42.

  1. If you want to list all the positions at once and for all motif repetitions, you can use the following command (a recursive 'loop' command):
  1. Finally, you can mark the notes in question in the score, either with a color or a character, e.g. * :

You can write the marked version of the score to a new file, whose path is depicted in the output cell and which you can in turn open with MuseScore:

2. Search for all transpositions of a sequence

In Music21, a command can be programmed to search for chromatic transpositions of a motif in one fell swoop. First we need the following command:

In the following, we will search for the motif in the 12 keys (and their respective enharmonic equivalents). To do this, one must create an algorithm that is repeated 12 times. A second loop helps to enter the information from each repetition into the results list.

3. Tasks

Now load the other movements of the Missa one after the other and look for the motif! You can use this notebook for this purpose:

  1. save it under a new name.
  2. then load another movement (cf. https://analyse.hfm-weimar.de/doku.php?id=en:prjode).
  3. tap on 'Run' and then start the other code cells - or select 'Cell' -> 'Run All' in the menu.

How often does the motif appear in the other sentences? In which voices?