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 1 commit
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
27 changes: 18 additions & 9 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,16 @@ 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);
double step = range() * fact * (px > 0 ? 1 : -1);
szeli1 marked this conversation as resolved.
Show resolved Hide resolved
szeli1 marked this conversation as resolved.
Show resolved Hide resolved

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;
// get the real start and end frame
const double sampleStart = static_cast<double>(m_sample->startFrame());
const double sampleEnd = static_cast<double>(m_sample->endFrame());

const double stepFrom = std::clamp(sampleStart + step, 0.0, static_cast<double>(m_sample->sampleSize())) - sampleStart;
const double stepTo = std::clamp(sampleEnd + step, sampleStart + 1.0, static_cast<double>(m_sample->sampleSize())) - sampleEnd;
szeli1 marked this conversation as resolved.
Show resolved Hide resolved
step = std::abs(stepFrom) < std::abs(stepTo) ? stepFrom : stepTo;

setFrom(m_from + step);
setTo(m_to + step);
slideSampleByFrames(step);
}

Expand All @@ -395,7 +403,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 frames, bool slide_to)
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
{
knob * a_knob = m_startKnob;
switch(point)
Expand Down Expand Up @@ -430,7 +438,7 @@ void AudioFileProcessorWaveView::slideSamplePointByFrames(Point point, f_cnt_t f



void AudioFileProcessorWaveView::slideSampleByFrames(f_cnt_t frames)
void AudioFileProcessorWaveView::slideSampleByFrames(long frames)
{
if (m_sample->sampleSize() <= 1)
{
Expand Down Expand Up @@ -499,6 +507,7 @@ void AudioFileProcessorWaveView::knob::slideTo(double v, bool check_bound)
{
return;
}

szeli1 marked this conversation as resolved.
Show resolved Hide resolved
model()->setValue(v);
emit sliderMoved(model()->value());
}
Expand Down
9 changes: 7 additions & 2 deletions plugins/AudioFileProcessor/AudioFileProcessorWaveView.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,18 @@ public slots:
enum class DraggingType
{
Wave,
SlideWave,
ZoomWave,
SampleStart,
SampleEnd,
SampleLoop
} ;

Sample const* m_sample;
QPixmap m_graph;
// display from
szeli1 marked this conversation as resolved.
Show resolved Hide resolved
int m_from;
// display to
szeli1 marked this conversation as resolved.
Show resolved Hide resolved
int m_to;
int m_last_from;
int m_last_to;
Expand Down Expand Up @@ -158,8 +162,9 @@ 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);
// point: wihch knob to slide, frames: how mutch, can be negative, slide_to: should set the value instead of adding it
szeli1 marked this conversation as resolved.
Show resolved Hide resolved
void slideSamplePointByFrames(Point point, long frames, bool slide_to = false);
szeli1 marked this conversation as resolved.
Show resolved Hide resolved
void slideSampleByFrames(long frames);

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