Boundary detection

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 partitura_midi_import, pianoroll
from amads.music import example

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

# Import MIDI using partitura
myscore = partitura_midi_import(my_midi_file, ptprint=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
plot boundary
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/partitura/io/importmidi.py:575: UserWarning: pitch spelling
  warnings.warn("pitch spelling")
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/partitura/io/importmidi.py:658: UserWarning: create_part
  part = create_part(
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/partitura/io/importmidi.py:658: UserWarning: add notes
  part = create_part(
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/partitura/io/importmidi.py:658: UserWarning: add time sigs and measures
  part = create_part(
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/partitura/io/importmidi.py:658: UserWarning: tie notes
  part = create_part(
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/partitura/io/importmidi.py:658: UserWarning: find tuplets
  part = create_part(
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/partitura/io/importmidi.py:658: UserWarning: done create_part
  part = create_part(
partitura_convert_part: after pass 1, measures are
[(1, 0, 1919), ('timesig', 4, 4), ('keysig', 0), (2, 1919, 3839), (3, 3839, 5759), (4, 5759, 7679), (5, 7679, 7681)]
div_to_quarter: div 1919 qtrs 4.0
div_to_quarter: div 0 qtrs 0.0
div_to_quarter: div 3839 qtrs 8.0
div_to_quarter: div 1919 qtrs 4.0
div_to_quarter: div 5759 qtrs 12.0
div_to_quarter: div 3839 qtrs 8.0
div_to_quarter: div 7679 qtrs 16.0
div_to_quarter: div 5759 qtrs 12.0
div_to_quarter: div 7681 qtrs 16.0
div_to_quarter: div 7679 qtrs 16.0
div_to_quarter: div 0 qtrs 0.0
ignoring 0-- Clef sign=G line=2 number=1
ignoring 0--1919 Measure number=1 name=1
ignoring 0-- TimeSignature 4/4
div_to_quarter: div 0 qtrs 0.0
Tempo start 0.0 tempo 1.6666666666666667
append_beat_tempo 1.6666666666666667 <amads.core.time_map.MapBeat object at 0x7f96103f6410>
ignoring 0-- KeySignature fifths=0, mode=major (C)
div_to_quarter: div 481 qtrs 1.0020833333333334
div_to_quarter: div 961 qtrs 2.002083333333333
div_to_quarter: div 1440 qtrs 3.0
Tempo start 3.0 tempo 1.8333318055568286
append_beat_tempo 1.8333318055568286 <amads.core.time_map.MapBeat object at 0x7f96103f4ac0>
div_to_quarter: div 1441 qtrs 3.002083333333333
div_to_quarter: div 1919 qtrs 3.997916666666667
ignoring 1919--3839 Measure number=2 name=2
div_to_quarter: div 1921 qtrs 4.002083333333333
div_to_quarter: div 2401 qtrs 5.002083333333333
div_to_quarter: div 2880 qtrs 6.0
Tempo start 6.0 tempo 1.499999250000375
append_beat_tempo 1.499999250000375 <amads.core.time_map.MapBeat object at 0x7f96103f57b0>
div_to_quarter: div 2881 qtrs 6.002083333333333
div_to_quarter: div 3361 qtrs 7.002083333333333
div_to_quarter: div 3839 qtrs 7.997916666666667
ignoring 3839--5759 Measure number=3 name=3
div_to_quarter: div 3841 qtrs 8.002083333333333
div_to_quarter: div 4320 qtrs 9.0
Tempo start 9.0 tempo 2.0
append_beat_tempo 2.0 <amads.core.time_map.MapBeat object at 0x7f96103f5780>
div_to_quarter: div 4321 qtrs 9.002083333333333
div_to_quarter: div 4801 qtrs 10.002083333333333
div_to_quarter: div 5281 qtrs 11.002083333333333
div_to_quarter: div 5759 qtrs 11.997916666666667
ignoring 5759--7679 Measure number=4 name=4
div_to_quarter: div 5760 qtrs 12.0
Tempo start 12.0 tempo 1.6666666666666667
append_beat_tempo 1.6666666666666667 <amads.core.time_map.MapBeat object at 0x7f96103f4460>
div_to_quarter: div 5761 qtrs 12.002083333333333
div_to_quarter: div 6241 qtrs 13.002083333333333
div_to_quarter: div 6720 qtrs 14.0
Tempo start 14.0 tempo 1.8333318055568286
append_beat_tempo 1.8333318055568286 <amads.core.time_map.MapBeat object at 0x7f96103f4610>
div_to_quarter: div 6721 qtrs 14.002083333333333
div_to_quarter: div 7201 qtrs 15.002083333333333
div_to_quarter: div 7679 qtrs 15.997916666666667
ignoring 7679--7681 Measure number=5 name=5
BEGIN retie_note ['Note', 3.002083333333333, 0.9958333333333333, None, 65, 'n3', True, <partitura.score.Note object at 0x7f96103f6e00>]
GROUP BEFORE:  [['Note', 3.002083333333333, 0.9958333333333333, None, 65, 'n3', True, <partitura.score.Note object at 0x7f96103f6e00>], ['Note', 3.997916666666667, 0.004166666666666667, None, 65, 'n3a', True, <partitura.score.Note object at 0x7f96103f74f0>]]
BEGIN retie_note ['Note', 4.0, 0, None, 65, 'n3a', True, <partitura.score.Note object at 0x7f96103f74f0>]
BEGIN retie_note ['Note', 7.002083333333333, 0.9958333333333333, None, 71, 'n7', True, <partitura.score.Note object at 0x7f96103f4df0>]
GROUP BEFORE:  [['Note', 7.002083333333333, 0.9958333333333333, None, 71, 'n7', True, <partitura.score.Note object at 0x7f96103f4df0>], ['Note', 7.997916666666667, 0.004166666666666667, None, 71, 'n7a', True, <partitura.score.Note object at 0x7f96103f7490>]]
BEGIN retie_note ['Note', 8.0, 0, None, 71, 'n7a', True, <partitura.score.Note object at 0x7f96103f7490>]
BEGIN retie_note ['Note', 11.002083333333333, 0.9958333333333333, None, 71, 'n11', True, <partitura.score.Note object at 0x7f96103f4c70>]
GROUP BEFORE:  [['Note', 11.002083333333333, 0.9958333333333333, None, 71, 'n11', True, <partitura.score.Note object at 0x7f96103f4c70>], ['Note', 11.997916666666667, 0.004166666666666667, None, 71, 'n11a', True, <partitura.score.Note object at 0x7f96103f5ea0>]]
BEGIN retie_note ['Note', 12.0, 0, None, 71, 'n11a', True, <partitura.score.Note object at 0x7f96103f5ea0>]
BEGIN retie_note ['Note', 15.002083333333333, 0.9958333333333333, None, 67, 'n15', True, <partitura.score.Note object at 0x7f96103f6110>]
GROUP BEFORE:  [['Note', 15.002083333333333, 0.9958333333333333, None, 67, 'n15', True, <partitura.score.Note object at 0x7f96103f6110>], ['Note', 15.997916666666667, 0.004166666666666667, None, 67, 'n15a', True, <partitura.score.Note object at 0x7f96103f6350>]]
BEGIN retie_note ['Note', 16.0, 0, None, 67, 'n15a', True, <partitura.score.Note object at 0x7f96103f6350>]
Something is wrong; could not find measure for ['Note', 16.0, 0, None, 67, 'n15a', True, <partitura.score.Note object at 0x7f96103f6350>]
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.002083333333333 at 66.5
draw note from 3.002083333333333 to 4.0 at 64.5
draw note from 4.002083333333333 to 5.002083333333333 at 66.5
draw note from 5.002083333333333 to 6.002083333333333 at 63.5
draw note from 6.002083333333333 to 7.002083333333333 at 66.5
draw note from 7.002083333333333 to 8.0 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.0 at 70.5
draw note from 12.002083333333333 to 13.002083333333333 at 68.5
draw note from 13.002083333333333 to 14.002083333333333 at 66.5
draw note from 14.002083333333333 to 15.002083333333333 at 63.5
draw note from 15.002083333333333 to 16.0 at 66.5
[(0.0, 1), (1.0020833333333334, 0.0), (2.002083333333333, 0.0792702879157893), (3.002083333333333, 0.05249999787500048), (4.002083333333333, 0.05354116478155189), (5.002083333333333, 0.07874999681250064), (6.002083333333333, 0.05625000093749986), (7.002083333333333, 0.25), (8.002083333333333, 0.08854116628155156), (9.002083333333333, 0.052499997875000426), (10.002083333333333, 0.07874999681250064), (11.002083333333333, 0.07874999681250064), (12.002083333333333, 0.05354116478155189), (13.002083333333333, 0.052499997875000426), (14.002083333333333, 0.07874999681250064), (15.002083333333333, 0.0)]

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

Gallery generated by Sphinx-Gallery