Skip to content

Commit

Permalink
fix #38341
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Nov 13, 2014
1 parent b86905b commit 4196bd1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
49 changes: 28 additions & 21 deletions libmscore/range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ void TrackList::appendGap(const Fraction& d)
// read
//---------------------------------------------------------

void TrackList::read(int track, const Segment* fs, const Segment* es)
void TrackList::read(const Segment* fs, const Segment* es)
{
int tick = fs->tick();
int gap = 0;
const Segment* s;
for (s = fs; s && (s != es); s = s->next1()) {
Element* e = s->element(track);
Element* e = s->element(_track);
if (!e || e->generated()) {
foreach(Element* ee, s->annotations()) {
if (ee->track() == track)
if (ee->track() == _track)
_range->annotations.push_back({ s->tick(), ee->clone() });
}
continue;
Expand Down Expand Up @@ -306,10 +306,10 @@ void TrackList::dump() const

//---------------------------------------------------------
// write
// rewrite notes into measure list m
// rewrite notes into measure list measure
//---------------------------------------------------------

bool TrackList::write(int track, Measure* measure) const
bool TrackList::write(Measure* measure) const
{
Fraction pos;
Measure* m = measure;
Expand Down Expand Up @@ -341,11 +341,11 @@ bool TrackList::write(int track, Measure* measure) const
// handle full measure rest
//
segment = m->getSegment(e, m->tick() + pos.ticks());
if ((track % VOICES) == 0) {
if ((_track % VOICES) == 0) {
// write only for voice 1
Rest* r = new Rest(score, TDuration::DurationType::V_MEASURE);
r->setDuration(m->len());
r->setTrack(track);
r->setTrack(_track);
segment->add(r);
}
duration -= m->len();
Expand All @@ -357,7 +357,7 @@ bool TrackList::write(int track, Measure* measure) const
if (e->type() == Element::Type::REST || e->type() == Element::Type::REPEAT_MEASURE) {
segment = m->getSegment(Segment::Type::ChordRest, m->tick() + pos.ticks());
Rest* r = new Rest(score, TDuration(d));
r->setTrack(track);
r->setTrack(_track);
segment->add(r);
duration -= d;
rest -= d;
Expand All @@ -367,7 +367,7 @@ bool TrackList::write(int track, Measure* measure) const
segment = m->getSegment(e, m->tick() + pos.ticks());
Chord* c = static_cast<Chord*>(e)->clone();
c->setScore(score);
c->setTrack(track);
c->setTrack(_track);
c->setDuration(d);
c->setDurationType(TDuration(d));
segment->add(c);
Expand Down Expand Up @@ -400,7 +400,7 @@ bool TrackList::write(int track, Measure* measure) const
else {
if (!duration.isZero()) {
qDebug("Tracklist::write: premature end of measure list in track %d, rest %d/%d",
track, duration.numerator(), duration.denominator());
_track, duration.numerator(), duration.denominator());
++i;
qDebug("%d elements missing", n-i);
for (; i < n; ++i) {
Expand Down Expand Up @@ -437,7 +437,7 @@ bool TrackList::write(int track, Measure* measure) const
segment = m->getSegment(e, m->tick() + ((e->type() == Element::Type::KEYSIG) ? 0 : pos.ticks()));
Element* ne = e->clone();
ne->setScore(score);
ne->setTrack(track);
ne->setTrack(_track);
segment->add(ne);
}
}
Expand All @@ -447,7 +447,7 @@ bool TrackList::write(int track, Measure* measure) const
//

for (Segment* s = measure->first(); s; s = s->next1()) {
Chord* chord = static_cast<Chord*>(s->element(track));
Chord* chord = static_cast<Chord*>(s->element(_track));
if (chord == 0 || chord->type() != Element::Type::CHORD)
continue;
foreach (Note* n, chord->notes()) {
Expand Down Expand Up @@ -498,8 +498,12 @@ void ScoreRange::read(Segment* first, Segment* last)
{
_first = first;
_last = last;
Score* score = first->score();
QList<int> sl = score->uniqueStaves();

int startTrack = 0;
int endTrack = first->score()->nstaves() * VOICES;
int endTrack = score->nstaves() * VOICES;

spanner.clear();
for (auto i : first->score()->spanner()) {
Spanner* s = i.second;
Expand All @@ -511,10 +515,15 @@ void ScoreRange::read(Segment* first, Segment* last)
spanner.push_back(ns);
}
}
for (int track = startTrack; track < endTrack; ++track) {
TrackList* dl = new TrackList(this);
dl->read(track, first, last);
tracks.append(dl);
for (int staffIdx : sl) {
int sTrack = staffIdx * VOICES;
int eTrack = sTrack + VOICES;
for (int track = sTrack; track < eTrack; ++track) {
TrackList* dl = new TrackList(this);
dl->setTrack(track);
dl->read(first, last);
tracks.append(dl);
}
}
}

Expand All @@ -524,11 +533,10 @@ void ScoreRange::read(Segment* first, Segment* last)

bool ScoreRange::write(Score* score, int tick) const
{
int track = 0;
for (TrackList* dl : tracks) {
if (!dl->write(track, score->tick2measure(tick)))
int track = dl->track();
if (!dl->write(score->tick2measure(tick)))
return false;

if ((track % VOICES) == 0) {
int staffIdx = track / VOICES;
Staff* ostaff = score->staff(staffIdx);
Expand All @@ -541,7 +549,6 @@ bool ScoreRange::write(Score* score, int tick) const
}
}
}

++track;
}
for (Spanner* s : spanner) {
Expand Down
8 changes: 6 additions & 2 deletions libmscore/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ class TrackList : public QList<Element*>
{
Fraction _duration;
ScoreRange* _range;
int _track;

Tuplet* writeTuplet(Tuplet* tuplet, Measure* measure, int tick) const;
void append(Element*);

public:
TrackList(ScoreRange* r) { _range = r; }
~TrackList();
void read(int track, const Segment* fs, const Segment* ls);

int track() const { return _track; }
void setTrack(int val) { _track = val; }
void read(const Segment* fs, const Segment* ls);
bool canWrite(const Fraction& f) const;
bool write(int track, Measure*) const;
bool write(Measure*) const;
Fraction duration() const { return _duration; }
ScoreRange* range() const { return _range; }
void appendGap(const Fraction&);
Expand Down
4 changes: 4 additions & 0 deletions libmscore/undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,10 @@ void AddElement::endUndoRedo(bool isUndo) const
undoRemoveTuplet(static_cast<ChordRest*>(element));
else
undoAddTuplet(static_cast<ChordRest*>(element));
if (element->type() == Element::Type::CHORD) {
Measure* m = static_cast<Chord*>(element)->measure();
m->cmdUpdateNotes(element->staffIdx());
}
}
else if (element->type() == Element::Type::NOTE) {
Measure* m = static_cast<Note*>(element)->chord()->measure();
Expand Down

0 comments on commit 4196bd1

Please sign in to comment.