Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various issues with system objects and multirests #26965

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/engraving/dom/excerpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,11 @@ void Excerpt::cloneStaff2(Staff* srcStaff, Staff* dstStaff, const Fraction& star
}
bool systemObject = e->systemFlag() && e->track() == 0;
EngravingItem* linkedElement = e->findLinkedInScore(score);
bool alreadyCloned = linkedElement && linkedElement->parent() == ns;
Segment* linkedParent = linkedElement ? toSegment(linkedElement->parent()) : nullptr;
bool alreadyCloned = linkedParent && (linkedParent == ns
|| (linkedParent->isType(Segment::CHORD_REST_OR_TIME_TICK_TYPE)
&& ns->isType(Segment::CHORD_REST_OR_TIME_TICK_TYPE)
&& linkedParent->tick() == ns->tick()));
bool cloneAnnotation = !alreadyCloned && (e->elementAppliesToTrack(srcTrack) || systemObject);

if (!cloneAnnotation) {
Expand Down
6 changes: 6 additions & 0 deletions src/engraving/dom/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,12 @@ void Score::dragPosition(const PointF& p, staff_idx_t* rst, Segment** seg, doubl
SegmentType st = allowTimeAnchor ? Segment::CHORD_REST_OR_TIME_TICK_TYPE : SegmentType::ChordRest;
Segment* segment = m->searchSegment(pppp.x(), st, strack, etrack, *seg, spacingFactor);
if (segment) {
if (segment->isTimeTickType()) {
if (Segment* crAtSamePos = m->findSegmentR(SegmentType::ChordRest, segment->rtick())) {
// If TimeTick and ChordRest at same position, prefer ChordRest
segment = crAtSamePos;
}
}
*rst = i;
*seg = segment;
return;
Expand Down
20 changes: 19 additions & 1 deletion src/engraving/dom/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,7 @@ PropertyValue TextBase::getProperty(Pid propertyId) const

bool TextBase::setProperty(Pid pid, const PropertyValue& v)
{
if (m_textInvalid) {
if (m_textInvalid && ldata() && ldata()->isValid()) {
genText();
}

Expand Down Expand Up @@ -3437,6 +3437,24 @@ bool TextBase::moveSegment(const EditData& ed)

void TextBase::undoMoveSegment(Segment* newSeg, Fraction tickDiff)
{
// NOTE: when creating mmRests, we clone text elements from the underlying measure onto the
// mmRest measure. This creates lots of additional linked copies which are hard to manage
// and can result in duplicates. Here we need to remove copies on mmRests because they are invalidated
// when moving segments (and if needed will be recreated at the next layout). In future we need to
// change approach and *move* elements onto the mmRests, not clone them. [M.S.]
std::list<EngravingObject*> linkedElements = linkList();
for (EngravingObject* linkedElement : linkedElements) {
if (linkedElement == this) {
continue;
}
Segment* curParent = toSegment(linkedElement->parent());
bool isOnMMRest = curParent->parent() && toMeasure(curParent->parent())->isMMRest();
if (isOnMMRest) {
linkedElement->undoUnlink();
score()->undoRemoveElement(static_cast<EngravingItem*>(linkedElement));
}
}

score()->undoChangeParent(this, newSeg, staffIdx());
moveSnappedItems(newSeg, tickDiff);
}
Expand Down
25 changes: 20 additions & 5 deletions src/engraving/rendering/score/measurelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ static bool validMMRestMeasure(const LayoutContext& ctx, const Measure* m)
if (!e->staff()->show() || !e->visible()) {
continue;
}
if (!muse::contains(BREAK_TYPES, e->type())) {
if (muse::contains(BREAK_TYPES, e->type()) && !s->rtick().isZero()) {
return false;
}
}
Expand Down Expand Up @@ -811,10 +811,25 @@ void MeasureLayout::createMultiMeasureRestsIfNeed(MeasureBase* currentMB, Layout
firstMeasure->setMMRestCount(0);
ctx.mutState().setMeasureNo(mno);
}
} else if (firstMeasure->isMMRest()) {
LOGD("mmrest: no %d += %d", ctx.state().measureNo(), firstMeasure->mmRestCount());
int measureNo = ctx.state().measureNo() + firstMeasure->mmRestCount() - 1;
ctx.mutState().setMeasureNo(measureNo);
} else if (firstMeasure->mmRest()) {
// Removed linked clones that were created for the mmRest measure
Measure* mmRestMeasure = firstMeasure->mmRest();
for (EngravingItem* item : mmRestMeasure->el()) {
item->undoUnlink();
mmRestMeasure->score()->doUndoRemoveElement(item);
}
for (Segment* seg = mmRestMeasure->first(); seg && seg->rtick().isZero(); seg = seg->next()) {
for (EngravingItem* item : seg->annotations()) {
item->undoUnlink();
mmRestMeasure->score()->doUndoRemoveElement(item);
}
}

if (firstMeasure->mmRestCount() > 0) {
LOGD("mmrest: no %d += %d", ctx.state().measureNo(), firstMeasure->mmRestCount());
int measureNo = ctx.state().measureNo() + firstMeasure->mmRestCount() - 1;
ctx.mutState().setMeasureNo(measureNo);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/links_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,12 @@ TEST_F(Engraving_LinksTests, test5LinkedParts_94911)
EXPECT_TRUE(score->excerpts().size() == 1);
}

TEST_F(Engraving_LinksTests, testMMRestLink)
TEST_F(Engraving_LinksTests, DISABLED_testMMRestLink)
{
// NOTE: Temporarily disabling this test because it assumes that the loaded score has multiMeasureRests active,
// but that is not the case because the mscx file *doesn't contain the style information*, so this
// score gets actually loaded *without* mmRest, making the test invalid. [M.S.]

MasterScore* score = ScoreRW::readScore(LINKS_DATA_DIR + u"testMMRestLink.mscx");
ASSERT_TRUE(score);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
<sigD>4</sigD>
</TimeSig>
<StaffText>
<linkedMain/>
<offset x="-12.5239" y="-3.69242"/>
<text>test1</text>
</StaffText>
Expand Down Expand Up @@ -134,7 +133,6 @@
<Measure>
<voice>
<StaffText>
<linkedMain/>
<offset x="28.5455" y="-4.14373"/>
<text>test2</text>
</StaffText>
Expand Down Expand Up @@ -162,7 +160,6 @@
<Measure>
<voice>
<StaffText>
<linkedMain/>
<text>test3</text>
</StaffText>
<Rest>
Expand Down