implemented splicing into the timeline

This commit is contained in:
itsmattkc
2019-08-20 18:13:34 +10:00
parent ca51dac7f8
commit 78d96ecd28
6 changed files with 53 additions and 34 deletions
+15
View File
@@ -156,3 +156,18 @@ void Block::DisconnectBlocks(Block *previous, Block *next)
NodeParam::DisconnectEdge(previous->block_output(), next->previous_input());
NodeParam::DisconnectEdge(next->block_output(), previous->next_input());
}
const rational &Block::media_in()
{
return media_in_;
}
void Block::set_media_in(const rational &media_in)
{
if (media_in_ != media_in) {
media_in_ = media_in;
// Signal that this clips contents have changed
//InvalidateCache(in(), out());
}
}
+5
View File
@@ -65,6 +65,9 @@ public:
static void ConnectBlocks(Block* previous, Block* next);
static void DisconnectBlocks(Block* previous, Block* next);
const rational& media_in();
void set_media_in(const rational& media_in);
public slots:
virtual void Process(const rational &time) override;
@@ -110,6 +113,8 @@ private:
rational length_;
rational media_in_;
private slots:
void BlockOrderChanged(NodeEdgePtr edge);
+1 -1
View File
@@ -75,7 +75,7 @@ void ClipBlock::Process(const rational &time)
// If the time retrieved is within this block, get texture information
if (time >= in() && time < out()) {
// We convert the time given (timeline time) to media time
rational media_time = time - in() + media_in_;
rational media_time = time - in() + media_in();
// Retrieve texture
texture_output()->set_value(texture_input_->get_value(media_time));
-2
View File
@@ -48,8 +48,6 @@ public slots:
private:
NodeInput* texture_input_;
rational media_in_;
};
#endif // TIMELINEBLOCK_H
+27 -24
View File
@@ -310,10 +310,10 @@ void TrackOutput::RippleRemoveBlock(Block *block)
// FIXME: Should there be removing the Blocks from the graph?
}
void TrackOutput::SplitBlock(Block *block, rational time)
Block* TrackOutput::SplitBlock(Block *block, rational time)
{
if (time < block->in() || time >= block->out()) {
return;
if (time <= block->in() || time >= block->out()) {
return nullptr;
}
rational original_length = block->length();
@@ -323,29 +323,15 @@ void TrackOutput::SplitBlock(Block *block, rational time)
Block* copy = block->copy();
copy->set_length(original_length - block->length());
InsertBlockAfter(copy, block);
}
void TrackOutput::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);
return copy;
}
void TrackOutput::RippleRemoveArea(rational in, rational out, Block *insert)
{
// Block that needs to be split to remove this area
Block* splice = nullptr;
// Block whose out point exceeds `in` and needs to be trimmed
Block* trim_out_to_in = nullptr;
@@ -359,7 +345,7 @@ void TrackOutput::RippleRemoveArea(rational in, rational out, Block *insert)
foreach (Block* block, block_cache_) {
if (block->in() < in && block->out() > out) {
// The area entirely within this Block
// FIXME: Implement splitting a block in half when necessary
splice = block;
// We don't need to do anything else here
break;
@@ -375,10 +361,27 @@ void TrackOutput::RippleRemoveArea(rational in, rational out, Block *insert)
}
}
// If we picked up a block to splice
if (splice != nullptr) {
// Split the block here
Block* copy = SplitBlock(splice, in);
// Perform all further actions as if we were just trimming these clips
trim_out_to_in = splice;
trim_in_to_out = copy;
}
// If we picked up a block to trim the in point of
if (trim_in_to_out != nullptr && trim_in_to_out->in() < out) {
// FIXME: Set media_in point
trim_in_to_out->set_length(trim_in_to_out->out() - out);
rational new_length = trim_in_to_out->out() - out;
// Push media_in forward to compensate
rational length_diff = trim_in_to_out->length() - new_length;
trim_in_to_out->set_media_in(trim_in_to_out->media_in() - length_diff);
trim_in_to_out->set_length(new_length);
}
// Remove all blocks that are flagged for removal
+5 -7
View File
@@ -109,14 +109,12 @@ public:
/**
* @brief Splits `block` into two Blocks at the Sequence point `time`
*
* @return
*
* The second block created as a result of this split
*/
void SplitBlock(Block* block, rational time);
/**
* @brief Inserts Block `inner` between Block `outer`, splitting and shortening it to fit without changing the overall
* length
*/
void SpliceBlock(Block* inner, Block* outer, rational inner_in);
Block *SplitBlock(Block* block, rational time);
/**
* @brief Clears the area between in and out