Absolute pitch

Full module path: melody_features.feature_definitions.absolute_pitch.

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

Absolute pitch feature definitions.

pitch_range(pitches)[source]

Subtract the lowest pitch number in the melody from the highest.

Parameters:

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

Returns:

Range between highest and lowest pitch in semitones

Return type:

int

Note

This feature is named ambitus in MIDI Toolbox.

pitch_standard_deviation(pitches)[source]

Standard deviation of all pitch numbers in the melody.

Parameters:

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

Returns:

Standard deviation of pitches

Return type:

float

first_pitch(pitches)[source]

The first pitch number in the melody.

Parameters:

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

Returns:

First pitch in the melody

Return type:

int

last_pitch(pitches)[source]

The last pitch number in the melody.

Parameters:

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

Returns:

Last pitch in the melody

Return type:

int

basic_pitch_histogram(pitches)[source]

A histogram of pitch values and their counts, with one pitch bin per non-zero count.

Parameters:

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

Returns:

Mapping from MIDI pitch (0–127) to note count. Only pitches with count > 0 are included.

Return type:

dict[int, int]

Note

We only return bins for pitches that have a count > 0. An implementation that is truer to the original jSymbolic implementation would return 128 bins (0-127) regardless of how any different pitches are present. However, we believe our approach is more concise and easier to understand for many purposes.

melodic_pitch_variety(pitches, starts, tempo=120.0, ppqn=480)[source]

The average number of onset positions before a pitch is repeated.

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

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

  • tempo (float, default=120.0) – Tempo in beats per minute

  • ppqn (int, default=480) – Pulses per quarter note (MIDI resolution)

Returns:

Average number of distinct onset positions before pitch repetition.

Return type:

float

mean_pitch(pitches)[source]

The arithmetic mean of the pitch numbers in the melody.

Parameters:

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

Returns:

Mean pitch value, or 0.0 for empty input

Return type:

float

most_common_pitch(pitches)[source]

The most frequently occurring pitch number in the melody.

Parameters:

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

Returns:

Most common pitch value

Return type:

int

number_of_unique_pitches(pitches)[source]

The number of unique pitch numbers in the melody.

Parameters:

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

Returns:

Number of unique pitches

Return type:

int

number_of_common_pitches(pitches)[source]

The number of unique pitch numbers that appear in at least 9% of total notes.

Parameters:

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

Returns:

Number of unique pitches that appear in at least 9% of notes

Return type:

int

tessitura(pitches)[source]

Tessitura is based on standard deviation from median pitch height. The median range of the melody tends to be favoured and thus more expected. Tessitura predicts whether listeners expect tones close to median pitch height. Higher tessitura values correspond to melodies that have a wider range of pitches.

Parameters:

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

Returns:

  • list[float] – Absolute local tessitura value for each note in sequence

  • Citation

  • ———

  • von Hippel (2000).

Return type:

list[float]

mean_tessitura(pitches)[source]

The arithmetic mean of local tessitura values.

Parameters:

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

Returns:

Mean tessitura value

Return type:

float

tessitura_std(pitches)[source]

The standard deviation of the sequence of tessitura values.

Parameters:

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

Returns:

Standard deviation of tessitura values

Return type:

float

prevalence_of_most_common_pitch(pitches)[source]

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

Parameters:

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

Returns:

Proportion of most common pitch (0.0 if there are no pitches)

Return type:

float

relative_prevalence_of_top_pitches(pitches)[source]

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

Parameters:

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

Returns:

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

Return type:

float

interval_between_most_prevalent_pitches(pitches)[source]

The number of semitones between the two most prevalent pitches.

Parameters:

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

Returns:

Number of semitones between the most prevalent pitches

Return type:

int

pitch_skewness(pitches)[source]

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

Parameters:

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

Returns:

Median skewness of pitch values, or 0 for empty input or when std dev is 0

Return type:

float

pitch_kurtosis(pitches)[source]

The sample excess kurtosis of the pitch histogram.

Parameters:

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

Returns:

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

Return type:

float

importance_of_bass_register(pitches)[source]

The proportion of pitch numbers in the melody that are between 0 and 54.

Parameters:

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

Returns:

Proportion of MIDI pitch numbers that are between 0 and 54 (0.0 if there are no pitches)

Return type:

float

importance_of_middle_register(pitches)[source]

The proportion of pitch numbers in the melody that are between 55 and 72.

Parameters:

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

Returns:

Proportion of MIDI pitch numbers that are between 55 and 72 (0.0 if there are no pitches)

Return type:

float

importance_of_high_register(pitches)[source]

The proportion of pitch numbers in the melody that are between 73 and 127.

Parameters:

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

Returns:

Proportion of MIDI pitch numbers that are between 73 and 127 (0.0 if there are no pitches)

Return type:

float

pitch_spelling(melody)[source]

Pitch spelling using the ps13s1 algorithm.

Parameters:

melody (Melody) – A melody-features Melody object.

Returns:

  • list[str] – List of pitch spellings.

  • Citation

  • ———-

  • Meredith (2006)

Return type:

list[str]

repeated_notes(pitches)[source]

The proportion of repeated notes in the melody.

Parameters:

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

Returns:

Proportion of intervals that are repeated notes (0.0-1.0). Returns -1.0 if input is None, 0.0 if input is empty or has only one value.

Return type:

float

stepwise_motion(pitches)[source]

The proportion of stepwise motion in the melody. Stepwise motion is defined as a melodic interval of 1 or 2 semitones.

Parameters:

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

Returns:

Proportion of intervals that are stepwise (0.0-1.0). Returns -1.0 if input is None, 0.0 if input is empty or has only one value.

Return type:

float