Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zooming and sliding of the waveform view in AudioFileProcessor #7377

Merged
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
31 changes: 19 additions & 12 deletions plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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 sampleStart = static_cast<double>(m_sample->startFrame());
const auto sampleEnd = static_cast<double>(m_sample->endFrame());

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 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);
}

Expand All @@ -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)
Expand All @@ -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);
}
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions plugins/AudioFileProcessor/AudioFileProcessorWaveView.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public slots:
enum class DraggingType
{
Wave,
SlideWave,
ZoomWave,
SampleStart,
SampleEnd,
SampleLoop
Expand Down Expand Up @@ -158,8 +160,8 @@ public slots:
void zoom(const bool out = false);
void slide(int px);
void slideSamplePointByPx(Point point, int px);
void slideSamplePointByFrames(Point point, f_cnt_t frames, bool slide_to = false);
void slideSampleByFrames(f_cnt_t frames);
void slideSamplePointByFrames(Point point, long frameOffset, bool slideTo = false);
void slideSampleByFrames(long frameOffset);

void slideSamplePointToFrames(Point point, f_cnt_t frames)
{
Expand Down
Loading