Skip to content

Commit

Permalink
fix #28881: bad spacing of full measure rest in multivoice context
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSabatella committed Aug 4, 2014
1 parent cf1da9f commit 42f8ece
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 deletions.
27 changes: 18 additions & 9 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3294,16 +3294,16 @@ qreal Score::computeMinWidth(Segment* fs)
if (_nstaves == 0)
return 1.0;

qreal _spatium = spatium();
qreal clefKeyRightMargin = styleS(StyleIdx::clefKeyRightMargin).val() * _spatium;
qreal minNoteDistance = styleS(StyleIdx::minNoteDistance).val() * _spatium;
qreal minHarmonyDistance = styleS(StyleIdx::minHarmonyDistance).val() * _spatium;
qreal _spatium = spatium();
qreal clefKeyRightMargin = styleS(StyleIdx::clefKeyRightMargin).val() * _spatium;
qreal minNoteDistance = styleS(StyleIdx::minNoteDistance).val() * _spatium;
qreal minHarmonyDistance = styleS(StyleIdx::minHarmonyDistance).val() * _spatium;
qreal maxHarmonyBarDistance = styleS(StyleIdx::maxHarmonyBarDistance).val() * _spatium;

qreal rest[_nstaves]; // fixed space needed from previous segment
qreal rest[_nstaves]; // fixed space needed from previous segment
memset(rest, 0, _nstaves * sizeof(qreal));

qreal hRest[_nstaves]; // fixed space needed from previous harmony
qreal hRest[_nstaves]; // fixed space needed from previous harmony
memset(hRest, 0, _nstaves * sizeof(qreal));

qreal clefWidth[_nstaves];
Expand Down Expand Up @@ -3336,18 +3336,19 @@ qreal Score::computeMinWidth(Segment* fs)
bool rest2[_nstaves];
bool hRest2[_nstaves];
bool spaceHarmony = false;
Segment::Type segType = s->segmentType();
Segment::Type segType = s->segmentType();
qreal segmentWidth = 0.0;
qreal harmonyWidth = 0.0;
qreal stretchDistance = 0.0;
Segment::Type pt = pSeg ? pSeg->segmentType() : Segment::Type::BarLine;
Segment::Type pt = pSeg ? pSeg->segmentType() : Segment::Type::BarLine;

for (int staffIdx = 0; staffIdx < _nstaves; ++staffIdx) {
if (!staff(staffIdx)->show())
continue;
qreal minDistance = 0.0;
Space space;
Space hSpace;
Space naSpace; // space needed for full measure rests (and potentially other non-aligned elements)
QRectF hBbox;
int track = staffIdx * VOICES;
bool found = false;
Expand Down Expand Up @@ -3426,7 +3427,13 @@ qreal Score::computeMinWidth(Segment* fs)
qreal rx = qMin(cxu, 0.0); // nudge right shouldn't require more trailing space
Space crSpace = cr->space();
Space segRelSpace(crSpace.lw()-lx, crSpace.rw()+rx);
space.max(segRelSpace);
// always allocate sufficient space
// but in Measure::layoutX() we will ignore full measure rests
// since they do not need to affect spacing in other voices
if (cr->durationType() != TDuration::DurationType::V_MEASURE)
space.max(segRelSpace);
else
naSpace.max(segRelSpace);

// lyrics
foreach (Lyrics* l, cr->lyricsList()) {
Expand All @@ -3443,6 +3450,8 @@ qreal Score::computeMinWidth(Segment* fs)
}
}
}

space.max(naSpace);
if (lyrics)
space.max(Space(llw, rrw));

Expand Down
23 changes: 14 additions & 9 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2981,10 +2981,10 @@ void Measure::layoutX(qreal stretch)
if (nstaves == 0 || segs == 0)
return;

