Fix Clip Creation Quantization in Song Editor (#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.
This commit is contained in:
@@ -70,7 +70,7 @@ public:
|
||||
TimePos( const bar_t bar, const tick_t ticks );
|
||||
TimePos( const tick_t ticks = 0 );
|
||||
|
||||
TimePos quantize(float) const;
|
||||
TimePos quantize(float bars, bool forceRoundDown = false) const;
|
||||
TimePos toAbsoluteBar() const { return getBar() * s_ticksPerBar; }
|
||||
|
||||
TimePos& operator+=(const TimePos& time)
|
||||
|
||||
@@ -53,7 +53,7 @@ TimePos::TimePos( const tick_t ticks ) :
|
||||
{
|
||||
}
|
||||
|
||||
TimePos TimePos::quantize(float bars) const
|
||||
TimePos TimePos::quantize(float bars, bool forceRoundDown) const
|
||||
{
|
||||
//The intervals we should snap to, our new position should be a factor of this
|
||||
int interval = s_ticksPerBar * bars;
|
||||
@@ -65,7 +65,7 @@ TimePos TimePos::quantize(float bars) const
|
||||
// Ternary expression is making sure that the snap happens in the direction to
|
||||
// the right even if m_ticks is negative and the offset is exactly half-way
|
||||
// More details on issue #5840 and PR #5847
|
||||
int snapUp = ((2 * offset) == -interval)
|
||||
int snapUp = forceRoundDown || ((2 * offset) == -interval)
|
||||
? 0
|
||||
: (2 * offset) / interval;
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "Knob.h"
|
||||
#include "SampleClip.h"
|
||||
#include "SampleTrackWindow.h"
|
||||
#include "SongEditor.h"
|
||||
#include "StringPairDrag.h"
|
||||
#include "TrackContainerView.h"
|
||||
#include "TrackLabelButton.h"
|
||||
@@ -211,11 +212,12 @@ void SampleTrackView::dropEvent(QDropEvent *de)
|
||||
? trackHeadWidth
|
||||
: de->pos().x();
|
||||
|
||||
const float snapSize = getGUI()->songEditor()->m_editor->getSnapSize();
|
||||
TimePos clipPos = trackContainerView()->fixedClips()
|
||||
? TimePos(0)
|
||||
: TimePos(((xPos - trackHeadWidth) / trackContainerView()->pixelsPerBar()
|
||||
* TimePos::ticksPerBar()) + trackContainerView()->currentPosition()
|
||||
).quantize(1.0);
|
||||
).quantize(snapSize, true);
|
||||
|
||||
auto sClip = static_cast<SampleClip*>(getTrack()->createClip(clipPos));
|
||||
if (sClip) { sClip->setSampleFile(value); }
|
||||
|
||||
@@ -598,8 +598,8 @@ void TrackContentWidget::mousePressEvent( QMouseEvent * me )
|
||||
so.at( i )->setSelected( false);
|
||||
}
|
||||
getTrack()->addJournalCheckPoint();
|
||||
const TimePos pos = getPosition( me->x() ).getBar() *
|
||||
TimePos::ticksPerBar();
|
||||
const float snapSize = getGUI()->songEditor()->m_editor->getSnapSize();
|
||||
const TimePos pos = TimePos(getPosition(me->x())).quantize(snapSize, true);
|
||||
getTrack()->createClip(pos);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user