Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #305487: Invisible accidentals take space #6100

Merged

Conversation

mattmcclinch
Copy link
Contributor

@MarcSabatella
Copy link
Contributor

What would you think about changing those tests from visible() to addToSkyline()? Admittedly this isn’t the actual skyline, but also I probably didn’t choose the best name for that function, as I think I use it a couple of other places where it isn’t literally about the skyline.

Anyhow the point is to also disable these same things if autoplace is turned off. The advantage would be allowing accidental on a note in one voice to tuck under/over notes in other voices (they already do for rests even without disabling autoplace).

@mattmcclinch
Copy link
Contributor Author

I think the point of #305487 is that invisible accidentals should not take space, but I could be wrong. Testing for addToSkyline() instead of visible() is not the answer, but I could see testing for both.

@mattmcclinch
Copy link
Contributor Author

Oh, I see. addToSkyline() returns false if the element is invisible. Very well then. I will modify this PR accordingly.

@MarcSabatella
Copy link
Contributor

Of course I’ll want to test to make sure this really does work as expected, I hadn’t originally thought of maki g the change anywhere but layoutPitched(). I’ll look into this more later today. Originally I had punted in doing anything with that issue thinking it made more sense to wait for MuseScore 4, but this could actually be a good opportunity to do just this much and make a difference for those who care about such things.

@Harmoniker1
Copy link
Contributor

@MarcSabatella What is "skyline"?

@MarcSabatella
Copy link
Contributor

#6100 (comment)

The skyline is the heart and soul of autoplace. It’s the shape you get if you draw a zigzag line across the top of the staff, accounting for all elements that are above sticking out from the staff. We do most collision detection against this shape, not the individual elements themselves.

@MarcSabatella
Copy link
Contributor

I think we should also add a check in hasAccidental(), a static function in measure.cpp. Otherwise, if the first note of a measure has an invisible accidental, we use the barline-to-accidental style setting rather than barline-to-note.

@MarcSabatella
Copy link
Contributor

Dang it, I added some review comments, or so I thought, then apparently lost them somehow. Will re-add now.

@Jojo-Schmitz
Copy link
Contributor

Jojo-Schmitz commented May 20, 2020

I don't understand how your current changes could possibly cause those mtest failures in the guitar pro tests? See https://travis-ci.org/github/musescore/MuseScore/jobs/689317166#L4353-L4917

Edit I see, #6101 seems the culprit, brown bag for me... (and for a quite stupid GP 3,4,5 import)
Should be fixed with #6103

Copy link
Contributor

@MarcSabatella MarcSabatella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left review comments. The most important is the one regarding the accidental stacking code - the PR as is will lose accidentals "completely" (as far as the layout is concerned) on reload.

@@ -841,7 +841,7 @@ void Score::layoutChords3(std::vector<Note*>& notes, const Staff* staff, Segment
for (int i = nNotes-1; i >= 0; --i) {
Note* note = notes[i];
Accidental* ac = note->accidental();
if (ac && !note->fixed()) {
if (ac && ac->addToSkyline() && !note->fixed()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work correctly - it causes the layout to be skipped entirely. That means, among other things, the invisible or non-autoplaced accidental will disappear completely on save/reload.

Dealing with this will be tricky because of the interdependencies between accidentals on a single chord (which is what this code - some of the very first I contributed to MuseScore! - is dealing with). Ideally we want to still place the accidental where it would have been otherwise if it were visible and autoplaced, but we would not let this affect the position of other accidentals. But I'm not sure how feasible that is here.

The easiest answer would be to lose this particular change. This would be fine for chords with a single accidental.
But the downside would be, a single invisible accidental in the middle of a chord with multiple accidentals would leave a "gap" in the accidental stack, just as it does now.

Another possibility is to start the block so we still get the layout, but add an "if (!ac->visible()) continue;" right after the layout. Well, might be good to set some explicit x position, otherwise it will end up staying where it is when you first make it invisible, but then become 0 on save/reload. This wouldn't be acceptable for visible accidentals with autoplace turned off, though - they still need to stack normally.

Anything else would probably require deeper change to the accidental stacking algorithm further below, and I'm not even sure it would be possible to define a more sensible behavior.

@@ -3429,7 +3429,7 @@ Shape Note::shape() const
Shape shape(r, name());
for (NoteDot* dot : _dots)
shape.add(symBbox(SymId::augmentationDot).translated(dot->pos()), dot->name());
if (_accidental)
if (_accidental && _accidental->addToSkyline())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the purpose of making sure accidentals can tuck over/under other notes, this is not needed. Which is to say, it could be visible() instead of addToSkyline(). As it is, this change means non-autoplaced accidentals can not only tuck over/under, they can also collide with previous notes. I guess that's expected, although not what I was originally thinking might be nice. I suppose it's more of a hack, though, so I'm fine leaving this as you have it. Just wanted to mention it in case it sparks any additional thoughts.

@@ -3442,7 +3442,7 @@ Shape Note::shape() const
Shape shape(r);
for (NoteDot* dot : _dots)
shape.add(symBbox(SymId::augmentationDot).translated(dot->pos()));
if (_accidental)
if (_accidental && _accidental->addToSkyline())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I wonder if we could lose this NDEBUG duplication? Right now it buys us some better debug info on the shapes when compiling in debug mode, without a performance penalty otherwise. But maybe there is a less error-prone way of doing that? Way too easy for these two sections of code to get out of sync.

@@ -3442,7 +3442,7 @@ Shape Note::shape() const
Shape shape(r);
for (NoteDot* dot : _dots)
shape.add(symBbox(SymId::augmentationDot).translated(dot->pos()));
if (_accidental)
if (_accidental && _accidental->addToSkyline())
shape.add(_accidental->bbox().translated(_accidental->pos()));
for (auto e : _el) {
if (e->autoplace() && e->visible()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, not your code of course, but this could now be addToSkyline() too if we wanted.

@MarcSabatella
Copy link
Contributor

MarcSabatella commented May 20, 2020

FWIW, since I was implementing and testing my suggestions as I went along, here's my version. Main question to me would be what to actually assign as the x position for invisible accidentals. I used -width which places them just to left of the notehead. We could try to get fancy and leave a margin, account for ledger line, etc - or not.

https://github.com/MarcSabatella/MuseScore/tree/noauto-accidentals

This skips allocating space for accidentals if marked invisible
or no autoplace.
For accidentals marked invisible, they also don't affect stacking
of multiple accidentals.
@Jojo-Schmitz
Copy link
Contributor

For some strange reason GitHub shows the Travis job as Pending, but that finished successfully

@anatoly-os anatoly-os merged commit 4a053fc into musescore:3.x Jun 2, 2020
anatoly-os added a commit that referenced this pull request Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants