timeline/renderer: automatically update timeline view when a visual waveform

has updated
This commit is contained in:
itsmattkc
2020-03-07 02:44:15 +11:00
parent b2792b7c58
commit f2d6d3b32c
6 changed files with 38 additions and 32 deletions
+3
View File
@@ -50,6 +50,9 @@ public:
virtual void Retranslate() override;
signals:
void PreviewUpdated();
private:
NodeInput* texture_input_;
+7 -1
View File
@@ -6,6 +6,7 @@
#include "audio/audiomanager.h"
#include "audio/sumsamples.h"
#include "config/config.h"
#include "node/block/clip/clip.h"
AudioRenderWorker::AudioRenderWorker(DecoderCache* decoder_cache, QHash<Node *, Node *> *copy_map, QObject *parent) :
RenderWorker(decoder_cache, parent),
@@ -90,10 +91,11 @@ NodeValueTable AudioRenderWorker::RenderBlock(const TrackOutput *track, const Ti
actual_copy_size);
// Save waveform to file
Block* src_block = static_cast<Block*>(copy_map_->value(b));
QDir local_appdata_dir(Config::Current()["DiskCachePath"].toString());
QDir waveform_loc = local_appdata_dir.filePath("waveform");
waveform_loc.mkpath(".");
QFile wave_file(waveform_loc.filePath(QString::number(reinterpret_cast<quintptr>(copy_map_->value(b)))));
QFile wave_file(waveform_loc.filePath(QString::number(reinterpret_cast<quintptr>(src_block))));
wave_file.open(QFile::ReadWrite);
// FIXME: Assumes 32-bit float
@@ -125,6 +127,10 @@ NodeValueTable AudioRenderWorker::RenderBlock(const TrackOutput *track, const Ti
}
wave_file.close();
if (src_block->type() == Block::kClip) {
emit static_cast<ClipBlock*>(src_block)->PreviewUpdated();
}
}
}
+17 -5
View File
@@ -662,10 +662,9 @@ void TimelineWidget::AddBlock(Block *block, TrackReference track)
case Block::kTransition:
case Block::kGap:
{
TimelineViewBlockItem* item = new TimelineViewBlockItem();
// Set up clip with view parameters (clip item will automatically size its rect accordingly)
item->SetBlock(block);
TimelineViewBlockItem* item = new TimelineViewBlockItem(block);
item->SetYCoords(GetTrackY(track), GetTrackHeight(track));
item->SetScale(GetScale());
item->SetTrack(track);
@@ -677,6 +676,10 @@ void TimelineWidget::AddBlock(Block *block, TrackReference track)
views_.at(track.type())->view()->scene()->addItem(item);
connect(block, &Block::Refreshed, this, &TimelineWidget::BlockChanged);
if (block->type() == Block::kClip) {
connect(static_cast<ClipBlock*>(block), &ClipBlock::PreviewUpdated, this, &TimelineWidget::PreviewUpdated);
}
break;
}
}
@@ -721,13 +724,22 @@ void TimelineWidget::ViewSelectionChanged()
void TimelineWidget::BlockChanged()
{
TimelineViewRect* rect = block_items_[static_cast<Block*>(sender())];
TimelineViewRect* rect = block_items_.value(static_cast<Block*>(sender()));
if (rect != nullptr) {
if (rect) {
rect->UpdateRect();
}
}
void TimelineWidget::PreviewUpdated()
{
TimelineViewRect* rect = block_items_.value(static_cast<Block*>(sender()));
if (rect) {
rect->update();
}
}
void TimelineWidget::UpdateHorizontalSplitters()
{
QSplitter* sender_splitter = static_cast<QSplitter*>(sender());
@@ -425,6 +425,8 @@ private slots:
*/
void BlockChanged();
void PreviewUpdated();
void UpdateHorizontalSplitters();
void UpdateTimecodeWidthFromSplitters(QSplitter *s);
@@ -34,23 +34,12 @@
#include "config/config.h"
#include "node/block/transition/transition.h"
TimelineViewBlockItem::TimelineViewBlockItem(QGraphicsItem* parent) :
TimelineViewBlockItem::TimelineViewBlockItem(Block *block, QGraphicsItem* parent) :
TimelineViewRect(parent),
block_(nullptr)
block_(block)
{
setBrush(Qt::white);
setCursor(Qt::DragMoveCursor);
}
Block *TimelineViewBlockItem::block()
{
return block_;
}
void TimelineViewBlockItem::SetBlock(Block *block)
{
block_ = block;
setFlag(QGraphicsItem::ItemIsSelectable,
block_->type() == Block::kClip
|| block_->type() == Block::kGap
@@ -59,12 +48,13 @@ void TimelineViewBlockItem::SetBlock(Block *block)
UpdateRect();
}
Block *TimelineViewBlockItem::block() const
{
return block_;
}
void TimelineViewBlockItem::UpdateRect()
{
if (block_ == nullptr) {
return;
}
double item_left = TimeToScene(block_->in());
double item_width = TimeToScene(block_->length());
@@ -81,12 +71,6 @@ void TimelineViewBlockItem::UpdateRect()
void TimelineViewBlockItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget)
if (block_ == nullptr) {
return;
}
switch (block_->type()) {
case Block::kClip:
{
@@ -30,10 +30,9 @@
class TimelineViewBlockItem : public TimelineViewRect
{
public:
TimelineViewBlockItem(QGraphicsItem* parent = nullptr);
TimelineViewBlockItem(Block* block, QGraphicsItem* parent = nullptr);
Block* block();
void SetBlock(Block *block);
Block* block() const;
virtual void UpdateRect() override;