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 GH#16363: Accidentals in chord symbols rendered incorrectly when using custom XML file #22541

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jojo-Schmitz
Copy link
Contributor

Resolves: #16363

@Jojo-Schmitz Jojo-Schmitz force-pushed the broken-chord-symbols branch 3 times, most recently from bdab1b0 to 0690feb Compare April 23, 2024 13:43
if (!code.startsWith(u"0x") && !code.startsWith(u"0") && !code.startsWith('&') && !code.endsWith(';')) {
// fix broken chord lists, see https://github.com/musescore/MuseScore/issues/16363
code = u"0x" + code;
}
bool ok = true;
char32_t val = code.toUInt(&ok, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

If code.startsWith('&') is true, then this would fail anyway. Does this case occur at all?
If not, let's not check for it, because that only makes the code noisy
If yes, we should add proper handling for that case.

However, I'm not very confident whether I like this approach; it means that our String::number method behaves differently from QString::number, which seems a potential source of confusion.
Wouldn't the problem be fixed instantly if you do

Suggested change
char32_t val = code.toUInt(&ok, 0);
char32_t val = code.toUInt(&ok, 16);

and drop all other changes? Or is it not certain that it will be a base16 number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If code.startsWith('&') is true, then this would fail anyway. Does this case occur at all? If not, let's not check for it, because that only makes the code noisy If yes, we should add proper handling for that case.

We don't have full control over the content of a chords.xml, it could contain ♭ (@MarcSabatella even recommeded the latter in the issue as a workaround, #16363 (comment)).

The toUInt(..., 0) would fail on it (as would a toUInt(..., 16)), but return the string unchanged, as far as I understand.

Be generous in what you accept, but strict in what you generate ;-) (and that's why toUInt(..., 0) exists)

However, I'm not very confident whether I like this approach; it means that our String::number method behaves differently from QString::number, which seems a potential source of confusion. Wouldn't the problem be fixed instantly if you do
...
and drop all other changes? Or is it not certain that it will be a base16 number?

The problem isn't that toUInt()doesn't return a hex number, but that this number as a string doesn't look like one to the writer because of the missing "0x".
Also, as said above, it might be an octal number od a string with an HTML entity, we don't have full control over the content of these files.

But we can leave the String::number() as it was and just do it like in the 1st commit and prepend the "0x" there,
after all we do know though that we write as hex there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can understand your concerns reg. different behavoir of String::number() vs. QString::number(), so reverted that 2nd commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And we may not need the read fix at all, as save/close/open fixes the issue too, its just nice to have, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW: this would work too:

                        int base = 0; // guess, based on content
                        if (!code.startsWith(u"0") && !(code.startsWith(u"&#") && code.endsWith(u";"))) {
                            // fix broken chord lists, see https://github.com/musescore/MuseScore/issues/16363
                            base = 16; // force hex
                        }
                        bool ok = true;
                        char32_t val = code.toUInt(&ok, base);

And it does read that ♭ too, not a © though, toUInt() (or rather rather std::strtol()) probably just ignores all the non-alpha-numerical chars and (rightfully) interprets the rest as decimal.

@Jojo-Schmitz Jojo-Schmitz force-pushed the broken-chord-symbols branch 5 times, most recently from 24cee54 to 7fcc2b6 Compare April 24, 2024 07:55
@Jojo-Schmitz
Copy link
Contributor Author

Came up again in https://musescore.org/en/node/364348

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.

[MU4 Issue] Accidentals in chord symbols rendered incorrectly when using custom XML file
2 participants