Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miiizen committed Dec 30, 2024
1 parent 672a005 commit cc454db
Show file tree
Hide file tree
Showing 26 changed files with 412 additions and 395 deletions.
2 changes: 1 addition & 1 deletion src/engraving/compat/midi/compatmidirender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ std::set<size_t> CompatMidiRender::getNotesIndexesToRender(Chord* chord)
}

auto noteShouldBeRendered = [](Note* n) {
while (n->tieBack() && !n->incomingPartialTie() && n != n->tieBack()->startNote()) {
while (n->tieBackNonPartial() && n != n->tieBack()->startNote()) {
n = n->tieBack()->startNote();
if (findFirstTrill(n->chord())) {
// The previous tied note probably has events for this note too.
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ void Chord::cmdUpdateNotes(AccidentalState* as, staff_idx_t staffIdx)
if (vStaffIdx() == staffIdx) {
std::vector<Note*> lnotes(notes()); // we need a copy!
for (Note* note : lnotes) {
if (note->tieBack() && !note->incomingPartialTie() && note->tpc() == note->tieBack()->startNote()->tpc()) {
if (note->tieBackNonPartial() && note->tpc() == note->tieBack()->startNote()->tpc()) {
// same pitch
if (note->accidental() && note->accidental()->role() == AccidentalRole::AUTO) {
// not courtesy
Expand Down
6 changes: 3 additions & 3 deletions src/engraving/dom/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,8 +1693,8 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest)
}
for (Note* n : c->notes()) {
if (Tie* tie = n->tieFor()) {
if (tie->tieEndPoints()) {
tie->removeTiesFromEndPoints();
if (tie->tieJumpPoints()) {
tie->removeTiesFromJumpPoints();
}
undoRemoveElement(tie);
}
Expand Down Expand Up @@ -3793,7 +3793,7 @@ void Score::cmdImplode()
// see if we are tying in to this chord
Chord* tied = 0;
for (Note* n : dstChord->notes()) {
if (n->tieBack() && !n->incomingPartialTie()) {
if (n->tieBackNonPartial()) {
tied = n->tieBack()->startNote()->chord();
break;
}
Expand Down
17 changes: 8 additions & 9 deletions src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1895,19 +1895,18 @@ std::vector<Note*> Score::cmdTieNoteList(const Selection& selection, bool noteEn
static Tie* createAndAddTie(Note* startNote, Note* endNote)
{
Score* score = startNote->score();
const bool createPartialTie = !endNote;
Tie* tie = createPartialTie ? Factory::createPartialTie(startNote) : Factory::createTie(startNote);
Tie* tie = endNote ? Factory::createTie(startNote) : Factory::createPartialTie(startNote);
tie->setStartNote(startNote);
tie->setTrack(startNote->track());
tie->setTick(startNote->chord()->segment()->tick());
if (!createPartialTie) {
if (endNote) {
tie->setEndNote(endNote);
tie->setTicks(endNote->chord()->segment()->tick() - startNote->chord()->segment()->tick());
}
score->undoAddElement(tie);

tie->addTiesToEndPoints();
if (!tie->endNote() && tie->tieEndPoints() && tie->tieEndPoints()->empty()) {
tie->addTiesToJumpPoints();
if (!tie->endNote() && tie->tieJumpPoints() && tie->tieJumpPoints()->empty()) {
score->undoRemoveElement(tie);
tie = nullptr;
}
Expand Down Expand Up @@ -2071,7 +2070,7 @@ Tie* Score::cmdToggleTie()
undoRemoveElement(tie);
tie = nullptr;
shouldTieListSelection = false;
} else if (n->followingJumpItem()) {
} else if (n->hasFollowingJumpItem()) {
// Create outgoing partial tie
tie = createAndAddTie(n, nullptr);
shouldTieListSelection = false;
Expand Down Expand Up @@ -2922,10 +2921,10 @@ void Score::deleteItem(EngravingItem* el)
el = toSpannerSegment(el)->spanner();
if (el->isTie()) {
Tie* tie = toTie(el);
if (tie->tieEndPoints()) {
tie->removeTiesFromEndPoints();
if (tie->tieJumpPoints()) {
tie->removeTiesFromJumpPoints();
}
if (tie->endPoint()) {
if (tie->jumpPoint()) {
tie->updateStartTieOnRemoval();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/excerpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ static void collectTieEndPoints(TieMap& tieMap)
for (auto& tie : tieMap) {
Tie* newTie = toTie(tie.second);
if (newTie->type() == ElementType::TIE || (newTie->type() == ElementType::PARTIAL_TIE && toPartialTie(newTie)->isOutgoing())) {
newTie->collectPossibleEndPoints();
newTie->collectPossibleJumpPoints();
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,13 +1032,9 @@ void Measure::spatiumChanged(double /*oldValue*/, double /*newValue*/)

void Measure::removePartialTiesOnRepeatChange(bool outgoing)
{
const track_idx_t startTrack = 0;
const track_idx_t ntracks = score()->ntracks();

Segment* seg = first(SegmentType::ChordRest);
while (seg) {
for (track_idx_t track = startTrack; track < ntracks; track++) {
EngravingItem* item = seg->element(track);
for (EngravingItem* item : seg->elist()) {
if (!item || !item->isChord()) {
continue;
}
Expand All @@ -1052,7 +1048,7 @@ void Measure::removePartialTiesOnRepeatChange(bool outgoing)
}

if (outgoing) {
tie->removeTiesFromEndPoints();
tie->removeTiesFromJumpPoints();
} else if (tie->isPartialTie()) {
score()->doUndoRemoveElement(tie);
}
Expand Down
107 changes: 32 additions & 75 deletions src/engraving/dom/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ void Note::add(EngravingItem* e)
case ElementType::PARTIAL_TIE: {
PartialTie* pt = toPartialTie(e);
pt->setTick(tick());
if (pt->partialSpannerDirection() == PartialSpannerDirection::OUTGOING) {
if (pt->isOutgoing()) {
pt->setStartNote(this);
setTieFor(pt);
} else {
Expand Down Expand Up @@ -1387,7 +1387,7 @@ void Note::remove(EngravingItem* e)
setTieFor(nullptr);
} else {
setTieBack(nullptr);
pt->setEndPoint(nullptr);
pt->setJumpPoint(nullptr);
}
break;
}
Expand All @@ -1396,7 +1396,7 @@ void Note::remove(EngravingItem* e)
Tie* tie = toTie(e);
assert(tie->startNote() == this);
setTieFor(nullptr);
tie->setEndPoint(nullptr);
tie->setJumpPoint(nullptr);
if (tie->endNote()) {
tie->endNote()->setTieBack(0);
}
Expand Down Expand Up @@ -2232,7 +2232,7 @@ void Note::updateAccidental(AccidentalState* as)
as->setAccidentalVal(eAbsLine, accVal, m_tieBack != 0 && m_accidental == 0);
acci = Accidental::value2subtype(accVal);
// if previous tied note has same tpc, don't show accidental
if (m_tieBack && !incomingPartialTie() && m_tieBack->startNote()->tpc1() == tpc1()) {
if (tieBackNonPartial() && m_tieBack->startNote()->tpc1() == tpc1()) {
acci = AccidentalType::NONE;
} else if (acci == AccidentalType::NONE) {
acci = AccidentalType::NATURAL;
Expand Down Expand Up @@ -2461,6 +2461,24 @@ GuitarBend* Note::bendBack() const
return nullptr;
}

Tie* Note::tieForNonPartial() const
{
if (!m_tieFor || m_tieFor->type() != ElementType::TIE) {
return nullptr;
}

return m_tieFor;
}

Tie* Note::tieBackNonPartial() const
{
if (!m_tieBack || m_tieBack->type() != ElementType::TIE) {
return nullptr;
}

return m_tieBack;
}

LaissezVib* Note::laissezVib() const
{
if (!m_tieFor || !m_tieFor->isLaissezVib()) {
Expand Down Expand Up @@ -2491,13 +2509,13 @@ PartialTie* Note::outgoingPartialTie() const
void Note::setTieFor(Tie* t)
{
m_tieFor = t;
m_endPoints.setStartTie(m_tieFor);
m_jumpPoints.setStartTie(m_tieFor);
}

void Note::setTieBack(Tie* t)
{
if (m_tieBack && t && m_tieBack->endPoint()) {
t->setEndPoint(m_tieBack->endPoint());
if (m_tieBack && t && m_tieBack->jumpPoint()) {
t->setJumpPoint(m_tieBack->jumpPoint());
}
m_tieBack = t;
}
Expand Down Expand Up @@ -3743,17 +3761,17 @@ std::vector<Note*> Note::findTiedNotes(Note* startNote, bool followPartialTies)

while (note->tieFor()) {
if (followPartialTies) {
for (TieEndPoint* endPoint : *note->tieEndPoints()) {
if (!endPoint->active() || endPoint->followingNote()) {
for (TieJumpPoint* jumpPoint : *note->tieJumpPoints()) {
if (!jumpPoint->active() || jumpPoint->followingNote()) {
continue;
}
if (!endPoint->note() || std::find(notes.begin(), notes.end(), endPoint->note()) != notes.end()) {
if (!jumpPoint->note() || std::find(notes.begin(), notes.end(), jumpPoint->note()) != notes.end()) {
continue;
}
// ONLY backtrack when end point is a full tie eg. around a segno
const bool endTieIsFullTie = endPoint->endTie() && !endPoint->endTie()->isPartialTie();
Note* endPointNote = endTieIsFullTie ? endPoint->endTie()->startNote()->firstTiedNote() : endPoint->note();
std::vector<Note*> partialTieNotes = findTiedNotes(endPointNote, !endTieIsFullTie);
const bool endTieIsFullTie = jumpPoint->endTie() && !jumpPoint->endTie()->isPartialTie();
Note* jumpPointNote = endTieIsFullTie ? jumpPoint->endTie()->startNote()->firstTiedNote() : jumpPoint->note();
std::vector<Note*> partialTieNotes = findTiedNotes(jumpPointNote, !endTieIsFullTie);
notes.insert(notes.end(), partialTieNotes.begin(), partialTieNotes.end());
}
}
Expand Down Expand Up @@ -3829,7 +3847,7 @@ void Note::connectTiedNotes()
}
}

bool Note::followingJumpItem()
bool Note::hasFollowingJumpItem()
{
const Chord* startChord = chord();
const Segment* seg = startChord->segment();
Expand Down Expand Up @@ -3884,67 +3902,6 @@ bool Note::followingJumpItem()
return false;
}

String Note::precedingJumpItemName()
{
const Chord* startChord = chord();
const Segment* seg = startChord->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) != startChord->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(startChord->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");
}

//---------------------------------------------------------
// accidentalType
//---------------------------------------------------------
Expand Down
11 changes: 6 additions & 5 deletions src/engraving/dom/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ class Note final : public EngravingItem
GuitarBend* bendBack() const;
Tie* tieFor() const { return m_tieFor; }
Tie* tieBack() const { return m_tieBack; }
Tie* tieForNonPartial() const;
Tie* tieBackNonPartial() const;
LaissezVib* laissezVib() const;
PartialTie* incomingPartialTie() const;
PartialTie* outgoingPartialTie() const;
Expand All @@ -313,8 +315,7 @@ class Note final : public EngravingItem
void disconnectTiedNotes();
void connectTiedNotes();

bool followingJumpItem();
String precedingJumpItemName();
bool hasFollowingJumpItem();

void setupAfterRead(const Fraction& tick, bool pasteMode);

Expand Down Expand Up @@ -467,8 +468,8 @@ class Note final : public EngravingItem

void setVisible(bool v) override;

TieEndPointList* tieEndPoints() { return &m_endPoints; }
const TieEndPointList* tieEndPoints() const { return &m_endPoints; }
TieJumpPointList* tieJumpPoints() { return &m_jumpPoints; }
const TieJumpPointList* tieJumpPoints() const { return &m_jumpPoints; }

struct LayoutData : public EngravingItem::LayoutData {
ld_field<bool> useTablature = { "[Note] useTablature", false };
Expand Down Expand Up @@ -575,6 +576,6 @@ class Note final : public EngravingItem
String m_fretString;

std::vector<LineAttachPoint> m_lineAttachPoints;
TieEndPointList m_endPoints;
TieJumpPointList m_jumpPoints;
};
} // namespace mu::engraving
12 changes: 6 additions & 6 deletions src/engraving/dom/partialtie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,30 @@ void PartialTie::setEndNote(Note* note)
setParent(note);
}

bool PartialTie::allEndPointsInactive() const
bool PartialTie::allJumpPointsInactive() const
{
if (!isOutgoing()) {
return false;
}
return Tie::allEndPointsInactive();
return Tie::allJumpPointsInactive();
}

TieEndPointList* PartialTie::tieEndPoints()
TieJumpPointList* PartialTie::tieJumpPoints()
{
if (!isOutgoing()) {
return nullptr;
}

return Tie::tieEndPoints();
return Tie::tieJumpPoints();
}

const TieEndPointList* PartialTie::tieEndPoints() const
const TieJumpPointList* PartialTie::tieJumpPoints() const
{
if (!isOutgoing()) {
return nullptr;
}

return Tie::tieEndPoints();
return Tie::tieJumpPoints();
}

Note* PartialTie::startNote() const
Expand Down
6 changes: 3 additions & 3 deletions src/engraving/dom/partialtie.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class PartialTie : public Tie
void setStartNote(Note* note) override;
void setEndNote(Note* note) override;

TieEndPointList* tieEndPoints() override;
const TieEndPointList* tieEndPoints() const override;
bool allEndPointsInactive() const override;
TieJumpPointList* tieJumpPoints() override;
const TieJumpPointList* tieJumpPoints() const override;
bool allJumpPointsInactive() const override;

Note* startNote() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5742,7 +5742,7 @@ void Score::connectTies(bool silent)
// connect a tie without end note
Tie* tie = n->tieFor();
if (tie) {
tie->collectPossibleEndPoints();
tie->collectPossibleJumpPoints();
}
if (tie && !tie->isPartialTie() && !tie->endNote()) {
Note* nnote;
Expand Down
Loading

0 comments on commit cc454db

Please sign in to comment.