Skip to content

Commit

Permalink
Merge pull request #19546 from sammik/correct-timesig-in-joined-measure
Browse files Browse the repository at this point in the history
fix #19323 move or remove TimeSigs of joined measures
  • Loading branch information
cbjeukendrup committed Oct 12, 2023
2 parents cad9ab7 + 320cd04 commit a3badf9
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/engraving/dom/joinMeasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "factory.h"
#include "masterscore.h"
#include "measure.h"
#include "range.h"
#include "score.h"
#include "spanner.h"
#include "timesig.h"
#include "undo.h"

using namespace mu;
Expand Down Expand Up @@ -135,5 +137,44 @@ void MasterScore::joinMeasure(const Fraction& tick1, const Fraction& tick2)
inserted->adjustToLen(newLen, /* appendRests... */ false);

range.write(this, m1->tick());

// if there are some Time Signatures in joined measures, move last one to the next measure (if there is not one already)
Segment* ts = inserted->last()->prev(SegmentType::TimeSig);
if (ts && ts->rtick().isNotZero()) {
for (Segment* insMSeg = inserted->last()->prev(SegmentType::TimeSig); insMSeg && insMSeg->rtick().isNotZero();
insMSeg = insMSeg->prev(SegmentType::TimeSig)) {
for (staff_idx_t staffIdx = 0; staffIdx < nstaves(); ++staffIdx) {
if (TimeSig* insTimeSig = toTimeSig(insMSeg->element(staffIdx * VOICES))) {
TimeSig* lts = nullptr;
for (EngravingObject* l : insTimeSig->linkList()) {
Score* score = l->score();
TimeSig* timeSig = toTimeSig(l);
Segment* tSeg = timeSig->segment();
track_idx_t track = timeSig->track();
Measure* sNext = next ? score->tick2measure(next->tick()) : nullptr;
Segment* nextTSeg = sNext ? sNext->undoGetSegmentR(SegmentType::TimeSig, Fraction(0, 1)) : nullptr;
if (sNext && !nextTSeg->element(track)) {
TimeSig* nsig = Factory::copyTimeSig(*timeSig);
nsig->setScore(score);
nsig->setTrack(track);
nsig->setParent(nextTSeg);

score->undo(new AddElement(nsig));

if (!lts) {
lts = nsig;
} else {
score->undo(new Link(lts, nsig));
}
}
score->undo(new RemoveElement(timeSig));
if (tSeg->empty()) {
score->undo(new RemoveElement(tSeg));
}
}
}
}
}
}
}
}

0 comments on commit a3badf9

Please sign in to comment.