Skip to content

Commit

Permalink
slur cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jul 4, 2016
1 parent d14da5b commit 863c9ac
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 44 deletions.
2 changes: 1 addition & 1 deletion effects/noeffect/noeffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class NoEffect : public Effect
virtual void init(float) override {}
virtual void process(int, float*, float*) override;

virtual void setValue(int, double) override {}
// virtual void setValue(int, double) override {}
virtual void setNValue(int, double) override {}
virtual double value(int) const override { return 0.0; }
virtual double nvalue(int) const override { return 0.0; }
Expand Down
94 changes: 51 additions & 43 deletions libmscore/slur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void SlurSegment::draw(QPainter* painter) const
{
// hide tie toward the second chord of a cross-measure value
if ((slurTie()->isTie())
&& (static_cast<Tie*>(slurTie())->endNote())
&& (static_cast<Tie*>(slurTie())->endNote()->chord()->crossMeasure() == CrossMeasure::SECOND))
&& (toTie(slurTie())->endNote())
&& (toTie(slurTie())->endNote()->chord()->crossMeasure() == CrossMeasure::SECOND))
return;

QPen pen(curColor());
Expand Down Expand Up @@ -129,13 +129,13 @@ static ChordRest* searchCR(Segment* segment, int startTrack, int endTrack)
if (startTrack > endTrack) {
for (int t = startTrack-1; t >= endTrack; --t) {
if (s->element(t))
return static_cast<ChordRest*>(s->element(t));
return toChordRest(s->element(t));
}
}
else {
for (int t = startTrack; t < endTrack; ++t) {
if (s->element(t))
return static_cast<ChordRest*>(s->element(t));
return toChordRest(s->element(t));
}
}
}
Expand All @@ -149,7 +149,7 @@ static ChordRest* searchCR(Segment* segment, int startTrack, int endTrack)

