Timing
Full module path: melody_features.feature_definitions.timing.
Also importable via import melody_features as mf (for example mf.pitch_range).
Timing feature definitions.
- durdist1(starts, ends, tempo=120.0)[source]
Note duration distribution in nine log-spaced beat bins.
Bin centers (in beats): 1/4, √2/4, 1/2, √2/2, 1, √2, 2, 2√2, 4.
- durdist2(starts, ends, tempo=120.0)[source]
Second-order duration transition distribution (MIDI Toolbox durdist2.m).
Returns a 9×9 matrix of transition probabilities between log-spaced duration bins (same bin centres as durdist1). Keys are (from_bin, to_bin) with bin indices 1–9.
- duration_range(starts, ends, tempo=120.0)[source]
The range between the longest and shortest note duration in quarter notes.
- mean_duration(starts, ends, tempo=120.0)[source]
The mean note duration in quarter notes, computed from the raw durations.
- Parameters:
- Returns:
Mean raw note duration in quarter notes
- Return type:
Note
We use raw durations here (in the style of FANTASTIC), rather than jSymbolic’s quantized rhythmic-value bins.
- average_note_duration(starts, ends)[source]
The average note duration in seconds.
- Parameters:
- Returns:
Average note duration in seconds
- Return type:
Note
This feature reports duration in seconds, unlike quarter-note duration means such as mean_duration and mean_rhythmic_value.
- duration_standard_deviation(starts, ends, tempo=120.0)[source]
The standard deviation of note durations in quarter notes.
- variability_of_note_durations(starts, ends)[source]
The standard deviation of note durations in seconds.
- modal_duration(starts, ends, tempo=120.0)[source]
The modal raw note duration in quarter notes.
- Parameters:
- Returns:
Most frequent raw note duration in quarter notes
- Return type:
Note
This computes the mode of raw quarter-note durations, so differs from jSymbolic most_common_rhythmic_value, which uses the modal bin in a 12-bin rhythmic-value histogram.
- number_of_unique_durations(starts, ends, tempo=120.0)[source]
The number of unique note durations, measured in quarter notes.
- note_density_variability(melody)[source]
The standard deviation of note density across 5-second windows.
- Parameters:
melody (Melody) – Melody object containing MIDI data
- Returns:
Standard deviation of note density using 5-second windows
- Return type:
Note
Our tests indicate a certain discrepancy between our outputs and JSymbolic’s outputs, which may be a consequence of JSymbolic’s tick-based approach, or perhaps its idiosyncratic windowing approach.
- note_density_per_quarter_note(melody)[source]
The average number of note onsets per unit of time corresponding to an idealized quarter note duration based on the tempo.
- note_density_per_quarter_note_variability(melody)[source]
The standard deviation of note density per quarter note.
Divides the melody into 8-quarter-note windows and calculates the standard deviation of note density across these windows.
- Parameters:
melody (Melody) – Melody object containing MIDI data
- Returns:
Standard deviation of note density across windows
- Return type:
Note
Our tests indicate a certain discrepancy between our outputs and JSymbolic’s outputs, which may be a consequence of JSymbolic’s tick-based approach, or perhaps its idiosyncratic windowing approach.
- duration_histogram(starts, ends, tempo=120.0)[source]
A histogram of note durations in quarter notes.
- range_of_rhythmic_values(starts, ends, tempo=120.0)[source]
The range of rhythmic values located within the 12-bin PPQN-based histogram. Durations are converted to quarter notes and mapped to 12 fixed rhythmic bins using midpoints. The returned value is the difference between the highest and lowest non-empty bins.
- number_of_different_rhythmic_values_present(starts, ends, tempo=120.0)[source]
The number of distinct rhythmic value bins that are present in the melody (non-zero).
- number_of_common_rhythmic_values_present(starts, ends, tempo=120.0)[source]
The number of rhythmic value bins with normalized proportion >= 0.15.
- prevalence_of_very_short_rhythmic_values(starts, ends, tempo=120.0)[source]
The sum of the two shortest rhythmic bins (indexes 0 and 1).
- prevalence_of_short_rhythmic_values(starts, ends, tempo=120.0)[source]
The sum of the three shortest rhythmic bins (indexes 0, 1, and 2).
- Parameters:
- Returns:
Proportion in [0, 1] for bins 0, 1 and 2 combined (0.0 if no durations)
- Return type:
Note
Rhythmic-bin families overlap by construction in jSymbolic (e.g., short/medium/long), so these prevalence values are not mutually exclusive and can sum to more than 1.0.
- prevalence_of_medium_rhythmic_values(starts, ends, tempo=120.0)[source]
The sum of rhythmic bins 2 to 6 (8th notes to half notes).
- Parameters:
- Returns:
Proportion in [0, 1] for bins 2..6 combined (0.0 if no durations)
- Return type:
Note
Rhythmic-bin families overlap by construction in jSymbolic (e.g., short/medium/long), so these prevalence values are not mutually exclusive and can sum to more than 1.0.
- prevalence_of_long_rhythmic_values(starts, ends, tempo=120.0)[source]
The sum of rhythmic bins 6 to 11 (half notes to dotted double whole notes or more).
- Parameters:
- Returns:
Proportion in [0, 1] for bins 6 to 11 combined (0.0 if no durations)
- Return type:
Note
Rhythmic-bin families overlap by construction in jSymbolic (e.g., short/medium/long), so these prevalence values are not mutually exclusive and can sum to more than 1.0.
- prevalence_of_very_long_rhythmic_values(starts, ends, tempo=120.0)[source]
The sum of rhythmic bins 9 to 11 (dotted whole notes to dotted double whole notes or more).
- prevalence_of_dotted_notes(starts, ends, tempo=120.0)[source]
The sum of dotted rhythmic bins: 3, 5, 7, 9, 11.
- shortest_rhythmic_value(starts, ends, tempo=120.0)[source]
The shortest quantized (non-zero) rhythmic-bin value (in quarter notes).
- Parameters:
- Returns:
Shortest quantized rhythmic-bin ideal value in quarter notes (0.0 if empty)
- Return type:
Note
This returns the ideal value of the shortest occupied histogram bin, not the raw minimum note duration.
- longest_rhythmic_value(starts, ends, tempo=120.0)[source]
The longest quantized rhythmic-bin value (in quarter notes).
- Parameters:
- Returns:
Longest quantized rhythmic-bin ideal value in quarter notes (0.0 if empty)
- Return type:
Note
This returns the ideal value of the longest occupied histogram bin, not the raw maximum note duration.
- mean_rhythmic_value(starts, ends, tempo=120.0)[source]
The mean quantized rhythmic value in quarter notes.
- Parameters:
- Returns:
Weighted mean rhythmic-bin ideal value in quarter notes (0.0 if empty)
- Return type:
Note
Uses histogram-bin ideal values rather than raw note durations.
- most_common_rhythmic_value(starts, ends, tempo=120.0)[source]
The modal quantized rhythmic value (in quarter notes).
- Parameters:
- Returns:
Modal rhythmic-bin ideal value in quarter notes (0.0 if empty or all-zero)
- Return type:
Note
Uses rhythmic-value mode from a 12-bin histogram. Differs from modal_duration, which computes a raw-duration mode in quarter-note units.
- prevalence_of_most_common_rhythmic_value(starts, ends, tempo=120.0)[source]
The proportion (0.0 - 1.0) of the modal rhythmic bin.
- relative_prevalence_of_most_common_rhythmic_values(starts, ends, tempo=120.0)[source]
The ratio of the second-most-common rhythmic bin to the most common bin.
- Parameters:
- Returns:
Ratio of the second-most-common rhythmic bin to the most common bin (0.0 if empty)
- Return type:
- difference_between_most_common_rhythmic_values(starts, ends, tempo=120.0)[source]
The absolute difference in bins between most and second most common rhythmic values.
- Parameters:
- Returns:
Absolute difference in bins between most and second most common rhythmic values (0.0 if empty)
- Return type:
- mean_rhythmic_value_run_length(starts, ends, tempo=120.0)[source]
The mean run length of identical rhythmic values across the melody. Run length is the number of consecutive notes with the same rhythmic value.
Returns 0.0 if there are fewer than 1 notes.
- median_rhythmic_value_run_length(starts, ends, tempo=120.0)[source]
The median run length of identical rhythmic values across the melody. Run length is the number of consecutive notes with the same rhythmic value.
- variability_in_rhythmic_value_run_lengths(starts, ends, tempo=120.0)[source]
The standard deviation of rhythmic value run lengths. Run length is the number of consecutive notes with the same rhythmic value.
- mean_rhythmic_value_offset(starts, ends, tempo=120.0)[source]
The mean quantized offset from the nearest ideal rhythmic value (in quarter notes).
- Parameters:
- Returns:
Mean quantized offset from the nearest ideal rhythmic value (in quarter notes) (0.0 if no durations)
- Return type:
- median_rhythmic_value_offset(starts, ends, tempo=120.0)[source]
The median quantized offset from the nearest ideal rhythmic value (in quarter notes).
- Parameters:
- Returns:
Median quantized offset from the nearest ideal rhythmic value (in quarter notes) (0.0 if no durations)
- Return type:
- variability_of_rhythmic_value_offsets(starts, ends, tempo=120.0)[source]
The standard deviation of rhythmic value offsets (in quarter notes).
- Parameters:
- Returns:
Standard deviation of rhythmic value offsets (in quarter notes) (0.0 if no durations)
- Return type:
- complete_rests_fraction(starts, ends, tempo=120.0, ppqn=480)[source]
The fraction of the total duration during which no pitched notes are sounding.
- Parameters:
- Returns:
Fraction of total duration during which no pitched notes are sounding (0.0 if no durations)
- Return type:
Note
This feature includes all complete silent runs (including those shorter than 0.1 quarter notes), whereas other complete-rest summary statistics apply a minimum 0.1 quarter-note threshold.
- longest_complete_rest(starts, ends, tempo=120.0, ppqn=480)[source]
The longest uninterrupted complete rest in quarter-note units (ignoring rests shorter than 0.1 QN).
- Parameters:
- Returns:
Longest uninterrupted complete rest in quarter-note units (0.0 if no durations)
- Return type:
- mean_complete_rest_duration(starts, ends, tempo=120.0, ppqn=480)[source]
The mean duration of complete rests in quarter-note units (ignoring rests shorter than 0.1 QN).
- Parameters:
- Returns:
Mean duration of complete rests in quarter-note units (0.0 if no durations)
- Return type:
- median_complete_rest_duration(starts, ends, tempo=120.0, ppqn=480)[source]
The median duration of complete rests in quarter-note units (ignoring rests shorter than 0.1 QN).
- Parameters:
- Returns:
Median duration of complete rests in quarter-note units (0.0 if no durations)
- Return type:
- variability_of_complete_rest_durations(starts, ends, tempo=120.0, ppqn=480)[source]
The standard deviation of complete rest durations in quarter notes (ignoring rests shorter than 0.1 QN).
- Parameters:
- Returns:
Standard deviation of complete rest durations in quarter notes (0.0 if no durations)
- Return type:
- strongest_rhythmic_pulse(starts, ends, tempo=120.0, ppqn=480)[source]
The bin index (BPM) of the maximum beat histogram magnitude.
- Parameters:
- Returns:
Bin index (BPM) of the maximum beat histogram magnitude (0.0 if no durations)
- Return type:
- strongest_rhythmic_pulse_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The bin index (BPM) of the maximum in the 120-BPM standardized beat histogram.
- Parameters:
- Returns:
Bin index (BPM) of the maximum beat histogram magnitude (0.0 if no durations)
- Return type:
- second_strongest_rhythmic_pulse(starts, ends, tempo=120.0, ppqn=480)[source]
The bin index (BPM) of the second-highest magnitude in the beat histogram.
- Parameters:
- Returns:
Bin index (BPM) of the second-highest magnitude in the beat histogram (0.0 if no durations)
- Return type:
- second_strongest_rhythmic_pulse_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The bin index (BPM) of the second-highest magnitude in the 120-BPM standardized beat histogram.
- Parameters:
- Returns:
Bin index (BPM) of the second-highest magnitude in the 120-BPM standardized beat histogram (0.0 if no durations)
- Return type:
- harmonicity_of_two_strongest_rhythmic_pulses(starts, ends, tempo=120.0, ppqn=480)[source]
The ratio of higher to lower bin index of the two strongest rhythmic pulses.
- Parameters:
- Returns:
Ratio of higher to lower bin index of the two strongest rhythmic pulses (0.0 if no durations).
- Return type:
Note
The first peak is selected from the raw beat histogram and the second peak is selected from the thresholded peak table (column 1), excluding the first peak bin.
- harmonicity_of_two_strongest_rhythmic_pulses_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The ratio of higher to lower bin index of the two strongest rhythmic pulses (120-BPM standardized histogram).
- Parameters:
- Returns:
Ratio of higher to lower bin index of the two strongest rhythmic pulses (120-BPM standardized histogram) (0.0 if no durations).
- Return type:
Note
The first peak is selected from the standardized histogram values from the standardized histogram values and the second peak is selected from the standardized thresholded peak table (column 1), excluding the first peak bin.
- strength_of_strongest_rhythmic_pulse(starts, ends, tempo=120.0, ppqn=480)[source]
The magnitude of the beat histogram bin with the highest magnitude.
- Parameters:
- Returns:
Magnitude of the beat histogram bin with the highest magnitude (0.0 if no durations)
- Return type:
- strength_of_strongest_rhythmic_pulse_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The magnitude of the tempo-standardized beat histogram bin with the highest magnitude.
- Parameters:
- Returns:
Magnitude of the tempo-standardized beat histogram bin with the highest magnitude (0.0 if no durations)
- Return type:
- strength_of_second_strongest_rhythmic_pulse(starts, ends, tempo=120.0, ppqn=480)[source]
The magnitude of the beat histogram bin with the second-highest magnitude.
- Parameters:
- Returns:
Magnitude of the beat histogram bin with the second-highest magnitude (0.0 if no durations)
- Return type:
- strength_of_second_strongest_rhythmic_pulse_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The magnitude of the tempo-standardized beat histogram bin with the second-highest magnitude.
- Parameters:
- Returns:
Magnitude of the tempo-standardized beat histogram bin with the second-highest magnitude (0.0 if no durations)
- Return type:
- strength_ratio_of_two_strongest_rhythmic_pulses(starts, ends, tempo=120.0, ppqn=480)[source]
Ratio of the magnitude of the strongest to second-strongest rhythmic pulse.
- Parameters:
- Returns:
Ratio of the magnitude of the strongest to second-strongest rhythmic pulse (0.0 if no durations)
- Return type:
- strength_ratio_of_two_strongest_rhythmic_pulses_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
Ratio of the magnitude of the strongest to second-strongest rhythmic pulse (120-BPM standardized histogram).
- Parameters:
- Returns:
Ratio of the magnitude of the strongest to second-strongest rhythmic pulse (120-BPM standardized histogram) (0.0 if no durations)
- Return type:
- combined_strength_of_two_strongest_rhythmic_pulses(starts, ends, tempo=120.0, ppqn=480)[source]
Sum of the magnitudes of the two strongest rhythmic pulses.
- Parameters:
- Returns:
Sum of the magnitudes of the two strongest rhythmic pulses (0.0 if no durations)
- Return type:
- combined_strength_of_two_strongest_rhythmic_pulses_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
Sum of the magnitudes of the two strongest rhythmic pulses using tempo-standardized histogram.
- Parameters:
- Returns:
Sum of the magnitudes of the two strongest rhythmic pulses using tempo-standardized histogram (0.0 if no durations)
- Return type:
- rhythmic_variability(starts, ends, tempo=120.0, ppqn=480)[source]
The standard deviation of the beat histogram bin magnitudes, excluding the first 40 bins.
- Parameters:
- Returns:
Standard deviation of the beat histogram bin magnitudes, excluding the first 40 bins (0.0 if no durations)
- Return type:
- rhythmic_variability_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The standard deviation of the tempo-standardized beat histogram bin magnitudes, excluding the first 40 bins.
- Parameters:
- Returns:
Standard deviation of the tempo-standardized beat histogram bin magnitudes, excluding the first 40 bins (0.0 if no durations)
- Return type:
- rhythmic_looseness(starts, ends, tempo=120.0, ppqn=480)[source]
The average width of beat histogram peaks. Width is defined as the distance between points at 30% of the peak height.
- Parameters:
- Returns:
Average width of beat histogram peaks (0.0 if no durations)
- Return type:
- rhythmic_looseness_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The average width of beat histogram peaks using tempo-standardized histogram. Width is defined as the distance between points at 30% of the peak height.
- Parameters:
- Returns:
Average width of beat histogram peaks using tempo-standardized histogram (0.0 if no durations)
- Return type:
- polyrhythms(starts, ends, tempo=120.0, ppqn=480)[source]
The fraction of strong beat-histogram peaks related to the strongest peak.
Among peaks at least 30% as tall as the maximum, returns the proportion whose bin is an integer multiple/factor of the strongest (multipliers 1, 2, 3, 4, 6, 8; ±3 bins).
- Parameters:
- Returns:
hits / n_peaks, or 0.0 if there are no qualifying peaks.
- Return type:
- polyrhythms_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The fraction of strong beat-histogram peaks related to the strongest peak using the tempo-standardized beat histogram.
Among peaks at least 30% as tall as the maximum, returns the proportion whose bin is an integer multiple/factor of the strongest (multipliers 1, 2, 3, 4, 6, 8; ±3 bins).
- Parameters:
- Returns:
hits / n_peaks, or 0.0 if there are no qualifying peaks.
- Return type:
- number_of_strong_rhythmic_pulses(starts, ends, tempo=120.0, ppqn=480)[source]
The count of BPM bins with strong rhythmic pulses (> 0.1 in the underlying beat histogram).
- Parameters:
- Returns:
Count of BPM bins 40-200 with a thresholded strong-pulse value (> 0.1 in the underlying beat histogram), or 0.0 if no durations.
- Return type:
- number_of_strong_rhythmic_pulses_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The count of BPM bins with strong pulses (> 0.1 in the underlying standardized beat histogram).
- Parameters:
- Returns:
Count of BPM bins 40-200 with a thresholded strong-pulse value (> 0.1 in the underlying standardized histogram), or 0.0 if no durations.
- Return type:
- number_of_moderate_rhythmic_pulses(starts, ends, tempo=120.0, ppqn=480)[source]
The number of beat histogram peaks with normalized magnitudes over 0.01.
- Parameters:
- Returns:
Number of beat histogram peaks with normalized magnitudes over 0.01 (0.0 if no durations)
- Return type:
- number_of_moderate_rhythmic_pulses_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The number of tempo-standardized beat histogram peaks with normalized magnitudes over 0.01.
- Parameters:
- Returns:
Number of tempo-standardized beat histogram peaks with normalized magnitudes over 0.01 (0.0 if no durations)
- Return type:
- number_of_relatively_strong_rhythmic_pulses(starts, ends, tempo=120.0, ppqn=480)[source]
The number of peaks at least 30% of the max magnitude.
- Parameters:
- Returns:
Number of peaks at least 30% of the max magnitude (0.0 if no durations)
- Return type:
- number_of_relatively_strong_rhythmic_pulses_tempo_standardized(starts, ends, tempo=120.0, ppqn=480)[source]
The number of tempo-standardized peaks at least 30% of the max magnitude.
- Parameters:
- Returns:
Number of tempo-standardized peaks at least 30% of the max magnitude (0.0 if no durations)
- Return type:
- equal_duration_transitions(starts, ends, tempo=120.0)[source]
The proportion of duration transitions that are equal in length.
- Parameters:
- Returns:
float – Proportion of equal duration transitions (0.0 to 1.0)
Citation
——–
Steinbeck (1982)
- Return type:
- half_duration_transitions(starts, ends, tempo=120.0)[source]
The proportion of duration transitions that are halved or doubled.
- Parameters:
- Returns:
float – Proportion of half/double duration transitions (0.0 to 1.0)
Citation
——–
Steinbeck (1982)
- Return type:
- dotted_duration_transitions(starts, ends, tempo=120.0)[source]
The proportion of duration transitions that are dotted.
- Parameters:
- Returns:
float – Proportion of dotted duration transitions (0.0 to 1.0)
Citation
——–
Steinbeck (1982)
- Return type:
- amount_of_staccato(starts, ends)[source]
The proportion of notes with a duration shorter than 0.1 seconds.
- Parameters:
- Returns:
Fraction of notes shorter than 0.1 seconds
- Return type:
Note
Though this feature is named Amount Of Staccato, it is a fixed-duration cutoff statistic rather than symbolic articulation parsing.
- npvi(starts, ends, tempo=120.0)[source]
The normalized Pairwise Variability Index (nPVI) of note durations in quarter notes. The nPVI measures the durational variability of events, originally developed for language research to distinguish stress-timed vs. syllable-timed languages. Applied to music by Patel & Daniele (2003) to study the prosodic influences on musical rhythm.
- onset_autocorrelation(starts, ends, divisions_per_quarter=4, max_lag_quarters=8, tempo=120.0, tempo_changes=None)[source]
The autocorrelation function of onset times weighted by duration accents. This is calculated by weighting the onset times by the duration accents, as defined by Parncutt (1994).
Onsets are converted to quarter-note beats using tempo before grid quantization.
- Parameters:
- Returns:
list[float] – Normalized autocorrelation from lag 0 through max_lag_quarters quarters
Citation
——–
Parncutt (1994)
- Return type: