Skip to content
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
98 changes: 63 additions & 35 deletions src/engraving/editing/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
#include "../dom/barline.h"
#include "../dom/box.h"
#include "../dom/chord.h"
#include "../dom/chordrest.h"
#include "../dom/clef.h"
#include "../dom/drumset.h"
#include "../dom/durationtype.h"
#include "../dom/dynamic.h"
#include "../dom/factory.h"
#include "../dom/glissando.h"
Expand Down Expand Up @@ -3303,45 +3305,71 @@ void Score::cmdMirrorNoteHead()

void Score::cmdIncDecDuration(int nSteps, bool stepDotted)
{
EngravingItem* el = selection().element();
if (el == 0) {
return;
}
if (el->isNote()) {
el = el->parentItem();
}
if (!el->isChordRest()) {
return;
}

ChordRest* cr = toChordRest(el);
if (m_selection.isRange()) {
if (!m_selection.canCopy()) {
return;
}
ChordRest* firstCR = m_selection.firstChordRest();
if (firstCR->isGrace()) {
firstCR = toChordRest(firstCR->parent());
}
TDuration initialDuration = firstCR->ticks();
TDuration d = initialDuration.shiftRetainDots(nSteps, stepDotted);
if (!d.isValid()) {
return;
}
Fraction scale = d.ticks() / initialDuration.ticks();
for (ChordRest* cr : getSelectedChordRests()) {
Fraction newTicks = cr->ticks() * scale;
if (newTicks < Fraction(1, 1024)
|| (stepDotted && cr->durationType().dots() != firstCR->durationType().dots()
&& !cr->isGrace())) {
return;
}
}
const muse::ByteArray mimeData(m_selection.mimeData());
XmlReader e(mimeData);
deleteRange(m_selection.startSegment(), m_selection.endSegment(), staff2track(m_selection.staffStart()),
staff2track(m_selection.staffEnd()), selectionFilter(), m_selection.rangeContainsMultiNoteChords());
pasteStaff(e, m_selection.startSegment(), m_selection.staffStart(), scale);
} else if (m_selection.isList()) {
const std::set<ChordRest*> crs = getSelectedChordRests();
for (ChordRest* cr : crs) {
// if measure rest is selected as input, then the correct initialDuration will be the
// duration of the measure's time signature, else is just the ChordRest's duration
TDuration initialDuration = cr->durationType();
if (initialDuration == DurationType::V_MEASURE) {
initialDuration = TDuration(cr->measure()->timesig(), true);

if (initialDuration.fraction() < cr->measure()->timesig() && nSteps > 0) {
// Duration already shortened by truncation; shorten one step less
--nSteps;
}
}

// if measure rest is selected as input, then the correct initialDuration will be the
// duration of the measure's time signature, else is just the ChordRest's duration
TDuration initialDuration = cr->durationType();
if (initialDuration == DurationType::V_MEASURE) {
initialDuration = TDuration(cr->measure()->timesig(), true);
TDuration newDuration { stepDotted ? initialDuration.shiftRetainDots(nSteps, stepDotted) : initialDuration.shift(nSteps) };
if (!newDuration.isValid()) {
continue;
}

if (initialDuration.fraction() < cr->measure()->timesig() && nSteps > 0) {
// Duration already shortened by truncation; shorten one step less
--nSteps;
if (cr->isGrace()) {
undoChangeChordRestLen(cr, newDuration);
} else {
changeCRlen(cr, newDuration);
}
}
// 2nd loop needed to reselect what was selected before 1st loop
// as `changeCRlen()` changes the selection to `SelectType::SINGLE`
for (ChordRest* cr : crs) {
EngravingItem* e = cr;
if (cr->isChord()) {
e = toChord(cr)->upNote();
}
if (canReselectItem(e)) {
select(e, SelectType::ADD);
}
}
}

TDuration d = (nSteps != 0) ? initialDuration.shiftRetainDots(nSteps, stepDotted) : initialDuration;
if (!d.isValid()) {
return;
}
if (cr->isChord() && (toChord(cr)->noteType() != NoteType::NORMAL)) {
//
// handle appoggiatura and acciaccatura
//
undoChangeChordRestLen(cr, d);
} else {
changeCRlen(cr, d);
}
m_is.setDuration(d);
nextInputPos(cr, false);
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/editing/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6195,7 +6195,7 @@ static Chord* findLinkedChord(Chord* c, Staff* nstaff)
Segment* s = c->segment();
Measure* nm = nstaff->score()->tick2measure(s->tick());
Segment* ns = nm->findSegment(s->segmentType(), s->tick());
EngravingItem* ne = ns->element(dtrack);
EngravingItem* ne = ns ? ns->element(dtrack) : nullptr;
if (!ne || !ne->isChord()) {
return nullptr;
}
Expand Down
Loading