Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miiizen committed Dec 20, 2024
1 parent 1bc8525 commit bbd42e1
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 78 deletions.
74 changes: 11 additions & 63 deletions src/engraving/dom/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,12 +1306,16 @@ void ChordRest::checkStaffMoveValidity()
}
}

bool ChordRest::followingJumpItem() const
bool ChordRest::hasFollowingJumpItem() const
{
const Segment* seg = segment();
const Measure* measure = seg->measure();
const Fraction nextTick = seg->tick() + actualTicks();

if (measure->lastChordRest(track()) != this) {
return false;
}

// Jumps & markers
for (const EngravingItem* e : measure->el()) {
if (!e->isJump() && !e->isMarker()) {
Expand Down Expand Up @@ -1340,7 +1344,7 @@ bool ChordRest::followingJumpItem() const
}

// Repeats
if (measure->endTick() == nextTick && measure->repeatEnd()) {
if (measure->repeatEnd()) {
return true;
}

Expand All @@ -1360,11 +1364,15 @@ bool ChordRest::followingJumpItem() const
return false;
}

bool ChordRest::precedingJumpItem() const
bool ChordRest::hasPrecedingJumpItem() const
{
const Segment* seg = segment();
const Measure* measure = seg->measure();

if (measure->firstChordRest(track()) != this) {
return false;
}

if (seg->score()->firstSegment(SegmentType::ChordRest) == seg) {
return true;
}
Expand Down Expand Up @@ -1413,64 +1421,4 @@ bool ChordRest::precedingJumpItem() const

return false;
}

String ChordRest::precedingJumpItemName() const
{
const Segment* seg = segment();
const Measure* measure = seg->measure();

if (seg->score()->firstSegment(SegmentType::ChordRest) == seg) {
return muse::mtrc("engraving", "start of score");
}

// Markers
for (const EngravingItem* e : measure->el()) {
if (!e->isMarker()) {
continue;
}

const Marker* marker = toMarker(e);
if (muse::contains(Marker::RIGHT_MARKERS, marker->markerType())) {
continue;
}

if (marker->markerType() == MarkerType::CODA || marker->markerType() == MarkerType::VARCODA) {
return muse::mtrc("engraving", "coda");
} else {
return muse::mtrc("engraving", "segno");
}
}

// Voltas
auto spanners = score()->spannerMap().findOverlapping(measure->tick().ticks(), measure->tick().ticks());
for (auto& spanner : spanners) {
if (!spanner.value->isVolta() || Fraction::fromTicks(spanner.start) != tick()) {
continue;
}

Volta* volta = toVolta(spanner.value);

return muse::mtrc("engraving", "“%1” volta").arg(volta->beginText());
}

// Repeat barlines
if (measure->repeatStart()) {
return muse::mtrc("engraving", "start repeat");
}

for (Segment* prevSeg = seg->prev(SegmentType::BarLineType); prevSeg && prevSeg->tick() == seg->tick();
prevSeg = prevSeg->prev(SegmentType::BarLineType)) {
EngravingItem* el = prevSeg->element(track());
if (!el || !el->isBarLine()) {
continue;
}

BarLine* bl = toBarLine(el);
if (bl->barLineType() & (BarLineType::START_REPEAT | BarLineType::END_START_REPEAT)) {
return muse::mtrc("engraving", "start repeat");
}
}

return muse::mtrc("engraving", "invalid");
}
}
5 changes: 2 additions & 3 deletions src/engraving/dom/chordrest.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ class ChordRest : public DurationElement

bool isBelowCrossBeam(const BeamBase* beamBase) const;

bool followingJumpItem() const;
bool precedingJumpItem() const;
String precedingJumpItemName() const;
bool hasFollowingJumpItem() const;
bool hasPrecedingJumpItem() const;

struct LayoutData : public DurationElement::LayoutData {
ld_field<bool> up = { "[ChordRest] up", true }; // actual stem direction
Expand Down
30 changes: 29 additions & 1 deletion src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,7 @@ Tie* Score::cmdToggleTie()
undoRemoveElement(tie);
tie = nullptr;
shouldTieListSelection = false;
} else if (chord->followingJumpItem()) {
} else if (chord->hasFollowingJumpItem()) {
// Create outgoing partial tie
tie = createAndAddTie(n, nullptr);
shouldTieListSelection = false;
Expand Down Expand Up @@ -7125,6 +7125,26 @@ void Score::doUndoRemoveStaleTieJumpPoints(Tie* tie)
}
}

