Skip to content

Commit

Permalink
Merge pull request #1849 from MarcSabatella/fix-floating-beam
Browse files Browse the repository at this point in the history
fix regression with beam direction
  • Loading branch information
MarcSabatella committed Mar 7, 2015
2 parents 091cf77 + ecc69af commit 911328c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
75 changes: 49 additions & 26 deletions libmscore/beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,9 +1600,12 @@ void Beam::layout2(QList<ChordRest*>crl, SpannerSegmentType, int frag)

qreal x1 = crl[0]->stemPosX() + crl[0]->pageX() - pageX();

int baseLevel = 0;
int baseLevel = 0; // beam level that covers all notes of beam
int crBase[n]; // offset of beam level 0 for each chord
bool growDown = _up;

for (int beamLevel = 0; beamLevel < beamLevels; ++beamLevel) {
bool growDown = _up;

// loop through the different groups for this beam level
// inner loop will advance through chordrests within each group
for (int i = 0; i < n;) {
Expand All @@ -1613,6 +1616,7 @@ void Beam::layout2(QList<ChordRest*>crl, SpannerSegmentType, int frag)
++i;
continue;
}

// at the beginning of a group
// loop through chordrests looking for end
int c1 = i;
Expand All @@ -1634,35 +1638,54 @@ void Beam::layout2(QList<ChordRest*>crl, SpannerSegmentType, int frag)
}
}

// found end of group
int c2 = i;
ChordRest* cr2 = crl[c2 - 1];

// if group covers whole beam, we are still at base level
if (c1 == 0 && c2 == n)
baseLevel = beamLevel;

// default assumption - everything grows in same direction
int bl = growDown ? beamLevel : -beamLevel;
bool growDownGroup = growDown;

// calculate direction for this group
if (beamLevel > baseLevel) {

if ((c1 && (cr1->up() == cr2->up()))
|| ((c2 == n) && (cr1->up() != cr2->up()))) {
// matching direction for outer stems, not first group
// or, opposing direction for outer stems, last group
// recalculate beam for this group based on its *first* cr
growDownGroup = cr1->up();
}

else if (!c1 && (c2 < n) && (cr1->up() != cr2->up())) {
// opposing directions for outer stems, first (but not only) group
// recalculate beam for this group if necessary based on its *last* cr
growDownGroup = cr2->up();
}

// recalculate segment offset bl
int base = crBase[c1];
if (growDownGroup && base <= 0)
bl = base + beamLevel;
else if (growDownGroup)
bl = base + 1;
else if (!growDownGroup && base >= 0)
bl = base - beamLevel;
else if (!growDownGroup)
bl = base - 1;

ChordRest* cr2 = crl[i-1]; // last cr of group for this beam level
if ((c1 && (cr1->up() == cr2->up()))
|| ((i == n) && (cr1->up() != cr2->up()))) {
// matching direction for outer stems, not first group
// or, opposing direction for outer stems, last group
// recalculate growth direction for this group based on its *first* cr
#if 1
bl = cr1->up() ? beamLevel : -beamLevel;
#else
QPointF stemPos(cr1->stemPos());
qreal x2 = stemPos.x() - _pagePos.x();
qreal y1 = (x2 - x1) * slope + py1 + _pagePos.y();
qreal y2 = cr1->stemPos().y();
if ((y1 < y2) != growDown)
bl = baseLevel - (beamLevel + 1);
#endif
}
else if (!c1 && (i < n) && (cr1->up() != cr2->up())) {
// opposing directions for outer stems, first (but not only) group
// recalculate growth direction for this group based on its *last* cr
bl = cr2->up() ? beamLevel : -beamLevel;

// if there are more beam levels,
// record current beam offsets for all notes of this group for re-use
if (beamLevel < beamLevels - 1) {
for (int i = c1; i < c2; ++i)
crBase[i] = bl;
}
int c2 = i;
if (c1 == 0 && c2 == n)
++baseLevel;

qreal stemWidth = point(score()->styleS(StyleIdx::stemWidth));
qreal x2 = cr1->stemPosX() + cr1->pageX() - _pagePos.x();
Expand Down
Binary file added vtest/beams-17-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/beams-17.mscz
Binary file not shown.
2 changes: 1 addition & 1 deletion vtest/gen
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ else
tie-1 tie-2 tie-3 grace-1 grace-2 grace-3 grace-4 tuplets-1 breath-1\
harmony-1 harmony-2 harmony-3 harmony-4 harmony-5 harmony-6 harmony-7 harmony-8 harmony-9 harmony-10 harmony-11\
beams-1 beams-2 beams-3 beams-4 beams-5 beams-6 beams-7 beams-8 beams-9 beams-10\
beams-11 beams-12 beams-13 beams-14 beams-15 beams-16\
beams-11 beams-12 beams-13 beams-14 beams-15 beams-16 beams-17\
user-offset-1 user-offset-2 chord-space-1 chord-space-2 tablature-1 image-1\
lyrics-1 lyrics-2 lyrics-3 lyrics-4 voice-1 voice-2 slash-1 slash-2 system-1 system-2 system-3"
fi
Expand Down
2 changes: 1 addition & 1 deletion vtest/gen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set SRC=mmrest-1,bravura-mmrest,gonville-mmrest,mmrest-2,mmrest-4,mmrest-5,mmres
tie-1,tie-2,tie-3,grace-1,grace-2,grace-3,grace-4,tuplets-1,breath-1, ^
harmony-1,harmony-2,harmony-3,harmony-4,harmony-5,harmony-6,harmony-7,harmony-8,harmony-9,harmony-10,harmony-11, ^
beams-1,beams-2,beams-3,beams-4,beams-5,beams-6,beams-7,beams-8,beams-9,beams-10, ^
beams-11,beams-12,beams-13,beams-14,beams-15,beams-16, ^
beams-11,beams-12,beams-13,beams-14,beams-15,beams-16,beams-17, ^
user-offset-1,user-offset-2,chord-space-1,chord-space-2,tablature-1,image-1, ^
lyrics-1,lyrics-2,lyrics-3,lyrics-4,voice-1,voice-2,slash-1,slash-2,system-1,system-2,system-3

Expand Down

0 comments on commit 911328c

Please sign in to comment.