Pitch class

Full module path: melody_features.feature_definitions.pitch_class.

Also importable via import melody_features as mf (for example mf.pitch_range).

Pitch class feature definitions.

pitch_class_variability(pitches)[source]

Standard deviation of all pitch classes in the melody.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Standard deviation of pitch class values

Return type:

float

pitch_class_variability_after_folding(pitches)[source]

Standard deviation of all pitch classes after arranging the pitch classes by perfect fifths. Provides a measure of how close the pitch classes are as a whole from the mean pitch class from a dominant-tonic perspective.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Standard deviation of folded pitch class values

Return type:

float

pcdist1(pitches, starts, ends)[source]

Pitch-class distribution weighted by Parncutt duration accent.

Parameters:
  • pitches (list[int]) – List of MIDI pitch values

  • starts (list[float]) – List of note start times

  • ends (list[float]) – List of note end times

Returns:

Map from pitch class (0–11) to proportion

Return type:

dict

pcdist2(pitches, starts, ends)[source]

Second-order pitch-class transition distribution (MIDI Toolbox pcdist2.m).

Transition weights are the product of Parncutt duration accents of the two notes. Keys are (from_pitch_class, to_pitch_class) with pitch classes 0–11 (C=0, …, B=11).

Parameters:
  • pitches (list[int]) – List of MIDI pitch values

  • starts (list[float]) – List of note start times

  • ends (list[float]) – List of note end times

Returns:

Map from pitch-class transition to proportion

Return type:

dict

first_pitch_class(pitches)[source]

The first pitch class in the melody.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

First pitch class in the melody

Return type:

int - between 0 and 11

last_pitch_class(pitches)[source]

The last pitch class in the melody.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Return type:

int - between 0 and 11

dominant_spread(pitches)[source]

The longest sequence of pitch classes separated by perfect 5ths that each appear >9% of the time.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Length of longest sequence of significant pitch classes separated by perfect 5ths

Return type:

int

mean_pitch_class(pitches)[source]

The arithmetic mean of the pitch classes in the melody.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Linear arithmetic mean pitch class value (between 0 and 11)

Return type:

float

Note

This is a linear (non-circular) mean over pitch classes. For example, pitch classes near the wraparound boundary (e.g., 11 and 0) are averaged numerically rather than on the unit circle.

most_common_pitch_class(pitches)[source]

The most frequently occurring pitch class in the melody.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Most common pitch class value

Return type:

int

number_of_unique_pitch_classes(pitches)[source]

The number of unique pitch classes in the melody.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Number of unique pitch classes

Return type:

int

number_of_common_pitch_classes(pitches)[source]

The number of pitch classes that appear in at least 20% of total notes.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Number of significant pitch classes

Return type:

int

prevalence_of_most_common_pitch_class(pitches)[source]

The proportion of pitch classes that are the most common pitch class with regards to the total number of pitch classes in the melody.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Proportion of most common pitch class

Return type:

float

relative_prevalence_of_top_pitch_classes(pitches)[source]

The ratio of the frequency of the second most common pitch class to the frequency of the most common pitch class.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Ratio of second most common pitch class frequency to most common pitch class frequency

Return type:

float

interval_between_most_prevalent_pitch_classes(pitches)[source]

The number of semitones between the two most prevalent pitch classes.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Number of semitones between the most prevalent pitch classes

Return type:

int

folded_fifths_pitch_class_histogram(pitches)[source]

A histogram of pitch classes arranged according to the circle of fifths.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Dictionary mapping pitch classes to counts, arranged according to the circle of fifths (using jSymbolic’s Folded Fifths Pitch Class Histogram)

Return type:

dict

pitch_class_skewness(pitches)[source]

The skewness of the pitch class histogram, using Pearson’s median skewness formula.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Skewness of pitch class histogram values, or 0 for empty input

Return type:

float

pitch_class_kurtosis(pitches)[source]

The sample excess kurtosis of the pitch class histogram.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Kurtosis of pitch class histogram values, or 0 for empty input

Return type:

float

pitch_class_skewness_after_folding(pitches)[source]

The skewness of the pitch class histogram, using Pearson’s median skewness formula, after arranging the pitch classes according to the circle of fifths.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Skewness of folded fifths histogram values, or 0 for empty input

Return type:

float

pitch_class_kurtosis_after_folding(pitches)[source]

The sample excess kurtosis of the pitch class histogram, after arranging the pitch classes according to the circle of fifths.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Kurtosis of folded fifths histogram values, or 0 for empty input

Return type:

float

strong_tonal_centres(pitches)[source]

Counts the number of isolated peaks in the pitch class histogram that each account for at least 9% of notes, arranged according to the circle of fifths.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Number of strong tonal centres (peaks >= 9% in fifths histogram)

Return type:

float