timelineview is now a true view of the blocks at all times
This commit is contained in:
+2
-2
@@ -295,10 +295,10 @@ void Core::CreateNewSequence()
|
||||
NodeParam::ConnectEdge(sg->texture_output(), cb1->texture_input());
|
||||
NodeParam::ConnectEdge(ii->texture_output(), cb2->texture_input());
|
||||
Block::ConnectBlocks(cb1, cb2);
|
||||
NodeParam::ConnectEdge(cb2->block_output(), tb->block_input());
|
||||
Block::ConnectBlocks(cb2, tb);
|
||||
NodeParam::ConnectEdge(tb->texture_output(), vo->texture_input());
|
||||
|
||||
tb->Refresh();
|
||||
//tb->Refresh();
|
||||
tb->AttachTimeline(olive::panel_focus_manager->MostRecentlyFocused<TimelinePanel>());
|
||||
|
||||
olive::panel_focus_manager->MostRecentlyFocused<NodePanel>()->SetGraph(new_sequence.get());
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "block.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Block::Block()
|
||||
{
|
||||
previous_input_ = new NodeInput();
|
||||
@@ -37,6 +39,9 @@ Block::Block()
|
||||
texture_output_ = new NodeOutput();
|
||||
texture_output_->set_data_type(NodeParam::kTexture);
|
||||
AddParameter(texture_output_);
|
||||
|
||||
connect(this, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(BlockOrderChanged(NodeEdgePtr)));
|
||||
connect(this, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(BlockOrderChanged(NodeEdgePtr)));
|
||||
}
|
||||
|
||||
QString Block::Category()
|
||||
@@ -115,6 +120,14 @@ void Block::RefreshFollowing()
|
||||
}
|
||||
}
|
||||
|
||||
void Block::BlockOrderChanged(NodeEdgePtr edge)
|
||||
{
|
||||
if (edge->input() == previous_input() || edge->input() == next_input()) {
|
||||
// The blocks surrounding this one have changed, we need to Refresh()
|
||||
RefreshFollowing();
|
||||
}
|
||||
}
|
||||
|
||||
NodeOutput *Block::texture_output()
|
||||
{
|
||||
return texture_output_;
|
||||
|
||||
+16
-3
@@ -37,7 +37,8 @@ public:
|
||||
|
||||
enum Type {
|
||||
kClip,
|
||||
kGap
|
||||
kGap,
|
||||
kEnd
|
||||
};
|
||||
|
||||
virtual Type type() = 0;
|
||||
@@ -78,16 +79,24 @@ public slots:
|
||||
* Blocks before it are accurate and up to date. You may need to traverse through the Block list (using previous())
|
||||
* and run Refresh() on all Blocks sequentially.
|
||||
*/
|
||||
void Refresh();
|
||||
virtual void Refresh();
|
||||
|
||||
/**
|
||||
* @brief Calls Refresh() on this block and all blocks connected after it (but not before it)
|
||||
*/
|
||||
void RefreshFollowing();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when this Block is refreshed
|
||||
*
|
||||
* Can be used as essentially a "changed" signal for UI widgets to know when to update their views
|
||||
*/
|
||||
void Refreshed();
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
private:
|
||||
NodeInput* previous_input_;
|
||||
NodeInput* next_input_;
|
||||
NodeOutput* block_output_;
|
||||
@@ -96,6 +105,10 @@ private:
|
||||
|
||||
rational in_point_;
|
||||
rational out_point_;
|
||||
|
||||
private slots:
|
||||
void BlockOrderChanged(NodeEdgePtr edge);
|
||||
|
||||
};
|
||||
|
||||
#endif // BLOCK_H
|
||||
|
||||
@@ -87,6 +87,17 @@ int Node::IndexOfParameter(NodeParam *param)
|
||||
return children().indexOf(param);
|
||||
}
|
||||
|
||||
QList<Node *> Node::GetDependencies()
|
||||
{
|
||||
QList<NodeParam*> params = parameters();
|
||||
|
||||
foreach (NodeParam* p, params) {
|
||||
if (p->type() == NodeParam::kInput) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVariant Node::PtrToValue(void *ptr)
|
||||
{
|
||||
return reinterpret_cast<quintptr>(ptr);
|
||||
|
||||
@@ -108,6 +108,11 @@ public:
|
||||
*/
|
||||
int IndexOfParameter(NodeParam* param);
|
||||
|
||||
/**
|
||||
* @brief Return a list of all Nodes that this Node's inputs are connected to
|
||||
*/
|
||||
QList<Node*> GetDependencies();
|
||||
|
||||
/**
|
||||
* @brief Convert a pointer to a value that can be sent between NodeParams
|
||||
*/
|
||||
|
||||
@@ -20,20 +20,17 @@
|
||||
|
||||
#include "timeline.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
TimelineOutput::TimelineOutput() :
|
||||
first_block_(nullptr),
|
||||
current_block_(nullptr),
|
||||
current_block_(this),
|
||||
attached_timeline_(nullptr)
|
||||
{
|
||||
block_input_ = new NodeInput();
|
||||
block_input_->add_data_input(NodeInput::kBlock);
|
||||
AddParameter(block_input_);
|
||||
}
|
||||
|
||||
texture_output_ = new NodeOutput();
|
||||
texture_output_->set_data_type(NodeOutput::kTexture);
|
||||
AddParameter(texture_output_);
|
||||
Block::Type TimelineOutput::type()
|
||||
{
|
||||
return kEnd;
|
||||
}
|
||||
|
||||
QString TimelineOutput::Name()
|
||||
@@ -93,50 +90,55 @@ void TimelineOutput::AttachTimeline(TimelinePanel *timeline)
|
||||
}
|
||||
}
|
||||
|
||||
NodeInput *TimelineOutput::block_input()
|
||||
rational TimelineOutput::length()
|
||||
{
|
||||
return block_input_;
|
||||
}
|
||||
|
||||
NodeOutput *TimelineOutput::texture_output()
|
||||
{
|
||||
return texture_output_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TimelineOutput::Refresh()
|
||||
{
|
||||
QVector<Block*> detect_attached_blocks;
|
||||
|
||||
Block* previous = attached_block();
|
||||
|
||||
first_block_ = nullptr;
|
||||
|
||||
// Find first block
|
||||
while (previous != nullptr) {
|
||||
detect_attached_blocks.prepend(previous);
|
||||
|
||||
// Cache block in "first", if this is indeed the first, its previous will be nullptr thus breaking the loop
|
||||
first_block_ = previous;
|
||||
if (attached_timeline_ != nullptr && !block_cache_.contains(previous)) {
|
||||
// FIXME: Remove the need to cast this
|
||||
attached_timeline_->AddClip(static_cast<ClipBlock*>(previous));
|
||||
}
|
||||
|
||||
previous = previous->previous();
|
||||
}
|
||||
|
||||
if (first_block_ != nullptr) {
|
||||
first_block_->RefreshFollowing();
|
||||
if (attached_timeline_ != nullptr) {
|
||||
foreach (Block* b, block_cache_) {
|
||||
if (!detect_attached_blocks.contains(b)) {
|
||||
attached_timeline_->RemoveClip(static_cast<ClipBlock*>(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
block_cache_ = detect_attached_blocks;
|
||||
|
||||
Block::Refresh();
|
||||
}
|
||||
|
||||
void TimelineOutput::Process(const rational &time)
|
||||
{
|
||||
// This node is intended to connect to the end of the timeline, so being beyond its out point is considered the end
|
||||
// of the sequence
|
||||
if (attached_block() == nullptr || time >= attached_block()->out()) {
|
||||
texture_output_->set_value(0);
|
||||
current_block_ = nullptr;
|
||||
// Run default node processing
|
||||
Block::Process(time);
|
||||
|
||||
// This node representso the end of the timeline, so being beyond its in point is considered the end of the sequence
|
||||
if (time >= in()) {
|
||||
texture_output()->set_value(0);
|
||||
current_block_ = this;
|
||||
return;
|
||||
}
|
||||
|
||||
// If we're here, we need to find the current clip to display
|
||||
if (current_block_ == nullptr) {
|
||||
current_block_ = attached_block();
|
||||
}
|
||||
// attached_block() is guaranteed to not be nullptr if we didn't return before
|
||||
current_block_ = attached_block();
|
||||
|
||||
// If the time requested is an earlier Block, traverse earlier until we find it
|
||||
while (time < current_block_->in()) {
|
||||
@@ -149,12 +151,21 @@ void TimelineOutput::Process(const rational &time)
|
||||
}
|
||||
|
||||
// At this point, we must have found the correct block so we use its texture output to produce the image
|
||||
texture_output_->set_value(current_block_->texture_output()->get_value(time));
|
||||
texture_output()->set_value(current_block_->texture_output()->get_value(time));
|
||||
}
|
||||
|
||||
Block *TimelineOutput::first_block()
|
||||
{
|
||||
if (block_cache_.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return block_cache_.first();
|
||||
}
|
||||
|
||||
Block *TimelineOutput::attached_block()
|
||||
{
|
||||
return ValueToPtr<Block>(block_input_->get_value(0));
|
||||
return ValueToPtr<Block>(previous_input()->get_value(0));
|
||||
}
|
||||
|
||||
void TimelineOutput::InsertBlock(Block *block, int index)
|
||||
@@ -165,48 +176,32 @@ void TimelineOutput::InsertBlock(Block *block, int index)
|
||||
|
||||
// FIXME: We'll probably want to add more nodes than this?
|
||||
|
||||
Block* block_before = nullptr;
|
||||
Block* block_after = first_block_;
|
||||
if (block_cache_.isEmpty()) {
|
||||
|
||||
for (int i=0;i<index;i++) {
|
||||
block_before = block_after;
|
||||
Block::ConnectBlocks(block, this);
|
||||
|
||||
block_after = block_after->next();
|
||||
} else if (index == 0) {
|
||||
|
||||
if (block_after == nullptr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Prepend block before all others
|
||||
Block::ConnectBlocks(block, block_cache_.first());
|
||||
|
||||
if (block_before != nullptr && block_after != nullptr) {
|
||||
// If neither blocks are null, we're inserting this block between them
|
||||
|
||||
// Disconnect existing blocks
|
||||
Block::DisconnectBlocks(block_before, block_after);
|
||||
Block::ConnectBlocks(block_before, block);
|
||||
Block::ConnectBlocks(block, block_after);
|
||||
} else if (block_before != nullptr) {
|
||||
// We're at the end of the Sequence
|
||||
|
||||
// Disconnect previous ending clip from this one
|
||||
NodeParam::DisconnectEdge(block_before->block_output(), block_input_);
|
||||
NodeParam::ConnectEdge(block->block_output(), block_input_);
|
||||
|
||||
// Connect both blocks together
|
||||
Block::ConnectBlocks(block_before, block);
|
||||
} else if (block_after != nullptr) {
|
||||
// We're at the start of the Sequence
|
||||
|
||||
// Connect both blocks together
|
||||
Block::ConnectBlocks(block, block_after);
|
||||
} else {
|
||||
// Sequence is empty
|
||||
NodeParam::ConnectEdge(block->block_output(), block_input_);
|
||||
}
|
||||
|
||||
if (attached_timeline_ != nullptr) {
|
||||
attached_timeline_->AddClip(static_cast<ClipBlock*>(block));
|
||||
}
|
||||
// Insert block between
|
||||
Block* before;
|
||||
Block* after;
|
||||
|
||||
Refresh();
|
||||
if (index < block_cache_.size()) {
|
||||
before = block_cache_.at(index - 1);
|
||||
after = block_cache_.at(index);
|
||||
} else {
|
||||
before = block_cache_.last();
|
||||
after = this;
|
||||
}
|
||||
|
||||
Block::DisconnectBlocks(before, after);
|
||||
Block::ConnectBlocks(before, block);
|
||||
Block::ConnectBlocks(block, after);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,18 +21,20 @@
|
||||
#ifndef TIMELINEOUTPUT_H
|
||||
#define TIMELINEOUTPUT_H
|
||||
|
||||
#include "node/node.h"
|
||||
#include "node/block/block.h"
|
||||
#include "panel/timeline/timeline.h"
|
||||
|
||||
/**
|
||||
* @brief Node that represents the end of the Timeline as well as a time traversal Node
|
||||
*/
|
||||
class TimelineOutput : public Node
|
||||
class TimelineOutput : public Block
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TimelineOutput();
|
||||
|
||||
virtual Type type() override;
|
||||
|
||||
virtual QString Name() override;
|
||||
virtual QString id() override;
|
||||
virtual QString Category() override;
|
||||
@@ -40,23 +42,23 @@ public:
|
||||
|
||||
void AttachTimeline(TimelinePanel* timeline);
|
||||
|
||||
NodeInput* block_input();
|
||||
NodeOutput* texture_output();
|
||||
virtual rational length() override;
|
||||
|
||||
virtual void Refresh() override;
|
||||
|
||||
public slots:
|
||||
void Refresh();
|
||||
|
||||
virtual void Process(const rational &time) override;
|
||||
|
||||
private:
|
||||
QVector<Block*> block_cache_;
|
||||
|
||||
Block* first_block();
|
||||
|
||||
Block* attached_block();
|
||||
|
||||
Block* first_block_;
|
||||
Block* current_block_;
|
||||
|
||||
NodeInput* block_input_;
|
||||
NodeOutput* texture_output_;
|
||||
|
||||
TimelinePanel* attached_timeline_;
|
||||
|
||||
private slots:
|
||||
|
||||
+2
-2
@@ -128,7 +128,7 @@ NodeEdgePtr NodeParam::ConnectEdge(NodeOutput *output, NodeInput *input)
|
||||
input->edges_.append(edge);
|
||||
|
||||
// Emit a signal than an edge was added (only one signal needs emitting)
|
||||
emit output->EdgeAdded(edge);
|
||||
emit input->EdgeAdded(edge);
|
||||
|
||||
return edge;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ void NodeParam::DisconnectEdge(NodeEdgePtr edge)
|
||||
output->edges_.removeAll(edge);
|
||||
input->edges_.removeAll(edge);
|
||||
|
||||
emit output->EdgeRemoved(edge);
|
||||
emit input->EdgeRemoved(edge);
|
||||
}
|
||||
|
||||
void NodeParam::DisconnectEdge(NodeOutput *output, NodeInput *input)
|
||||
|
||||
@@ -63,6 +63,11 @@ void TimelinePanel::AddClip(ClipBlock *clip)
|
||||
view_->AddClip(clip);
|
||||
}
|
||||
|
||||
void TimelinePanel::RemoveClip(ClipBlock *clip)
|
||||
{
|
||||
view_->RemoveClip(clip);
|
||||
}
|
||||
|
||||
void TimelinePanel::SetTimebase(const rational &timebase)
|
||||
{
|
||||
ruler_->SetTimebase(timebase);
|
||||
|
||||
@@ -35,6 +35,8 @@ public:
|
||||
|
||||
void AddClip(ClipBlock* clip);
|
||||
|
||||
void RemoveClip(ClipBlock* clip);
|
||||
|
||||
void SetTimebase(const rational& timebase);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -35,6 +35,8 @@ NodeView::NodeView(QWidget *parent) :
|
||||
void NodeView::SetGraph(NodeGraph *graph)
|
||||
{
|
||||
if (graph_ != nullptr) {
|
||||
disconnect(graph_, SIGNAL(NodeAdded(Node*)), this, SLOT(AddNode(Node*)));
|
||||
disconnect(graph_, SIGNAL(NodeRemoved(Node*)), this, SLOT(RemoveNode(Node*)));
|
||||
disconnect(graph_, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(AddEdge(NodeEdgePtr)));
|
||||
disconnect(graph_, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(RemoveEdge(NodeEdgePtr)));
|
||||
}
|
||||
|
||||
@@ -257,6 +257,8 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
}
|
||||
}
|
||||
|
||||
#include "node/block/block.h"
|
||||
|
||||
void NodeViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
// We override standard mouse behavior in some cases. In these cases, we don't want the standard "move" and "release"
|
||||
|
||||
@@ -67,6 +67,11 @@ void TimelineView::AddClip(ClipBlock *clip)
|
||||
connect(clip, SIGNAL(Refreshed()), this, SLOT(BlockChanged()));
|
||||
}
|
||||
|
||||
void TimelineView::RemoveClip(ClipBlock *clip)
|
||||
{
|
||||
delete clip_items_[clip];
|
||||
}
|
||||
|
||||
void TimelineView::SetScale(const double &scale)
|
||||
{
|
||||
scale_ = scale;
|
||||
|
||||
Reference in New Issue
Block a user