Cross-staff slurs/ties trying to avoid note on wrong staff

• Dec 1, 2018 - 20:24
Reported version
P0 - Critical
S3 - Major

1) load attached score

Result as shown:


Bar two has the last note moved to the bottom staff using cross staff notations; bar three has the last note actually entered onto the bottom staff directly. Either way, creating a slur that ends on this note is showing an obviously wrong endpoint, far too high.

Attachment Size
cross-staff-slur.mscz 5.27 KB


Priority P1 - High P0 - Critical

I realize now it's not just cross-staff notation in the sense of notes moved from one staff to another with Ctrl+Shift+Up/Down, internally) - it's also slurs that connect notes on different staves with no cross-staff movement involved. So, it's not about checking staffMove() somewhere, it's about checking the vStaffIdx() probably, and adding in an offset I guess. I thought spanners were generally calculated relative to the system but it seems they are actually relative to the staff - maybe that was changed as part of the "new" layout?

Ties between cross-staff notes have the same issue.

Thinking a little more, I think we have a chicken-and-egg problem. Right now I assume we layout slurs before finalizing staff distance, because in fact the existence of slurs can increase staff distance. So at the point of slur layout, we don't know the relative position of staves.

So my thinking we is, if we detect a cross-staff slur or tie, we should disable autoplace (results would probably be disastrous anyhow) and somehow mark it as needing attention. Then do a second pass to fix up the cross-staff slurs and ties after we've finalized staff positions.

I still feel this would be very important to get right before release, but am not sure it makes sense for me to tackle that right now.

As an experiment, I tried to postpone cross-staff slurs layout to the moment after finishing Y placement of staves and made slur positions calculations take note staff into account (though I could miss something there). Sometimes the results are more or less sane:
... and sometimes even worse than they were before:

It seems that cross-staff slurs layout would require not only taking into correct notes positions into account but also some tweaks to automatic slur direction choosing and making autoplacement not so aggressive in moving slurs out of staves.

Thanks for looking, and indeed, I don't expect this to be trivial. Might need to pass on this for initial release, but who knows. But do note my pending PR regarding relative layout of articulations & slurs ( which probably touches some of the same code. To me, the articulation is higher priority as it's likely to affect many more scores, even if the current results aren't as dramatically bad.

So I just realize "note anchored lines" (a little-known feature, can only be added from the Add menu, directly connects two notes) actually does work across staves. Badly at first in that when you try to add one by Ctrl+clicking two notes then using the menu, it adds above the top staff of the system regardless of what staves you are actually connecting. But, if you turn off autoplace, the line jumps right back down to where it belongs, and it does track changes in staff distance, so it's basically doing the right thing.

The line gets added as a TextLine apparently but is "owned" by the note, using Spanner::Anchor::NOTE (same anchor type used for ties). Hmm. Probably there is a solution here.

Note anchored lines are handled toward the end of the loop in collectPage() right after ties, but then again a few later as part of Measure::layout2(). Probably we don't need both and could lose the calls within collectPage() itself. I'm thinking it's Measure::layout2() that would be the sensible place to handle cross-staff slurs, but only if we can get cross-staff ties working too (well, "regular" ties but between cross-staff notes), so I'm trying that first.

EDIT: both of those calls are no-ops - they called tie->layout() which doesn't actually do anything. Real layout happens in layoutFor() an layoutBack(), which are called in layoutSystemElements(), somewhat later than slurs but still too soon.

Probably you are discovering similar things, but maybe that's helpful information. I think that's as far as I'm getting tonight.

Surprisingly, while the symptom is very similar (line display above top of system), the causes was totally different. But my PR for that issue fixes both.

Status PR created active

No, sorry that was confusing. That PR fixes regular lines above top staff and again more lines above top staff even though cause we're very different. Cross staff slurs are not part of the PR.

Priority P0 - Critical P1 - High
Workaround No Yes

We definitely must fix this issue, but it is too complex and too rare in common use cases. Workaround is to manually adjust the slurs position.

For the record, cross-staff notation in general and cross-staff slurs are not uncommon at all in piano music, but given the complexity of the issue and the risk involved with the sort of structural change that would probably be needed to fix this, I agree it is better to live with it for now.

Workaround Yes No

Yes, it's not uncommon. Just stumbled upon this bug. Can you at least fix the position of the slur, when it is not cross-staff, but when all notes moved as a whole to the next staff? Here is an example from Clementi's Sonatina in G Major, Op. 36, No. 2.

Thanks for the offer! You are of course welcome to participate in development however you like - MuseScore is open sour e, after all. See the Contribute menu above, then click Development.

I can say that this particular problem isn't much about math. But one that is is handling cases like a slur between three notes - middle line B, B an octave higher, then back to middle line B. We draw the slur too flat, so the endpoints end up too far from the start and end notes:


We use a bezier curve algorithm to draw the slur with no consideration to how curved it will actually need to be to clear the high B in the middle. I have ideas on how to improve the algorithm to draw a more curved slur in these cases, so we'd get something more like this:


But I am not confident on how to get the math right (hard to admit for a math major, but my specialty was abstract math, not applied...)

In reply to by Marc Sabatella

Marc, I am talking about another problem. Or at least I don't understand how they are connected. See my Clementi example. When I move the notes to the lower staff (Ctrl+Shift+DownArrow), the slur remains completely at the top staff. It has nothing to do with the curvature of the slur, it's just painted in the wrong place completely. Should I file another bug for that?

I can help with the curvature math as well, of course. :)

Sorry for being confusing. I get these are different. I just meant, if you're looking to help, and your specialty is math, it's the curvature issue that we could use help with. The cross-staff slur problem I think we have something of a handle on, and it's not a math problem at all but one of the data structures and algorithms, so perhaps harder for a newcomer to the code to deal with anyhow.

Using the 3.0 stable version.

I think I found the origin of the problem. When I used click the start note then ctrl+click the note in the other staff, the anchor is set to be in the original staff. This is difficult to see, because the anchor point is not drawn while in edit mode. If you grab the endpoint that should be in the other staff, you will see it is still in the original staff.

cross staff slur.gif

I see no way to anchor the slur in the other staff. Using shift+up arrow should change the anchor to the other staff, but this does not work. The best you can hope for it to make it look right, and this is a deal breaker for the Blind user I'm trying to make this score for.

Priority P1 - High P0 - Critical

There is indeed no way to get this right currently. There has been some work to try to address this but I think it's not ready. Absolutely a very high priority.

Status active PR created

The following PR should fix things for both slurs and ties, both for cases where the notes themselves are cross-staff and when they are simply on different staves "for real". Ties work whether one or both notes are moved. It's not a big change, and shouldn't affect layout in any cases except cross-staff, except for fixing a small glitch with the layout of ties between enharmonic notes along the way.

Fix version