cuthbertLab / music21j

Javascript port of music21 -- Toolkit for Computational Musicology
Other
147 stars 43 forks source link

Stream.noteElementFromScaledX(): handle note overlaps #217

Closed vanderstel closed 1 year ago

vanderstel commented 1 year ago

Background

Stream.noteElementFromScaledX() returns a note n from the stream whose leftmost x position (n.x) and rightmost x position (n.x + n.width) are within allowablePixels of the given x position. If no note falls within this range, we select the note whose leftmost and rightmost x positions are nearest to x.

Problem

It is possible for a note's rightmost x position to overlap with the next note's leftmost position. If n1 ends at 123 and n2 begins at 120, then an x value of 121 will return n2, but 122 will return n1!

Solution

The current PR fixes this issue by truncating note widths so that n1 never ends after n2 begins.

mscuthbert commented 1 year ago

Perfect. Thank you!