amads.melody.contour.step_contour#
Calculates the Step Contour of a melody, along with related features, as implemented in the FANTASTIC toolbox of Müllensiefen (2009) [1] (features 20–22). Exemplified in Steinbeck (1982) [2], Juhász (2000) [3], Eerola and Toiviainen (2004) [4].
- class amads.melody.contour.step_contour.StepContour(pitches, durations, step_contour_length=64)[source]#
Class for calculating and analyzing the step contour of a melody. A step contour is a list of MIDI pitch values, repeated proportionally to the duration (measured in tatums) of each note relative to the total melody length. This list is normalized to a user defined length, defaulting to 64 steps as used in FANTASTIC. Rests are considered as extending the duration of the previous note.
Examples
>>> pitches = [60, 64, 67] # C4, E4, G4 >>> durations = [2.0, 1.0, 1.0] # First note is 2 beats, others are 1 beat >>> sc = StepContour(pitches, durations) >>> len(sc.contour) # Default length is 64 64 >>> pitches = [60, 62, 64, 65, 67] # C4, D4, E4, F4, G4 >>> durations = [1.0, 1.0, 1.0, 1.0, 1.0] # Notes have equal durations >>> sc = StepContour(pitches, durations) >>> sc.contour[:8] # First 8 values of 64-length contour [60, 60, 60, 60, 60, 60, 60, 60] >>> sc.global_variation # Standard deviation of contour 2.3974 >>> sc.global_direction # Correlation with ascending line 0.9746 >>> sc.local_variation # Average absolute difference between adjacent values 0.1111
- Parameters:
pitches (
list
[int
])durations (
list
[float
])step_contour_length (
int
)
- property global_direction: float#
Calculate the global direction of the step contour by taking the correlation between the step contour vector and an ascending linear function y = x.
- Returns:
Float value representing the global direction of the step contour Returns 0.0 if the contour is flat
- Return type:
float
Examples
>>> sc = StepContour([60, 62, 64], [1.0, 1.0, 1.0]) >>> sc.global_direction 0.943 >>> sc = StepContour([60, 60, 60], [1.0, 1.0, 1.0]) >>> sc.global_direction 0.0 >>> sc = StepContour([64, 62, 60], [1.0, 1.0, 1.0]) # Descending melody >>> sc.global_direction -0.943
- property global_variation: float#
Calculate the global variation of the step contour by taking the standard deviation of the step contour vector.
- Returns:
Float value representing the global variation of the step contour
- Return type:
float
Examples
>>> sc = StepContour([60, 62, 64], [1.0, 1.0, 1.0]) >>> sc.global_variation 1.64
- property local_variation: float#
Calculate the local variation of the step contour, by taking the mean absolute difference between adjacent values.
- Returns:
Float value representing the local variation of the step contour
- Return type:
float
Examples
>>> sc = StepContour([60, 62, 64], [1.0, 1.0, 1.0]) >>> sc.local_variation 0.0634