simplify and comment getGraceSegment

This commit is contained in:
lasconic 2012-09-30 15:46:17 +02:00
parent 664599032b
commit c47cad0235

View file

@ -784,35 +784,26 @@ Segment* Measure::getGraceSegment(int t, int gl)
{ {
Segment* s = 0; Segment* s = 0;
// find the first segment at tick >= t // find the first segment at tick == t and create it if necessary
for (Segment* ss = first(Segment::SegChordRest); ss && ss->tick() <= t; ss = ss->next(Segment::SegChordRest)) { for (Segment* ss = first(Segment::SegChordRest); ss && ss->tick() <= t; ss = ss->next(Segment::SegChordRest)) {
if(ss->tick() == t) { if(ss->tick() == t) {
s = ss; s = ss;
break; break;
} }
} }
if (s == 0) { if (s == 0) {
s = new Segment(this, Segment::SegChordRest, t); s = new Segment(this, Segment::SegChordRest, t);
add(s); add(s);
} }
// find the first SegChordRest segment at tick = t
// while counting the SegGrace segments
int nGraces = 0; int nGraces = 0;
Segment* sCr = 0; Segment* sCr = s;
for (Segment* ss = s; ss && ss->tick() == t; ss = ss->next()) { // count SegGrace segments
if (ss->subtype() == Segment::SegChordRest) { for (Segment* ss = sCr; ss && ss->tick() == t; ss = ss->prev()) {
sCr = ss; if ((ss->subtype() == Segment::SegGrace) && (ss->tick() == t))
break; nGraces++;
}
} }
//create grace segment if necessary
for (Segment* ss = sCr; ss && ss->tick() == t; ss = ss->prev()) {
if ((ss->subtype() == Segment::SegGrace) && (ss->tick() == t))
nGraces++;
}
for (; nGraces < gl; ++nGraces) { for (; nGraces < gl; ++nGraces) {
Segment* ps = new Segment(this, Segment::SegGrace, t); Segment* ps = new Segment(this, Segment::SegGrace, t);
_segments.insert(ps, s); _segments.insert(ps, s);