import sys
from music21 import * # activate library
import pandas as pd
Ch. 9 – Key-finding
Install music21
and other elements needed to run the environment Press play and wait for all commands to be executed - this initial command might take some time as it needs to build the music21
environment.
Key-finding
Key-finding algorithm applied to an example excerpt (bach/bwv30.6
).
= corpus.parse('bach/bwv30.6.xml')# 30.6
bwv30_6 print(bwv30_6.analyze('key.krumhanslkessler'))
= bwv30_6.measures(1,4) # First 3 measures
bwv30_6_3meas
= analysis.discrete.KrumhanslKessler() # Key profile
KK = analysis.windowed.WindowedAnalysis(bwv30_6_3meas, KK)
wa = wa.analyze(2, windowType='overlap')
a,b
=[]; mode=[]; key=[]
keyclarfor x in range(len(a)):
0])
key.append(a[x][1])
mode.append(a[x][2])
keyclar.append(a[x][=pd.DataFrame({'key':key,'mode':mode,'r':keyclar})
dataprint(data)
A major
key mode r
0 E major 0.881687
1 E major 0.892883
2 A major 0.588537
3 B major 0.833787
4 E major 0.972757
5 E major 0.901069
6 F# minor 0.717810
7 E major 0.847699
8 E major 0.882310
9 E major 0.807233
10 F# minor 0.746200
11 B major 0.694972
12 B minor 0.684539
13 B minor 0.696579
14 E major 0.813827
Tension
Analysis of tonal tension using the model by Herremans and Chew (2016), implemented in partitura
library for Python.
import partitura
import numpy as np
= partitura.load_musicxml('data/bwv306.musicxml')
part = partitura.musicanalysis.estimate_tonaltension(part, ss='onset')
tonal_tension = getattr(tonal_tension['onset_beat'][0:50], "tolist", lambda: value)()
x = tonal_tension['cloud_momentum'][0:50]
y
= {'beat': x,'tension': y}
d = pd.DataFrame(data=d)
df print(df)
beat tension
0 0.0 0.000000
1 1.0 0.132809
2 2.0 0.132809
3 2.5 0.031124
4 3.0 0.192431
5 3.5 0.046758
6 4.0 0.142699
7 4.5 0.055152
8 5.0 0.082517
9 5.5 0.072674
10 6.0 0.088245
11 7.0 0.158890
12 7.5 0.023576
13 8.0 0.135350
14 10.0 0.126068
15 11.0 0.111489
16 11.5 0.031124
17 12.0 0.092913
18 12.5 0.036120
19 13.0 0.125584
20 13.5 0.073635
21 14.0 0.168273
22 14.5 0.114459
23 15.0 0.116256
24 15.5 0.080099
25 16.0 0.061819
26 20.0 0.032064
27 21.0 0.111489
28 21.5 0.031124
29 22.0 0.043444
30 22.5 0.109472
31 23.0 0.086467
32 23.5 0.080719
33 24.0 0.218836
34 24.5 0.064623
35 25.0 0.236635
36 25.5 0.092383
37 26.0 0.236347
38 28.0 0.177259
39 28.5 0.046247
40 29.0 0.034470
41 29.5 0.052403
42 30.0 0.097112
43 30.5 0.051889
44 31.0 0.131294
45 31.5 0.046758
46 32.0 0.127003
47 32.5 0.059613
48 33.0 0.085597
49 33.5 0.075891
/Users/tuomaseerola/miniconda3/envs/relative_mode/lib/python3.9/site-packages/partitura/io/importmusicxml.py:421: UserWarning: Found repeat without start
Starting point 0 is assumed
warnings.warn(
References
- Herremans, D., & Chew, E. (2016). Tension ribbons: Quantifying and visualising tonal tension. Second International Conference on Technologies for Music Notation and Representation. TENOR, 2.