From 666ea12d002058d3068b5a6b2bf52e7832374e1d Mon Sep 17 00:00:00 2001 From: ws Date: Mon, 10 Nov 2014 14:18:42 +0100 Subject: [PATCH] fix #38486 --- libmscore/duration.cpp | 5 +---- libmscore/excerpt.cpp | 45 +++++++++++++++++++++++++++++---------- libmscore/measure.cpp | 4 ++++ libmscore/measurebase.cpp | 2 ++ 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/libmscore/duration.cpp b/libmscore/duration.cpp index acc16babb2..0860de730c 100644 --- a/libmscore/duration.cpp +++ b/libmscore/duration.cpp @@ -46,11 +46,8 @@ DurationElement::DurationElement(const DurationElement& e) DurationElement::~DurationElement() { - qDebug("~DurationElement: tuplet %p", tuplet()); - if (tuplet() && !tuplet()->elements().isEmpty() && tuplet()->elements().front() == this) { - qDebug(" delete tuplet"); + if (tuplet() && !tuplet()->elements().isEmpty() && tuplet()->elements().front() == this) delete tuplet(); - } } //--------------------------------------------------------- diff --git a/libmscore/excerpt.cpp b/libmscore/excerpt.cpp index d5f23829df..85948e51e2 100644 --- a/libmscore/excerpt.cpp +++ b/libmscore/excerpt.cpp @@ -287,6 +287,26 @@ static void cloneTuplets(ChordRest* ocr, ChordRest* ncr, Tuplet* ot, TupletMap& ncr->setTuplet(nt); } +//--------------------------------------------------------- +// mapTrack +//--------------------------------------------------------- + +static int mapTrack(int srcTrack, const QList& map) + { + if (srcTrack == -1) + return -1; + int track = -1; + int st = 0; + foreach(int staff, map) { + if (staff == srcTrack / VOICES) { + track = (st * VOICES) + srcTrack % VOICES; + break; + } + ++st; + } + return track; + } + //--------------------------------------------------------- // cloneStaves //--------------------------------------------------------- @@ -327,15 +347,9 @@ void cloneStaves(Score* oscore, Score* score, const QList& map) int tracks = oscore->nstaves() * VOICES; for (int srcTrack = 0; srcTrack < tracks; ++srcTrack) { TupletMap tupletMap; // tuplets cannot cross measure boundaries - int track = -1; - int st = 0; - foreach(int staff, map) { - if (staff == srcTrack/VOICES) { - track = (st * VOICES) + srcTrack % VOICES; - break; - } - ++st; - } + + int track = mapTrack(srcTrack, map); + Tremolo* tremolo = 0; for (Segment* oseg = m->first(); oseg; oseg = oseg->next()) { Segment* ns = nullptr; //create segment later, on demand @@ -461,12 +475,20 @@ void cloneStaves(Score* oscore, Score* score, const QList& map) if (st == LayoutBreak::Type::PAGE || st == LayoutBreak::Type::LINE) continue; } + int track = -1; + if (e->track() != -1) { + track = mapTrack(e->track(), map); + if (track == -1) + continue; + } + Element* ne; if (e->type() == Element::Type::TEXT || e->type() == Element::Type::LAYOUT_BREAK) // link the title, subtitle etc... ne = e->linkedClone(); else ne = e->clone(); ne->setScore(score); + ne->setTrack(track); nmb->add(ne); } nmbl->add(nmb); @@ -500,9 +522,10 @@ void cloneStaves(Score* oscore, Score* score, const QList& map) int dstTrack = -1; int dstTrack2 = -1; int st = 0; - //always export voltas to first staff in part - if (s->type() == Element::Type::VOLTA) + if (s->type() == Element::Type::VOLTA) { + //always export voltas to first staff in part dstTrack = s->voice(); + } else { //export other spanner if staffidx matches for (int index : map) { if (index == staffIdx) { diff --git a/libmscore/measure.cpp b/libmscore/measure.cpp index e9f702a59e..aec29f5c65 100644 --- a/libmscore/measure.cpp +++ b/libmscore/measure.cpp @@ -2329,6 +2329,10 @@ bool Measure::visible(int staffIdx) const { if (system() && (system()->staves()->isEmpty() || !system()->staff(staffIdx)->show())) return false; + if (staffIdx >= score()->staves().size()) { + qDebug("Measure::visible: bad staffIdx: %d", staffIdx); + return false; + } return score()->staff(staffIdx)->show() && staves[staffIdx]->_visible; } diff --git a/libmscore/measurebase.cpp b/libmscore/measurebase.cpp index d9d63acb7e..a0b6d7aa99 100644 --- a/libmscore/measurebase.cpp +++ b/libmscore/measurebase.cpp @@ -86,6 +86,8 @@ void MeasureBase::scanElements(void* data, void (*func)(void*, Element*), bool a if (type() == Element::Type::MEASURE) { foreach(Element* e, _el) { if (score()->tagIsValid(e->tag())) { + if (e->staffIdx() >= score()->staves().size()) + qDebug("MeasureBase::scanElements: bad staffIdx %d in element %s", e->staffIdx(), e->name()); if ((e->track() == -1) || ((Measure*)this)->visible(e->staffIdx())) e->scanElements(data, func, all); }