Skip to content

Commit

Permalink
some regression fixes, code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Apr 13, 2016
1 parent 9f933d8 commit 3d8749f
Show file tree
Hide file tree
Showing 51 changed files with 680 additions and 595 deletions.
2 changes: 1 addition & 1 deletion libmscore/arpeggio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ void Arpeggio::symbolLine(SymId end, SymId fill)
ScoreFont* f = score()->scoreFont();

symbols.clear();
symbols.push_back(end);
qreal w1 = f->advance(end, mag);
qreal w2 = f->advance(fill, mag);
int n = lrint((w - w1) / w2);
for (int i = 0; i < n; ++i)
symbols.push_back(fill);
symbols.push_back(end);
}

//---------------------------------------------------------
Expand Down
99 changes: 63 additions & 36 deletions libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,34 +642,27 @@ Element* BarLine::drop(const DropData& data)
{
Element* e = data.element;
Element::Type type = e->type();

if (type == Element::Type::BAR_LINE) {
BarLine* bl = static_cast<BarLine*>(e);
BarLine* bl = e->barLine(); // static_cast<BarLine*>(e);
BarLineType st = bl->barLineType();

// if no change in subtype or no change in span, do nothing
if (st == barLineType() && bl->spanFrom() == 0 && bl->spanTo() == DEFAULT_BARLINE_TO) {
delete e;
return 0;
}
// system left-side bar line: route type change to first measure of system
if (parent()->type() == Element::Type::SYSTEM) {
Measure* m = static_cast<System*>(parent())->firstMeasure();
if (m && m->systemInitialBarLineType() != bl->barLineType())
m->undoChangeProperty(P_ID::SYSTEM_INITIAL_BARLINE_TYPE, int(bl->barLineType()));
delete e;
return 0;
}

// parent is a segment
Measure* m = static_cast<Segment*>(parent())->measure();
// check if the new property can apply to this single bar line
bool oldRepeat = (barLineType() == BarLineType::START_REPEAT || barLineType() == BarLineType::END_REPEAT
|| barLineType() == BarLineType::END_START_REPEAT);
bool newRepeat = (bl->barLineType() == BarLineType::START_REPEAT || bl->barLineType() == BarLineType::END_REPEAT
|| bl->barLineType() == BarLineType::END_START_REPEAT);

// if ctrl was used and repeats are not involved,
// or if drop refers to span rather than subtype =>
// single bar line drop
if (((data.modifiers & Qt::ControlModifier) && !oldRepeat && !newRepeat) || (bl->spanFrom() != 0 || bl->spanTo() != DEFAULT_BARLINE_TO) ) {

if ((data.control() && !oldRepeat && !newRepeat) || (bl->spanFrom() != 0 || bl->spanTo() != DEFAULT_BARLINE_TO) ) {
// if drop refers to span, update this bar line span
if (bl->spanFrom() != 0 || bl->spanTo() != DEFAULT_BARLINE_TO) {
// if dropped spanFrom or spanTo are below the middle of standard staff (5 lines)
Expand All @@ -680,28 +673,67 @@ Element* BarLine::drop(const DropData& data)
score()->undoChangeSingleBarLineSpan(this, 1, spanFrom, spanTo);
}
// if drop refers to subtype, update this bar line subtype
else {
// score()->undoChangeBarLine(m, bl->barLineType());
score()->undoChangeProperty(this, P_ID::SUBTYPE, int(bl->barLineType()));
}
else
undoChangeProperty(P_ID::BARLINE_TYPE, int(bl->barLineType()));
delete e;
return 0;
}

// drop applies to all bar lines of the measure
if (st == BarLineType::START_REPEAT) {
m = m->nextMeasure();
if (m == 0) {
delete e;
return 0;
//---------------------------------------------
// Update repeat flags for current measure
// and next measure if this is a EndBarLine.
//---------------------------------------------

if (segment()->segmentType() == Segment::Type::EndBarLine) {
Measure* m = segment()->measure();
Measure* nm = m->nextMeasure();
switch (st) {
case BarLineType::END_REPEAT:
m->undoChangeProperty(P_ID::REPEAT_END, true);
if (nm && nm->system() == m->system())
nm->undoChangeProperty(P_ID::REPEAT_START, false);
break;
case BarLineType::START_REPEAT:
m->undoChangeProperty(P_ID::REPEAT_END, false);
if (nm)
nm->undoChangeProperty(P_ID::REPEAT_START, true);
break;
case BarLineType::END_START_REPEAT:
m->undoChangeProperty(P_ID::REPEAT_END, true);
if (nm)
nm->undoChangeProperty(P_ID::REPEAT_START, true);
break;
case BarLineType::DOUBLE:
case BarLineType::BROKEN:
case BarLineType::END:
case BarLineType::DOTTED:
for (Element* e : segment()->elist()) {
if (e)
e->undoChangeProperty(P_ID::GENERATED, false);
}

case BarLineType::NORMAL:
if (nm && nm->system() == m->system())
nm->undoChangeProperty(P_ID::REPEAT_START, false);
m->undoChangeProperty(P_ID::REPEAT_END, false);
for (Element* e : segment()->elist()) {
if (e)
e->undoChangeProperty(P_ID::BARLINE_TYPE, int(st));
}
break;
}
}
//TODO score()->undoChangeBarLine(m, bl->barLineType());
else if (segment()->segmentType() == Segment::Type::BeginBarLine) {
undoChangeProperty(P_ID::BARLINE_TYPE, int(st));
undoChangeProperty(P_ID::GENERATED, false);
}

delete e;
return 0;
}

else if (type == Element::Type::ARTICULATION) {
Articulation* atr = static_cast<Articulation*>(e);
Articulation* atr = e->articulation();
atr->setParent(this);
atr->setTrack(track());
score()->undoAddElement(atr);
Expand Down Expand Up @@ -1216,8 +1248,6 @@ void BarLine::add(Element* e)
case Element::Type::ARTICULATION:
_el.push_back(e);
setGenerated(false);
// if (parent() && parent()->parent())
// static_cast<Measure*>(parent()->parent())->setEndBarLineGenerated(false);
break;
default:
qDebug("BarLine::add() not impl. %s", e->name());
Expand Down Expand Up @@ -1281,8 +1311,7 @@ void BarLine::updateCustomType()
case Segment::Type::StartRepeatBarLine:
// if a start-repeat segment, ref. type is START_REPEAT
// if measure has relevant repeat flag or none if measure hasn't
refType = (seg->measure()->repeatFlags() & Repeat::START) != 0
? BarLineType::START_REPEAT : BarLineType(-1);
refType = seg->measure()->repeatStart() ? BarLineType::START_REPEAT : BarLineType(-1);
break;
case Segment::Type::BarLine:
// if a non-end-measure bar line, type is always custom
Expand Down Expand Up @@ -1357,7 +1386,7 @@ void BarLine::updateGenerated(bool canBeTrue)
QVariant BarLine::getProperty(P_ID id) const
{
switch (id) {
case P_ID::SUBTYPE:
case P_ID::BARLINE_TYPE:
return int(_barLineType);
case P_ID::BARLINE_SPAN:
return span();
Expand All @@ -1378,7 +1407,7 @@ QVariant BarLine::getProperty(P_ID id) const
bool BarLine::setProperty(P_ID id, const QVariant& v)
{
switch(id) {
case P_ID::SUBTYPE:
case P_ID::BARLINE_TYPE:
setBarLineType(BarLineType(v.toInt()));
break;
case P_ID::BARLINE_SPAN:
Expand All @@ -1404,11 +1433,9 @@ bool BarLine::setProperty(P_ID id, const QVariant& v)
QVariant BarLine::propertyDefault(P_ID propertyId) const
{
switch (propertyId) {
case P_ID::SUBTYPE:
// default subtype is the subtype of the measure, if any

//TODO? if (parent() && parent()->type() == Element::Type::SEGMENT && static_cast<Segment*>(parent())->measure() )
// return int(static_cast<Segment*>(parent())->measure()->endBarLineType());
case P_ID::BARLINE_TYPE:
if (segment() && segment()->measure() && !segment()->measure()->nextMeasure())
return int(BarLineType::END);
return int(BarLineType::NORMAL);

case P_ID::BARLINE_SPAN:
Expand Down
2 changes: 2 additions & 0 deletions libmscore/barline.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class BarLine : public Element {
virtual bool acceptDrop(const DropData&) const override;
virtual Element* drop(const DropData&) override;

Segment* segment() const { return (Segment*)parent(); }

void setCustomSpan(bool val) { _customSpan = val; }
void setCustomSubtype(bool val) { _customSubtype = val; }
void setSpan(int val);
Expand Down
3 changes: 2 additions & 1 deletion libmscore/beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void Beam::layoutGraceNotes()
qreal graceMag = score()->styleD(StyleIdx::graceNoteMag);
setMag(graceMag);

foreach (ChordRest* cr, _elements) {
for (ChordRest* cr : _elements) {
c2 = static_cast<Chord*>(cr);
if (c1 == 0)
c1 = c2;
Expand Down Expand Up @@ -1924,6 +1924,7 @@ void Beam::layout2(QList<ChordRest*>crl, SpannerSegmentType, int frag)
x2, beamSegments.front()->x1(),
beamSegments.back()->x2());
}
by = 0;
}
if (stem) {
stem->setLen(y2 - (by + _pagePos.y()));
Expand Down
11 changes: 6 additions & 5 deletions libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ void Chord::layout2()
s = nullptr;
// start from the right (if next segment found, x of it relative to this chord;
// chord right space otherwise)
qreal xOff = s ? s->pos().x() - (segment()->pos().x() + pos().x()) : 0.0; // TODO: space().rw();
qreal xOff = s ? s->pos().x() - (segment()->pos().x() + pos().x()) : _spaceRw;
// final distance: if near to another chord, leave minNoteDist at right of last grace
// else leave note-to-barline distance;
xOff -= (s != nullptr && s->segmentType() != Segment::Type::ChordRest)
Expand All @@ -1562,9 +1562,9 @@ void Chord::layout2()
int n = gna.size();
for (int i = n-1; i >= 0; i--) {
Chord* g = gna.value(i);
//TODO xOff -= g->space().rw(); // move to left by grace note left space (incl. grace own width)
xOff -= g->_spaceRw; // move to left by grace note left space (incl. grace own width)
g->rxpos() = xOff;
//TODO xOff -= minNoteDist + g->space().lw(); // move to left by grace note right space and inter-grace distance
xOff -= minNoteDist + g->_spaceLw; // move to left by grace note right space and inter-grace distance
}
}

Expand Down Expand Up @@ -2001,7 +2001,7 @@ void Chord::layoutPitched()
_spaceRw = rrr;

if (gnb){
qreal xl = 0.0; // TODO -(_spaceLw + minNoteDistance) - chordX;
qreal xl = -(_spaceLw + minNoteDistance) - chordX;
for (int i = gnb-1; i >= 0; --i) {
Chord* g = graceNotesBefore.value(i);
xl -= g->_spaceRw/* * 1.2*/;
Expand Down Expand Up @@ -3211,13 +3211,14 @@ Shape Chord::shape() const
Shape s = e->shape();
// compute distance between grace notes and chord
// TODO: distinguish between grace notes before/after
if (e->type() == Element::Type::CHORD) {
/* if (e->type() == Element::Type::CHORD) {
qreal minNoteDistance = score()->styleD(StyleIdx::minNoteDistance);
qreal nhw = score()->noteHeadWidth() * score()->styleD(StyleIdx::graceNoteMag);
qreal dist = qMax(s.minHorizontalDistance(shape), nhw) + minNoteDistance;
e->rxpos() = -dist;
s.translate(e->pos());
}
*/
shape.add(s);
});
shape.add(ChordRest::shape());
Expand Down
2 changes: 1 addition & 1 deletion libmscore/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ void ChordRest::removeDeleteBeam(bool beamed)
}
if (chord->hook())
score()->undoRemoveElement(chord->hook());
if (chord->stem())
if (chord->stem() && !chord->isGrace())
chord->layoutStem();
}
}
Expand Down
13 changes: 10 additions & 3 deletions libmscore/clef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ void Clef::setSelected(bool f)

void Clef::layout()
{
setPos(QPoint());

// determine current number of lines and line distance
int lines;
qreal lineDist;
Expand Down Expand Up @@ -181,7 +179,7 @@ void Clef::layout()
// if courtesy clef: show if score has courtesy clefs on
|| ( score()->styleB(StyleIdx::genCourtesyClef)
// AND measure is not at the end of a repeat or of a section
&& !( (m->repeatFlags() & Repeat::END) || m->isFinalMeasureOfSection() )
&& !( m->repeatEnd() || m->isFinalMeasureOfSection() )
// AND this clef has courtesy clef turned on
&& showCourtesy() );
}
Expand Down Expand Up @@ -316,7 +314,16 @@ void Clef::layout()
r |= e->bbox().translated(e->pos());
e->setSelected(selected());
}

// clefs are right aligned to Segment

qreal clefKeyRightMargin = score()->styleS(StyleIdx::clefKeyRightMargin).val() * _spatium;
QPointF off(-r.right() - clefKeyRightMargin, 0);
for (Element* e : elements)
e->move(off);
r.translate(off);
setbbox(r);
setPos(QPointF());
}

//---------------------------------------------------------
Expand Down
64 changes: 20 additions & 44 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,55 +1843,31 @@ void Score::deleteItem(Element* el)

case Element::Type::BAR_LINE:
{
BarLine* bl = static_cast<BarLine*>(el);
// if system initial bar ine, route change to system first measure
if (bl->parent()->type() == Element::Type::SYSTEM) {
Measure* m = static_cast<System*>(bl->parent())->firstMeasure();
if (m && m->systemInitialBarLineType() != BarLineType::NORMAL)
m->undoChangeProperty(P_ID::SYSTEM_INITIAL_BARLINE_TYPE, int(BarLineType::NORMAL));
break;
}
// if regular measure bar line
Segment* seg = static_cast<Segment*>(bl->parent());
//TODO bool normalBar = seg->measure()->endBarLineType() == BarLineType::NORMAL;
bool normalBar = true;
int tick = seg->tick();
BarLine* bl = el->barLine();
Segment* seg = bl->segment();
Measure* m = seg->measure();
Segment::Type segType = seg->segmentType();

if (segType == Segment::Type::BarLine) {
if (segType == Segment::Type::BarLine)
undoRemoveElement(el);
break;
}

foreach(Score* score, scoreList()) {
Measure* m = score->tick2measure(tick);
if (segType == Segment::Type::StartRepeatBarLine)
undoChangeProperty(m, P_ID::REPEAT_FLAGS, int(m->repeatFlags()) & ~int(Repeat::START));
else if (segType == Segment::Type::EndBarLine) {
// if bar line has custom barLineType, change to barLineType of the whole measure
//TODO if (bl->customSubtype()) {
// undoChangeProperty(bl, P_ID::SUBTYPE, int(seg->measure()->endBarLineType()));
// }
// otherwise, if whole measure has special end bar line, change to normal
/*else*/ if (!normalBar) {
if (m->tick() >= tick)
m = m->prevMeasure();
undoChangeProperty(m, P_ID::REPEAT_FLAGS, int(m->repeatFlags()) & ~int(Repeat::END));
Measure* nm = m->nextMeasure();
if (nm)
undoChangeProperty(nm, P_ID::REPEAT_FLAGS, int(nm->repeatFlags()) & ~int(Repeat::START));
// undoChangeEndBarLineType(m, BarLineType::NORMAL);
//TODO m->setEndBarLineGenerated(true);
}
// if bar line has custom span, reset to staff default
if (bl->customSpan() && bl->staff()) {
Staff* stf = bl->staff();
undoChangeProperty(bl, P_ID::BARLINE_SPAN, stf->barLineSpan());
undoChangeProperty(bl, P_ID::BARLINE_SPAN_FROM, stf->barLineFrom());
undoChangeProperty(bl, P_ID::BARLINE_SPAN_TO, stf->barLineTo());
}
else if (segType == Segment::Type::EndBarLine) {
m->undoResetProperty(P_ID::REPEAT_END);
Measure* nm = m->nextMeasure();
if (nm && m->system() == nm->system())
nm->undoResetProperty(P_ID::REPEAT_START);
for (Element* e : seg->elist()) {
if (!e)
continue;
BarLine* b = e->barLine();
b->undoChangeProperty(P_ID::GENERATED, true);
b->undoResetProperty(P_ID::BARLINE_TYPE);
b->undoResetProperty(P_ID::BARLINE_SPAN);
b->undoResetProperty(P_ID::BARLINE_SPAN_FROM);
b->undoResetProperty(P_ID::BARLINE_SPAN_TO);
}
}
else if (segType == Segment::Type::StartRepeatBarLine)
m->undoChangeProperty(P_ID::REPEAT_START, false);
}
break;

Expand Down
Loading

0 comments on commit 3d8749f

Please sign in to comment.