Skip to content

Commit

Permalink
Merge pull request #2988 from AntonioBL/gp6ottava
Browse files Browse the repository at this point in the history
fix #70571 fix #93116 [GP6] crash when importing gpx ottava
  • Loading branch information
wschweer authored Feb 10, 2017
2 parents 59191a3 + 07c5181 commit b92296d
Show file tree
Hide file tree
Showing 14 changed files with 4,970 additions and 34 deletions.
43 changes: 18 additions & 25 deletions mscore/importgtp-gp6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,20 +1201,17 @@ int GuitarPro6::readBeats(QString beats, GPPartInfo* partInfo, Measure* measure,

/* if the ottava is a continuation (need to end old one), or we don't
* see one in the current note when we are tracking one then end the ottava. */
if (ottavaFound == 2 || (ottavaFound == 1 && currentNode.parentNode().firstChildElement("Ottavia").isNull())) {
Segment* prevSeg = segment->prev1(Segment::Type::ChordRest);
Element* e = prevSeg->element(track);
if (e)
if (e->type() == ElementType::CHORD || e->type() == ElementType::REST) {
ChordRest* crPrev = static_cast<Chord*>(e);
createOttava(false, track, crPrev, ottavaValue);
}
ottavaFound = 1;
if (ottavaFound.at(track) == 2 || (ottavaFound.at(track) == 1 && currentNode.parentNode().firstChildElement("Ottavia").isNull())) {
createOttava(false, track, cr, ottavaValue.at(track));
if (ottavaFound.at(track) == 2)
ottavaFound.at(track) = 1;
else
ottavaFound.at(track) = 0;
}
if (ottavaFound) {
createOttava(ottavaFound, track, cr, ottavaValue);
if (ottavaFound.at(track)) {
createOttava(true, track, cr, ottavaValue.at(track));
int pitch = note->pitch();
Ottava::Type type = ottava[track]->ottavaType();
Ottava::Type type = ottava.at(track)->ottavaType();
if (type == Ottava::Type::OTTAVA_8VA)
note->setPitch(pitch-12);
else if (type == Ottava::Type::OTTAVA_8VB)
Expand Down Expand Up @@ -1309,12 +1306,11 @@ int GuitarPro6::readBeats(QString beats, GPPartInfo* partInfo, Measure* measure,
else if (!currentNode.nodeName().compare("Ottavia")) {
/* if we saw an ottava and have an updated
* information string, set to 2 indicating that. */
if (ottavaFound == 1 && ottavaValue.compare(currentNode.toElement().text())) {
ottavaFound = 2;
}
if (ottavaFound.at(track) == 1 && ottavaValue.at(track).compare(currentNode.toElement().text()))
ottavaFound.at(track) = 2;
else
ottavaFound = 1;
ottavaValue = currentNode.toElement().text();
ottavaFound.at(track) = 1;
ottavaValue.at(track) = currentNode.toElement().text();
}
currentNode = currentNode.nextSibling();
}
Expand Down Expand Up @@ -1400,7 +1396,7 @@ void GuitarPro6::readBars(QDomNode* barList, Measure* measure, ClefType oldClefI
// only add the clef to the bar if it differs from previous measure
if (measure->prevMeasure()) {
if (clefId != oldClefId[staffIdx]) {
Segment* segment = measure->getSegment(Segment::Type::Clef, 0);
Segment* segment = measure->getSegment(Segment::Type::Clef, tick);
segment->add(newClef);
oldClefId[staffIdx] = clefId;
}
Expand Down Expand Up @@ -1795,12 +1791,11 @@ void GuitarPro6::readGpif(QByteArray* data)

// now we know how many staves there are from readTracks, we can initialise slurs
slurs = new Slur*[staves];
ottava = new Ottava*[staves];
for (int i = 0; i < staves; ++i) {
ottava.assign(staves * VOICES, 0);
ottavaFound.assign(staves * VOICES, 0);
ottavaValue.assign(staves * VOICES, "");
for (int i = 0; i < staves; ++i)
slurs[i] = 0;
ottava[i] = 0;
}


// MasterBars node
GPPartInfo partInfo;
Expand Down Expand Up @@ -1838,8 +1833,6 @@ void GuitarPro6::read(QFile* fp)
slides = new QMap<int,int>();

previousTempo = -1;
ottavaFound = 0;
ottavaValue = "";
this->buffer = new QByteArray();
*(this->buffer) = fp->readAll();

Expand Down
12 changes: 6 additions & 6 deletions mscore/importgtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ void GuitarPro::createSlur(bool hasSlur, int staffIdx, ChordRest* cr)

void GuitarPro::createOttava(bool hasOttava, int track, ChordRest* cr, QString value)
{
if (hasOttava && (ottava[track] == 0)) {
if (hasOttava && (ottava.at(track) == 0)) {
Ottava* newOttava = new Ottava(score);
newOttava->setTrack(track);
if (!value.compare("8va"))
Expand All @@ -1142,15 +1142,15 @@ void GuitarPro::createOttava(bool hasOttava, int track, ChordRest* cr, QString v
without an ottava. We also allow the ottava to continue
over rests, as that's what Guitar Pro does. */
newOttava->setTick2(cr->tick());
ottava[track] = newOttava;
ottava.at(track) = newOttava;
score->addElement(newOttava);
}
else if (ottava[track] && !hasOttava) {
Ottava* currentOttava = ottava[track];
ottava[track] = 0;
else if (ottava.at(track) && !hasOttava) {
Ottava* currentOttava = ottava.at(track);
ottava.at(track) = 0;
currentOttava->setTick2(cr->tick());
currentOttava->setProperty(P_ID::LINE_WIDTH,0.1);
//ottava[track]->staff()->updateOttava(ottava[track]);
//ottava.at(track)->staff()->updateOttava(ottava.at(track));
}
}

Expand Down
6 changes: 3 additions & 3 deletions mscore/importgtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ class GuitarPro {
int key;

QMap<int, QList<GPFermata>*> fermatas;
Ottava** ottava;
std::vector<Ottava*> ottava;
Hairpin** hairpins;
Score* score;
QFile* f;
int curPos;
int previousTempo;
int previousDynamic;
int ottavaFound;
QString ottavaValue;
std::vector<int> ottavaFound;
std::vector<QString> ottavaValue;
int tempo;
QMap<int,int> slides;

Expand Down
Binary file added mtest/guitarpro/ottava1.gpx
Binary file not shown.
Loading

0 comments on commit b92296d

Please sign in to comment.