Skip to content

Commit

Permalink
fix #23230
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Oct 21, 2013
1 parent 7abd2b4 commit 3a6fa1f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 52 deletions.
10 changes: 10 additions & 0 deletions libmscore/durationtype.cpp
Expand Up @@ -507,5 +507,15 @@ void TDuration::print() const
qDebug(" %s,dots=%d)", s, _dots);
}

//---------------------------------------------------------
// setType
//---------------------------------------------------------

void TDuration::setType(DurationType t)
{
_val = t;
if (_val == V_MEASURE)
_dots = 0;
}
}

2 changes: 1 addition & 1 deletion libmscore/durationtype.h
Expand Up @@ -40,7 +40,7 @@ class TDuration {
bool isValid() const { return _val != V_INVALID; }
bool isZero() const { return _val == V_ZERO; }
void setVal(int tick);
void setType(DurationType t) { _val = t; }
void setType(DurationType t);
void setType(const QString&);

int ticks() const;
Expand Down
100 changes: 49 additions & 51 deletions libmscore/measure.cpp
Expand Up @@ -1579,11 +1579,13 @@ void Measure::adjustToLen(Fraction nf)
int ol = len().ticks();
int nl = nf.ticks();

score()->undo(new ChangeMeasureLen(this, nf));

int staves = score()->nstaves();
int diff = nl - ol;

if (nl > ol) {
// move EndBarLine
// move EndBarLine, TimeSigAnnounce, KeySigAnnounce
for (Segment* s = first(); s; s = s->next()) {
if (s->segmentType() & (Segment::SegEndBarLine|Segment::SegTimeSigAnnounce|Segment::SegKeySigAnnounce)) {
s->setTick(tick() + nl);
Expand All @@ -1600,65 +1602,61 @@ void Measure::adjustToLen(Fraction nf)
int etrack = strack + VOICES;
for (int track = strack; track < etrack; ++track) {
Element* e = segment->element(track);
if (e && e->type() == REST) {
++rests;
rest = static_cast<Rest*>(e);
if (e) {
if (e->type() == REST) {
++rests;
rest = static_cast<Rest*>(e);
}
else if (e->type() == CHORD)
++chords;
}
else if (e && e->type() == CHORD)
++chords;
}
}
if (rests == 1 && chords == 0 && rest->durationType().type() == TDuration::V_MEASURE) {
rest->setDuration(Fraction::fromTicks(nl));
continue;
}
if ((_timesig == _len) && (rests == 1) && (chords == 0)) {
rest->setDurationType(TDuration::V_MEASURE); // whole measure rest
if (rests == 1 && chords == 0) {
if (rest->durationType().type() == TDuration::V_MEASURE) {
rest->setDuration(nf);
continue;
}
else if (_timesig == nf) {
score()->undo(new ChangeChordRestLen(rest, TDuration(TDuration::V_MEASURE)));
continue;
}
}
else {
int strack = staffIdx * VOICES;
int etrack = strack + VOICES;

for (int trk = strack; trk < etrack; ++trk) {
int n = diff;
bool rFlag = false;
if (n < 0) {
for (Segment* segment = last(); segment;) {
Segment* pseg = segment->prev();
Element* e = segment->element(trk);
if (e && e->isChordRest()) {
ChordRest* cr = static_cast<ChordRest*>(e);
if (cr->durationType() == TDuration::V_MEASURE)
n = nl;
else
n += cr->actualTicks();
score()->undoRemoveElement(e);
if (segment->isEmpty())
score()->undoRemoveElement(segment);
if (n >= 0)
break;
}
segment = pseg;
int strack = staffIdx * VOICES;
int etrack = strack + VOICES;

for (int trk = strack; trk < etrack; ++trk) {
int n = diff;
bool rFlag = false;
if (n < 0) {
for (Segment* segment = last(); segment;) {
Segment* pseg = segment->prev();
Element* e = segment->element(trk);
if (e && e->isChordRest()) {
ChordRest* cr = static_cast<ChordRest*>(e);
if (cr->durationType() == TDuration::V_MEASURE)
n = nl;
else
n += cr->actualTicks();
score()->undoRemoveElement(e);
if (segment->isEmpty())
score()->undoRemoveElement(segment);
if (n >= 0)
break;
}
rFlag = true;
}
int voice = trk % VOICES;
if ((n > 0) && (rFlag || voice == 0)) {
// add rest to measure
int rtick = tick() + nl - n;
Segment* seg = undoGetSegment(Segment::SegChordRest, rtick);
TDuration d;
d.setVal(n);
rest = new Rest(score(), d);
rest->setDuration(d.fraction());
rest->setTrack(staffIdx * VOICES + voice);
rest->setParent(seg);
score()->undoAddElement(rest);
segment = pseg;
}
rFlag = true;
}
int voice = trk % VOICES;
if ((n > 0) && (rFlag || voice == 0)) {
// add rest to measure
int rtick = tick() + nl - n;
int track = staffIdx * VOICES + voice;
score()->setRest(rtick, track, Fraction::fromTicks(n), true, 0);
}
}
}
score()->undo(new ChangeMeasureLen(this, nf));
if (diff < 0) {
//
// CHECK: do not remove all slurs
Expand Down

0 comments on commit 3a6fa1f

Please sign in to comment.