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 MS #314800 Add Ledger Lines to Key Signatures #10488

Merged
merged 1 commit into from
Jul 4, 2022

Conversation

sammik
Copy link
Contributor

@sammik sammik commented Feb 8, 2022

Resolves: (MS #314800)

Added ledger lines to key signatures. If accidental was above, or belove staff, ledger lines were missing and it was difficualt to recognize its position. Now it is fixed.

Possible conflicts with #10609, will need to rebase on top of it.
Rebased on top of current master.

  • I signed CLA
  • I made sure the code in the PR follows the coding rules
  • I made sure the code compiles on my machine
  • I made sure there are no unnecessary changes in the code
  • I made sure the title of the PR reflects the core meaning of the issue you are solving
  • I made sure the commit message(s) contain a description and answer the question "Why do those changes fix that particular issue?" or "Why are those changes really necessary as improvements?"
  • I made sure the commit message title starts with "fix #424242:" if there is a related issue
  • I created the test (mtest, vtest, script test) to verify the changes I made

@sammik
Copy link
Contributor Author

sammik commented Feb 8, 2022

KeySig-LedgerLines

drawSymbol(SymId::legerLine, painter, PointF((ks.pos.x() - xshift), (_line * _spatium)));
++_line;
}
while (_line >= 5) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you assume that a staff has 5 lines, but that might not always be the case. Better use staff() ? staff()->staffTypeForElement(this)->lines() : 5 instead of 5. As an optimization, you could take that out of the for-loop and store it in a variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you'll also need to account for staff line distance. Look at this failing VTest for example:
Schermafbeelding 2022-02-08 om 11 06 49
It's just a 5-line staff, but with a staff line spacing of 2.50 sp.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't staff() ? staff()->staffTypeForElement(this)->lineDistance().val() : 1.0; help here?

Copy link
Contributor Author

@sammik sammik Feb 8, 2022

Choose a reason for hiding this comment

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

Scaling bug for ledger lines seems to be fxed now:
Ledger_spacing
Found another bug, but it is not caused by this PR (already there in 3.6.2) - scaling misplaces accidentals in custom key signatures #10497

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I would expect the distance between the ledger lines to be the same as the distance between the staff lines. That of course relates to the other bug you just discovered. If you would like to solve that bug yourself (while on it), I could assign it to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, that VTest still seems to fail the same way as before... you will indeed need to use staff() ? staff()->staffTypeForElement(this)->lineDistance().val() : 1.0;, as Jojo suggests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, distance should be same, as distance between lines, but as you can see, ledger lines corresponds with accidentals. I will chek something. Thank You.
One question staff()->staffTypeForElement(this)->lineDistance().val() or staff()->lineDistance(tick()) would be OK?

Copy link
Contributor

Choose a reason for hiding this comment

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

The latter looks simpler, but for symmetry alone I'd rather use the former?

Copy link
Contributor

Choose a reason for hiding this comment

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

