cuthbertLab / music21j

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

Calculate Part estimated staff length based on longest system #227

Closed vanderstel closed 1 year ago

vanderstel commented 1 year ago

Part.estimateStaffLength() calculates the staff length by incrementing measure lengths until reaching a measure with startNewSystem, at which point it exits. The problem with this approach is that different systems can have different estimated lengths, so any system that is longer than the first one will appear visually to be truncated when the Part is rendered to the DOM.

This PR instead calculates the lengths of all systems and then selects the longest length as the estimated length of the Part as a whole.

Small note for those who are curious: previously, when calculating the length of the first system we also included the length the first measure that appeared after the system break (i.e. the measure with startNewSystem). This seemed wrong, but was in fact necessary as it ensured that most subsequent parts did not get truncated despite the issue outlined above. (See a comment in the old code: this looks wrong, but actually seems to be right. moving it to after the break breaks things.) This hack is no longer necessary, so we now exit right at the system break like you would expect.