Duration pair distributions

Duration pair distributions#

This example demonstrates how to calculate and visualize the pair-wise duration distribution of notes in a MIDI file.

Duration Pairs Distribution
In readscore: importing prettymidi-based midi reader.
Duration pair distribution: [[0.3566666666666667, 0.0, 0.04666666666666667, 0.0, 0.0, 0.01, 0.0033333333333333335, 0.0033333333333333335, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.05, 0.0, 0.4266666666666667, 0.0, 0.023333333333333334, 0.006666666666666667, 0.006666666666666667, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.023333333333333334, 0.0, 0.016666666666666666, 0.0, 0.0, 0.0, 0.0], [0.013333333333333334, 0.0, 0.0033333333333333335, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]] ['sixteenth', '0.35', 'eighth', '0.71', 'quarter', '1.41', 'half', '2.83', 'whole'] ['sixteenth', '0.35', 'eighth', '0.71', 'quarter', '1.41', 'half', '2.83', 'whole'] Duration (to) Duration (from)

from amads.algorithms import duration_distribution_2
from amads.io import import_midi
from amads.music import example

# Load example MIDI file
my_midi_file = example.fullpath("midi/sarabande.mid")

# Import MIDI using partitura
myscore = import_midi(my_midi_file, show=False)
# myscore.show()

# Calculate duration distribution
dd = duration_distribution_2(myscore)
fig = dd.plot()

print(
    "Duration pair distribution:",
    dd.data,
    dd.x_categories,
    dd.y_categories,
    dd.x_label,
    dd.y_label,
)

Total running time of the script: (0 minutes 0.120 seconds)

Gallery generated by Sphinx-Gallery