Skip to content

Commit

Permalink
AudioFileProcessorWaveView_fixed_zooming_and_sliding
Browse files Browse the repository at this point in the history
  • Loading branch information
szeli1 committed Jul 12, 2024
1 parent 1420a1f commit 718e3c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
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);

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

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
int m_from;
// display to
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
void slideSamplePointByFrames(Point point, long frames, bool slide_to = false);
void slideSampleByFrames(long frames);

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

0 comments on commit 718e3c8

Please sign in to comment.