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

Write location before spanner end on score end #20107

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/engraving/rw/write/twrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,27 @@ void TWrite::writeSpannerStart(Spanner* s, XmlWriter& xml, WriteContext& ctx, co
void TWrite::writeSpannerEnd(Spanner* s, XmlWriter& xml, WriteContext& ctx, const EngravingItem* current, track_idx_t track, Fraction tick)
{
Fraction frac = fraction(ctx.clipboardmode(), current, tick);
if (frac == s->score()->endTick()) {
// Write a location tag if the spanner ends on the last tick of the score
Location spannerEndLoc = Location::absolute();
spannerEndLoc.setFrac(frac);
spannerEndLoc.setMeasure(0);
spannerEndLoc.setTrack(track);
spannerEndLoc.setVoice(track2voice(track));
spannerEndLoc.setStaff(s->staffIdx());

Location prevLoc = Location::absolute();
prevLoc.setFrac(ctx.curTick());
prevLoc.setMeasure(0);
prevLoc.setTrack(track);
prevLoc.setVoice(track2voice(track));
prevLoc.setStaff(s->staffIdx());

spannerEndLoc.toRelative(prevLoc);
if (spannerEndLoc.frac() != Fraction(0, 1)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this condition better get moved up to the first if?

    if (frac == s->score()->endTick() && frac != Fraction(0,1)) {

Or ever the other way round?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, as spannerEndLoc has been made relative to the previous location by this point. This is checking if spannerEndLoc is the same as the previous location written to the file (difference between fractions is 0). If so, we don't need to bother writing to the file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks for explaining

write(&spannerEndLoc, xml, ctx);
}
}
SpannerWriter w(xml, &ctx, current, s, static_cast<int>(track), frac, false);
w.write();
}
Expand Down