void Score::doUndoResetPartialSlur(Slur* slur)
{
const size_t undoIdx = undoStack()->currentIndex();
if (!slur->startCR()->hasPrecedingJumpItem() && slur->isIncoming()) {
startCmd(TranslatableString("engraving", "Reset incoming partial slur"));
slur->undoSetIncoming(false);
endCmd();
}

if (!slur->endCR()->hasFollowingJumpItem() && slur->isOutgoing()) {
startCmd(TranslatableString("engraving", "Reset outgoing partial slur"));
slur->undoSetOutgoing(false);
endCmd();
}

if (undoIdx != undoStack()->currentIndex()) {
undoStack()->mergeCommands(undoStack()->currentIndex() - 2);
}
}

void Score::undoRemoveStaleTieJumpPoints()
{
size_t tracks = nstaves() * VOICES;
Expand All @@ -7133,6 +7153,14 @@ void Score::undoRemoveStaleTieJumpPoints()
return;
}

for (auto& interval : spanner()) {
Spanner* sp = interval.second;
if (!sp || !sp->isSlur()) {
continue;
}
doUndoResetPartialSlur(toSlur(sp));
}

SegmentType st = SegmentType::ChordRest;
for (Segment* s = m->first(st); s; s = s->next1(st)) {
for (track_idx_t i = 0; i < tracks; ++i) {
Expand Down
16 changes: 16 additions & 0 deletions src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3214,6 +3214,22 @@ double Measure::firstNoteRestSegmentX(bool leading) const
margin = style().styleMM(Sid::repeatBarlineDotSeparation);
}
return std::min(seg->measure()->pos().x() + seg->pos().x() + width + margin, noteRestPos);
} else if (!isFirstInSystem() && !isFirstInSection() && prevMeasure()) {
const BarLine* endBl = prevMeasure()->endBarLine();
const Segment* endBlSeg = endBl ? endBl->segment() : nullptr;

if (!endBlSeg) {
return noteRestPos;
}

double width = 0.0;
if (endBl && endBl->addToSkyline()) {
width = std::max(width, endBl->pos().x() + endBl->ldata()->bbox().right());
}

const double startBlMargin = style().styleMM(Sid::lineEndToSystemEndDistance);

return std::min(endBlSeg->measure()->pos().x() + endBlSeg->pos().x() + width + startBlMargin, noteRestPos);
} else {
return noteRestPos;
}
Expand Down
4 changes: 3 additions & 1 deletion src/engraving/dom/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,6 @@ class Score : public EngravingObject, public muse::Injectable

void connectTies(bool silent = false);
void undoRemoveStaleTieJumpPoints();
void doUndoRemoveStaleTieJumpPoints(Tie* tie);

void scanElementsInRange(void* data, void (* func)(void*, EngravingItem*), bool all = true);
int fileDivision() const { return m_fileDivision; } ///< division of current loading *.msc file
Expand Down Expand Up @@ -1077,6 +1076,9 @@ class Score : public EngravingObject, public muse::Injectable
void rebuildTempoAndTimeSigMaps(Measure* m, std::optional<BeatsPerSecond>& tempoPrimo);
void fixAnacrusisTempo(const std::vector<Measure*>& measures) const;

void doUndoRemoveStaleTieJumpPoints(Tie* tie);
void doUndoResetPartialSlur(Slur* slur);

