Calculate the degree of melodiousness (gradus suavitatis) according to Euler (1739).
The gradus suavitatis measures melodic pleasantness based on the simplicity of
frequency ratios between successive notes. Lower values indicate higher melodiousness.
The calculation decomposes intervals into frequency ratios and analyzes their prime factors.
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:
-
float
–
The degree of melodiousness value. Lower values indicate higher melodiousness.
Returns 0 for empty scores or single notes.
References
Euler, L. (1739). Tentamen novae theoriae musicae.
Leman, M. (1995). Music and schema theory: Cognitive foundations of
systematic musicology. Berlin: Springer.
Source code in amads/melody/gradus.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 | def gradus(score: Score) -> float | None:
"""
Calculate the degree of melodiousness (gradus suavitatis) according to Euler (1739).
The gradus suavitatis measures melodic pleasantness based on the simplicity of
frequency ratios between successive notes. Lower values indicate higher melodiousness.
The calculation decomposes intervals into frequency ratios and analyzes their prime factors.
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
-------
float
The degree of melodiousness value. Lower values indicate higher melodiousness.
Returns 0 for empty scores or single notes.
References
----------
Euler, L. (1739). Tentamen novae theoriae musicae.
Leman, M. (1995). Music and schema theory: Cognitive foundations of
systematic musicology. Berlin: Springer.
"""
note_iter = score.find_all(Note)
note_iter, next_note_iter = tee(note_iter)
if next(next_note_iter, None) is None:
return None
gradus_sum = 0
num_intervals = 0
for current_note, next_note in pairwise(note_iter):
interval = next_note.midi_num - current_note.midi_num
# interval processed to be within an octave and always positive.
processed_interval = abs(interval) % 12
gradus_sum += _suavitatis(_gradus_interval_ratios[processed_interval])
num_intervals += 1
if num_intervals > 0:
# essentially returns the mean gradus sum
return gradus_sum / num_intervals
else:
return None
|