Skip to content

Commit 1e37c83

Browse files
authored
Fixes bug with pasting of TCOs (LMMS#5840) (LMMS#5847)
* Fixes bug with pasting of TCOs (LMMS#5840) TimePos::quantize works for negative values, but ends up snapping the TCO to the opposite direction. This is because the snapping happens in the direction of the origin, which is left for positive values and right for negative values. That wasn't accounted for in the pasteSelection method and we ended up with wrong positions when pasting before the TCO(s) we copied. This PR fixes the issue by ensuring that we snap in the same direction when halfway through an interval, regardless of negative or positive offset. * Fixes a calculation on TimePos::quantize Since we are working with integers, using "offset / (interval/2)" would be problematic if interval was odd. We instead multiply both sides by two and use "(2 * offset) / interval" to obtain the result for snapUp.
1 parent 06c8157 commit 1e37c83

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/core/TimePos.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ TimePos TimePos::quantize(float bars) const
7272
//Offset from the lower position
7373
int offset = m_ticks % interval;
7474
//1 if we should snap up, 0 if we shouldn't
75-
int snapUp = offset / (interval / 2);
75+
// Ternary expression is making sure that the snap happens in the direction to
76+
// the right even if m_ticks is negative and the offset is exactly half-way
77+
// More details on issue #5840 and PR #5847
78+
int snapUp = ((2 * offset) == -interval)
79+
? 0
80+
: (2 * offset) / interval;
7681

7782
return (lowPos + snapUp) * interval;
7883
}

src/gui/widgets/TrackContentWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ bool TrackContentWidget::pasteSelection( TimePos tcoPos, const QMimeData * md, b
477477
// All patterns should be offset the same amount as the grabbed pattern
478478
TimePos offset = TimePos(tcoPos - grabbedTCOPos);
479479
// Users expect clips to "fall" backwards, so bias the offset
480-
offset = offset - TimePos::ticksPerBar() * snapSize / 2;
480+
offset -= TimePos::ticksPerBar() * snapSize / 2;
481481
// The offset is quantized (rather than the positions) to preserve fine adjustments
482482
offset = offset.quantize(snapSize);
483483

0 commit comments

Comments
 (0)