void deleteOrShortenOutSpannersFromRange(const Fraction& t1, const Fraction& t2, track_idx_t trackStart, track_idx_t trackEnd,
const SelectionFilter& filter);
void deleteSlursFromRange(const Fraction& t1, const Fraction& t2, track_idx_t trackStart, track_idx_t trackEnd,
Expand Down
8 changes: 4 additions & 4 deletions src/engraving/dom/slur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ bool SlurSegment::edit(EditData& ed)
const Measure* measure = e->measure();
if (start) {
cr = measure->firstChordRest(e->track());
if (!cr->precedingJumpItem()) {
if (!cr->hasPrecedingJumpItem()) {
return false;
}
sl->undoSetIncoming(true);
} else if (e->followingJumpItem()) {
} else if (e->hasFollowingJumpItem()) {
sl->undoSetOutgoing(false);
}
} else {
Expand All @@ -155,11 +155,11 @@ bool SlurSegment::edit(EditData& ed)
} else if (ed.key == Key_Right) {
if (extendToBarLine) {
const Measure* measure = e->measure();
if (start && e->precedingJumpItem()) {
if (start && e->hasPrecedingJumpItem()) {
sl->undoSetIncoming(false);
} else if (!start) {
cr = measure->lastChordRest(e->track());
if (!cr->followingJumpItem()) {
if (!cr->hasFollowingJumpItem()) {
return false;
}
sl->undoSetOutgoing(true);
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/tie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void Tie::updatePossibleJumpPoints()

tieJumpPoints()->clear();

if (!chord->followingJumpItem()) {
if (!chord->hasFollowingJumpItem()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/score/slurtielayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ SpannerSegment* SlurTieLayout::layoutSystem(Slur* item, System* system, LayoutCo
endPoint = tie->segmentAt(0)->ups(Grip::END).pos();
}

if (outgoingPartialSlur && tie->nsegments() == 1) {
if (outgoingPartialSlur && tie->type() == ElementType::TIE && tie->nsegments() == 1) {
// For partial slurs ending midway through a tie, get top of the tie shape at the slur's end X
const TieSegment* tieSeg = tie->frontSegment();
const Shape tieShape = tieSeg->shape().translate(tieSeg->pos());
Expand Down
21 changes: 17 additions & 4 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2268,20 +2268,33 @@ void NotationInteraction::doAddSlur(EngravingItem* firstItem, EngravingItem* sec

if (firstItem && secondItem && (firstItem->isBarLine() != secondItem->isBarLine())) {
const bool outgoing = firstItem->isChordRest();
const ChordRest* cr = outgoing ? toChordRest(firstItem) : toChordRest(secondItem);
const BarLine* bl = outgoing ? toBarLine(secondItem) : toBarLine(firstItem);

// Check the barline is the start of a repeat section
const Segment* adjacentCrSeg
= outgoing ? bl->segment()->prev1(SegmentType::ChordRest) : bl->segment()->next1(SegmentType::ChordRest);
ChordRest* adjacentCr = nullptr;
for (track_idx_t track = 0; track < score()->ntracks(); track++) {
EngravingItem* adjacentItem = adjacentCrSeg->element(track);
if (!adjacentItem || !adjacentItem->isChordRest()) {
continue;
}
adjacentCr = toChordRest(adjacentItem);
break;
}

if ((outgoing && !cr->followingJumpItem()) || (!outgoing && !cr->precedingJumpItem())) {
if (!adjacentCr || (outgoing && !adjacentCr->hasFollowingJumpItem()) || (!outgoing && !adjacentCr->hasPrecedingJumpItem())) {
return;
}

Slur* partialSlur = slurTemplate ? slurTemplate->clone() : Factory::createSlur(score()->dummy());
if (outgoing) {
partialSlur->undoSetOutgoing(true);
firstChordRest = toChordRest(firstItem);
secondChordRest = toChordRest(firstItem);
secondChordRest = toChordRest(adjacentCr);
} else {
partialSlur->undoSetIncoming(true);
firstChordRest = toChordRest(secondItem);
firstChordRest = toChordRest(adjacentCr);
secondChordRest = toChordRest(secondItem);
}
slurTemplate = partialSlur;
Expand Down

0 comments on commit bbd42e1

Please sign in to comment.