Skip to content

Commit cb8badc

Browse files
authored
Fix Clip Creation Quantization in Song Editor (LMMS#7763)
Previously, clicking on a track or dragging in a sample would always create a clip on the closest/previous bar, no matter what the Song Editor's snap size was. This fixes that issue by using the Song Editor's quantization when placing new clips, so for example if the snap size is 1/4 bar, the clip will be added at the closest/previous 1/4 bar mark.
1 parent d06c594 commit cb8badc

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

include/TimePos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class LMMS_EXPORT TimePos
7070
TimePos( const bar_t bar, const tick_t ticks );
7171
TimePos( const tick_t ticks = 0 );
7272

73-
TimePos quantize(float) const;
73+
TimePos quantize(float bars, bool forceRoundDown = false) const;
7474
TimePos toAbsoluteBar() const { return getBar() * s_ticksPerBar; }
7575

7676
TimePos& operator+=(const TimePos& time)

src/core/TimePos.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ TimePos::TimePos( const tick_t ticks ) :
5353
{
5454
}
5555

56-
TimePos TimePos::quantize(float bars) const
56+
TimePos TimePos::quantize(float bars, bool forceRoundDown) const
5757
{
5858
//The intervals we should snap to, our new position should be a factor of this
5959
int interval = s_ticksPerBar * bars;
@@ -65,7 +65,7 @@ TimePos TimePos::quantize(float bars) const
6565
// Ternary expression is making sure that the snap happens in the direction to
6666
// the right even if m_ticks is negative and the offset is exactly half-way
6767
// More details on issue #5840 and PR #5847
68-
int snapUp = ((2 * offset) == -interval)
68+
int snapUp = forceRoundDown || ((2 * offset) == -interval)
6969
? 0
7070
: (2 * offset) / interval;
7171

src/gui/tracks/SampleTrackView.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "Knob.h"
3838
#include "SampleClip.h"
3939
#include "SampleTrackWindow.h"
40+
#include "SongEditor.h"
4041
#include "StringPairDrag.h"
4142
#include "TrackContainerView.h"
4243
#include "TrackLabelButton.h"
@@ -211,11 +212,12 @@ void SampleTrackView::dropEvent(QDropEvent *de)
211212
? trackHeadWidth
212213
: de->pos().x();
213214

215+
const float snapSize = getGUI()->songEditor()->m_editor->getSnapSize();
214216
TimePos clipPos = trackContainerView()->fixedClips()
215217
? TimePos(0)
216218
: TimePos(((xPos - trackHeadWidth) / trackContainerView()->pixelsPerBar()
217219
* TimePos::ticksPerBar()) + trackContainerView()->currentPosition()
218-
).quantize(1.0);
220+
).quantize(snapSize, true);
219221

220222
auto sClip = static_cast<SampleClip*>(getTrack()->createClip(clipPos));
221223
if (sClip) { sClip->setSampleFile(value); }

src/gui/tracks/TrackContentWidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ void TrackContentWidget::mousePressEvent( QMouseEvent * me )
598598
so.at( i )->setSelected( false);
599599
}
600600
getTrack()->addJournalCheckPoint();
601-
const TimePos pos = getPosition( me->x() ).getBar() *
602-
TimePos::ticksPerBar();
601+
const float snapSize = getGUI()->songEditor()->m_editor->getSnapSize();
602+
const TimePos pos = TimePos(getPosition(me->x())).quantize(snapSize, true);
603603
getTrack()->createClip(pos);
604604
}
605605
}

0 commit comments

Comments
 (0)