Contour representations
Contour features in get_all_features come from
melody_features.feature_definitions.contour. Under the hood they use
classes in melody_features.contour that expose the full contour vectors
and summary properties — useful when you want intermediates, not only
scalars.
Classes
StepContour— duration-weighted step contour (default length 64, FANTASTIC-style), withglobal_variation,global_direction,local_variationInterpolationContour— interpolated contour statistics andclass_labelPolynomialContour— polynomial fit;coefficientsviapolynomial_contour_coefficients()HuronContour— Huron contour /get_huron_contour()
Example: step contour
Durations are typically in beats/tatums (feature helpers derive them from
starts / ends / tempo). Constructing the class directly:
from melody_features.contour import StepContour
from melody_features.io.midi import load_midi
melody = load_midi("example.mid")
# durations in beats (seconds × tempo/60)
beat = 60.0 / melody.tempo
durations = [(e - s) / beat for s, e in zip(melody.starts, melody.ends)]
sc = StepContour(melody.pitches, durations, method="amads") # or "fantastic"
print(len(sc.contour)) # 64 by default
print(sc.global_variation)
print(sc.global_direction)
print(sc.local_variation)
For batch scalar features only, prefer
melody_features.features.get_contour_features(melody) or
mf.get_all_features.
API reference: Contour.