Skip to content

Commit

Permalink
fix #40031: stem tremolo on grace note. Also make tremolo size depend…
Browse files Browse the repository at this point in the history
…ent of chord size.
  • Loading branch information
lasconic committed Nov 29, 2014
1 parent 912bc5e commit c3d48c6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
15 changes: 12 additions & 3 deletions libmscore/tremolo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ Tremolo::Tremolo(const Tremolo& t)
setFlags(ElementFlag::MOVABLE | ElementFlag::SELECTABLE);
}

//---------------------------------------------------------
// mag
//---------------------------------------------------------

qreal Tremolo::mag() const
{
return parent() ? parent()->mag() : 1.0;
}

//---------------------------------------------------------
// draw
//---------------------------------------------------------
Expand All @@ -68,7 +77,7 @@ void Tremolo::draw(QPainter* painter) const
qreal x = 0.0; // bbox().width() * .25;
QPen pen(curColor(), point(score()->styleS(StyleIdx::stemWidth)));
painter->setPen(pen);
qreal _spatium = spatium();
qreal _spatium = spatium() * mag();
painter->drawLine(QLineF(x, -_spatium*.5, x, path.boundingRect().height() + _spatium));
}
}
Expand Down Expand Up @@ -105,7 +114,7 @@ void Tremolo::setTremoloType(TremoloType t)

void Tremolo::layout()
{
qreal _spatium = spatium();
qreal _spatium = spatium() * mag();

qreal w2 = _spatium * score()->styleS(StyleIdx::tremoloWidth).val() * .5;
qreal h2 = _spatium * score()->styleS(StyleIdx::tremoloBoxHeight).val() * .5;
Expand Down Expand Up @@ -214,7 +223,7 @@ void Tremolo::layout()
},
};
int idx = _chord1->hook() ? 1 : (_chord1->beam() ? 2 : 0);
y = (line + t[idx][up][_lines-1][line & 1]) * _spatium * .5;
y = (line + t[idx][up][_lines-1][line & 1]) * spatium() * .5;
setPos(x, y);
return;
}
Expand Down
1 change: 1 addition & 0 deletions libmscore/tremolo.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Tremolo : public Element {
void setTremoloType(TremoloType t);
TremoloType tremoloType() const { return _tremoloType; }

virtual qreal mag() const;
virtual void draw(QPainter*) const;
virtual void layout();
virtual void write(Xml& xml) const;
Expand Down
26 changes: 22 additions & 4 deletions libmscore/undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,10 +1160,28 @@ void Score::undoAddElement(Element* element)
ntremolo->setParent(c1);
undo(new AddElement(ntremolo));
}
else if (
(element->type() == Element::Type::TREMOLO && !static_cast<Tremolo*>(element)->twoNotes())
|| (element->type() == Element::Type::ARPEGGIO))
{
else if (element->type() == Element::Type::TREMOLO && !static_cast<Tremolo*>(element)->twoNotes()) {
ChordRest* cr = static_cast<ChordRest*>(element->parent());
Segment* s = cr->segment();
Measure* m = s->measure();
Measure* nm = score->tick2measure(m->tick());
Segment* ns = nm->findSegment(s->segmentType(), s->tick());
Chord* c1 = static_cast<Chord*>(ns->element(staffIdx * VOICES + cr->voice()));
if (cr->isGrace()) { // find the corresponding grace note by index
Chord* pcr = static_cast<Chord*>(cr->parent());
int index = 0;
for (Chord* gc : pcr->graceNotes()) {
if (cr == gc)
break;
index++;
}
if (index < c1->graceNotes().length())
c1 = c1->graceNotes().at(index);
}
ne->setParent(c1);
undo(new AddElement(ne));
}
else if (element->type() == Element::Type::ARPEGGIO) {
ChordRest* cr = static_cast<ChordRest*>(element->parent());
Segment* s = cr->segment();
Measure* m = s->measure();
Expand Down

0 comments on commit c3d48c6

Please sign in to comment.