fix #109021: wandering lines due to bad barline widths on load #3055
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This might not fix all the cases of so-called "wandering hairpins" that people have encountered, but it fixes the couple I have been able to reproduce. Namely, the one in https://musescore.org/en/node/109021 and the one in https://musescore.org/en/node/180601#comment-672671. Both were due to a discrepancy in the widths of a few measures resulting from a miscalculation of the widths of repeat barlines. I tracked it down to a simple root cause: a "double" scaling down the barline width in cases where the score spatium is less than the nominal 1.764mm. The same miscalculation happened with system barlines, so I applied the same simple fix there.
As I sad, I do not claim this will fix all cases of wandering hairpins et al. So I left in place a couple of commented-out qDebug statements that were key in helping me track down this particular problem. They just print the minimum widths of each measure as calculated during system layout, so we can compare the result on initial load versus after first relayout. Any discrepancy that leads to a measure jumping from one page to another will also result in wandering hairpins, so it just becomes a matter of figuring out where the discrepancy comes from. Chances are problems may still lurk in the the handling of other generated elements (headers, courtesy elements, etc). But again, the cases I can reproduce actually work out perfectly for all measures (width on load same as after first relayout) except those with repeat barlines, and this PR fixes that so these also work out perfectly.