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 #35176: ottava layout in various special situations #1364

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 52 additions & 13 deletions libmscore/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,51 +468,90 @@ QPointF SLine::linePos(GripLine grip, System** sys) const
ChordRest* cr;
if (grip == GripLine::START) {
cr = static_cast<ChordRest*>(startElement());
if (cr) {
if ((cr->x() < 0.0) || (cr->durationType() == TDuration::DurationType::V_MEASURE && type() == Element::Type::OTTAVA))
x = cr->x();
}
}
else {
cr = static_cast<ChordRest*>(endElement());
qreal sp = staff()->spatium();
if (type() == Element::Type::OTTAVA) {
// lay out to right edge of note (including dots)
if (cr)
x += cr->segment()->width();
if (cr && cr->durationType() == TDuration::DurationType::V_MEASURE) {
x = cr->x() + cr->width();
}
else if (cr) {
#if 1
// lay out just past right edge of all notes for this segment on this staff
qreal width = 0;
Segment* s = cr->segment();
int n = staffIdx() * VOICES;
for (int i = 0; i < VOICES; ++i) {
ChordRest* vcr = static_cast<ChordRest*>(s->element(n + i));
if (vcr)
width = qMax(width, vcr->space().rw());
}
// extend 1sp past chord/rest
x = width + sp;
// but don't overlap next chord/rest
Segment* ns = s->next();
bool crFound = false;
while (ns) {
for (int i = 0; i < VOICES; ++i) {
if (ns->element(n + i)) {
crFound = true;
break;
}
}
if (crFound)
break;
ns = ns->next();
}
if (crFound) {
qreal nextNoteDistance = ns->x() - s->x();
if (x > nextNoteDistance)
x = qMax(width, nextNoteDistance);
}
#else
// seems like this *should* work, but it currently fails sometimes -
// too many places where segment width is not set well
x = cr->segment()->width();
#endif
}
}
else if (type() == Element::Type::HAIRPIN || type() == Element::Type::TRILL || type() == Element::Type::TEXTLINE) {
// lay out all the way to next CR or (almost to) barline
// lay out to just before next CR or barline
if (cr && endElement()->parent() && endElement()->parent()->type() == Element::Type::SEGMENT) {
qreal x2 = 0.0;
qreal sp = endElement()->staff()->spatium();
qreal x2 = cr->x() + cr->space().rw();
int t = track2();
Segment* seg = static_cast<Segment*>(endElement()->parent())->next();
for ( ; seg; seg = seg->next()) {
if (seg->segmentType() == Segment::Type::ChordRest) {
if (t != -1 && !seg->element(t)) {
continue;
}
x2 = seg->x() - sp; // 1sp shy of next chord
x2 = qMax(x2, seg->x() - sp);
break;
}
else if (seg->segmentType() == Segment::Type::EndBarLine) {
x2 = seg->x() - sp;
x2 = qMax(x2, seg->x() - sp);
break;
}
}
if (!seg) {
// no end segment found, use measure width
x2 = endElement()->parent()->parent()->width() - sp;
}
x += x2 - endElement()->parent()->x();
x = x2 - endElement()->parent()->x();
}
}
}

if (cr && cr->durationType() == TDuration::DurationType::V_MEASURE)
x -= cr->x();

int t = grip == GripLine::START ? tick() : tick2();
Measure* m = cr ? cr->measure() : score()->tick2measure(t);

if (m) {
x += cr ? cr->pos().x() + cr->segment()->pos().x() + m->pos().x() : m->tick2pos(t);
x += cr ? cr->segment()->pos().x() + m->pos().x() : m->tick2pos(t);
*sys = m->system();
}
else
Expand Down
2 changes: 1 addition & 1 deletion vtest/gen
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ else
emmentaler-text-1 gonville-text-1 bravura-text-1 musejazz-text-1\
emmentaler-text-2 gonville-text-2 bravura-text-2 musejazz-text-2\
emmentaler-text-3 gonville-text-3 bravura-text-3 musejazz-text-3\
frametext ottava slurs-1 slurs-2 hairpins-1 pedal-1 line-1 line-2 line-3\
frametext ottava slurs-1 slurs-2 hairpins-1 pedal-1 line-1 line-2 line-3 line-4\
chord-layout-1 chord-layout-2 chord-layout-3 chord-layout-4 chord-layout-5\
chord-layout-6 chord-layout-7 chord-layout-8 chord-layout-9 chord-layout-10\
chord-layout-11 chord-layout-12 chord-layout-13 chord-layout-14 cross-1\
Expand Down
2 changes: 1 addition & 1 deletion vtest/gen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set SRC=mmrest-1,bravura-mmrest,gonville-mmrest,mmrest-2,mmrest-4,mmrest-5,mmres
emmentaler-text-1,bravura-test-1,gonville-test-1,musejazz-text-1 ^
emmentaler-text-2,bravura-test-2,gonville-test-2,musejazz-text-2 ^
emmentaler-text-3,bravura-test-3,gonville-test-3,musejazz-text-3 ^
frametext,ottava,slurs-1,slurs-2,hairpins-1,pedal-1,line-1,line-2,line-3, ^
frametext,ottava,slurs-1,slurs-2,hairpins-1,pedal-1,line-1,line-2,line-3,line-4, ^
chord-layout-1,chord-layout-2,chord-layout-3,chord-layout-4,chord-layout-5, ^
chord-layout-6,chord-layout-7,chord-layout-8,chord-layout-9,chord-layout-10, ^
chord-layout-11,chord-layout-12,chord-layout-13,chord-layout-14,cross-1, ^
Expand Down
Binary file modified vtest/line-1-ref.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vtest/line-1.mscz
Binary file not shown.
Binary file added vtest/line-4-ref.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vtest/line-4.mscz
Binary file not shown.