-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[MU3] Fix #311792: Override alter tag with note tuning value if present #6693
Conversation
You ticked the 2nd to last box of that PR comment template, but in the commit title forgot the # ;-) @lvinken mind to check, this being a MusicXML fix? |
Yes terribly sorry! I read the guidelines after pushing the commit... Do you have a suggestion to fix that? |
Quite simple: |
Thanks. I used the recipe at https://www.educative.io/edpresso/how-to-change-a-git-commit-message-after-a-push, because it was the second-to-last commit that needed a change. Out of curiosity, do you use the squash option during PR merge? |
No, usually not, we'd rather have the submitter to do it ;-) |
First remarks:
|
importexport/musicxml/exportxml.cpp
Outdated
@@ -3211,6 +3211,11 @@ static void writePitch(XmlWriter& xml, const Note* const note, const bool useDru | |||
default: break; | |||
} | |||
} | |||
// Override accidental with explicit note tuning | |||
auto tun = note->tuning(); | |||
if (fabs(tun) > 0.0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As MuseScore's UI allows tuning with 2 decimal digits only, and as comparing float
to 0.0
and using it as a bool
isn't a good idea anyway, maybe better use if (fabs(tun) > 0.01) {
, similar to how it is used in
MuseScore/mscore/musescore.cpp
Line 6114 in 090b8ca
else if (note->ppitch() != pitch || fabs(tuning - note->tuning()) > 0.01) { |
See also @lvinken 's comment about this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the comparison
Now please squash those 3 commits into one. |
Thanks for the useful test case. I have a few questions and comments:
|
Thanks, I'll do that once I'm done with all changes here if you don't mind. Just a note, though: GitHub gives the option to "squash and merge" automatically, without using |
Sure, take your time. As said, to the best of my knowledge the folks doing the merges do not squash. |
One more comment to @lvinken : there's a TODO in
In my opinion, If you agree, can I include this fix too in this PR? |
On this one I cannot immediately provide a full answer to and I do not have the time available to work out the details. In retrospect, I am not sure transposition is the main issue here. The current implementation uses a special case for a few microtonal accidentals, ignores other and also ignores the tuning values. This implies the output may be incorrect in several corner cases. All I can add at this time is: please try to make sure whatever the MuseScore GUI can do(in terms of creating internal data structures and visualisation on screen), leads to the expected MusicXML output. |
OK, thanks. I'll do my best to enumerate the possible combinations and cases. |
Something went severely wrong with this, I guess you used |
Thanks, I think I fixed. |
I added code + updated tests to ensure that the 2 |
importexport/musicxml/exportxml.cpp
Outdated
// `alter2` represents a microtone or manually-adjusted note tuning. | ||
// In MusicXML, These two values are merged in the same "alter" tag. | ||
if (alter || alter2) | ||
xml.tag("alter", (double)alter + alter2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not double(alter+alter2)
, i.e. casting the result of the addition rather than just one of the 2 and in a more C++ way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, one of them is int and the other double.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see, but the result is a double in any case. No cast needed at all.
importexport/musicxml/exportxml.cpp
Outdated
@@ -3239,7 +3239,7 @@ static void writePitch(XmlWriter& xml, const Note* const note, const bool useDru | |||
// `alter2` represents a microtone or manually-adjusted note tuning. | |||
// In MusicXML, These two values are merged in the same "alter" tag. | |||
if (alter || alter2) | |||
xml.tag("alter", (double)alter + alter2); | |||
xml.tag("alter", double(alter + alter2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if you drop that cast? If that doesn't result in a compiler warning, just drop it.
The default result of any arithmetic involving a double
and an int
is to convert the result into a double
anyhow.
See also https://docs.microsoft.com/en-us/cpp/cpp/standard-conversions?view=msvc-160#arithmetic-conversions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, dropping the cast also seems to pass the tests.
I've squashed my commits and rebased to the latest 3.x. Waiting for tests then it's ready from my side. |
…resent Code revivew issues from musescore#25022, for musescore#6693, that had been ported earlier
…resent Code revivew issues from musescore#25022, for musescore#6693, that had been ported earlier
…resent Code revivew issues from musescore#25022, for musescore#6693, that had been ported earlier
Resolves: https://musescore.org/en/node/311792
This patch modifies function
writePitch()
in exportxml.cpp to override the "alter" MusicXML element with the value found in thenote->tuning()
if present. This allows the manual note tuning to be preserved during MusicXML export.A test
TestMxmlIO::noteTuning()
is added to verify the desired behaviour.