/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
***/
#ifndef TIMELINEUNDOABLE_H
#define TIMELINEUNDOABLE_H
#include
#include "node/block/block.h"
#include "node/block/gap/gap.h"
#include "node/block/transition/transition.h"
#include "node/output/track/track.h"
#include "node/output/track/tracklist.h"
#include "timeline/timelinepoints.h"
#include "undo/undocommand.h"
#include "widget/timelinewidget/timelinewidgetselections.h"
namespace olive {
class BlockResizeCommand : public UndoCommand {
public:
BlockResizeCommand(Block* block, rational new_length, QUndoCommand* parent = nullptr) :
UndoCommand(parent),
block_(block),
new_length_(new_length)
{
}
virtual Project* GetRelevantProject() const override
{
return block_->parent()->project();
}
protected:
virtual void redo_internal() override
{
old_length_ = block_->length();
block_->set_length_and_media_out(new_length_);
}
virtual void undo_internal() override
{
block_->set_length_and_media_out(old_length_);
}
private:
Block* block_;
rational old_length_;
rational new_length_;
};
class BlockResizeWithMediaInCommand : public UndoCommand {
public:
BlockResizeWithMediaInCommand(Block* block, rational new_length, QUndoCommand* parent = nullptr) :
UndoCommand(parent),
block_(block),
new_length_(new_length)
{
}
virtual Project* GetRelevantProject() const override
{
return block_->parent()->project();
}
protected:
virtual void redo_internal() override
{
old_length_ = block_->length();
block_->set_length_and_media_in(new_length_);
}
virtual void undo_internal() override
{
block_->set_length_and_media_in(old_length_);
}
private:
Block* block_;
rational old_length_;
rational new_length_;
};
class BlockTrimCommand : public UndoCommand {
public:
BlockTrimCommand(Track *track, Block* block, rational new_length, Timeline::MovementMode mode, QUndoCommand* command = nullptr);
virtual Project* GetRelevantProject() const override;
void SetTrimIsARollEdit(bool e)
{
trim_is_a_roll_edit_ = e;
}
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
Track* track_;
Block* block_;
rational old_length_;
rational new_length_;
Timeline::MovementMode mode_;
Block* adjacent_;
bool we_created_adjacent_;
bool we_deleted_adjacent_;
bool trim_is_a_roll_edit_;
QObject memory_manager_;
};
class BlockSetMediaInCommand : public UndoCommand {
public:
BlockSetMediaInCommand(Block* block, rational new_media_in, QUndoCommand* parent = nullptr) :
UndoCommand(parent),
block_(block),
new_media_in_(new_media_in)
{
}
virtual Project* GetRelevantProject() const override
{
return block_->parent()->project();
}
protected:
virtual void redo_internal() override
{
old_media_in_ = block_->media_in();
block_->set_media_in(new_media_in_);
}
virtual void undo_internal() override
{
block_->set_media_in(old_media_in_);
}
private:
Block* block_;
rational old_media_in_;
rational new_media_in_;
};
class TrackRippleRemoveBlockCommand : public UndoCommand {
public:
TrackRippleRemoveBlockCommand(Track* track, Block* block, QUndoCommand* parent = nullptr) :
UndoCommand(parent),
track_(track),
block_(block)
{
}
virtual Project* GetRelevantProject() const override
{
return track_->parent()->project();
}
protected:
virtual void redo_internal() override
{
before_ = block_->previous();
track_->RippleRemoveBlock(block_);
}
virtual void undo_internal() override
{
if (before_) {
track_->InsertBlockAfter(block_, before_);
} else {
track_->PrependBlock(block_);
}
}
private:
Track* track_;
Block* block_;
Block* before_;
};
class TrackPrependBlockCommand : public UndoCommand {
public:
TrackPrependBlockCommand(Track* track, Block* block, QUndoCommand* parent = nullptr);
virtual Project* GetRelevantProject() const override;
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
Track* track_;
Block* block_;
};
class TrackInsertBlockAfterCommand : public UndoCommand {
public:
TrackInsertBlockAfterCommand(Track* track, Block* block, Block* before, QUndoCommand* parent = nullptr) :
UndoCommand(parent),
track_(track),
block_(block),
before_(before)
{
}
virtual Project* GetRelevantProject() const override
{
return block_->parent()->project();
}
protected:
virtual void redo_internal() override
{
track_->InsertBlockAfter(block_, before_);
}
virtual void undo_internal() override
{
track_->RippleRemoveBlock(block_);
}
private:
Track* track_;
Block* block_;
Block* before_;
};
/**
* @brief Clears the area between in and out
*
* The area between `in` and `out` is guaranteed to be freed. BLocks are trimmed and removed to free this space.
* By default, nothing takes this area meaning all subsequent clips are pushed backward, however you can specify
* a block to insert at the `in` point. No checking is done to ensure `insert` is the same length as `in` to `out`.
*/
class TrackRippleRemoveAreaCommand : public UndoCommand {
public:
TrackRippleRemoveAreaCommand(Track* track, rational in, rational out, QUndoCommand* parent = nullptr);
virtual Project* GetRelevantProject() const override;
void SetInsert(Block* insert);
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
protected:
Project* project_;
Track* track_;
rational in_;
rational out_;
bool splice_;
QUndoCommand* splice_split_command_;
Block* trim_out_;
Block* trim_in_;
QVector removed_blocks_;
rational trim_in_old_length_;
rational trim_out_old_length_;
rational trim_in_new_length_;
rational trim_out_new_length_;
Block* insert_;
QObject memory_manager_;
QVector remove_block_commands_;
};
class TrackListRippleRemoveAreaCommand : public UndoCommand {
public:
TrackListRippleRemoveAreaCommand(TrackList* list, rational in, rational out, QUndoCommand* parent = nullptr);
virtual ~TrackListRippleRemoveAreaCommand() override;
virtual Project* GetRelevantProject() const override;
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
TrackList* list_;
QList