Read/write beams without using IDs

This commit is contained in:
Dmitri Ovodok 2018-06-09 05:45:54 +03:00
parent 68a06d68b2
commit d0a24894d2
6 changed files with 22 additions and 22 deletions

View file

@ -1988,7 +1988,7 @@ void Beam::write(XmlWriter& xml) const
{
if (_elements.empty())
return;
xml.stag(QString("Beam id=\"%1\"").arg(_id));
xml.stag(name());
Element::writeProperties(xml);
writeProperty(xml, Pid::STEM_DIRECTION);
@ -2029,7 +2029,6 @@ void Beam::read(XmlReader& e)
{
QPointF p1, p2;
qreal _spatium = spatium();
_id = e.intAttribute("id");
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "StemDirection") {

View file

@ -905,9 +905,9 @@ Note* Chord::selectedNote() const
void Chord::write(XmlWriter& xml) const
{
for (Chord* c : _graceNotes) {
c->writeBeam(xml);
c->write(xml);
}
writeBeam(xml);
xml.stag("Chord");
ChordRest::writeProperties(xml);
for (const Articulation* a : _articulations)

View file

@ -171,13 +171,6 @@ void ChordRest::writeProperties(XmlWriter& xml) const
//xml.tagE("duration z=\"%d\" n=\"%d\"", duration().numerator(), duration().denominator());
}
#ifndef NDEBUG
if (_beam && (MScore::testMode || !_beam->generated()))
xml.tag("Beam", _beam->id());
#else
if (_beam && !_beam->generated())
xml.tag("Beam", _beam->id());
#endif
for (Lyrics* lyrics : _lyrics)
lyrics->write(xml);
if (!isGrace()) {
@ -264,14 +257,6 @@ bool ChordRest::readProperties(XmlReader& e)
qDebug("ChordRest: %s obsolete", tag.toLocal8Bit().data());
e.skipCurrentElement();
}
else if (tag == "Beam") {
int id = e.readInt();
Beam* beam = e.findBeam(id);
if (beam)
beam->add(this); // also calls this->setBeam(beam)
else
qDebug("Beam id %d not found", id);
}
else if (tag == "small")
_small = e.readInt();
else if (tag == "duration")
@ -889,11 +874,10 @@ bool ChordRest::isGraceAfter() const
// writeBeam
//---------------------------------------------------------
void ChordRest::writeBeam(XmlWriter& xml)
void ChordRest::writeBeam(XmlWriter& xml) const
{
Beam* b = beam();
if (b && b->elements().front() == this && (MScore::testMode || !b->generated())) {
b->setId(xml.nextBeamId());
b->write(xml);
}
}

View file

@ -1848,6 +1848,7 @@ void Measure::read(XmlReader& e, int staffIdx)
qreal _spatium = spatium();
QList<Chord*> graceNotes;
Beam* startingBeam = nullptr;
e.tuplets().clear();
e.setTrack(staffIdx * VOICES);
e.setCurrentMeasure(this);
@ -1929,6 +1930,10 @@ void Measure::read(XmlReader& e, int staffIdx)
Chord* chord = new Chord(score());
chord->setTrack(e.track());
chord->read(e);
if (startingBeam) {
startingBeam->add(chord); // also calls chord->setBeam(startingBeam)
startingBeam = nullptr;
}
segment = getSegment(SegmentType::ChordRest, e.tick());
if (chord->noteType() != NoteType::NORMAL)
graceNotes.push_back(chord);
@ -1950,6 +1955,10 @@ void Measure::read(XmlReader& e, int staffIdx)
rest->setDuration(timesig()/timeStretch);
rest->setTrack(e.track());
rest->read(e);
if (startingBeam) {
startingBeam->add(rest); // also calls rest->setBeam(startingBeam)
startingBeam = nullptr;
}
segment = getSegment(SegmentType::ChordRest, e.tick());
segment->add(rest);
@ -2195,7 +2204,11 @@ void Measure::read(XmlReader& e, int staffIdx)
beam->setTrack(e.track());
beam->read(e);
beam->setParent(0);
e.addBeam(beam);
if (startingBeam) {
qDebug("The read beam was not used");
delete startingBeam;
}
startingBeam = beam;
}
else if (tag == "Segment")
segment->read(e);
@ -2233,6 +2246,10 @@ void Measure::read(XmlReader& e, int staffIdx)
}
e.checkTuplets();
e.checkConnectors();
if (startingBeam) {
qDebug("The read beam was not used");
delete startingBeam;
}
e.setCurrentMeasure(nullptr);
}

View file

@ -848,6 +848,7 @@ void Rest::write(XmlWriter& xml) const
{
if (_gap)
return;
writeBeam(xml);
xml.stag(name());
ChordRest::writeProperties(xml);
el().write(xml);

View file

@ -1242,7 +1242,6 @@ void Score::writeSegments(XmlWriter& xml, int strack, int etrack,
}
if (e->isChordRest()) {
ChordRest* cr = toChordRest(e);
cr->writeBeam(xml);
cr->writeTuplet(xml);
}
// if (segment->isEndBarLine() && (m->mmRestCount() < 0 || m->mmRest())) {