added some more timeline functions

This commit is contained in:
itsmattkc
2019-08-13 21:50:39 +10:00
parent 737442e513
commit 4f4737a395
21 changed files with 291 additions and 87 deletions
+93 -18
View File
@@ -26,7 +26,6 @@
#include "node/graph.h"
TimelineOutput::TimelineOutput() :
first_block_(nullptr),
current_block_(this),
attached_timeline_(nullptr)
{
@@ -37,6 +36,11 @@ Block::Type TimelineOutput::type()
return kEnd;
}
Block *TimelineOutput::copy()
{
return new TimelineOutput();
}
QString TimelineOutput::Name()
{
return tr("Timeline");
@@ -89,14 +93,16 @@ void TimelineOutput::AttachTimeline(TimelinePanel *timeline)
previous_block = previous_block->previous();
}
connect(attached_timeline_, SIGNAL(RequestInsertBlockAtIndex(Block*, int)), this, SLOT(InsertBlockAtIndex(Block*, int)));
connect(attached_timeline_, SIGNAL(RequestPlaceBlock(Block*, rational)), this, SLOT(PlaceBlock(Block*, rational)));
TimelineView* view = attached_timeline_->view();
connect(view, SIGNAL(RequestInsertBlockAtIndex(Block*, int)), this, SLOT(InsertBlockAtIndex(Block*, int)));
connect(view, SIGNAL(RequestPlaceBlock(Block*, rational)), this, SLOT(PlaceBlock(Block*, rational)));
}
}
rational TimelineOutput::length()
void TimelineOutput::set_length(const rational &)
{
return 0;
// Prevent length changing on this Block
}
void TimelineOutput::Refresh()
@@ -167,13 +173,9 @@ void TimelineOutput::InsertBlockBetweenBlocks(Block *block, Block *before, Block
Block::ConnectBlocks(block, after);
}
Block *TimelineOutput::first_block()
void TimelineOutput::InsertBlockAfter(Block *block, Block *before)
{
if (block_cache_.isEmpty()) {
return nullptr;
}
return block_cache_.first();
InsertBlockBetweenBlocks(block, before, before->next());
}
Block *TimelineOutput::attached_block()
@@ -248,6 +250,7 @@ void TimelineOutput::PlaceBlock(Block *block, rational start)
{
AddBlockToGraph(block);
// Place block at the beginning
if (start == 0) {
// FIXME: Remove existing
@@ -256,15 +259,16 @@ void TimelineOutput::PlaceBlock(Block *block, rational start)
}
// Check if the placement location is past the end of the timeline
if (start > in()) {
// FIXME: Remove existing
if (start >= in()) {
if (start > in()) {
// If so, insert a gap here
GapBlock* gap = new GapBlock();
gap->set_length(start - in());
// If so, insert a gap here
GapBlock* gap = new GapBlock();
gap->set_length(start - in());
// Then append them
AppendBlock(gap);
}
// Then append them
AppendBlock(gap);
AppendBlock(block);
return;
@@ -284,3 +288,74 @@ void TimelineOutput::PlaceBlock(Block *block, rational start)
}
}
}
void TimelineOutput::RemoveBlock(Block *block)
{
GapBlock* gap = new GapBlock();
gap->set_length(block->length());
Block* previous = block->previous();
Block* next = block->next();
// Remove block
RippleRemoveBlock(block);
if (previous == nullptr) {
// Block must be at the beginning
PrependBlock(gap);
} else {
InsertBlockBetweenBlocks(gap, previous, next);
}
}
void TimelineOutput::RippleRemoveBlock(Block *block)
{
Block* previous = block->previous();
Block* next = block->next();
if (previous != nullptr) {
Block::DisconnectBlocks(previous, block);
}
if (next != nullptr) {
Block::DisconnectBlocks(block, next);
}
if (previous != nullptr && next != nullptr) {
Block::ConnectBlocks(previous, next);
}
}
void TimelineOutput::SplitBlock(Block *block, rational time)
{
if (time < block->in() || time >= block->out()) {
return;
}
rational original_length = block->length();
block->set_length(time - block->in());
Block* copy = block->copy();
copy->set_length(original_length - block->length());
InsertBlockAfter(copy, block);
}
void TimelineOutput::SpliceBlock(Block *inner, Block *outer, rational inner_in)
{
Q_ASSERT(inner_in >= outer->in() && inner_in < outer->out());
// Cache original length
rational original_length = outer->length();
// Set outer clip to the clip that PRECEDES the inner clip
outer->set_length(inner_in - outer->in());
// Insert inner clip between BEFORE clip and its next clip
InsertBlockAfter(inner, outer);
// Create the AFTER clip
Block* copy = outer->copy();
copy->set_length(original_length - outer->length() - inner->length());
InsertBlockAfter(copy, inner);
}
+17 -10
View File
@@ -35,6 +35,8 @@ public:
virtual Type type() override;
virtual Block* copy() override;
virtual QString Name() override;
virtual QString id() override;
virtual QString Category() override;
@@ -42,7 +44,7 @@ public:
void AttachTimeline(TimelinePanel* timeline);
virtual rational length() override;
virtual void set_length(const rational &length) override;
virtual void Refresh() override;
@@ -67,13 +69,10 @@ private:
*/
void AddBlockToGraph(Block* block);
QVector<Block*> block_cache_;
Block* first_block();
Block* attached_block();
Block* first_block_;
QVector<Block*> block_cache_;
Block* current_block_;
TimelinePanel* attached_timeline_;
@@ -99,6 +98,13 @@ private slots:
*/
void InsertBlockBetweenBlocks(Block* block, Block* before, Block* after);
/**
* @brief Inserts Block after another Block
*
* Equivalent to calling InsertBlockBetweenBlocks(block, before, before->next())
*/
void InsertBlockAfter(Block* block, Block* before);
/**
* @brief Adds Block `block` at the very end of the Sequence after all other clips
*/
@@ -124,14 +130,15 @@ private slots:
void RippleRemoveBlock(Block* block);
/**
* @brief Removes the Block at the given index pushing all subsequent Blocks earlier to take up the space
* @brief Splits `block` into two Blocks at the Sequence point `time`
*/
void RippleRemoveBlockAtIndex(int index);
void SplitBlock(Block* block, rational time);
/**
* @brief Removes the last Block of the Sequence at the given index
* @brief Inserts Block `inner` between Block `outer`, splitting and shortening it to fit without changing the overall
* length
*/
void RippleRemoveLast();
void SpliceBlock(Block* inner, Block* outer, rational inner_in);
};
#endif // TIMELINEOUTPUT_H