Skip to content

Commit

Permalink
Select tuplet when calling next-element/prev-element actions
Browse files Browse the repository at this point in the history
  • Loading branch information
efu98 authored and shoogle committed Aug 28, 2024
1 parent abd13ae commit 77d4cc2
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/engraving/dom/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,21 @@ Ornament* Chord::findOrnament(bool forPlayback) const
return nullptr;
}

//---------------------------------
// firstGraceOrNote
//---------------------------------
Note* Chord::firstGraceOrNote()
{
GraceNotesGroup& graceNotesBefore = this->graceNotesBefore();
if (!graceNotesBefore.empty()) {
if (Chord* graceNotesBeforeFirstChord = graceNotesBefore.front()) {
return graceNotesBeforeFirstChord->notes().front();
}
}

return this->notes().back();
}

//---------------------------------
// GRACE NOTES
//---------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ class Chord final : public ChordRest

String accessibleExtraInfo() const override;

Note* firstGraceOrNote();

#ifndef ENGRAVING_NO_ACCESSIBILITY
AccessibleItemPtr createAccessible() override;
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/engraving/dom/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,12 @@ EngravingItem* ChordRest::prevElement()
break;
}
}

Tuplet* tuplet = this->tuplet();
if (tuplet && this == tuplet->elements().front()) {
return tuplet;
}

staff_idx_t staffId = e->staffIdx();
EngravingItem* prevItem = segment()->prevElement(staffId);
if (prevItem && prevItem->isNote()) {
Expand Down
6 changes: 4 additions & 2 deletions src/engraving/dom/navigate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ EngravingItem* Score::nextElement()
case ElementType::NOTE:
case ElementType::REST:
case ElementType::MMREST:
case ElementType::CHORD: {
case ElementType::CHORD:
case ElementType::TUPLET: {
EngravingItem* next = e->nextElement();
if (next) {
return next;
Expand Down Expand Up @@ -871,7 +872,8 @@ EngravingItem* Score::prevElement()
case ElementType::NOTE:
case ElementType::REST:
case ElementType::MMREST:
case ElementType::CHORD: {
case ElementType::CHORD:
case ElementType::TUPLET: {
EngravingItem* prev = e->prevElement();
if (prev) {
return prev;
Expand Down
20 changes: 11 additions & 9 deletions src/engraving/dom/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,16 +1682,17 @@ EngravingItem* Segment::firstElementOfSegment(staff_idx_t activeStaff) const
{
for (auto i: m_elist) {
if (i && i->staffIdx() == activeStaff) {
if (i->type() == ElementType::CHORD) {
Chord* chord = toChord(i);
GraceNotesGroup& graceNotesBefore = chord->graceNotesBefore();
if (!graceNotesBefore.empty()) {
if (Chord* graceNotesBeforeFirstChord = graceNotesBefore.front()) {
return graceNotesBeforeFirstChord->notes().front();
}
if (i->isDurationElement()) {
DurationElement* de = toDurationElement(i);
Tuplet* tuplet = de->tuplet();
if (tuplet && de == tuplet->elements().front()) {
return tuplet;
}
}

return toChord(i)->notes().back();
if (i->type() == ElementType::CHORD) {
Chord* chord = toChord(i);
return chord->firstGraceOrNote();
} else {
return i;
}
Expand Down Expand Up @@ -1974,7 +1975,8 @@ EngravingItem* Segment::nextElement(staff_idx_t activeStaff)
case ElementType::STAFF_STATE:
case ElementType::INSTRUMENT_CHANGE:
case ElementType::HARP_DIAGRAM:
case ElementType::STICKING: {
case ElementType::STICKING:
case ElementType::TUPLET: {
EngravingItem* next = nullptr;
if (e->explicitParent() == this) {
next = nextAnnotation(e);
Expand Down
22 changes: 22 additions & 0 deletions src/engraving/dom/tuplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "rest.h"
#include "score.h"
#include "text.h"
#include "segment.h"
#include "note.h"

#include "log.h"

Expand Down Expand Up @@ -844,4 +846,24 @@ int Tuplet::computeTupletDenominator(int numerator, Fraction totalDuration)
}
return ratio.numerator();
}

EngravingItem* Tuplet::nextElement()
{
ChordRest* firstElement = toChordRest(elements().front());
if (firstElement->type() == ElementType::CHORD) {
Chord* chord = toChord(firstElement);
return chord->firstGraceOrNote();
} else {
return toRest(firstElement);
}
return firstElement;
}

EngravingItem* Tuplet::prevElement()
{
ChordRest* firstElement = toChordRest(elements().front());
staff_idx_t staffId = firstElement->staffIdx();
EngravingItem* prevItem = firstElement->segment()->prevElement(staffId);
return prevItem;
}
} // namespace mu::engraving
4 changes: 4 additions & 0 deletions src/engraving/dom/tuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class Tuplet final : public DurationElement

PointF bracketL[4];
PointF bracketR[3];

EngravingItem* nextElement() override;
EngravingItem* prevElement() override;

private:

friend class DurationElement;
Expand Down

0 comments on commit 77d4cc2

Please sign in to comment.