Skip to content

Commit

Permalink
fix #107671: Accidentals and grace notes collide with stems
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Apr 27, 2016
1 parent 994090f commit e6fed8a
Show file tree
Hide file tree
Showing 199 changed files with 76 additions and 191 deletions.
33 changes: 23 additions & 10 deletions libmscore/beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,16 @@ void Beam::layout1()
for (ChordRest* cr : _elements) {
// leave initial guess alone for moved chords within a beam that crosses staves
// otherwise, assume beam direction is stem direction
if (!_cross || !cr->staffMove())
cr->setUp(_up);
}
if (!_cross || !cr->staffMove()) {
if (cr->isChord()) {
if (cr->up() != _up) {
cr->setUp(_up);
toChord(cr)->layoutStem1();
}
}
}

}
} // end of if/else(tablature)
}

Expand Down Expand Up @@ -459,8 +465,11 @@ void Beam::layoutGraceNotes()
slope = 0.0;

if (!_userModified[idx]) {
for (ChordRest* cr : _elements)
for (ChordRest* cr : _elements) {
cr->setUp(_up);
if (cr->isChord())
toChord(cr)->layoutStem1(); /* create stems needed to calculate horizontal spacing */
}
}
}

Expand Down Expand Up @@ -1914,7 +1923,6 @@ void Beam::layout2(std::vector<ChordRest*>crl, SpannerSegmentType, int frag)
if (!cr->isChord())
continue;
Chord* c = toChord(cr);
c->layoutStem1();
if (c->hook())
score()->undoRemoveElement(c->hook());

Expand All @@ -1941,14 +1949,19 @@ void Beam::layout2(std::vector<ChordRest*>crl, SpannerSegmentType, int frag)
}
by = 0;
}
Stem* stem = c->stem();

Stem* stem = c->stem();
Shape& shape = c->segment()->staffShape(c->vStaffIdx());

if (stem) {
qreal sw2 = score()->styleP(StyleIdx::stemWidth) * .5;
if (cr->up())
shape.remove(stem->shape());

qreal sw2 = stem->lineWidth() * .5;
if (c->up())
sw2 = -sw2;
stem->setLen(y2 - (by + _pagePos.y()));
stem->rxpos() = c->stemPosX() + sw2;
Shape& shape = cr->segment()->staffShape(cr->vStaffIdx());
stem->setLen(y2 - (by + _pagePos.y()));

shape.add(stem->shape());
}

Expand Down
33 changes: 9 additions & 24 deletions libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,17 @@ void Chord::add(Element* e)
break;
case Element::Type::STEM:
Q_ASSERT(!_stem);
_stem = static_cast<Stem*>(e);
_stem = toStem(e);
break;
case Element::Type::HOOK:
_hook = static_cast<Hook*>(e);
_hook = toHook(e);
break;
case Element::Type::CHORDLINE:
_el.push_back(e);
break;
case Element::Type::STEM_SLASH:
Q_ASSERT(!_stemSlash);
_stemSlash = static_cast<StemSlash*>(e);
_stemSlash = toStemSlash(e);
break;
case Element::Type::CHORD:
{
Expand Down Expand Up @@ -1054,23 +1054,6 @@ void Chord::read(XmlReader& e)
else
e.unknown();
}
if (score()->mscVersion() <= 114) { // #19988
Note * n = upNote();
if (n) {
if (notes().size() == 1) {
setUserOff(n->userOff() + userOff());
n->setUserOff(QPoint());
n->setReadPos(QPoint());
}
else if(!n->userOff().isNull()) {
if(!_stem) {
_stem = new Stem(score());
add(_stem);
}
_stem->setUserOff(n->userOff() + _stem->userOff());
}
}
}
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1350,6 +1333,10 @@ void Chord::layoutStem1()
}
else if (_stemSlash)
remove(_stemSlash);

qreal stemWidth5 = _stem->lineWidth() * .5;
_stem->rxpos() = stemPosX() + (up() ? -stemWidth5 : +stemWidth5);
_stem->setLen(defaultStemLength());
}
else {
if (_stem)
Expand All @@ -1376,7 +1363,6 @@ void Chord::layoutStem()
//
// TAB
//
qreal _spatium = spatium();
StaffType* tab = 0;
if (staff() && staff()->isTabStaff()) {
tab = staff()->staffType();
Expand All @@ -1392,7 +1378,7 @@ void Chord::layoutStem()
if (!tab->stemThrough()) {
if (_stem) { // (duplicate code with defaultStemLength())
// process stem:
_stem->setLen(tab->chordStemLength(this) * _spatium);
_stem->setLen(tab->chordStemLength(this) * spatium());
// process hook
int hookIdx = durationType().hooks();
if (!up())
Expand Down Expand Up @@ -1422,7 +1408,6 @@ void Chord::layoutStem()
// NON-TAB (or TAB with stems through staff)
//
if (_stem) {
_stem->layout(); //?
_stem->setLen(defaultStemLength());
// if (isGrace())
// abort();
Expand Down Expand Up @@ -3214,7 +3199,7 @@ Shape Chord::shape() const
{
Shape shape;
processSiblings([&shape, this] (Element* e) {
if (!(e->isStem() && beam()))
// if (!(e->isStem() && beam()))
shape.add(e->shape());
});
shape.add(ChordRest::shape()); // add articulation + lyrics
Expand Down
2 changes: 1 addition & 1 deletion libmscore/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Chord : public ChordRest {

qreal defaultStemLength();

void layoutStem1();
virtual void layoutStem1() override;
void layoutStem();
void layoutArpeggio2();

Expand Down
3 changes: 0 additions & 3 deletions libmscore/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,9 +1186,6 @@ void ChordRest::removeDeleteBeam(bool beamed)
}
if (chord->hook())
score()->undoRemoveElement(chord->hook());
// if (chord->stem() && !chord->isGrace())
if (chord->stem())
chord->layoutStem();
}
}

Expand Down
1 change: 1 addition & 0 deletions libmscore/chordrest.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class ChordRest : public DurationElement {
virtual Element* prevElement() override;
virtual QString accessibleExtraInfo() const override;
virtual Shape shape() const override;
virtual void layoutStem1() {};
};


Expand Down
6 changes: 6 additions & 0 deletions libmscore/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Lyrics;
class Stem;
class SlurSegment;
class Beam;
class Hook;
class StemSlash;

enum class SymId;

Expand Down Expand Up @@ -659,6 +661,8 @@ class Element : public QObject, public ScoreElement {
CONVERT(Lyrics, LYRICS);
CONVERT(Stem, STEM);
CONVERT(Beam, BEAM);
CONVERT(Hook, HOOK);
CONVERT(StemSlash, STEM_SLASH);
CONVERT(SlurSegment, SLUR_SEGMENT);
#undef CONVERT
};
Expand Down Expand Up @@ -719,6 +723,8 @@ static inline const a* to##a(const Element* e) { Q_ASSERT(e == 0 || e->type() ==
CONVERT(Lyrics, LYRICS);
CONVERT(Stem, STEM);
CONVERT(Beam, BEAM);
CONVERT(Hook, HOOK);
CONVERT(StemSlash, STEM_SLASH);
CONVERT(SlurSegment, SLUR_SEGMENT);
#undef CONVERT

Expand Down
Loading

0 comments on commit e6fed8a

Please sign in to comment.