mirror of
https://github.com/LMMS/lmms.git
synced 2026-03-25 01:13:36 -04:00
Fix zooming and sliding of the waveform view in AudioFileProcessor (#7377)
This commit is contained in:
@@ -166,16 +166,22 @@ void AudioFileProcessorWaveView::mouseMoveEvent(QMouseEvent * me)
|
||||
case DraggingType::SampleLoop:
|
||||
slideSamplePointByPx(Point::Loop, step);
|
||||
break;
|
||||
case DraggingType::SlideWave:
|
||||
slide(step);
|
||||
break;
|
||||
case DraggingType::ZoomWave:
|
||||
zoom(me->y() < m_draggingLastPoint.y());
|
||||
break;
|
||||
case DraggingType::Wave:
|
||||
default:
|
||||
if (qAbs(me->y() - m_draggingLastPoint.y())
|
||||
< 2 * qAbs(me->x() - m_draggingLastPoint.x()))
|
||||
{
|
||||
slide(step);
|
||||
m_draggingType = DraggingType::SlideWave;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoom(me->y() < m_draggingLastPoint.y());
|
||||
m_draggingType = DraggingType::ZoomWave;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,14 +382,15 @@ void AudioFileProcessorWaveView::zoom(const bool out)
|
||||
void AudioFileProcessorWaveView::slide(int px)
|
||||
{
|
||||
const double fact = qAbs(double(px) / width());
|
||||
auto step = range() * fact * (px > 0 ? -1 : 1);
|
||||
auto step = range() * fact * (px > 0 ? 1 : -1);
|
||||
|
||||
const auto stepFrom = std::clamp(m_from + step, 0.0, static_cast<double>(m_sample->sampleSize())) - m_from;
|
||||
const auto stepTo = std::clamp(m_to + step, m_from + 1.0, static_cast<double>(m_sample->sampleSize())) - m_to;
|
||||
const auto sampleStart = static_cast<double>(m_sample->startFrame());
|
||||
const auto sampleEnd = static_cast<double>(m_sample->endFrame());
|
||||
|
||||
const auto stepFrom = std::clamp(sampleStart + step, 0.0, static_cast<double>(m_sample->sampleSize())) - sampleStart;
|
||||
const auto stepTo = std::clamp(sampleEnd + step, sampleStart + 1.0, static_cast<double>(m_sample->sampleSize())) - sampleEnd;
|
||||
step = std::abs(stepFrom) < std::abs(stepTo) ? stepFrom : stepTo;
|
||||
|
||||
setFrom(m_from + step);
|
||||
setTo(m_to + step);
|
||||
slideSampleByFrames(step);
|
||||
}
|
||||
|
||||
@@ -395,7 +402,7 @@ void AudioFileProcessorWaveView::slideSamplePointByPx(Point point, int px)
|
||||
);
|
||||
}
|
||||
|
||||
void AudioFileProcessorWaveView::slideSamplePointByFrames(Point point, f_cnt_t frames, bool slide_to)
|
||||
void AudioFileProcessorWaveView::slideSamplePointByFrames(Point point, long frameOffset, bool slideTo)
|
||||
{
|
||||
knob * a_knob = m_startKnob;
|
||||
switch(point)
|
||||
@@ -415,8 +422,8 @@ void AudioFileProcessorWaveView::slideSamplePointByFrames(Point point, f_cnt_t f
|
||||
}
|
||||
else
|
||||
{
|
||||
const double v = static_cast<double>(frames) / m_sample->sampleSize();
|
||||
if (slide_to)
|
||||
const double v = static_cast<double>(frameOffset) / m_sample->sampleSize();
|
||||
if (slideTo)
|
||||
{
|
||||
a_knob->slideTo(v);
|
||||
}
|
||||
@@ -430,13 +437,13 @@ void AudioFileProcessorWaveView::slideSamplePointByFrames(Point point, f_cnt_t f
|
||||
|
||||
|
||||
|
||||
void AudioFileProcessorWaveView::slideSampleByFrames(f_cnt_t frames)
|
||||
void AudioFileProcessorWaveView::slideSampleByFrames(long frameOffset)
|
||||
{
|
||||
if (m_sample->sampleSize() <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const double v = static_cast<double>(frames) / m_sample->sampleSize();
|
||||
const double v = static_cast<double>(frameOffset) / m_sample->sampleSize();
|
||||
// update knobs in the right order
|
||||
// to avoid them clamping each other
|
||||
if (v < 0)
|
||||
|
||||
Reference in New Issue
Block a user