-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 #34451: Add rest position in musicxml export #9955
Fix #34451: Add rest position in musicxml export #9955
Conversation
Hi ! I added some code to export rest positional attributes in the same way as for the notes. |
@lvinken Mind to double-check this? |
@@ -3757,6 +3781,7 @@ void ExportMusicXml::rest(Rest* rest, int staff) | |||
|
|||
QString noteTag = QString("note"); | |||
noteTag += color2xml(rest); | |||
noteTag += restPosition(this, rest); |
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.
I wonder if we could simply use noteTag += notePosition(this, dynamic_cast<Note*>(rest));
here, i.e. fully reuse the existing code (which except for that type is 100% identical) rather than duplicating it? Makes the entire fix a one-liner.
Or is this to 'hacky'?
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.
Or, probably much cleaner, change notePosition to this:
//---------------------------------------------------------
// noteRestPosition
//---------------------------------------------------------
QString ExportMusicXml::noteRestPosition(const ExportMusicXml* const expMxml, const ChordRest* const cr)
{
QString res;
IF_ASSERT_FAILED(!cr->isNote() && !cr->isRest()) {
return res;
}
if (configuration()->musicxmlExportLayout()) {
const double pageHeight = expMxml->getTenthsFromInches(expMxml->score()->styleD(Sid::pageHeight));
double measureX = expMxml->getTenthsFromDots(cr->measure()->pagePos().x());
double measureY = pageHeight - expMxml->getTenthsFromDots(cr->measure()->pagePos().y());
double noteX = expMxml->getTenthsFromDots(cr->pagePos().x());
double noteY = pageHeight - expMxml->getTenthsFromDots(cr->pagePos().y());
res += QString(" default-x=\"%1\"").arg(QString::number(noteX - measureX, 'f', 2));
res += QString(" default-y=\"%1\"").arg(QString::number(noteY - measureY, 'f', 2));
}
return res;
}
(not 100% sure whether I got the assertion right)
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.
Maybe even call it chordRestPosition()
and drop the IF_ASSERT_FAILED
part entirely, as it should be legal for chords too.
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.
Actually just forget about it, it just doesn't work. And the code isn't 100% identical either, notePosition()
picks on the chord a note belongs to, restPosition()
(of course) does not.
So back to your initial approach, 2 methods for 2 types, which similar but not identical code.
Sorry for the mess...
I actually thought it was possible but I'm not very familliar with c++ and thus did not know the correct syntax. |
Well, yeah, I'm not sure about that casting trick either, it certainly does look quite hacky, but maybe my alternative approach is better, no casting needed and inside making sure the single method for both is reall only used on notes and rests, not also on chords. |
@@ -3757,6 +3757,7 @@ void ExportMusicXml::rest(Rest* rest, int staff) | |||
|
|||
QString noteTag = QString("note"); | |||
noteTag += color2xml(rest); | |||
noteTag += notePosition(this, dynamic_cast<Note*>(rest)), |
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.
semicolon, not colon ;-)
Oups sorry... |
Should I try with your cleaner approach ? |
I'd like input from others on that |
7a10f23
to
218a460
Compare
Oh yes I forgot to mention this slight difference between the notePosition and restPosition methods. |
Actually the issue this fixes is https://musescore.org/en/node/34451, https://musescore.org/en/node/34346 is just a forum thread that triggered the creation of that issue. |
218a460
to
30dd4e2
Compare
Done for PR and commit titles |
Backport of musescore#9955 Todo: Attribute this commit to @julienripoche
Checked, thanks for looking into this. In its current state (commit 30dd4e2) the code does exactly what it is supposed to do. I do agree with Jojo that the duplication of code is not desired and also think the mechanism to generate default-x and default-y should be generalised (and extended to other elements). Wrt to this change specifically, as the code (both for Note and Rest) depends the element's postion and its containing measure's position, in master both Note and Rest inherit from EngravingItem and EngravingItem defines the measure() function, the solution for now could be to create a single function supporting both Note and Rest with an EngravingItem as parameter. |
So something like this?
(Now tested: It does build!) @lvinken : it apparently is |
For 3.x this here does seem work:
|
Both Jojo's 3.x and master solution look OK to me. |
Backport of musescore#9955 Todo: Attribute this commit to @julienripoche
Backport of musescore#9955 Todo: Attribute this commit to @julienripoche
Hi @Jojo-Schmitz and happy new year ! |
Note that the |
I think an assertion is kind of useful here: if the code is generalised it should be robust against being called for unexpected element types (such as elements that are not attached to measures). In that case for a production build simply returning an empty string should be OK. For a development build either a message or a failed assertion would be OK. This could be achieved by |
OK, so for master is should be |
Yes, but (I assume) without the exclamation mark.
…On Sat, Feb 5, 2022 at 10:44 AM Joachim Schmitz ***@***.***> wrote:
OK, so for master is should be IF_ASSERT_FAILED(!meas)
—
Reply to this email directly, view it on GitHub
<#9955 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAK4YKSXNVO2LWTOWJTNLSDUZTWPPANCNFSM5JG4SG2A>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
No, it is like a normal
bit of a screwed up logic that threw me off several time already (and here too) @julienripoche are you going to implement it that way, or should I? I just did it, see PR #10456. It ran all the tests and passed them too. |
Backport of musescore#9955, resp. musescore#10456
Backport of musescore#9955, resp. musescore#10456
Closing, since this has been replaced by #10456. |
Backport of musescore#9955, resp. musescore#10456
Resolves: https://musescore.org/en/node/34451
Export rest position attributes (default-x, default-y) in the same way it has already been done for notes.