waveformview: made UI seekable

This commit is contained in:
itsmattkc
2020-03-14 01:57:40 +11:00
parent 73d693f2d5
commit 7f2dcc8200
12 changed files with 233 additions and 185 deletions
+2
View File
@@ -96,6 +96,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
audio_renderer_ = new AudioBackend(this);
waveform_view_->SetBackend(audio_renderer_);
connect(waveform_view_, &WaveformView::TimeChanged, this, &ViewerWidget::SetTimeAndSignal);
connect(PixelFormat::instance(), &PixelFormat::FormatChanged, this, &ViewerWidget::UpdateRendererParameters);
@@ -109,6 +110,7 @@ void ViewerWidget::TimeChangedEvent(const int64_t &i)
}
controls_->SetTime(i);
waveform_view_->SetTime(i);
if (GetConnectedNode() && last_time_ != i) {
rational time_set = Timecode::timestamp_to_time(i, timebase());
+18 -20
View File
@@ -7,7 +7,7 @@
#include "common/clamp.h"
WaveformView::WaveformView(QWidget *parent) :
TimelineScaledWidget(parent),
SeekableWidget(parent),
backend_(nullptr)
{
setAutoFillBackground(true);
@@ -18,12 +18,18 @@ void WaveformView::SetBackend(AudioRenderBackend *backend)
{
if (backend_) {
disconnect(backend_, &AudioRenderBackend::QueueComplete, this, static_cast<void (WaveformView::*)()>(&WaveformView::update));
disconnect(backend_, &AudioRenderBackend::ParamsChanged, this, &WaveformView::BackendParamsChanged);
SetTimebase(0);
}
backend_ = backend;
if (backend_) {
connect(backend_, &AudioRenderBackend::QueueComplete, this, static_cast<void (WaveformView::*)()>(&WaveformView::update));
connect(backend_, &AudioRenderBackend::ParamsChanged, this, &WaveformView::BackendParamsChanged);
SetTimebase(rational(1, backend_->params().sample_rate()));
}
update();
@@ -69,15 +75,6 @@ void WaveformView::DrawWaveform(QPainter *painter, const QRect& rect, const doub
}
}
void WaveformView::SetScroll(int scroll)
{
scroll_ = scroll;
qDebug() << "Got scroll" << scroll_;
update();
}
void WaveformView::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
@@ -94,6 +91,7 @@ void WaveformView::paintEvent(QPaintEvent *event)
QPainter p(this);
// FIXME: Hardcoded color
p.setPen(Qt::green);
int channel_height = height() / params.channel_count();
@@ -101,11 +99,11 @@ void WaveformView::paintEvent(QPaintEvent *event)
int drew = 0;
fs.seek(params.samples_to_bytes(GetSampleIndexFromPixel(0)));
fs.seek(params.samples_to_bytes(ScreenToUnitRounded(0)));
for (int x=0; x<width() && !fs.atEnd(); x++) {
int samples_len = GetSampleIndexFromPixel(x+1) - GetSampleIndexFromPixel(x);
int samples_len = ScreenToUnitRounded(x+1) - ScreenToUnitRounded(x);
int max_read_size = params.samples_to_bytes(samples_len);
QByteArray read_buffer = fs.read(max_read_size);
@@ -133,16 +131,16 @@ void WaveformView::paintEvent(QPaintEvent *event)
fs.close();
// Draw playhead
p.setPen(GetPlayheadColor());
int playhead_x = UnitToScreen(GetTime());
p.drawLine(playhead_x, 0, playhead_x, height());
}
}
void WaveformView::ScaleChangedEvent(const double &)
void WaveformView::BackendParamsChanged()
{
update();
}
int WaveformView::GetSampleIndexFromPixel(int x) const
{
qDebug() << "X was" << x << "scroll was" << scroll_ << "=" << (x + scroll_);
return qRound(static_cast<double>(x + scroll_) * static_cast<double>(backend_->params().sample_rate()) / GetScale());
SetTimebase(rational(1, backend_->params().sample_rate()));
}
+4 -10
View File
@@ -6,9 +6,9 @@
#include "audio/sumsamples.h"
#include "render/audioparams.h"
#include "render/backend/audiorenderbackend.h"
#include "widget/timelinewidget/timelinescaledobject.h"
#include "widget/timeruler/seekablewidget.h"
class WaveformView : public TimelineScaledWidget
class WaveformView : public SeekableWidget
{
Q_OBJECT
public:
@@ -20,20 +20,14 @@ public:
static void DrawWaveform(QPainter* painter, const QRect &rect, const double &scale, const SampleSummer::Sum *samples, int nb_samples, int channels);
public slots:
void SetScroll(int scroll);
protected:
virtual void paintEvent(QPaintEvent* event) override;
virtual void ScaleChangedEvent(const double& s) override;
private:
int GetSampleIndexFromPixel(int x) const;
AudioRenderBackend* backend_;
int scroll_;
private slots:
void BackendParamsChanged();
};