bool SlurSegment::edit(MuseScoreView* viewer, Grip curGrip, int key, Qt::KeyboardModifiers modifiers, const QString&)
{
Slur* sl = static_cast<Slur*>(slurTie());
Slur* sl = toSlur(slurTie());

if (key == Qt::Key_X) {
sl->setSlurDirection(sl->up() ? Direction::DOWN : Direction::UP);
Expand All @@ -172,8 +172,16 @@ bool SlurSegment::edit(MuseScoreView* viewer, Grip curGrip, int key, Qt::Keyboar
return false;

ChordRest* cr = 0;
ChordRest* e = curGrip == Grip::START ? sl->startCR() : sl->endCR();
ChordRest* e1 = curGrip == Grip::START ? sl->endCR() : sl->startCR();
ChordRest* e;
ChordRest* e1;
if (curGrip == Grip::START) {
e = sl->startCR();
e1 = sl->endCR();
}
else {
e = sl->endCR();
e1 = sl->startCR();
}

if (key == Qt::Key_Left)
cr = prevChordRest(e);
Expand Down Expand Up @@ -207,8 +215,8 @@ void SlurSegment::changeAnchor(MuseScoreView* viewer, Grip curGrip, Element* ele
spanner()->setStartElement(element);
switch (spanner()->anchor()) {
case Spanner::Anchor::NOTE: {
Tie* tie = static_cast<Tie*>(spanner());
Note* note = static_cast<Note*>(element);
Tie* tie = toTie(spanner());
Note* note = toNote(element);
if (note->chord()->tick() <= tie->endNote()->chord()->tick()) {
tie->startNote()->setTieFor(0);
tie->setStartNote(note);
Expand All @@ -217,8 +225,11 @@ void SlurSegment::changeAnchor(MuseScoreView* viewer, Grip curGrip, Element* ele
break;
}
case Spanner::Anchor::CHORD:
spanner()->setTick(static_cast<Chord*>(element)->tick());
spanner()->setTick(toChord(element)->tick());
spanner()->setTick2(spanner()->endElement()->tick());
spanner()->setTrack(element->track());
if (score()->spannerMap().removeSpanner(spanner()))
score()->addSpanner(spanner());
break;
case Spanner::Anchor::SEGMENT:
case Spanner::Anchor::MEASURE:
Expand All @@ -230,8 +241,8 @@ void SlurSegment::changeAnchor(MuseScoreView* viewer, Grip curGrip, Element* ele
spanner()->setEndElement(element);
switch (spanner()->anchor()) {
case Spanner::Anchor::NOTE: {
Tie* tie = static_cast<Tie*>(spanner());
Note* note = static_cast<Note*>(element);
Tie* tie = toTie(spanner());
Note* note = toNote(element);
// do not allow backward ties
if (note->chord()->tick() >= tie->startNote()->chord()->tick()) {
tie->endNote()->setTieBack(0);
Expand All @@ -241,7 +252,7 @@ void SlurSegment::changeAnchor(MuseScoreView* viewer, Grip curGrip, Element* ele
break;
}
case Spanner::Anchor::CHORD:
spanner()->setTick2(static_cast<Chord*>(element)->tick());
spanner()->setTick2(toChord(element)->tick());
spanner()->setTrack2(element->track());
break;

Expand All @@ -258,7 +269,7 @@ void SlurSegment::changeAnchor(MuseScoreView* viewer, Grip curGrip, Element* ele
if (spanner()->spannerSegments().size() != segments) {
QList<SpannerSegment*>& ss = spanner()->spannerSegments();

SlurSegment* newSegment = static_cast<SlurSegment*>(curGrip == Grip::END ? ss.back() : ss.front());
SlurSegment* newSegment = toSlurSegment(curGrip == Grip::END ? ss.back() : ss.front());
score()->endCmd();
score()->startCmd();
viewer->startEdit(newSegment, curGrip);
Expand Down Expand Up @@ -352,24 +363,21 @@ void SlurSegment::editDrag(const EditData& ed)
qreal _spatium = spatium();
ups(ed.curGrip).off += (ed.delta / _spatium);

if (ed.curGrip == Grip::START || ed.curGrip == Grip::END) {
Grip g = ed.curGrip;

if (g == Grip::START || g == Grip::END) {
slurTie()->computeBezier(this);
//
// move anchor for slurs/ties
//
SpannerSegmentType st = spannerSegmentType();
if (
(ed.curGrip == Grip::START && (st == SpannerSegmentType::SINGLE || st == SpannerSegmentType::BEGIN))
|| (ed.curGrip == Grip::END && (st == SpannerSegmentType::SINGLE || st == SpannerSegmentType::END))
) {
if ((g == Grip::START && isSingleBeginType()) || (g == Grip::END && isSingleEndType())) {
Spanner* spanner = slurTie();
Qt::KeyboardModifiers km = qApp->keyboardModifiers();
Note* note = static_cast<Note*>(ed.view->elementNear(ed.pos));
if (note && note->type() == Element::Type::NOTE &&
((ed.curGrip == Grip::END && note->chord()->tick() > slurTie()->tick())
|| (ed.curGrip == Grip::START && note->chord()->tick() < slurTie()->tick2()))
if (note && note->isNote()
&& ((g == Grip::END && note->tick() > slurTie()->tick()) || (g == Grip::START && note->tick() < slurTie()->tick2()))
) {
if (ed.curGrip == Grip::END && spanner->type() == Element::Type::TIE) {
if (g == Grip::END && spanner->isTie()) {
Tie* tie = toTie(spanner);
if (tie->startNote()->pitch() == note->pitch()
&& tie->startNote()->chord()->tick() < note->chord()->tick()) {
Expand All @@ -380,11 +388,11 @@ void SlurSegment::editDrag(const EditData& ed)
}
}
}
else if (spanner->type() != Element::Type::TIE && km != (Qt::ShiftModifier | Qt::ControlModifier)) {
else if (!spanner->isTie() && km != (Qt::ShiftModifier | Qt::ControlModifier)) {
Chord* c = note->chord();
ed.view->setDropTarget(note);
if (c != spanner->endCR()) {
changeAnchor(ed.view, ed.curGrip, c);
changeAnchor(ed.view, g, c);
slurTie()->layout();
}
}
Expand Down Expand Up @@ -607,10 +615,10 @@ void SlurSegment::layoutSegment(const QPointF& p1, const QPointF& p2)
// adjust position to avoid staff line if necessary
Staff* st = staff();
bool reverseAdjust = false;
if (slurTie()->type() == Element::Type::TIE && st && !st->isTabStaff()) {
if (slurTie()->isTie() && st && !st->isTabStaff()) {
// multinote chords with ties need special handling
// otherwise, adjusted tie might crowd an unadjusted tie unnecessarily
Tie* t = static_cast<Tie*>(slurTie());
Tie* t = toTie(slurTie());
Note* sn = t->startNote();
Chord* sc = sn ? sn->chord() : 0;
// normally, the adjustment moves ties according to their direction (eg, up if tie is up)
Expand Down Expand Up @@ -836,14 +844,14 @@ void Slur::slurPos(SlurPos* sp)
ChordRest* ecr = endCR();
Chord* sc = 0;
Note* note1 = 0;
if (scr->type() == Element::Type::CHORD) {
sc = static_cast<Chord*>(scr);
if (scr->isChord()) {
sc = toChord(scr);
note1 = _up ? sc->upNote() : sc->downNote();
}
Chord* ec = 0;
Note* note2 = 0;
if (ecr->type() == Element::Type::CHORD) {
ec = static_cast<Chord*>(ecr);
if (ecr->isChord()) {
ec = toChord(ecr);
note2 = _up ? ec->upNote() : ec->downNote();
}

Expand Down Expand Up @@ -1393,8 +1401,8 @@ static bool isDirectionMixture(Chord* c1, Chord* c2)
{
bool up = c1->up();
for (Segment* seg = c1->segment(); seg; seg = seg->next(Segment::Type::ChordRest)) {
Chord* c = static_cast<Chord*>(seg->element(c1->track()));
if (!c || c->type() != Element::Type::CHORD)
Chord* c = toChord(seg->element(c1->track()));
if (!c || !c->isChord())
continue;
if (c->up() != up)
return true;
Expand All @@ -1416,7 +1424,7 @@ void Slur::layoutSystem(System* system)
SlurSegment* slurSegment = 0;
for (SpannerSegment* ss : segments) {
if (!ss->system()) {
slurSegment = static_cast<SlurSegment*>(ss);
slurSegment = toSlurSegment(ss);
break;
}
}
Expand Down Expand Up @@ -1590,8 +1598,8 @@ void Slur::layout()
}
Measure* m1 = startCR()->measure();

Chord* c1 = (startCR()->type() == Element::Type::CHORD) ? static_cast<Chord*>(startCR()) : 0;
Chord* c2 = (endCR()->type() == Element::Type::CHORD) ? static_cast<Chord*>(endCR()) : 0;
Chord* c1 = startCR()->isChord() ? toChord(startCR()) : 0;
Chord* c2 = endCR()->isChord() ? toChord(endCR()) : 0;

_up = !(startCR()->up());

Expand Down Expand Up @@ -1697,11 +1705,11 @@ void Slur::layout()

qreal SlurTie::firstNoteRestSegmentX(System* system)
{
foreach(const MeasureBase* mb, system->measures()) {
if (mb->type() == Element::Type::MEASURE) {
for (const MeasureBase* mb : system->measures()) {
if (mb->isMeasure()) {
const Measure* measure = static_cast<const Measure*>(mb);
for (const Segment* seg = measure->first(); seg; seg = seg->next()) {
if (seg->segmentType() == Segment::Type::ChordRest) {
if (seg->isChordRestType()) {
// first CR found; back up to previous segment
seg = seg->prev();
if (seg) {
Expand Down Expand Up @@ -1734,7 +1742,7 @@ qreal SlurTie::firstNoteRestSegmentX(System* system)
void Slur::setTrack(int n)
{
Element::setTrack(n);
foreach(SpannerSegment* ss, spannerSegments())
for (SpannerSegment* ss : spannerSegments())
ss->setTrack(n);
}

Expand Down Expand Up @@ -1779,9 +1787,9 @@ void SlurTie::startEdit(MuseScoreView* view, const QPointF& pt)
editEndElement = endElement();

editUps.clear();
foreach (SpannerSegment* s, spannerSegments()) {
for (SpannerSegment* s : spannerSegments()) {
SlurOffsets o;
SlurSegment* ss = static_cast<SlurSegment*>(s);
SlurSegment* ss = toSlurSegment(s);
o.o[0] = ss->getProperty(P_ID::SLUR_UOFF1).toPointF();
o.o[1] = ss->getProperty(P_ID::SLUR_UOFF2).toPointF();
o.o[2] = ss->getProperty(P_ID::SLUR_UOFF3).toPointF();
Expand Down
2 changes: 2 additions & 0 deletions libmscore/spanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class SpannerSegment : public Element {
SpannerSegmentType spannerSegmentType() const { return _spannerSegmentType; }
bool isSingleType() const { return spannerSegmentType() == SpannerSegmentType::SINGLE; }
bool isBeginType() const { return spannerSegmentType() == SpannerSegmentType::BEGIN; }
bool isSingleBeginType() const { return isSingleType() || isBeginType(); }
bool isSingleEndType() const { return isSingleType() || isEndType(); }
bool isMiddleType() const { return spannerSegmentType() == SpannerSegmentType::MIDDLE; }
bool isEndType() const { return spannerSegmentType() == SpannerSegmentType::END; }

Expand Down
1 change: 1 addition & 0 deletions libmscore/textframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TBox : public VBox {
virtual TBox* clone() const { return new TBox(*this); }
virtual Element::Type type() const { return Element::Type::TBOX; }
virtual void write(Xml&) const override;
using VBox::write;
virtual void read(XmlReader&) override;
virtual Element* drop(const DropData&) override;
virtual void add(Element* e) override;
Expand Down

1 comment on commit 863c9ac

@Jojo-Schmitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this commit causes some mtest failures

Please sign in to comment.