Calculate the mobility measure for each tone in a melody (von Hippel, 2000).
Mobility describes why melodies change direction after large skips by observing
that they would otherwise run out of the comfortable melodic range. It uses
lag-one autocorrelation between successive pitch heights.
Parameters:
-
score
(Score)
–
A Score object containing the melody to analyze. The score will be
flattened and collapsed into a single sequence of notes ordered by
onset time.
Returns:
-
Optional[Score]
–
score with ties stripped where each note is annotated with a
mobility value (in float) in the attribute "mobility"
None if score is not monophonic or there are not enough notes
in the score to run mobility
References
von Hippel, P. (2000). Redefining pitch proximity: Tessitura and
mobility as constraints on melodic interval size. Music Perception,
17 (3), 315-327.
Source code in amads/melody/mobility.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 | def mobility(score: Score) -> Score | None:
"""
Calculate the mobility measure for each tone in a melody (von Hippel, 2000).
Mobility describes why melodies change direction after large skips by observing
that they would otherwise run out of the comfortable melodic range. It uses
lag-one autocorrelation between successive pitch heights.
Parameters
----------
score : Score
A Score object containing the melody to analyze. The score will be
flattened and collapsed into a single sequence of notes ordered by
onset time.
Returns
-------
Optional[Score]
score with ties stripped where each note is annotated with a
mobility value (in float) in the attribute "mobility"
None if score is not monophonic or there are not enough notes
in the score to run mobility
References
----------
von Hippel, P. (2000). Redefining pitch proximity: Tessitura and
mobility as constraints on melodic interval size. Music Perception,
17 (3), 315-327.
"""
# hack to check if score is empty
if not score.ismonophonic():
return None
pitches = [note.midi_num for note in score.get_sorted_notes()]
if len(pitches) < 3:
return None
means = [sum / (num + 1) for num, sum in enumerate(accumulate(pitches))]
# list of pitch differences to running mean, added 0 at the beginning for
# convenience when slicing lists for correlation coefficients
pitch_diffs = [0]
pitch_diffs.extend((pitch - mean for pitch, mean in zip(pitches, means)))
current_corrcoef = 0.0
mobility_vals = [0.0, 0.0]
for idx in range(1, len(pitches) - 1):
assert not math.isnan(current_corrcoef)
mobility_val = abs(current_corrcoef * (pitches[idx + 1] - means[idx]))
mobility_vals.append(mobility_val)
# prepare next corrcoef by slicing the pitch diff lists for corrcoef
prev_list = pitch_diffs[: idx + 2]
next_list = pitch_diffs[1 : idx + 2]
next_list.append(pitch_diffs[idx + 1])
slice_list = [prev_list, next_list]
slice_array = np.array(slice_list)
coef_array = np.corrcoef(slice_array)
current_corrcoef = coef_array[0, 1]
# annotate a score
annotated_score = cast(Score, score.merge_tied_notes())
annotate_str = "mobility"
for note, mobility_val in zip(
annotated_score.find_all(Note), mobility_vals
):
note.set(annotate_str, mobility_val)
return annotated_score
|