timeline: when trimming, removing adjacent if its length is reduced to zero

This commit is contained in:
itsmattkc
2020-06-09 15:38:47 +10:00
parent 43513a2b3c
commit 494609410b
2 changed files with 27 additions and 4 deletions
+24 -4
View File
@@ -844,6 +844,7 @@ BlockTrimCommand::BlockTrimCommand(TrackOutput* track, Block *block, rational ne
mode_(mode),
adjacent_(nullptr),
we_created_adjacent_(false),
we_deleted_adjacent_(false),
allow_nongap_trimming_(false)
{
}
@@ -907,10 +908,17 @@ void BlockTrimCommand::redo_internal()
if (adjacent_) {
// If trimming LONGER, we'll need to trim the adjacent
// (assume if there's no adjacent, we're at the end of the timeline and do nothing)
if (mode_ == Timeline::kTrimIn) {
adjacent_->set_length_and_media_out(adjacent_->length() + trim_diff);
rational adjacent_length = adjacent_->length() + trim_diff;
if (adjacent_length.isNull()) {
// Ripple remove block
track_->RippleRemoveBlock(adjacent_);
TakeNodeFromParentGraph(adjacent_, &memory_manager_);
we_deleted_adjacent_ = true;
} else if (mode_ == Timeline::kTrimIn) {
adjacent_->set_length_and_media_out(adjacent_length);
} else {
adjacent_->set_length_and_media_in(adjacent_->length() + trim_diff);
adjacent_->set_length_and_media_in(adjacent_length);
}
}
}
@@ -943,8 +951,20 @@ void BlockTrimCommand::undo_internal()
if (adjacent_) {
// If trimmed LONGER, we adjusted an existing block
// (assume if there's no adjacent, we're at the end of the timeline and do nothing)
if (mode_ == Timeline::kTrimIn) {
if (we_deleted_adjacent_) {
static_cast<NodeGraph*>(track_->parent())->AddNode(adjacent_);
if (mode_ == Timeline::kTrimIn) {
track_->InsertBlockBefore(adjacent_, block_);
} else {
track_->InsertBlockAfter(adjacent_, block_);
}
we_deleted_adjacent_ = false;
} else if (mode_ == Timeline::kTrimIn) {
adjacent_->set_length_and_media_out(adjacent_->length() - trim_diff);
} else {
adjacent_->set_length_and_media_in(adjacent_->length() - trim_diff);
}
}
}
+3
View File
@@ -88,9 +88,12 @@ private:
Block* adjacent_;
bool we_created_adjacent_;
bool we_deleted_adjacent_;
bool allow_nongap_trimming_;
QObject memory_manager_;
};
class BlockSetMediaInCommand : public UndoCommand {