The former contains a small optimization compared to the latter, because it avoids a call to tick() in case there is only one staff type on that staff (which is the case in most scores, I'd think). For some elements, tick() is a very trivial call, but for others, it involves a bit more.

Jojo-Schmitz added a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 8, 2022
qreal _spatium = spatium();
qreal xshift = (ks.sym == SymId::accidentalSharp) ? (_spatium * .15) : (_spatium * .25);
int y = int(ks.spos.y());
int staffLines = staff() ? staff()->staffTypeForElement(this)->lines() : 5;
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Feb 8, 2022

Choose a reason for hiding this comment

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

Maybe better move this line to before the for loop?

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 8, 2022
@sammik sammik force-pushed the key-sig-ledger-lines branch from 0717dfc to d748d71 Compare February 8, 2022 18:48
@@ -315,6 +315,19 @@ void KeySig::draw(mu::draw::Painter* painter) const
painter->setPen(curColor());
for (const KeySym& ks: _sig.keySymbols()) {
drawSymbol(ks.sym, painter, PointF(ks.pos.x(), ks.pos.y()));
// draw ledgerLines
qreal _spatium = spatium();
qreal xshift = (ks.sym == SymId::accidentalSharp) ? (_spatium * .15) : (_spatium * .25);
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Feb 8, 2022

Choose a reason for hiding this comment

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

Maybe make this qreal x = ks.pos.x() - (ks.sym == SymId::accidentalSharp) ? (_spatium * .15) : (_spatium * .25); and use that in the 2 drawSymbol() calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, they are never called both, every time just one of them, so what is the reason for this change? Pretyfng code?

Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz Feb 8, 2022

Choose a reason for hiding this comment

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

Ah, I missed that. but it won't harm anyway

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 8, 2022
@sammik
Copy link
Contributor Author

sammik commented Feb 8, 2022

I hope, finaly its fixed.
Thank You @Jojo-Schmitz and @cbjeukendrup for Your patience and help!
Ledger_spacing
(It looks may be weird a bit, because of that other bug.)

@Jojo-Schmitz
Copy link
Contributor

Jojo-Schmitz commented Feb 9, 2022

Hmm, my backport to 3.x doesn't work well:
image
using the sample score from #10497, maybe that's why.

Have a sample score to test this? Preferably for MuseScore 3?

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 9, 2022
@sammik
Copy link
Contributor Author

sammik commented Feb 9, 2022

Hmm, my backport to 3.x doesn't work well

Somehow one line became wrong in Your backport.
Jojo-Schmitz@4ba24e6#r66315029

for (const KeySym& ks: _sig.keySymbols()) {
drawSymbol(ks.sym, painter, PointF(ks.pos.x(), ks.pos.y()));
// draw ledgerLines
qreal x = ks.pos.x() - ((ks.sym == SymId::accidentalSharp) ? (_spatium * .15) : (_spatium * .25));
int i = int(ks.spos.y() / lineDist);
Copy link
Contributor

Choose a reason for hiding this comment

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

This kind of casts are frowned upon, in master at least, better use the more verbose static_cast<int>(...)

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 9, 2022
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 9, 2022
@sammik sammik force-pushed the key-sig-ledger-lines branch from ee5bc8d to 87f8a5f Compare February 9, 2022 14:47
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 9, 2022
@sammik sammik requested a review from cbjeukendrup February 9, 2022 21:30
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 10, 2022
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 14, 2022
@cbjeukendrup
Copy link
Contributor

cbjeukendrup commented Feb 18, 2022

@sammik I think it would be good if we would merge #10609 first, and then you rebase this PR on top of it. So could you please fix the review comments on that PR?

@sammik
Copy link
Contributor Author

sammik commented Feb 18, 2022

@sammik I think it would be good if we would merge #10609 first, and then you rebase this PR on top of it. So could you please fix the review comments on that PR?

Sorry, I was playing.
It should be fixed, so once it will be merged, Ill rebase this one.

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 24, 2022
@sammik sammik force-pushed the key-sig-ledger-lines branch from 87f8a5f to 4ce902c Compare May 1, 2022 06:28
@sammik
Copy link
Contributor Author

sammik commented May 1, 2022

vtests failure is good

before
custom-keysig-2-1 ref

after
custom-keysig-2-1

@sammik sammik force-pushed the key-sig-ledger-lines branch 2 times, most recently from d653437 to 52a72ad Compare May 10, 2022 14:22
@sammik
Copy link
Contributor Author

sammik commented May 10, 2022

@cbjeukendrup may I kindly ask for vtest label?

@cbjeukendrup cbjeukendrup added the vtests This PR produces approved changes to vtest results label May 10, 2022
@cbjeukendrup
Copy link
Contributor

Added!

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request May 12, 2022
@sammik sammik force-pushed the key-sig-ledger-lines branch from 52a72ad to 677c8d2 Compare July 1, 2022 21:33
@cbjeukendrup
Copy link
Contributor

I had another look at this today, and I thought, maybe we should not use the SymId::legerLine etc. symbols, but instead, just draw lines, using the Painter object. This enables us to make the line length dynamic, so that it will be good for every accidental regardless of how wide it is. It also enables us to follow the ledger line thickness specified in the style settings. This is how it is done for chords too. Probably a good example of this is in ShadowNote::draw. The relevant Sids are Sid::ledgerLineLength (the amount to be added at each side of the accidental) and Sid::ledgerLineWidth (the line thickness).

@sammik sammik force-pushed the key-sig-ledger-lines branch from 677c8d2 to 225a04f Compare July 3, 2022 22:33
@sammik
Copy link
Contributor Author

sammik commented Jul 3, 2022

I had another look at this today, and I thought, maybe we should not use the SymId::legerLine etc. symbols, but instead, just draw lines, using the Painter object. This enables us to make the line length dynamic, so that it will be good for every accidental regardless of how wide it is. It also enables us to follow the ledger line thickness specified in the style settings. This is how it is done for chords too. Probably a good example of this is in ShadowNote::draw. The relevant Sids are Sid::ledgerLineLength (the amount to be added at each side of the accidental) and Sid::ledgerLineWidth (the line thickness).

Done!

@cbjeukendrup cbjeukendrup merged commit 5a006a4 into musescore:master Jul 4, 2022
@sammik sammik deleted the key-sig-ledger-lines branch July 4, 2022 11:57
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vtests This PR produces approved changes to vtest results
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants