added some basic timeline functionality
This commit is contained in:
@@ -29,6 +29,21 @@ Block::Type GapBlock::type()
|
||||
return kGap;
|
||||
}
|
||||
|
||||
QString GapBlock::Name()
|
||||
{
|
||||
return tr("Gap");
|
||||
}
|
||||
|
||||
QString GapBlock::id()
|
||||
{
|
||||
return "org.olivevideoeditor.Olive.gap";
|
||||
}
|
||||
|
||||
QString GapBlock::Description()
|
||||
{
|
||||
return tr("A time-based node that represents an empty space.");
|
||||
}
|
||||
|
||||
rational GapBlock::length()
|
||||
{
|
||||
return length_;
|
||||
|
||||
@@ -34,6 +34,10 @@ public:
|
||||
|
||||
virtual Type type() override;
|
||||
|
||||
virtual QString Name() override;
|
||||
virtual QString id() override;
|
||||
virtual QString Description() override;
|
||||
|
||||
virtual rational length() override;
|
||||
virtual void set_length(const rational &length) override;
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@ NodeGraph::NodeGraph()
|
||||
|
||||
void NodeGraph::AddNode(Node *node)
|
||||
{
|
||||
if (ContainsNode(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
node->setParent(this);
|
||||
|
||||
connect(node, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SIGNAL(EdgeAdded(NodeEdgePtr)));
|
||||
@@ -37,7 +41,24 @@ void NodeGraph::AddNode(Node *node)
|
||||
emit NodeAdded(node);
|
||||
}
|
||||
|
||||
void NodeGraph::AddNodeWithDependencies(Node *node)
|
||||
{
|
||||
// Add node and its connected nodes to graph
|
||||
AddNode(node);
|
||||
|
||||
// Add all of Block's dependencies
|
||||
QList<Node*> node_dependencies = node->GetDependencies();
|
||||
foreach (Node* dep, node_dependencies) {
|
||||
AddNode(dep);
|
||||
}
|
||||
}
|
||||
|
||||
QList<Node *> NodeGraph::nodes()
|
||||
{
|
||||
return static_qobjectlist_cast<Node>(children());
|
||||
}
|
||||
|
||||
bool NodeGraph::ContainsNode(Node *n)
|
||||
{
|
||||
return (n->parent() == this);
|
||||
}
|
||||
|
||||
@@ -45,11 +45,24 @@ public:
|
||||
*/
|
||||
void AddNode(Node* node);
|
||||
|
||||
/**
|
||||
* @brief Adds a node to this graph and all nodes connected to its inputs
|
||||
*
|
||||
* Adds the Node to the graph and runs through its inputs adding all of its dependencies (and all of their
|
||||
* dependencies and so forth).
|
||||
*/
|
||||
void AddNodeWithDependencies(Node* node);
|
||||
|
||||
/**
|
||||
* @brief Retrieve a complete list of the nodes belonging to this graph
|
||||
*/
|
||||
QList<Node*> nodes();
|
||||
|
||||
/**
|
||||
* @brief Returns whether a certain Node is in the graph or not
|
||||
*/
|
||||
bool ContainsNode(Node* n);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when a Node is added to the graph
|
||||
|
||||
@@ -107,15 +107,18 @@ void MediaInput::Process(const rational &time)
|
||||
decoder_->set_stream(footage->stream(0));
|
||||
}
|
||||
|
||||
// Get frame from Decoder
|
||||
FramePtr frame = decoder_->Retrieve(time);
|
||||
|
||||
if (frame == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use OCIO
|
||||
frame = PixelService::ConvertPixelFormat(frame, olive::PIX_FMT_RGBA32F);
|
||||
ColorService::ConvertFrame(frame);
|
||||
// Convert the frame to the Renderer format
|
||||
//frame = PixelService::ConvertPixelFormat(frame, olive::PIX_FMT_RGBA16F);
|
||||
|
||||
// Convert the frame to the Renderer color space
|
||||
//ColorService::ConvertFrame(frame);
|
||||
|
||||
// FIXME: Test code
|
||||
if (tex_buf_.IsCreated()) {
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
|
||||
#include "timeline.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "node/block/gap/gap.h"
|
||||
#include "node/graph.h"
|
||||
|
||||
TimelineOutput::TimelineOutput() :
|
||||
first_block_(nullptr),
|
||||
@@ -54,12 +58,11 @@ QString TimelineOutput::Description()
|
||||
"Sequence.");
|
||||
}
|
||||
|
||||
#include "project/item/sequence/sequence.h"
|
||||
|
||||
void TimelineOutput::AttachTimeline(TimelinePanel *timeline)
|
||||
{
|
||||
if (attached_timeline_ != nullptr) {
|
||||
disconnect(attached_timeline_, SIGNAL(RequestInsertBlock(Block*, int)), this, SLOT(InsertBlock(Block*, int)));
|
||||
disconnect(attached_timeline_, SIGNAL(RequestInsertBlockAtIndex(Block*, int)), this, SLOT(InsertBlockAtIndex(Block*, int)));
|
||||
disconnect(attached_timeline_, SIGNAL(RequestPlaceBlock(Block*, rational)), this, SLOT(PlaceBlock(Block*, rational)));
|
||||
|
||||
attached_timeline_->Clear();
|
||||
}
|
||||
@@ -86,7 +89,8 @@ void TimelineOutput::AttachTimeline(TimelinePanel *timeline)
|
||||
previous_block = previous_block->previous();
|
||||
}
|
||||
|
||||
connect(attached_timeline_, SIGNAL(RequestInsertBlock(Block*, int)), this, SLOT(InsertBlock(Block*, int)));
|
||||
connect(attached_timeline_, SIGNAL(RequestInsertBlockAtIndex(Block*, int)), this, SLOT(InsertBlockAtIndex(Block*, int)));
|
||||
connect(attached_timeline_, SIGNAL(RequestPlaceBlock(Block*, rational)), this, SLOT(PlaceBlock(Block*, rational)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +158,15 @@ void TimelineOutput::Process(const rational &time)
|
||||
texture_output()->set_value(current_block_->texture_output()->get_value(time));
|
||||
}
|
||||
|
||||
void TimelineOutput::InsertBlockBetweenBlocks(Block *block, Block *before, Block *after)
|
||||
{
|
||||
AddBlockToGraph(block);
|
||||
|
||||
Block::DisconnectBlocks(before, after);
|
||||
Block::ConnectBlocks(before, block);
|
||||
Block::ConnectBlocks(block, after);
|
||||
}
|
||||
|
||||
Block *TimelineOutput::first_block()
|
||||
{
|
||||
if (block_cache_.isEmpty()) {
|
||||
@@ -168,48 +181,106 @@ Block *TimelineOutput::attached_block()
|
||||
return ValueToPtr<Block>(previous_input()->get_value(0));
|
||||
}
|
||||
|
||||
void TimelineOutput::InsertBlock(Block *block, int index)
|
||||
void TimelineOutput::PrependBlock(Block *block)
|
||||
{
|
||||
// Add node and its connected nodes to graph
|
||||
NodeGraph* graph = static_cast<NodeGraph*>(parent());
|
||||
graph->AddNode(block);
|
||||
AddBlockToGraph(block);
|
||||
|
||||
// Add all of Block's dependencies
|
||||
QList<Node*> block_dependencies = block->GetDependencies();
|
||||
foreach (Node* dep, block_dependencies) {
|
||||
graph->AddNode(dep);
|
||||
if (block_cache_.isEmpty()) {
|
||||
ConnectBlockInternal(block);
|
||||
} else {
|
||||
Block::ConnectBlocks(block, block_cache_.first());
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineOutput::InsertBlockAtIndex(Block *block, int index)
|
||||
{
|
||||
AddBlockToGraph(block);
|
||||
|
||||
if (block_cache_.isEmpty()) {
|
||||
|
||||
// If there are no blocks connected, the index doesn't matter. Just connect it.
|
||||
Block::ConnectBlocks(block, this);
|
||||
ConnectBlockInternal(block);
|
||||
|
||||
} else if (index == 0) {
|
||||
|
||||
// If the index is 0, it goes at the very beginning
|
||||
Block::ConnectBlocks(block, block_cache_.first());
|
||||
PrependBlock(block);
|
||||
|
||||
} else if (index >= block_cache_.size()) {
|
||||
|
||||
// Append Block at the end
|
||||
AppendBlock(block);
|
||||
|
||||
} else {
|
||||
|
||||
// Otherwise, the block goes between two other blocks somehow
|
||||
Block* before;
|
||||
Block* after;
|
||||
|
||||
if (index < block_cache_.size()) {
|
||||
// The block goes somewhere in between some set of two blocks
|
||||
before = block_cache_.at(index - 1);
|
||||
after = block_cache_.at(index);
|
||||
} else {
|
||||
// The block goes at the very end
|
||||
before = block_cache_.last();
|
||||
after = this;
|
||||
}
|
||||
|
||||
// Connect blocks correctly
|
||||
Block::DisconnectBlocks(before, after);
|
||||
Block::ConnectBlocks(before, block);
|
||||
Block::ConnectBlocks(block, after);
|
||||
// Insert Block just before the Block currently at that index so that it becomes the new Block at that index
|
||||
InsertBlockBetweenBlocks(block, block_cache_.at(index - 1), block_cache_.at(index));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineOutput::AppendBlock(Block *block)
|
||||
{
|
||||
AddBlockToGraph(block);
|
||||
|
||||
if (block_cache_.isEmpty()) {
|
||||
ConnectBlockInternal(block);
|
||||
} else {
|
||||
InsertBlockBetweenBlocks(block, block_cache_.last(), this);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineOutput::ConnectBlockInternal(Block *block)
|
||||
{
|
||||
AddBlockToGraph(block);
|
||||
|
||||
Block::ConnectBlocks(block, this);
|
||||
}
|
||||
|
||||
void TimelineOutput::AddBlockToGraph(Block *block)
|
||||
{
|
||||
// Find the parent graph
|
||||
NodeGraph* graph = static_cast<NodeGraph*>(parent());
|
||||
graph->AddNodeWithDependencies(block);
|
||||
}
|
||||
|
||||
void TimelineOutput::PlaceBlock(Block *block, rational start)
|
||||
{
|
||||
AddBlockToGraph(block);
|
||||
|
||||
if (start == 0) {
|
||||
// FIXME: Remove existing
|
||||
|
||||
PrependBlock(block);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the placement location is past the end of the timeline
|
||||
if (start > in()) {
|
||||
// FIXME: Remove existing
|
||||
|
||||
// If so, insert a gap here
|
||||
GapBlock* gap = new GapBlock();
|
||||
gap->set_length(start - in());
|
||||
|
||||
// Then append them
|
||||
AppendBlock(gap);
|
||||
AppendBlock(block);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the Block is placed at the in point of an existing Block, in which case a simple insert between will
|
||||
// suffice
|
||||
for (int i=1;i<block_cache_.size();i++) {
|
||||
Block* comparison = block_cache_.at(i);
|
||||
|
||||
if (comparison->in() == start) {
|
||||
Block* previous = block_cache_.at(i-1);
|
||||
|
||||
// InsertBlockAtIndex() could work here, but this function is faster since we've already found the Blocks
|
||||
InsertBlockBetweenBlocks(block, previous, comparison);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,18 @@ public slots:
|
||||
virtual void Process(const rational &time) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Sets this Block as the only block in the Timeline (creating essentially a one clip sequence)
|
||||
*/
|
||||
void ConnectBlockInternal(Block* block);
|
||||
|
||||
/**
|
||||
* @brief Adds a Block to the parent graph so it can be connected to other Nodes
|
||||
*
|
||||
* Also runs through Node's dependencies (the Nodes whose outputs are connected to this Node's inputs)
|
||||
*/
|
||||
void AddBlockToGraph(Block* block);
|
||||
|
||||
QVector<Block*> block_cache_;
|
||||
|
||||
Block* first_block();
|
||||
@@ -62,7 +74,39 @@ private:
|
||||
TimelinePanel* attached_timeline_;
|
||||
|
||||
private slots:
|
||||
void InsertBlock(Block* block, int index);
|
||||
/**
|
||||
* @brief Adds Block `block` at the very beginning of the Sequence before all other clips
|
||||
*/
|
||||
void PrependBlock(Block* block);
|
||||
|
||||
/**
|
||||
* @brief Inserts Block `block` at a specific index (0 is the start of the timeline)
|
||||
*
|
||||
* If the index == 0, this function does the same as PrependBlock(). If the index >= the current number of blocks,
|
||||
* this function is the same as AppendBlock().
|
||||
*/
|
||||
void InsertBlockAtIndex(Block* block, int index);
|
||||
|
||||
/**
|
||||
* @brief Inserts a Block between two other Blocks
|
||||
*
|
||||
* Disconnects `before` and `after`, and connects them to `block` with `block` in between.
|
||||
*/
|
||||
void InsertBlockBetweenBlocks(Block* block, Block* before, Block* after);
|
||||
|
||||
/**
|
||||
* @brief Adds Block `block` at the very end of the Sequence after all other clips
|
||||
*/
|
||||
void AppendBlock(Block* block);
|
||||
|
||||
/**
|
||||
* @brief Destructively places `block` at the in point `start`
|
||||
*
|
||||
* The Block is guaranteed to be placed at the starting point specified. If there are Blocks in this area, they are
|
||||
* either trimmed or removed to make space for this Block. Additionally, if the Block is placed beyond the end of
|
||||
* the Sequence, a GapBlock is inserted to compensate.
|
||||
*/
|
||||
void PlaceBlock(Block* block, rational start);
|
||||
};
|
||||
|
||||
#endif // TIMELINEOUTPUT_H
|
||||
|
||||
Reference in New Issue
Block a user