qreal _spatium = spatium();
int tracks = nstaves * VOICES;
qreal clefKeyRightMargin = score()->styleS(StyleIdx::clefKeyRightMargin).val() * _spatium;
qreal minHarmonyDistance = score()->styleS(StyleIdx::minHarmonyDistance).val() * _spatium;
qreal _spatium = spatium();
int tracks = nstaves * VOICES;
qreal clefKeyRightMargin = score()->styleS(StyleIdx::clefKeyRightMargin).val() * _spatium;
qreal minHarmonyDistance = score()->styleS(StyleIdx::minHarmonyDistance).val() * _spatium;
qreal maxHarmonyBarDistance = score()->styleS(StyleIdx::maxHarmonyBarDistance).val() * _spatium;

qreal rest[nstaves]; // fixed space needed from previous segment
Expand Down Expand Up @@ -3042,11 +3042,11 @@ void Measure::layoutX(qreal stretch)
bool rest2[nstaves];
bool hRest2[nstaves];
bool spaceHarmony = false;
Segment::Type segType = s->segmentType();
Segment::Type segType = s->segmentType();
qreal segmentWidth = 0.0;
qreal harmonyWidth = 0.0;
qreal stretchDistance = 0.0;
Segment::Type pt = pSeg ? pSeg->segmentType() : Segment::Type::BarLine;
Segment::Type pt = pSeg ? pSeg->segmentType() : Segment::Type::BarLine;
#if 0
qreal firstHarmonyDistance = 0.0;
#endif
Expand Down Expand Up @@ -3145,9 +3145,14 @@ void Measure::layoutX(qreal stretch)
qreal cxu = cr->userOff().x();
qreal lx = qMax(cxu, 0.0); // nudge left shouldn't require more leading space
qreal rx = qMin(cxu, 0.0); // nudge right shouldn't require more trailing space
Space crSpace = cr->space();
Space segRelSpace(crSpace.lw()-lx, crSpace.rw()+rx);
space.max(segRelSpace);
// Score::computeMinWidth already allocated enough space for full measure rests
// but do not account for them when spacing within the measure
// because they do not need to align with the other elements in segment
if (cr->durationType() != TDuration::DurationType::V_MEASURE) {
Space crSpace = cr->space();
Space segRelSpace(crSpace.lw()-lx, crSpace.rw()+rx);
space.max(segRelSpace);
}

// lyrics
int n = cr->lyricsList().size();
Expand Down
5 changes: 4 additions & 1 deletion libmscore/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ void Rest::layout()
+ dots() * score()->styleS(StyleIdx::dotDotDistance));
}
setbbox(symBbox(_sym));
_space.setRw(width() + point(rs));
qreal symOffset = bbox().x();
if (symOffset < 0.0)
_space.setLw(-symOffset);
_space.setRw(width() + point(rs) + symOffset);
}

//---------------------------------------------------------
Expand Down
Binary file added vtest/chord-layout-13-ref.png
Loading
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/chord-layout-13.mscz
Binary file not shown.
5 changes: 3 additions & 2 deletions vtest/gen
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ else
emmentaler-6 bravura-6 emmentaler-7 bravura-7\
emmentaler-8 bravura-8 emmentaler-9 bravura-9 emmentaler-10 bravura-10\
emmentaler-11 bravura-11 frametext ottava slurs-1 slurs-2\
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-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\
accidental-1 accidental-2 accidental-3 accidental-4\
accidental-5 accidental-6 accidental-7 accidental-8\
tie-1 grace-1 grace-2 grace-3 harmony-1 harmony-2 harmony-3 beams-1 beams-2\
Expand Down
5 changes: 3 additions & 2 deletions vtest/gen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ set SRC=mmrest-1,bravura-mmrest,mmrest-2,mmrest-4,mmrest-5,mmrest-6,mmrest-7,mmr
emmentaler-6,bravura-6,emmentaler-7,bravura-7, ^
emmentaler-8,bravura-8,emmentaler-9,bravura-9,emmentaler-10,bravura-10, ^
emmentlar-11,bravura-11,frametext,ottava,slurs-1,slurs-2, ^
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-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, ^
accidental-1,accidental-2,accidental-3,accidental-4, ^
accidental-5,accidental-6,accidental-7,accidental-8, ^
tie-1,grace-1,grace-2,grace-3,harmony-1,harmony-2,harmony-3,beams-1,beams-2, ^
Expand Down

0 comments on commit 42f8ece

Please sign in to comment.