(version 08_02_2022)
This tutorial introduces the search of interval sequences based on CAMAT (Computer-Assisted Music Analysis Tool).
Working through the tutorial should enable you to search for interval sequences in your own music examples (sheet music files).
import sys
import os
sys.path.append(os.getcwd().replace(os.path.join('music_xml_parser', 'ipynb'), ''))
import music_xml_parser as mp
from music21 import *
import csv
from IPython.display import HTML, display
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# With these commands not only the CAMAT music_xml_parser are loaded
# but also the python libraries 'numpy' and 'pandas' for static evaluations,
# 'music21' and 'matplotlib' for graphical representations.
environment.set('autoDownload', 'allow')
# This enables the download of xml files from the Internet.
First, a note file must be selected for the search, loaded and designated with a variable name (here: 'xml_file'). We choose a composition by a composer who is famous for the use of motives: Ludwig van Beethoven. We select the first movement of the String Quartet Op. 18, No. 1.
xml_file = 'https://analyse.hfm-weimar.de/database/03/BeLuva_Op18_1-6_1-4_StringQuar_003_00104.xml'
The following command generates a search query and then displays a list of results. The interval sequence searched for is specified in semitone steps; the individual interval steps are separated by a comma.
For example: search for three tones in a sequence of two ascending major seconds (whole tones)
interval=[2, 2]
Second example: search for three tones, a major third up followed by minor second (semitone) down.
interval=[4, -1]
In the Beethoven score, we want to search for the initial motive F G F E F C. How often and where exactly does it appear in the further course of the movement? Expressed in semitones, the motive consists of the following sequence of intervals:
interval=[2, -2, -1, 1, -5]
results_01 = mp.core.search.simple_interval_search(xml_file,
interval=[2, -2, -1, 1, -5],
return_details=False)
results_01
Downloading file:BeLuva_Op18_1-6_1-4_StringQuar_003_00104.xml >>> BeLuva_Op18_1-6_1-4_StringQuar_003_00104.xml downloaded! File at: ../music_xml_parser/data/xmls_to_parse/hfm_database/BeLuva_Op18_1-6_1-4_StringQuar_003_00104.xml
Pitch | Occurance | |
---|---|---|
0 | B-1 | 3 |
1 | F | 14 |
2 | G-1 | 1 |
3 | D-1 | 1 |
As expected, the motif occurs most frequently with the initial note F - 14 times.
ATTENTION: -1 stands for a b-sign, 1 for a #-sign, 0 for a resolution sign, -2 for a double bb, and so on. This means:
With 'return_details=False' only the frequencies of the searched interval sequence related to different starting tones are displayed.
The output can be refined by the parameter 'return_details=true'. Then not only the frequencies are displayed, but the exact instances: in which voice, with which starting note, in which measure and at which beat (LocalOnset). The column 'Onset' refers to the order of all notes in the piece.
results_02 = mp.core.search.simple_interval_search(xml_file,
interval=[2, -2, -1, 1, -5],
return_details=True)
results_02
File at: ../music_xml_parser/data/xmls_to_parse/hfm_database/BeLuva_Op18_1-6_1-4_StringQuar_003_00104.xml
Pitch | Octave | MIDI | PartName | PartID | Measure | Onset | LocalOnset | |
---|---|---|---|---|---|---|---|---|
0 | F | 4 | 65.0 | Violin I | 1 | 1 | 0.0 | 1.0 |
1 | F | 4 | 65.0 | Violin I | 1 | 9 | 24.0 | 1.0 |
2 | B-1 | 5 | 82.0 | Violin I | 1 | 152 | 453.0 | 1.0 |
3 | F | 5 | 77.0 | Violin I | 1 | 159 | 474.0 | 1.0 |
4 | F | 5 | 77.0 | Violin I | 1 | 179 | 534.0 | 1.0 |
5 | F | 4 | 65.0 | Violin I | 1 | 312 | 933.0 | 1.0 |
6 | F | 4 | 65.0 | Violin II | 2 | 1 | 0.0 | 1.0 |
7 | F | 4 | 65.0 | Violin II | 2 | 9 | 24.0 | 1.0 |
8 | G-1 | 5 | 78.0 | Violin II | 2 | 155 | 462.0 | 1.0 |
9 | D-1 | 5 | 73.0 | Violin II | 2 | 163 | 486.0 | 1.0 |
10 | F | 4 | 65.0 | Violin II | 2 | 179 | 534.0 | 1.0 |
11 | F | 3 | 53.0 | Viola | 3 | 1 | 0.0 | 1.0 |
12 | F | 3 | 53.0 | Viola | 3 | 9 | 24.0 | 1.0 |
13 | B-1 | 3 | 58.0 | Viola | 3 | 119 | 354.0 | 1.0 |
14 | F | 3 | 53.0 | Viola | 3 | 179 | 534.0 | 1.0 |
15 | F | 3 | 53.0 | Violoncello | 4 | 1 | 0.0 | 1.0 |
16 | F | 3 | 53.0 | Violoncello | 4 | 9 | 24.0 | 1.0 |
17 | B-1 | 2 | 46.0 | Violoncello | 4 | 119 | 354.0 | 1.0 |
18 | F | 2 | 41.0 | Violoncello | 4 | 179 | 534.0 | 1.0 |
The motif always starts at the beginning of a bar (LocalOnset 1.0) and is never shifted to other metric positions. It would be shifted, for example, if LocalOnset were 2.0 (on the second beat) or 1.5 (on the third eighth note).
# The following command can be used to rename the columns of the table:
# mp.utils.display_table(data=results_02, columns=['Start Tone', 'Octave position', 'Midi', 'Voice', 'PartID', 'Bar', 'Position', 'Onset'])
A look at the score reveals that often not the whole motive but only the first five notes of the motive occur - followed not by a fourth, but by another interval. We therefore want to look for this shortened motive with the next command:
results_03 = mp.core.search.simple_interval_search(xml_file,
interval=[2, -2, -1, 1],
return_details=False)
results_03
File at: ../music_xml_parser/data/xmls_to_parse/hfm_database/BeLuva_Op18_1-6_1-4_StringQuar_003_00104.xml
Pitch | Occurance | |
---|---|---|
0 | D-1 | 9 |
1 | G | 8 |
2 | E-1 | 6 |
3 | A-1 | 6 |
4 | F | 44 |
5 | C | 19 |
6 | B-1 | 16 |
7 | G-1 | 1 |
8 | D | 1 |
The shortened motive - without the leap of a fourth at the end or with a different following interval - thus occurs much more frequently and with nine different starting pitches: In total, it occurs 110 times!
Get a detailed list of the results and find the individual motives in the score of the string quartet. How often does the motive occur with the same rhythm as the initial motive? What do you think: what other results with a different rhythm can be identified as variations of the motive? What about the interval sequences that do not start at the beginning of the bar, but at a different position in the bar?
Load the sheet music file of a composition of your choice, choose a concise motive - e.g. the main theme at the beginning - and, then, check whether and how often the motive appears in the further course of the piece.