Note
Go to the end to download the full example code.
Boundary detection#
This example demonstrates how to detect boundaries in a MIDI file using the boundary detection algorithm.
import matplotlib.pyplot as plt
from amads.algorithms import boundary
from amads.io import import_midi, pianoroll
from amads.music import example
# Load example MIDI file
my_midi_file = example.fullpath("midi/tempo.mid")
# Import MIDI using partitura
myscore = import_midi(my_midi_file, show=False)
# Create piano roll visualization
fig = pianoroll(myscore)
# Detect boundaries and get strength values
strength_list = boundary(myscore)
print(strength_list)
# TODO: consider a graph sharing the same time axis as
# our score plot so that the "soft" boundary strengths could be
# accentuated. How do we visualize strength?
plt.show() # hello

In readscore: importing prettymidi-based midi reader.
draw note from 0.0 to 1.0020833333333334 at 66.5
draw note from 1.0020833333333334 to 2.002083333333333 at 63.5
draw note from 2.002083333333333 to 3.0020833333333337 at 66.5
draw note from 3.0020833333333337 to 4.002083333333334 at 64.5
draw note from 4.002083333333334 to 5.002083333333333 at 66.5
draw note from 5.002083333333333 to 6.002083333333334 at 63.5
draw note from 6.002083333333334 to 7.002083333333334 at 66.5
draw note from 7.002083333333334 to 8.002083333333333 at 70.5
draw note from 8.002083333333333 to 9.002083333333333 at 68.5
draw note from 9.002083333333333 to 10.002083333333333 at 70.5
draw note from 10.002083333333333 to 11.002083333333333 at 73.5
draw note from 11.002083333333333 to 12.002083333333333 at 70.5
draw note from 12.002083333333333 to 13.002083333333335 at 68.5
draw note from 13.002083333333335 to 14.002083333333333 at 66.5
draw note from 14.002083333333333 to 15.002083333333333 at 63.5
draw note from 15.002083333333333 to 16.00208333333333 at 66.5
[(0.0, 1), (1.0020833333333334, 0.0), (2.002083333333333, 0.07927028791578941), (3.0020833333333337, 0.05249999787500059), (4.002083333333334, 0.05249999787500076), (5.002083333333333, 0.07874999681250142), (6.002083333333334, 0.05625000093750052), (7.002083333333334, 0.25000000000000044), (8.002083333333333, 0.08749999937500054), (9.002083333333333, 0.05249999787500065), (10.002083333333333, 0.07874999681250064), (11.002083333333333, 0.07874999681250064), (12.002083333333333, 0.05249999787500087), (13.002083333333335, 0.05249999787500176), (14.002083333333333, 0.07874999681250197), (15.002083333333333, 4.440889878055691e-16)]
Total running time of the script: (0 minutes 0.098 seconds)