Skip to content

Commit

Permalink
fix #27901
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jul 21, 2014
1 parent 17910f7 commit 28a31cc
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion libmscore/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ bool Element::readProperties(XmlReader& e)
// when we re-discover the issue that caused the check for SYMBOL to be added,
// we will need to find a different solution if possible
if (score()->mscVersion() > 114 || (type() != Element::Type::GLISSANDO && type() != Element::Type::FINGERING))
e.setTick(score()->fileDivision(val));
e.initTick(score()->fileDivision(val));
}
}
else if (tag == "offset")
Expand Down
10 changes: 5 additions & 5 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ void Measure::read(XmlReader& e, int staffIdx)

// tick is obsolete
if (e.hasAttribute("tick"))
e.setTick(score()->fileDivision(e.intAttribute("tick")));
e.initTick(score()->fileDivision(e.intAttribute("tick")));
// setTick(e.tick());
// e.setTick(tick());

Expand All @@ -1758,7 +1758,7 @@ void Measure::read(XmlReader& e, int staffIdx)
const QStringRef& tag(e.name());

if (tag == "tick")
e.setTick(e.readInt());
e.initTick(e.readInt());
else if (tag == "BarLine") {
BarLine* barLine = new BarLine(score());
barLine->setTrack(e.track());
Expand Down Expand Up @@ -1871,7 +1871,7 @@ void Measure::read(XmlReader& e, int staffIdx)
tremolo->setParent(chord);
}
}
e.rtick() += crticks;
e.incTick(crticks);
}
}
else if (tag == "Rest") {
Expand All @@ -1887,7 +1887,7 @@ void Measure::read(XmlReader& e, int staffIdx)
rest->setDuration(timesig()/timeStretch);
Fraction ts(timeStretch * rest->globalDuration());

e.rtick() += ts.ticks();
e.incTick(ts.ticks());
}
else if (tag == "Breath") {
Breath* breath = new Breath(score());
Expand Down Expand Up @@ -1963,7 +1963,7 @@ void Measure::read(XmlReader& e, int staffIdx)
rm->read(e);
segment = getSegment(Segment::Type::ChordRest, e.tick());
segment->add(rm);
e.setTick(e.tick() + ticks());
e.incTick(ticks());
}
else if (tag == "Clef") {
Clef* clef = new Clef(score());
Expand Down
29 changes: 15 additions & 14 deletions libmscore/paste.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
break;
}
QString version = e.attribute("version", "NONE");
if(version != MSC_VERSION)
if (version != MSC_VERSION)
break;
int tickStart = e.intAttribute("tick", 0);
tickLen = e.intAttribute("len", 0);
int srcStaffStart = e.intAttribute("staff", 0);
staves = e.intAttribute("staves", 0);
e.setTick(tickStart);
e.setTickOffset(dstTick - tickStart);
e.initTick(0);

