Contour
Full module path: melody_features.feature_definitions.contour.
Also importable via import melody_features as mf (for example mf.pitch_range).
Contour feature definitions.
- get_step_contour_features(pitches, starts, ends, tempo=120.0, method='amads')[source]
Calculate summary features from a duration-weighted step contour.
A step contour represents a melody as a fixed-length sequence of pitch samples: each note’s MIDI pitch is repeated in proportion to its duration relative to the whole melody. The implementation follows the FANTASTIC convention of resampling the melody to 64 steps by default. The returned features summarize the resulting pitch sequence as global variation, global direction, and local variation.
- Parameters:
- Returns:
(global_variation, global_direction, local_variation), where global variation is the standard deviation of the step-contour vector, global direction is its correlation with an ascending linear ramp, and local variation is the mean absolute difference between adjacent contour samples.
- Return type:
- get_interpolation_contour_features(pitches, starts)[source]
Calculate features from an interpolation contour.
An interpolation contour approximates melodic shape by identifying contour turning points and replacing the pitch trajectory between successive turning points with linear gradients. The returned features summarize the gradient sequence by overall direction, mean absolute gradient, gradient variability, direction-change rate, and a four-letter contour class.
- Parameters:
- Returns:
(global_direction, mean_gradient, gradient_std, direction_changes, class_label). The class label encodes four sampled gradient categories from strong downward to strong upward.
- Return type:
- comb_contour_matrix(pitches)[source]
The Marvin and Laprade comb contour matrix.
For a melody with n notes, this feature returns an n x n lower-triangular binary matrix. Entry C[i][j] is 1 when note j is higher than note i and i >= j; otherwise it is 0. The matrix encodes pairwise pitch-height relations in the melodic contour.
- get_huron_contour_features(melody)[source]
Classify a melody using Huron’s three-point contour scheme.
The Huron contour reduces a melody to three pitch points: the first pitch, a rounded duration-weighted mean pitch, and the last pitch. Their relative ordering is mapped to a categorical contour label such as “ascending”, “descending”, “convex”, “concave”, or “horizontal”.