(version 2022_02_08)
This tutorial introduces the computer-assisted possibilities of simple statistical queries based on CAMAT (Computer-Assisted Music Analysis Tool), now with comparative queries of several pieces. Queried are
Working through the tutorial should enable you to examine your own music examples using the computer-based methods presented and to compare between different pieces of music.
At the beginning you have to load various libraries with the following commands:
import sys
import os
sys.path.append(os.getcwd().replace(os.path.join('music_xml_parser', 'ipynb'), ''))
import music_xml_parser as mp
import csv
from IPython.display import HTML, display
import numpy as np
import pandas as pd
# Here defaults for the formatting of the table output:
pd.set_option('display.max_rows', 9999) # Setting the max. number of lines
pd.set_option('display.max_columns', 9999) # Setting the max. number of columns
pd.set_option('display.width', 100) # Setting column width
In the Statistics Tutorial (Part 2), we looked at the first movement from the String Quartet K. 171 by Wolfgang Amadeus Mozart. Now we want to compare between the four movements of the string quartet.
Here are the URL's of the four files:
We can load the four files with the following command under the common name 'xml_files':
xml_files = ['https://analyse.hfm-weimar.de/database/03/MoWo_K171_COM_1-4_StringQuar_003_00867.xml',
'https://analyse.hfm-weimar.de/database/03/MoWo_K171_COM_2-4_StringQuar_003_00868.xml',
'https://analyse.hfm-weimar.de/database/03/MoWo_K171_COM_3-4_StringQuar_003_00869.xml',
'https://analyse.hfm-weimar.de/database/03/MoWo_K171_COM_4-4_StringQuar_003_00870.xml']
# The four file names have to be written in simple apostrophes ' '.
# and are separated by commas.
# Alternatively, files can also be read in from the local hard disk:
# xml_files = ['MoWo_K171_COM_1-4_StringQuar_003_00867.xml',
# 'MoWo_K171_COM_2-4_StringQuar_003_00868.xml',
# 'MoWo_K171_COM_3-4_StringQuar_003_00869.xml',
# 'MoWo_K171_COM_4-4_StringQuar_003_00870.xml']
# Before that, however, the four files must have been saved in the following folder:
# ... / music_xml_parser / data / xmls_to_parse / hfm_database
The following command ('df = mp.core.corpus.analyse_interval') creates a table (or 'dataframe' named 'df'), which can then be displayed as a table in the browser by the command 'df' or saved as a csv file by the command 'df.to_csv'.
The calculation can take - depending on the number and size of the files - some seconds up to several minutes...
A number of parameters can be set beforehand.
df = mp.core.corpus.analyse_interval(xml_files,
separate_parts=True,
include_basic_stats=True,
include_pitchclass=True,
interval_range=[-5, 5],
get_full_axis=False,
get_in_percentage=False)
The following parameters can be changed:
= name of the loaded note files (see above)
This parameter isolates the individual voices. (The specification 'False' is not possible here).
The statistical data will be displayed for all voices.
For all voices a distribution of pitch classes is shown. (From 0=C to 11=B (H).) If this is not desired, please select 'include_pitchclass=False'!
With this parameter you can set which interval increments are displayed. With [-6, 6], for example, fifths down (-6 semitones) to fifths up (+6 semitones) are displayed; all larger intervals are placed in two common rest classes (<6 or >6). For 'None', all intervals that occur are represented.
With this parameter all intervals that occur are displayed.
This allows you to switch between absolute frequencies (i.e. the number of pitch classes or intervals that occur) at 'False' and relative frequencies (i.e. percentage) at 'True'.
When you have set all parameters, please add the following simple command 'df', which will display the table ('Run').
df = mp.core.corpus.analyse_interval(xml_files,
separate_parts=True,
include_basic_stats=True,
include_pitchclass=True,
interval_range=[-5, 5],
get_full_axis=False,
get_in_percentage=False)
df
FileName | PartID | PartName | TotalPart | TotalMeasure | PitchMin | PitchMax | Ambitus | TimeSignature | C | C# | D | D# | E | F | F# | G | G# | A | A# | B | <-5 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 5< | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | MoWo_K171_COM_1-4_StringQuar_003_00867 | 1 | Violino I | 1 | 159 | A3 | D#6 | 30 | [3/4, 4/4] | 41 | 0 | 66 | 119 | 0 | 59 | 2 | 55 | 51 | 31 | 83 | 4 | 30 | 20 | 19 | 37 | 91 | 78 | 33 | 79 | 36 | 8 | 7 | 20 | 52 |
1 | MoWo_K171_COM_1-4_StringQuar_003_00867 | 2 | Violino II | 1 | 159 | G3 | A#5 | 27 | [3/4, 4/4] | 60 | 0 | 62 | 110 | 1 | 76 | 2 | 56 | 49 | 29 | 102 | 5 | 19 | 13 | 10 | 27 | 137 | 87 | 36 | 70 | 56 | 23 | 15 | 20 | 38 |
2 | MoWo_K171_COM_1-4_StringQuar_003_00867 | 3 | Viola | 1 | 159 | C3 | D#5 | 27 | [3/4, 4/4] | 23 | 0 | 32 | 57 | 0 | 46 | 0 | 40 | 31 | 18 | 60 | 5 | 18 | 18 | 19 | 15 | 55 | 43 | 14 | 39 | 22 | 12 | 11 | 21 | 24 |
3 | MoWo_K171_COM_1-4_StringQuar_003_00867 | 4 | Violoncello | 1 | 159 | D#2 | G4 | 28 | [3/4, 4/4] | 26 | 2 | 22 | 49 | 0 | 33 | 0 | 21 | 19 | 8 | 57 | 4 | 40 | 7 | 9 | 1 | 20 | 22 | 16 | 24 | 53 | 3 | 1 | 30 | 14 |
4 | MoWo_K171_COM_1-4_StringQuar_003_00867 | AllParts | AllParts | 4 | 159 | D#2 | D#6 | 48 | [4/4, 3/4] | 150 | 2 | 182 | 335 | 1 | 214 | 4 | 172 | 150 | 86 | 302 | 18 | 107 | 58 | 57 | 80 | 303 | 230 | 99 | 212 | 167 | 46 | 34 | 91 | 128 |
5 | MoWo_K171_COM_2-4_StringQuar_003_00868 | 1 | None | 1 | 51 | G3 | G#5 | 25 | [3/4] | 8 | 7 | 5 | 40 | 1 | 19 | 2 | 21 | 24 | 4 | 35 | 3 | 2 | 2 | 10 | 10 | 25 | 22 | 48 | 16 | 3 | 11 | 3 | 8 | 8 |
6 | MoWo_K171_COM_2-4_StringQuar_003_00868 | 2 | None | 1 | 51 | G3 | F5 | 22 | [3/4] | 21 | 21 | 5 | 17 | 0 | 8 | 0 | 6 | 6 | 4 | 16 | 0 | 1 | 2 | 5 | 7 | 16 | 13 | 29 | 11 | 6 | 2 | 2 | 3 | 6 |
7 | MoWo_K171_COM_2-4_StringQuar_003_00868 | 3 | None | 1 | 51 | D#3 | D#5 | 24 | [3/4] | 9 | 6 | 5 | 28 | 0 | 12 | 0 | 8 | 12 | 1 | 16 | 0 | 2 | 0 | 2 | 14 | 24 | 9 | 16 | 5 | 4 | 5 | 2 | 5 | 8 |
8 | MoWo_K171_COM_2-4_StringQuar_003_00868 | 4 | None | 1 | 51 | D#2 | C4 | 21 | [3/4] | 9 | 6 | 5 | 17 | 0 | 6 | 0 | 17 | 21 | 1 | 29 | 0 | 8 | 2 | 7 | 1 | 6 | 9 | 40 | 7 | 15 | 1 | 0 | 11 | 3 |
9 | MoWo_K171_COM_2-4_StringQuar_003_00868 | AllParts | AllParts | 4 | 51 | D#2 | G#5 | 41 | [3/4] | 47 | 40 | 20 | 102 | 1 | 45 | 2 | 52 | 63 | 10 | 96 | 3 | 13 | 6 | 24 | 32 | 71 | 53 | 133 | 39 | 28 | 19 | 7 | 27 | 25 |
10 | MoWo_K171_COM_3-4_StringQuar_003_00869 | 1 | None | 1 | 29 | G3 | D#6 | 32 | [4/4] | 44 | 1 | 35 | 37 | 5 | 20 | 18 | 39 | 12 | 13 | 17 | 25 | 14 | 17 | 21 | 32 | 39 | 19 | 11 | 39 | 24 | 11 | 6 | 5 | 27 |
11 | MoWo_K171_COM_3-4_StringQuar_003_00869 | 2 | None | 1 | 29 | G3 | G5 | 24 | [4/4] | 35 | 2 | 36 | 21 | 2 | 14 | 11 | 47 | 14 | 23 | 23 | 9 | 11 | 21 | 18 | 17 | 30 | 27 | 12 | 27 | 23 | 14 | 5 | 15 | 16 |
12 | MoWo_K171_COM_3-4_StringQuar_003_00869 | 3 | None | 1 | 29 | C3 | A4 | 21 | [4/4] | 22 | 0 | 23 | 15 | 1 | 12 | 9 | 27 | 5 | 5 | 11 | 6 | 10 | 1 | 11 | 18 | 25 | 6 | 10 | 12 | 9 | 6 | 5 | 5 | 17 |
13 | MoWo_K171_COM_3-4_StringQuar_003_00869 | 4 | None | 1 | 29 | C2 | D#4 | 27 | [4/4] | 23 | 1 | 24 | 23 | 1 | 12 | 3 | 48 | 8 | 7 | 12 | 4 | 26 | 2 | 8 | 9 | 7 | 14 | 32 | 12 | 13 | 11 | 4 | 13 | 14 |
14 | MoWo_K171_COM_3-4_StringQuar_003_00869 | AllParts | AllParts | 4 | 29 | C2 | D#6 | 51 | [4/4] | 124 | 4 | 118 | 96 | 9 | 58 | 41 | 161 | 39 | 48 | 63 | 44 | 61 | 41 | 58 | 76 | 101 | 66 | 65 | 90 | 69 | 42 | 20 | 38 | 74 |
15 | MoWo_K171_COM_4-4_StringQuar_003_00870 | 1 | None | 1 | 162 | G3 | G6 | 36 | [3/8] | 48 | 1 | 45 | 52 | 1 | 83 | 0 | 66 | 33 | 19 | 98 | 0 | 28 | 3 | 2 | 15 | 123 | 50 | 63 | 31 | 68 | 9 | 5 | 9 | 39 |
16 | MoWo_K171_COM_4-4_StringQuar_003_00870 | 2 | None | 1 | 162 | G3 | D#6 | 32 | [3/8] | 30 | 0 | 46 | 73 | 0 | 65 | 0 | 45 | 23 | 18 | 72 | 1 | 21 | 6 | 15 | 20 | 71 | 40 | 44 | 40 | 51 | 2 | 16 | 11 | 35 |
17 | MoWo_K171_COM_4-4_StringQuar_003_00870 | 3 | None | 1 | 162 | C3 | D#5 | 27 | [3/8] | 26 | 0 | 33 | 70 | 1 | 52 | 0 | 47 | 25 | 10 | 96 | 0 | 12 | 2 | 27 | 26 | 46 | 33 | 91 | 23 | 37 | 9 | 17 | 11 | 25 |
18 | MoWo_K171_COM_4-4_StringQuar_003_00870 | 4 | None | 1 | 162 | D2 | A#3 | 20 | [3/8] | 7 | 0 | 23 | 89 | 1 | 26 | 0 | 18 | 33 | 7 | 116 | 0 | 33 | 7 | 5 | 4 | 13 | 10 | 153 | 28 | 20 | 0 | 9 | 25 | 12 |
19 | MoWo_K171_COM_4-4_StringQuar_003_00870 | AllParts | AllParts | 4 | 162 | D2 | G6 | 53 | [3/8] | 111 | 1 | 147 | 284 | 3 | 226 | 0 | 176 | 114 | 54 | 382 | 1 | 94 | 18 | 49 | 65 | 253 | 133 | 351 | 122 | 176 | 20 | 47 | 56 | 111 |
Please compare the frequency of the pitch classes for different movements and voices. For an easier comparative evaluation, please, select the relative proportion in percentages (get_in_percentage=True).
How diatonic or chromatic are the individual movements and voices?
What can be said about the interval progressions in the individual voices? Which voice has the most or the largest leaps? In which voice do the (small) interval steps dominate?
The following command saves the table as a csv file.
Please enter first a local path name as well as the file name, then delete # and 'Run'!
# df.to_csv("/Pfad ... /Tabellenname.csv", sep=';')
# By sep=';' a semicolon is chosen as separator between the cells.
# This facilitates the representation as in external table software.
You can vary the variable 'df' for the table when querying again, e.g. 'df2' instead of 'df'. Here is the example of a query of intervals up to 12 semitones, i.e. one octave (up and down) in percent. The general pitches and pitch classes are now no longer of interest, thus:
'include_basic_stats=False' and 'include_pitchclass=False'.
df2 = mp.core.corpus.analyse_interval(xml_files,
separate_parts=True,
include_basic_stats=False,
include_pitchclass=False,
interval_range=[-12, 12],
get_full_axis=False,
get_in_percentage=True)
df2
FileName | PartID | PartName | <-12 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 12< | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | MoWo_K171_COM_1-4_StringQuar_003_00867 | 1 | Violino I | 0 | 0.78 | 0.00 | 0.98 | 0.98 | 0.20 | 0.78 | 1.37 | 3.92 | 3.73 | 7.25 | 17.84 | 15.29 | 6.47 | 15.49 | 7.06 | 1.57 | 1.37 | 3.92 | 0.00 | 2.75 | 3.73 | 0.78 | 0.00 | 0.00 | 0.39 | 0 |
1 | MoWo_K171_COM_1-4_StringQuar_003_00867 | 2 | Violino II | 0 | 0.54 | 0.00 | 0.36 | 0.18 | 0.36 | 0.18 | 0.54 | 2.36 | 1.81 | 4.90 | 24.86 | 15.79 | 6.53 | 12.70 | 10.16 | 4.17 | 2.72 | 3.63 | 0.00 | 1.45 | 2.54 | 0.73 | 0.73 | 0.00 | 1.27 | 0 |
2 | MoWo_K171_COM_1-4_StringQuar_003_00867 | 3 | Viola | 0 | 1.61 | 0.00 | 0.64 | 0.64 | 0.96 | 0.96 | 0.64 | 5.79 | 6.11 | 4.82 | 17.68 | 13.83 | 4.50 | 12.54 | 7.07 | 3.86 | 3.54 | 6.75 | 0.00 | 0.64 | 1.61 | 1.29 | 0.64 | 0.64 | 1.29 | 0 |
3 | MoWo_K171_COM_1-4_StringQuar_003_00867 | 4 | Violoncello | 0 | 0.83 | 1.25 | 0.00 | 2.08 | 0.00 | 11.67 | 0.83 | 2.92 | 3.75 | 0.42 | 8.33 | 9.17 | 6.67 | 10.00 | 22.08 | 1.25 | 0.42 | 12.50 | 0.42 | 1.67 | 0.00 | 0.83 | 0.83 | 0.42 | 0.83 | 0 |
4 | MoWo_K171_COM_1-4_StringQuar_003_00867 | AllParts | AllParts | 0 | 0.87 | 0.19 | 0.56 | 0.81 | 0.37 | 2.23 | 0.87 | 3.60 | 3.54 | 4.96 | 18.80 | 14.27 | 6.14 | 13.15 | 10.36 | 2.85 | 2.11 | 5.65 | 0.06 | 1.74 | 2.36 | 0.87 | 0.50 | 0.19 | 0.93 | 0 |
5 | MoWo_K171_COM_2-4_StringQuar_003_00868 | 1 | None | 0 | 1.19 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 1.19 | 5.95 | 5.95 | 14.88 | 13.10 | 28.57 | 9.52 | 1.79 | 6.55 | 1.79 | 4.76 | 0.00 | 2.38 | 0.60 | 0.60 | 0.60 | 0.00 | 0.60 | 0 |
6 | MoWo_K171_COM_2-4_StringQuar_003_00868 | 2 | None | 0 | 0.00 | 0.00 | 0.97 | 0.00 | 0.00 | 0.00 | 0.00 | 1.94 | 4.85 | 6.80 | 15.53 | 12.62 | 28.16 | 10.68 | 5.83 | 1.94 | 1.94 | 2.91 | 0.00 | 0.97 | 1.94 | 1.94 | 0.97 | 0.00 | 0.00 | 0 |
7 | MoWo_K171_COM_2-4_StringQuar_003_00868 | 3 | None | 1 | 0.00 | 0.00 | 0.00 | 1.04 | 0.00 | 0.00 | 0.00 | 0.00 | 2.08 | 14.58 | 25.00 | 9.38 | 16.67 | 5.21 | 4.17 | 5.21 | 2.08 | 5.21 | 0.00 | 5.21 | 0.00 | 0.00 | 1.04 | 0.00 | 1.04 | 1 |
8 | MoWo_K171_COM_2-4_StringQuar_003_00868 | 4 | None | 0 | 1.82 | 0.00 | 0.00 | 0.00 | 0.00 | 4.55 | 0.91 | 1.82 | 6.36 | 0.91 | 5.45 | 8.18 | 36.36 | 6.36 | 13.64 | 0.91 | 0.00 | 10.00 | 0.00 | 0.91 | 0.00 | 1.82 | 0.00 | 0.00 | 0.00 | 0 |
9 | MoWo_K171_COM_2-4_StringQuar_003_00868 | AllParts | AllParts | 0 | 0.84 | 0.00 | 0.21 | 0.21 | 0.00 | 1.05 | 0.21 | 1.26 | 5.03 | 6.71 | 14.88 | 11.11 | 27.88 | 8.18 | 5.87 | 3.98 | 1.47 | 5.66 | 0.00 | 2.31 | 0.63 | 1.05 | 0.63 | 0.00 | 0.42 | 0 |
10 | MoWo_K171_COM_3-4_StringQuar_003_00869 | 1 | None | 0 | 0.38 | 0.00 | 0.38 | 0.38 | 1.52 | 1.14 | 1.52 | 6.44 | 7.95 | 12.12 | 14.77 | 7.20 | 4.17 | 14.77 | 9.09 | 4.17 | 2.27 | 1.89 | 1.14 | 0.38 | 0.00 | 2.27 | 1.52 | 0.00 | 3.03 | 2 |
11 | MoWo_K171_COM_3-4_StringQuar_003_00869 | 2 | None | 0 | 0.85 | 0.00 | 0.00 | 0.42 | 0.42 | 2.97 | 0.00 | 8.90 | 7.63 | 7.20 | 12.71 | 11.44 | 5.08 | 11.44 | 9.75 | 5.93 | 2.12 | 6.36 | 0.42 | 0.00 | 0.42 | 0.85 | 2.12 | 0.00 | 1.27 | 0 |
12 | MoWo_K171_COM_3-4_StringQuar_003_00869 | 3 | None | 0 | 2.96 | 0.00 | 0.74 | 0.00 | 0.00 | 2.96 | 0.74 | 0.74 | 8.15 | 13.33 | 18.52 | 4.44 | 7.41 | 8.89 | 6.67 | 4.44 | 3.70 | 3.70 | 0.00 | 4.44 | 1.48 | 0.00 | 1.48 | 1.48 | 2.96 | 0 |
13 | MoWo_K171_COM_3-4_StringQuar_003_00869 | 4 | None | 0 | 0.61 | 0.00 | 0.00 | 1.21 | 0.61 | 13.33 | 0.00 | 1.21 | 4.85 | 5.45 | 4.24 | 8.48 | 19.39 | 7.27 | 7.88 | 6.67 | 2.42 | 7.88 | 0.61 | 3.64 | 1.21 | 0.00 | 0.00 | 0.00 | 2.42 | 0 |
14 | MoWo_K171_COM_3-4_StringQuar_003_00869 | AllParts | AllParts | 0 | 1.00 | 0.00 | 0.25 | 0.50 | 0.75 | 4.50 | 0.62 | 5.12 | 7.25 | 9.50 | 12.62 | 8.25 | 8.12 | 11.25 | 8.62 | 5.25 | 2.50 | 4.75 | 0.62 | 1.62 | 0.62 | 1.00 | 1.38 | 0.25 | 2.38 | 1 |
15 | MoWo_K171_COM_4-4_StringQuar_003_00870 | 1 | None | 0 | 0.22 | 0.67 | 1.80 | 0.00 | 1.35 | 1.35 | 0.00 | 0.67 | 0.45 | 3.37 | 27.64 | 11.24 | 14.16 | 6.97 | 15.28 | 2.02 | 1.12 | 2.02 | 0.00 | 0.67 | 3.15 | 2.70 | 0.45 | 0.00 | 0.90 | 0 |
16 | MoWo_K171_COM_4-4_StringQuar_003_00870 | 2 | None | 0 | 1.08 | 0.27 | 1.34 | 0.54 | 0.27 | 1.08 | 0.00 | 1.61 | 4.03 | 5.38 | 19.09 | 10.75 | 11.83 | 10.75 | 13.71 | 0.54 | 4.30 | 2.96 | 1.08 | 2.96 | 1.88 | 1.88 | 0.81 | 0.27 | 0.00 | 0 |
17 | MoWo_K171_COM_4-4_StringQuar_003_00870 | 3 | None | 0 | 1.39 | 0.00 | 0.56 | 0.28 | 0.00 | 0.84 | 0.00 | 0.56 | 7.52 | 7.24 | 12.81 | 9.19 | 25.35 | 6.41 | 10.31 | 2.51 | 4.74 | 3.06 | 1.11 | 2.79 | 1.39 | 0.56 | 0.00 | 0.00 | 1.11 | 0 |
18 | MoWo_K171_COM_4-4_StringQuar_003_00870 | 4 | None | 0 | 2.51 | 0.00 | 0.00 | 0.00 | 0.31 | 5.02 | 2.51 | 2.19 | 1.57 | 1.25 | 4.08 | 3.13 | 47.96 | 8.78 | 6.27 | 0.00 | 2.82 | 7.84 | 0.00 | 1.25 | 0.00 | 0.00 | 0.00 | 0.00 | 2.19 | 0 |
19 | MoWo_K171_COM_4-4_StringQuar_003_00870 | AllParts | AllParts | 0 | 1.20 | 0.27 | 1.00 | 0.20 | 0.54 | 1.94 | 0.54 | 1.20 | 3.28 | 4.35 | 16.92 | 8.90 | 23.48 | 8.16 | 11.77 | 1.34 | 3.14 | 3.75 | 0.54 | 1.87 | 1.74 | 1.40 | 0.33 | 0.07 | 1.00 | 0 |
How do the individual movements (and voices) differ with respect to the intervals that occur? Which intervals occur frequently - which (almost) never?
And now have fun with the comparative study of the distribution of pitch classes and interval progressions between compositions of your choice!!!