while (e.readNextStartElement()) {
if (done)
Expand Down Expand Up @@ -89,7 +90,7 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
e.setTransposeDiatonic(e.readInt());
else if (tag == "tick") {
int tick = e.readInt();
e.setTick(tick);
e.initTick(tick);
int shift = tick - tickStart;
if (makeGap && !makeGap1(dstTick + shift, dstStaffIdx, Fraction::fromTicks(tickLen - shift))) {
qDebug("cannot make gap in staff %d at tick %d", dstStaffIdx, dstTick + shift);
Expand All @@ -102,7 +103,7 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
Tuplet* tuplet = new Tuplet(this);
tuplet->setTrack(e.track());
tuplet->read(e);
int tick = e.tick() - tickStart + dstTick;
int tick = e.tick();
Measure* measure = tick2measure(tick);
tuplet->setParent(measure);
tuplet->setTick(tick);
Expand All @@ -116,11 +117,11 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
int voice = cr->voice();
int track = dstStaffIdx * VOICES + voice;
cr->setTrack(track);
int tick = e.tick() - tickStart + dstTick;
int tick = e.tick();
if (cr->isGrace())
graceNotes.push_back(static_cast<Chord*>(cr));
else {
e.setTick(e.tick() + cr->actualTicks());
e.incTick(cr->actualTicks());
if (cr->type() == Element::Type::CHORD) {
Chord* chord = static_cast<Chord*>(cr);
for (int i = 0; i < graceNotes.size(); ++i) {
Expand All @@ -144,22 +145,22 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
sp->read(e);
sp->setTrack(dstStaffIdx * VOICES);
sp->setTrack2(dstStaffIdx * VOICES);
sp->setTick(e.tick() - tickStart + dstTick);
sp->setTick(e.tick());
addSpanner(sp);
}
else if (tag == "Slur") {
Spanner* sp = static_cast<Spanner*>(Element::name2Element(tag, this));
sp->read(e);
sp->setTrack(dstStaffIdx * VOICES);
sp->setTick(e.tick() - tickStart + dstTick);
sp->setTick(e.tick());
undoAddElement(sp);
}
else if (tag == "endSpanner") {
int id = e.intAttribute("id");
Spanner* spanner = e.findSpanner(id);
if (spanner) {
// e.spanner().removeOne(spanner);
spanner->setTick2(e.tick() - tickStart + dstTick);
spanner->setTick2(e.tick());
removeSpanner(spanner);
undoAddElement(spanner);
if (spanner->type() == Element::Type::OTTAVA)
Expand All @@ -178,7 +179,7 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
lyrics->setTrack(e.track());
lyrics->read(e);
lyrics->setTrack(dstStaffIdx * VOICES);
int tick = e.tick() - tickStart + dstTick;
int tick = e.tick();
Segment* segment = tick2segment(tick);
if (segment) {
lyrics->setParent(segment);
Expand All @@ -205,7 +206,7 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
undoTransposeHarmony(harmony, rootTpc, baseTpc);
}

int tick = e.tick() - tickStart + dstTick;
int tick = e.tick();
Measure* m = tick2measure(tick);
Segment* seg = m->undoGetSegment(Segment::Type::ChordRest, tick);
harmony->setParent(seg);
Expand All @@ -225,7 +226,7 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
Element* el = Element::name2Element(tag, this);
el->setTrack(dstStaffIdx * VOICES); // a valid track might be necessary for el->read() to work

int tick = e.tick() - tickStart + dstTick;
int tick = e.tick();
Measure* m = tick2measure(tick);
Segment* seg = m->undoGetSegment(Segment::Type::ChordRest, tick);
el->setParent(seg);
Expand All @@ -240,7 +241,7 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
Clef* clef = new Clef(this);
clef->read(e);
clef->setTrack(dstStaffIdx * VOICES);
int tick = e.tick() - tickStart + dstTick;
int tick = e.tick();
Measure* m = tick2measure(tick);
if (m->tick() && m->tick() == tick)
m = m->prevMeasure();
Expand All @@ -252,7 +253,7 @@ void Score::pasteStaff(XmlReader& e, Segment* dst, int staffIdx)
Breath* breath = new Breath(this);
breath->read(e);
breath->setTrack(dstStaffIdx * VOICES);
int tick = e.tick() - tickStart + dstTick;
int tick = e.tick();
Measure* m = tick2measure(tick);
Segment* segment = m->undoGetSegment(Segment::Type::Breath, tick);
breath->setParent(segment);
Expand Down
2 changes: 1 addition & 1 deletion libmscore/read114.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Score::FileError Score::read114(XmlReader& e)
if (s->tick() == -1)
s->setTick(e.tick());
else
e.setTick(s->tick()); // update current tick
e.initTick(s->tick()); // update current tick
if (s->track2() == -1)
s->setTrack2(s->track());
if (s->tick2() == -1) {
Expand Down
10 changes: 5 additions & 5 deletions libmscore/scorefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void Score::write(Xml& xml, bool selectionOnly)
void Score::readStaff(XmlReader& e)
{
int staff = e.intAttribute("id", 1) - 1;
e.setTick(0);
e.initTick(0);
e.setTrack(staff * VOICES);

if (staff == 0) {
Expand Down Expand Up @@ -235,7 +235,7 @@ void Score::readStaff(XmlReader& e)
if (!measure->isMMRest()) {
measures()->add(measure);
e.setLastMeasure(measure);
e.setTick(measure->tick() + measure->ticks());
e.initTick(measure->tick() + measure->ticks());
}
}
else if (tag == "HBox" || tag == "VBox" || tag == "TBox" || tag == "FBox") {
Expand All @@ -245,7 +245,7 @@ void Score::readStaff(XmlReader& e)
measures()->add(mb);
}
else if (tag == "tick")
e.setTick(e.readInt());
e.initTick(e.readInt());
else
e.unknown();
}
Expand All @@ -262,7 +262,7 @@ void Score::readStaff(XmlReader& e)
measure->setTick(e.tick());
measures()->add(measure);
}
e.setTick(measure->tick());
e.initTick(measure->tick());
measure->read(e, staff);
if (measure->isMMRest())
measure = e.lastMeasure()->nextMeasure();
Expand All @@ -275,7 +275,7 @@ void Score::readStaff(XmlReader& e)
}
}
else if (tag == "tick")
e.setTick(e.readInt());
e.initTick(e.readInt());
else
e.unknown();
}
Expand Down
14 changes: 8 additions & 6 deletions libmscore/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class XmlReader : public XmlStreamReader {
QString docName; // used for error reporting

// Score read context (for read optimizations):
int _tick = 0;
int _tick = 0;
int _tickOffset = 0;
int _track = 0;
Measure* _lastMeasure = 0;
QList<Beam*> _beams;
Expand Down Expand Up @@ -86,11 +87,12 @@ class XmlReader : public XmlStreamReader {
void setDocName(const QString& s) { docName = s; }
QString getDocName() const { return docName; }

int tick() const { return _tick; }
int& rtick() { return _tick; }
void setTick(int val) { _tick = val; }
int track() const { return _track; }
void setTrack(int val) { _track = val; }
int tick() const { return _tick + _tickOffset; }
void initTick(int val) { _tick = val; }
void incTick(int val) { _tick += val; }
void setTickOffset(int val) { _tickOffset = val; }
int track() const { return _track; }
void setTrack(int val) { _track = val; }
void addTuplet(Tuplet* s);
void addBeam(Beam* s) { _beams.append(s); }

Expand Down
2 changes: 1 addition & 1 deletion mscore/debugger/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ void Debugger::updateElement(Element* el)
for (int i = 0;; ++i) {
QTreeWidgetItem* item = list->topLevelItem(i);
if (item == 0) {
qDebug("Debugger::Element not found %s %p", el->name(), el);
qDebug("Debugger::Element not found %s %p idx %d", el->name(), el, i);
break;
}
if (item->type() == QTreeWidgetItem::Type)
Expand Down

0 comments on commit 28a31cc

Please sign in to comment.