Skip to content

Commit

Permalink
Merge pull request #18311 from mike-spa/portingSeveralPRs
Browse files Browse the repository at this point in the history
Porting several PRs
  • Loading branch information
RomanPudashkin committed Jun 30, 2023
2 parents f7fab29 + 8e9b37a commit f32d585
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 45 deletions.
1 change: 1 addition & 0 deletions src/engraving/libmscore/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ EngravingItem* ChordRest::drop(EditData& data)
delete ks;
} else {
// apply to all staves, at the beginning of the measure
data.pos = canvasPos(); // measure->drop() expects to receive canvas pos
return m->drop(data);
}
}
Expand Down
69 changes: 24 additions & 45 deletions src/engraving/libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3402,7 +3402,6 @@ void Score::cmdDeleteSelection()
// so we don't try to delete them twice if they are also in selection
std::set<Spanner*> deletedSpanners;

bool allertInstrChange = true;
for (EngravingItem* e : el) {
// these are the linked elements we are about to delete
std::list<EngravingObject*> links;
Expand Down Expand Up @@ -3458,20 +3457,17 @@ void Score::cmdDeleteSelection()
// Also instrument change key signatures should be undeletable.
// The correct action is for the user to set an atonal/custom keySig as needed.
if (e->isKeySig()) {
if (e->tick() == Fraction(0, 1)) {
continue;
} else if (toKeySig(e)->forInstrumentChange()) {
if (allertInstrChange) {
MessageBox::warning(mtrc("engraving", "Instrument change key signature cannot be deleted").toStdString(),
mtrc("engraving",
"Please replace it with a key signature from the palettes instead.").toStdString(),
{ MessageBox::Ok });
allertInstrChange = false;
}
if (e->tick() == Fraction(0, 1) || toKeySig(e)->forInstrumentChange()) {
MScore::setError(MsError::CANNOT_REMOVE_KEY_SIG);
continue;
}
}

// Don't allow deleting the trill cue note
if (e->isNote() && toNote(e)->isTrillCueNote()) {
continue;
}

// delete element if we have not done so already
if (deletedElements.find(e) == deletedElements.end()) {
// do not delete two spanner segments from the same spanner
Expand Down Expand Up @@ -6299,8 +6295,6 @@ void Score::undoAddCR(ChordRest* cr, Measure* measure, const Fraction& tick)

SegmentType segmentType = SegmentType::ChordRest;

Tuplet* crTuplet = cr->tuplet();

// For linked staves the length of staffList is always > 1 since the list contains the staff itself too!
const bool linked = ostaff->staffList().size() > 1;

Expand Down Expand Up @@ -6369,41 +6363,26 @@ void Score::undoAddCR(ChordRest* cr, Measure* measure, const Fraction& tick)
}
}
#endif
if (crTuplet && staff != ostaff) {
// In case of nested tuplets, get the parent tuplet.
Tuplet* parTuplet { nullptr };
if (crTuplet->tuplet()) {
// Look for a tuplet, linked to the parent tuplet of crTuplet but
// which is on the same staff as the new ChordRest.
for (auto e : crTuplet->tuplet()->linkList()) {
Tuplet* t = toTuplet(e);
if (t->staff() == newcr->staff()) {
parTuplet = t;
break;
}
}
}

// Look for a tuplet linked to crTuplet but is on the same staff as
// the new ChordRest. Create a new tuplet if not found.
Tuplet* newTuplet { nullptr };
for (auto e : crTuplet->linkList()) {
Tuplet* t = toTuplet(e);
if (t->staff() == newcr->staff()) {
newTuplet = t;
break;
}
// Climb up the (possibly nested) tuplets from this chordRest
// Make sure all tuplets are cloned and correctly nested
DurationElement* elementBelow = cr;
Tuplet* tupletAbove = elementBelow->tuplet();
while (tupletAbove) {
DurationElement* linkedElementBelow = (DurationElement*)elementBelow->findLinkedInScore(score);
if (!linkedElementBelow) { // shouldn't happen
break;
}

if (!newTuplet) {
newTuplet = toTuplet(crTuplet->linkedClone());
newTuplet->setTuplet(parTuplet);
newTuplet->setScore(score);
newTuplet->setTrack(newcr->track());
newTuplet->setParent(m);
Tuplet* linkedTuplet = (Tuplet*)tupletAbove->findLinkedInScore(score);
if (!linkedTuplet) {
linkedTuplet = toTuplet(tupletAbove->linkedClone());
linkedTuplet->setScore(score);
linkedTuplet->setTrack(newcr->track());
linkedTuplet->setParent(m);
}
linkedElementBelow->setTuplet(linkedTuplet);

newcr->setTuplet(newTuplet);
elementBelow = tupletAbove;
tupletAbove = tupletAbove->tuplet();
}

if (newcr->isRest() && (toRest(newcr)->isGap()) && !(toRest(newcr)->track() % VOICES)) {
Expand Down
1 change: 1 addition & 0 deletions src/engraving/libmscore/mscore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ std::string MScore::errorToString(MsError err)
case MsError::CANNOT_CHANGE_LOCAL_TIMESIG_MEASURE_NOT_EMPTY: return "CANNOT_CHANGE_LOCAL_TIMESIG_MEASURE_NOT_EMPTY";
case MsError::CANNOT_CHANGE_LOCAL_TIMESIG_HAS_EXCERPTS: return "CANNOT_CHANGE_LOCAL_TIMESIG_HAS_EXCERPTS";
case MsError::CORRUPTED_MEASURE: return "CORRUPTED_MEASURE";
case MsError::CANNOT_REMOVE_KEY_SIG: return "CANNOT_REMOVE_KEY_SIG";
}

return {};
Expand Down
1 change: 1 addition & 0 deletions src/engraving/libmscore/mscore.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ enum class MsError {
CANNOT_CHANGE_LOCAL_TIMESIG_MEASURE_NOT_EMPTY,
CANNOT_CHANGE_LOCAL_TIMESIG_HAS_EXCERPTS,
CORRUPTED_MEASURE,
CANNOT_REMOVE_KEY_SIG,
};

/// \cond PLUGIN_API \private \endcond
Expand Down
5 changes: 5 additions & 0 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ void NotationInteraction::checkAndShowMScoreError() const
case MsError::CORRUPTED_MEASURE:
title = trc("notation", "Cannot change time signature in front of a corrupted measure");
break;
case MsError::CANNOT_REMOVE_KEY_SIG:
title = trc("notation", "This key signature cannot be deleted");
message = trc("notation", "Please replace it with a key signature from the palettes instead.");
break;
}

IInteractive::Result result
Expand Down Expand Up @@ -3755,6 +3759,7 @@ void NotationInteraction::deleteSelection()
score()->cmdDeleteSelection();
}

checkAndShowMScoreError();
apply();
resetHitElementContext();
}
Expand Down

0 comments on commit f32d585

Please sign in to comment.