remove shifts, operations, and make caches node-agnostic
This commit is contained in:
@@ -416,8 +416,7 @@ void TimelineWidget::SplitAtPlayhead()
|
||||
void TimelineWidget::ReplaceBlocksWithGaps(const QVector<Block *> &blocks,
|
||||
bool remove_from_graph,
|
||||
MultiUndoCommand *command,
|
||||
bool handle_transitions,
|
||||
bool handle_invalidations)
|
||||
bool handle_transitions)
|
||||
{
|
||||
foreach (Block* b, blocks) {
|
||||
if (dynamic_cast<GapBlock*>(b)) {
|
||||
@@ -428,7 +427,7 @@ void TimelineWidget::ReplaceBlocksWithGaps(const QVector<Block *> &blocks,
|
||||
|
||||
Track* original_track = b->track();
|
||||
|
||||
command->add_child(new TrackReplaceBlockWithGapCommand(original_track, b, handle_transitions, handle_invalidations));
|
||||
command->add_child(new TrackReplaceBlockWithGapCommand(original_track, b, handle_transitions));
|
||||
|
||||
if (remove_from_graph) {
|
||||
command->add_child(new NodeRemoveWithExclusiveDependenciesAndDisconnect(b));
|
||||
@@ -482,7 +481,7 @@ void TimelineWidget::DeleteSelected(bool ripple)
|
||||
}
|
||||
|
||||
// Replace clips with gaps (effectively deleting them)
|
||||
ReplaceBlocksWithGaps(clips_to_delete, true, command, false, !ripple);
|
||||
ReplaceBlocksWithGaps(clips_to_delete, true, command, false);
|
||||
|
||||
// Insert ripple command now that it's all cleaned up gaps
|
||||
TimelineRippleDeleteGapsAtRegionsCommand *ripple_command = nullptr;
|
||||
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
|
||||
void RestoreSplitterState(const QByteArray& state);
|
||||
|
||||
static void ReplaceBlocksWithGaps(const QVector<Block *> &blocks, bool remove_from_graph, MultiUndoCommand *command, bool handle_transitions = true, bool handle_invalidations = true);
|
||||
static void ReplaceBlocksWithGaps(const QVector<Block *> &blocks, bool remove_from_graph, MultiUndoCommand *command, bool handle_transitions = true);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the QGraphicsItem at a particular scene position
|
||||
|
||||
@@ -208,8 +208,6 @@ void TransitionRemoveCommand::redo()
|
||||
|
||||
Q_ASSERT(out_block_ || in_block_);
|
||||
|
||||
track_->BeginOperation();
|
||||
|
||||
TimeRange invalidate_range(block_->in(), block_->out());
|
||||
|
||||
if (in_block_) {
|
||||
@@ -230,10 +228,6 @@ void TransitionRemoveCommand::redo()
|
||||
|
||||
track_->RippleRemoveBlock(block_);
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
track_->Node::InvalidateCache(invalidate_range, Track::kBlockInput);
|
||||
|
||||
if (remove_from_graph_) {
|
||||
if (!remove_command_) {
|
||||
remove_command_ = CreateRemoveCommand(block_);
|
||||
@@ -249,8 +243,6 @@ void TransitionRemoveCommand::undo()
|
||||
remove_command_->undo_now();
|
||||
}
|
||||
|
||||
track_->BeginOperation();
|
||||
|
||||
if (in_block_) {
|
||||
track_->InsertBlockBefore(block_, in_block_);
|
||||
} else {
|
||||
@@ -275,10 +267,6 @@ void TransitionRemoveCommand::undo()
|
||||
if (out_block_) {
|
||||
out_block_->set_length_and_media_out(out_block_->length() - block_->out_offset());
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
track_->Node::InvalidateCache(TimeRange(block_->in(), block_->out()), Track::kBlockInput);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -287,11 +275,8 @@ void TransitionRemoveCommand::undo()
|
||||
void TrackListInsertGaps::prepare()
|
||||
{
|
||||
// Determine if all tracks will be affected, which will allow us to make some optimizations
|
||||
all_tracks_unlocked_ = true;
|
||||
|
||||
foreach (Track* track, track_list_->GetTracks()) {
|
||||
if (track->IsLocked()) {
|
||||
all_tracks_unlocked_ = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -346,19 +331,6 @@ void TrackListInsertGaps::prepare()
|
||||
|
||||
void TrackListInsertGaps::redo()
|
||||
{
|
||||
if (all_tracks_unlocked_) {
|
||||
// Optimize by shifting over since we have a constant amount of time being inserted
|
||||
if (track_list_->type() == Track::kVideo) {
|
||||
track_list_->parent()->ShiftVideoCache(point_, point_ + length_);
|
||||
} else if (track_list_->type() == Track::kAudio) {
|
||||
track_list_->parent()->ShiftAudioCache(point_, point_ + length_);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->BeginOperation();
|
||||
}
|
||||
|
||||
foreach (Block* gap, gaps_to_extend_) {
|
||||
gap->set_length_and_media_out(gap->length() + length_);
|
||||
}
|
||||
@@ -371,33 +343,10 @@ void TrackListInsertGaps::redo()
|
||||
add_gap.gap->setParent(add_gap.track->parent());
|
||||
add_gap.track->InsertBlockAfter(add_gap.gap, add_gap.before);
|
||||
}
|
||||
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->EndOperation();
|
||||
}
|
||||
|
||||
if (!all_tracks_unlocked_) {
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->Node::InvalidateCache(TimeRange(point_, RATIONAL_MAX), Track::kBlockInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TrackListInsertGaps::undo()
|
||||
{
|
||||
if (all_tracks_unlocked_) {
|
||||
// Optimize by shifting over since we have a constant amount of time being inserted
|
||||
if (track_list_->type() == Track::kVideo) {
|
||||
track_list_->parent()->ShiftVideoCache(point_ + length_, point_);
|
||||
} else if (track_list_->type() == Track::kAudio) {
|
||||
track_list_->parent()->ShiftAudioCache(point_ + length_, point_);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->BeginOperation();
|
||||
}
|
||||
|
||||
// Remove added gaps
|
||||
foreach (auto add_gap, gaps_added_) {
|
||||
add_gap.gap->track()->RippleRemoveBlock(add_gap.gap);
|
||||
@@ -413,16 +362,6 @@ void TrackListInsertGaps::undo()
|
||||
foreach (Block* gap, gaps_to_extend_) {
|
||||
gap->set_length_and_media_out(gap->length() - length_);
|
||||
}
|
||||
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->EndOperation();
|
||||
}
|
||||
|
||||
if (!all_tracks_unlocked_) {
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->Node::InvalidateCache(TimeRange(point_, RATIONAL_MAX), Track::kBlockInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -440,8 +379,6 @@ void TrackReplaceBlockWithGapCommand::redo()
|
||||
}
|
||||
|
||||
if (block_->next()) {
|
||||
track_->BeginOperation();
|
||||
|
||||
// Invalidate the range inhabited by this block
|
||||
TimeRange invalidate_range(block_->in(), block_->out());
|
||||
|
||||
@@ -488,12 +425,6 @@ void TrackReplaceBlockWithGapCommand::redo()
|
||||
track_->ReplaceBlock(block_, our_gap_);
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
if (handle_invalidations_) {
|
||||
track_->Node::InvalidateCache(invalidate_range, Track::kBlockInput);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Block is at the end of the track, simply remove it
|
||||
Block* preceding = block_->previous();
|
||||
@@ -512,8 +443,6 @@ void TrackReplaceBlockWithGapCommand::redo()
|
||||
void TrackReplaceBlockWithGapCommand::undo()
|
||||
{
|
||||
if (our_gap_ || existing_gap_) {
|
||||
track_->BeginOperation();
|
||||
|
||||
if (our_gap_) {
|
||||
|
||||
// We made this gap, simply swap our gap back
|
||||
@@ -547,11 +476,6 @@ void TrackReplaceBlockWithGapCommand::undo()
|
||||
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
if (handle_invalidations_) {
|
||||
track_->Node::InvalidateCache(TimeRange(block_->in(), block_->out()), Track::kBlockInput);
|
||||
}
|
||||
} else {
|
||||
|
||||
// Our gap and existing gap were both null, our block must have been at the end and thus
|
||||
|
||||
@@ -233,14 +233,13 @@ private:
|
||||
|
||||
class TrackReplaceBlockWithGapCommand : public UndoCommand {
|
||||
public:
|
||||
TrackReplaceBlockWithGapCommand(Track* track, Block* block, bool handle_transitions = true, bool handle_invalidations = true) :
|
||||
TrackReplaceBlockWithGapCommand(Track* track, Block* block, bool handle_transitions = true) :
|
||||
track_(track),
|
||||
block_(block),
|
||||
existing_gap_(nullptr),
|
||||
existing_merged_gap_(nullptr),
|
||||
our_gap_(nullptr),
|
||||
handle_transitions_(handle_transitions),
|
||||
handle_invalidations_(handle_invalidations)
|
||||
handle_transitions_(handle_transitions)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -266,7 +265,6 @@ private:
|
||||
GapBlock* our_gap_;
|
||||
|
||||
bool handle_transitions_;
|
||||
bool handle_invalidations_;
|
||||
|
||||
QObject memory_manager_;
|
||||
|
||||
@@ -344,8 +342,6 @@ private:
|
||||
|
||||
QVector<Track*> working_tracks_;
|
||||
|
||||
bool all_tracks_unlocked_;
|
||||
|
||||
QVector<Block*> gaps_to_extend_;
|
||||
|
||||
struct AddGap {
|
||||
@@ -362,62 +358,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class NodeBeginOperationCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeBeginOperationCommand(Node *node) :
|
||||
node_(node)
|
||||
{}
|
||||
|
||||
virtual Project* GetRelevantProject() const override
|
||||
{
|
||||
return node_->project();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void redo() override
|
||||
{
|
||||
node_->BeginOperation();
|
||||
}
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
node_->EndOperation();
|
||||
}
|
||||
|
||||
private:
|
||||
Node *node_;
|
||||
|
||||
};
|
||||
|
||||
class NodeEndOperationCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeEndOperationCommand(Node *node) :
|
||||
node_(node)
|
||||
{}
|
||||
|
||||
virtual Project* GetRelevantProject() const override
|
||||
{
|
||||
return node_->project();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void redo() override
|
||||
{
|
||||
node_->EndOperation();
|
||||
}
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
node_->BeginOperation();
|
||||
}
|
||||
|
||||
private:
|
||||
Node *node_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TIMELINEUNDOGENERAL_H
|
||||
|
||||
@@ -36,9 +36,6 @@ void BlockTrimCommand::redo()
|
||||
return;
|
||||
}
|
||||
|
||||
// Begin an operation since we'll be doing a lot
|
||||
track_->BeginOperation();
|
||||
|
||||
// Determine how much time to invalidate
|
||||
TimeRange invalidate_range;
|
||||
|
||||
@@ -82,14 +79,10 @@ void BlockTrimCommand::redo()
|
||||
}
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
if (dynamic_cast<TransitionBlock*>(block_)) {
|
||||
// Whole transition needs to be invalidated
|
||||
invalidate_range = block_->range();
|
||||
}
|
||||
|
||||
track_->Node::InvalidateCache(invalidate_range, Track::kBlockInput);
|
||||
}
|
||||
|
||||
void BlockTrimCommand::undo()
|
||||
@@ -98,8 +91,6 @@ void BlockTrimCommand::undo()
|
||||
return;
|
||||
}
|
||||
|
||||
track_->BeginOperation();
|
||||
|
||||
// Will be POSITIVE if trimming shorter and NEGATIVE if trimming longer
|
||||
if (needs_adjacent_) {
|
||||
if (we_created_adjacent_) {
|
||||
@@ -146,10 +137,6 @@ void BlockTrimCommand::undo()
|
||||
// Whole transition needs to be invalidated
|
||||
invalidate_range = block_->range();
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
track_->Node::InvalidateCache(invalidate_range, Track::kBlockInput);
|
||||
}
|
||||
|
||||
void BlockTrimCommand::prepare()
|
||||
@@ -200,8 +187,6 @@ void TrackSlideCommand::redo()
|
||||
// Make sure all movement blocks' old positions are invalidated
|
||||
TimeRange invalidate_range(blocks_.first()->in(), blocks_.last()->out());
|
||||
|
||||
track_->BeginOperation();
|
||||
|
||||
// We will always have an in adjacent if there was a valid slide
|
||||
if (we_created_in_adjacent_) {
|
||||
// We created in adjacent, so all we have to do is insert it
|
||||
@@ -246,13 +231,9 @@ void TrackSlideCommand::redo()
|
||||
}
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
// Make sure all movement blocks' new positions are invalidated
|
||||
invalidate_range.set_range(qMin(invalidate_range.in(), blocks_.first()->in()),
|
||||
qMax(invalidate_range.out(), blocks_.last()->out()));
|
||||
|
||||
track_->Node::InvalidateCache(invalidate_range, Track::kBlockInput);
|
||||
}
|
||||
|
||||
|
||||
@@ -261,8 +242,6 @@ void TrackSlideCommand::undo()
|
||||
// Make sure all movement blocks' old positions are invalidated
|
||||
TimeRange invalidate_range(blocks_.first()->in(), blocks_.last()->out());
|
||||
|
||||
track_->BeginOperation();
|
||||
|
||||
if (we_created_in_adjacent_) {
|
||||
// We created this, so we can remove it now
|
||||
track_->RippleRemoveBlock(in_adjacent_);
|
||||
@@ -287,13 +266,9 @@ void TrackSlideCommand::undo()
|
||||
}
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
// Make sure all movement blocks' new positions are invalidated
|
||||
invalidate_range.set_range(qMin(invalidate_range.in(), blocks_.first()->in()),
|
||||
qMax(invalidate_range.out(), blocks_.last()->out()));
|
||||
|
||||
track_->Node::InvalidateCache(invalidate_range, Track::kBlockInput);
|
||||
}
|
||||
|
||||
void TrackSlideCommand::prepare()
|
||||
@@ -328,8 +303,6 @@ TrackPlaceBlockCommand::~TrackPlaceBlockCommand()
|
||||
|
||||
void TrackPlaceBlockCommand::redo()
|
||||
{
|
||||
TimeRangeList ranges_to_invalidate;
|
||||
|
||||
// Determine if we need to add tracks
|
||||
if (track_index_ >= timeline_->GetTracks().size()) {
|
||||
if (add_track_commands_.isEmpty()) {
|
||||
@@ -348,8 +321,6 @@ void TrackPlaceBlockCommand::redo()
|
||||
|
||||
Track* track = timeline_->GetTrackAt(track_index_);
|
||||
|
||||
track->BeginOperation();
|
||||
|
||||
bool append = (in_ >= track->track_length());
|
||||
|
||||
// Check if the placement location is past the end of the timeline
|
||||
@@ -362,7 +333,6 @@ void TrackPlaceBlockCommand::redo()
|
||||
}
|
||||
gap_->setParent(track->parent());
|
||||
track->AppendBlock(gap_);
|
||||
ranges_to_invalidate.insert(gap_->range());
|
||||
}
|
||||
|
||||
track->AppendBlock(insert_);
|
||||
@@ -376,14 +346,6 @@ void TrackPlaceBlockCommand::redo()
|
||||
ripple_remove_command_->redo_now();
|
||||
track->InsertBlockAfter(insert_, ripple_remove_command_->GetInsertionIndex());
|
||||
}
|
||||
|
||||
track->EndOperation();
|
||||
|
||||
ranges_to_invalidate.insert(insert_->range());
|
||||
|
||||
foreach (const TimeRange &r, ranges_to_invalidate) {
|
||||
track->Node::InvalidateCache(r, Track::kBlockInput);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackPlaceBlockCommand::undo()
|
||||
@@ -393,7 +355,6 @@ void TrackPlaceBlockCommand::undo()
|
||||
TimeRange insert_range(insert_->in(), insert_->out());
|
||||
|
||||
// Firstly, remove our insert
|
||||
t->BeginOperation();
|
||||
t->RippleRemoveBlock(insert_);
|
||||
|
||||
if (ripple_remove_command_) {
|
||||
@@ -403,9 +364,6 @@ void TrackPlaceBlockCommand::undo()
|
||||
t->RippleRemoveBlock(gap_);
|
||||
gap_->setParent(&memory_manager_);
|
||||
}
|
||||
t->EndOperation();
|
||||
|
||||
t->Node::InvalidateCache(insert_range, Track::kBlockInput);
|
||||
|
||||
// Remove tracks if we added them
|
||||
for (int i=add_track_commands_.size()-1; i>=0; i--) {
|
||||
|
||||
@@ -106,8 +106,6 @@ void TrackRippleRemoveAreaCommand::prepare()
|
||||
|
||||
void TrackRippleRemoveAreaCommand::redo()
|
||||
{
|
||||
track_->BeginOperation();
|
||||
|
||||
if (splice_split_command_) {
|
||||
// We're just splicing
|
||||
splice_split_command_->redo_now();
|
||||
@@ -145,17 +143,10 @@ void TrackRippleRemoveAreaCommand::redo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
track_->EndOperation();
|
||||
|
||||
track_->Node::InvalidateCache(TimeRange(range_.in(), RATIONAL_MAX), Track::kBlockInput);
|
||||
}
|
||||
|
||||
void TrackRippleRemoveAreaCommand::undo()
|
||||
{
|
||||
// Begin operations
|
||||
track_->BeginOperation();
|
||||
|
||||
if (splice_split_command_) {
|
||||
splice_split_command_->undo_now();
|
||||
} else {
|
||||
@@ -176,85 +167,36 @@ void TrackRippleRemoveAreaCommand::undo()
|
||||
track_->InsertBlockAfter(op.block, op.before);
|
||||
}
|
||||
}
|
||||
|
||||
// End operations and invalidate
|
||||
track_->EndOperation();
|
||||
|
||||
track_->Node::InvalidateCache(TimeRange(range_.in(), RATIONAL_MAX), Track::kBlockInput);
|
||||
}
|
||||
|
||||
//
|
||||
// TrackListRippleRemoveAreaCommand
|
||||
//
|
||||
void TrackListRippleRemoveAreaCommand::prepare()
|
||||
{
|
||||
foreach (Track* track, list_->GetTracks()) {
|
||||
if (track->IsLocked()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TrackRippleRemoveAreaCommand* c = new TrackRippleRemoveAreaCommand(track, range_);
|
||||
commands_.append(c);
|
||||
working_tracks_.append(track);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackListRippleRemoveAreaCommand::redo()
|
||||
{
|
||||
// Code that's only run on the first redo
|
||||
if (commands_.isEmpty()) {
|
||||
all_tracks_unlocked_ = true;
|
||||
|
||||
foreach (Track* track, list_->GetTracks()) {
|
||||
if (track->IsLocked()) {
|
||||
all_tracks_unlocked_ = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
TrackRippleRemoveAreaCommand* c = new TrackRippleRemoveAreaCommand(track, range_);
|
||||
commands_.append(c);
|
||||
working_tracks_.append(track);
|
||||
}
|
||||
}
|
||||
|
||||
if (all_tracks_unlocked_) {
|
||||
// We can optimize here by simply shifting the whole cache forward instead of re-caching
|
||||
// everything following this time
|
||||
if (list_->type() == Track::kVideo) {
|
||||
list_->parent()->ShiftVideoCache(range_.out(), range_.in());
|
||||
} else if (list_->type() == Track::kAudio) {
|
||||
list_->parent()->ShiftAudioCache(range_.out(), range_.in());
|
||||
}
|
||||
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->BeginOperation();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (TrackRippleRemoveAreaCommand* c, commands_) {
|
||||
c->redo_now();
|
||||
}
|
||||
|
||||
if (all_tracks_unlocked_) {
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->EndOperation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TrackListRippleRemoveAreaCommand::undo()
|
||||
{
|
||||
if (all_tracks_unlocked_) {
|
||||
// We can optimize here by simply shifting the whole cache forward instead of re-caching
|
||||
// everything following this time
|
||||
if (list_->type() == Track::kVideo) {
|
||||
list_->parent()->ShiftVideoCache(range_.in(), range_.out());
|
||||
} else if (list_->type() == Track::kAudio) {
|
||||
list_->parent()->ShiftAudioCache(range_.in(), range_.out());
|
||||
}
|
||||
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->BeginOperation();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (TrackRippleRemoveAreaCommand* c, commands_) {
|
||||
c->undo_now();
|
||||
}
|
||||
|
||||
if (all_tracks_unlocked_) {
|
||||
foreach (Track* track, working_tracks_) {
|
||||
track->EndOperation();
|
||||
track->Node::InvalidateCache(range_, Track::kBlockInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -282,7 +224,6 @@ TrackListRippleToolCommand::TrackListRippleToolCommand(TrackList* track_list,
|
||||
ripple_movement_(ripple_movement),
|
||||
movement_mode_(movement_mode)
|
||||
{
|
||||
all_tracks_unlocked_ = (info_.size() == track_list_->GetTrackCount());
|
||||
}
|
||||
|
||||
void TrackListRippleToolCommand::ripple(bool redo)
|
||||
@@ -324,9 +265,6 @@ void TrackListRippleToolCommand::ripple(bool redo)
|
||||
rational pre_shift;
|
||||
rational post_shift;
|
||||
|
||||
// Begin operation so we can invalidate better later
|
||||
track->BeginOperation();
|
||||
|
||||
if (info.append_gap) {
|
||||
|
||||
// Rather than rippling the referenced block, we'll insert a gap and ripple with that
|
||||
@@ -429,29 +367,6 @@ void TrackListRippleToolCommand::ripple(bool redo)
|
||||
pre_latest_out = qMax(pre_latest_out, pre_shift);
|
||||
post_latest_out = qMax(post_latest_out, post_shift);
|
||||
}
|
||||
|
||||
if (all_tracks_unlocked_) {
|
||||
// We rippled all the tracks, so we can shift the whole cache
|
||||
if (track_list_->type() == Track::kVideo) {
|
||||
track_list_->parent()->ShiftVideoCache(pre_latest_out, post_latest_out);
|
||||
} else if (track_list_->type() == Track::kAudio) {
|
||||
track_list_->parent()->ShiftAudioCache(pre_latest_out, post_latest_out);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it=working_data_.cbegin(); it!=working_data_.cend(); it++) {
|
||||
Track* track = it.key();
|
||||
|
||||
track->EndOperation();
|
||||
|
||||
if (!all_tracks_unlocked_) {
|
||||
// If we're not shifting, the whole track must get invalidated
|
||||
track->Node::InvalidateCache(TimeRange(it.value().earliest_point_of_change, RATIONAL_MAX), Track::kBlockInput);
|
||||
} else if (pre_latest_out < post_latest_out) {
|
||||
// If we're here, then a new section has been rippled in that needs to be rendered
|
||||
track->Node::InvalidateCache(TimeRange(pre_latest_out, post_latest_out), Track::kBlockInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -513,11 +428,8 @@ void TimelineRippleDeleteGapsAtRegionsCommand::prepare()
|
||||
// Determine which gaps will be involved in this operation
|
||||
QVector<GapBlock*> gaps;
|
||||
|
||||
bool all_tracks_unlocked = true;
|
||||
|
||||
foreach (Track* track, timeline_->GetTracks()) {
|
||||
if (track->IsLocked()) {
|
||||
all_tracks_unlocked = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -573,24 +485,12 @@ void TimelineRippleDeleteGapsAtRegionsCommand::prepare()
|
||||
|
||||
if (ripple_length > 0) {
|
||||
foreach (GapBlock *gap, gaps) {
|
||||
if (all_tracks_unlocked) {
|
||||
commands_.append(new NodeBeginOperationCommand(gap->track()));
|
||||
}
|
||||
|
||||
if (gap_lengths.value(gap) == ripple_length) {
|
||||
commands_.append(new TrackRippleRemoveBlockCommand(gap->track(), gap));
|
||||
} else {
|
||||
gap_lengths[gap] -= ripple_length;
|
||||
commands_.append(new BlockResizeCommand(gap, gap_lengths.value(gap)));
|
||||
}
|
||||
|
||||
if (all_tracks_unlocked) {
|
||||
commands_.append(new NodeEndOperationCommand(gap->track()));
|
||||
}
|
||||
}
|
||||
|
||||
if (all_tracks_unlocked) {
|
||||
commands_.append(new TimelineShiftCacheCommand(timeline_, latest_point, latest_point - ripple_length));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -610,14 +510,4 @@ void TimelineRippleDeleteGapsAtRegionsCommand::undo()
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineShiftCacheCommand::redo()
|
||||
{
|
||||
timeline_->ShiftCache(from_, to_);
|
||||
}
|
||||
|
||||
void TimelineShiftCacheCommand::undo()
|
||||
{
|
||||
timeline_->ShiftCache(to_, from_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -119,6 +119,8 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void prepare() override;
|
||||
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override;
|
||||
@@ -130,8 +132,6 @@ private:
|
||||
|
||||
TimeRange range_;
|
||||
|
||||
bool all_tracks_unlocked_;
|
||||
|
||||
QVector<TrackRippleRemoveAreaCommand*> commands_;
|
||||
|
||||
};
|
||||
@@ -200,8 +200,6 @@ private:
|
||||
|
||||
QObject memory_manager_;
|
||||
|
||||
bool all_tracks_unlocked_;
|
||||
|
||||
};
|
||||
|
||||
class TimelineRippleDeleteGapsAtRegionsCommand : public UndoCommand
|
||||
@@ -250,34 +248,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class TimelineShiftCacheCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
TimelineShiftCacheCommand(Sequence* timeline, const rational &from, const rational &to) :
|
||||
timeline_(timeline),
|
||||
from_(from),
|
||||
to_(to)
|
||||
{}
|
||||
|
||||
virtual Project* GetRelevantProject() const override
|
||||
{
|
||||
return timeline_->project();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Sequence* timeline_;
|
||||
|
||||
rational from_;
|
||||
|
||||
rational to_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TIMELINEUNDORIPPLE_H
|
||||
|
||||
@@ -53,7 +53,6 @@ void BlockSplitCommand::redo()
|
||||
|
||||
// Begin an operation
|
||||
Track* track = block_->track();
|
||||
track->BeginOperation();
|
||||
|
||||
// Set lengths
|
||||
block_->set_length_and_media_out(new_length);
|
||||
@@ -76,16 +75,12 @@ void BlockSplitCommand::redo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
track->EndOperation();
|
||||
}
|
||||
|
||||
void BlockSplitCommand::undo()
|
||||
{
|
||||
Track* track = block_->track();
|
||||
|
||||
track->BeginOperation();
|
||||
|
||||
if (moved_transition_.IsValid()) {
|
||||
Node::DisconnectEdge(new_block(), moved_transition_);
|
||||
Node::ConnectEdge(block_, moved_transition_);
|
||||
@@ -96,8 +91,6 @@ void BlockSplitCommand::undo()
|
||||
|
||||
// If we ran a reconnect command, disconnect now
|
||||
reconnect_tree_command_->undo_now();
|
||||
|
||||
track->EndOperation();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -82,7 +82,6 @@ void TimeRuler::SetPlaybackCache(PlaybackCache *cache)
|
||||
if (playback_cache_) {
|
||||
disconnect(playback_cache_, &PlaybackCache::Invalidated, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
disconnect(playback_cache_, &PlaybackCache::Validated, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
disconnect(playback_cache_, &PlaybackCache::Shifted, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
}
|
||||
|
||||
playback_cache_ = cache;
|
||||
@@ -90,7 +89,6 @@ void TimeRuler::SetPlaybackCache(PlaybackCache *cache)
|
||||
if (playback_cache_) {
|
||||
connect(playback_cache_, &PlaybackCache::Invalidated, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
connect(playback_cache_, &PlaybackCache::Validated, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
connect(playback_cache_, &PlaybackCache::Shifted, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
}
|
||||
|
||||
update();
|
||||
@@ -257,35 +255,37 @@ void TimeRuler::drawForeground(QPainter *p, const QRectF &rect)
|
||||
// If cache status is enabled
|
||||
if (show_cache_status_ && playback_cache_) {
|
||||
// FIXME: Hardcoded to get video length, if we ever need audio length, this will have to change
|
||||
rational len = playback_cache_->viewer_parent()->GetVideoLength();
|
||||
int lim_left = GetScroll();
|
||||
int lim_right = lim_left + width();
|
||||
if (ViewerOutput *viewer = dynamic_cast<ViewerOutput*>(playback_cache_->parent())) {
|
||||
rational len = viewer->GetVideoLength();
|
||||
int lim_left = GetScroll();
|
||||
int lim_right = lim_left + width();
|
||||
|
||||
int cache_screen_length = TimeToScene(len);
|
||||
int cache_screen_length = TimeToScene(len);
|
||||
|
||||
if (cache_screen_length > 0) {
|
||||
int cache_y = height() - cache_status_height_;
|
||||
if (cache_screen_length > 0) {
|
||||
int cache_y = height() - cache_status_height_;
|
||||
|
||||
p->fillRect(0, cache_y, cache_screen_length, cache_status_height_, Qt::green);
|
||||
p->fillRect(0, cache_y, cache_screen_length, cache_status_height_, Qt::green);
|
||||
|
||||
foreach (const TimeRange& range, playback_cache_->GetInvalidatedRanges(len)) {
|
||||
int range_left = TimeToScene(range.in());
|
||||
if (range_left >= width()) {
|
||||
continue;
|
||||
foreach (const TimeRange& range, playback_cache_->GetInvalidatedRanges(len)) {
|
||||
int range_left = TimeToScene(range.in());
|
||||
if (range_left >= width()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int range_right = TimeToScene(range.out());
|
||||
if (range_right < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int adjusted_left = qMax(lim_left, range_left);
|
||||
|
||||
p->fillRect(adjusted_left,
|
||||
cache_y,
|
||||
qMin(lim_right, range_right) - adjusted_left,
|
||||
cache_status_height_,
|
||||
Qt::red);
|
||||
}
|
||||
|
||||
int range_right = TimeToScene(range.out());
|
||||
if (range_right < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int adjusted_left = qMax(lim_left, range_left);
|
||||
|
||||
p->fillRect(adjusted_left,
|
||||
cache_y,
|
||||
qMin(lim_right, range_right) - adjusted_left,
|
||||
cache_status_height_,
|
||||
Qt::red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,6 @@ void ViewerWidget::ConnectNodeEvent(ViewerOutput *n)
|
||||
connect(n, &ViewerOutput::VideoParamsChanged, this, &ViewerWidget::UpdateRendererVideoParameters);
|
||||
connect(n, &ViewerOutput::AudioParamsChanged, this, &ViewerWidget::UpdateRendererAudioParameters);
|
||||
connect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedVideoRange);
|
||||
connect(n->video_frame_cache(), &FrameHashCache::Shifted, this, &ViewerWidget::ViewerShiftedRange);
|
||||
connect(n, &ViewerOutput::TextureInputChanged, this, &ViewerWidget::UpdateStack);
|
||||
|
||||
VideoParams vp = n->GetVideoParams();
|
||||
@@ -250,7 +249,6 @@ void ViewerWidget::DisconnectNodeEvent(ViewerOutput *n)
|
||||
disconnect(n, &ViewerOutput::VideoParamsChanged, this, &ViewerWidget::UpdateRendererVideoParameters);
|
||||
disconnect(n, &ViewerOutput::AudioParamsChanged, this, &ViewerWidget::UpdateRendererAudioParameters);
|
||||
disconnect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedVideoRange);
|
||||
disconnect(n->video_frame_cache(), &FrameHashCache::Shifted, this, &ViewerWidget::ViewerShiftedRange);
|
||||
disconnect(n, &ViewerOutput::TextureInputChanged, this, &ViewerWidget::UpdateStack);
|
||||
|
||||
CloseAudioProcessor();
|
||||
@@ -1556,13 +1554,6 @@ void ViewerWidget::ManualSwitchToWaveform(bool e)
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::ViewerShiftedRange(const rational &from, const rational &to)
|
||||
{
|
||||
if (GetTime() >= qMin(from, to)) {
|
||||
QMetaObject::invokeMethod(this, &ViewerWidget::UpdateTextureFromNode, Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::DragEntered(QDragEnterEvent* event)
|
||||
{
|
||||
if (event->mimeData()->formats().contains(Project::kItemMimeType)) {
|
||||
|
||||
@@ -291,8 +291,6 @@ private slots:
|
||||
|
||||
void SetZoomFromMenu(QAction* action);
|
||||
|
||||
void ViewerShiftedRange(const olive::rational& from, const olive::rational& to);
|
||||
|
||||
void UpdateStack();
|
||||
|
||||
void ContextMenuSetFullScreen(QAction* action);
|
||||
|
||||
Reference in New Issue
Block a user