inserting blocks through the timeline implemented
This commit is contained in:
+21
-11
@@ -88,7 +88,7 @@ void Block::Process(const rational &time)
|
||||
}
|
||||
|
||||
void Block::Refresh()
|
||||
{
|
||||
{
|
||||
// Set in point to the out point of the previous Node
|
||||
if (previous() != nullptr) {
|
||||
in_point_ = previous()->out();
|
||||
@@ -98,22 +98,20 @@ void Block::Refresh()
|
||||
|
||||
// Update out point by adding this clip's length to the just calculated in point
|
||||
out_point_ = in_point_ + length();
|
||||
|
||||
emit Refreshed();
|
||||
}
|
||||
|
||||
void Block::RefreshSurrounds()
|
||||
void Block::RefreshFollowing()
|
||||
{
|
||||
Block* acting_node = previous();
|
||||
Refresh();
|
||||
|
||||
while (acting_node != nullptr) {
|
||||
acting_node->Refresh();
|
||||
acting_node = acting_node->previous();
|
||||
}
|
||||
Block* next_block = next();
|
||||
|
||||
acting_node = next();
|
||||
while (next_block != nullptr) {
|
||||
next_block->Refresh();
|
||||
|
||||
while (acting_node != nullptr) {
|
||||
acting_node->Refresh();
|
||||
acting_node = acting_node->next();
|
||||
next_block = next_block->next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,3 +124,15 @@ NodeOutput *Block::block_output()
|
||||
{
|
||||
return block_output_;
|
||||
}
|
||||
|
||||
void Block::ConnectBlocks(Block *previous, Block *next)
|
||||
{
|
||||
NodeParam::ConnectEdge(previous->block_output(), next->previous_input());
|
||||
NodeParam::ConnectEdge(next->block_output(), previous->next_input());
|
||||
}
|
||||
|
||||
void Block::DisconnectBlocks(Block *previous, Block *next)
|
||||
{
|
||||
NodeParam::DisconnectEdge(previous->block_output(), next->previous_input());
|
||||
NodeParam::DisconnectEdge(next->block_output(), previous->next_input());
|
||||
}
|
||||
|
||||
+15
-1
@@ -35,6 +35,13 @@ class Block : public Node
|
||||
public:
|
||||
Block();
|
||||
|
||||
enum Type {
|
||||
kClip,
|
||||
kGap
|
||||
};
|
||||
|
||||
virtual Type type() = 0;
|
||||
|
||||
virtual QString Category() override;
|
||||
|
||||
const rational& in();
|
||||
@@ -52,6 +59,9 @@ public:
|
||||
NodeOutput* texture_output();
|
||||
NodeOutput* block_output();
|
||||
|
||||
static void ConnectBlocks(Block* previous, Block* next);
|
||||
static void DisconnectBlocks(Block* previous, Block* next);
|
||||
|
||||
public slots:
|
||||
virtual void Process(const rational &time) override;
|
||||
|
||||
@@ -70,8 +80,12 @@ public slots:
|
||||
*/
|
||||
void Refresh();
|
||||
|
||||
void RefreshFollowing();
|
||||
|
||||
signals:
|
||||
void Refreshed();
|
||||
|
||||
protected:
|
||||
void RefreshSurrounds();
|
||||
|
||||
private:
|
||||
NodeInput* previous_input_;
|
||||
|
||||
@@ -29,6 +29,11 @@ ClipBlock::ClipBlock()
|
||||
AddParameter(texture_input_);
|
||||
}
|
||||
|
||||
Block::Type ClipBlock::type()
|
||||
{
|
||||
return kClip;
|
||||
}
|
||||
|
||||
QString ClipBlock::Name()
|
||||
{
|
||||
return tr("Clip");
|
||||
@@ -52,6 +57,8 @@ rational ClipBlock::length()
|
||||
void ClipBlock::set_length(const rational &length)
|
||||
{
|
||||
length_ = length;
|
||||
|
||||
RefreshFollowing();
|
||||
}
|
||||
|
||||
NodeInput *ClipBlock::texture_input()
|
||||
|
||||
@@ -32,6 +32,8 @@ class ClipBlock : public Block
|
||||
public:
|
||||
ClipBlock();
|
||||
|
||||
virtual Type type() override;
|
||||
|
||||
virtual QString Name() override;
|
||||
virtual QString id() override;
|
||||
virtual QString Description() override;
|
||||
|
||||
@@ -24,6 +24,11 @@ GapBlock::GapBlock()
|
||||
{
|
||||
}
|
||||
|
||||
Block::Type GapBlock::type()
|
||||
{
|
||||
return kGap;
|
||||
}
|
||||
|
||||
rational GapBlock::length()
|
||||
{
|
||||
return length_;
|
||||
@@ -33,5 +38,5 @@ void GapBlock::set_length(const rational &length)
|
||||
{
|
||||
length_ = length;
|
||||
|
||||
RefreshSurrounds();
|
||||
RefreshFollowing();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ class GapBlock : public Block
|
||||
public:
|
||||
GapBlock();
|
||||
|
||||
virtual Type type() override;
|
||||
|
||||
virtual rational length() override;
|
||||
virtual void set_length(const rational &length) override;
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ void NodeGraph::AddNode(Node *node)
|
||||
|
||||
connect(node, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SIGNAL(EdgeAdded(NodeEdgePtr)));
|
||||
connect(node, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SIGNAL(EdgeRemoved(NodeEdgePtr)));
|
||||
|
||||
emit NodeAdded(node);
|
||||
}
|
||||
|
||||
QList<Node *> NodeGraph::nodes()
|
||||
|
||||
@@ -51,6 +51,16 @@ public:
|
||||
QList<Node*> nodes();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when a Node is added to the graph
|
||||
*/
|
||||
void NodeAdded(Node* node);
|
||||
|
||||
/**
|
||||
* @brief Signal emitted when a Node is removed from the graph
|
||||
*/
|
||||
void NodeRemoved(Node* node);
|
||||
|
||||
/**
|
||||
* @brief Signal emitted when a member node of this graph has been connected to another (creating an "edge")
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
|
||||
#include "timeline.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
TimelineOutput::TimelineOutput() :
|
||||
first_block_(nullptr),
|
||||
current_block_(nullptr),
|
||||
attached_timeline_(nullptr)
|
||||
{
|
||||
@@ -59,6 +62,8 @@ QString TimelineOutput::Description()
|
||||
void TimelineOutput::AttachTimeline(TimelinePanel *timeline)
|
||||
{
|
||||
if (attached_timeline_ != nullptr) {
|
||||
disconnect(attached_timeline_, SIGNAL(RequestInsertBlock(Block*, int)), this, SLOT(InsertBlock(Block*, int)));
|
||||
|
||||
attached_timeline_->Clear();
|
||||
}
|
||||
|
||||
@@ -83,6 +88,8 @@ void TimelineOutput::AttachTimeline(TimelinePanel *timeline)
|
||||
|
||||
previous_block = previous_block->previous();
|
||||
}
|
||||
|
||||
connect(attached_timeline_, SIGNAL(RequestInsertBlock(Block*, int)), this, SLOT(InsertBlock(Block*, int)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +103,26 @@ NodeOutput *TimelineOutput::texture_output()
|
||||
return texture_output_;
|
||||
}
|
||||
|
||||
void TimelineOutput::Refresh()
|
||||
{
|
||||
Block* previous = attached_block();
|
||||
|
||||
first_block_ = nullptr;
|
||||
|
||||
// Find first block
|
||||
while (previous != nullptr) {
|
||||
|
||||
// Cache block in "first", if this is indeed the first, its previous will be nullptr thus breaking the loop
|
||||
first_block_ = previous;
|
||||
|
||||
previous = previous->previous();
|
||||
}
|
||||
|
||||
if (first_block_ != nullptr) {
|
||||
first_block_->RefreshFollowing();
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -129,3 +156,57 @@ Block *TimelineOutput::attached_block()
|
||||
{
|
||||
return ValueToPtr<Block>(block_input_->get_value(0));
|
||||
}
|
||||
|
||||
void TimelineOutput::InsertBlock(Block *block, int index)
|
||||
{
|
||||
// Add node and its connected nodes to graph
|
||||
NodeGraph* graph = static_cast<NodeGraph*>(parent());
|
||||
graph->AddNode(block);
|
||||
|
||||
// FIXME: We'll probably want to add more nodes than this?
|
||||
|
||||
Block* block_before = nullptr;
|
||||
Block* block_after = first_block_;
|
||||
|
||||
for (int i=0;i<index;i++) {
|
||||
block_before = block_after;
|
||||
|
||||
block_after = block_after->next();
|
||||
|
||||
if (block_after == nullptr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
@@ -44,16 +44,23 @@ public:
|
||||
NodeOutput* texture_output();
|
||||
|
||||
public slots:
|
||||
void Refresh();
|
||||
|
||||
virtual void Process(const rational &time) override;
|
||||
|
||||
private:
|
||||
Block* attached_block();
|
||||
|
||||
Block* first_block_;
|
||||
Block* current_block_;
|
||||
|
||||
NodeInput* block_input_;
|
||||
NodeOutput* texture_output_;
|
||||
|
||||
TimelinePanel* attached_timeline_;
|
||||
|
||||
private slots:
|
||||
void InsertBlock(Block* block, int index);
|
||||
};
|
||||
|
||||
#endif // TIMELINEOUTPUT_H
|
||||
|
||||
Reference in New Issue
Block a user