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:
  • pitches (list[int]) – MIDI pitch values for the melody notes.

  • starts (list[float]) – Note onset times in seconds.

  • ends (list[float]) – Note offset times in seconds.

  • tempo (float, optional) – Tempo in beats per minute, used to convert note durations to quarter-note units.

  • method (str, optional) – Contour statistic method, either “amads” or “fantastic”. Defaults to “amads”.

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:

Tuple[float, float, float]

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:
  • pitches (list[int]) – MIDI pitch values for the melody notes.

  • starts (list[float]) – Note onset times in seconds.

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:

Tuple[int, float, float, float, str]

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.

Parameters:

pitches (list[int]) – Sequence of MIDI pitches.

Returns:

Lower-triangular binary contour matrix.

Return type:

list[list[int]]

get_polynomial_contour_features(melody)[source]

Calculate polynomial contour features.

Parameters:

melody (Melody) – The melody to analyze

Returns:

List of first 3 polynomial contour coefficients for the melody

Return type:

List[float]

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”.

Parameters:

melody (Melody) – The melody to analyze

Returns:

Huron contour classification.

Return type:

str

get_contour_features(melody)[source]

Compute all contour-based features for a melody.

Parameters:

melody (Melody) – The melody to analyze

Returns:

Dictionary of contour-based feature values

Return type:

Dict